@@ -1,444 +1,444 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | class RPC extends Handler_Protected { |
| 3 | 3 | |
| 4 | - public function csrf_ignore($method) { |
|
| 5 | - $csrf_ignored = array("sanitycheck", "completelabels", "saveprofile"); |
|
| 4 | + public function csrf_ignore($method) { |
|
| 5 | + $csrf_ignored = array("sanitycheck", "completelabels", "saveprofile"); |
|
| 6 | 6 | |
| 7 | - return array_search($method, $csrf_ignored) !== false; |
|
| 8 | - } |
|
| 7 | + return array_search($method, $csrf_ignored) !== false; |
|
| 8 | + } |
|
| 9 | 9 | |
| 10 | - public function setprofile() { |
|
| 11 | - $_SESSION["profile"] = (int) clean($_REQUEST["id"]); |
|
| 10 | + public function setprofile() { |
|
| 11 | + $_SESSION["profile"] = (int) clean($_REQUEST["id"]); |
|
| 12 | 12 | |
| 13 | - // default value |
|
| 14 | - if (!$_SESSION["profile"]) { |
|
| 15 | - $_SESSION["profile"] = null; |
|
| 16 | - } |
|
| 17 | - } |
|
| 13 | + // default value |
|
| 14 | + if (!$_SESSION["profile"]) { |
|
| 15 | + $_SESSION["profile"] = null; |
|
| 16 | + } |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - public function remprofiles() { |
|
| 20 | - $ids = explode(",", trim(clean($_REQUEST["ids"]))); |
|
| 19 | + public function remprofiles() { |
|
| 20 | + $ids = explode(",", trim(clean($_REQUEST["ids"]))); |
|
| 21 | 21 | |
| 22 | - foreach ($ids as $id) { |
|
| 23 | - if ($_SESSION["profile"] != $id) { |
|
| 24 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_settings_profiles WHERE id = ? AND |
|
| 22 | + foreach ($ids as $id) { |
|
| 23 | + if ($_SESSION["profile"] != $id) { |
|
| 24 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_settings_profiles WHERE id = ? AND |
|
| 25 | 25 | owner_uid = ?"); |
| 26 | - $sth->execute([$id, $_SESSION['uid']]); |
|
| 27 | - } |
|
| 28 | - } |
|
| 29 | - } |
|
| 26 | + $sth->execute([$id, $_SESSION['uid']]); |
|
| 27 | + } |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - // Silent |
|
| 32 | - public function addprofile() { |
|
| 33 | - $title = trim(clean($_REQUEST["title"])); |
|
| 31 | + // Silent |
|
| 32 | + public function addprofile() { |
|
| 33 | + $title = trim(clean($_REQUEST["title"])); |
|
| 34 | 34 | |
| 35 | - if ($title) { |
|
| 36 | - $this->pdo->beginTransaction(); |
|
| 35 | + if ($title) { |
|
| 36 | + $this->pdo->beginTransaction(); |
|
| 37 | 37 | |
| 38 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles |
|
| 38 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles |
|
| 39 | 39 | WHERE title = ? AND owner_uid = ?"); |
| 40 | - $sth->execute([$title, $_SESSION['uid']]); |
|
| 40 | + $sth->execute([$title, $_SESSION['uid']]); |
|
| 41 | 41 | |
| 42 | - if (!$sth->fetch()) { |
|
| 42 | + if (!$sth->fetch()) { |
|
| 43 | 43 | |
| 44 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_settings_profiles (title, owner_uid) |
|
| 44 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_settings_profiles (title, owner_uid) |
|
| 45 | 45 | VALUES (?, ?)"); |
| 46 | 46 | |
| 47 | - $sth->execute([$title, $_SESSION['uid']]); |
|
| 47 | + $sth->execute([$title, $_SESSION['uid']]); |
|
| 48 | 48 | |
| 49 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles WHERE |
|
| 49 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles WHERE |
|
| 50 | 50 | title = ? AND owner_uid = ?"); |
| 51 | - $sth->execute([$title, $_SESSION['uid']]); |
|
| 51 | + $sth->execute([$title, $_SESSION['uid']]); |
|
| 52 | 52 | |
| 53 | - if ($row = $sth->fetch()) { |
|
| 54 | - $profile_id = $row['id']; |
|
| 53 | + if ($row = $sth->fetch()) { |
|
| 54 | + $profile_id = $row['id']; |
|
| 55 | 55 | |
| 56 | - if ($profile_id) { |
|
| 57 | - initialize_user_prefs($_SESSION["uid"], $profile_id); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 56 | + if ($profile_id) { |
|
| 57 | + initialize_user_prefs($_SESSION["uid"], $profile_id); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - $this->pdo->commit(); |
|
| 63 | - } |
|
| 64 | - } |
|
| 62 | + $this->pdo->commit(); |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - public function saveprofile() { |
|
| 67 | - $id = clean($_REQUEST["id"]); |
|
| 68 | - $title = trim(clean($_REQUEST["value"])); |
|
| 66 | + public function saveprofile() { |
|
| 67 | + $id = clean($_REQUEST["id"]); |
|
| 68 | + $title = trim(clean($_REQUEST["value"])); |
|
| 69 | 69 | |
| 70 | - if ($id == 0) { |
|
| 71 | - print __("Default profile"); |
|
| 72 | - return; |
|
| 73 | - } |
|
| 70 | + if ($id == 0) { |
|
| 71 | + print __("Default profile"); |
|
| 72 | + return; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - if ($title) { |
|
| 76 | - $sth = $this->pdo->prepare("UPDATE ttrss_settings_profiles |
|
| 75 | + if ($title) { |
|
| 76 | + $sth = $this->pdo->prepare("UPDATE ttrss_settings_profiles |
|
| 77 | 77 | SET title = ? WHERE id = ? AND |
| 78 | 78 | owner_uid = ?"); |
| 79 | 79 | |
| 80 | - $sth->execute([$title, $id, $_SESSION['uid']]); |
|
| 81 | - print $title; |
|
| 82 | - } |
|
| 83 | - } |
|
| 80 | + $sth->execute([$title, $id, $_SESSION['uid']]); |
|
| 81 | + print $title; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - // Silent |
|
| 86 | - public function remarchive() { |
|
| 87 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 85 | + // Silent |
|
| 86 | + public function remarchive() { |
|
| 87 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 88 | 88 | |
| 89 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_archived_feeds WHERE |
|
| 89 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_archived_feeds WHERE |
|
| 90 | 90 | (SELECT COUNT(*) FROM ttrss_user_entries |
| 91 | 91 | WHERE orig_feed_id = :id) = 0 AND |
| 92 | 92 | id = :id AND owner_uid = :uid"); |
| 93 | 93 | |
| 94 | - foreach ($ids as $id) { |
|
| 95 | - $sth->execute([":id" => $id, ":uid" => $_SESSION['uid']]); |
|
| 96 | - } |
|
| 97 | - } |
|
| 94 | + foreach ($ids as $id) { |
|
| 95 | + $sth->execute([":id" => $id, ":uid" => $_SESSION['uid']]); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - public function addfeed() { |
|
| 100 | - $feed = clean($_REQUEST['feed']); |
|
| 101 | - $cat = clean($_REQUEST['cat']); |
|
| 102 | - $need_auth = isset($_REQUEST['need_auth']); |
|
| 103 | - $login = $need_auth ? clean($_REQUEST['login']) : ''; |
|
| 104 | - $pass = $need_auth ? trim(clean($_REQUEST['pass'])) : ''; |
|
| 99 | + public function addfeed() { |
|
| 100 | + $feed = clean($_REQUEST['feed']); |
|
| 101 | + $cat = clean($_REQUEST['cat']); |
|
| 102 | + $need_auth = isset($_REQUEST['need_auth']); |
|
| 103 | + $login = $need_auth ? clean($_REQUEST['login']) : ''; |
|
| 104 | + $pass = $need_auth ? trim(clean($_REQUEST['pass'])) : ''; |
|
| 105 | 105 | |
| 106 | - $rc = Feeds::subscribe_to_feed($feed, $cat, $login, $pass); |
|
| 106 | + $rc = Feeds::subscribe_to_feed($feed, $cat, $login, $pass); |
|
| 107 | 107 | |
| 108 | - print json_encode(array("result" => $rc)); |
|
| 109 | - } |
|
| 108 | + print json_encode(array("result" => $rc)); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - public function togglepref() { |
|
| 112 | - $key = clean($_REQUEST["key"]); |
|
| 113 | - set_pref($key, !get_pref($key)); |
|
| 114 | - $value = get_pref($key); |
|
| 111 | + public function togglepref() { |
|
| 112 | + $key = clean($_REQUEST["key"]); |
|
| 113 | + set_pref($key, !get_pref($key)); |
|
| 114 | + $value = get_pref($key); |
|
| 115 | 115 | |
| 116 | - print json_encode(array("param" =>$key, "value" => $value)); |
|
| 117 | - } |
|
| 116 | + print json_encode(array("param" =>$key, "value" => $value)); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - public function setpref() { |
|
| 120 | - // set_pref escapes input, so no need to double escape it here |
|
| 121 | - $key = clean($_REQUEST['key']); |
|
| 122 | - $value = $_REQUEST['value']; |
|
| 119 | + public function setpref() { |
|
| 120 | + // set_pref escapes input, so no need to double escape it here |
|
| 121 | + $key = clean($_REQUEST['key']); |
|
| 122 | + $value = $_REQUEST['value']; |
|
| 123 | 123 | |
| 124 | - set_pref($key, $value, false, $key != 'USER_STYLESHEET'); |
|
| 124 | + set_pref($key, $value, false, $key != 'USER_STYLESHEET'); |
|
| 125 | 125 | |
| 126 | - print json_encode(array("param" =>$key, "value" => $value)); |
|
| 127 | - } |
|
| 126 | + print json_encode(array("param" =>$key, "value" => $value)); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - public function mark() { |
|
| 130 | - $mark = clean($_REQUEST["mark"]); |
|
| 131 | - $id = clean($_REQUEST["id"]); |
|
| 129 | + public function mark() { |
|
| 130 | + $mark = clean($_REQUEST["mark"]); |
|
| 131 | + $id = clean($_REQUEST["id"]); |
|
| 132 | 132 | |
| 133 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET marked = ?, |
|
| 133 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET marked = ?, |
|
| 134 | 134 | last_marked = NOW() |
| 135 | 135 | WHERE ref_id = ? AND owner_uid = ?"); |
| 136 | 136 | |
| 137 | - $sth->execute([$mark, $id, $_SESSION['uid']]); |
|
| 137 | + $sth->execute([$mark, $id, $_SESSION['uid']]); |
|
| 138 | 138 | |
| 139 | - print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
| 140 | - } |
|
| 139 | + print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - public function delete() { |
|
| 143 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 144 | - $ids_qmarks = arr_qmarks($ids); |
|
| 142 | + public function delete() { |
|
| 143 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 144 | + $ids_qmarks = arr_qmarks($ids); |
|
| 145 | 145 | |
| 146 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_user_entries |
|
| 146 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_user_entries |
|
| 147 | 147 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
| 148 | - $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
| 148 | + $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
| 149 | 149 | |
| 150 | - Article::purge_orphans(); |
|
| 150 | + Article::purge_orphans(); |
|
| 151 | 151 | |
| 152 | - print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
| 153 | - } |
|
| 152 | + print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - public function unarchive() { |
|
| 156 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 155 | + public function unarchive() { |
|
| 156 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 157 | 157 | |
| 158 | - foreach ($ids as $id) { |
|
| 159 | - $this->pdo->beginTransaction(); |
|
| 158 | + foreach ($ids as $id) { |
|
| 159 | + $this->pdo->beginTransaction(); |
|
| 160 | 160 | |
| 161 | - $sth = $this->pdo->prepare("SELECT feed_url,site_url,title FROM ttrss_archived_feeds |
|
| 161 | + $sth = $this->pdo->prepare("SELECT feed_url,site_url,title FROM ttrss_archived_feeds |
|
| 162 | 162 | WHERE id = (SELECT orig_feed_id FROM ttrss_user_entries WHERE ref_id = :id |
| 163 | 163 | AND owner_uid = :uid) AND owner_uid = :uid"); |
| 164 | - $sth->execute([":uid" => $_SESSION['uid'], ":id" => $id]); |
|
| 164 | + $sth->execute([":uid" => $_SESSION['uid'], ":id" => $id]); |
|
| 165 | 165 | |
| 166 | - if ($row = $sth->fetch()) { |
|
| 167 | - $feed_url = $row['feed_url']; |
|
| 168 | - $site_url = $row['site_url']; |
|
| 169 | - $title = $row['title']; |
|
| 166 | + if ($row = $sth->fetch()) { |
|
| 167 | + $feed_url = $row['feed_url']; |
|
| 168 | + $site_url = $row['site_url']; |
|
| 169 | + $title = $row['title']; |
|
| 170 | 170 | |
| 171 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ? |
|
| 171 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ? |
|
| 172 | 172 | AND owner_uid = ?"); |
| 173 | - $sth->execute([$feed_url, $_SESSION['uid']]); |
|
| 173 | + $sth->execute([$feed_url, $_SESSION['uid']]); |
|
| 174 | 174 | |
| 175 | - if ($row = $sth->fetch()) { |
|
| 176 | - $feed_id = $row["id"]; |
|
| 177 | - } else { |
|
| 178 | - if (!$title) { |
|
| 179 | - $title = '[Unknown]'; |
|
| 180 | - } |
|
| 175 | + if ($row = $sth->fetch()) { |
|
| 176 | + $feed_id = $row["id"]; |
|
| 177 | + } else { |
|
| 178 | + if (!$title) { |
|
| 179 | + $title = '[Unknown]'; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
| 182 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
| 183 | 183 | (owner_uid,feed_url,site_url,title,cat_id,auth_login,auth_pass,update_method) |
| 184 | 184 | VALUES (?, ?, ?, ?, NULL, '', '', 0)"); |
| 185 | - $sth->execute([$_SESSION['uid'], $feed_url, $site_url, $title]); |
|
| 185 | + $sth->execute([$_SESSION['uid'], $feed_url, $site_url, $title]); |
|
| 186 | 186 | |
| 187 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ? |
|
| 187 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ? |
|
| 188 | 188 | AND owner_uid = ?"); |
| 189 | - $sth->execute([$feed_url, $_SESSION['uid']]); |
|
| 189 | + $sth->execute([$feed_url, $_SESSION['uid']]); |
|
| 190 | 190 | |
| 191 | - if ($row = $sth->fetch()) { |
|
| 192 | - $feed_id = $row['id']; |
|
| 193 | - } |
|
| 194 | - } |
|
| 191 | + if ($row = $sth->fetch()) { |
|
| 192 | + $feed_id = $row['id']; |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - if ($feed_id) { |
|
| 197 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries |
|
| 196 | + if ($feed_id) { |
|
| 197 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries |
|
| 198 | 198 | SET feed_id = ?, orig_feed_id = NULL |
| 199 | 199 | WHERE ref_id = ? AND owner_uid = ?"); |
| 200 | - $sth->execute([$feed_id, $id, $_SESSION['uid']]); |
|
| 201 | - } |
|
| 202 | - } |
|
| 200 | + $sth->execute([$feed_id, $id, $_SESSION['uid']]); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - $this->pdo->commit(); |
|
| 205 | - } |
|
| 204 | + $this->pdo->commit(); |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
| 208 | - } |
|
| 207 | + print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - public function archive() { |
|
| 211 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 210 | + public function archive() { |
|
| 211 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 212 | 212 | |
| 213 | - foreach ($ids as $id) { |
|
| 214 | - $this->archive_article($id, $_SESSION["uid"]); |
|
| 215 | - } |
|
| 213 | + foreach ($ids as $id) { |
|
| 214 | + $this->archive_article($id, $_SESSION["uid"]); |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
| 218 | - } |
|
| 217 | + print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - private function archive_article($id, $owner_uid) { |
|
| 221 | - $this->pdo->beginTransaction(); |
|
| 220 | + private function archive_article($id, $owner_uid) { |
|
| 221 | + $this->pdo->beginTransaction(); |
|
| 222 | 222 | |
| 223 | - if (!$owner_uid) { |
|
| 224 | - $owner_uid = $_SESSION['uid']; |
|
| 225 | - } |
|
| 223 | + if (!$owner_uid) { |
|
| 224 | + $owner_uid = $_SESSION['uid']; |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - $sth = $this->pdo->prepare("SELECT feed_id FROM ttrss_user_entries |
|
| 227 | + $sth = $this->pdo->prepare("SELECT feed_id FROM ttrss_user_entries |
|
| 228 | 228 | WHERE ref_id = ? AND owner_uid = ?"); |
| 229 | - $sth->execute([$id, $owner_uid]); |
|
| 229 | + $sth->execute([$id, $owner_uid]); |
|
| 230 | 230 | |
| 231 | - if ($row = $sth->fetch()) { |
|
| 231 | + if ($row = $sth->fetch()) { |
|
| 232 | 232 | |
| 233 | - /* prepare the archived table */ |
|
| 233 | + /* prepare the archived table */ |
|
| 234 | 234 | |
| 235 | - $feed_id = (int) $row['feed_id']; |
|
| 235 | + $feed_id = (int) $row['feed_id']; |
|
| 236 | 236 | |
| 237 | - if ($feed_id) { |
|
| 238 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_archived_feeds |
|
| 237 | + if ($feed_id) { |
|
| 238 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_archived_feeds |
|
| 239 | 239 | WHERE id = ? AND owner_uid = ?"); |
| 240 | - $sth->execute([$feed_id, $owner_uid]); |
|
| 240 | + $sth->execute([$feed_id, $owner_uid]); |
|
| 241 | 241 | |
| 242 | - if ($row = $sth->fetch()) { |
|
| 243 | - $new_feed_id = $row['id']; |
|
| 244 | - } else { |
|
| 245 | - $row = $this->pdo->query("SELECT MAX(id) AS id FROM ttrss_archived_feeds")->fetch(); |
|
| 246 | - $new_feed_id = (int) $row['id'] + 1; |
|
| 242 | + if ($row = $sth->fetch()) { |
|
| 243 | + $new_feed_id = $row['id']; |
|
| 244 | + } else { |
|
| 245 | + $row = $this->pdo->query("SELECT MAX(id) AS id FROM ttrss_archived_feeds")->fetch(); |
|
| 246 | + $new_feed_id = (int) $row['id'] + 1; |
|
| 247 | 247 | |
| 248 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_archived_feeds |
|
| 248 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_archived_feeds |
|
| 249 | 249 | (id, owner_uid, title, feed_url, site_url, created) |
| 250 | 250 | SELECT ?, owner_uid, title, feed_url, site_url, NOW() from ttrss_feeds |
| 251 | 251 | WHERE id = ?"); |
| 252 | 252 | |
| 253 | - $sth->execute([$new_feed_id, $feed_id]); |
|
| 254 | - } |
|
| 253 | + $sth->execute([$new_feed_id, $feed_id]); |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries |
|
| 256 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries |
|
| 257 | 257 | SET orig_feed_id = ?, feed_id = NULL |
| 258 | 258 | WHERE ref_id = ? AND owner_uid = ?"); |
| 259 | - $sth->execute([$new_feed_id, $id, $owner_uid]); |
|
| 260 | - } |
|
| 261 | - } |
|
| 259 | + $sth->execute([$new_feed_id, $id, $owner_uid]); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - $this->pdo->commit(); |
|
| 264 | - } |
|
| 263 | + $this->pdo->commit(); |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - public function publ() { |
|
| 267 | - $pub = clean($_REQUEST["pub"]); |
|
| 268 | - $id = clean($_REQUEST["id"]); |
|
| 266 | + public function publ() { |
|
| 267 | + $pub = clean($_REQUEST["pub"]); |
|
| 268 | + $id = clean($_REQUEST["id"]); |
|
| 269 | 269 | |
| 270 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 270 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 271 | 271 | published = ?, last_published = NOW() |
| 272 | 272 | WHERE ref_id = ? AND owner_uid = ?"); |
| 273 | 273 | |
| 274 | - $sth->execute([$pub, $id, $_SESSION['uid']]); |
|
| 274 | + $sth->execute([$pub, $id, $_SESSION['uid']]); |
|
| 275 | 275 | |
| 276 | - print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
| 277 | - } |
|
| 276 | + print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - public function getAllCounters() { |
|
| 280 | - @$seq = (int) $_REQUEST['seq']; |
|
| 279 | + public function getAllCounters() { |
|
| 280 | + @$seq = (int) $_REQUEST['seq']; |
|
| 281 | 281 | |
| 282 | - $reply = [ |
|
| 283 | - 'counters' => Counters::getAllCounters(), |
|
| 284 | - 'seq' => $seq |
|
| 285 | - ]; |
|
| 282 | + $reply = [ |
|
| 283 | + 'counters' => Counters::getAllCounters(), |
|
| 284 | + 'seq' => $seq |
|
| 285 | + ]; |
|
| 286 | 286 | |
| 287 | - if ($seq % 2 == 0) { |
|
| 288 | - $reply['runtime-info'] = make_runtime_info(); |
|
| 289 | - } |
|
| 287 | + if ($seq % 2 == 0) { |
|
| 288 | + $reply['runtime-info'] = make_runtime_info(); |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - print json_encode($reply); |
|
| 292 | - } |
|
| 291 | + print json_encode($reply); |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ |
|
| 295 | - public function catchupSelected() { |
|
| 296 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 297 | - $cmode = (int) clean($_REQUEST["cmode"]); |
|
| 294 | + /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ |
|
| 295 | + public function catchupSelected() { |
|
| 296 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 297 | + $cmode = (int) clean($_REQUEST["cmode"]); |
|
| 298 | 298 | |
| 299 | - Article::catchupArticlesById($ids, $cmode); |
|
| 299 | + Article::catchupArticlesById($ids, $cmode); |
|
| 300 | 300 | |
| 301 | - print json_encode(array("message" => "UPDATE_COUNTERS", "ids" => $ids)); |
|
| 302 | - } |
|
| 301 | + print json_encode(array("message" => "UPDATE_COUNTERS", "ids" => $ids)); |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | - public function markSelected() { |
|
| 305 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 306 | - $cmode = (int) clean($_REQUEST["cmode"]); |
|
| 304 | + public function markSelected() { |
|
| 305 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 306 | + $cmode = (int) clean($_REQUEST["cmode"]); |
|
| 307 | 307 | |
| 308 | - $this->markArticlesById($ids, $cmode); |
|
| 308 | + $this->markArticlesById($ids, $cmode); |
|
| 309 | 309 | |
| 310 | - print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
| 311 | - } |
|
| 310 | + print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - public function publishSelected() { |
|
| 314 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 315 | - $cmode = (int) clean($_REQUEST["cmode"]); |
|
| 313 | + public function publishSelected() { |
|
| 314 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 315 | + $cmode = (int) clean($_REQUEST["cmode"]); |
|
| 316 | 316 | |
| 317 | - $this->publishArticlesById($ids, $cmode); |
|
| 317 | + $this->publishArticlesById($ids, $cmode); |
|
| 318 | 318 | |
| 319 | - print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
| 320 | - } |
|
| 319 | + print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | - public function sanityCheck() { |
|
| 323 | - $_SESSION["hasAudio"] = clean($_REQUEST["hasAudio"]) === "true"; |
|
| 324 | - $_SESSION["hasSandbox"] = clean($_REQUEST["hasSandbox"]) === "true"; |
|
| 325 | - $_SESSION["hasMp3"] = clean($_REQUEST["hasMp3"]) === "true"; |
|
| 326 | - $_SESSION["clientTzOffset"] = clean($_REQUEST["clientTzOffset"]); |
|
| 322 | + public function sanityCheck() { |
|
| 323 | + $_SESSION["hasAudio"] = clean($_REQUEST["hasAudio"]) === "true"; |
|
| 324 | + $_SESSION["hasSandbox"] = clean($_REQUEST["hasSandbox"]) === "true"; |
|
| 325 | + $_SESSION["hasMp3"] = clean($_REQUEST["hasMp3"]) === "true"; |
|
| 326 | + $_SESSION["clientTzOffset"] = clean($_REQUEST["clientTzOffset"]); |
|
| 327 | 327 | |
| 328 | - $reply = array(); |
|
| 328 | + $reply = array(); |
|
| 329 | 329 | |
| 330 | - $reply['error'] = sanity_check(); |
|
| 330 | + $reply['error'] = sanity_check(); |
|
| 331 | 331 | |
| 332 | - if ($reply['error']['code'] == 0) { |
|
| 333 | - $reply['init-params'] = make_init_params(); |
|
| 334 | - $reply['runtime-info'] = make_runtime_info(); |
|
| 335 | - } |
|
| 332 | + if ($reply['error']['code'] == 0) { |
|
| 333 | + $reply['init-params'] = make_init_params(); |
|
| 334 | + $reply['runtime-info'] = make_runtime_info(); |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | - print json_encode($reply); |
|
| 338 | - } |
|
| 337 | + print json_encode($reply); |
|
| 338 | + } |
|
| 339 | 339 | |
| 340 | - public function completeLabels() { |
|
| 341 | - $search = clean($_REQUEST["search"]); |
|
| 340 | + public function completeLabels() { |
|
| 341 | + $search = clean($_REQUEST["search"]); |
|
| 342 | 342 | |
| 343 | - $sth = $this->pdo->prepare("SELECT DISTINCT caption FROM |
|
| 343 | + $sth = $this->pdo->prepare("SELECT DISTINCT caption FROM |
|
| 344 | 344 | ttrss_labels2 |
| 345 | 345 | WHERE owner_uid = ? AND |
| 346 | 346 | LOWER(caption) LIKE LOWER(?) ORDER BY caption |
| 347 | 347 | LIMIT 5"); |
| 348 | - $sth->execute([$_SESSION['uid'], "%$search%"]); |
|
| 348 | + $sth->execute([$_SESSION['uid'], "%$search%"]); |
|
| 349 | 349 | |
| 350 | - print "<ul>"; |
|
| 351 | - while ($line = $sth->fetch()) { |
|
| 352 | - print "<li>".$line["caption"]."</li>"; |
|
| 353 | - } |
|
| 354 | - print "</ul>"; |
|
| 355 | - } |
|
| 350 | + print "<ul>"; |
|
| 351 | + while ($line = $sth->fetch()) { |
|
| 352 | + print "<li>".$line["caption"]."</li>"; |
|
| 353 | + } |
|
| 354 | + print "</ul>"; |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | - // Silent |
|
| 358 | - public function massSubscribe() { |
|
| 357 | + // Silent |
|
| 358 | + public function massSubscribe() { |
|
| 359 | 359 | |
| 360 | - $payload = json_decode(clean($_REQUEST["payload"]), false); |
|
| 361 | - $mode = clean($_REQUEST["mode"]); |
|
| 360 | + $payload = json_decode(clean($_REQUEST["payload"]), false); |
|
| 361 | + $mode = clean($_REQUEST["mode"]); |
|
| 362 | 362 | |
| 363 | - if (!$payload || !is_array($payload)) { |
|
| 364 | - return; |
|
| 365 | - } |
|
| 363 | + if (!$payload || !is_array($payload)) { |
|
| 364 | + return; |
|
| 365 | + } |
|
| 366 | 366 | |
| 367 | - if ($mode == 1) { |
|
| 368 | - foreach ($payload as $feed) { |
|
| 367 | + if ($mode == 1) { |
|
| 368 | + foreach ($payload as $feed) { |
|
| 369 | 369 | |
| 370 | - $title = $feed[0]; |
|
| 371 | - $feed_url = $feed[1]; |
|
| 370 | + $title = $feed[0]; |
|
| 371 | + $feed_url = $feed[1]; |
|
| 372 | 372 | |
| 373 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
| 373 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
| 374 | 374 | feed_url = ? AND owner_uid = ?"); |
| 375 | - $sth->execute([$feed_url, $_SESSION['uid']]); |
|
| 375 | + $sth->execute([$feed_url, $_SESSION['uid']]); |
|
| 376 | 376 | |
| 377 | - if (!$sth->fetch()) { |
|
| 378 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
| 377 | + if (!$sth->fetch()) { |
|
| 378 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
| 379 | 379 | (owner_uid,feed_url,title,cat_id,site_url) |
| 380 | 380 | VALUES (?, ?, ?, NULL, '')"); |
| 381 | 381 | |
| 382 | - $sth->execute([$_SESSION['uid'], $feed_url, $title]); |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - } else if ($mode == 2) { |
|
| 386 | - // feed archive |
|
| 387 | - foreach ($payload as $id) { |
|
| 388 | - $sth = $this->pdo->prepare("SELECT * FROM ttrss_archived_feeds |
|
| 382 | + $sth->execute([$_SESSION['uid'], $feed_url, $title]); |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + } else if ($mode == 2) { |
|
| 386 | + // feed archive |
|
| 387 | + foreach ($payload as $id) { |
|
| 388 | + $sth = $this->pdo->prepare("SELECT * FROM ttrss_archived_feeds |
|
| 389 | 389 | WHERE id = ? AND owner_uid = ?"); |
| 390 | - $sth->execute([$id, $_SESSION['uid']]); |
|
| 390 | + $sth->execute([$id, $_SESSION['uid']]); |
|
| 391 | 391 | |
| 392 | - if ($row = $sth->fetch()) { |
|
| 393 | - $site_url = $row['site_url']; |
|
| 394 | - $feed_url = $row['feed_url']; |
|
| 395 | - $title = $row['title']; |
|
| 392 | + if ($row = $sth->fetch()) { |
|
| 393 | + $site_url = $row['site_url']; |
|
| 394 | + $feed_url = $row['feed_url']; |
|
| 395 | + $title = $row['title']; |
|
| 396 | 396 | |
| 397 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
| 397 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
| 398 | 398 | feed_url = ? AND owner_uid = ?"); |
| 399 | - $sth->execute([$feed_url, $_SESSION['uid']]); |
|
| 399 | + $sth->execute([$feed_url, $_SESSION['uid']]); |
|
| 400 | 400 | |
| 401 | - if (!$sth->fetch()) { |
|
| 402 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
| 401 | + if (!$sth->fetch()) { |
|
| 402 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
| 403 | 403 | (owner_uid,feed_url,title,cat_id,site_url) |
| 404 | 404 | VALUES (?, ?, ?, NULL, ?)"); |
| 405 | 405 | |
| 406 | - $sth->execute([$_SESSION['uid'], $feed_url, $title, $site_url]); |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - } |
|
| 406 | + $sth->execute([$_SESSION['uid'], $feed_url, $title, $site_url]); |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | 412 | |
| 413 | - public function catchupFeed() { |
|
| 414 | - $feed_id = clean($_REQUEST['feed_id']); |
|
| 415 | - $is_cat = clean($_REQUEST['is_cat']) == "true"; |
|
| 416 | - $mode = clean($_REQUEST['mode']); |
|
| 417 | - $search_query = clean($_REQUEST['search_query']); |
|
| 418 | - $search_lang = clean($_REQUEST['search_lang']); |
|
| 413 | + public function catchupFeed() { |
|
| 414 | + $feed_id = clean($_REQUEST['feed_id']); |
|
| 415 | + $is_cat = clean($_REQUEST['is_cat']) == "true"; |
|
| 416 | + $mode = clean($_REQUEST['mode']); |
|
| 417 | + $search_query = clean($_REQUEST['search_query']); |
|
| 418 | + $search_lang = clean($_REQUEST['search_lang']); |
|
| 419 | 419 | |
| 420 | - Feeds::catchup_feed($feed_id, $is_cat, false, $mode, [$search_query, $search_lang]); |
|
| 420 | + Feeds::catchup_feed($feed_id, $is_cat, false, $mode, [$search_query, $search_lang]); |
|
| 421 | 421 | |
| 422 | - // return counters here synchronously so that frontend can figure out next unread feed properly |
|
| 423 | - print json_encode(['counters' => Counters::getAllCounters()]); |
|
| 422 | + // return counters here synchronously so that frontend can figure out next unread feed properly |
|
| 423 | + print json_encode(['counters' => Counters::getAllCounters()]); |
|
| 424 | 424 | |
| 425 | - //print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
| 426 | - } |
|
| 425 | + //print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
| 426 | + } |
|
| 427 | 427 | |
| 428 | - public function setpanelmode() { |
|
| 429 | - $wide = (int) clean($_REQUEST["wide"]); |
|
| 428 | + public function setpanelmode() { |
|
| 429 | + $wide = (int) clean($_REQUEST["wide"]); |
|
| 430 | 430 | |
| 431 | - setcookie("ttrss_widescreen", $wide, |
|
| 432 | - time() + COOKIE_LIFETIME_LONG); |
|
| 431 | + setcookie("ttrss_widescreen", $wide, |
|
| 432 | + time() + COOKIE_LIFETIME_LONG); |
|
| 433 | 433 | |
| 434 | - print json_encode(array("wide" => $wide)); |
|
| 435 | - } |
|
| 434 | + print json_encode(array("wide" => $wide)); |
|
| 435 | + } |
|
| 436 | 436 | |
| 437 | - public static function updaterandomfeed_real() { |
|
| 437 | + public static function updaterandomfeed_real() { |
|
| 438 | 438 | |
| 439 | - // Test if the feed need a update (update interval exceded). |
|
| 440 | - if (DB_TYPE == "pgsql") { |
|
| 441 | - $update_limit_qpart = "AND (( |
|
| 439 | + // Test if the feed need a update (update interval exceded). |
|
| 440 | + if (DB_TYPE == "pgsql") { |
|
| 441 | + $update_limit_qpart = "AND (( |
|
| 442 | 442 | ttrss_feeds.update_interval = 0 |
| 443 | 443 | AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL) |
| 444 | 444 | ) OR ( |
@@ -446,8 +446,8 @@ discard block |
||
| 446 | 446 | AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL) |
| 447 | 447 | ) OR ttrss_feeds.last_updated IS NULL |
| 448 | 448 | OR last_updated = '1970-01-01 00:00:00')"; |
| 449 | - } else { |
|
| 450 | - $update_limit_qpart = "AND (( |
|
| 449 | + } else { |
|
| 450 | + $update_limit_qpart = "AND (( |
|
| 451 | 451 | ttrss_feeds.update_interval = 0 |
| 452 | 452 | AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE) |
| 453 | 453 | ) OR ( |
@@ -455,28 +455,28 @@ discard block |
||
| 455 | 455 | AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE) |
| 456 | 456 | ) OR ttrss_feeds.last_updated IS NULL |
| 457 | 457 | OR last_updated = '1970-01-01 00:00:00')"; |
| 458 | - } |
|
| 458 | + } |
|
| 459 | 459 | |
| 460 | - // Test if feed is currently being updated by another process. |
|
| 461 | - if (DB_TYPE == "pgsql") { |
|
| 462 | - $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')"; |
|
| 463 | - } else { |
|
| 464 | - $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))"; |
|
| 465 | - } |
|
| 460 | + // Test if feed is currently being updated by another process. |
|
| 461 | + if (DB_TYPE == "pgsql") { |
|
| 462 | + $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')"; |
|
| 463 | + } else { |
|
| 464 | + $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))"; |
|
| 465 | + } |
|
| 466 | 466 | |
| 467 | - $random_qpart = sql_random_function(); |
|
| 467 | + $random_qpart = sql_random_function(); |
|
| 468 | 468 | |
| 469 | - $pdo = Db::pdo(); |
|
| 469 | + $pdo = Db::pdo(); |
|
| 470 | 470 | |
| 471 | - // we could be invoked from public.php with no active session |
|
| 472 | - if ($_SESSION["uid"]) { |
|
| 473 | - $owner_check_qpart = "AND ttrss_feeds.owner_uid = ".$pdo->quote($_SESSION["uid"]); |
|
| 474 | - } else { |
|
| 475 | - $owner_check_qpart = ""; |
|
| 476 | - } |
|
| 471 | + // we could be invoked from public.php with no active session |
|
| 472 | + if ($_SESSION["uid"]) { |
|
| 473 | + $owner_check_qpart = "AND ttrss_feeds.owner_uid = ".$pdo->quote($_SESSION["uid"]); |
|
| 474 | + } else { |
|
| 475 | + $owner_check_qpart = ""; |
|
| 476 | + } |
|
| 477 | 477 | |
| 478 | - // We search for feed needing update. |
|
| 479 | - $res = $pdo->query("SELECT ttrss_feeds.feed_url,ttrss_feeds.id |
|
| 478 | + // We search for feed needing update. |
|
| 479 | + $res = $pdo->query("SELECT ttrss_feeds.feed_url,ttrss_feeds.id |
|
| 480 | 480 | FROM |
| 481 | 481 | ttrss_feeds, ttrss_users, ttrss_user_prefs |
| 482 | 482 | WHERE |
@@ -488,139 +488,139 @@ discard block |
||
| 488 | 488 | $updstart_thresh_qpart |
| 489 | 489 | ORDER BY $random_qpart LIMIT 30"); |
| 490 | 490 | |
| 491 | - $num_updated = 0; |
|
| 491 | + $num_updated = 0; |
|
| 492 | 492 | |
| 493 | - $tstart = time(); |
|
| 493 | + $tstart = time(); |
|
| 494 | 494 | |
| 495 | - while ($line = $res->fetch()) { |
|
| 496 | - $feed_id = $line["id"]; |
|
| 495 | + while ($line = $res->fetch()) { |
|
| 496 | + $feed_id = $line["id"]; |
|
| 497 | 497 | |
| 498 | - if (time() - $tstart < ini_get("max_execution_time") * 0.7) { |
|
| 499 | - RSSUtils::update_rss_feed($feed_id, true); |
|
| 500 | - ++$num_updated; |
|
| 501 | - } else { |
|
| 502 | - break; |
|
| 503 | - } |
|
| 504 | - } |
|
| 498 | + if (time() - $tstart < ini_get("max_execution_time") * 0.7) { |
|
| 499 | + RSSUtils::update_rss_feed($feed_id, true); |
|
| 500 | + ++$num_updated; |
|
| 501 | + } else { |
|
| 502 | + break; |
|
| 503 | + } |
|
| 504 | + } |
|
| 505 | 505 | |
| 506 | - // Purge orphans and cleanup tags |
|
| 507 | - Article::purge_orphans(); |
|
| 508 | - //cleanup_tags(14, 50000); |
|
| 506 | + // Purge orphans and cleanup tags |
|
| 507 | + Article::purge_orphans(); |
|
| 508 | + //cleanup_tags(14, 50000); |
|
| 509 | 509 | |
| 510 | - if ($num_updated > 0) { |
|
| 511 | - print json_encode(array("message" => "UPDATE_COUNTERS", |
|
| 512 | - "num_updated" => $num_updated)); |
|
| 513 | - } else { |
|
| 514 | - print json_encode(array("message" => "NOTHING_TO_UPDATE")); |
|
| 515 | - } |
|
| 510 | + if ($num_updated > 0) { |
|
| 511 | + print json_encode(array("message" => "UPDATE_COUNTERS", |
|
| 512 | + "num_updated" => $num_updated)); |
|
| 513 | + } else { |
|
| 514 | + print json_encode(array("message" => "NOTHING_TO_UPDATE")); |
|
| 515 | + } |
|
| 516 | 516 | |
| 517 | - } |
|
| 517 | + } |
|
| 518 | 518 | |
| 519 | - public function updaterandomfeed() { |
|
| 520 | - RPC::updaterandomfeed_real(); |
|
| 521 | - } |
|
| 519 | + public function updaterandomfeed() { |
|
| 520 | + RPC::updaterandomfeed_real(); |
|
| 521 | + } |
|
| 522 | 522 | |
| 523 | - private function markArticlesById($ids, $cmode) { |
|
| 523 | + private function markArticlesById($ids, $cmode) { |
|
| 524 | 524 | |
| 525 | - $ids_qmarks = arr_qmarks($ids); |
|
| 525 | + $ids_qmarks = arr_qmarks($ids); |
|
| 526 | 526 | |
| 527 | - if ($cmode == 0) { |
|
| 528 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 527 | + if ($cmode == 0) { |
|
| 528 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 529 | 529 | marked = false, last_marked = NOW() |
| 530 | 530 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
| 531 | - } else if ($cmode == 1) { |
|
| 532 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 531 | + } else if ($cmode == 1) { |
|
| 532 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 533 | 533 | marked = true, last_marked = NOW() |
| 534 | 534 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
| 535 | - } else { |
|
| 536 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 535 | + } else { |
|
| 536 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 537 | 537 | marked = NOT marked,last_marked = NOW() |
| 538 | 538 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
| 539 | - } |
|
| 539 | + } |
|
| 540 | 540 | |
| 541 | - $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
| 542 | - } |
|
| 541 | + $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
| 542 | + } |
|
| 543 | 543 | |
| 544 | - private function publishArticlesById($ids, $cmode) { |
|
| 544 | + private function publishArticlesById($ids, $cmode) { |
|
| 545 | 545 | |
| 546 | - $ids_qmarks = arr_qmarks($ids); |
|
| 546 | + $ids_qmarks = arr_qmarks($ids); |
|
| 547 | 547 | |
| 548 | - if ($cmode == 0) { |
|
| 549 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 548 | + if ($cmode == 0) { |
|
| 549 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 550 | 550 | published = false, last_published = NOW() |
| 551 | 551 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
| 552 | - } else if ($cmode == 1) { |
|
| 553 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 552 | + } else if ($cmode == 1) { |
|
| 553 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 554 | 554 | published = true, last_published = NOW() |
| 555 | 555 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
| 556 | - } else { |
|
| 557 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 556 | + } else { |
|
| 557 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 558 | 558 | published = NOT published,last_published = NOW() |
| 559 | 559 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
| 560 | - } |
|
| 560 | + } |
|
| 561 | 561 | |
| 562 | - $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
| 563 | - } |
|
| 562 | + $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
| 563 | + } |
|
| 564 | 564 | |
| 565 | - public function getlinktitlebyid() { |
|
| 566 | - $id = clean($_REQUEST['id']); |
|
| 565 | + public function getlinktitlebyid() { |
|
| 566 | + $id = clean($_REQUEST['id']); |
|
| 567 | 567 | |
| 568 | - $sth = $this->pdo->prepare("SELECT link, title FROM ttrss_entries, ttrss_user_entries |
|
| 568 | + $sth = $this->pdo->prepare("SELECT link, title FROM ttrss_entries, ttrss_user_entries |
|
| 569 | 569 | WHERE ref_id = ? AND ref_id = id AND owner_uid = ?"); |
| 570 | - $sth->execute([$id, $_SESSION['uid']]); |
|
| 570 | + $sth->execute([$id, $_SESSION['uid']]); |
|
| 571 | 571 | |
| 572 | - if ($row = $sth->fetch()) { |
|
| 573 | - $link = $row['link']; |
|
| 574 | - $title = $row['title']; |
|
| 572 | + if ($row = $sth->fetch()) { |
|
| 573 | + $link = $row['link']; |
|
| 574 | + $title = $row['title']; |
|
| 575 | 575 | |
| 576 | - echo json_encode(array("link" => $link, "title" => $title)); |
|
| 577 | - } else { |
|
| 578 | - echo json_encode(array("error" => "ARTICLE_NOT_FOUND")); |
|
| 579 | - } |
|
| 580 | - } |
|
| 576 | + echo json_encode(array("link" => $link, "title" => $title)); |
|
| 577 | + } else { |
|
| 578 | + echo json_encode(array("error" => "ARTICLE_NOT_FOUND")); |
|
| 579 | + } |
|
| 580 | + } |
|
| 581 | 581 | |
| 582 | - public function log() { |
|
| 583 | - $msg = clean($_REQUEST['msg']); |
|
| 584 | - $file = clean_filename($_REQUEST['file']); |
|
| 585 | - $line = (int) clean($_REQUEST['line']); |
|
| 586 | - $context = clean($_REQUEST['context']); |
|
| 582 | + public function log() { |
|
| 583 | + $msg = clean($_REQUEST['msg']); |
|
| 584 | + $file = clean_filename($_REQUEST['file']); |
|
| 585 | + $line = (int) clean($_REQUEST['line']); |
|
| 586 | + $context = clean($_REQUEST['context']); |
|
| 587 | 587 | |
| 588 | - if ($msg) { |
|
| 589 | - Logger::get()->log_error(E_USER_WARNING, |
|
| 590 | - $msg, 'client-js:'.$file, $line, $context); |
|
| 588 | + if ($msg) { |
|
| 589 | + Logger::get()->log_error(E_USER_WARNING, |
|
| 590 | + $msg, 'client-js:'.$file, $line, $context); |
|
| 591 | 591 | |
| 592 | - echo json_encode(array("message" => "HOST_ERROR_LOGGED")); |
|
| 593 | - } else { |
|
| 594 | - echo json_encode(array("error" => "MESSAGE_NOT_FOUND")); |
|
| 595 | - } |
|
| 592 | + echo json_encode(array("message" => "HOST_ERROR_LOGGED")); |
|
| 593 | + } else { |
|
| 594 | + echo json_encode(array("error" => "MESSAGE_NOT_FOUND")); |
|
| 595 | + } |
|
| 596 | 596 | |
| 597 | - } |
|
| 597 | + } |
|
| 598 | 598 | |
| 599 | - public function checkforupdates() { |
|
| 600 | - $rv = []; |
|
| 599 | + public function checkforupdates() { |
|
| 600 | + $rv = []; |
|
| 601 | 601 | |
| 602 | - $git_timestamp = false; |
|
| 603 | - $git_commit = false; |
|
| 602 | + $git_timestamp = false; |
|
| 603 | + $git_commit = false; |
|
| 604 | 604 | |
| 605 | - get_version($git_commit, $git_timestamp); |
|
| 605 | + get_version($git_commit, $git_timestamp); |
|
| 606 | 606 | |
| 607 | - if (CHECK_FOR_UPDATES && $_SESSION["access_level"] >= 10 && $git_timestamp) { |
|
| 608 | - $content = @fetch_file_contents(["url" => "https://srv.tt-rss.org/version.json"]); |
|
| 607 | + if (CHECK_FOR_UPDATES && $_SESSION["access_level"] >= 10 && $git_timestamp) { |
|
| 608 | + $content = @fetch_file_contents(["url" => "https://srv.tt-rss.org/version.json"]); |
|
| 609 | 609 | |
| 610 | - if ($content) { |
|
| 611 | - $content = json_decode($content, true); |
|
| 610 | + if ($content) { |
|
| 611 | + $content = json_decode($content, true); |
|
| 612 | 612 | |
| 613 | - if ($content && isset($content["changeset"])) { |
|
| 614 | - if ($git_timestamp < (int) $content["changeset"]["timestamp"] && |
|
| 615 | - $git_commit != $content["changeset"]["id"]) { |
|
| 613 | + if ($content && isset($content["changeset"])) { |
|
| 614 | + if ($git_timestamp < (int) $content["changeset"]["timestamp"] && |
|
| 615 | + $git_commit != $content["changeset"]["id"]) { |
|
| 616 | 616 | |
| 617 | - $rv = $content["changeset"]; |
|
| 618 | - } |
|
| 619 | - } |
|
| 620 | - } |
|
| 621 | - } |
|
| 617 | + $rv = $content["changeset"]; |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + } |
|
| 621 | + } |
|
| 622 | 622 | |
| 623 | - print json_encode($rv); |
|
| 624 | - } |
|
| 623 | + print json_encode($rv); |
|
| 624 | + } |
|
| 625 | 625 | |
| 626 | 626 | } |
@@ -1,33 +1,33 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | class Logger_Syslog { |
| 3 | 3 | |
| 4 | - /** |
|
| 5 | - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
| 6 | - */ |
|
| 7 | - public function log_error($errno, $errstr, $file, $line, $context) { |
|
| 4 | + /** |
|
| 5 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
| 6 | + */ |
|
| 7 | + public function log_error($errno, $errstr, $file, $line, $context) { |
|
| 8 | 8 | |
| 9 | - switch ($errno) { |
|
| 10 | - case E_ERROR: |
|
| 11 | - case E_PARSE: |
|
| 12 | - case E_CORE_ERROR: |
|
| 13 | - case E_COMPILE_ERROR: |
|
| 14 | - case E_USER_ERROR: |
|
| 15 | - $priority = LOG_ERR; |
|
| 16 | - break; |
|
| 17 | - case E_WARNING: |
|
| 18 | - case E_CORE_WARNING: |
|
| 19 | - case E_COMPILE_WARNING: |
|
| 20 | - case E_USER_WARNING: |
|
| 21 | - $priority = LOG_WARNING; |
|
| 22 | - break; |
|
| 23 | - default: |
|
| 24 | - $priority = LOG_INFO; |
|
| 25 | - } |
|
| 9 | + switch ($errno) { |
|
| 10 | + case E_ERROR: |
|
| 11 | + case E_PARSE: |
|
| 12 | + case E_CORE_ERROR: |
|
| 13 | + case E_COMPILE_ERROR: |
|
| 14 | + case E_USER_ERROR: |
|
| 15 | + $priority = LOG_ERR; |
|
| 16 | + break; |
|
| 17 | + case E_WARNING: |
|
| 18 | + case E_CORE_WARNING: |
|
| 19 | + case E_COMPILE_WARNING: |
|
| 20 | + case E_USER_WARNING: |
|
| 21 | + $priority = LOG_WARNING; |
|
| 22 | + break; |
|
| 23 | + default: |
|
| 24 | + $priority = LOG_INFO; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - $errname = Logger::$errornames[$errno]." ($errno)"; |
|
| 27 | + $errname = Logger::$errornames[$errno]." ($errno)"; |
|
| 28 | 28 | |
| 29 | - syslog($priority, "[tt-rss] $errname ($file:$line) $errstr"); |
|
| 29 | + syslog($priority, "[tt-rss] $errname ($file:$line) $errstr"); |
|
| 30 | 30 | |
| 31 | - } |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | 33 | } |
@@ -1,545 +1,545 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | class PluginHost { |
| 3 | - private $pdo; |
|
| 4 | - private $hooks = array(); |
|
| 5 | - private $plugins = array(); |
|
| 6 | - private $handlers = array(); |
|
| 7 | - private $commands = array(); |
|
| 8 | - private $storage = array(); |
|
| 9 | - private $feeds = array(); |
|
| 10 | - private $api_methods = array(); |
|
| 11 | - private $plugin_actions = array(); |
|
| 12 | - private $owner_uid; |
|
| 13 | - private $last_registered; |
|
| 14 | - private static $instance; |
|
| 15 | - |
|
| 16 | - const API_VERSION = 2; |
|
| 17 | - |
|
| 18 | - // Hooks marked with *1 are run in global context and available |
|
| 19 | - // to plugins loaded in config.php only |
|
| 20 | - |
|
| 21 | - const HOOK_ARTICLE_BUTTON = 1; |
|
| 22 | - const HOOK_ARTICLE_FILTER = 2; |
|
| 23 | - const HOOK_PREFS_TAB = 3; |
|
| 24 | - const HOOK_PREFS_TAB_SECTION = 4; |
|
| 25 | - const HOOK_PREFS_TABS = 5; |
|
| 26 | - const HOOK_FEED_PARSED = 6; |
|
| 27 | - const HOOK_UPDATE_TASK = 7; // *1 |
|
| 28 | - const HOOK_AUTH_USER = 8; |
|
| 29 | - const HOOK_HOTKEY_MAP = 9; |
|
| 30 | - const HOOK_RENDER_ARTICLE = 10; |
|
| 31 | - const HOOK_RENDER_ARTICLE_CDM = 11; |
|
| 32 | - const HOOK_FEED_FETCHED = 12; |
|
| 33 | - const HOOK_SANITIZE = 13; |
|
| 34 | - const HOOK_RENDER_ARTICLE_API = 14; |
|
| 35 | - const HOOK_TOOLBAR_BUTTON = 15; |
|
| 36 | - const HOOK_ACTION_ITEM = 16; |
|
| 37 | - const HOOK_HEADLINE_TOOLBAR_BUTTON = 17; |
|
| 38 | - const HOOK_HOTKEY_INFO = 18; |
|
| 39 | - const HOOK_ARTICLE_LEFT_BUTTON = 19; |
|
| 40 | - const HOOK_PREFS_EDIT_FEED = 20; |
|
| 41 | - const HOOK_PREFS_SAVE_FEED = 21; |
|
| 42 | - const HOOK_FETCH_FEED = 22; |
|
| 43 | - const HOOK_QUERY_HEADLINES = 23; |
|
| 44 | - const HOOK_HOUSE_KEEPING = 24; // *1 |
|
| 45 | - const HOOK_SEARCH = 25; |
|
| 46 | - const HOOK_FORMAT_ENCLOSURES = 26; |
|
| 47 | - const HOOK_SUBSCRIBE_FEED = 27; |
|
| 48 | - const HOOK_HEADLINES_BEFORE = 28; |
|
| 49 | - const HOOK_RENDER_ENCLOSURE = 29; |
|
| 50 | - const HOOK_ARTICLE_FILTER_ACTION = 30; |
|
| 51 | - const HOOK_ARTICLE_EXPORT_FEED = 31; |
|
| 52 | - const HOOK_MAIN_TOOLBAR_BUTTON = 32; |
|
| 53 | - const HOOK_ENCLOSURE_ENTRY = 33; |
|
| 54 | - const HOOK_FORMAT_ARTICLE = 34; |
|
| 55 | - const HOOK_FORMAT_ARTICLE_CDM = 35; /* RIP */ |
|
| 56 | - const HOOK_FEED_BASIC_INFO = 36; |
|
| 57 | - const HOOK_SEND_LOCAL_FILE = 37; |
|
| 58 | - const HOOK_UNSUBSCRIBE_FEED = 38; |
|
| 59 | - const HOOK_SEND_MAIL = 39; |
|
| 60 | - const HOOK_FILTER_TRIGGERED = 40; |
|
| 61 | - const HOOK_GET_FULL_TEXT = 41; |
|
| 62 | - const HOOK_ARTICLE_IMAGE = 42; |
|
| 63 | - const HOOK_FEED_TREE = 43; |
|
| 64 | - const HOOK_IFRAME_WHITELISTED = 44; |
|
| 65 | - |
|
| 66 | - const KIND_ALL = 1; |
|
| 67 | - const KIND_SYSTEM = 2; |
|
| 68 | - const KIND_USER = 3; |
|
| 69 | - |
|
| 70 | - public static function object_to_domain($plugin) { |
|
| 71 | - return strtolower(get_class($plugin)); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - public function __construct() { |
|
| 75 | - $this->pdo = Db::pdo(); |
|
| 76 | - |
|
| 77 | - $this->storage = array(); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - private function __clone() { |
|
| 81 | - // |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - public static function getInstance() { |
|
| 85 | - if (self::$instance == null) { |
|
| 86 | - self::$instance = new self(); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - return self::$instance; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - private function register_plugin($name, $plugin) { |
|
| 93 | - //array_push($this->plugins, $plugin); |
|
| 94 | - $this->plugins[$name] = $plugin; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // needed for compatibility with API 1 |
|
| 98 | - public function get_link() { |
|
| 99 | - return false; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - public function get_dbh() { |
|
| 103 | - return Db::get(); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - public function get_pdo() { |
|
| 107 | - return $this->pdo; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - public function get_plugin_names() { |
|
| 111 | - $names = array(); |
|
| 112 | - |
|
| 113 | - foreach ($this->plugins as $p) { |
|
| 114 | - array_push($names, get_class($p)); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return $names; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - public function get_plugins() { |
|
| 121 | - return $this->plugins; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - public function get_plugin($name) { |
|
| 125 | - return $this->plugins[strtolower($name)]; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function run_hooks($type, $method, $args) { |
|
| 129 | - foreach ($this->get_hooks($type) as $hook) { |
|
| 130 | - $hook->$method($args); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - public function add_hook($type, $sender, $priority = 50) { |
|
| 135 | - $priority = (int) $priority; |
|
| 136 | - |
|
| 137 | - if (!is_array($this->hooks[$type])) { |
|
| 138 | - $this->hooks[$type] = []; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - if (!is_array($this->hooks[$type][$priority])) { |
|
| 142 | - $this->hooks[$type][$priority] = []; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - array_push($this->hooks[$type][$priority], $sender); |
|
| 146 | - ksort($this->hooks[$type]); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - public function del_hook($type, $sender) { |
|
| 150 | - if (is_array($this->hooks[$type])) { |
|
| 151 | - foreach (array_keys($this->hooks[$type]) as $prio) { |
|
| 152 | - $key = array_search($sender, $this->hooks[$type][$prio]); |
|
| 153 | - |
|
| 154 | - if ($key !== false) { |
|
| 155 | - unset($this->hooks[$type][$prio][$key]); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - public function get_hooks($type) { |
|
| 162 | - if (isset($this->hooks[$type])) { |
|
| 163 | - $tmp = []; |
|
| 164 | - |
|
| 165 | - foreach (array_keys($this->hooks[$type]) as $prio) { |
|
| 166 | - $tmp = array_merge($tmp, $this->hooks[$type][$prio]); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - return $tmp; |
|
| 170 | - } else { |
|
| 171 | - return []; |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - public function load_all($kind, $owner_uid = false, $skip_init = false) { |
|
| 175 | - |
|
| 176 | - $plugins = array_merge(glob("plugins/*"), glob("plugins.local/*")); |
|
| 177 | - $plugins = array_filter($plugins, "is_dir"); |
|
| 178 | - $plugins = array_map("basename", $plugins); |
|
| 179 | - |
|
| 180 | - asort($plugins); |
|
| 181 | - |
|
| 182 | - $this->load(join(",", $plugins), $kind, $owner_uid, $skip_init); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - public function load($classlist, $kind, $owner_uid = false, $skip_init = false) { |
|
| 186 | - $plugins = explode(",", $classlist); |
|
| 187 | - |
|
| 188 | - $this->owner_uid = (int) $owner_uid; |
|
| 189 | - |
|
| 190 | - foreach ($plugins as $class) { |
|
| 191 | - $class = trim($class); |
|
| 192 | - $class_file = strtolower(clean_filename($class)); |
|
| 193 | - |
|
| 194 | - if (!is_dir(__DIR__."/../plugins/$class_file") && |
|
| 195 | - !is_dir(__DIR__."/../plugins.local/$class_file")) { |
|
| 196 | - continue; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - // try system plugin directory first |
|
| 200 | - $file = __DIR__."/../plugins/$class_file/init.php"; |
|
| 201 | - $vendor_dir = __DIR__."/../plugins/$class_file/vendor"; |
|
| 202 | - |
|
| 203 | - if (!file_exists($file)) { |
|
| 204 | - $file = __DIR__."/../plugins.local/$class_file/init.php"; |
|
| 205 | - $vendor_dir = __DIR__."/../plugins.local/$class_file/vendor"; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - if (!isset($this->plugins[$class])) { |
|
| 209 | - if (file_exists($file)) { |
|
| 210 | - require_once $file; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - if (class_exists($class) && is_subclass_of($class, "Plugin")) { |
|
| 214 | - |
|
| 215 | - // register plugin autoloader if necessary, for namespaced classes ONLY |
|
| 216 | - // layout corresponds to tt-rss main /vendor/author/Package/Class.php |
|
| 217 | - |
|
| 218 | - if (file_exists($vendor_dir)) { |
|
| 219 | - spl_autoload_register(function($class) use ($vendor_dir) { |
|
| 220 | - |
|
| 221 | - if (strpos($class, '\\') !== false) { |
|
| 222 | - list ($namespace, $class_name) = explode('\\', $class, 2); |
|
| 223 | - |
|
| 224 | - if ($namespace && $class_name) { |
|
| 225 | - $class_file = "$vendor_dir/$namespace/".str_replace('\\', '/', $class_name).".php"; |
|
| 226 | - |
|
| 227 | - if (file_exists($class_file)) { |
|
| 228 | - require_once $class_file; |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - }); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - $plugin = new $class($this); |
|
| 236 | - |
|
| 237 | - $plugin_api = $plugin->api_version(); |
|
| 238 | - |
|
| 239 | - if ($plugin_api < PluginHost::API_VERSION) { |
|
| 240 | - user_error("plugin $class is not compatible with current API version (need: ".PluginHost::API_VERSION.", got: $plugin_api)", E_USER_WARNING); |
|
| 241 | - continue; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - if (file_exists(dirname($file)."/locale")) { |
|
| 245 | - _bindtextdomain($class, dirname($file)."/locale"); |
|
| 246 | - _bind_textdomain_codeset($class, "UTF-8"); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - $this->last_registered = $class; |
|
| 250 | - |
|
| 251 | - switch ($kind) { |
|
| 252 | - case $this::KIND_SYSTEM: |
|
| 253 | - if ($this->is_system($plugin)) { |
|
| 254 | - if (!$skip_init) { |
|
| 255 | - $plugin->init($this); |
|
| 256 | - } |
|
| 257 | - $this->register_plugin($class, $plugin); |
|
| 258 | - } |
|
| 259 | - break; |
|
| 260 | - case $this::KIND_USER: |
|
| 261 | - if (!$this->is_system($plugin)) { |
|
| 262 | - if (!$skip_init) { |
|
| 263 | - $plugin->init($this); |
|
| 264 | - } |
|
| 265 | - $this->register_plugin($class, $plugin); |
|
| 266 | - } |
|
| 267 | - break; |
|
| 268 | - case $this::KIND_ALL: |
|
| 269 | - if (!$skip_init) { |
|
| 270 | - $plugin->init($this); |
|
| 271 | - } |
|
| 272 | - $this->register_plugin($class, $plugin); |
|
| 273 | - break; |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - public function is_system($plugin) { |
|
| 281 | - $about = $plugin->about(); |
|
| 282 | - |
|
| 283 | - return @$about[3]; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - // only system plugins are allowed to modify routing |
|
| 287 | - public function add_handler($handler, $method, $sender) { |
|
| 288 | - $handler = str_replace("-", "_", strtolower($handler)); |
|
| 289 | - $method = strtolower($method); |
|
| 290 | - |
|
| 291 | - if ($this->is_system($sender)) { |
|
| 292 | - if (!is_array($this->handlers[$handler])) { |
|
| 293 | - $this->handlers[$handler] = array(); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - $this->handlers[$handler][$method] = $sender; |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - public function del_handler($handler, $method, $sender) { |
|
| 301 | - $handler = str_replace("-", "_", strtolower($handler)); |
|
| 302 | - $method = strtolower($method); |
|
| 303 | - |
|
| 304 | - if ($this->is_system($sender)) { |
|
| 305 | - unset($this->handlers[$handler][$method]); |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - public function lookup_handler($handler, $method) { |
|
| 310 | - $handler = str_replace("-", "_", strtolower($handler)); |
|
| 311 | - $method = strtolower($method); |
|
| 312 | - |
|
| 313 | - if (is_array($this->handlers[$handler])) { |
|
| 314 | - if (isset($this->handlers[$handler]["*"])) { |
|
| 315 | - return $this->handlers[$handler]["*"]; |
|
| 316 | - } else { |
|
| 317 | - return $this->handlers[$handler][$method]; |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - return false; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - public function add_command($command, $description, $sender, $suffix = "", $arghelp = "") { |
|
| 325 | - $command = str_replace("-", "_", strtolower($command)); |
|
| 326 | - |
|
| 327 | - $this->commands[$command] = array("description" => $description, |
|
| 328 | - "suffix" => $suffix, |
|
| 329 | - "arghelp" => $arghelp, |
|
| 330 | - "class" => $sender); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - public function del_command($command) { |
|
| 334 | - $command = "-".strtolower($command); |
|
| 335 | - |
|
| 336 | - unset($this->commands[$command]); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - public function lookup_command($command) { |
|
| 340 | - $command = "-".strtolower($command); |
|
| 341 | - |
|
| 342 | - if (is_array($this->commands[$command])) { |
|
| 343 | - return $this->commands[$command]["class"]; |
|
| 344 | - } else { |
|
| 345 | - return false; |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - public function get_commands() { |
|
| 350 | - return $this->commands; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - public function run_commands($args) { |
|
| 354 | - foreach ($this->get_commands() as $command => $data) { |
|
| 355 | - if (isset($args[$command])) { |
|
| 356 | - $command = str_replace("-", "", $command); |
|
| 357 | - $data["class"]->$command($args); |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - public function load_data() { |
|
| 363 | - if ($this->owner_uid) { |
|
| 364 | - $sth = $this->pdo->prepare("SELECT name, content FROM ttrss_plugin_storage |
|
| 3 | + private $pdo; |
|
| 4 | + private $hooks = array(); |
|
| 5 | + private $plugins = array(); |
|
| 6 | + private $handlers = array(); |
|
| 7 | + private $commands = array(); |
|
| 8 | + private $storage = array(); |
|
| 9 | + private $feeds = array(); |
|
| 10 | + private $api_methods = array(); |
|
| 11 | + private $plugin_actions = array(); |
|
| 12 | + private $owner_uid; |
|
| 13 | + private $last_registered; |
|
| 14 | + private static $instance; |
|
| 15 | + |
|
| 16 | + const API_VERSION = 2; |
|
| 17 | + |
|
| 18 | + // Hooks marked with *1 are run in global context and available |
|
| 19 | + // to plugins loaded in config.php only |
|
| 20 | + |
|
| 21 | + const HOOK_ARTICLE_BUTTON = 1; |
|
| 22 | + const HOOK_ARTICLE_FILTER = 2; |
|
| 23 | + const HOOK_PREFS_TAB = 3; |
|
| 24 | + const HOOK_PREFS_TAB_SECTION = 4; |
|
| 25 | + const HOOK_PREFS_TABS = 5; |
|
| 26 | + const HOOK_FEED_PARSED = 6; |
|
| 27 | + const HOOK_UPDATE_TASK = 7; // *1 |
|
| 28 | + const HOOK_AUTH_USER = 8; |
|
| 29 | + const HOOK_HOTKEY_MAP = 9; |
|
| 30 | + const HOOK_RENDER_ARTICLE = 10; |
|
| 31 | + const HOOK_RENDER_ARTICLE_CDM = 11; |
|
| 32 | + const HOOK_FEED_FETCHED = 12; |
|
| 33 | + const HOOK_SANITIZE = 13; |
|
| 34 | + const HOOK_RENDER_ARTICLE_API = 14; |
|
| 35 | + const HOOK_TOOLBAR_BUTTON = 15; |
|
| 36 | + const HOOK_ACTION_ITEM = 16; |
|
| 37 | + const HOOK_HEADLINE_TOOLBAR_BUTTON = 17; |
|
| 38 | + const HOOK_HOTKEY_INFO = 18; |
|
| 39 | + const HOOK_ARTICLE_LEFT_BUTTON = 19; |
|
| 40 | + const HOOK_PREFS_EDIT_FEED = 20; |
|
| 41 | + const HOOK_PREFS_SAVE_FEED = 21; |
|
| 42 | + const HOOK_FETCH_FEED = 22; |
|
| 43 | + const HOOK_QUERY_HEADLINES = 23; |
|
| 44 | + const HOOK_HOUSE_KEEPING = 24; // *1 |
|
| 45 | + const HOOK_SEARCH = 25; |
|
| 46 | + const HOOK_FORMAT_ENCLOSURES = 26; |
|
| 47 | + const HOOK_SUBSCRIBE_FEED = 27; |
|
| 48 | + const HOOK_HEADLINES_BEFORE = 28; |
|
| 49 | + const HOOK_RENDER_ENCLOSURE = 29; |
|
| 50 | + const HOOK_ARTICLE_FILTER_ACTION = 30; |
|
| 51 | + const HOOK_ARTICLE_EXPORT_FEED = 31; |
|
| 52 | + const HOOK_MAIN_TOOLBAR_BUTTON = 32; |
|
| 53 | + const HOOK_ENCLOSURE_ENTRY = 33; |
|
| 54 | + const HOOK_FORMAT_ARTICLE = 34; |
|
| 55 | + const HOOK_FORMAT_ARTICLE_CDM = 35; /* RIP */ |
|
| 56 | + const HOOK_FEED_BASIC_INFO = 36; |
|
| 57 | + const HOOK_SEND_LOCAL_FILE = 37; |
|
| 58 | + const HOOK_UNSUBSCRIBE_FEED = 38; |
|
| 59 | + const HOOK_SEND_MAIL = 39; |
|
| 60 | + const HOOK_FILTER_TRIGGERED = 40; |
|
| 61 | + const HOOK_GET_FULL_TEXT = 41; |
|
| 62 | + const HOOK_ARTICLE_IMAGE = 42; |
|
| 63 | + const HOOK_FEED_TREE = 43; |
|
| 64 | + const HOOK_IFRAME_WHITELISTED = 44; |
|
| 65 | + |
|
| 66 | + const KIND_ALL = 1; |
|
| 67 | + const KIND_SYSTEM = 2; |
|
| 68 | + const KIND_USER = 3; |
|
| 69 | + |
|
| 70 | + public static function object_to_domain($plugin) { |
|
| 71 | + return strtolower(get_class($plugin)); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + public function __construct() { |
|
| 75 | + $this->pdo = Db::pdo(); |
|
| 76 | + |
|
| 77 | + $this->storage = array(); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + private function __clone() { |
|
| 81 | + // |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + public static function getInstance() { |
|
| 85 | + if (self::$instance == null) { |
|
| 86 | + self::$instance = new self(); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + return self::$instance; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + private function register_plugin($name, $plugin) { |
|
| 93 | + //array_push($this->plugins, $plugin); |
|
| 94 | + $this->plugins[$name] = $plugin; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // needed for compatibility with API 1 |
|
| 98 | + public function get_link() { |
|
| 99 | + return false; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + public function get_dbh() { |
|
| 103 | + return Db::get(); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + public function get_pdo() { |
|
| 107 | + return $this->pdo; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + public function get_plugin_names() { |
|
| 111 | + $names = array(); |
|
| 112 | + |
|
| 113 | + foreach ($this->plugins as $p) { |
|
| 114 | + array_push($names, get_class($p)); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return $names; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + public function get_plugins() { |
|
| 121 | + return $this->plugins; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + public function get_plugin($name) { |
|
| 125 | + return $this->plugins[strtolower($name)]; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function run_hooks($type, $method, $args) { |
|
| 129 | + foreach ($this->get_hooks($type) as $hook) { |
|
| 130 | + $hook->$method($args); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + public function add_hook($type, $sender, $priority = 50) { |
|
| 135 | + $priority = (int) $priority; |
|
| 136 | + |
|
| 137 | + if (!is_array($this->hooks[$type])) { |
|
| 138 | + $this->hooks[$type] = []; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + if (!is_array($this->hooks[$type][$priority])) { |
|
| 142 | + $this->hooks[$type][$priority] = []; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + array_push($this->hooks[$type][$priority], $sender); |
|
| 146 | + ksort($this->hooks[$type]); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + public function del_hook($type, $sender) { |
|
| 150 | + if (is_array($this->hooks[$type])) { |
|
| 151 | + foreach (array_keys($this->hooks[$type]) as $prio) { |
|
| 152 | + $key = array_search($sender, $this->hooks[$type][$prio]); |
|
| 153 | + |
|
| 154 | + if ($key !== false) { |
|
| 155 | + unset($this->hooks[$type][$prio][$key]); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + public function get_hooks($type) { |
|
| 162 | + if (isset($this->hooks[$type])) { |
|
| 163 | + $tmp = []; |
|
| 164 | + |
|
| 165 | + foreach (array_keys($this->hooks[$type]) as $prio) { |
|
| 166 | + $tmp = array_merge($tmp, $this->hooks[$type][$prio]); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + return $tmp; |
|
| 170 | + } else { |
|
| 171 | + return []; |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + public function load_all($kind, $owner_uid = false, $skip_init = false) { |
|
| 175 | + |
|
| 176 | + $plugins = array_merge(glob("plugins/*"), glob("plugins.local/*")); |
|
| 177 | + $plugins = array_filter($plugins, "is_dir"); |
|
| 178 | + $plugins = array_map("basename", $plugins); |
|
| 179 | + |
|
| 180 | + asort($plugins); |
|
| 181 | + |
|
| 182 | + $this->load(join(",", $plugins), $kind, $owner_uid, $skip_init); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + public function load($classlist, $kind, $owner_uid = false, $skip_init = false) { |
|
| 186 | + $plugins = explode(",", $classlist); |
|
| 187 | + |
|
| 188 | + $this->owner_uid = (int) $owner_uid; |
|
| 189 | + |
|
| 190 | + foreach ($plugins as $class) { |
|
| 191 | + $class = trim($class); |
|
| 192 | + $class_file = strtolower(clean_filename($class)); |
|
| 193 | + |
|
| 194 | + if (!is_dir(__DIR__."/../plugins/$class_file") && |
|
| 195 | + !is_dir(__DIR__."/../plugins.local/$class_file")) { |
|
| 196 | + continue; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + // try system plugin directory first |
|
| 200 | + $file = __DIR__."/../plugins/$class_file/init.php"; |
|
| 201 | + $vendor_dir = __DIR__."/../plugins/$class_file/vendor"; |
|
| 202 | + |
|
| 203 | + if (!file_exists($file)) { |
|
| 204 | + $file = __DIR__."/../plugins.local/$class_file/init.php"; |
|
| 205 | + $vendor_dir = __DIR__."/../plugins.local/$class_file/vendor"; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + if (!isset($this->plugins[$class])) { |
|
| 209 | + if (file_exists($file)) { |
|
| 210 | + require_once $file; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + if (class_exists($class) && is_subclass_of($class, "Plugin")) { |
|
| 214 | + |
|
| 215 | + // register plugin autoloader if necessary, for namespaced classes ONLY |
|
| 216 | + // layout corresponds to tt-rss main /vendor/author/Package/Class.php |
|
| 217 | + |
|
| 218 | + if (file_exists($vendor_dir)) { |
|
| 219 | + spl_autoload_register(function($class) use ($vendor_dir) { |
|
| 220 | + |
|
| 221 | + if (strpos($class, '\\') !== false) { |
|
| 222 | + list ($namespace, $class_name) = explode('\\', $class, 2); |
|
| 223 | + |
|
| 224 | + if ($namespace && $class_name) { |
|
| 225 | + $class_file = "$vendor_dir/$namespace/".str_replace('\\', '/', $class_name).".php"; |
|
| 226 | + |
|
| 227 | + if (file_exists($class_file)) { |
|
| 228 | + require_once $class_file; |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + }); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + $plugin = new $class($this); |
|
| 236 | + |
|
| 237 | + $plugin_api = $plugin->api_version(); |
|
| 238 | + |
|
| 239 | + if ($plugin_api < PluginHost::API_VERSION) { |
|
| 240 | + user_error("plugin $class is not compatible with current API version (need: ".PluginHost::API_VERSION.", got: $plugin_api)", E_USER_WARNING); |
|
| 241 | + continue; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + if (file_exists(dirname($file)."/locale")) { |
|
| 245 | + _bindtextdomain($class, dirname($file)."/locale"); |
|
| 246 | + _bind_textdomain_codeset($class, "UTF-8"); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + $this->last_registered = $class; |
|
| 250 | + |
|
| 251 | + switch ($kind) { |
|
| 252 | + case $this::KIND_SYSTEM: |
|
| 253 | + if ($this->is_system($plugin)) { |
|
| 254 | + if (!$skip_init) { |
|
| 255 | + $plugin->init($this); |
|
| 256 | + } |
|
| 257 | + $this->register_plugin($class, $plugin); |
|
| 258 | + } |
|
| 259 | + break; |
|
| 260 | + case $this::KIND_USER: |
|
| 261 | + if (!$this->is_system($plugin)) { |
|
| 262 | + if (!$skip_init) { |
|
| 263 | + $plugin->init($this); |
|
| 264 | + } |
|
| 265 | + $this->register_plugin($class, $plugin); |
|
| 266 | + } |
|
| 267 | + break; |
|
| 268 | + case $this::KIND_ALL: |
|
| 269 | + if (!$skip_init) { |
|
| 270 | + $plugin->init($this); |
|
| 271 | + } |
|
| 272 | + $this->register_plugin($class, $plugin); |
|
| 273 | + break; |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + public function is_system($plugin) { |
|
| 281 | + $about = $plugin->about(); |
|
| 282 | + |
|
| 283 | + return @$about[3]; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + // only system plugins are allowed to modify routing |
|
| 287 | + public function add_handler($handler, $method, $sender) { |
|
| 288 | + $handler = str_replace("-", "_", strtolower($handler)); |
|
| 289 | + $method = strtolower($method); |
|
| 290 | + |
|
| 291 | + if ($this->is_system($sender)) { |
|
| 292 | + if (!is_array($this->handlers[$handler])) { |
|
| 293 | + $this->handlers[$handler] = array(); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + $this->handlers[$handler][$method] = $sender; |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + public function del_handler($handler, $method, $sender) { |
|
| 301 | + $handler = str_replace("-", "_", strtolower($handler)); |
|
| 302 | + $method = strtolower($method); |
|
| 303 | + |
|
| 304 | + if ($this->is_system($sender)) { |
|
| 305 | + unset($this->handlers[$handler][$method]); |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + public function lookup_handler($handler, $method) { |
|
| 310 | + $handler = str_replace("-", "_", strtolower($handler)); |
|
| 311 | + $method = strtolower($method); |
|
| 312 | + |
|
| 313 | + if (is_array($this->handlers[$handler])) { |
|
| 314 | + if (isset($this->handlers[$handler]["*"])) { |
|
| 315 | + return $this->handlers[$handler]["*"]; |
|
| 316 | + } else { |
|
| 317 | + return $this->handlers[$handler][$method]; |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + return false; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + public function add_command($command, $description, $sender, $suffix = "", $arghelp = "") { |
|
| 325 | + $command = str_replace("-", "_", strtolower($command)); |
|
| 326 | + |
|
| 327 | + $this->commands[$command] = array("description" => $description, |
|
| 328 | + "suffix" => $suffix, |
|
| 329 | + "arghelp" => $arghelp, |
|
| 330 | + "class" => $sender); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + public function del_command($command) { |
|
| 334 | + $command = "-".strtolower($command); |
|
| 335 | + |
|
| 336 | + unset($this->commands[$command]); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + public function lookup_command($command) { |
|
| 340 | + $command = "-".strtolower($command); |
|
| 341 | + |
|
| 342 | + if (is_array($this->commands[$command])) { |
|
| 343 | + return $this->commands[$command]["class"]; |
|
| 344 | + } else { |
|
| 345 | + return false; |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + public function get_commands() { |
|
| 350 | + return $this->commands; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + public function run_commands($args) { |
|
| 354 | + foreach ($this->get_commands() as $command => $data) { |
|
| 355 | + if (isset($args[$command])) { |
|
| 356 | + $command = str_replace("-", "", $command); |
|
| 357 | + $data["class"]->$command($args); |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + public function load_data() { |
|
| 363 | + if ($this->owner_uid) { |
|
| 364 | + $sth = $this->pdo->prepare("SELECT name, content FROM ttrss_plugin_storage |
|
| 365 | 365 | WHERE owner_uid = ?"); |
| 366 | - $sth->execute([$this->owner_uid]); |
|
| 366 | + $sth->execute([$this->owner_uid]); |
|
| 367 | 367 | |
| 368 | - while ($line = $sth->fetch()) { |
|
| 369 | - $this->storage[$line["name"]] = unserialize($line["content"]); |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - } |
|
| 368 | + while ($line = $sth->fetch()) { |
|
| 369 | + $this->storage[$line["name"]] = unserialize($line["content"]); |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | - private function save_data($plugin) { |
|
| 375 | - if ($this->owner_uid) { |
|
| 376 | - $this->pdo->beginTransaction(); |
|
| 374 | + private function save_data($plugin) { |
|
| 375 | + if ($this->owner_uid) { |
|
| 376 | + $this->pdo->beginTransaction(); |
|
| 377 | 377 | |
| 378 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_plugin_storage WHERE |
|
| 378 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_plugin_storage WHERE |
|
| 379 | 379 | owner_uid= ? AND name = ?"); |
| 380 | - $sth->execute([$this->owner_uid, $plugin]); |
|
| 380 | + $sth->execute([$this->owner_uid, $plugin]); |
|
| 381 | 381 | |
| 382 | - if (!isset($this->storage[$plugin])) { |
|
| 383 | - $this->storage[$plugin] = array(); |
|
| 384 | - } |
|
| 382 | + if (!isset($this->storage[$plugin])) { |
|
| 383 | + $this->storage[$plugin] = array(); |
|
| 384 | + } |
|
| 385 | 385 | |
| 386 | - $content = serialize($this->storage[$plugin]); |
|
| 386 | + $content = serialize($this->storage[$plugin]); |
|
| 387 | 387 | |
| 388 | - if ($sth->fetch()) { |
|
| 389 | - $sth = $this->pdo->prepare("UPDATE ttrss_plugin_storage SET content = ? |
|
| 388 | + if ($sth->fetch()) { |
|
| 389 | + $sth = $this->pdo->prepare("UPDATE ttrss_plugin_storage SET content = ? |
|
| 390 | 390 | WHERE owner_uid= ? AND name = ?"); |
| 391 | - $sth->execute([(string) $content, $this->owner_uid, $plugin]); |
|
| 391 | + $sth->execute([(string) $content, $this->owner_uid, $plugin]); |
|
| 392 | 392 | |
| 393 | - } else { |
|
| 394 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_plugin_storage |
|
| 393 | + } else { |
|
| 394 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_plugin_storage |
|
| 395 | 395 | (name,owner_uid,content) VALUES |
| 396 | 396 | (?, ?, ?)"); |
| 397 | - $sth->execute([$plugin, $this->owner_uid, (string) $content]); |
|
| 398 | - } |
|
| 397 | + $sth->execute([$plugin, $this->owner_uid, (string) $content]); |
|
| 398 | + } |
|
| 399 | 399 | |
| 400 | - $this->pdo->commit(); |
|
| 401 | - } |
|
| 402 | - } |
|
| 400 | + $this->pdo->commit(); |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | 403 | |
| 404 | - public function set($sender, $name, $value, $sync = true) { |
|
| 405 | - $idx = get_class($sender); |
|
| 404 | + public function set($sender, $name, $value, $sync = true) { |
|
| 405 | + $idx = get_class($sender); |
|
| 406 | 406 | |
| 407 | - if (!isset($this->storage[$idx])) { |
|
| 408 | - $this->storage[$idx] = array(); |
|
| 409 | - } |
|
| 407 | + if (!isset($this->storage[$idx])) { |
|
| 408 | + $this->storage[$idx] = array(); |
|
| 409 | + } |
|
| 410 | 410 | |
| 411 | - $this->storage[$idx][$name] = $value; |
|
| 411 | + $this->storage[$idx][$name] = $value; |
|
| 412 | 412 | |
| 413 | - if ($sync) { |
|
| 414 | - $this->save_data(get_class($sender)); |
|
| 415 | - } |
|
| 416 | - } |
|
| 413 | + if ($sync) { |
|
| 414 | + $this->save_data(get_class($sender)); |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | 417 | |
| 418 | - public function get($sender, $name, $default_value = false) { |
|
| 419 | - $idx = get_class($sender); |
|
| 418 | + public function get($sender, $name, $default_value = false) { |
|
| 419 | + $idx = get_class($sender); |
|
| 420 | 420 | |
| 421 | - if (isset($this->storage[$idx][$name])) { |
|
| 422 | - return $this->storage[$idx][$name]; |
|
| 423 | - } else { |
|
| 424 | - return $default_value; |
|
| 425 | - } |
|
| 426 | - } |
|
| 421 | + if (isset($this->storage[$idx][$name])) { |
|
| 422 | + return $this->storage[$idx][$name]; |
|
| 423 | + } else { |
|
| 424 | + return $default_value; |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | 427 | |
| 428 | - public function get_all($sender) { |
|
| 429 | - $idx = get_class($sender); |
|
| 428 | + public function get_all($sender) { |
|
| 429 | + $idx = get_class($sender); |
|
| 430 | 430 | |
| 431 | - $data = $this->storage[$idx]; |
|
| 431 | + $data = $this->storage[$idx]; |
|
| 432 | 432 | |
| 433 | - return $data ? $data : []; |
|
| 434 | - } |
|
| 433 | + return $data ? $data : []; |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | - public function clear_data($sender) { |
|
| 437 | - if ($this->owner_uid) { |
|
| 438 | - $idx = get_class($sender); |
|
| 436 | + public function clear_data($sender) { |
|
| 437 | + if ($this->owner_uid) { |
|
| 438 | + $idx = get_class($sender); |
|
| 439 | 439 | |
| 440 | - unset($this->storage[$idx]); |
|
| 440 | + unset($this->storage[$idx]); |
|
| 441 | 441 | |
| 442 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_plugin_storage WHERE name = ? |
|
| 442 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_plugin_storage WHERE name = ? |
|
| 443 | 443 | AND owner_uid = ?"); |
| 444 | - $sth->execute([$idx, $this->owner_uid]); |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - // Plugin feed functions are *EXPERIMENTAL*! |
|
| 449 | - |
|
| 450 | - // cat_id: only -1 is supported (Special) |
|
| 451 | - public function add_feed($cat_id, $title, $icon, $sender) { |
|
| 452 | - if (!$this->feeds[$cat_id]) { |
|
| 453 | - $this->feeds[$cat_id] = array(); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - $id = count($this->feeds[$cat_id]); |
|
| 457 | - |
|
| 458 | - array_push($this->feeds[$cat_id], |
|
| 459 | - array('id' => $id, 'title' => $title, 'sender' => $sender, 'icon' => $icon)); |
|
| 460 | - |
|
| 461 | - return $id; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - public function get_feeds($cat_id) { |
|
| 465 | - return $this->feeds[$cat_id]; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - // convert feed_id (e.g. -129) to pfeed_id first |
|
| 469 | - public function get_feed_handler($pfeed_id) { |
|
| 470 | - foreach ($this->feeds as $cat) { |
|
| 471 | - foreach ($cat as $feed) { |
|
| 472 | - if ($feed['id'] == $pfeed_id) { |
|
| 473 | - return $feed['sender']; |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - public static function pfeed_to_feed_id($label) { |
|
| 480 | - return PLUGIN_FEED_BASE_INDEX - 1 - abs($label); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - public static function feed_to_pfeed_id($feed) { |
|
| 484 | - return PLUGIN_FEED_BASE_INDEX - 1 + abs($feed); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - public function add_api_method($name, $sender) { |
|
| 488 | - if ($this->is_system($sender)) { |
|
| 489 | - $this->api_methods[strtolower($name)] = $sender; |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - public function get_api_method($name) { |
|
| 494 | - return $this->api_methods[$name]; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - public function add_filter_action($sender, $action_name, $action_desc) { |
|
| 498 | - $sender_class = get_class($sender); |
|
| 499 | - |
|
| 500 | - if (!isset($this->plugin_actions[$sender_class])) { |
|
| 501 | - $this->plugin_actions[$sender_class] = array(); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - array_push($this->plugin_actions[$sender_class], |
|
| 505 | - array("action" => $action_name, "description" => $action_desc, "sender" => $sender)); |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - public function get_filter_actions() { |
|
| 509 | - return $this->plugin_actions; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - public function get_owner_uid() { |
|
| 513 | - return $this->owner_uid; |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - // handled by classes/pluginhandler.php, requires valid session |
|
| 517 | - public function get_method_url($sender, $method, $params) { |
|
| 518 | - return get_self_url_prefix()."/backend.php?". |
|
| 519 | - http_build_query( |
|
| 520 | - array_merge( |
|
| 521 | - [ |
|
| 522 | - "op" => "pluginhandler", |
|
| 523 | - "plugin" => strtolower(get_class($sender)), |
|
| 524 | - "method" => $method |
|
| 525 | - ], |
|
| 526 | - $params)); |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - // WARNING: endpoint in public.php, exposed to unauthenticated users |
|
| 530 | - public function get_public_method_url($sender, $method, $params) { |
|
| 531 | - if ($sender->is_public_method($method)) { |
|
| 532 | - return get_self_url_prefix()."/public.php?". |
|
| 533 | - http_build_query( |
|
| 534 | - array_merge( |
|
| 535 | - [ |
|
| 536 | - "op" => "pluginhandler", |
|
| 537 | - "plugin" => strtolower(get_class($sender)), |
|
| 538 | - "pmethod" => $method |
|
| 539 | - ], |
|
| 540 | - $params)); |
|
| 541 | - } else { |
|
| 542 | - user_error("get_public_method_url: requested method '$method' of '".get_class($sender)."' is private."); |
|
| 543 | - } |
|
| 544 | - } |
|
| 444 | + $sth->execute([$idx, $this->owner_uid]); |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + // Plugin feed functions are *EXPERIMENTAL*! |
|
| 449 | + |
|
| 450 | + // cat_id: only -1 is supported (Special) |
|
| 451 | + public function add_feed($cat_id, $title, $icon, $sender) { |
|
| 452 | + if (!$this->feeds[$cat_id]) { |
|
| 453 | + $this->feeds[$cat_id] = array(); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + $id = count($this->feeds[$cat_id]); |
|
| 457 | + |
|
| 458 | + array_push($this->feeds[$cat_id], |
|
| 459 | + array('id' => $id, 'title' => $title, 'sender' => $sender, 'icon' => $icon)); |
|
| 460 | + |
|
| 461 | + return $id; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + public function get_feeds($cat_id) { |
|
| 465 | + return $this->feeds[$cat_id]; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + // convert feed_id (e.g. -129) to pfeed_id first |
|
| 469 | + public function get_feed_handler($pfeed_id) { |
|
| 470 | + foreach ($this->feeds as $cat) { |
|
| 471 | + foreach ($cat as $feed) { |
|
| 472 | + if ($feed['id'] == $pfeed_id) { |
|
| 473 | + return $feed['sender']; |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + public static function pfeed_to_feed_id($label) { |
|
| 480 | + return PLUGIN_FEED_BASE_INDEX - 1 - abs($label); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + public static function feed_to_pfeed_id($feed) { |
|
| 484 | + return PLUGIN_FEED_BASE_INDEX - 1 + abs($feed); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + public function add_api_method($name, $sender) { |
|
| 488 | + if ($this->is_system($sender)) { |
|
| 489 | + $this->api_methods[strtolower($name)] = $sender; |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + public function get_api_method($name) { |
|
| 494 | + return $this->api_methods[$name]; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + public function add_filter_action($sender, $action_name, $action_desc) { |
|
| 498 | + $sender_class = get_class($sender); |
|
| 499 | + |
|
| 500 | + if (!isset($this->plugin_actions[$sender_class])) { |
|
| 501 | + $this->plugin_actions[$sender_class] = array(); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + array_push($this->plugin_actions[$sender_class], |
|
| 505 | + array("action" => $action_name, "description" => $action_desc, "sender" => $sender)); |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + public function get_filter_actions() { |
|
| 509 | + return $this->plugin_actions; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + public function get_owner_uid() { |
|
| 513 | + return $this->owner_uid; |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + // handled by classes/pluginhandler.php, requires valid session |
|
| 517 | + public function get_method_url($sender, $method, $params) { |
|
| 518 | + return get_self_url_prefix()."/backend.php?". |
|
| 519 | + http_build_query( |
|
| 520 | + array_merge( |
|
| 521 | + [ |
|
| 522 | + "op" => "pluginhandler", |
|
| 523 | + "plugin" => strtolower(get_class($sender)), |
|
| 524 | + "method" => $method |
|
| 525 | + ], |
|
| 526 | + $params)); |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + // WARNING: endpoint in public.php, exposed to unauthenticated users |
|
| 530 | + public function get_public_method_url($sender, $method, $params) { |
|
| 531 | + if ($sender->is_public_method($method)) { |
|
| 532 | + return get_self_url_prefix()."/public.php?". |
|
| 533 | + http_build_query( |
|
| 534 | + array_merge( |
|
| 535 | + [ |
|
| 536 | + "op" => "pluginhandler", |
|
| 537 | + "plugin" => strtolower(get_class($sender)), |
|
| 538 | + "pmethod" => $method |
|
| 539 | + ], |
|
| 540 | + $params)); |
|
| 541 | + } else { |
|
| 542 | + user_error("get_public_method_url: requested method '$method' of '".get_class($sender)."' is private."); |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | 545 | } |
@@ -1,162 +1,162 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | class FeedItem_Atom extends FeedItem_Common { |
| 3 | - const NS_XML = "http://www.w3.org/XML/1998/namespace"; |
|
| 3 | + const NS_XML = "http://www.w3.org/XML/1998/namespace"; |
|
| 4 | 4 | |
| 5 | - public function get_id() { |
|
| 6 | - $id = $this->elem->getElementsByTagName("id")->item(0); |
|
| 7 | - |
|
| 8 | - if ($id) { |
|
| 9 | - return $id->nodeValue; |
|
| 10 | - } else { |
|
| 11 | - return clean($this->get_link()); |
|
| 12 | - } |
|
| 13 | - } |
|
| 14 | - |
|
| 15 | - public function get_date() { |
|
| 16 | - $updated = $this->elem->getElementsByTagName("updated")->item(0); |
|
| 5 | + public function get_id() { |
|
| 6 | + $id = $this->elem->getElementsByTagName("id")->item(0); |
|
| 7 | + |
|
| 8 | + if ($id) { |
|
| 9 | + return $id->nodeValue; |
|
| 10 | + } else { |
|
| 11 | + return clean($this->get_link()); |
|
| 12 | + } |
|
| 13 | + } |
|
| 14 | + |
|
| 15 | + public function get_date() { |
|
| 16 | + $updated = $this->elem->getElementsByTagName("updated")->item(0); |
|
| 17 | 17 | |
| 18 | - if ($updated) { |
|
| 19 | - return strtotime($updated->nodeValue); |
|
| 20 | - } |
|
| 18 | + if ($updated) { |
|
| 19 | + return strtotime($updated->nodeValue); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - $published = $this->elem->getElementsByTagName("published")->item(0); |
|
| 22 | + $published = $this->elem->getElementsByTagName("published")->item(0); |
|
| 23 | 23 | |
| 24 | - if ($published) { |
|
| 25 | - return strtotime($published->nodeValue); |
|
| 26 | - } |
|
| 24 | + if ($published) { |
|
| 25 | + return strtotime($published->nodeValue); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - $date = $this->xpath->query("dc:date", $this->elem)->item(0); |
|
| 28 | + $date = $this->xpath->query("dc:date", $this->elem)->item(0); |
|
| 29 | 29 | |
| 30 | - if ($date) { |
|
| 31 | - return strtotime($date->nodeValue); |
|
| 32 | - } |
|
| 33 | - } |
|
| 30 | + if ($date) { |
|
| 31 | + return strtotime($date->nodeValue); |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | - public function get_link() { |
|
| 37 | - $links = $this->elem->getElementsByTagName("link"); |
|
| 36 | + public function get_link() { |
|
| 37 | + $links = $this->elem->getElementsByTagName("link"); |
|
| 38 | 38 | |
| 39 | - foreach ($links as $link) { |
|
| 40 | - if ($link && $link->hasAttribute("href") && |
|
| 41 | - (!$link->hasAttribute("rel") |
|
| 42 | - || $link->getAttribute("rel") == "alternate" |
|
| 43 | - || $link->getAttribute("rel") == "standout")) { |
|
| 44 | - $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link); |
|
| 39 | + foreach ($links as $link) { |
|
| 40 | + if ($link && $link->hasAttribute("href") && |
|
| 41 | + (!$link->hasAttribute("rel") |
|
| 42 | + || $link->getAttribute("rel") == "alternate" |
|
| 43 | + || $link->getAttribute("rel") == "standout")) { |
|
| 44 | + $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link); |
|
| 45 | 45 | |
| 46 | - if ($base) { |
|
| 47 | - return rewrite_relative_url($base, clean(trim($link->getAttribute("href")))); |
|
| 48 | - } else { |
|
| 49 | - return clean(trim($link->getAttribute("href"))); |
|
| 50 | - } |
|
| 46 | + if ($base) { |
|
| 47 | + return rewrite_relative_url($base, clean(trim($link->getAttribute("href")))); |
|
| 48 | + } else { |
|
| 49 | + return clean(trim($link->getAttribute("href"))); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - } |
|
| 53 | - } |
|
| 54 | - } |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function get_title() { |
|
| 57 | - $title = $this->elem->getElementsByTagName("title")->item(0); |
|
| 58 | - |
|
| 59 | - if ($title) { |
|
| 60 | - return clean(trim($title->nodeValue)); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - public function get_content() { |
|
| 65 | - $content = $this->elem->getElementsByTagName("content")->item(0); |
|
| 66 | - |
|
| 67 | - if ($content) { |
|
| 68 | - if ($content->hasAttribute('type')) { |
|
| 69 | - if ($content->getAttribute('type') == 'xhtml') { |
|
| 70 | - for ($i = 0; $i < $content->childNodes->length; $i++) { |
|
| 71 | - $child = $content->childNodes->item($i); |
|
| 72 | - |
|
| 73 | - if ($child->hasChildNodes()) { |
|
| 74 | - return $this->doc->saveHTML($child); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - return $this->subtree_or_text($content); |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - public function get_description() { |
|
| 85 | - $content = $this->elem->getElementsByTagName("summary")->item(0); |
|
| 86 | - |
|
| 87 | - if ($content) { |
|
| 88 | - if ($content->hasAttribute('type')) { |
|
| 89 | - if ($content->getAttribute('type') == 'xhtml') { |
|
| 90 | - for ($i = 0; $i < $content->childNodes->length; $i++) { |
|
| 91 | - $child = $content->childNodes->item($i); |
|
| 92 | - |
|
| 93 | - if ($child->hasChildNodes()) { |
|
| 94 | - return $this->doc->saveHTML($child); |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return $this->subtree_or_text($content); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function get_categories() { |
|
| 106 | - $categories = $this->elem->getElementsByTagName("category"); |
|
| 107 | - $cats = []; |
|
| 108 | - |
|
| 109 | - foreach ($categories as $cat) { |
|
| 110 | - if ($cat->hasAttribute("term")) { |
|
| 111 | - array_push($cats, $cat->getAttribute("term")); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $categories = $this->xpath->query("dc:subject", $this->elem); |
|
| 116 | - |
|
| 117 | - foreach ($categories as $cat) { |
|
| 118 | - array_push($cats, $cat->nodeValue); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - return $this->normalize_categories($cats); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - public function get_enclosures() { |
|
| 125 | - $links = $this->elem->getElementsByTagName("link"); |
|
| 126 | - |
|
| 127 | - $encs = array(); |
|
| 128 | - |
|
| 129 | - foreach ($links as $link) { |
|
| 130 | - if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) { |
|
| 131 | - if ($link->getAttribute("rel") == "enclosure") { |
|
| 132 | - $enc = new FeedEnclosure(); |
|
| 133 | - |
|
| 134 | - $enc->type = clean($link->getAttribute("type")); |
|
| 135 | - $enc->link = clean($link->getAttribute("href")); |
|
| 136 | - $enc->length = clean($link->getAttribute("length")); |
|
| 137 | - |
|
| 138 | - array_push($encs, $enc); |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - $encs = array_merge($encs, parent::get_enclosures()); |
|
| 144 | - |
|
| 145 | - return $encs; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - public function get_language() { |
|
| 149 | - $lang = $this->elem->getAttributeNS(self::NS_XML, "lang"); |
|
| 150 | - |
|
| 151 | - if (!empty($lang)) { |
|
| 152 | - return clean($lang); |
|
| 153 | - } else { |
|
| 154 | - // Fall back to the language declared on the feed, if any. |
|
| 155 | - foreach ($this->doc->childNodes as $child) { |
|
| 156 | - if (method_exists($child, "getAttributeNS")) { |
|
| 157 | - return clean($child->getAttributeNS(self::NS_XML, "lang")); |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - } |
|
| 56 | + public function get_title() { |
|
| 57 | + $title = $this->elem->getElementsByTagName("title")->item(0); |
|
| 58 | + |
|
| 59 | + if ($title) { |
|
| 60 | + return clean(trim($title->nodeValue)); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + public function get_content() { |
|
| 65 | + $content = $this->elem->getElementsByTagName("content")->item(0); |
|
| 66 | + |
|
| 67 | + if ($content) { |
|
| 68 | + if ($content->hasAttribute('type')) { |
|
| 69 | + if ($content->getAttribute('type') == 'xhtml') { |
|
| 70 | + for ($i = 0; $i < $content->childNodes->length; $i++) { |
|
| 71 | + $child = $content->childNodes->item($i); |
|
| 72 | + |
|
| 73 | + if ($child->hasChildNodes()) { |
|
| 74 | + return $this->doc->saveHTML($child); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + return $this->subtree_or_text($content); |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + public function get_description() { |
|
| 85 | + $content = $this->elem->getElementsByTagName("summary")->item(0); |
|
| 86 | + |
|
| 87 | + if ($content) { |
|
| 88 | + if ($content->hasAttribute('type')) { |
|
| 89 | + if ($content->getAttribute('type') == 'xhtml') { |
|
| 90 | + for ($i = 0; $i < $content->childNodes->length; $i++) { |
|
| 91 | + $child = $content->childNodes->item($i); |
|
| 92 | + |
|
| 93 | + if ($child->hasChildNodes()) { |
|
| 94 | + return $this->doc->saveHTML($child); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return $this->subtree_or_text($content); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function get_categories() { |
|
| 106 | + $categories = $this->elem->getElementsByTagName("category"); |
|
| 107 | + $cats = []; |
|
| 108 | + |
|
| 109 | + foreach ($categories as $cat) { |
|
| 110 | + if ($cat->hasAttribute("term")) { |
|
| 111 | + array_push($cats, $cat->getAttribute("term")); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $categories = $this->xpath->query("dc:subject", $this->elem); |
|
| 116 | + |
|
| 117 | + foreach ($categories as $cat) { |
|
| 118 | + array_push($cats, $cat->nodeValue); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + return $this->normalize_categories($cats); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + public function get_enclosures() { |
|
| 125 | + $links = $this->elem->getElementsByTagName("link"); |
|
| 126 | + |
|
| 127 | + $encs = array(); |
|
| 128 | + |
|
| 129 | + foreach ($links as $link) { |
|
| 130 | + if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) { |
|
| 131 | + if ($link->getAttribute("rel") == "enclosure") { |
|
| 132 | + $enc = new FeedEnclosure(); |
|
| 133 | + |
|
| 134 | + $enc->type = clean($link->getAttribute("type")); |
|
| 135 | + $enc->link = clean($link->getAttribute("href")); |
|
| 136 | + $enc->length = clean($link->getAttribute("length")); |
|
| 137 | + |
|
| 138 | + array_push($encs, $enc); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + $encs = array_merge($encs, parent::get_enclosures()); |
|
| 144 | + |
|
| 145 | + return $encs; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + public function get_language() { |
|
| 149 | + $lang = $this->elem->getAttributeNS(self::NS_XML, "lang"); |
|
| 150 | + |
|
| 151 | + if (!empty($lang)) { |
|
| 152 | + return clean($lang); |
|
| 153 | + } else { |
|
| 154 | + // Fall back to the language declared on the feed, if any. |
|
| 155 | + foreach ($this->doc->childNodes as $child) { |
|
| 156 | + if (method_exists($child, "getAttributeNS")) { |
|
| 157 | + return clean($child->getAttributeNS(self::NS_XML, "lang")); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | 162 | } |
@@ -2,309 +2,309 @@ discard block |
||
| 2 | 2 | require_once "colors.php"; |
| 3 | 3 | |
| 4 | 4 | class Feeds extends Handler_Protected { |
| 5 | - const NEVER_GROUP_FEEDS = [ -6, 0]; |
|
| 6 | - const NEVER_GROUP_BY_DATE = [ -2, -1, -3]; |
|
| 5 | + const NEVER_GROUP_FEEDS = [ -6, 0]; |
|
| 6 | + const NEVER_GROUP_BY_DATE = [ -2, -1, -3]; |
|
| 7 | 7 | |
| 8 | 8 | private $params; |
| 9 | 9 | |
| 10 | 10 | function csrf_ignore($method) { |
| 11 | - $csrf_ignored = array("index", "quickaddfeed", "search"); |
|
| 11 | + $csrf_ignored = array("index", "quickaddfeed", "search"); |
|
| 12 | 12 | |
| 13 | - return array_search($method, $csrf_ignored) !== false; |
|
| 14 | - } |
|
| 13 | + return array_search($method, $csrf_ignored) !== false; |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - private function format_headline_subtoolbar($feed_site_url, $feed_title, |
|
| 17 | - $feed_id, $is_cat, $search, |
|
| 18 | - $error, $feed_last_updated) { |
|
| 16 | + private function format_headline_subtoolbar($feed_site_url, $feed_title, |
|
| 17 | + $feed_id, $is_cat, $search, |
|
| 18 | + $error, $feed_last_updated) { |
|
| 19 | 19 | |
| 20 | - if ($is_cat) { |
|
| 21 | - $cat_q = "&is_cat=$is_cat"; |
|
| 22 | - } |
|
| 20 | + if ($is_cat) { |
|
| 21 | + $cat_q = "&is_cat=$is_cat"; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - if ($search) { |
|
| 25 | - $search_q = "&q=$search"; |
|
| 26 | - } else { |
|
| 27 | - $search_q = ""; |
|
| 28 | - } |
|
| 24 | + if ($search) { |
|
| 25 | + $search_q = "&q=$search"; |
|
| 26 | + } else { |
|
| 27 | + $search_q = ""; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - $reply = ""; |
|
| 30 | + $reply = ""; |
|
| 31 | 31 | |
| 32 | - $rss_link = htmlspecialchars(get_self_url_prefix(). |
|
| 33 | - "/public.php?op=rss&id=$feed_id$cat_q$search_q"); |
|
| 32 | + $rss_link = htmlspecialchars(get_self_url_prefix(). |
|
| 33 | + "/public.php?op=rss&id=$feed_id$cat_q$search_q"); |
|
| 34 | 34 | |
| 35 | - $reply .= "<span class='left'>"; |
|
| 35 | + $reply .= "<span class='left'>"; |
|
| 36 | 36 | |
| 37 | - $reply .= "<a href=\"#\" |
|
| 37 | + $reply .= "<a href=\"#\" |
|
| 38 | 38 | title=\"".__("Show as feed")."\" |
| 39 | 39 | onclick=\"App.displayDlg('".__("Show as feed")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\"> |
| 40 | 40 | <i class='icon-syndicate material-icons'>rss_feed</i></a>"; |
| 41 | 41 | |
| 42 | - $reply .= "<span id='feed_title'>"; |
|
| 42 | + $reply .= "<span id='feed_title'>"; |
|
| 43 | 43 | |
| 44 | - if ($feed_site_url) { |
|
| 45 | - $last_updated = T_sprintf("Last updated: %s", $feed_last_updated); |
|
| 44 | + if ($feed_site_url) { |
|
| 45 | + $last_updated = T_sprintf("Last updated: %s", $feed_last_updated); |
|
| 46 | 46 | |
| 47 | - $reply .= "<a title=\"$last_updated\" target='_blank' href=\"$feed_site_url\">". |
|
| 48 | - truncate_string(strip_tags($feed_title), 30)."</a>"; |
|
| 49 | - } else { |
|
| 50 | - $reply .= strip_tags($feed_title); |
|
| 51 | - } |
|
| 47 | + $reply .= "<a title=\"$last_updated\" target='_blank' href=\"$feed_site_url\">". |
|
| 48 | + truncate_string(strip_tags($feed_title), 30)."</a>"; |
|
| 49 | + } else { |
|
| 50 | + $reply .= strip_tags($feed_title); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - if ($error) |
|
| 54 | - $reply .= " <i title=\"".htmlspecialchars($error)."\" class='material-icons icon-error'>error</i>"; |
|
| 53 | + if ($error) |
|
| 54 | + $reply .= " <i title=\"".htmlspecialchars($error)."\" class='material-icons icon-error'>error</i>"; |
|
| 55 | 55 | |
| 56 | - $reply .= "</span>"; |
|
| 57 | - $reply .= "<span id='feed_current_unread' style='display: none'></span>"; |
|
| 58 | - $reply .= "</span>"; |
|
| 56 | + $reply .= "</span>"; |
|
| 57 | + $reply .= "<span id='feed_current_unread' style='display: none'></span>"; |
|
| 58 | + $reply .= "</span>"; |
|
| 59 | 59 | |
| 60 | - $reply .= "<span class=\"right\">"; |
|
| 61 | - $reply .= "<span id='selected_prompt'></span>"; |
|
| 62 | - $reply .= " "; |
|
| 63 | - $reply .= "<select dojoType=\"fox.form.Select\" |
|
| 60 | + $reply .= "<span class=\"right\">"; |
|
| 61 | + $reply .= "<span id='selected_prompt'></span>"; |
|
| 62 | + $reply .= " "; |
|
| 63 | + $reply .= "<select dojoType=\"fox.form.Select\" |
|
| 64 | 64 | onchange=\"Headlines.onActionChanged(this)\">"; |
| 65 | 65 | |
| 66 | - $reply .= "<option value=\"0\" disabled='1'>".__('Select...')."</option>"; |
|
| 66 | + $reply .= "<option value=\"0\" disabled='1'>".__('Select...')."</option>"; |
|
| 67 | 67 | |
| 68 | - $reply .= "<option value=\"Headlines.select('all')\">".__('All')."</option>"; |
|
| 69 | - $reply .= "<option value=\"Headlines.select('unread')\">".__('Unread')."</option>"; |
|
| 70 | - $reply .= "<option value=\"Headlines.select('invert')\">".__('Invert')."</option>"; |
|
| 71 | - $reply .= "<option value=\"Headlines.select('none')\">".__('None')."</option>"; |
|
| 68 | + $reply .= "<option value=\"Headlines.select('all')\">".__('All')."</option>"; |
|
| 69 | + $reply .= "<option value=\"Headlines.select('unread')\">".__('Unread')."</option>"; |
|
| 70 | + $reply .= "<option value=\"Headlines.select('invert')\">".__('Invert')."</option>"; |
|
| 71 | + $reply .= "<option value=\"Headlines.select('none')\">".__('None')."</option>"; |
|
| 72 | 72 | |
| 73 | - $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>"; |
|
| 73 | + $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection toggle:')."</option>"; |
|
| 74 | 74 | |
| 75 | - $reply .= "<option value=\"Headlines.selectionToggleUnread()\">".__('Unread')."</option> |
|
| 75 | + $reply .= "<option value=\"Headlines.selectionToggleUnread()\">".__('Unread')."</option> |
|
| 76 | 76 | <option value=\"Headlines.selectionToggleMarked()\">".__('Starred')."</option> |
| 77 | 77 | <option value=\"Headlines.selectionTogglePublished()\">".__('Published')."</option>"; |
| 78 | 78 | |
| 79 | - $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>"; |
|
| 79 | + $reply .= "<option value=\"0\" disabled=\"1\">".__('Selection:')."</option>"; |
|
| 80 | 80 | |
| 81 | - $reply .= "<option value=\"Headlines.catchupSelection()\">".__('Mark as read')."</option>"; |
|
| 82 | - $reply .= "<option value=\"Article.selectionSetScore()\">".__('Set score')."</option>"; |
|
| 81 | + $reply .= "<option value=\"Headlines.catchupSelection()\">".__('Mark as read')."</option>"; |
|
| 82 | + $reply .= "<option value=\"Article.selectionSetScore()\">".__('Set score')."</option>"; |
|
| 83 | 83 | |
| 84 | - if ($feed_id == 0 && !$is_cat) { |
|
| 85 | - $reply .= "<option value=\"Headlines.archiveSelection()\">".__('Move back')."</option>"; |
|
| 86 | - $reply .= "<option value=\"Headlines.deleteSelection()\">".__('Delete')."</option>"; |
|
| 87 | - } else { |
|
| 88 | - $reply .= "<option value=\"Headlines.archiveSelection()\">".__('Archive')."</option>"; |
|
| 89 | - } |
|
| 84 | + if ($feed_id == 0 && !$is_cat) { |
|
| 85 | + $reply .= "<option value=\"Headlines.archiveSelection()\">".__('Move back')."</option>"; |
|
| 86 | + $reply .= "<option value=\"Headlines.deleteSelection()\">".__('Delete')."</option>"; |
|
| 87 | + } else { |
|
| 88 | + $reply .= "<option value=\"Headlines.archiveSelection()\">".__('Archive')."</option>"; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - if (PluginHost::getInstance()->get_plugin("mail")) { |
|
| 92 | - $reply .= "<option value=\"Plugins.Mail.send()\">".__('Forward by email'). |
|
| 93 | - "</option>"; |
|
| 94 | - } |
|
| 91 | + if (PluginHost::getInstance()->get_plugin("mail")) { |
|
| 92 | + $reply .= "<option value=\"Plugins.Mail.send()\">".__('Forward by email'). |
|
| 93 | + "</option>"; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - if (PluginHost::getInstance()->get_plugin("mailto")) { |
|
| 97 | - $reply .= "<option value=\"Plugins.Mailto.send()\">".__('Forward by email'). |
|
| 98 | - "</option>"; |
|
| 99 | - } |
|
| 96 | + if (PluginHost::getInstance()->get_plugin("mailto")) { |
|
| 97 | + $reply .= "<option value=\"Plugins.Mailto.send()\">".__('Forward by email'). |
|
| 98 | + "</option>"; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>"; |
|
| 101 | + $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>"; |
|
| 102 | 102 | |
| 103 | - //$reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>"; |
|
| 103 | + //$reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>"; |
|
| 104 | 104 | |
| 105 | - $reply .= "<option value=\"App.displayDlg('".__("Show as feed")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">". |
|
| 105 | + $reply .= "<option value=\"App.displayDlg('".__("Show as feed")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">". |
|
| 106 | 106 | __('Show as feed')."</option>"; |
| 107 | 107 | |
| 108 | - $reply .= "</select>"; |
|
| 108 | + $reply .= "</select>"; |
|
| 109 | 109 | |
| 110 | - //$reply .= "</h2"; |
|
| 110 | + //$reply .= "</h2"; |
|
| 111 | 111 | |
| 112 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HEADLINE_TOOLBAR_BUTTON) as $p) { |
|
| 113 | - $reply .= $p->hook_headline_toolbar_button($feed_id, $is_cat); |
|
| 114 | - } |
|
| 112 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HEADLINE_TOOLBAR_BUTTON) as $p) { |
|
| 113 | + $reply .= $p->hook_headline_toolbar_button($feed_id, $is_cat); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - $reply .= "</span>"; |
|
| 116 | + $reply .= "</span>"; |
|
| 117 | 117 | |
| 118 | - return $reply; |
|
| 119 | - } |
|
| 118 | + return $reply; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, |
|
| 122 | - $offset, $override_order = false, $include_children = false, $check_first_id = false, |
|
| 123 | - $skip_first_id_check = false, $order_by = false) { |
|
| 121 | + private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, |
|
| 122 | + $offset, $override_order = false, $include_children = false, $check_first_id = false, |
|
| 123 | + $skip_first_id_check = false, $order_by = false) { |
|
| 124 | 124 | |
| 125 | - $disable_cache = false; |
|
| 125 | + $disable_cache = false; |
|
| 126 | 126 | |
| 127 | - $reply = array(); |
|
| 127 | + $reply = array(); |
|
| 128 | 128 | |
| 129 | - $rgba_cache = array(); |
|
| 130 | - $topmost_article_ids = array(); |
|
| 129 | + $rgba_cache = array(); |
|
| 130 | + $topmost_article_ids = array(); |
|
| 131 | 131 | |
| 132 | - if (!$offset) { |
|
| 133 | - $offset = 0; |
|
| 134 | - } |
|
| 135 | - if ($method == "undefined") { |
|
| 136 | - $method = ""; |
|
| 137 | - } |
|
| 132 | + if (!$offset) { |
|
| 133 | + $offset = 0; |
|
| 134 | + } |
|
| 135 | + if ($method == "undefined") { |
|
| 136 | + $method = ""; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - $method_split = explode(":", $method); |
|
| 139 | + $method_split = explode(":", $method); |
|
| 140 | 140 | |
| 141 | - if ($method == "ForceUpdate" && $feed > 0 && is_numeric($feed)) { |
|
| 141 | + if ($method == "ForceUpdate" && $feed > 0 && is_numeric($feed)) { |
|
| 142 | 142 | $sth = $this->pdo->prepare("UPDATE ttrss_feeds |
| 143 | 143 | SET last_updated = '1970-01-01', last_update_started = '1970-01-01' |
| 144 | 144 | WHERE id = ?"); |
| 145 | 145 | $sth->execute([$feed]); |
| 146 | - } |
|
| 147 | - |
|
| 148 | - if ($method_split[0] == "MarkAllReadGR") { |
|
| 149 | - $this->catchup_feed($method_split[1], false); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // FIXME: might break tag display? |
|
| 153 | - |
|
| 154 | - if (is_numeric($feed) && $feed > 0 && !$cat_view) { |
|
| 155 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ? LIMIT 1"); |
|
| 156 | - $sth->execute([$feed]); |
|
| 157 | - |
|
| 158 | - if (!$sth->fetch()) { |
|
| 159 | - $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>"; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - @$search = $_REQUEST["query"]; |
|
| 164 | - @$search_language = $_REQUEST["search_language"]; // PGSQL only |
|
| 165 | - |
|
| 166 | - if ($search) { |
|
| 167 | - $disable_cache = true; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - if (!$cat_view && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) { |
|
| 171 | - $handler = PluginHost::getInstance()->get_feed_handler( |
|
| 172 | - PluginHost::feed_to_pfeed_id($feed)); |
|
| 173 | - |
|
| 174 | - if ($handler) { |
|
| 175 | - $options = array( |
|
| 176 | - "limit" => $limit, |
|
| 177 | - "view_mode" => $view_mode, |
|
| 178 | - "cat_view" => $cat_view, |
|
| 179 | - "search" => $search, |
|
| 180 | - "override_order" => $override_order, |
|
| 181 | - "offset" => $offset, |
|
| 182 | - "owner_uid" => $_SESSION["uid"], |
|
| 183 | - "filter" => false, |
|
| 184 | - "since_id" => 0, |
|
| 185 | - "include_children" => $include_children, |
|
| 186 | - "order_by" => $order_by); |
|
| 187 | - |
|
| 188 | - $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed), |
|
| 189 | - $options); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - } else { |
|
| 193 | - |
|
| 194 | - $params = array( |
|
| 195 | - "feed" => $feed, |
|
| 196 | - "limit" => $limit, |
|
| 197 | - "view_mode" => $view_mode, |
|
| 198 | - "cat_view" => $cat_view, |
|
| 199 | - "search" => $search, |
|
| 200 | - "search_language" => $search_language, |
|
| 201 | - "override_order" => $override_order, |
|
| 202 | - "offset" => $offset, |
|
| 203 | - "include_children" => $include_children, |
|
| 204 | - "check_first_id" => $check_first_id, |
|
| 205 | - "skip_first_id_check" => $skip_first_id_check, |
|
| 206 | - "order_by" => $order_by |
|
| 207 | - ); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + if ($method_split[0] == "MarkAllReadGR") { |
|
| 149 | + $this->catchup_feed($method_split[1], false); |
|
| 150 | + } |
|
| 208 | 151 | |
| 209 | - $qfh_ret = $this->queryFeedHeadlines($params); |
|
| 210 | - } |
|
| 152 | + // FIXME: might break tag display? |
|
| 153 | + |
|
| 154 | + if (is_numeric($feed) && $feed > 0 && !$cat_view) { |
|
| 155 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ? LIMIT 1"); |
|
| 156 | + $sth->execute([$feed]); |
|
| 157 | + |
|
| 158 | + if (!$sth->fetch()) { |
|
| 159 | + $reply['content'] = "<div align='center'>".__('Feed not found.')."</div>"; |
|
| 160 | + } |
|
| 161 | + } |
|
| 211 | 162 | |
| 212 | - $vfeed_group_enabled = get_pref("VFEED_GROUP_BY_FEED") && |
|
| 213 | - !(in_array($feed, Feeds::NEVER_GROUP_FEEDS) && !$cat_view); |
|
| 163 | + @$search = $_REQUEST["query"]; |
|
| 164 | + @$search_language = $_REQUEST["search_language"]; // PGSQL only |
|
| 214 | 165 | |
| 215 | - $result = $qfh_ret[0]; // this could be either a PDO query result or a -1 if first id changed |
|
| 216 | - $feed_title = $qfh_ret[1]; |
|
| 217 | - $feed_site_url = $qfh_ret[2]; |
|
| 218 | - $last_error = $qfh_ret[3]; |
|
| 219 | - $last_updated = strpos($qfh_ret[4], '1970-') === false ? |
|
| 220 | - make_local_datetime($qfh_ret[4], false) : __("Never"); |
|
| 221 | - $highlight_words = $qfh_ret[5]; |
|
| 222 | - $reply['first_id'] = $qfh_ret[6]; |
|
| 223 | - $reply['is_vfeed'] = $qfh_ret[7]; |
|
| 224 | - $query_error_override = $qfh_ret[8]; |
|
| 166 | + if ($search) { |
|
| 167 | + $disable_cache = true; |
|
| 168 | + } |
|
| 225 | 169 | |
| 226 | - $reply['search_query'] = [$search, $search_language]; |
|
| 227 | - $reply['vfeed_group_enabled'] = $vfeed_group_enabled; |
|
| 170 | + if (!$cat_view && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) { |
|
| 171 | + $handler = PluginHost::getInstance()->get_feed_handler( |
|
| 172 | + PluginHost::feed_to_pfeed_id($feed)); |
|
| 173 | + |
|
| 174 | + if ($handler) { |
|
| 175 | + $options = array( |
|
| 176 | + "limit" => $limit, |
|
| 177 | + "view_mode" => $view_mode, |
|
| 178 | + "cat_view" => $cat_view, |
|
| 179 | + "search" => $search, |
|
| 180 | + "override_order" => $override_order, |
|
| 181 | + "offset" => $offset, |
|
| 182 | + "owner_uid" => $_SESSION["uid"], |
|
| 183 | + "filter" => false, |
|
| 184 | + "since_id" => 0, |
|
| 185 | + "include_children" => $include_children, |
|
| 186 | + "order_by" => $order_by); |
|
| 187 | + |
|
| 188 | + $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed), |
|
| 189 | + $options); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + } else { |
|
| 193 | + |
|
| 194 | + $params = array( |
|
| 195 | + "feed" => $feed, |
|
| 196 | + "limit" => $limit, |
|
| 197 | + "view_mode" => $view_mode, |
|
| 198 | + "cat_view" => $cat_view, |
|
| 199 | + "search" => $search, |
|
| 200 | + "search_language" => $search_language, |
|
| 201 | + "override_order" => $override_order, |
|
| 202 | + "offset" => $offset, |
|
| 203 | + "include_children" => $include_children, |
|
| 204 | + "check_first_id" => $check_first_id, |
|
| 205 | + "skip_first_id_check" => $skip_first_id_check, |
|
| 206 | + "order_by" => $order_by |
|
| 207 | + ); |
|
| 228 | 208 | |
| 229 | - $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url, |
|
| 230 | - $feed_title, |
|
| 231 | - $feed, $cat_view, $search, |
|
| 232 | - $last_error, $last_updated); |
|
| 209 | + $qfh_ret = $this->queryFeedHeadlines($params); |
|
| 210 | + } |
|
| 233 | 211 | |
| 234 | - if ($offset == 0) { |
|
| 235 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HEADLINES_BEFORE) as $p) { |
|
| 236 | - $reply['content'] .= $p->hook_headlines_before($feed, $cat_view, $qfh_ret); |
|
| 237 | - } |
|
| 238 | - } |
|
| 212 | + $vfeed_group_enabled = get_pref("VFEED_GROUP_BY_FEED") && |
|
| 213 | + !(in_array($feed, Feeds::NEVER_GROUP_FEEDS) && !$cat_view); |
|
| 214 | + |
|
| 215 | + $result = $qfh_ret[0]; // this could be either a PDO query result or a -1 if first id changed |
|
| 216 | + $feed_title = $qfh_ret[1]; |
|
| 217 | + $feed_site_url = $qfh_ret[2]; |
|
| 218 | + $last_error = $qfh_ret[3]; |
|
| 219 | + $last_updated = strpos($qfh_ret[4], '1970-') === false ? |
|
| 220 | + make_local_datetime($qfh_ret[4], false) : __("Never"); |
|
| 221 | + $highlight_words = $qfh_ret[5]; |
|
| 222 | + $reply['first_id'] = $qfh_ret[6]; |
|
| 223 | + $reply['is_vfeed'] = $qfh_ret[7]; |
|
| 224 | + $query_error_override = $qfh_ret[8]; |
|
| 225 | + |
|
| 226 | + $reply['search_query'] = [$search, $search_language]; |
|
| 227 | + $reply['vfeed_group_enabled'] = $vfeed_group_enabled; |
|
| 228 | + |
|
| 229 | + $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url, |
|
| 230 | + $feed_title, |
|
| 231 | + $feed, $cat_view, $search, |
|
| 232 | + $last_error, $last_updated); |
|
| 233 | + |
|
| 234 | + if ($offset == 0) { |
|
| 235 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_HEADLINES_BEFORE) as $p) { |
|
| 236 | + $reply['content'] .= $p->hook_headlines_before($feed, $cat_view, $qfh_ret); |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - $reply['content'] = []; |
|
| 240 | + $reply['content'] = []; |
|
| 241 | 241 | |
| 242 | - $headlines_count = 0; |
|
| 242 | + $headlines_count = 0; |
|
| 243 | 243 | |
| 244 | 244 | if (is_object($result)) { |
| 245 | - while ($line = $result->fetch(PDO::FETCH_ASSOC)) { |
|
| 245 | + while ($line = $result->fetch(PDO::FETCH_ASSOC)) { |
|
| 246 | 246 | |
| 247 | - ++$headlines_count; |
|
| 247 | + ++$headlines_count; |
|
| 248 | 248 | |
| 249 | - if (!get_pref('SHOW_CONTENT_PREVIEW')) { |
|
| 250 | - $line["content_preview"] = ""; |
|
| 251 | - } else { |
|
| 252 | - $line["content_preview"] = "— ".truncate_string(strip_tags($line["content"]), 250); |
|
| 249 | + if (!get_pref('SHOW_CONTENT_PREVIEW')) { |
|
| 250 | + $line["content_preview"] = ""; |
|
| 251 | + } else { |
|
| 252 | + $line["content_preview"] = "— ".truncate_string(strip_tags($line["content"]), 250); |
|
| 253 | 253 | |
| 254 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
| 255 | - $line = $p->hook_query_headlines($line, 250, false); |
|
| 256 | - } |
|
| 254 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
| 255 | + $line = $p->hook_query_headlines($line, 250, false); |
|
| 256 | + } |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - $id = $line["id"]; |
|
| 259 | + $id = $line["id"]; |
|
| 260 | 260 | |
| 261 | - // frontend doesn't expect pdo returning booleans as strings on mysql |
|
| 262 | - if (DB_TYPE == "mysql") { |
|
| 263 | - foreach (["unread", "marked", "published"] as $k) { |
|
| 264 | - $line[$k] = $line[$k] === "1"; |
|
| 265 | - } |
|
| 266 | - } |
|
| 261 | + // frontend doesn't expect pdo returning booleans as strings on mysql |
|
| 262 | + if (DB_TYPE == "mysql") { |
|
| 263 | + foreach (["unread", "marked", "published"] as $k) { |
|
| 264 | + $line[$k] = $line[$k] === "1"; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - // normalize archived feed |
|
| 269 | - if ($line['feed_id'] === null) { |
|
| 270 | - $line['feed_id'] = 0; |
|
| 271 | - $line["feed_title"] = __("Archived articles"); |
|
| 272 | - } |
|
| 268 | + // normalize archived feed |
|
| 269 | + if ($line['feed_id'] === null) { |
|
| 270 | + $line['feed_id'] = 0; |
|
| 271 | + $line["feed_title"] = __("Archived articles"); |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - $feed_id = $line["feed_id"]; |
|
| 274 | + $feed_id = $line["feed_id"]; |
|
| 275 | 275 | |
| 276 | - $label_cache = $line["label_cache"]; |
|
| 277 | - $labels = false; |
|
| 276 | + $label_cache = $line["label_cache"]; |
|
| 277 | + $labels = false; |
|
| 278 | 278 | |
| 279 | - if ($label_cache) { |
|
| 280 | - $label_cache = json_decode($label_cache, true); |
|
| 279 | + if ($label_cache) { |
|
| 280 | + $label_cache = json_decode($label_cache, true); |
|
| 281 | 281 | |
| 282 | - if ($label_cache) { |
|
| 283 | - if ($label_cache["no-labels"] == 1) { |
|
| 284 | - $labels = array(); |
|
| 285 | - } else { |
|
| 286 | - $labels = $label_cache; |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - } |
|
| 282 | + if ($label_cache) { |
|
| 283 | + if ($label_cache["no-labels"] == 1) { |
|
| 284 | + $labels = array(); |
|
| 285 | + } else { |
|
| 286 | + $labels = $label_cache; |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - if (!is_array($labels)) { |
|
| 292 | - $labels = Article::get_article_labels($id); |
|
| 293 | - } |
|
| 291 | + if (!is_array($labels)) { |
|
| 292 | + $labels = Article::get_article_labels($id); |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | - $labels_str = "<span class=\"HLLCTR-$id\">"; |
|
| 296 | - $labels_str .= Article::format_article_labels($labels); |
|
| 297 | - $labels_str .= "</span>"; |
|
| 295 | + $labels_str = "<span class=\"HLLCTR-$id\">"; |
|
| 296 | + $labels_str .= Article::format_article_labels($labels); |
|
| 297 | + $labels_str .= "</span>"; |
|
| 298 | 298 | |
| 299 | - $line["labels"] = $labels_str; |
|
| 299 | + $line["labels"] = $labels_str; |
|
| 300 | 300 | |
| 301 | - if (count($topmost_article_ids) < 3) { |
|
| 302 | - array_push($topmost_article_ids, $id); |
|
| 303 | - } |
|
| 301 | + if (count($topmost_article_ids) < 3) { |
|
| 302 | + array_push($topmost_article_ids, $id); |
|
| 303 | + } |
|
| 304 | 304 | |
| 305 | - if (!$line["feed_title"]) { |
|
| 306 | - $line["feed_title"] = ""; |
|
| 307 | - } |
|
| 305 | + if (!$line["feed_title"]) { |
|
| 306 | + $line["feed_title"] = ""; |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | 309 | $line["buttons_left"] = ""; |
| 310 | 310 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_LEFT_BUTTON) as $p) { |
@@ -355,346 +355,346 @@ discard block |
||
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - $line["updated_long"] = make_local_datetime($line["updated"], true); |
|
| 359 | - $line["updated"] = make_local_datetime($line["updated"], false, false, false, true); |
|
| 358 | + $line["updated_long"] = make_local_datetime($line["updated"], true); |
|
| 359 | + $line["updated"] = make_local_datetime($line["updated"], false, false, false, true); |
|
| 360 | 360 | |
| 361 | 361 | |
| 362 | - $line['imported'] = T_sprintf("Imported at %s", |
|
| 363 | - make_local_datetime($line["date_entered"], false)); |
|
| 362 | + $line['imported'] = T_sprintf("Imported at %s", |
|
| 363 | + make_local_datetime($line["date_entered"], false)); |
|
| 364 | 364 | |
| 365 | - if ($line["tag_cache"]) { |
|
| 366 | - $tags = explode(",", $line["tag_cache"]); |
|
| 367 | - } else { |
|
| 368 | - $tags = false; |
|
| 369 | - } |
|
| 365 | + if ($line["tag_cache"]) { |
|
| 366 | + $tags = explode(",", $line["tag_cache"]); |
|
| 367 | + } else { |
|
| 368 | + $tags = false; |
|
| 369 | + } |
|
| 370 | 370 | |
| 371 | - $line["tags_str"] = Article::format_tags_string($tags); |
|
| 371 | + $line["tags_str"] = Article::format_tags_string($tags); |
|
| 372 | 372 | |
| 373 | - if (feeds::feedHasIcon($feed_id)) { |
|
| 374 | - $line['feed_icon'] = "<img class=\"icon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">"; |
|
| 375 | - } else { |
|
| 376 | - $line['feed_icon'] = "<i class='icon-no-feed material-icons'>rss_feed</i>"; |
|
| 377 | - } |
|
| 373 | + if (feeds::feedHasIcon($feed_id)) { |
|
| 374 | + $line['feed_icon'] = "<img class=\"icon\" src=\"".ICONS_URL."/$feed_id.ico\" alt=\"\">"; |
|
| 375 | + } else { |
|
| 376 | + $line['feed_icon'] = "<i class='icon-no-feed material-icons'>rss_feed</i>"; |
|
| 377 | + } |
|
| 378 | 378 | |
| 379 | - //setting feed headline background color, needs to change text color based on dark/light |
|
| 380 | - $fav_color = $line['favicon_avg_color']; |
|
| 379 | + //setting feed headline background color, needs to change text color based on dark/light |
|
| 380 | + $fav_color = $line['favicon_avg_color']; |
|
| 381 | 381 | |
| 382 | - require_once "colors.php"; |
|
| 382 | + require_once "colors.php"; |
|
| 383 | 383 | |
| 384 | - if (!isset($rgba_cache[$feed_id])) { |
|
| 385 | - if ($fav_color && $fav_color != 'fail') { |
|
| 386 | - $rgba_cache[$feed_id] = _color_unpack($fav_color); |
|
| 387 | - } else { |
|
| 388 | - $rgba_cache[$feed_id] = _color_unpack($this->color_of($line['feed_title'])); |
|
| 389 | - } |
|
| 390 | - } |
|
| 384 | + if (!isset($rgba_cache[$feed_id])) { |
|
| 385 | + if ($fav_color && $fav_color != 'fail') { |
|
| 386 | + $rgba_cache[$feed_id] = _color_unpack($fav_color); |
|
| 387 | + } else { |
|
| 388 | + $rgba_cache[$feed_id] = _color_unpack($this->color_of($line['feed_title'])); |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | 391 | |
| 392 | - if (isset($rgba_cache[$feed_id])) { |
|
| 393 | - $line['feed_bg_color'] = 'rgba('.implode(",", $rgba_cache[$feed_id]).',0.3)'; |
|
| 392 | + if (isset($rgba_cache[$feed_id])) { |
|
| 393 | + $line['feed_bg_color'] = 'rgba('.implode(",", $rgba_cache[$feed_id]).',0.3)'; |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - /* we don't need those */ |
|
| 396 | + /* we don't need those */ |
|
| 397 | 397 | |
| 398 | 398 | foreach (["date_entered", "guid", "last_published", "last_marked", "tag_cache", "favicon_avg_color", |
| 399 | - "uuid", "label_cache", "yyiw"] as $k) { |
|
| 399 | + "uuid", "label_cache", "yyiw"] as $k) { |
|
| 400 | 400 | unset($line[$k]); |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - array_push($reply['content'], $line); |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - if (!$headlines_count) { |
|
| 408 | - |
|
| 409 | - if (is_object($result)) { |
|
| 410 | - |
|
| 411 | - if ($query_error_override) { |
|
| 412 | - $message = $query_error_override; |
|
| 413 | - } else { |
|
| 414 | - switch ($view_mode) { |
|
| 415 | - case "unread": |
|
| 416 | - $message = __("No unread articles found to display."); |
|
| 417 | - break; |
|
| 418 | - case "updated": |
|
| 419 | - $message = __("No updated articles found to display."); |
|
| 420 | - break; |
|
| 421 | - case "marked": |
|
| 422 | - $message = __("No starred articles found to display."); |
|
| 423 | - break; |
|
| 424 | - default: |
|
| 425 | - if ($feed < LABEL_BASE_INDEX) { |
|
| 426 | - $message = __("No articles found to display. You can assign articles to labels manually from article header context menu (applies to all selected articles) or use a filter."); |
|
| 427 | - } else { |
|
| 428 | - $message = __("No articles found to display."); |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - if (!$offset && $message) { |
|
| 434 | - $reply['content'] = "<div class='whiteBox'>$message"; |
|
| 435 | - |
|
| 436 | - $reply['content'] .= "<p><span class=\"text-muted\">"; |
|
| 437 | - |
|
| 438 | - $sth = $this->pdo->prepare("SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds |
|
| 439 | - WHERE owner_uid = ?"); |
|
| 440 | - $sth->execute([$_SESSION['uid']]); |
|
| 441 | - $row = $sth->fetch(); |
|
| 403 | + array_push($reply['content'], $line); |
|
| 404 | + } |
|
| 405 | + } |
|
| 442 | 406 | |
| 443 | - $last_updated = make_local_datetime($row["last_updated"], false); |
|
| 407 | + if (!$headlines_count) { |
|
| 444 | 408 | |
| 445 | - $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated); |
|
| 409 | + if (is_object($result)) { |
|
| 446 | 410 | |
| 447 | - $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_errors |
|
| 448 | - FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?"); |
|
| 449 | - $sth->execute([$_SESSION['uid']]); |
|
| 450 | - $row = $sth->fetch(); |
|
| 411 | + if ($query_error_override) { |
|
| 412 | + $message = $query_error_override; |
|
| 413 | + } else { |
|
| 414 | + switch ($view_mode) { |
|
| 415 | + case "unread": |
|
| 416 | + $message = __("No unread articles found to display."); |
|
| 417 | + break; |
|
| 418 | + case "updated": |
|
| 419 | + $message = __("No updated articles found to display."); |
|
| 420 | + break; |
|
| 421 | + case "marked": |
|
| 422 | + $message = __("No starred articles found to display."); |
|
| 423 | + break; |
|
| 424 | + default: |
|
| 425 | + if ($feed < LABEL_BASE_INDEX) { |
|
| 426 | + $message = __("No articles found to display. You can assign articles to labels manually from article header context menu (applies to all selected articles) or use a filter."); |
|
| 427 | + } else { |
|
| 428 | + $message = __("No articles found to display."); |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + } |
|
| 451 | 432 | |
| 452 | - $num_errors = $row["num_errors"]; |
|
| 433 | + if (!$offset && $message) { |
|
| 434 | + $reply['content'] = "<div class='whiteBox'>$message"; |
|
| 453 | 435 | |
| 454 | - if ($num_errors > 0) { |
|
| 455 | - $reply['content'] .= "<br/>"; |
|
| 456 | - $reply['content'] .= "<a class=\"text-muted\" href=\"#\" onclick=\"CommonDialogs.showFeedsWithErrors()\">". |
|
| 457 | - __('Some feeds have update errors (click for details)')."</a>"; |
|
| 458 | - } |
|
| 459 | - $reply['content'] .= "</span></p></div>"; |
|
| 436 | + $reply['content'] .= "<p><span class=\"text-muted\">"; |
|
| 460 | 437 | |
| 461 | - } |
|
| 462 | - } else if (is_numeric($result) && $result == -1) { |
|
| 463 | - $reply['first_id_changed'] = true; |
|
| 464 | - } |
|
| 465 | - } |
|
| 438 | + $sth = $this->pdo->prepare("SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds |
|
| 439 | + WHERE owner_uid = ?"); |
|
| 440 | + $sth->execute([$_SESSION['uid']]); |
|
| 441 | + $row = $sth->fetch(); |
|
| 466 | 442 | |
| 467 | - return array($topmost_article_ids, $headlines_count, $feed, $disable_cache, $reply); |
|
| 468 | - } |
|
| 443 | + $last_updated = make_local_datetime($row["last_updated"], false); |
|
| 469 | 444 | |
| 470 | - public function catchupAll() { |
|
| 471 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 472 | - last_read = NOW(), unread = false WHERE unread = true AND owner_uid = ?"); |
|
| 473 | - $sth->execute([$_SESSION['uid']]); |
|
| 445 | + $reply['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated); |
|
| 446 | + |
|
| 447 | + $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_errors |
|
| 448 | + FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?"); |
|
| 449 | + $sth->execute([$_SESSION['uid']]); |
|
| 450 | + $row = $sth->fetch(); |
|
| 474 | 451 | |
| 475 | - CCache::zero_all($_SESSION["uid"]); |
|
| 476 | - } |
|
| 452 | + $num_errors = $row["num_errors"]; |
|
| 477 | 453 | |
| 478 | - public function view() { |
|
| 479 | - $reply = array(); |
|
| 454 | + if ($num_errors > 0) { |
|
| 455 | + $reply['content'] .= "<br/>"; |
|
| 456 | + $reply['content'] .= "<a class=\"text-muted\" href=\"#\" onclick=\"CommonDialogs.showFeedsWithErrors()\">". |
|
| 457 | + __('Some feeds have update errors (click for details)')."</a>"; |
|
| 458 | + } |
|
| 459 | + $reply['content'] .= "</span></p></div>"; |
|
| 480 | 460 | |
| 481 | - $feed = $_REQUEST["feed"]; |
|
| 482 | - $method = $_REQUEST["m"]; |
|
| 483 | - $view_mode = $_REQUEST["view_mode"]; |
|
| 484 | - $limit = 30; |
|
| 485 | - @$cat_view = $_REQUEST["cat"] == "true"; |
|
| 486 | - @$next_unread_feed = $_REQUEST["nuf"]; |
|
| 487 | - @$offset = $_REQUEST["skip"]; |
|
| 488 | - $order_by = $_REQUEST["order_by"]; |
|
| 489 | - $check_first_id = $_REQUEST["fid"]; |
|
| 461 | + } |
|
| 462 | + } else if (is_numeric($result) && $result == -1) { |
|
| 463 | + $reply['first_id_changed'] = true; |
|
| 464 | + } |
|
| 465 | + } |
|
| 490 | 466 | |
| 491 | - if (is_numeric($feed)) { |
|
| 492 | - $feed = (int) $feed; |
|
| 493 | - } |
|
| 467 | + return array($topmost_article_ids, $headlines_count, $feed, $disable_cache, $reply); |
|
| 468 | + } |
|
| 494 | 469 | |
| 495 | - /* Feed -5 is a special case: it is used to display auxiliary information |
|
| 470 | + public function catchupAll() { |
|
| 471 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 472 | + last_read = NOW(), unread = false WHERE unread = true AND owner_uid = ?"); |
|
| 473 | + $sth->execute([$_SESSION['uid']]); |
|
| 474 | + |
|
| 475 | + CCache::zero_all($_SESSION["uid"]); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + public function view() { |
|
| 479 | + $reply = array(); |
|
| 480 | + |
|
| 481 | + $feed = $_REQUEST["feed"]; |
|
| 482 | + $method = $_REQUEST["m"]; |
|
| 483 | + $view_mode = $_REQUEST["view_mode"]; |
|
| 484 | + $limit = 30; |
|
| 485 | + @$cat_view = $_REQUEST["cat"] == "true"; |
|
| 486 | + @$next_unread_feed = $_REQUEST["nuf"]; |
|
| 487 | + @$offset = $_REQUEST["skip"]; |
|
| 488 | + $order_by = $_REQUEST["order_by"]; |
|
| 489 | + $check_first_id = $_REQUEST["fid"]; |
|
| 490 | + |
|
| 491 | + if (is_numeric($feed)) { |
|
| 492 | + $feed = (int) $feed; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + /* Feed -5 is a special case: it is used to display auxiliary information |
|
| 496 | 496 | * when there's nothing to load - e.g. no stuff in fresh feed */ |
| 497 | 497 | |
| 498 | - if ($feed == -5) { |
|
| 499 | - print json_encode($this->generate_dashboard_feed()); |
|
| 500 | - return; |
|
| 501 | - } |
|
| 498 | + if ($feed == -5) { |
|
| 499 | + print json_encode($this->generate_dashboard_feed()); |
|
| 500 | + return; |
|
| 501 | + } |
|
| 502 | 502 | |
| 503 | - $sth = false; |
|
| 504 | - if ($feed < LABEL_BASE_INDEX) { |
|
| 503 | + $sth = false; |
|
| 504 | + if ($feed < LABEL_BASE_INDEX) { |
|
| 505 | 505 | |
| 506 | - $label_feed = Labels::feed_to_label_id($feed); |
|
| 506 | + $label_feed = Labels::feed_to_label_id($feed); |
|
| 507 | 507 | |
| 508 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_labels2 WHERE |
|
| 508 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_labels2 WHERE |
|
| 509 | 509 | id = ? AND owner_uid = ?"); |
| 510 | - $sth->execute([$label_feed, $_SESSION['uid']]); |
|
| 510 | + $sth->execute([$label_feed, $_SESSION['uid']]); |
|
| 511 | 511 | |
| 512 | - } else if (!$cat_view && is_numeric($feed) && $feed > 0) { |
|
| 512 | + } else if (!$cat_view && is_numeric($feed) && $feed > 0) { |
|
| 513 | 513 | |
| 514 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
| 514 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
| 515 | 515 | id = ? AND owner_uid = ?"); |
| 516 | - $sth->execute([$feed, $_SESSION['uid']]); |
|
| 516 | + $sth->execute([$feed, $_SESSION['uid']]); |
|
| 517 | 517 | |
| 518 | - } else if ($cat_view && is_numeric($feed) && $feed > 0) { |
|
| 518 | + } else if ($cat_view && is_numeric($feed) && $feed > 0) { |
|
| 519 | 519 | |
| 520 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories WHERE |
|
| 520 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feed_categories WHERE |
|
| 521 | 521 | id = ? AND owner_uid = ?"); |
| 522 | 522 | |
| 523 | - $sth->execute([$feed, $_SESSION['uid']]); |
|
| 524 | - } |
|
| 523 | + $sth->execute([$feed, $_SESSION['uid']]); |
|
| 524 | + } |
|
| 525 | 525 | |
| 526 | - if ($sth && !$sth->fetch()) { |
|
| 527 | - print json_encode($this->generate_error_feed(__("Feed not found."))); |
|
| 528 | - return; |
|
| 529 | - } |
|
| 526 | + if ($sth && !$sth->fetch()) { |
|
| 527 | + print json_encode($this->generate_error_feed(__("Feed not found."))); |
|
| 528 | + return; |
|
| 529 | + } |
|
| 530 | 530 | |
| 531 | - /* Updating a label ccache means recalculating all of the caches |
|
| 531 | + /* Updating a label ccache means recalculating all of the caches |
|
| 532 | 532 | * so for performance reasons we don't do that here */ |
| 533 | 533 | |
| 534 | - if ($feed >= 0) { |
|
| 535 | - CCache::update($feed, $_SESSION["uid"], $cat_view); |
|
| 536 | - } |
|
| 534 | + if ($feed >= 0) { |
|
| 535 | + CCache::update($feed, $_SESSION["uid"], $cat_view); |
|
| 536 | + } |
|
| 537 | 537 | |
| 538 | - set_pref("_DEFAULT_VIEW_MODE", $view_mode); |
|
| 539 | - set_pref("_DEFAULT_VIEW_ORDER_BY", $order_by); |
|
| 538 | + set_pref("_DEFAULT_VIEW_MODE", $view_mode); |
|
| 539 | + set_pref("_DEFAULT_VIEW_ORDER_BY", $order_by); |
|
| 540 | 540 | |
| 541 | - /* bump login timestamp if needed */ |
|
| 542 | - if (time() - $_SESSION["last_login_update"] > 3600) { |
|
| 543 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET last_login = NOW() WHERE id = ?"); |
|
| 544 | - $sth->execute([$_SESSION['uid']]); |
|
| 541 | + /* bump login timestamp if needed */ |
|
| 542 | + if (time() - $_SESSION["last_login_update"] > 3600) { |
|
| 543 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET last_login = NOW() WHERE id = ?"); |
|
| 544 | + $sth->execute([$_SESSION['uid']]); |
|
| 545 | 545 | |
| 546 | - $_SESSION["last_login_update"] = time(); |
|
| 547 | - } |
|
| 546 | + $_SESSION["last_login_update"] = time(); |
|
| 547 | + } |
|
| 548 | 548 | |
| 549 | - if (!$cat_view && is_numeric($feed) && $feed > 0) { |
|
| 550 | - $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET last_viewed = NOW() |
|
| 549 | + if (!$cat_view && is_numeric($feed) && $feed > 0) { |
|
| 550 | + $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET last_viewed = NOW() |
|
| 551 | 551 | WHERE id = ? AND owner_uid = ?"); |
| 552 | - $sth->execute([$feed, $_SESSION['uid']]); |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - $reply['headlines'] = []; |
|
| 556 | - |
|
| 557 | - $override_order = false; |
|
| 558 | - $skip_first_id_check = false; |
|
| 552 | + $sth->execute([$feed, $_SESSION['uid']]); |
|
| 553 | + } |
|
| 559 | 554 | |
| 560 | - switch ($order_by) { |
|
| 561 | - case "title": |
|
| 562 | - $override_order = "ttrss_entries.title, date_entered, updated"; |
|
| 563 | - break; |
|
| 564 | - case "date_reverse": |
|
| 565 | - $override_order = "score DESC, date_entered, updated"; |
|
| 566 | - $skip_first_id_check = true; |
|
| 567 | - break; |
|
| 568 | - case "feed_dates": |
|
| 569 | - $override_order = "updated DESC"; |
|
| 570 | - break; |
|
| 571 | - } |
|
| 555 | + $reply['headlines'] = []; |
|
| 556 | + |
|
| 557 | + $override_order = false; |
|
| 558 | + $skip_first_id_check = false; |
|
| 559 | + |
|
| 560 | + switch ($order_by) { |
|
| 561 | + case "title": |
|
| 562 | + $override_order = "ttrss_entries.title, date_entered, updated"; |
|
| 563 | + break; |
|
| 564 | + case "date_reverse": |
|
| 565 | + $override_order = "score DESC, date_entered, updated"; |
|
| 566 | + $skip_first_id_check = true; |
|
| 567 | + break; |
|
| 568 | + case "feed_dates": |
|
| 569 | + $override_order = "updated DESC"; |
|
| 570 | + break; |
|
| 571 | + } |
|
| 572 | 572 | |
| 573 | - $ret = $this->format_headlines_list($feed, $method, |
|
| 574 | - $view_mode, $limit, $cat_view, $offset, |
|
| 575 | - $override_order, true, $check_first_id, $skip_first_id_check, $order_by); |
|
| 573 | + $ret = $this->format_headlines_list($feed, $method, |
|
| 574 | + $view_mode, $limit, $cat_view, $offset, |
|
| 575 | + $override_order, true, $check_first_id, $skip_first_id_check, $order_by); |
|
| 576 | 576 | |
| 577 | - $headlines_count = $ret[1]; |
|
| 578 | - $disable_cache = $ret[3]; |
|
| 579 | - $reply['headlines'] = $ret[4]; |
|
| 577 | + $headlines_count = $ret[1]; |
|
| 578 | + $disable_cache = $ret[3]; |
|
| 579 | + $reply['headlines'] = $ret[4]; |
|
| 580 | 580 | |
| 581 | - if (!$next_unread_feed) { |
|
| 582 | - $reply['headlines']['id'] = $feed; |
|
| 583 | - } else { |
|
| 584 | - $reply['headlines']['id'] = $next_unread_feed; |
|
| 585 | - } |
|
| 581 | + if (!$next_unread_feed) { |
|
| 582 | + $reply['headlines']['id'] = $feed; |
|
| 583 | + } else { |
|
| 584 | + $reply['headlines']['id'] = $next_unread_feed; |
|
| 585 | + } |
|
| 586 | 586 | |
| 587 | - $reply['headlines']['is_cat'] = (bool) $cat_view; |
|
| 587 | + $reply['headlines']['is_cat'] = (bool) $cat_view; |
|
| 588 | 588 | |
| 589 | - $reply['headlines-info'] = ["count" => (int) $headlines_count, |
|
| 590 | - "disable_cache" => (bool) $disable_cache]; |
|
| 589 | + $reply['headlines-info'] = ["count" => (int) $headlines_count, |
|
| 590 | + "disable_cache" => (bool) $disable_cache]; |
|
| 591 | 591 | |
| 592 | - // this is parsed by handleRpcJson() on first viewfeed() to set cdm expanded, etc |
|
| 593 | - $reply['runtime-info'] = make_runtime_info(); |
|
| 592 | + // this is parsed by handleRpcJson() on first viewfeed() to set cdm expanded, etc |
|
| 593 | + $reply['runtime-info'] = make_runtime_info(); |
|
| 594 | 594 | |
| 595 | - $reply_json = json_encode($reply); |
|
| 595 | + $reply_json = json_encode($reply); |
|
| 596 | 596 | |
| 597 | - if (!$reply_json) { |
|
| 598 | - $reply_json = json_encode(["error" => ["code" => 15, |
|
| 597 | + if (!$reply_json) { |
|
| 598 | + $reply_json = json_encode(["error" => ["code" => 15, |
|
| 599 | 599 | "message" => json_last_error_msg()]]); |
| 600 | 600 | } |
| 601 | 601 | |
| 602 | - print $reply_json; |
|
| 602 | + print $reply_json; |
|
| 603 | 603 | |
| 604 | - } |
|
| 604 | + } |
|
| 605 | 605 | |
| 606 | - private function generate_dashboard_feed() { |
|
| 607 | - $reply = array(); |
|
| 606 | + private function generate_dashboard_feed() { |
|
| 607 | + $reply = array(); |
|
| 608 | 608 | |
| 609 | - $reply['headlines']['id'] = -5; |
|
| 610 | - $reply['headlines']['is_cat'] = false; |
|
| 609 | + $reply['headlines']['id'] = -5; |
|
| 610 | + $reply['headlines']['is_cat'] = false; |
|
| 611 | 611 | |
| 612 | - $reply['headlines']['toolbar'] = ''; |
|
| 612 | + $reply['headlines']['toolbar'] = ''; |
|
| 613 | 613 | |
| 614 | - $reply['headlines']['content'] = "<div class='whiteBox'>".__('No feed selected.'); |
|
| 614 | + $reply['headlines']['content'] = "<div class='whiteBox'>".__('No feed selected.'); |
|
| 615 | 615 | |
| 616 | - $reply['headlines']['content'] .= "<p><span class=\"text-muted\">"; |
|
| 616 | + $reply['headlines']['content'] .= "<p><span class=\"text-muted\">"; |
|
| 617 | 617 | |
| 618 | - $sth = $this->pdo->prepare("SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds |
|
| 618 | + $sth = $this->pdo->prepare("SELECT ".SUBSTRING_FOR_DATE."(MAX(last_updated), 1, 19) AS last_updated FROM ttrss_feeds |
|
| 619 | 619 | WHERE owner_uid = ?"); |
| 620 | - $sth->execute([$_SESSION['uid']]); |
|
| 621 | - $row = $sth->fetch(); |
|
| 620 | + $sth->execute([$_SESSION['uid']]); |
|
| 621 | + $row = $sth->fetch(); |
|
| 622 | 622 | |
| 623 | - $last_updated = make_local_datetime($row["last_updated"], false); |
|
| 623 | + $last_updated = make_local_datetime($row["last_updated"], false); |
|
| 624 | 624 | |
| 625 | - $reply['headlines']['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated); |
|
| 625 | + $reply['headlines']['content'] .= sprintf(__("Feeds last updated at %s"), $last_updated); |
|
| 626 | 626 | |
| 627 | - $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_errors |
|
| 627 | + $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_errors |
|
| 628 | 628 | FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?"); |
| 629 | - $sth->execute([$_SESSION['uid']]); |
|
| 630 | - $row = $sth->fetch(); |
|
| 629 | + $sth->execute([$_SESSION['uid']]); |
|
| 630 | + $row = $sth->fetch(); |
|
| 631 | 631 | |
| 632 | - $num_errors = $row["num_errors"]; |
|
| 632 | + $num_errors = $row["num_errors"]; |
|
| 633 | 633 | |
| 634 | - if ($num_errors > 0) { |
|
| 635 | - $reply['headlines']['content'] .= "<br/>"; |
|
| 636 | - $reply['headlines']['content'] .= "<a class=\"text-muted\" href=\"#\" onclick=\"CommonDialogs.showFeedsWithErrors()\">". |
|
| 637 | - __('Some feeds have update errors (click for details)')."</a>"; |
|
| 638 | - } |
|
| 639 | - $reply['headlines']['content'] .= "</span></p>"; |
|
| 634 | + if ($num_errors > 0) { |
|
| 635 | + $reply['headlines']['content'] .= "<br/>"; |
|
| 636 | + $reply['headlines']['content'] .= "<a class=\"text-muted\" href=\"#\" onclick=\"CommonDialogs.showFeedsWithErrors()\">". |
|
| 637 | + __('Some feeds have update errors (click for details)')."</a>"; |
|
| 638 | + } |
|
| 639 | + $reply['headlines']['content'] .= "</span></p>"; |
|
| 640 | 640 | |
| 641 | - $reply['headlines-info'] = array("count" => 0, |
|
| 642 | - "unread" => 0, |
|
| 643 | - "disable_cache" => true); |
|
| 641 | + $reply['headlines-info'] = array("count" => 0, |
|
| 642 | + "unread" => 0, |
|
| 643 | + "disable_cache" => true); |
|
| 644 | 644 | |
| 645 | - return $reply; |
|
| 646 | - } |
|
| 645 | + return $reply; |
|
| 646 | + } |
|
| 647 | 647 | |
| 648 | - private function generate_error_feed($error) { |
|
| 649 | - $reply = array(); |
|
| 648 | + private function generate_error_feed($error) { |
|
| 649 | + $reply = array(); |
|
| 650 | 650 | |
| 651 | - $reply['headlines']['id'] = -7; |
|
| 652 | - $reply['headlines']['is_cat'] = false; |
|
| 651 | + $reply['headlines']['id'] = -7; |
|
| 652 | + $reply['headlines']['is_cat'] = false; |
|
| 653 | 653 | |
| 654 | - $reply['headlines']['toolbar'] = ''; |
|
| 655 | - $reply['headlines']['content'] = "<div class='whiteBox'>".$error."</div>"; |
|
| 654 | + $reply['headlines']['toolbar'] = ''; |
|
| 655 | + $reply['headlines']['content'] = "<div class='whiteBox'>".$error."</div>"; |
|
| 656 | 656 | |
| 657 | - $reply['headlines-info'] = array("count" => 0, |
|
| 658 | - "unread" => 0, |
|
| 659 | - "disable_cache" => true); |
|
| 657 | + $reply['headlines-info'] = array("count" => 0, |
|
| 658 | + "unread" => 0, |
|
| 659 | + "disable_cache" => true); |
|
| 660 | 660 | |
| 661 | - return $reply; |
|
| 662 | - } |
|
| 661 | + return $reply; |
|
| 662 | + } |
|
| 663 | 663 | |
| 664 | - public function quickAddFeed() { |
|
| 665 | - print "<form onsubmit='return false'>"; |
|
| 664 | + public function quickAddFeed() { |
|
| 665 | + print "<form onsubmit='return false'>"; |
|
| 666 | 666 | |
| 667 | - print_hidden("op", "rpc"); |
|
| 668 | - print_hidden("method", "addfeed"); |
|
| 667 | + print_hidden("op", "rpc"); |
|
| 668 | + print_hidden("method", "addfeed"); |
|
| 669 | 669 | |
| 670 | - print "<div id='fadd_error_message' style='display : none' class='alert alert-danger'></div>"; |
|
| 670 | + print "<div id='fadd_error_message' style='display : none' class='alert alert-danger'></div>"; |
|
| 671 | 671 | |
| 672 | - print "<div id='fadd_multiple_notify' style='display : none'>"; |
|
| 673 | - print_notice("Provided URL is a HTML page referencing multiple feeds, please select required feed from the dropdown menu below."); |
|
| 674 | - print "<p></div>"; |
|
| 672 | + print "<div id='fadd_multiple_notify' style='display : none'>"; |
|
| 673 | + print_notice("Provided URL is a HTML page referencing multiple feeds, please select required feed from the dropdown menu below."); |
|
| 674 | + print "<p></div>"; |
|
| 675 | 675 | |
| 676 | - print "<section>"; |
|
| 676 | + print "<section>"; |
|
| 677 | 677 | |
| 678 | - print "<fieldset>"; |
|
| 679 | - print "<div style='float : right'><img style='display : none' id='feed_add_spinner' src='images/indicator_white.gif'></div>"; |
|
| 680 | - print "<input style='font-size : 16px; width : 500px;' |
|
| 678 | + print "<fieldset>"; |
|
| 679 | + print "<div style='float : right'><img style='display : none' id='feed_add_spinner' src='images/indicator_white.gif'></div>"; |
|
| 680 | + print "<input style='font-size : 16px; width : 500px;' |
|
| 681 | 681 | placeHolder=\"".__("Feed or site URL")."\" |
| 682 | 682 | dojoType='dijit.form.ValidationTextBox' required='1' name='feed' id='feedDlg_feedUrl'>"; |
| 683 | 683 | |
| 684 | - print "</fieldset>"; |
|
| 684 | + print "</fieldset>"; |
|
| 685 | 685 | |
| 686 | - print "<fieldset>"; |
|
| 686 | + print "<fieldset>"; |
|
| 687 | 687 | |
| 688 | - if (get_pref('ENABLE_FEED_CATS')) { |
|
| 689 | - print "<label class='inline'>".__('Place in category:')."</label> "; |
|
| 690 | - print_feed_cat_select("cat", false, 'dojoType="fox.form.Select"'); |
|
| 691 | - } |
|
| 688 | + if (get_pref('ENABLE_FEED_CATS')) { |
|
| 689 | + print "<label class='inline'>".__('Place in category:')."</label> "; |
|
| 690 | + print_feed_cat_select("cat", false, 'dojoType="fox.form.Select"'); |
|
| 691 | + } |
|
| 692 | 692 | |
| 693 | - print "</fieldset>"; |
|
| 693 | + print "</fieldset>"; |
|
| 694 | 694 | |
| 695 | - print "</section>"; |
|
| 695 | + print "</section>"; |
|
| 696 | 696 | |
| 697 | - print '<div id="feedDlg_feedsContainer" style="display : none"> |
|
| 697 | + print '<div id="feedDlg_feedsContainer" style="display : none"> |
|
| 698 | 698 | <header>' . __('Available feeds').'</header> |
| 699 | 699 | <section> |
| 700 | 700 | <fieldset> |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | </section> |
| 709 | 709 | </div>'; |
| 710 | 710 | |
| 711 | - print "<div id='feedDlg_loginContainer' style='display : none'> |
|
| 711 | + print "<div id='feedDlg_loginContainer' style='display : none'> |
|
| 712 | 712 | <section> |
| 713 | 713 | <fieldset> |
| 714 | 714 | <input dojoType=\"dijit.form.TextBox\" name='login'\" |
@@ -724,98 +724,98 @@ discard block |
||
| 724 | 724 | </section> |
| 725 | 725 | </div>"; |
| 726 | 726 | |
| 727 | - print "<section>"; |
|
| 728 | - print "<label> |
|
| 727 | + print "<section>"; |
|
| 728 | + print "<label> |
|
| 729 | 729 | <label class='checkbox'><input type='checkbox' name='need_auth' dojoType='dijit.form.CheckBox' id='feedDlg_loginCheck' |
| 730 | 730 | onclick='displayIfChecked(this, \"feedDlg_loginContainer\")'> |
| 731 | 731 | ".__('This feed requires authentication.')."</label>"; |
| 732 | - print "</section>"; |
|
| 732 | + print "</section>"; |
|
| 733 | 733 | |
| 734 | - print "<footer>"; |
|
| 735 | - print "<button dojoType='dijit.form.Button' class='alt-primary' type='submit' |
|
| 734 | + print "<footer>"; |
|
| 735 | + print "<button dojoType='dijit.form.Button' class='alt-primary' type='submit' |
|
| 736 | 736 | onclick=\"return dijit.byId('feedAddDlg').execute()\">".__('Subscribe')."</button>"; |
| 737 | 737 | |
| 738 | - print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('feedAddDlg').hide()\">".__('Cancel')."</button>"; |
|
| 739 | - print "</footer>"; |
|
| 738 | + print "<button dojoType='dijit.form.Button' onclick=\"return dijit.byId('feedAddDlg').hide()\">".__('Cancel')."</button>"; |
|
| 739 | + print "</footer>"; |
|
| 740 | 740 | |
| 741 | - print "</form>"; |
|
| 742 | - } |
|
| 741 | + print "</form>"; |
|
| 742 | + } |
|
| 743 | 743 | |
| 744 | - public function search() { |
|
| 745 | - $this->params = explode(":", $_REQUEST["param"], 2); |
|
| 744 | + public function search() { |
|
| 745 | + $this->params = explode(":", $_REQUEST["param"], 2); |
|
| 746 | 746 | |
| 747 | - $active_feed_id = sprintf("%d", $this->params[0]); |
|
| 748 | - $is_cat = $this->params[1] != "false"; |
|
| 747 | + $active_feed_id = sprintf("%d", $this->params[0]); |
|
| 748 | + $is_cat = $this->params[1] != "false"; |
|
| 749 | 749 | |
| 750 | - print "<form onsubmit='return false;'>"; |
|
| 750 | + print "<form onsubmit='return false;'>"; |
|
| 751 | 751 | |
| 752 | - print "<section>"; |
|
| 752 | + print "<section>"; |
|
| 753 | 753 | |
| 754 | - print "<fieldset>"; |
|
| 755 | - print "<input dojoType='dijit.form.ValidationTextBox' id='search_query' |
|
| 754 | + print "<fieldset>"; |
|
| 755 | + print "<input dojoType='dijit.form.ValidationTextBox' id='search_query' |
|
| 756 | 756 | style='font-size : 16px; width : 540px;' |
| 757 | 757 | placeHolder=\"".T_sprintf("Search %s...", $this->getFeedTitle($active_feed_id, $is_cat))."\" |
| 758 | 758 | name='query' type='search' value=''>"; |
| 759 | - print "</fieldset>"; |
|
| 760 | - |
|
| 761 | - if (DB_TYPE == "pgsql") { |
|
| 762 | - print "<fieldset>"; |
|
| 763 | - print "<label class='inline'>".__("Language:")."</label>"; |
|
| 764 | - print_select("search_language", get_pref('DEFAULT_SEARCH_LANGUAGE'), Pref_Feeds::get_ts_languages(), |
|
| 765 | - "dojoType='fox.form.Select' title=\"".__('Used for word stemming')."\""); |
|
| 766 | - print "</fieldset>"; |
|
| 767 | - } |
|
| 759 | + print "</fieldset>"; |
|
| 760 | + |
|
| 761 | + if (DB_TYPE == "pgsql") { |
|
| 762 | + print "<fieldset>"; |
|
| 763 | + print "<label class='inline'>".__("Language:")."</label>"; |
|
| 764 | + print_select("search_language", get_pref('DEFAULT_SEARCH_LANGUAGE'), Pref_Feeds::get_ts_languages(), |
|
| 765 | + "dojoType='fox.form.Select' title=\"".__('Used for word stemming')."\""); |
|
| 766 | + print "</fieldset>"; |
|
| 767 | + } |
|
| 768 | 768 | |
| 769 | - print "</section>"; |
|
| 769 | + print "</section>"; |
|
| 770 | 770 | |
| 771 | - print "<footer>"; |
|
| 771 | + print "<footer>"; |
|
| 772 | 772 | |
| 773 | - if (count(PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH)) == 0) { |
|
| 774 | - print "<button dojoType='dijit.form.Button' style='float : left' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/SearchSyntax\")'> |
|
| 773 | + if (count(PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH)) == 0) { |
|
| 774 | + print "<button dojoType='dijit.form.Button' style='float : left' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/SearchSyntax\")'> |
|
| 775 | 775 | <i class='material-icons'>help</i> ".__("Search syntax")."</button>"; |
| 776 | - } |
|
| 776 | + } |
|
| 777 | 777 | |
| 778 | - print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary' onclick=\"dijit.byId('searchDlg').execute()\">".__('Search')."</button> |
|
| 778 | + print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary' onclick=\"dijit.byId('searchDlg').execute()\">".__('Search')."</button> |
|
| 779 | 779 | <button dojoType='dijit.form.Button' onclick=\"dijit.byId('searchDlg').hide()\">".__('Cancel')."</button>"; |
| 780 | 780 | |
| 781 | - print "</footer>"; |
|
| 781 | + print "</footer>"; |
|
| 782 | 782 | |
| 783 | - print "</form>"; |
|
| 784 | - } |
|
| 783 | + print "</form>"; |
|
| 784 | + } |
|
| 785 | 785 | |
| 786 | - public function update_debugger() { |
|
| 787 | - header("Content-type: text/html"); |
|
| 786 | + public function update_debugger() { |
|
| 787 | + header("Content-type: text/html"); |
|
| 788 | 788 | |
| 789 | - Debug::set_enabled(true); |
|
| 790 | - Debug::set_loglevel($_REQUEST["xdebug"]); |
|
| 789 | + Debug::set_enabled(true); |
|
| 790 | + Debug::set_loglevel($_REQUEST["xdebug"]); |
|
| 791 | 791 | |
| 792 | - $feed_id = (int) $_REQUEST["feed_id"]; |
|
| 793 | - @$do_update = $_REQUEST["action"] == "do_update"; |
|
| 794 | - $csrf_token = $_REQUEST["csrf_token"]; |
|
| 792 | + $feed_id = (int) $_REQUEST["feed_id"]; |
|
| 793 | + @$do_update = $_REQUEST["action"] == "do_update"; |
|
| 794 | + $csrf_token = $_REQUEST["csrf_token"]; |
|
| 795 | 795 | |
| 796 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ? AND owner_uid = ?"); |
|
| 797 | - $sth->execute([$feed_id, $_SESSION['uid']]); |
|
| 796 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ? AND owner_uid = ?"); |
|
| 797 | + $sth->execute([$feed_id, $_SESSION['uid']]); |
|
| 798 | 798 | |
| 799 | - if (!$sth->fetch()) { |
|
| 800 | - print "Access denied."; |
|
| 801 | - return; |
|
| 799 | + if (!$sth->fetch()) { |
|
| 800 | + print "Access denied."; |
|
| 801 | + return; |
|
| 802 | 802 | } |
| 803 | 803 | |
| 804 | - $refetch_checked = isset($_REQUEST["force_refetch"]) ? "checked" : ""; |
|
| 805 | - $rehash_checked = isset($_REQUEST["force_rehash"]) ? "checked" : ""; |
|
| 804 | + $refetch_checked = isset($_REQUEST["force_refetch"]) ? "checked" : ""; |
|
| 805 | + $rehash_checked = isset($_REQUEST["force_rehash"]) ? "checked" : ""; |
|
| 806 | 806 | |
| 807 | - ?> |
|
| 807 | + ?> |
|
| 808 | 808 | <!DOCTYPE html> |
| 809 | 809 | <html> |
| 810 | 810 | <head> |
| 811 | 811 | <?php echo stylesheet_tag("css/default.css") ?> |
| 812 | 812 | <title>Feed Debugger</title> |
| 813 | 813 | <?php |
| 814 | - echo stylesheet_tag("css/default.css"); |
|
| 815 | - echo javascript_tag("lib/prototype.js"); |
|
| 816 | - echo javascript_tag("lib/dojo/dojo.js"); |
|
| 817 | - echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
| 818 | - ?> |
|
| 814 | + echo stylesheet_tag("css/default.css"); |
|
| 815 | + echo javascript_tag("lib/prototype.js"); |
|
| 816 | + echo javascript_tag("lib/dojo/dojo.js"); |
|
| 817 | + echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
| 818 | + ?> |
|
| 819 | 819 | </head> |
| 820 | 820 | <body class="flat ttrss_utility feed_debugger"> |
| 821 | 821 | <script type="text/javascript"> |
@@ -853,930 +853,930 @@ discard block |
||
| 853 | 853 | |
| 854 | 854 | <pre><?php |
| 855 | 855 | |
| 856 | - if ($do_update) { |
|
| 857 | - RSSUtils::update_rss_feed($feed_id, true); |
|
| 858 | - } |
|
| 856 | + if ($do_update) { |
|
| 857 | + RSSUtils::update_rss_feed($feed_id, true); |
|
| 858 | + } |
|
| 859 | 859 | |
| 860 | - ?></pre> |
|
| 860 | + ?></pre> |
|
| 861 | 861 | </div> |
| 862 | 862 | </div> |
| 863 | 863 | </body> |
| 864 | 864 | </html> |
| 865 | 865 | <?php |
| 866 | 866 | |
| 867 | - } |
|
| 868 | - |
|
| 869 | - public static function catchup_feed($feed, $cat_view, $owner_uid = false, $mode = 'all', $search = false) { |
|
| 870 | - |
|
| 871 | - if (!$owner_uid) { |
|
| 872 | - $owner_uid = $_SESSION['uid']; |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - $pdo = Db::pdo(); |
|
| 876 | - |
|
| 877 | - if (is_array($search) && $search[0]) { |
|
| 878 | - $search_qpart = ""; |
|
| 879 | - |
|
| 880 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH) as $plugin) { |
|
| 881 | - list($search_qpart, $search_words) = $plugin->hook_search($search[0]); |
|
| 882 | - break; |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - // fall back in case of no plugins |
|
| 886 | - if (!$search_qpart) { |
|
| 887 | - list($search_qpart, $search_words) = Feeds::search_to_sql($search[0], $search[1]); |
|
| 888 | - } |
|
| 889 | - } else { |
|
| 890 | - $search_qpart = "true"; |
|
| 891 | - } |
|
| 892 | - |
|
| 893 | - // TODO: all this interval stuff needs some generic generator function |
|
| 894 | - |
|
| 895 | - switch ($mode) { |
|
| 896 | - case "1day": |
|
| 897 | - if (DB_TYPE == "pgsql") { |
|
| 898 | - $date_qpart = "date_entered < NOW() - INTERVAL '1 day' "; |
|
| 899 | - } else { |
|
| 900 | - $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY) "; |
|
| 901 | - } |
|
| 902 | - break; |
|
| 903 | - case "1week": |
|
| 904 | - if (DB_TYPE == "pgsql") { |
|
| 905 | - $date_qpart = "date_entered < NOW() - INTERVAL '1 week' "; |
|
| 906 | - } else { |
|
| 907 | - $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 WEEK) "; |
|
| 908 | - } |
|
| 909 | - break; |
|
| 910 | - case "2week": |
|
| 911 | - if (DB_TYPE == "pgsql") { |
|
| 912 | - $date_qpart = "date_entered < NOW() - INTERVAL '2 week' "; |
|
| 913 | - } else { |
|
| 914 | - $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 2 WEEK) "; |
|
| 915 | - } |
|
| 916 | - break; |
|
| 917 | - default: |
|
| 918 | - $date_qpart = "true"; |
|
| 919 | - } |
|
| 920 | - |
|
| 921 | - if (is_numeric($feed)) { |
|
| 922 | - if ($cat_view) { |
|
| 923 | - |
|
| 924 | - if ($feed >= 0) { |
|
| 925 | - |
|
| 926 | - if ($feed > 0) { |
|
| 927 | - $children = Feeds::getChildCategories($feed, $owner_uid); |
|
| 928 | - array_push($children, $feed); |
|
| 929 | - $children = array_map("intval", $children); |
|
| 930 | - |
|
| 931 | - $children = join(",", $children); |
|
| 932 | - |
|
| 933 | - $cat_qpart = "cat_id IN ($children)"; |
|
| 934 | - } else { |
|
| 935 | - $cat_qpart = "cat_id IS NULL"; |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + public static function catchup_feed($feed, $cat_view, $owner_uid = false, $mode = 'all', $search = false) { |
|
| 870 | + |
|
| 871 | + if (!$owner_uid) { |
|
| 872 | + $owner_uid = $_SESSION['uid']; |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + $pdo = Db::pdo(); |
|
| 876 | + |
|
| 877 | + if (is_array($search) && $search[0]) { |
|
| 878 | + $search_qpart = ""; |
|
| 879 | + |
|
| 880 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH) as $plugin) { |
|
| 881 | + list($search_qpart, $search_words) = $plugin->hook_search($search[0]); |
|
| 882 | + break; |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + // fall back in case of no plugins |
|
| 886 | + if (!$search_qpart) { |
|
| 887 | + list($search_qpart, $search_words) = Feeds::search_to_sql($search[0], $search[1]); |
|
| 888 | + } |
|
| 889 | + } else { |
|
| 890 | + $search_qpart = "true"; |
|
| 891 | + } |
|
| 892 | + |
|
| 893 | + // TODO: all this interval stuff needs some generic generator function |
|
| 894 | + |
|
| 895 | + switch ($mode) { |
|
| 896 | + case "1day": |
|
| 897 | + if (DB_TYPE == "pgsql") { |
|
| 898 | + $date_qpart = "date_entered < NOW() - INTERVAL '1 day' "; |
|
| 899 | + } else { |
|
| 900 | + $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY) "; |
|
| 901 | + } |
|
| 902 | + break; |
|
| 903 | + case "1week": |
|
| 904 | + if (DB_TYPE == "pgsql") { |
|
| 905 | + $date_qpart = "date_entered < NOW() - INTERVAL '1 week' "; |
|
| 906 | + } else { |
|
| 907 | + $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 WEEK) "; |
|
| 908 | + } |
|
| 909 | + break; |
|
| 910 | + case "2week": |
|
| 911 | + if (DB_TYPE == "pgsql") { |
|
| 912 | + $date_qpart = "date_entered < NOW() - INTERVAL '2 week' "; |
|
| 913 | + } else { |
|
| 914 | + $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 2 WEEK) "; |
|
| 915 | + } |
|
| 916 | + break; |
|
| 917 | + default: |
|
| 918 | + $date_qpart = "true"; |
|
| 919 | + } |
|
| 920 | + |
|
| 921 | + if (is_numeric($feed)) { |
|
| 922 | + if ($cat_view) { |
|
| 923 | + |
|
| 924 | + if ($feed >= 0) { |
|
| 925 | + |
|
| 926 | + if ($feed > 0) { |
|
| 927 | + $children = Feeds::getChildCategories($feed, $owner_uid); |
|
| 928 | + array_push($children, $feed); |
|
| 929 | + $children = array_map("intval", $children); |
|
| 930 | + |
|
| 931 | + $children = join(",", $children); |
|
| 932 | + |
|
| 933 | + $cat_qpart = "cat_id IN ($children)"; |
|
| 934 | + } else { |
|
| 935 | + $cat_qpart = "cat_id IS NULL"; |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 939 | 939 | SET unread = false, last_read = NOW() WHERE ref_id IN |
| 940 | 940 | (SELECT id FROM |
| 941 | 941 | (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id |
| 942 | 942 | AND owner_uid = ? AND unread = true AND feed_id IN |
| 943 | 943 | (SELECT id FROM ttrss_feeds WHERE $cat_qpart) AND $date_qpart AND $search_qpart) as tmp)"); |
| 944 | - $sth->execute([$owner_uid]); |
|
| 944 | + $sth->execute([$owner_uid]); |
|
| 945 | 945 | |
| 946 | - } else if ($feed == -2) { |
|
| 946 | + } else if ($feed == -2) { |
|
| 947 | 947 | |
| 948 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 948 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 949 | 949 | SET unread = false,last_read = NOW() WHERE (SELECT COUNT(*) |
| 950 | 950 | FROM ttrss_user_labels2, ttrss_entries WHERE article_id = ref_id AND id = ref_id AND $date_qpart AND $search_qpart) > 0 |
| 951 | 951 | AND unread = true AND owner_uid = ?"); |
| 952 | - $sth->execute([$owner_uid]); |
|
| 953 | - } |
|
| 952 | + $sth->execute([$owner_uid]); |
|
| 953 | + } |
|
| 954 | 954 | |
| 955 | - } else if ($feed > 0) { |
|
| 955 | + } else if ($feed > 0) { |
|
| 956 | 956 | |
| 957 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 957 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 958 | 958 | SET unread = false, last_read = NOW() WHERE ref_id IN |
| 959 | 959 | (SELECT id FROM |
| 960 | 960 | (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id |
| 961 | 961 | AND owner_uid = ? AND unread = true AND feed_id = ? AND $date_qpart AND $search_qpart) as tmp)"); |
| 962 | - $sth->execute([$owner_uid, $feed]); |
|
| 962 | + $sth->execute([$owner_uid, $feed]); |
|
| 963 | 963 | |
| 964 | - } else if ($feed < 0 && $feed > LABEL_BASE_INDEX) { // special, like starred |
|
| 964 | + } else if ($feed < 0 && $feed > LABEL_BASE_INDEX) { // special, like starred |
|
| 965 | 965 | |
| 966 | - if ($feed == -1) { |
|
| 967 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 966 | + if ($feed == -1) { |
|
| 967 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 968 | 968 | SET unread = false, last_read = NOW() WHERE ref_id IN |
| 969 | 969 | (SELECT id FROM |
| 970 | 970 | (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id |
| 971 | 971 | AND owner_uid = ? AND unread = true AND marked = true AND $date_qpart AND $search_qpart) as tmp)"); |
| 972 | - $sth->execute([$owner_uid]); |
|
| 973 | - } |
|
| 972 | + $sth->execute([$owner_uid]); |
|
| 973 | + } |
|
| 974 | 974 | |
| 975 | - if ($feed == -2) { |
|
| 976 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 975 | + if ($feed == -2) { |
|
| 976 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 977 | 977 | SET unread = false, last_read = NOW() WHERE ref_id IN |
| 978 | 978 | (SELECT id FROM |
| 979 | 979 | (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id |
| 980 | 980 | AND owner_uid = ? AND unread = true AND published = true AND $date_qpart AND $search_qpart) as tmp)"); |
| 981 | - $sth->execute([$owner_uid]); |
|
| 982 | - } |
|
| 981 | + $sth->execute([$owner_uid]); |
|
| 982 | + } |
|
| 983 | 983 | |
| 984 | - if ($feed == -3) { |
|
| 984 | + if ($feed == -3) { |
|
| 985 | 985 | |
| 986 | - $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE"); |
|
| 986 | + $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE"); |
|
| 987 | 987 | |
| 988 | - if (DB_TYPE == "pgsql") { |
|
| 989 | - $match_part = "date_entered > NOW() - INTERVAL '$intl hour' "; |
|
| 990 | - } else { |
|
| 991 | - $match_part = "date_entered > DATE_SUB(NOW(), |
|
| 988 | + if (DB_TYPE == "pgsql") { |
|
| 989 | + $match_part = "date_entered > NOW() - INTERVAL '$intl hour' "; |
|
| 990 | + } else { |
|
| 991 | + $match_part = "date_entered > DATE_SUB(NOW(), |
|
| 992 | 992 | INTERVAL $intl HOUR) "; |
| 993 | - } |
|
| 993 | + } |
|
| 994 | 994 | |
| 995 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 995 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 996 | 996 | SET unread = false, last_read = NOW() WHERE ref_id IN |
| 997 | 997 | (SELECT id FROM |
| 998 | 998 | (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id |
| 999 | 999 | AND owner_uid = ? AND score >= 0 AND unread = true AND $date_qpart AND $match_part AND $search_qpart) as tmp)"); |
| 1000 | - $sth->execute([$owner_uid]); |
|
| 1001 | - } |
|
| 1000 | + $sth->execute([$owner_uid]); |
|
| 1001 | + } |
|
| 1002 | 1002 | |
| 1003 | - if ($feed == -4) { |
|
| 1004 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 1003 | + if ($feed == -4) { |
|
| 1004 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 1005 | 1005 | SET unread = false, last_read = NOW() WHERE ref_id IN |
| 1006 | 1006 | (SELECT id FROM |
| 1007 | 1007 | (SELECT DISTINCT id FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id |
| 1008 | 1008 | AND owner_uid = ? AND unread = true AND $date_qpart AND $search_qpart) as tmp)"); |
| 1009 | - $sth->execute([$owner_uid]); |
|
| 1010 | - } |
|
| 1009 | + $sth->execute([$owner_uid]); |
|
| 1010 | + } |
|
| 1011 | 1011 | |
| 1012 | - } else if ($feed < LABEL_BASE_INDEX) { // label |
|
| 1012 | + } else if ($feed < LABEL_BASE_INDEX) { // label |
|
| 1013 | 1013 | |
| 1014 | - $label_id = Labels::feed_to_label_id($feed); |
|
| 1014 | + $label_id = Labels::feed_to_label_id($feed); |
|
| 1015 | 1015 | |
| 1016 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 1016 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 1017 | 1017 | SET unread = false, last_read = NOW() WHERE ref_id IN |
| 1018 | 1018 | (SELECT id FROM |
| 1019 | 1019 | (SELECT DISTINCT ttrss_entries.id FROM ttrss_entries, ttrss_user_entries, ttrss_user_labels2 WHERE ref_id = id |
| 1020 | 1020 | AND label_id = ? AND ref_id = article_id |
| 1021 | 1021 | AND owner_uid = ? AND unread = true AND $date_qpart AND $search_qpart) as tmp)"); |
| 1022 | - $sth->execute([$label_id, $owner_uid]); |
|
| 1022 | + $sth->execute([$label_id, $owner_uid]); |
|
| 1023 | 1023 | |
| 1024 | - } |
|
| 1024 | + } |
|
| 1025 | 1025 | |
| 1026 | - CCache::update($feed, $owner_uid, $cat_view); |
|
| 1026 | + CCache::update($feed, $owner_uid, $cat_view); |
|
| 1027 | 1027 | |
| 1028 | - } else { // tag |
|
| 1029 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 1028 | + } else { // tag |
|
| 1029 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 1030 | 1030 | SET unread = false, last_read = NOW() WHERE ref_id IN |
| 1031 | 1031 | (SELECT id FROM |
| 1032 | 1032 | (SELECT DISTINCT ttrss_entries.id FROM ttrss_entries, ttrss_user_entries, ttrss_tags WHERE ref_id = ttrss_entries.id |
| 1033 | 1033 | AND post_int_id = int_id AND tag_name = ? |
| 1034 | 1034 | AND ttrss_user_entries.owner_uid = ? AND unread = true AND $date_qpart AND $search_qpart) as tmp)"); |
| 1035 | - $sth->execute([$feed, $owner_uid]); |
|
| 1035 | + $sth->execute([$feed, $owner_uid]); |
|
| 1036 | 1036 | |
| 1037 | - } |
|
| 1038 | - } |
|
| 1037 | + } |
|
| 1038 | + } |
|
| 1039 | 1039 | |
| 1040 | - public static function getFeedArticles($feed, $is_cat = false, $unread_only = false, |
|
| 1041 | - $owner_uid = false) { |
|
| 1040 | + public static function getFeedArticles($feed, $is_cat = false, $unread_only = false, |
|
| 1041 | + $owner_uid = false) { |
|
| 1042 | 1042 | |
| 1043 | - $n_feed = (int) $feed; |
|
| 1044 | - $need_entries = false; |
|
| 1043 | + $n_feed = (int) $feed; |
|
| 1044 | + $need_entries = false; |
|
| 1045 | 1045 | |
| 1046 | - $pdo = Db::pdo(); |
|
| 1046 | + $pdo = Db::pdo(); |
|
| 1047 | 1047 | |
| 1048 | - if (!$owner_uid) { |
|
| 1049 | - $owner_uid = $_SESSION["uid"]; |
|
| 1050 | - } |
|
| 1048 | + if (!$owner_uid) { |
|
| 1049 | + $owner_uid = $_SESSION["uid"]; |
|
| 1050 | + } |
|
| 1051 | 1051 | |
| 1052 | - if ($unread_only) { |
|
| 1053 | - $unread_qpart = "unread = true"; |
|
| 1054 | - } else { |
|
| 1055 | - $unread_qpart = "true"; |
|
| 1056 | - } |
|
| 1052 | + if ($unread_only) { |
|
| 1053 | + $unread_qpart = "unread = true"; |
|
| 1054 | + } else { |
|
| 1055 | + $unread_qpart = "true"; |
|
| 1056 | + } |
|
| 1057 | 1057 | |
| 1058 | - $match_part = ""; |
|
| 1058 | + $match_part = ""; |
|
| 1059 | 1059 | |
| 1060 | - if ($is_cat) { |
|
| 1061 | - return Feeds::getCategoryUnread($n_feed, $owner_uid); |
|
| 1062 | - } else if ($n_feed == -6) { |
|
| 1063 | - return 0; |
|
| 1064 | - } else if ($feed != "0" && $n_feed == 0) { |
|
| 1060 | + if ($is_cat) { |
|
| 1061 | + return Feeds::getCategoryUnread($n_feed, $owner_uid); |
|
| 1062 | + } else if ($n_feed == -6) { |
|
| 1063 | + return 0; |
|
| 1064 | + } else if ($feed != "0" && $n_feed == 0) { |
|
| 1065 | 1065 | |
| 1066 | - $sth = $pdo->prepare("SELECT SUM((SELECT COUNT(int_id) |
|
| 1066 | + $sth = $pdo->prepare("SELECT SUM((SELECT COUNT(int_id) |
|
| 1067 | 1067 | FROM ttrss_user_entries,ttrss_entries WHERE int_id = post_int_id |
| 1068 | 1068 | AND ref_id = id AND $unread_qpart)) AS count FROM ttrss_tags |
| 1069 | 1069 | WHERE owner_uid = ? AND tag_name = ?"); |
| 1070 | 1070 | |
| 1071 | - $sth->execute([$owner_uid, $feed]); |
|
| 1072 | - $row = $sth->fetch(); |
|
| 1071 | + $sth->execute([$owner_uid, $feed]); |
|
| 1072 | + $row = $sth->fetch(); |
|
| 1073 | 1073 | |
| 1074 | - return $row["count"]; |
|
| 1074 | + return $row["count"]; |
|
| 1075 | 1075 | |
| 1076 | - } else if ($n_feed == -1) { |
|
| 1077 | - $match_part = "marked = true"; |
|
| 1078 | - } else if ($n_feed == -2) { |
|
| 1079 | - $match_part = "published = true"; |
|
| 1080 | - } else if ($n_feed == -3) { |
|
| 1081 | - $match_part = "unread = true AND score >= 0"; |
|
| 1076 | + } else if ($n_feed == -1) { |
|
| 1077 | + $match_part = "marked = true"; |
|
| 1078 | + } else if ($n_feed == -2) { |
|
| 1079 | + $match_part = "published = true"; |
|
| 1080 | + } else if ($n_feed == -3) { |
|
| 1081 | + $match_part = "unread = true AND score >= 0"; |
|
| 1082 | 1082 | |
| 1083 | - $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE", $owner_uid); |
|
| 1083 | + $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE", $owner_uid); |
|
| 1084 | 1084 | |
| 1085 | - if (DB_TYPE == "pgsql") { |
|
| 1086 | - $match_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' "; |
|
| 1087 | - } else { |
|
| 1088 | - $match_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) "; |
|
| 1089 | - } |
|
| 1085 | + if (DB_TYPE == "pgsql") { |
|
| 1086 | + $match_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' "; |
|
| 1087 | + } else { |
|
| 1088 | + $match_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) "; |
|
| 1089 | + } |
|
| 1090 | 1090 | |
| 1091 | - $need_entries = true; |
|
| 1091 | + $need_entries = true; |
|
| 1092 | 1092 | |
| 1093 | - } else if ($n_feed == -4) { |
|
| 1094 | - $match_part = "true"; |
|
| 1095 | - } else if ($n_feed >= 0) { |
|
| 1093 | + } else if ($n_feed == -4) { |
|
| 1094 | + $match_part = "true"; |
|
| 1095 | + } else if ($n_feed >= 0) { |
|
| 1096 | 1096 | |
| 1097 | - if ($n_feed != 0) { |
|
| 1098 | - $match_part = "feed_id = ".(int) $n_feed; |
|
| 1099 | - } else { |
|
| 1100 | - $match_part = "feed_id IS NULL"; |
|
| 1101 | - } |
|
| 1097 | + if ($n_feed != 0) { |
|
| 1098 | + $match_part = "feed_id = ".(int) $n_feed; |
|
| 1099 | + } else { |
|
| 1100 | + $match_part = "feed_id IS NULL"; |
|
| 1101 | + } |
|
| 1102 | 1102 | |
| 1103 | - } else if ($feed < LABEL_BASE_INDEX) { |
|
| 1103 | + } else if ($feed < LABEL_BASE_INDEX) { |
|
| 1104 | 1104 | |
| 1105 | - $label_id = Labels::feed_to_label_id($feed); |
|
| 1105 | + $label_id = Labels::feed_to_label_id($feed); |
|
| 1106 | 1106 | |
| 1107 | - return Feeds::getLabelUnread($label_id, $owner_uid); |
|
| 1108 | - } |
|
| 1107 | + return Feeds::getLabelUnread($label_id, $owner_uid); |
|
| 1108 | + } |
|
| 1109 | 1109 | |
| 1110 | - if ($match_part) { |
|
| 1110 | + if ($match_part) { |
|
| 1111 | 1111 | |
| 1112 | - if ($need_entries) { |
|
| 1113 | - $from_qpart = "ttrss_user_entries,ttrss_entries"; |
|
| 1114 | - $from_where = "ttrss_entries.id = ttrss_user_entries.ref_id AND"; |
|
| 1115 | - } else { |
|
| 1116 | - $from_qpart = "ttrss_user_entries"; |
|
| 1117 | - $from_where = ""; |
|
| 1118 | - } |
|
| 1112 | + if ($need_entries) { |
|
| 1113 | + $from_qpart = "ttrss_user_entries,ttrss_entries"; |
|
| 1114 | + $from_where = "ttrss_entries.id = ttrss_user_entries.ref_id AND"; |
|
| 1115 | + } else { |
|
| 1116 | + $from_qpart = "ttrss_user_entries"; |
|
| 1117 | + $from_where = ""; |
|
| 1118 | + } |
|
| 1119 | 1119 | |
| 1120 | - $sth = $pdo->prepare("SELECT count(int_id) AS unread |
|
| 1120 | + $sth = $pdo->prepare("SELECT count(int_id) AS unread |
|
| 1121 | 1121 | FROM $from_qpart WHERE |
| 1122 | 1122 | $unread_qpart AND $from_where ($match_part) AND ttrss_user_entries.owner_uid = ?"); |
| 1123 | - $sth->execute([$owner_uid]); |
|
| 1124 | - $row = $sth->fetch(); |
|
| 1123 | + $sth->execute([$owner_uid]); |
|
| 1124 | + $row = $sth->fetch(); |
|
| 1125 | 1125 | |
| 1126 | - return $row["unread"]; |
|
| 1126 | + return $row["unread"]; |
|
| 1127 | 1127 | |
| 1128 | - } else { |
|
| 1128 | + } else { |
|
| 1129 | 1129 | |
| 1130 | - $sth = $pdo->prepare("SELECT COUNT(post_int_id) AS unread |
|
| 1130 | + $sth = $pdo->prepare("SELECT COUNT(post_int_id) AS unread |
|
| 1131 | 1131 | FROM ttrss_tags,ttrss_user_entries,ttrss_entries |
| 1132 | 1132 | WHERE tag_name = ? AND post_int_id = int_id AND ref_id = ttrss_entries.id |
| 1133 | 1133 | AND $unread_qpart AND ttrss_tags.owner_uid = ,"); |
| 1134 | 1134 | |
| 1135 | - $sth->execute([$feed, $owner_uid]); |
|
| 1136 | - $row = $sth->fetch(); |
|
| 1137 | - |
|
| 1138 | - return $row["unread"]; |
|
| 1139 | - } |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - /** |
|
| 1143 | - * @return array (code => Status code, message => error message if available) |
|
| 1144 | - * |
|
| 1145 | - * 0 - OK, Feed already exists |
|
| 1146 | - * 1 - OK, Feed added |
|
| 1147 | - * 2 - Invalid URL |
|
| 1148 | - * 3 - URL content is HTML, no feeds available |
|
| 1149 | - * 4 - URL content is HTML which contains multiple feeds. |
|
| 1150 | - * Here you should call extractfeedurls in rpc-backend |
|
| 1151 | - * to get all possible feeds. |
|
| 1152 | - * 5 - Couldn't download the URL content. |
|
| 1153 | - * 6 - Content is an invalid XML. |
|
| 1154 | - */ |
|
| 1155 | - public static function subscribe_to_feed($url, $cat_id = 0, |
|
| 1156 | - $auth_login = '', $auth_pass = '') { |
|
| 1157 | - |
|
| 1158 | - global $fetch_last_error; |
|
| 1159 | - global $fetch_last_error_content; |
|
| 1160 | - global $fetch_last_content_type; |
|
| 1161 | - |
|
| 1162 | - $pdo = Db::pdo(); |
|
| 1163 | - |
|
| 1164 | - $url = Feeds::fix_url($url); |
|
| 1165 | - |
|
| 1166 | - if (!$url || !Feeds::validate_feed_url($url)) { |
|
| 1167 | - return array("code" => 2); |
|
| 1168 | - } |
|
| 1169 | - |
|
| 1170 | - $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass); |
|
| 1171 | - |
|
| 1172 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SUBSCRIBE_FEED) as $plugin) { |
|
| 1173 | - $contents = $plugin->hook_subscribe_feed($contents, $url, $auth_login, $auth_pass); |
|
| 1174 | - } |
|
| 1175 | - |
|
| 1176 | - if (!$contents) { |
|
| 1177 | - if (preg_match("/cloudflare\.com/", $fetch_last_error_content)) { |
|
| 1178 | - $fetch_last_error .= " (feed behind Cloudflare)"; |
|
| 1179 | - } |
|
| 1180 | - |
|
| 1181 | - return array("code" => 5, "message" => $fetch_last_error); |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - if (mb_strpos($fetch_last_content_type, "html") !== false && Feeds::is_html($contents)) { |
|
| 1185 | - $feedUrls = Feeds::get_feeds_from_html($url, $contents); |
|
| 1186 | - |
|
| 1187 | - if (count($feedUrls) == 0) { |
|
| 1188 | - return array("code" => 3); |
|
| 1189 | - } else if (count($feedUrls) > 1) { |
|
| 1190 | - return array("code" => 4, "feeds" => $feedUrls); |
|
| 1191 | - } |
|
| 1192 | - //use feed url as new URL |
|
| 1193 | - $url = key($feedUrls); |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - if (!$cat_id) { |
|
| 1197 | - $cat_id = null; |
|
| 1198 | - } |
|
| 1199 | - |
|
| 1200 | - $sth = $pdo->prepare("SELECT id FROM ttrss_feeds |
|
| 1135 | + $sth->execute([$feed, $owner_uid]); |
|
| 1136 | + $row = $sth->fetch(); |
|
| 1137 | + |
|
| 1138 | + return $row["unread"]; |
|
| 1139 | + } |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + /** |
|
| 1143 | + * @return array (code => Status code, message => error message if available) |
|
| 1144 | + * |
|
| 1145 | + * 0 - OK, Feed already exists |
|
| 1146 | + * 1 - OK, Feed added |
|
| 1147 | + * 2 - Invalid URL |
|
| 1148 | + * 3 - URL content is HTML, no feeds available |
|
| 1149 | + * 4 - URL content is HTML which contains multiple feeds. |
|
| 1150 | + * Here you should call extractfeedurls in rpc-backend |
|
| 1151 | + * to get all possible feeds. |
|
| 1152 | + * 5 - Couldn't download the URL content. |
|
| 1153 | + * 6 - Content is an invalid XML. |
|
| 1154 | + */ |
|
| 1155 | + public static function subscribe_to_feed($url, $cat_id = 0, |
|
| 1156 | + $auth_login = '', $auth_pass = '') { |
|
| 1157 | + |
|
| 1158 | + global $fetch_last_error; |
|
| 1159 | + global $fetch_last_error_content; |
|
| 1160 | + global $fetch_last_content_type; |
|
| 1161 | + |
|
| 1162 | + $pdo = Db::pdo(); |
|
| 1163 | + |
|
| 1164 | + $url = Feeds::fix_url($url); |
|
| 1165 | + |
|
| 1166 | + if (!$url || !Feeds::validate_feed_url($url)) { |
|
| 1167 | + return array("code" => 2); |
|
| 1168 | + } |
|
| 1169 | + |
|
| 1170 | + $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass); |
|
| 1171 | + |
|
| 1172 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SUBSCRIBE_FEED) as $plugin) { |
|
| 1173 | + $contents = $plugin->hook_subscribe_feed($contents, $url, $auth_login, $auth_pass); |
|
| 1174 | + } |
|
| 1175 | + |
|
| 1176 | + if (!$contents) { |
|
| 1177 | + if (preg_match("/cloudflare\.com/", $fetch_last_error_content)) { |
|
| 1178 | + $fetch_last_error .= " (feed behind Cloudflare)"; |
|
| 1179 | + } |
|
| 1180 | + |
|
| 1181 | + return array("code" => 5, "message" => $fetch_last_error); |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + if (mb_strpos($fetch_last_content_type, "html") !== false && Feeds::is_html($contents)) { |
|
| 1185 | + $feedUrls = Feeds::get_feeds_from_html($url, $contents); |
|
| 1186 | + |
|
| 1187 | + if (count($feedUrls) == 0) { |
|
| 1188 | + return array("code" => 3); |
|
| 1189 | + } else if (count($feedUrls) > 1) { |
|
| 1190 | + return array("code" => 4, "feeds" => $feedUrls); |
|
| 1191 | + } |
|
| 1192 | + //use feed url as new URL |
|
| 1193 | + $url = key($feedUrls); |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + if (!$cat_id) { |
|
| 1197 | + $cat_id = null; |
|
| 1198 | + } |
|
| 1199 | + |
|
| 1200 | + $sth = $pdo->prepare("SELECT id FROM ttrss_feeds |
|
| 1201 | 1201 | WHERE feed_url = ? AND owner_uid = ?"); |
| 1202 | - $sth->execute([$url, $_SESSION['uid']]); |
|
| 1202 | + $sth->execute([$url, $_SESSION['uid']]); |
|
| 1203 | 1203 | |
| 1204 | - if ($row = $sth->fetch()) { |
|
| 1205 | - return array("code" => 0, "feed_id" => (int) $row["id"]); |
|
| 1206 | - } else { |
|
| 1207 | - $sth = $pdo->prepare( |
|
| 1208 | - "INSERT INTO ttrss_feeds |
|
| 1204 | + if ($row = $sth->fetch()) { |
|
| 1205 | + return array("code" => 0, "feed_id" => (int) $row["id"]); |
|
| 1206 | + } else { |
|
| 1207 | + $sth = $pdo->prepare( |
|
| 1208 | + "INSERT INTO ttrss_feeds |
|
| 1209 | 1209 | (owner_uid,feed_url,title,cat_id, auth_login,auth_pass,update_method,auth_pass_encrypted) |
| 1210 | 1210 | VALUES (?, ?, ?, ?, ?, ?, 0, false)"); |
| 1211 | 1211 | |
| 1212 | - $sth->execute([$_SESSION['uid'], $url, "[Unknown]", $cat_id, (string) $auth_login, (string) $auth_pass]); |
|
| 1212 | + $sth->execute([$_SESSION['uid'], $url, "[Unknown]", $cat_id, (string) $auth_login, (string) $auth_pass]); |
|
| 1213 | 1213 | |
| 1214 | - $sth = $pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ? |
|
| 1214 | + $sth = $pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ? |
|
| 1215 | 1215 | AND owner_uid = ?"); |
| 1216 | - $sth->execute([$url, $_SESSION['uid']]); |
|
| 1217 | - $row = $sth->fetch(); |
|
| 1218 | - |
|
| 1219 | - $feed_id = $row["id"]; |
|
| 1220 | - |
|
| 1221 | - if ($feed_id) { |
|
| 1222 | - RSSUtils::set_basic_feed_info($feed_id); |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - return array("code" => 1, "feed_id" => (int) $feed_id); |
|
| 1226 | - |
|
| 1227 | - } |
|
| 1228 | - } |
|
| 1229 | - |
|
| 1230 | - public static function getIconFile($feed_id) { |
|
| 1231 | - return ICONS_DIR."/$feed_id.ico"; |
|
| 1232 | - } |
|
| 1233 | - |
|
| 1234 | - public static function feedHasIcon($id) { |
|
| 1235 | - return is_file(ICONS_DIR."/$id.ico") && filesize(ICONS_DIR."/$id.ico") > 0; |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - public static function getFeedIcon($id) { |
|
| 1239 | - switch ($id) { |
|
| 1240 | - case 0: |
|
| 1241 | - return "archive"; |
|
| 1242 | - case -1: |
|
| 1243 | - return "star"; |
|
| 1244 | - case -2: |
|
| 1245 | - return "rss_feed"; |
|
| 1246 | - case -3: |
|
| 1247 | - return "whatshot"; |
|
| 1248 | - case -4: |
|
| 1249 | - return "inbox"; |
|
| 1250 | - case -6: |
|
| 1251 | - return "restore"; |
|
| 1252 | - default: |
|
| 1253 | - if ($id < LABEL_BASE_INDEX) { |
|
| 1254 | - return "label"; |
|
| 1255 | - } else { |
|
| 1256 | - $icon = self::getIconFile($id); |
|
| 1216 | + $sth->execute([$url, $_SESSION['uid']]); |
|
| 1217 | + $row = $sth->fetch(); |
|
| 1218 | + |
|
| 1219 | + $feed_id = $row["id"]; |
|
| 1220 | + |
|
| 1221 | + if ($feed_id) { |
|
| 1222 | + RSSUtils::set_basic_feed_info($feed_id); |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + return array("code" => 1, "feed_id" => (int) $feed_id); |
|
| 1226 | + |
|
| 1227 | + } |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + public static function getIconFile($feed_id) { |
|
| 1231 | + return ICONS_DIR."/$feed_id.ico"; |
|
| 1232 | + } |
|
| 1233 | + |
|
| 1234 | + public static function feedHasIcon($id) { |
|
| 1235 | + return is_file(ICONS_DIR."/$id.ico") && filesize(ICONS_DIR."/$id.ico") > 0; |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + public static function getFeedIcon($id) { |
|
| 1239 | + switch ($id) { |
|
| 1240 | + case 0: |
|
| 1241 | + return "archive"; |
|
| 1242 | + case -1: |
|
| 1243 | + return "star"; |
|
| 1244 | + case -2: |
|
| 1245 | + return "rss_feed"; |
|
| 1246 | + case -3: |
|
| 1247 | + return "whatshot"; |
|
| 1248 | + case -4: |
|
| 1249 | + return "inbox"; |
|
| 1250 | + case -6: |
|
| 1251 | + return "restore"; |
|
| 1252 | + default: |
|
| 1253 | + if ($id < LABEL_BASE_INDEX) { |
|
| 1254 | + return "label"; |
|
| 1255 | + } else { |
|
| 1256 | + $icon = self::getIconFile($id); |
|
| 1257 | 1257 | |
| 1258 | 1258 | if ($icon && file_exists($icon)) { |
| 1259 | - return ICONS_URL."/".basename($icon)."?".filemtime($icon); |
|
| 1260 | - } |
|
| 1261 | - } |
|
| 1262 | - } |
|
| 1263 | - |
|
| 1264 | - return false; |
|
| 1265 | - } |
|
| 1266 | - |
|
| 1267 | - public static function getFeedTitle($id, $cat = false) { |
|
| 1268 | - $pdo = Db::pdo(); |
|
| 1269 | - |
|
| 1270 | - if ($cat) { |
|
| 1271 | - return Feeds::getCategoryTitle($id); |
|
| 1272 | - } else if ($id == -1) { |
|
| 1273 | - return __("Starred articles"); |
|
| 1274 | - } else if ($id == -2) { |
|
| 1275 | - return __("Published articles"); |
|
| 1276 | - } else if ($id == -3) { |
|
| 1277 | - return __("Fresh articles"); |
|
| 1278 | - } else if ($id == -4) { |
|
| 1279 | - return __("All articles"); |
|
| 1280 | - } else if ($id === 0 || $id === "0") { |
|
| 1281 | - return __("Archived articles"); |
|
| 1282 | - } else if ($id == -6) { |
|
| 1283 | - return __("Recently read"); |
|
| 1284 | - } else if ($id < LABEL_BASE_INDEX) { |
|
| 1285 | - |
|
| 1286 | - $label_id = Labels::feed_to_label_id($id); |
|
| 1287 | - |
|
| 1288 | - $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2 WHERE id = ?"); |
|
| 1289 | - $sth->execute([$label_id]); |
|
| 1290 | - |
|
| 1291 | - if ($row = $sth->fetch()) { |
|
| 1292 | - return $row["caption"]; |
|
| 1293 | - } else { |
|
| 1294 | - return "Unknown label ($label_id)"; |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - } else if (is_numeric($id) && $id > 0) { |
|
| 1298 | - |
|
| 1299 | - $sth = $pdo->prepare("SELECT title FROM ttrss_feeds WHERE id = ?"); |
|
| 1300 | - $sth->execute([$id]); |
|
| 1301 | - |
|
| 1302 | - if ($row = $sth->fetch()) { |
|
| 1303 | - return $row["title"]; |
|
| 1304 | - } else { |
|
| 1305 | - return "Unknown feed ($id)"; |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - } else { |
|
| 1309 | - return $id; |
|
| 1310 | - } |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - public static function getCategoryUnread($cat, $owner_uid = false) { |
|
| 1314 | - |
|
| 1315 | - if (!$owner_uid) { |
|
| 1316 | - $owner_uid = $_SESSION["uid"]; |
|
| 1317 | - } |
|
| 1318 | - |
|
| 1319 | - $pdo = Db::pdo(); |
|
| 1320 | - |
|
| 1321 | - if ($cat >= 0) { |
|
| 1322 | - |
|
| 1323 | - if (!$cat) { |
|
| 1324 | - $cat = null; |
|
| 1325 | - } |
|
| 1326 | - |
|
| 1327 | - $sth = $pdo->prepare("SELECT id FROM ttrss_feeds |
|
| 1259 | + return ICONS_URL."/".basename($icon)."?".filemtime($icon); |
|
| 1260 | + } |
|
| 1261 | + } |
|
| 1262 | + } |
|
| 1263 | + |
|
| 1264 | + return false; |
|
| 1265 | + } |
|
| 1266 | + |
|
| 1267 | + public static function getFeedTitle($id, $cat = false) { |
|
| 1268 | + $pdo = Db::pdo(); |
|
| 1269 | + |
|
| 1270 | + if ($cat) { |
|
| 1271 | + return Feeds::getCategoryTitle($id); |
|
| 1272 | + } else if ($id == -1) { |
|
| 1273 | + return __("Starred articles"); |
|
| 1274 | + } else if ($id == -2) { |
|
| 1275 | + return __("Published articles"); |
|
| 1276 | + } else if ($id == -3) { |
|
| 1277 | + return __("Fresh articles"); |
|
| 1278 | + } else if ($id == -4) { |
|
| 1279 | + return __("All articles"); |
|
| 1280 | + } else if ($id === 0 || $id === "0") { |
|
| 1281 | + return __("Archived articles"); |
|
| 1282 | + } else if ($id == -6) { |
|
| 1283 | + return __("Recently read"); |
|
| 1284 | + } else if ($id < LABEL_BASE_INDEX) { |
|
| 1285 | + |
|
| 1286 | + $label_id = Labels::feed_to_label_id($id); |
|
| 1287 | + |
|
| 1288 | + $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2 WHERE id = ?"); |
|
| 1289 | + $sth->execute([$label_id]); |
|
| 1290 | + |
|
| 1291 | + if ($row = $sth->fetch()) { |
|
| 1292 | + return $row["caption"]; |
|
| 1293 | + } else { |
|
| 1294 | + return "Unknown label ($label_id)"; |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + } else if (is_numeric($id) && $id > 0) { |
|
| 1298 | + |
|
| 1299 | + $sth = $pdo->prepare("SELECT title FROM ttrss_feeds WHERE id = ?"); |
|
| 1300 | + $sth->execute([$id]); |
|
| 1301 | + |
|
| 1302 | + if ($row = $sth->fetch()) { |
|
| 1303 | + return $row["title"]; |
|
| 1304 | + } else { |
|
| 1305 | + return "Unknown feed ($id)"; |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + } else { |
|
| 1309 | + return $id; |
|
| 1310 | + } |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + public static function getCategoryUnread($cat, $owner_uid = false) { |
|
| 1314 | + |
|
| 1315 | + if (!$owner_uid) { |
|
| 1316 | + $owner_uid = $_SESSION["uid"]; |
|
| 1317 | + } |
|
| 1318 | + |
|
| 1319 | + $pdo = Db::pdo(); |
|
| 1320 | + |
|
| 1321 | + if ($cat >= 0) { |
|
| 1322 | + |
|
| 1323 | + if (!$cat) { |
|
| 1324 | + $cat = null; |
|
| 1325 | + } |
|
| 1326 | + |
|
| 1327 | + $sth = $pdo->prepare("SELECT id FROM ttrss_feeds |
|
| 1328 | 1328 | WHERE (cat_id = :cat OR (:cat IS NULL AND cat_id IS NULL)) |
| 1329 | 1329 | AND owner_uid = :uid"); |
| 1330 | 1330 | |
| 1331 | - $sth->execute([":cat" => $cat, ":uid" => $owner_uid]); |
|
| 1331 | + $sth->execute([":cat" => $cat, ":uid" => $owner_uid]); |
|
| 1332 | 1332 | |
| 1333 | - $cat_feeds = array(); |
|
| 1334 | - while ($line = $sth->fetch()) { |
|
| 1335 | - array_push($cat_feeds, "feed_id = ".(int) $line["id"]); |
|
| 1336 | - } |
|
| 1333 | + $cat_feeds = array(); |
|
| 1334 | + while ($line = $sth->fetch()) { |
|
| 1335 | + array_push($cat_feeds, "feed_id = ".(int) $line["id"]); |
|
| 1336 | + } |
|
| 1337 | 1337 | |
| 1338 | - if (count($cat_feeds) == 0) { |
|
| 1339 | - return 0; |
|
| 1340 | - } |
|
| 1338 | + if (count($cat_feeds) == 0) { |
|
| 1339 | + return 0; |
|
| 1340 | + } |
|
| 1341 | 1341 | |
| 1342 | - $match_part = implode(" OR ", $cat_feeds); |
|
| 1342 | + $match_part = implode(" OR ", $cat_feeds); |
|
| 1343 | 1343 | |
| 1344 | - $sth = $pdo->prepare("SELECT COUNT(int_id) AS unread |
|
| 1344 | + $sth = $pdo->prepare("SELECT COUNT(int_id) AS unread |
|
| 1345 | 1345 | FROM ttrss_user_entries |
| 1346 | 1346 | WHERE unread = true AND ($match_part) |
| 1347 | 1347 | AND owner_uid = ?"); |
| 1348 | - $sth->execute([$owner_uid]); |
|
| 1348 | + $sth->execute([$owner_uid]); |
|
| 1349 | 1349 | |
| 1350 | - $unread = 0; |
|
| 1350 | + $unread = 0; |
|
| 1351 | 1351 | |
| 1352 | - # this needs to be rewritten |
|
| 1353 | - while ($line = $sth->fetch()) { |
|
| 1354 | - $unread += $line["unread"]; |
|
| 1355 | - } |
|
| 1352 | + # this needs to be rewritten |
|
| 1353 | + while ($line = $sth->fetch()) { |
|
| 1354 | + $unread += $line["unread"]; |
|
| 1355 | + } |
|
| 1356 | 1356 | |
| 1357 | - return $unread; |
|
| 1358 | - } else if ($cat == -1) { |
|
| 1359 | - return getFeedUnread(-1) + getFeedUnread(-2) + getFeedUnread(-3) + getFeedUnread(0); |
|
| 1360 | - } else if ($cat == -2) { |
|
| 1357 | + return $unread; |
|
| 1358 | + } else if ($cat == -1) { |
|
| 1359 | + return getFeedUnread(-1) + getFeedUnread(-2) + getFeedUnread(-3) + getFeedUnread(0); |
|
| 1360 | + } else if ($cat == -2) { |
|
| 1361 | 1361 | |
| 1362 | - $sth = $pdo->prepare("SELECT COUNT(unread) AS unread FROM |
|
| 1362 | + $sth = $pdo->prepare("SELECT COUNT(unread) AS unread FROM |
|
| 1363 | 1363 | ttrss_user_entries, ttrss_user_labels2 |
| 1364 | 1364 | WHERE article_id = ref_id AND unread = true |
| 1365 | 1365 | AND ttrss_user_entries.owner_uid = ?"); |
| 1366 | - $sth->execute([$owner_uid]); |
|
| 1366 | + $sth->execute([$owner_uid]); |
|
| 1367 | 1367 | $row = $sth->fetch(); |
| 1368 | 1368 | |
| 1369 | - return $row["unread"]; |
|
| 1370 | - } |
|
| 1371 | - } |
|
| 1369 | + return $row["unread"]; |
|
| 1370 | + } |
|
| 1371 | + } |
|
| 1372 | 1372 | |
| 1373 | - // only accepts real cats (>= 0) |
|
| 1374 | - public static function getCategoryChildrenUnread($cat, $owner_uid = false) { |
|
| 1375 | - if (!$owner_uid) { |
|
| 1376 | - $owner_uid = $_SESSION["uid"]; |
|
| 1377 | - } |
|
| 1373 | + // only accepts real cats (>= 0) |
|
| 1374 | + public static function getCategoryChildrenUnread($cat, $owner_uid = false) { |
|
| 1375 | + if (!$owner_uid) { |
|
| 1376 | + $owner_uid = $_SESSION["uid"]; |
|
| 1377 | + } |
|
| 1378 | 1378 | |
| 1379 | - $pdo = Db::pdo(); |
|
| 1379 | + $pdo = Db::pdo(); |
|
| 1380 | 1380 | |
| 1381 | - $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories WHERE parent_cat = ? |
|
| 1381 | + $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories WHERE parent_cat = ? |
|
| 1382 | 1382 | AND owner_uid = ?"); |
| 1383 | - $sth->execute([$cat, $owner_uid]); |
|
| 1383 | + $sth->execute([$cat, $owner_uid]); |
|
| 1384 | 1384 | |
| 1385 | - $unread = 0; |
|
| 1385 | + $unread = 0; |
|
| 1386 | 1386 | |
| 1387 | - while ($line = $sth->fetch()) { |
|
| 1388 | - $unread += Feeds::getCategoryUnread($line["id"], $owner_uid); |
|
| 1389 | - $unread += Feeds::getCategoryChildrenUnread($line["id"], $owner_uid); |
|
| 1390 | - } |
|
| 1387 | + while ($line = $sth->fetch()) { |
|
| 1388 | + $unread += Feeds::getCategoryUnread($line["id"], $owner_uid); |
|
| 1389 | + $unread += Feeds::getCategoryChildrenUnread($line["id"], $owner_uid); |
|
| 1390 | + } |
|
| 1391 | 1391 | |
| 1392 | - return $unread; |
|
| 1393 | - } |
|
| 1392 | + return $unread; |
|
| 1393 | + } |
|
| 1394 | 1394 | |
| 1395 | - public static function getGlobalUnread($user_id = false) { |
|
| 1395 | + public static function getGlobalUnread($user_id = false) { |
|
| 1396 | 1396 | |
| 1397 | - if (!$user_id) { |
|
| 1398 | - $user_id = $_SESSION["uid"]; |
|
| 1399 | - } |
|
| 1397 | + if (!$user_id) { |
|
| 1398 | + $user_id = $_SESSION["uid"]; |
|
| 1399 | + } |
|
| 1400 | 1400 | |
| 1401 | - $pdo = Db::pdo(); |
|
| 1401 | + $pdo = Db::pdo(); |
|
| 1402 | 1402 | |
| 1403 | - $sth = $pdo->prepare("SELECT SUM(value) AS c_id FROM ttrss_counters_cache |
|
| 1403 | + $sth = $pdo->prepare("SELECT SUM(value) AS c_id FROM ttrss_counters_cache |
|
| 1404 | 1404 | WHERE owner_uid = ? AND feed_id > 0"); |
| 1405 | - $sth->execute([$user_id]); |
|
| 1406 | - $row = $sth->fetch(); |
|
| 1405 | + $sth->execute([$user_id]); |
|
| 1406 | + $row = $sth->fetch(); |
|
| 1407 | 1407 | |
| 1408 | - return $row["c_id"]; |
|
| 1409 | - } |
|
| 1408 | + return $row["c_id"]; |
|
| 1409 | + } |
|
| 1410 | 1410 | |
| 1411 | - public static function getCategoryTitle($cat_id) { |
|
| 1411 | + public static function getCategoryTitle($cat_id) { |
|
| 1412 | 1412 | |
| 1413 | - if ($cat_id == -1) { |
|
| 1414 | - return __("Special"); |
|
| 1415 | - } else if ($cat_id == -2) { |
|
| 1416 | - return __("Labels"); |
|
| 1417 | - } else { |
|
| 1413 | + if ($cat_id == -1) { |
|
| 1414 | + return __("Special"); |
|
| 1415 | + } else if ($cat_id == -2) { |
|
| 1416 | + return __("Labels"); |
|
| 1417 | + } else { |
|
| 1418 | 1418 | |
| 1419 | - $pdo = Db::pdo(); |
|
| 1419 | + $pdo = Db::pdo(); |
|
| 1420 | 1420 | |
| 1421 | - $sth = $pdo->prepare("SELECT title FROM ttrss_feed_categories WHERE |
|
| 1421 | + $sth = $pdo->prepare("SELECT title FROM ttrss_feed_categories WHERE |
|
| 1422 | 1422 | id = ?"); |
| 1423 | - $sth->execute([$cat_id]); |
|
| 1423 | + $sth->execute([$cat_id]); |
|
| 1424 | 1424 | |
| 1425 | - if ($row = $sth->fetch()) { |
|
| 1426 | - return $row["title"]; |
|
| 1427 | - } else { |
|
| 1428 | - return __("Uncategorized"); |
|
| 1429 | - } |
|
| 1430 | - } |
|
| 1431 | - } |
|
| 1425 | + if ($row = $sth->fetch()) { |
|
| 1426 | + return $row["title"]; |
|
| 1427 | + } else { |
|
| 1428 | + return __("Uncategorized"); |
|
| 1429 | + } |
|
| 1430 | + } |
|
| 1431 | + } |
|
| 1432 | 1432 | |
| 1433 | - public static function getLabelUnread($label_id, $owner_uid = false) { |
|
| 1434 | - if (!$owner_uid) { |
|
| 1435 | - $owner_uid = $_SESSION["uid"]; |
|
| 1436 | - } |
|
| 1433 | + public static function getLabelUnread($label_id, $owner_uid = false) { |
|
| 1434 | + if (!$owner_uid) { |
|
| 1435 | + $owner_uid = $_SESSION["uid"]; |
|
| 1436 | + } |
|
| 1437 | 1437 | |
| 1438 | - $pdo = Db::pdo(); |
|
| 1438 | + $pdo = Db::pdo(); |
|
| 1439 | 1439 | |
| 1440 | - $sth = $pdo->prepare("SELECT COUNT(ref_id) AS unread FROM ttrss_user_entries, ttrss_user_labels2 |
|
| 1440 | + $sth = $pdo->prepare("SELECT COUNT(ref_id) AS unread FROM ttrss_user_entries, ttrss_user_labels2 |
|
| 1441 | 1441 | WHERE owner_uid = ? AND unread = true AND label_id = ? AND article_id = ref_id"); |
| 1442 | 1442 | |
| 1443 | - $sth->execute([$owner_uid, $label_id]); |
|
| 1443 | + $sth->execute([$owner_uid, $label_id]); |
|
| 1444 | 1444 | |
| 1445 | - if ($row = $sth->fetch()) { |
|
| 1446 | - return $row["unread"]; |
|
| 1447 | - } else { |
|
| 1448 | - return 0; |
|
| 1449 | - } |
|
| 1450 | - } |
|
| 1445 | + if ($row = $sth->fetch()) { |
|
| 1446 | + return $row["unread"]; |
|
| 1447 | + } else { |
|
| 1448 | + return 0; |
|
| 1449 | + } |
|
| 1450 | + } |
|
| 1451 | 1451 | |
| 1452 | - public static function queryFeedHeadlines($params) { |
|
| 1452 | + public static function queryFeedHeadlines($params) { |
|
| 1453 | 1453 | |
| 1454 | - $pdo = Db::pdo(); |
|
| 1454 | + $pdo = Db::pdo(); |
|
| 1455 | 1455 | |
| 1456 | - // WARNING: due to highly dynamic nature of this query its going to quote parameters |
|
| 1456 | + // WARNING: due to highly dynamic nature of this query its going to quote parameters |
|
| 1457 | 1457 | // right before adding them to SQL part |
| 1458 | 1458 | |
| 1459 | - $feed = $params["feed"]; |
|
| 1460 | - $limit = isset($params["limit"]) ? $params["limit"] : 30; |
|
| 1461 | - $view_mode = $params["view_mode"]; |
|
| 1462 | - $cat_view = isset($params["cat_view"]) ? $params["cat_view"] : false; |
|
| 1463 | - $search = isset($params["search"]) ? $params["search"] : false; |
|
| 1464 | - $search_language = isset($params["search_language"]) ? $params["search_language"] : ""; |
|
| 1465 | - $override_order = isset($params["override_order"]) ? $params["override_order"] : false; |
|
| 1466 | - $offset = isset($params["offset"]) ? $params["offset"] : 0; |
|
| 1467 | - $owner_uid = isset($params["owner_uid"]) ? $params["owner_uid"] : $_SESSION["uid"]; |
|
| 1468 | - $since_id = isset($params["since_id"]) ? $params["since_id"] : 0; |
|
| 1469 | - $include_children = isset($params["include_children"]) ? $params["include_children"] : false; |
|
| 1470 | - $ignore_vfeed_group = isset($params["ignore_vfeed_group"]) ? $params["ignore_vfeed_group"] : false; |
|
| 1471 | - $override_strategy = isset($params["override_strategy"]) ? $params["override_strategy"] : false; |
|
| 1472 | - $override_vfeed = isset($params["override_vfeed"]) ? $params["override_vfeed"] : false; |
|
| 1473 | - $start_ts = isset($params["start_ts"]) ? $params["start_ts"] : false; |
|
| 1474 | - $check_first_id = isset($params["check_first_id"]) ? $params["check_first_id"] : false; |
|
| 1475 | - $skip_first_id_check = isset($params["skip_first_id_check"]) ? $params["skip_first_id_check"] : false; |
|
| 1476 | - //$order_by = isset($params["order_by"]) ? $params["order_by"] : false; |
|
| 1477 | - |
|
| 1478 | - $ext_tables_part = ""; |
|
| 1479 | - $limit_query_part = ""; |
|
| 1480 | - $query_error_override = ""; |
|
| 1481 | - |
|
| 1482 | - $search_words = []; |
|
| 1483 | - |
|
| 1484 | - if ($search) { |
|
| 1485 | - $search_query_part = ""; |
|
| 1486 | - |
|
| 1487 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH) as $plugin) { |
|
| 1488 | - list($search_query_part, $search_words) = $plugin->hook_search($search); |
|
| 1489 | - break; |
|
| 1490 | - } |
|
| 1491 | - |
|
| 1492 | - // fall back in case of no plugins |
|
| 1493 | - if (!$search_query_part) { |
|
| 1494 | - list($search_query_part, $search_words) = Feeds::search_to_sql($search, $search_language); |
|
| 1495 | - } |
|
| 1496 | - |
|
| 1497 | - if (DB_TYPE == "pgsql") { |
|
| 1498 | - $test_sth = $pdo->prepare("select $search_query_part |
|
| 1459 | + $feed = $params["feed"]; |
|
| 1460 | + $limit = isset($params["limit"]) ? $params["limit"] : 30; |
|
| 1461 | + $view_mode = $params["view_mode"]; |
|
| 1462 | + $cat_view = isset($params["cat_view"]) ? $params["cat_view"] : false; |
|
| 1463 | + $search = isset($params["search"]) ? $params["search"] : false; |
|
| 1464 | + $search_language = isset($params["search_language"]) ? $params["search_language"] : ""; |
|
| 1465 | + $override_order = isset($params["override_order"]) ? $params["override_order"] : false; |
|
| 1466 | + $offset = isset($params["offset"]) ? $params["offset"] : 0; |
|
| 1467 | + $owner_uid = isset($params["owner_uid"]) ? $params["owner_uid"] : $_SESSION["uid"]; |
|
| 1468 | + $since_id = isset($params["since_id"]) ? $params["since_id"] : 0; |
|
| 1469 | + $include_children = isset($params["include_children"]) ? $params["include_children"] : false; |
|
| 1470 | + $ignore_vfeed_group = isset($params["ignore_vfeed_group"]) ? $params["ignore_vfeed_group"] : false; |
|
| 1471 | + $override_strategy = isset($params["override_strategy"]) ? $params["override_strategy"] : false; |
|
| 1472 | + $override_vfeed = isset($params["override_vfeed"]) ? $params["override_vfeed"] : false; |
|
| 1473 | + $start_ts = isset($params["start_ts"]) ? $params["start_ts"] : false; |
|
| 1474 | + $check_first_id = isset($params["check_first_id"]) ? $params["check_first_id"] : false; |
|
| 1475 | + $skip_first_id_check = isset($params["skip_first_id_check"]) ? $params["skip_first_id_check"] : false; |
|
| 1476 | + //$order_by = isset($params["order_by"]) ? $params["order_by"] : false; |
|
| 1477 | + |
|
| 1478 | + $ext_tables_part = ""; |
|
| 1479 | + $limit_query_part = ""; |
|
| 1480 | + $query_error_override = ""; |
|
| 1481 | + |
|
| 1482 | + $search_words = []; |
|
| 1483 | + |
|
| 1484 | + if ($search) { |
|
| 1485 | + $search_query_part = ""; |
|
| 1486 | + |
|
| 1487 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH) as $plugin) { |
|
| 1488 | + list($search_query_part, $search_words) = $plugin->hook_search($search); |
|
| 1489 | + break; |
|
| 1490 | + } |
|
| 1491 | + |
|
| 1492 | + // fall back in case of no plugins |
|
| 1493 | + if (!$search_query_part) { |
|
| 1494 | + list($search_query_part, $search_words) = Feeds::search_to_sql($search, $search_language); |
|
| 1495 | + } |
|
| 1496 | + |
|
| 1497 | + if (DB_TYPE == "pgsql") { |
|
| 1498 | + $test_sth = $pdo->prepare("select $search_query_part |
|
| 1499 | 1499 | FROM ttrss_entries, ttrss_user_entries WHERE id = ref_id limit 1"); |
| 1500 | 1500 | |
| 1501 | - try { |
|
| 1502 | - $test_sth->execute(); |
|
| 1503 | - } catch (PDOException $e) { |
|
| 1504 | - // looks like tsquery syntax is invalid |
|
| 1505 | - $search_query_part = "false"; |
|
| 1501 | + try { |
|
| 1502 | + $test_sth->execute(); |
|
| 1503 | + } catch (PDOException $e) { |
|
| 1504 | + // looks like tsquery syntax is invalid |
|
| 1505 | + $search_query_part = "false"; |
|
| 1506 | 1506 | |
| 1507 | - $query_error_override = T_sprintf("Incorrect search syntax: %s.", implode(" ", $search_words)); |
|
| 1508 | - } |
|
| 1509 | - } |
|
| 1507 | + $query_error_override = T_sprintf("Incorrect search syntax: %s.", implode(" ", $search_words)); |
|
| 1508 | + } |
|
| 1509 | + } |
|
| 1510 | 1510 | |
| 1511 | - $search_query_part .= " AND "; |
|
| 1512 | - } else { |
|
| 1513 | - $search_query_part = ""; |
|
| 1514 | - } |
|
| 1511 | + $search_query_part .= " AND "; |
|
| 1512 | + } else { |
|
| 1513 | + $search_query_part = ""; |
|
| 1514 | + } |
|
| 1515 | 1515 | |
| 1516 | - if ($since_id) { |
|
| 1517 | - $since_id_part = "ttrss_entries.id > ".$pdo->quote($since_id)." AND "; |
|
| 1518 | - } else { |
|
| 1519 | - $since_id_part = ""; |
|
| 1520 | - } |
|
| 1516 | + if ($since_id) { |
|
| 1517 | + $since_id_part = "ttrss_entries.id > ".$pdo->quote($since_id)." AND "; |
|
| 1518 | + } else { |
|
| 1519 | + $since_id_part = ""; |
|
| 1520 | + } |
|
| 1521 | 1521 | |
| 1522 | - $view_query_part = ""; |
|
| 1522 | + $view_query_part = ""; |
|
| 1523 | 1523 | |
| 1524 | - if ($view_mode == "adaptive") { |
|
| 1525 | - if ($search) { |
|
| 1526 | - $view_query_part = " "; |
|
| 1527 | - } else if ($feed != -1) { |
|
| 1524 | + if ($view_mode == "adaptive") { |
|
| 1525 | + if ($search) { |
|
| 1526 | + $view_query_part = " "; |
|
| 1527 | + } else if ($feed != -1) { |
|
| 1528 | 1528 | |
| 1529 | - $unread = getFeedUnread($feed, $cat_view); |
|
| 1529 | + $unread = getFeedUnread($feed, $cat_view); |
|
| 1530 | 1530 | |
| 1531 | - if ($cat_view && $feed > 0 && $include_children) { |
|
| 1532 | - $unread += Feeds::getCategoryChildrenUnread($feed); |
|
| 1533 | - } |
|
| 1531 | + if ($cat_view && $feed > 0 && $include_children) { |
|
| 1532 | + $unread += Feeds::getCategoryChildrenUnread($feed); |
|
| 1533 | + } |
|
| 1534 | 1534 | |
| 1535 | - if ($unread > 0) { |
|
| 1536 | - $view_query_part = " unread = true AND "; |
|
| 1537 | - } |
|
| 1538 | - } |
|
| 1539 | - } |
|
| 1535 | + if ($unread > 0) { |
|
| 1536 | + $view_query_part = " unread = true AND "; |
|
| 1537 | + } |
|
| 1538 | + } |
|
| 1539 | + } |
|
| 1540 | 1540 | |
| 1541 | - if ($view_mode == "marked") { |
|
| 1542 | - $view_query_part = " marked = true AND "; |
|
| 1543 | - } |
|
| 1541 | + if ($view_mode == "marked") { |
|
| 1542 | + $view_query_part = " marked = true AND "; |
|
| 1543 | + } |
|
| 1544 | 1544 | |
| 1545 | - if ($view_mode == "has_note") { |
|
| 1546 | - $view_query_part = " (note IS NOT NULL AND note != '') AND "; |
|
| 1547 | - } |
|
| 1545 | + if ($view_mode == "has_note") { |
|
| 1546 | + $view_query_part = " (note IS NOT NULL AND note != '') AND "; |
|
| 1547 | + } |
|
| 1548 | 1548 | |
| 1549 | - if ($view_mode == "published") { |
|
| 1550 | - $view_query_part = " published = true AND "; |
|
| 1551 | - } |
|
| 1549 | + if ($view_mode == "published") { |
|
| 1550 | + $view_query_part = " published = true AND "; |
|
| 1551 | + } |
|
| 1552 | 1552 | |
| 1553 | - if ($view_mode == "unread" && $feed != -6) { |
|
| 1554 | - $view_query_part = " unread = true AND "; |
|
| 1555 | - } |
|
| 1553 | + if ($view_mode == "unread" && $feed != -6) { |
|
| 1554 | + $view_query_part = " unread = true AND "; |
|
| 1555 | + } |
|
| 1556 | 1556 | |
| 1557 | - if ($limit > 0) { |
|
| 1558 | - $limit_query_part = "LIMIT ".(int) $limit; |
|
| 1559 | - } |
|
| 1557 | + if ($limit > 0) { |
|
| 1558 | + $limit_query_part = "LIMIT ".(int) $limit; |
|
| 1559 | + } |
|
| 1560 | 1560 | |
| 1561 | - $allow_archived = false; |
|
| 1561 | + $allow_archived = false; |
|
| 1562 | 1562 | |
| 1563 | - $vfeed_query_part = ""; |
|
| 1563 | + $vfeed_query_part = ""; |
|
| 1564 | 1564 | |
| 1565 | - /* tags */ |
|
| 1566 | - if (!is_numeric($feed)) { |
|
| 1567 | - $query_strategy_part = "true"; |
|
| 1568 | - $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE |
|
| 1565 | + /* tags */ |
|
| 1566 | + if (!is_numeric($feed)) { |
|
| 1567 | + $query_strategy_part = "true"; |
|
| 1568 | + $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE |
|
| 1569 | 1569 | id = feed_id) as feed_title,"; |
| 1570 | - } else if ($feed > 0) { |
|
| 1571 | - |
|
| 1572 | - if ($cat_view) { |
|
| 1570 | + } else if ($feed > 0) { |
|
| 1573 | 1571 | |
| 1574 | - if ($feed > 0) { |
|
| 1575 | - if ($include_children) { |
|
| 1576 | - # sub-cats |
|
| 1577 | - $subcats = Feeds::getChildCategories($feed, $owner_uid); |
|
| 1578 | - array_push($subcats, $feed); |
|
| 1579 | - $subcats = array_map("intval", $subcats); |
|
| 1572 | + if ($cat_view) { |
|
| 1580 | 1573 | |
| 1581 | - $query_strategy_part = "cat_id IN (". |
|
| 1582 | - implode(",", $subcats).")"; |
|
| 1574 | + if ($feed > 0) { |
|
| 1575 | + if ($include_children) { |
|
| 1576 | + # sub-cats |
|
| 1577 | + $subcats = Feeds::getChildCategories($feed, $owner_uid); |
|
| 1578 | + array_push($subcats, $feed); |
|
| 1579 | + $subcats = array_map("intval", $subcats); |
|
| 1583 | 1580 | |
| 1584 | - } else { |
|
| 1585 | - $query_strategy_part = "cat_id = ".$pdo->quote($feed); |
|
| 1586 | - } |
|
| 1581 | + $query_strategy_part = "cat_id IN (". |
|
| 1582 | + implode(",", $subcats).")"; |
|
| 1587 | 1583 | |
| 1588 | - } else { |
|
| 1589 | - $query_strategy_part = "cat_id IS NULL"; |
|
| 1590 | - } |
|
| 1591 | - |
|
| 1592 | - $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1593 | - |
|
| 1594 | - } else { |
|
| 1595 | - $query_strategy_part = "feed_id = ".$pdo->quote($feed); |
|
| 1596 | - } |
|
| 1597 | - } else if ($feed == 0 && !$cat_view) { // archive virtual feed |
|
| 1598 | - $query_strategy_part = "feed_id IS NULL"; |
|
| 1599 | - $allow_archived = true; |
|
| 1600 | - } else if ($feed == 0 && $cat_view) { // uncategorized |
|
| 1601 | - $query_strategy_part = "cat_id IS NULL AND feed_id IS NOT NULL"; |
|
| 1602 | - $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1603 | - } else if ($feed == -1) { // starred virtual feed |
|
| 1604 | - $query_strategy_part = "marked = true"; |
|
| 1605 | - $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1606 | - $allow_archived = true; |
|
| 1607 | - |
|
| 1608 | - if (!$override_order) { |
|
| 1609 | - $override_order = "last_marked DESC, date_entered DESC, updated DESC"; |
|
| 1610 | - } |
|
| 1611 | - |
|
| 1612 | - } else if ($feed == -2) { // published virtual feed OR labels category |
|
| 1584 | + } else { |
|
| 1585 | + $query_strategy_part = "cat_id = ".$pdo->quote($feed); |
|
| 1586 | + } |
|
| 1613 | 1587 | |
| 1614 | - if (!$cat_view) { |
|
| 1615 | - $query_strategy_part = "published = true"; |
|
| 1616 | - $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1617 | - $allow_archived = true; |
|
| 1588 | + } else { |
|
| 1589 | + $query_strategy_part = "cat_id IS NULL"; |
|
| 1590 | + } |
|
| 1618 | 1591 | |
| 1619 | - if (!$override_order) { |
|
| 1620 | - $override_order = "last_published DESC, date_entered DESC, updated DESC"; |
|
| 1621 | - } |
|
| 1592 | + $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1593 | + |
|
| 1594 | + } else { |
|
| 1595 | + $query_strategy_part = "feed_id = ".$pdo->quote($feed); |
|
| 1596 | + } |
|
| 1597 | + } else if ($feed == 0 && !$cat_view) { // archive virtual feed |
|
| 1598 | + $query_strategy_part = "feed_id IS NULL"; |
|
| 1599 | + $allow_archived = true; |
|
| 1600 | + } else if ($feed == 0 && $cat_view) { // uncategorized |
|
| 1601 | + $query_strategy_part = "cat_id IS NULL AND feed_id IS NOT NULL"; |
|
| 1602 | + $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1603 | + } else if ($feed == -1) { // starred virtual feed |
|
| 1604 | + $query_strategy_part = "marked = true"; |
|
| 1605 | + $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1606 | + $allow_archived = true; |
|
| 1607 | + |
|
| 1608 | + if (!$override_order) { |
|
| 1609 | + $override_order = "last_marked DESC, date_entered DESC, updated DESC"; |
|
| 1610 | + } |
|
| 1611 | + |
|
| 1612 | + } else if ($feed == -2) { // published virtual feed OR labels category |
|
| 1613 | + |
|
| 1614 | + if (!$cat_view) { |
|
| 1615 | + $query_strategy_part = "published = true"; |
|
| 1616 | + $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1617 | + $allow_archived = true; |
|
| 1618 | + |
|
| 1619 | + if (!$override_order) { |
|
| 1620 | + $override_order = "last_published DESC, date_entered DESC, updated DESC"; |
|
| 1621 | + } |
|
| 1622 | 1622 | |
| 1623 | - } else { |
|
| 1624 | - $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1623 | + } else { |
|
| 1624 | + $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1625 | 1625 | |
| 1626 | - $ext_tables_part = "ttrss_labels2,ttrss_user_labels2,"; |
|
| 1626 | + $ext_tables_part = "ttrss_labels2,ttrss_user_labels2,"; |
|
| 1627 | 1627 | |
| 1628 | - $query_strategy_part = "ttrss_labels2.id = ttrss_user_labels2.label_id AND |
|
| 1628 | + $query_strategy_part = "ttrss_labels2.id = ttrss_user_labels2.label_id AND |
|
| 1629 | 1629 | ttrss_user_labels2.article_id = ref_id"; |
| 1630 | 1630 | |
| 1631 | - } |
|
| 1632 | - } else if ($feed == -6) { // recently read |
|
| 1633 | - $query_strategy_part = "unread = false AND last_read IS NOT NULL"; |
|
| 1631 | + } |
|
| 1632 | + } else if ($feed == -6) { // recently read |
|
| 1633 | + $query_strategy_part = "unread = false AND last_read IS NOT NULL"; |
|
| 1634 | 1634 | |
| 1635 | - if (DB_TYPE == "pgsql") { |
|
| 1636 | - $query_strategy_part .= " AND last_read > NOW() - INTERVAL '1 DAY' "; |
|
| 1637 | - } else { |
|
| 1638 | - $query_strategy_part .= " AND last_read > DATE_SUB(NOW(), INTERVAL 1 DAY) "; |
|
| 1639 | - } |
|
| 1635 | + if (DB_TYPE == "pgsql") { |
|
| 1636 | + $query_strategy_part .= " AND last_read > NOW() - INTERVAL '1 DAY' "; |
|
| 1637 | + } else { |
|
| 1638 | + $query_strategy_part .= " AND last_read > DATE_SUB(NOW(), INTERVAL 1 DAY) "; |
|
| 1639 | + } |
|
| 1640 | 1640 | |
| 1641 | - $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1642 | - $allow_archived = true; |
|
| 1643 | - $ignore_vfeed_group = true; |
|
| 1641 | + $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1642 | + $allow_archived = true; |
|
| 1643 | + $ignore_vfeed_group = true; |
|
| 1644 | 1644 | |
| 1645 | - if (!$override_order) { |
|
| 1646 | - $override_order = "last_read DESC"; |
|
| 1647 | - } |
|
| 1645 | + if (!$override_order) { |
|
| 1646 | + $override_order = "last_read DESC"; |
|
| 1647 | + } |
|
| 1648 | 1648 | |
| 1649 | - } else if ($feed == -3) { // fresh virtual feed |
|
| 1650 | - $query_strategy_part = "unread = true AND score >= 0"; |
|
| 1649 | + } else if ($feed == -3) { // fresh virtual feed |
|
| 1650 | + $query_strategy_part = "unread = true AND score >= 0"; |
|
| 1651 | 1651 | |
| 1652 | - $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE", $owner_uid); |
|
| 1652 | + $intl = (int) get_pref("FRESH_ARTICLE_MAX_AGE", $owner_uid); |
|
| 1653 | 1653 | |
| 1654 | - if (DB_TYPE == "pgsql") { |
|
| 1655 | - $query_strategy_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' "; |
|
| 1656 | - } else { |
|
| 1657 | - $query_strategy_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) "; |
|
| 1658 | - } |
|
| 1654 | + if (DB_TYPE == "pgsql") { |
|
| 1655 | + $query_strategy_part .= " AND date_entered > NOW() - INTERVAL '$intl hour' "; |
|
| 1656 | + } else { |
|
| 1657 | + $query_strategy_part .= " AND date_entered > DATE_SUB(NOW(), INTERVAL $intl HOUR) "; |
|
| 1658 | + } |
|
| 1659 | 1659 | |
| 1660 | - $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1661 | - } else if ($feed == -4) { // all articles virtual feed |
|
| 1662 | - $allow_archived = true; |
|
| 1663 | - $query_strategy_part = "true"; |
|
| 1664 | - $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1665 | - } else if ($feed <= LABEL_BASE_INDEX) { // labels |
|
| 1666 | - $label_id = Labels::feed_to_label_id($feed); |
|
| 1660 | + $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1661 | + } else if ($feed == -4) { // all articles virtual feed |
|
| 1662 | + $allow_archived = true; |
|
| 1663 | + $query_strategy_part = "true"; |
|
| 1664 | + $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1665 | + } else if ($feed <= LABEL_BASE_INDEX) { // labels |
|
| 1666 | + $label_id = Labels::feed_to_label_id($feed); |
|
| 1667 | 1667 | |
| 1668 | - $query_strategy_part = "label_id = ".$pdo->quote($label_id)." AND |
|
| 1668 | + $query_strategy_part = "label_id = ".$pdo->quote($label_id)." AND |
|
| 1669 | 1669 | ttrss_labels2.id = ttrss_user_labels2.label_id AND |
| 1670 | 1670 | ttrss_user_labels2.article_id = ref_id"; |
| 1671 | 1671 | |
| 1672 | - $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1673 | - $ext_tables_part = "ttrss_labels2,ttrss_user_labels2,"; |
|
| 1674 | - $allow_archived = true; |
|
| 1672 | + $vfeed_query_part = "ttrss_feeds.title AS feed_title,"; |
|
| 1673 | + $ext_tables_part = "ttrss_labels2,ttrss_user_labels2,"; |
|
| 1674 | + $allow_archived = true; |
|
| 1675 | 1675 | |
| 1676 | - } else { |
|
| 1677 | - $query_strategy_part = "true"; |
|
| 1678 | - } |
|
| 1676 | + } else { |
|
| 1677 | + $query_strategy_part = "true"; |
|
| 1678 | + } |
|
| 1679 | 1679 | |
| 1680 | - $order_by = "score DESC, date_entered DESC, updated DESC"; |
|
| 1680 | + $order_by = "score DESC, date_entered DESC, updated DESC"; |
|
| 1681 | 1681 | |
| 1682 | - if ($override_order) { |
|
| 1683 | - $order_by = $override_order; |
|
| 1684 | - } |
|
| 1682 | + if ($override_order) { |
|
| 1683 | + $order_by = $override_order; |
|
| 1684 | + } |
|
| 1685 | 1685 | |
| 1686 | - if ($override_strategy) { |
|
| 1687 | - $query_strategy_part = $override_strategy; |
|
| 1688 | - } |
|
| 1686 | + if ($override_strategy) { |
|
| 1687 | + $query_strategy_part = $override_strategy; |
|
| 1688 | + } |
|
| 1689 | 1689 | |
| 1690 | - if ($override_vfeed) { |
|
| 1691 | - $vfeed_query_part = $override_vfeed; |
|
| 1692 | - } |
|
| 1690 | + if ($override_vfeed) { |
|
| 1691 | + $vfeed_query_part = $override_vfeed; |
|
| 1692 | + } |
|
| 1693 | 1693 | |
| 1694 | - if ($search) { |
|
| 1695 | - $feed_title = T_sprintf("Search results: %s", $search); |
|
| 1696 | - } else { |
|
| 1697 | - if ($cat_view) { |
|
| 1698 | - $feed_title = Feeds::getCategoryTitle($feed); |
|
| 1699 | - } else { |
|
| 1700 | - if (is_numeric($feed) && $feed > 0) { |
|
| 1701 | - $ssth = $pdo->prepare("SELECT title,site_url,last_error,last_updated |
|
| 1694 | + if ($search) { |
|
| 1695 | + $feed_title = T_sprintf("Search results: %s", $search); |
|
| 1696 | + } else { |
|
| 1697 | + if ($cat_view) { |
|
| 1698 | + $feed_title = Feeds::getCategoryTitle($feed); |
|
| 1699 | + } else { |
|
| 1700 | + if (is_numeric($feed) && $feed > 0) { |
|
| 1701 | + $ssth = $pdo->prepare("SELECT title,site_url,last_error,last_updated |
|
| 1702 | 1702 | FROM ttrss_feeds WHERE id = ? AND owner_uid = ?"); |
| 1703 | - $ssth->execute([$feed, $owner_uid]); |
|
| 1703 | + $ssth->execute([$feed, $owner_uid]); |
|
| 1704 | 1704 | $row = $ssth->fetch(); |
| 1705 | 1705 | |
| 1706 | - $feed_title = $row["title"]; |
|
| 1707 | - $feed_site_url = $row["site_url"]; |
|
| 1708 | - $last_error = $row["last_error"]; |
|
| 1709 | - $last_updated = $row["last_updated"]; |
|
| 1710 | - } else { |
|
| 1711 | - $feed_title = Feeds::getFeedTitle($feed); |
|
| 1712 | - } |
|
| 1713 | - } |
|
| 1714 | - } |
|
| 1715 | - |
|
| 1716 | - $content_query_part = "content, "; |
|
| 1717 | - |
|
| 1718 | - if ($limit_query_part) { |
|
| 1719 | - $offset_query_part = "OFFSET ".(int) $offset; |
|
| 1720 | - } else { |
|
| 1721 | - $offset_query_part = ""; |
|
| 1722 | - } |
|
| 1723 | - |
|
| 1724 | - if ($start_ts) { |
|
| 1725 | - $start_ts_formatted = date("Y/m/d H:i:s", strtotime($start_ts)); |
|
| 1726 | - $start_ts_query_part = "date_entered >= '$start_ts_formatted' AND"; |
|
| 1727 | - } else { |
|
| 1728 | - $start_ts_query_part = ""; |
|
| 1729 | - } |
|
| 1730 | - |
|
| 1731 | - if (is_numeric($feed)) { |
|
| 1732 | - // proper override_order applied above |
|
| 1733 | - if ($vfeed_query_part && !$ignore_vfeed_group && get_pref('VFEED_GROUP_BY_FEED', $owner_uid)) { |
|
| 1734 | - |
|
| 1735 | - if (!(in_array($feed, Feeds::NEVER_GROUP_BY_DATE) && !$cat_view)) { |
|
| 1736 | - $yyiw_desc = $order_by == "date_reverse" ? "" : "desc"; |
|
| 1737 | - $yyiw_order_qpart = "yyiw $yyiw_desc, "; |
|
| 1738 | - } else { |
|
| 1739 | - $yyiw_order_qpart = ""; |
|
| 1740 | - } |
|
| 1741 | - |
|
| 1742 | - if (!$override_order) { |
|
| 1743 | - $order_by = "$yyiw_order_qpart ttrss_feeds.title, $order_by"; |
|
| 1744 | - } else { |
|
| 1745 | - $order_by = "$yyiw_order_qpart ttrss_feeds.title, $override_order"; |
|
| 1746 | - } |
|
| 1747 | - } |
|
| 1748 | - |
|
| 1749 | - if (!$allow_archived) { |
|
| 1750 | - $from_qpart = "${ext_tables_part}ttrss_entries LEFT JOIN ttrss_user_entries ON (ref_id = ttrss_entries.id),ttrss_feeds"; |
|
| 1751 | - $feed_check_qpart = "ttrss_user_entries.feed_id = ttrss_feeds.id AND"; |
|
| 1752 | - |
|
| 1753 | - } else { |
|
| 1754 | - $from_qpart = "${ext_tables_part}ttrss_entries LEFT JOIN ttrss_user_entries ON (ref_id = ttrss_entries.id) |
|
| 1706 | + $feed_title = $row["title"]; |
|
| 1707 | + $feed_site_url = $row["site_url"]; |
|
| 1708 | + $last_error = $row["last_error"]; |
|
| 1709 | + $last_updated = $row["last_updated"]; |
|
| 1710 | + } else { |
|
| 1711 | + $feed_title = Feeds::getFeedTitle($feed); |
|
| 1712 | + } |
|
| 1713 | + } |
|
| 1714 | + } |
|
| 1715 | + |
|
| 1716 | + $content_query_part = "content, "; |
|
| 1717 | + |
|
| 1718 | + if ($limit_query_part) { |
|
| 1719 | + $offset_query_part = "OFFSET ".(int) $offset; |
|
| 1720 | + } else { |
|
| 1721 | + $offset_query_part = ""; |
|
| 1722 | + } |
|
| 1723 | + |
|
| 1724 | + if ($start_ts) { |
|
| 1725 | + $start_ts_formatted = date("Y/m/d H:i:s", strtotime($start_ts)); |
|
| 1726 | + $start_ts_query_part = "date_entered >= '$start_ts_formatted' AND"; |
|
| 1727 | + } else { |
|
| 1728 | + $start_ts_query_part = ""; |
|
| 1729 | + } |
|
| 1730 | + |
|
| 1731 | + if (is_numeric($feed)) { |
|
| 1732 | + // proper override_order applied above |
|
| 1733 | + if ($vfeed_query_part && !$ignore_vfeed_group && get_pref('VFEED_GROUP_BY_FEED', $owner_uid)) { |
|
| 1734 | + |
|
| 1735 | + if (!(in_array($feed, Feeds::NEVER_GROUP_BY_DATE) && !$cat_view)) { |
|
| 1736 | + $yyiw_desc = $order_by == "date_reverse" ? "" : "desc"; |
|
| 1737 | + $yyiw_order_qpart = "yyiw $yyiw_desc, "; |
|
| 1738 | + } else { |
|
| 1739 | + $yyiw_order_qpart = ""; |
|
| 1740 | + } |
|
| 1741 | + |
|
| 1742 | + if (!$override_order) { |
|
| 1743 | + $order_by = "$yyiw_order_qpart ttrss_feeds.title, $order_by"; |
|
| 1744 | + } else { |
|
| 1745 | + $order_by = "$yyiw_order_qpart ttrss_feeds.title, $override_order"; |
|
| 1746 | + } |
|
| 1747 | + } |
|
| 1748 | + |
|
| 1749 | + if (!$allow_archived) { |
|
| 1750 | + $from_qpart = "${ext_tables_part}ttrss_entries LEFT JOIN ttrss_user_entries ON (ref_id = ttrss_entries.id),ttrss_feeds"; |
|
| 1751 | + $feed_check_qpart = "ttrss_user_entries.feed_id = ttrss_feeds.id AND"; |
|
| 1752 | + |
|
| 1753 | + } else { |
|
| 1754 | + $from_qpart = "${ext_tables_part}ttrss_entries LEFT JOIN ttrss_user_entries ON (ref_id = ttrss_entries.id) |
|
| 1755 | 1755 | LEFT JOIN ttrss_feeds ON (feed_id = ttrss_feeds.id)"; |
| 1756 | - } |
|
| 1757 | - |
|
| 1758 | - if ($vfeed_query_part) { |
|
| 1759 | - $vfeed_query_part .= "favicon_avg_color,"; |
|
| 1760 | - } |
|
| 1761 | - |
|
| 1762 | - $first_id = 0; |
|
| 1763 | - $first_id_query_strategy_part = $query_strategy_part; |
|
| 1764 | - |
|
| 1765 | - if ($feed == -3) { |
|
| 1766 | - $first_id_query_strategy_part = "true"; |
|
| 1767 | - } |
|
| 1768 | - |
|
| 1769 | - if (DB_TYPE == "pgsql") { |
|
| 1770 | - $sanity_interval_qpart = "date_entered >= NOW() - INTERVAL '1 hour' AND"; |
|
| 1771 | - $yyiw_qpart = "to_char(date_entered, 'IYYY-IW') AS yyiw"; |
|
| 1772 | - } else { |
|
| 1773 | - $sanity_interval_qpart = "date_entered >= DATE_SUB(NOW(), INTERVAL 1 hour) AND"; |
|
| 1774 | - $yyiw_qpart = "date_format(date_entered, '%Y-%u') AS yyiw"; |
|
| 1775 | - } |
|
| 1776 | - |
|
| 1777 | - if (!$search && !$skip_first_id_check) { |
|
| 1778 | - // if previous topmost article id changed that means our current pagination is no longer valid |
|
| 1779 | - $query = "SELECT DISTINCT |
|
| 1756 | + } |
|
| 1757 | + |
|
| 1758 | + if ($vfeed_query_part) { |
|
| 1759 | + $vfeed_query_part .= "favicon_avg_color,"; |
|
| 1760 | + } |
|
| 1761 | + |
|
| 1762 | + $first_id = 0; |
|
| 1763 | + $first_id_query_strategy_part = $query_strategy_part; |
|
| 1764 | + |
|
| 1765 | + if ($feed == -3) { |
|
| 1766 | + $first_id_query_strategy_part = "true"; |
|
| 1767 | + } |
|
| 1768 | + |
|
| 1769 | + if (DB_TYPE == "pgsql") { |
|
| 1770 | + $sanity_interval_qpart = "date_entered >= NOW() - INTERVAL '1 hour' AND"; |
|
| 1771 | + $yyiw_qpart = "to_char(date_entered, 'IYYY-IW') AS yyiw"; |
|
| 1772 | + } else { |
|
| 1773 | + $sanity_interval_qpart = "date_entered >= DATE_SUB(NOW(), INTERVAL 1 hour) AND"; |
|
| 1774 | + $yyiw_qpart = "date_format(date_entered, '%Y-%u') AS yyiw"; |
|
| 1775 | + } |
|
| 1776 | + |
|
| 1777 | + if (!$search && !$skip_first_id_check) { |
|
| 1778 | + // if previous topmost article id changed that means our current pagination is no longer valid |
|
| 1779 | + $query = "SELECT DISTINCT |
|
| 1780 | 1780 | ttrss_feeds.title, |
| 1781 | 1781 | date_entered, |
| 1782 | 1782 | $yyiw_qpart, |
@@ -1801,22 +1801,22 @@ discard block |
||
| 1801 | 1801 | $sanity_interval_qpart |
| 1802 | 1802 | $first_id_query_strategy_part ORDER BY $order_by LIMIT 1"; |
| 1803 | 1803 | |
| 1804 | - /*if ($_REQUEST["debug"]) { |
|
| 1804 | + /*if ($_REQUEST["debug"]) { |
|
| 1805 | 1805 | print $query; |
| 1806 | 1806 | }*/ |
| 1807 | 1807 | |
| 1808 | - $res = $pdo->query($query); |
|
| 1808 | + $res = $pdo->query($query); |
|
| 1809 | 1809 | |
| 1810 | - if ($row = $res->fetch()) { |
|
| 1811 | - $first_id = (int) $row["id"]; |
|
| 1810 | + if ($row = $res->fetch()) { |
|
| 1811 | + $first_id = (int) $row["id"]; |
|
| 1812 | 1812 | |
| 1813 | - if ($offset > 0 && $first_id && $check_first_id && $first_id != $check_first_id) { |
|
| 1814 | - return array(-1, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words, $first_id, $vfeed_query_part != "", $query_error_override); |
|
| 1815 | - } |
|
| 1816 | - } |
|
| 1817 | - } |
|
| 1813 | + if ($offset > 0 && $first_id && $check_first_id && $first_id != $check_first_id) { |
|
| 1814 | + return array(-1, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words, $first_id, $vfeed_query_part != "", $query_error_override); |
|
| 1815 | + } |
|
| 1816 | + } |
|
| 1817 | + } |
|
| 1818 | 1818 | |
| 1819 | - $query = "SELECT DISTINCT |
|
| 1819 | + $query = "SELECT DISTINCT |
|
| 1820 | 1820 | date_entered, |
| 1821 | 1821 | $yyiw_qpart, |
| 1822 | 1822 | guid, |
@@ -1850,14 +1850,14 @@ discard block |
||
| 1850 | 1850 | $query_strategy_part ORDER BY $order_by |
| 1851 | 1851 | $limit_query_part $offset_query_part"; |
| 1852 | 1852 | |
| 1853 | - //if ($_REQUEST["debug"]) print $query; |
|
| 1853 | + //if ($_REQUEST["debug"]) print $query; |
|
| 1854 | 1854 | |
| 1855 | - $res = $pdo->query($query); |
|
| 1855 | + $res = $pdo->query($query); |
|
| 1856 | 1856 | |
| 1857 | - } else { |
|
| 1858 | - // browsing by tag |
|
| 1857 | + } else { |
|
| 1858 | + // browsing by tag |
|
| 1859 | 1859 | |
| 1860 | - $query = "SELECT DISTINCT |
|
| 1860 | + $query = "SELECT DISTINCT |
|
| 1861 | 1861 | date_entered, |
| 1862 | 1862 | guid, |
| 1863 | 1863 | note, |
@@ -1896,65 +1896,65 @@ discard block |
||
| 1896 | 1896 | $query_strategy_part ORDER BY $order_by |
| 1897 | 1897 | $limit_query_part $offset_query_part"; |
| 1898 | 1898 | |
| 1899 | - if ($_REQUEST["debug"]) { |
|
| 1900 | - print $query; |
|
| 1901 | - } |
|
| 1899 | + if ($_REQUEST["debug"]) { |
|
| 1900 | + print $query; |
|
| 1901 | + } |
|
| 1902 | 1902 | |
| 1903 | - $res = $pdo->query($query); |
|
| 1904 | - } |
|
| 1903 | + $res = $pdo->query($query); |
|
| 1904 | + } |
|
| 1905 | 1905 | |
| 1906 | - return array($res, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words, $first_id, $vfeed_query_part != "", $query_error_override); |
|
| 1906 | + return array($res, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words, $first_id, $vfeed_query_part != "", $query_error_override); |
|
| 1907 | 1907 | |
| 1908 | - } |
|
| 1908 | + } |
|
| 1909 | 1909 | |
| 1910 | - public static function getParentCategories($cat, $owner_uid) { |
|
| 1911 | - $rv = array(); |
|
| 1910 | + public static function getParentCategories($cat, $owner_uid) { |
|
| 1911 | + $rv = array(); |
|
| 1912 | 1912 | |
| 1913 | - $pdo = Db::pdo(); |
|
| 1913 | + $pdo = Db::pdo(); |
|
| 1914 | 1914 | |
| 1915 | - $sth = $pdo->prepare("SELECT parent_cat FROM ttrss_feed_categories |
|
| 1915 | + $sth = $pdo->prepare("SELECT parent_cat FROM ttrss_feed_categories |
|
| 1916 | 1916 | WHERE id = ? AND parent_cat IS NOT NULL AND owner_uid = ?"); |
| 1917 | - $sth->execute([$cat, $owner_uid]); |
|
| 1917 | + $sth->execute([$cat, $owner_uid]); |
|
| 1918 | 1918 | |
| 1919 | - while ($line = $sth->fetch()) { |
|
| 1920 | - array_push($rv, $line["parent_cat"]); |
|
| 1921 | - $rv = array_merge($rv, Feeds::getParentCategories($line["parent_cat"], $owner_uid)); |
|
| 1922 | - } |
|
| 1919 | + while ($line = $sth->fetch()) { |
|
| 1920 | + array_push($rv, $line["parent_cat"]); |
|
| 1921 | + $rv = array_merge($rv, Feeds::getParentCategories($line["parent_cat"], $owner_uid)); |
|
| 1922 | + } |
|
| 1923 | 1923 | |
| 1924 | - return $rv; |
|
| 1925 | - } |
|
| 1924 | + return $rv; |
|
| 1925 | + } |
|
| 1926 | 1926 | |
| 1927 | - public static function getChildCategories($cat, $owner_uid) { |
|
| 1928 | - $rv = array(); |
|
| 1927 | + public static function getChildCategories($cat, $owner_uid) { |
|
| 1928 | + $rv = array(); |
|
| 1929 | 1929 | |
| 1930 | - $pdo = Db::pdo(); |
|
| 1930 | + $pdo = Db::pdo(); |
|
| 1931 | 1931 | |
| 1932 | - $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories |
|
| 1932 | + $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories |
|
| 1933 | 1933 | WHERE parent_cat = ? AND owner_uid = ?"); |
| 1934 | - $sth->execute([$cat, $owner_uid]); |
|
| 1934 | + $sth->execute([$cat, $owner_uid]); |
|
| 1935 | 1935 | |
| 1936 | - while ($line = $sth->fetch()) { |
|
| 1937 | - array_push($rv, $line["id"]); |
|
| 1938 | - $rv = array_merge($rv, Feeds::getChildCategories($line["id"], $owner_uid)); |
|
| 1939 | - } |
|
| 1936 | + while ($line = $sth->fetch()) { |
|
| 1937 | + array_push($rv, $line["id"]); |
|
| 1938 | + $rv = array_merge($rv, Feeds::getChildCategories($line["id"], $owner_uid)); |
|
| 1939 | + } |
|
| 1940 | 1940 | |
| 1941 | - return $rv; |
|
| 1942 | - } |
|
| 1941 | + return $rv; |
|
| 1942 | + } |
|
| 1943 | 1943 | |
| 1944 | - public static function getFeedCategory($feed) { |
|
| 1945 | - $pdo = Db::pdo(); |
|
| 1944 | + public static function getFeedCategory($feed) { |
|
| 1945 | + $pdo = Db::pdo(); |
|
| 1946 | 1946 | |
| 1947 | - $sth = $pdo->prepare("SELECT cat_id FROM ttrss_feeds |
|
| 1947 | + $sth = $pdo->prepare("SELECT cat_id FROM ttrss_feeds |
|
| 1948 | 1948 | WHERE id = ?"); |
| 1949 | - $sth->execute([$feed]); |
|
| 1949 | + $sth->execute([$feed]); |
|
| 1950 | 1950 | |
| 1951 | - if ($row = $sth->fetch()) { |
|
| 1952 | - return $row["cat_id"]; |
|
| 1953 | - } else { |
|
| 1954 | - return false; |
|
| 1955 | - } |
|
| 1951 | + if ($row = $sth->fetch()) { |
|
| 1952 | + return $row["cat_id"]; |
|
| 1953 | + } else { |
|
| 1954 | + return false; |
|
| 1955 | + } |
|
| 1956 | 1956 | |
| 1957 | - } |
|
| 1957 | + } |
|
| 1958 | 1958 | |
| 1959 | 1959 | function color_of($name) { |
| 1960 | 1960 | $colormap = ["#1cd7d7", "#d91111", "#1212d7", "#8e16e5", "#7b7b7b", |
@@ -1970,421 +1970,421 @@ discard block |
||
| 1970 | 1970 | $sum %= count($colormap); |
| 1971 | 1971 | |
| 1972 | 1972 | return $colormap[$sum]; |
| 1973 | - } |
|
| 1974 | - |
|
| 1975 | - public static function get_feeds_from_html($url, $content) { |
|
| 1976 | - $url = Feeds::fix_url($url); |
|
| 1977 | - $baseUrl = substr($url, 0, strrpos($url, '/') + 1); |
|
| 1978 | - |
|
| 1979 | - $feedUrls = []; |
|
| 1980 | - |
|
| 1981 | - $doc = new DOMDocument(); |
|
| 1982 | - if ($doc->loadHTML($content)) { |
|
| 1983 | - $xpath = new DOMXPath($doc); |
|
| 1984 | - $entries = $xpath->query('/html/head/link[@rel="alternate" and '. |
|
| 1985 | - '(contains(@type,"rss") or contains(@type,"atom"))]|/html/head/link[@rel="feed"]'); |
|
| 1986 | - |
|
| 1987 | - foreach ($entries as $entry) { |
|
| 1988 | - if ($entry->hasAttribute('href')) { |
|
| 1989 | - $title = $entry->getAttribute('title'); |
|
| 1990 | - if ($title == '') { |
|
| 1991 | - $title = $entry->getAttribute('type'); |
|
| 1992 | - } |
|
| 1993 | - $feedUrl = rewrite_relative_url( |
|
| 1994 | - $baseUrl, $entry->getAttribute('href') |
|
| 1995 | - ); |
|
| 1996 | - $feedUrls[$feedUrl] = $title; |
|
| 1997 | - } |
|
| 1998 | - } |
|
| 1999 | - } |
|
| 2000 | - return $feedUrls; |
|
| 2001 | - } |
|
| 2002 | - |
|
| 2003 | - public static function is_html($content) { |
|
| 2004 | - return preg_match("/<html|DOCTYPE html/i", substr($content, 0, 8192)) !== 0; |
|
| 2005 | - } |
|
| 2006 | - |
|
| 2007 | - public static function validate_feed_url($url) { |
|
| 2008 | - $parts = parse_url($url); |
|
| 2009 | - |
|
| 2010 | - return ($parts['scheme'] == 'http' || $parts['scheme'] == 'feed' || $parts['scheme'] == 'https'); |
|
| 2011 | - } |
|
| 2012 | - |
|
| 2013 | - /** |
|
| 2014 | - * Fixes incomplete URLs by prepending "http://". |
|
| 2015 | - * Also replaces feed:// with http://, and |
|
| 2016 | - * prepends a trailing slash if the url is a domain name only. |
|
| 2017 | - * |
|
| 2018 | - * @param string $url Possibly incomplete URL |
|
| 2019 | - * |
|
| 2020 | - * @return string Fixed URL. |
|
| 2021 | - */ |
|
| 2022 | - public static function fix_url($url) { |
|
| 2023 | - |
|
| 2024 | - // support schema-less urls |
|
| 2025 | - if (strpos($url, '//') === 0) { |
|
| 2026 | - $url = 'https:'.$url; |
|
| 2027 | - } |
|
| 2028 | - |
|
| 2029 | - if (strpos($url, '://') === false) { |
|
| 2030 | - $url = 'http://'.$url; |
|
| 2031 | - } else if (substr($url, 0, 5) == 'feed:') { |
|
| 2032 | - $url = 'http:'.substr($url, 5); |
|
| 2033 | - } |
|
| 2034 | - |
|
| 2035 | - //prepend slash if the URL has no slash in it |
|
| 2036 | - // "http://www.example" -> "http://www.example/" |
|
| 2037 | - if (strpos($url, '/', strpos($url, ':') + 3) === false) { |
|
| 2038 | - $url .= '/'; |
|
| 2039 | - } |
|
| 2040 | - |
|
| 2041 | - //convert IDNA hostname to punycode if possible |
|
| 2042 | - if (function_exists("idn_to_ascii")) { |
|
| 2043 | - $parts = parse_url($url); |
|
| 2044 | - if (mb_detect_encoding($parts['host']) != 'ASCII') |
|
| 2045 | - { |
|
| 2046 | - $parts['host'] = idn_to_ascii($parts['host']); |
|
| 2047 | - $url = build_url($parts); |
|
| 2048 | - } |
|
| 2049 | - } |
|
| 2050 | - |
|
| 2051 | - if ($url != "http:///") { |
|
| 2052 | - return $url; |
|
| 2053 | - } else { |
|
| 2054 | - return ''; |
|
| 2055 | - } |
|
| 2056 | - } |
|
| 2057 | - |
|
| 2058 | - public static function add_feed_category($feed_cat, $parent_cat_id = false, $order_id = 0) { |
|
| 2059 | - |
|
| 2060 | - if (!$feed_cat) { |
|
| 2061 | - return false; |
|
| 2062 | - } |
|
| 2063 | - |
|
| 2064 | - $feed_cat = mb_substr($feed_cat, 0, 250); |
|
| 2065 | - if (!$parent_cat_id) { |
|
| 2066 | - $parent_cat_id = null; |
|
| 2067 | - } |
|
| 2068 | - |
|
| 2069 | - $pdo = Db::pdo(); |
|
| 2070 | - $tr_in_progress = false; |
|
| 2071 | - |
|
| 2072 | - try { |
|
| 2073 | - $pdo->beginTransaction(); |
|
| 2074 | - } catch (Exception $e) { |
|
| 2075 | - $tr_in_progress = true; |
|
| 2076 | - } |
|
| 2077 | - |
|
| 2078 | - $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories |
|
| 1973 | + } |
|
| 1974 | + |
|
| 1975 | + public static function get_feeds_from_html($url, $content) { |
|
| 1976 | + $url = Feeds::fix_url($url); |
|
| 1977 | + $baseUrl = substr($url, 0, strrpos($url, '/') + 1); |
|
| 1978 | + |
|
| 1979 | + $feedUrls = []; |
|
| 1980 | + |
|
| 1981 | + $doc = new DOMDocument(); |
|
| 1982 | + if ($doc->loadHTML($content)) { |
|
| 1983 | + $xpath = new DOMXPath($doc); |
|
| 1984 | + $entries = $xpath->query('/html/head/link[@rel="alternate" and '. |
|
| 1985 | + '(contains(@type,"rss") or contains(@type,"atom"))]|/html/head/link[@rel="feed"]'); |
|
| 1986 | + |
|
| 1987 | + foreach ($entries as $entry) { |
|
| 1988 | + if ($entry->hasAttribute('href')) { |
|
| 1989 | + $title = $entry->getAttribute('title'); |
|
| 1990 | + if ($title == '') { |
|
| 1991 | + $title = $entry->getAttribute('type'); |
|
| 1992 | + } |
|
| 1993 | + $feedUrl = rewrite_relative_url( |
|
| 1994 | + $baseUrl, $entry->getAttribute('href') |
|
| 1995 | + ); |
|
| 1996 | + $feedUrls[$feedUrl] = $title; |
|
| 1997 | + } |
|
| 1998 | + } |
|
| 1999 | + } |
|
| 2000 | + return $feedUrls; |
|
| 2001 | + } |
|
| 2002 | + |
|
| 2003 | + public static function is_html($content) { |
|
| 2004 | + return preg_match("/<html|DOCTYPE html/i", substr($content, 0, 8192)) !== 0; |
|
| 2005 | + } |
|
| 2006 | + |
|
| 2007 | + public static function validate_feed_url($url) { |
|
| 2008 | + $parts = parse_url($url); |
|
| 2009 | + |
|
| 2010 | + return ($parts['scheme'] == 'http' || $parts['scheme'] == 'feed' || $parts['scheme'] == 'https'); |
|
| 2011 | + } |
|
| 2012 | + |
|
| 2013 | + /** |
|
| 2014 | + * Fixes incomplete URLs by prepending "http://". |
|
| 2015 | + * Also replaces feed:// with http://, and |
|
| 2016 | + * prepends a trailing slash if the url is a domain name only. |
|
| 2017 | + * |
|
| 2018 | + * @param string $url Possibly incomplete URL |
|
| 2019 | + * |
|
| 2020 | + * @return string Fixed URL. |
|
| 2021 | + */ |
|
| 2022 | + public static function fix_url($url) { |
|
| 2023 | + |
|
| 2024 | + // support schema-less urls |
|
| 2025 | + if (strpos($url, '//') === 0) { |
|
| 2026 | + $url = 'https:'.$url; |
|
| 2027 | + } |
|
| 2028 | + |
|
| 2029 | + if (strpos($url, '://') === false) { |
|
| 2030 | + $url = 'http://'.$url; |
|
| 2031 | + } else if (substr($url, 0, 5) == 'feed:') { |
|
| 2032 | + $url = 'http:'.substr($url, 5); |
|
| 2033 | + } |
|
| 2034 | + |
|
| 2035 | + //prepend slash if the URL has no slash in it |
|
| 2036 | + // "http://www.example" -> "http://www.example/" |
|
| 2037 | + if (strpos($url, '/', strpos($url, ':') + 3) === false) { |
|
| 2038 | + $url .= '/'; |
|
| 2039 | + } |
|
| 2040 | + |
|
| 2041 | + //convert IDNA hostname to punycode if possible |
|
| 2042 | + if (function_exists("idn_to_ascii")) { |
|
| 2043 | + $parts = parse_url($url); |
|
| 2044 | + if (mb_detect_encoding($parts['host']) != 'ASCII') |
|
| 2045 | + { |
|
| 2046 | + $parts['host'] = idn_to_ascii($parts['host']); |
|
| 2047 | + $url = build_url($parts); |
|
| 2048 | + } |
|
| 2049 | + } |
|
| 2050 | + |
|
| 2051 | + if ($url != "http:///") { |
|
| 2052 | + return $url; |
|
| 2053 | + } else { |
|
| 2054 | + return ''; |
|
| 2055 | + } |
|
| 2056 | + } |
|
| 2057 | + |
|
| 2058 | + public static function add_feed_category($feed_cat, $parent_cat_id = false, $order_id = 0) { |
|
| 2059 | + |
|
| 2060 | + if (!$feed_cat) { |
|
| 2061 | + return false; |
|
| 2062 | + } |
|
| 2063 | + |
|
| 2064 | + $feed_cat = mb_substr($feed_cat, 0, 250); |
|
| 2065 | + if (!$parent_cat_id) { |
|
| 2066 | + $parent_cat_id = null; |
|
| 2067 | + } |
|
| 2068 | + |
|
| 2069 | + $pdo = Db::pdo(); |
|
| 2070 | + $tr_in_progress = false; |
|
| 2071 | + |
|
| 2072 | + try { |
|
| 2073 | + $pdo->beginTransaction(); |
|
| 2074 | + } catch (Exception $e) { |
|
| 2075 | + $tr_in_progress = true; |
|
| 2076 | + } |
|
| 2077 | + |
|
| 2078 | + $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories |
|
| 2079 | 2079 | WHERE (parent_cat = :parent OR (:parent IS NULL AND parent_cat IS NULL)) |
| 2080 | 2080 | AND title = :title AND owner_uid = :uid"); |
| 2081 | - $sth->execute([':parent' => $parent_cat_id, ':title' => $feed_cat, ':uid' => $_SESSION['uid']]); |
|
| 2081 | + $sth->execute([':parent' => $parent_cat_id, ':title' => $feed_cat, ':uid' => $_SESSION['uid']]); |
|
| 2082 | 2082 | |
| 2083 | - if (!$sth->fetch()) { |
|
| 2083 | + if (!$sth->fetch()) { |
|
| 2084 | 2084 | |
| 2085 | - $sth = $pdo->prepare("INSERT INTO ttrss_feed_categories (owner_uid,title,parent_cat,order_id) |
|
| 2085 | + $sth = $pdo->prepare("INSERT INTO ttrss_feed_categories (owner_uid,title,parent_cat,order_id) |
|
| 2086 | 2086 | VALUES (?, ?, ?, ?)"); |
| 2087 | - $sth->execute([$_SESSION['uid'], $feed_cat, $parent_cat_id, (int) $order_id]); |
|
| 2087 | + $sth->execute([$_SESSION['uid'], $feed_cat, $parent_cat_id, (int) $order_id]); |
|
| 2088 | 2088 | |
| 2089 | - if (!$tr_in_progress) { |
|
| 2090 | - $pdo->commit(); |
|
| 2091 | - } |
|
| 2089 | + if (!$tr_in_progress) { |
|
| 2090 | + $pdo->commit(); |
|
| 2091 | + } |
|
| 2092 | 2092 | |
| 2093 | - return true; |
|
| 2094 | - } |
|
| 2093 | + return true; |
|
| 2094 | + } |
|
| 2095 | 2095 | |
| 2096 | - $pdo->commit(); |
|
| 2096 | + $pdo->commit(); |
|
| 2097 | 2097 | |
| 2098 | - return false; |
|
| 2099 | - } |
|
| 2098 | + return false; |
|
| 2099 | + } |
|
| 2100 | 2100 | |
| 2101 | - public static function get_feed_access_key($feed_id, $is_cat, $owner_uid = false) { |
|
| 2101 | + public static function get_feed_access_key($feed_id, $is_cat, $owner_uid = false) { |
|
| 2102 | 2102 | |
| 2103 | - if (!$owner_uid) { |
|
| 2104 | - $owner_uid = $_SESSION["uid"]; |
|
| 2105 | - } |
|
| 2103 | + if (!$owner_uid) { |
|
| 2104 | + $owner_uid = $_SESSION["uid"]; |
|
| 2105 | + } |
|
| 2106 | 2106 | |
| 2107 | - $is_cat = bool_to_sql_bool($is_cat); |
|
| 2107 | + $is_cat = bool_to_sql_bool($is_cat); |
|
| 2108 | 2108 | |
| 2109 | - $pdo = Db::pdo(); |
|
| 2109 | + $pdo = Db::pdo(); |
|
| 2110 | 2110 | |
| 2111 | - $sth = $pdo->prepare("SELECT access_key FROM ttrss_access_keys |
|
| 2111 | + $sth = $pdo->prepare("SELECT access_key FROM ttrss_access_keys |
|
| 2112 | 2112 | WHERE feed_id = ? AND is_cat = ? |
| 2113 | 2113 | AND owner_uid = ?"); |
| 2114 | - $sth->execute([$feed_id, $is_cat, $owner_uid]); |
|
| 2114 | + $sth->execute([$feed_id, $is_cat, $owner_uid]); |
|
| 2115 | 2115 | |
| 2116 | - if ($row = $sth->fetch()) { |
|
| 2117 | - return $row["access_key"]; |
|
| 2118 | - } else { |
|
| 2119 | - $key = uniqid_short(); |
|
| 2116 | + if ($row = $sth->fetch()) { |
|
| 2117 | + return $row["access_key"]; |
|
| 2118 | + } else { |
|
| 2119 | + $key = uniqid_short(); |
|
| 2120 | 2120 | |
| 2121 | - $sth = $pdo->prepare("INSERT INTO ttrss_access_keys |
|
| 2121 | + $sth = $pdo->prepare("INSERT INTO ttrss_access_keys |
|
| 2122 | 2122 | (access_key, feed_id, is_cat, owner_uid) |
| 2123 | 2123 | VALUES (?, ?, ?, ?)"); |
| 2124 | 2124 | |
| 2125 | - $sth->execute([$key, $feed_id, $is_cat, $owner_uid]); |
|
| 2126 | - |
|
| 2127 | - return $key; |
|
| 2128 | - } |
|
| 2129 | - } |
|
| 2130 | - |
|
| 2131 | - /** |
|
| 2132 | - * Purge a feed old posts. |
|
| 2133 | - * |
|
| 2134 | - * @param mixed $link A database connection. |
|
| 2135 | - * @param mixed $feed_id The id of the purged feed. |
|
| 2136 | - * @param mixed $purge_interval Olderness of purged posts. |
|
| 2137 | - * @param boolean $debug Set to True to enable the debug. False by default. |
|
| 2138 | - * @access public |
|
| 2139 | - * @return void |
|
| 2140 | - */ |
|
| 2141 | - public static function purge_feed($feed_id, $purge_interval) { |
|
| 2142 | - |
|
| 2143 | - if (!$purge_interval) { |
|
| 2144 | - $purge_interval = Feeds::feed_purge_interval($feed_id); |
|
| 2145 | - } |
|
| 2146 | - |
|
| 2147 | - $pdo = Db::pdo(); |
|
| 2148 | - |
|
| 2149 | - $sth = $pdo->prepare("SELECT owner_uid FROM ttrss_feeds WHERE id = ?"); |
|
| 2150 | - $sth->execute([$feed_id]); |
|
| 2151 | - |
|
| 2152 | - $owner_uid = false; |
|
| 2153 | - |
|
| 2154 | - if ($row = $sth->fetch()) { |
|
| 2155 | - $owner_uid = $row["owner_uid"]; |
|
| 2156 | - } |
|
| 2157 | - |
|
| 2158 | - if ($purge_interval == -1 || !$purge_interval) { |
|
| 2159 | - if ($owner_uid) { |
|
| 2160 | - CCache::update($feed_id, $owner_uid); |
|
| 2161 | - } |
|
| 2162 | - return; |
|
| 2163 | - } |
|
| 2164 | - |
|
| 2165 | - if (!$owner_uid) { |
|
| 2166 | - return; |
|
| 2167 | - } |
|
| 2168 | - |
|
| 2169 | - if (FORCE_ARTICLE_PURGE == 0) { |
|
| 2170 | - $purge_unread = get_pref("PURGE_UNREAD_ARTICLES", |
|
| 2171 | - $owner_uid, false); |
|
| 2172 | - } else { |
|
| 2173 | - $purge_unread = true; |
|
| 2174 | - $purge_interval = FORCE_ARTICLE_PURGE; |
|
| 2175 | - } |
|
| 2176 | - |
|
| 2177 | - if (!$purge_unread) { |
|
| 2178 | - $query_limit = " unread = false AND "; |
|
| 2179 | - } else { |
|
| 2180 | - $query_limit = ""; |
|
| 2181 | - } |
|
| 2182 | - |
|
| 2183 | - $purge_interval = (int) $purge_interval; |
|
| 2184 | - |
|
| 2185 | - if (DB_TYPE == "pgsql") { |
|
| 2186 | - $sth = $pdo->prepare("DELETE FROM ttrss_user_entries |
|
| 2125 | + $sth->execute([$key, $feed_id, $is_cat, $owner_uid]); |
|
| 2126 | + |
|
| 2127 | + return $key; |
|
| 2128 | + } |
|
| 2129 | + } |
|
| 2130 | + |
|
| 2131 | + /** |
|
| 2132 | + * Purge a feed old posts. |
|
| 2133 | + * |
|
| 2134 | + * @param mixed $link A database connection. |
|
| 2135 | + * @param mixed $feed_id The id of the purged feed. |
|
| 2136 | + * @param mixed $purge_interval Olderness of purged posts. |
|
| 2137 | + * @param boolean $debug Set to True to enable the debug. False by default. |
|
| 2138 | + * @access public |
|
| 2139 | + * @return void |
|
| 2140 | + */ |
|
| 2141 | + public static function purge_feed($feed_id, $purge_interval) { |
|
| 2142 | + |
|
| 2143 | + if (!$purge_interval) { |
|
| 2144 | + $purge_interval = Feeds::feed_purge_interval($feed_id); |
|
| 2145 | + } |
|
| 2146 | + |
|
| 2147 | + $pdo = Db::pdo(); |
|
| 2148 | + |
|
| 2149 | + $sth = $pdo->prepare("SELECT owner_uid FROM ttrss_feeds WHERE id = ?"); |
|
| 2150 | + $sth->execute([$feed_id]); |
|
| 2151 | + |
|
| 2152 | + $owner_uid = false; |
|
| 2153 | + |
|
| 2154 | + if ($row = $sth->fetch()) { |
|
| 2155 | + $owner_uid = $row["owner_uid"]; |
|
| 2156 | + } |
|
| 2157 | + |
|
| 2158 | + if ($purge_interval == -1 || !$purge_interval) { |
|
| 2159 | + if ($owner_uid) { |
|
| 2160 | + CCache::update($feed_id, $owner_uid); |
|
| 2161 | + } |
|
| 2162 | + return; |
|
| 2163 | + } |
|
| 2164 | + |
|
| 2165 | + if (!$owner_uid) { |
|
| 2166 | + return; |
|
| 2167 | + } |
|
| 2168 | + |
|
| 2169 | + if (FORCE_ARTICLE_PURGE == 0) { |
|
| 2170 | + $purge_unread = get_pref("PURGE_UNREAD_ARTICLES", |
|
| 2171 | + $owner_uid, false); |
|
| 2172 | + } else { |
|
| 2173 | + $purge_unread = true; |
|
| 2174 | + $purge_interval = FORCE_ARTICLE_PURGE; |
|
| 2175 | + } |
|
| 2176 | + |
|
| 2177 | + if (!$purge_unread) { |
|
| 2178 | + $query_limit = " unread = false AND "; |
|
| 2179 | + } else { |
|
| 2180 | + $query_limit = ""; |
|
| 2181 | + } |
|
| 2182 | + |
|
| 2183 | + $purge_interval = (int) $purge_interval; |
|
| 2184 | + |
|
| 2185 | + if (DB_TYPE == "pgsql") { |
|
| 2186 | + $sth = $pdo->prepare("DELETE FROM ttrss_user_entries |
|
| 2187 | 2187 | USING ttrss_entries |
| 2188 | 2188 | WHERE ttrss_entries.id = ref_id AND |
| 2189 | 2189 | marked = false AND |
| 2190 | 2190 | feed_id = ? AND |
| 2191 | 2191 | $query_limit |
| 2192 | 2192 | ttrss_entries.date_updated < NOW() - INTERVAL '$purge_interval days'"); |
| 2193 | - $sth->execute([$feed_id]); |
|
| 2193 | + $sth->execute([$feed_id]); |
|
| 2194 | 2194 | |
| 2195 | - } else { |
|
| 2196 | - $sth = $pdo->prepare("DELETE FROM ttrss_user_entries |
|
| 2195 | + } else { |
|
| 2196 | + $sth = $pdo->prepare("DELETE FROM ttrss_user_entries |
|
| 2197 | 2197 | USING ttrss_user_entries, ttrss_entries |
| 2198 | 2198 | WHERE ttrss_entries.id = ref_id AND |
| 2199 | 2199 | marked = false AND |
| 2200 | 2200 | feed_id = ? AND |
| 2201 | 2201 | $query_limit |
| 2202 | 2202 | ttrss_entries.date_updated < DATE_SUB(NOW(), INTERVAL $purge_interval DAY)"); |
| 2203 | - $sth->execute([$feed_id]); |
|
| 2203 | + $sth->execute([$feed_id]); |
|
| 2204 | 2204 | |
| 2205 | - } |
|
| 2205 | + } |
|
| 2206 | 2206 | |
| 2207 | - $rows = $sth->rowCount(); |
|
| 2207 | + $rows = $sth->rowCount(); |
|
| 2208 | 2208 | |
| 2209 | - CCache::update($feed_id, $owner_uid); |
|
| 2209 | + CCache::update($feed_id, $owner_uid); |
|
| 2210 | 2210 | |
| 2211 | - Debug::log("Purged feed $feed_id ($purge_interval): deleted $rows articles"); |
|
| 2211 | + Debug::log("Purged feed $feed_id ($purge_interval): deleted $rows articles"); |
|
| 2212 | 2212 | |
| 2213 | - return $rows; |
|
| 2214 | - } |
|
| 2213 | + return $rows; |
|
| 2214 | + } |
|
| 2215 | 2215 | |
| 2216 | - public static function feed_purge_interval($feed_id) { |
|
| 2216 | + public static function feed_purge_interval($feed_id) { |
|
| 2217 | 2217 | |
| 2218 | - $pdo = DB::pdo(); |
|
| 2218 | + $pdo = DB::pdo(); |
|
| 2219 | 2219 | |
| 2220 | - $sth = $pdo->prepare("SELECT purge_interval, owner_uid FROM ttrss_feeds |
|
| 2220 | + $sth = $pdo->prepare("SELECT purge_interval, owner_uid FROM ttrss_feeds |
|
| 2221 | 2221 | WHERE id = ?"); |
| 2222 | - $sth->execute([$feed_id]); |
|
| 2223 | - |
|
| 2224 | - if ($row = $sth->fetch()) { |
|
| 2225 | - $purge_interval = $row["purge_interval"]; |
|
| 2226 | - $owner_uid = $row["owner_uid"]; |
|
| 2227 | - |
|
| 2228 | - if ($purge_interval == 0) { |
|
| 2229 | - $purge_interval = get_pref( |
|
| 2230 | - 'PURGE_OLD_DAYS', $owner_uid); |
|
| 2231 | - } |
|
| 2232 | - |
|
| 2233 | - return $purge_interval; |
|
| 2234 | - |
|
| 2235 | - } else { |
|
| 2236 | - return -1; |
|
| 2237 | - } |
|
| 2238 | - } |
|
| 2239 | - |
|
| 2240 | - public static function search_to_sql($search, $search_language) { |
|
| 2241 | - |
|
| 2242 | - $keywords = str_getcsv(trim($search), " "); |
|
| 2243 | - $query_keywords = array(); |
|
| 2244 | - $search_words = array(); |
|
| 2245 | - $search_query_leftover = array(); |
|
| 2246 | - |
|
| 2247 | - $pdo = Db::pdo(); |
|
| 2248 | - |
|
| 2249 | - if ($search_language) { |
|
| 2250 | - $search_language = $pdo->quote(mb_strtolower($search_language)); |
|
| 2251 | - } else { |
|
| 2252 | - $search_language = $pdo->quote("english"); |
|
| 2253 | - } |
|
| 2254 | - |
|
| 2255 | - foreach ($keywords as $k) { |
|
| 2256 | - if (strpos($k, "-") === 0) { |
|
| 2257 | - $k = substr($k, 1); |
|
| 2258 | - $not = "NOT"; |
|
| 2259 | - } else { |
|
| 2260 | - $not = ""; |
|
| 2261 | - } |
|
| 2262 | - |
|
| 2263 | - $commandpair = explode(":", mb_strtolower($k), 2); |
|
| 2264 | - |
|
| 2265 | - switch ($commandpair[0]) { |
|
| 2266 | - case "title": |
|
| 2267 | - if ($commandpair[1]) { |
|
| 2268 | - array_push($query_keywords, "($not (LOWER(ttrss_entries.title) LIKE ". |
|
| 2269 | - $pdo->quote('%'.mb_strtolower($commandpair[1]).'%')."))"); |
|
| 2270 | - } else { |
|
| 2271 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
| 2222 | + $sth->execute([$feed_id]); |
|
| 2223 | + |
|
| 2224 | + if ($row = $sth->fetch()) { |
|
| 2225 | + $purge_interval = $row["purge_interval"]; |
|
| 2226 | + $owner_uid = $row["owner_uid"]; |
|
| 2227 | + |
|
| 2228 | + if ($purge_interval == 0) { |
|
| 2229 | + $purge_interval = get_pref( |
|
| 2230 | + 'PURGE_OLD_DAYS', $owner_uid); |
|
| 2231 | + } |
|
| 2232 | + |
|
| 2233 | + return $purge_interval; |
|
| 2234 | + |
|
| 2235 | + } else { |
|
| 2236 | + return -1; |
|
| 2237 | + } |
|
| 2238 | + } |
|
| 2239 | + |
|
| 2240 | + public static function search_to_sql($search, $search_language) { |
|
| 2241 | + |
|
| 2242 | + $keywords = str_getcsv(trim($search), " "); |
|
| 2243 | + $query_keywords = array(); |
|
| 2244 | + $search_words = array(); |
|
| 2245 | + $search_query_leftover = array(); |
|
| 2246 | + |
|
| 2247 | + $pdo = Db::pdo(); |
|
| 2248 | + |
|
| 2249 | + if ($search_language) { |
|
| 2250 | + $search_language = $pdo->quote(mb_strtolower($search_language)); |
|
| 2251 | + } else { |
|
| 2252 | + $search_language = $pdo->quote("english"); |
|
| 2253 | + } |
|
| 2254 | + |
|
| 2255 | + foreach ($keywords as $k) { |
|
| 2256 | + if (strpos($k, "-") === 0) { |
|
| 2257 | + $k = substr($k, 1); |
|
| 2258 | + $not = "NOT"; |
|
| 2259 | + } else { |
|
| 2260 | + $not = ""; |
|
| 2261 | + } |
|
| 2262 | + |
|
| 2263 | + $commandpair = explode(":", mb_strtolower($k), 2); |
|
| 2264 | + |
|
| 2265 | + switch ($commandpair[0]) { |
|
| 2266 | + case "title": |
|
| 2267 | + if ($commandpair[1]) { |
|
| 2268 | + array_push($query_keywords, "($not (LOWER(ttrss_entries.title) LIKE ". |
|
| 2269 | + $pdo->quote('%'.mb_strtolower($commandpair[1]).'%')."))"); |
|
| 2270 | + } else { |
|
| 2271 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
| 2272 | 2272 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2273 | - array_push($search_words, $k); |
|
| 2274 | - } |
|
| 2275 | - break; |
|
| 2276 | - case "author": |
|
| 2277 | - if ($commandpair[1]) { |
|
| 2278 | - array_push($query_keywords, "($not (LOWER(author) LIKE ". |
|
| 2279 | - $pdo->quote('%'.mb_strtolower($commandpair[1]).'%')."))"); |
|
| 2280 | - } else { |
|
| 2281 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
| 2273 | + array_push($search_words, $k); |
|
| 2274 | + } |
|
| 2275 | + break; |
|
| 2276 | + case "author": |
|
| 2277 | + if ($commandpair[1]) { |
|
| 2278 | + array_push($query_keywords, "($not (LOWER(author) LIKE ". |
|
| 2279 | + $pdo->quote('%'.mb_strtolower($commandpair[1]).'%')."))"); |
|
| 2280 | + } else { |
|
| 2281 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
| 2282 | 2282 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2283 | - array_push($search_words, $k); |
|
| 2284 | - } |
|
| 2285 | - break; |
|
| 2286 | - case "note": |
|
| 2287 | - if ($commandpair[1]) { |
|
| 2288 | - if ($commandpair[1] == "true") |
|
| 2289 | - array_push($query_keywords, "($not (note IS NOT NULL AND note != ''))"); |
|
| 2290 | - else if ($commandpair[1] == "false") |
|
| 2291 | - array_push($query_keywords, "($not (note IS NULL OR note = ''))"); |
|
| 2292 | - else |
|
| 2293 | - array_push($query_keywords, "($not (LOWER(note) LIKE ". |
|
| 2294 | - $pdo->quote('%'.mb_strtolower($commandpair[1]).'%')."))"); |
|
| 2295 | - } else { |
|
| 2296 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
| 2283 | + array_push($search_words, $k); |
|
| 2284 | + } |
|
| 2285 | + break; |
|
| 2286 | + case "note": |
|
| 2287 | + if ($commandpair[1]) { |
|
| 2288 | + if ($commandpair[1] == "true") |
|
| 2289 | + array_push($query_keywords, "($not (note IS NOT NULL AND note != ''))"); |
|
| 2290 | + else if ($commandpair[1] == "false") |
|
| 2291 | + array_push($query_keywords, "($not (note IS NULL OR note = ''))"); |
|
| 2292 | + else |
|
| 2293 | + array_push($query_keywords, "($not (LOWER(note) LIKE ". |
|
| 2294 | + $pdo->quote('%'.mb_strtolower($commandpair[1]).'%')."))"); |
|
| 2295 | + } else { |
|
| 2296 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
| 2297 | 2297 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2298 | - if (!$not) array_push($search_words, $k); |
|
| 2299 | - } |
|
| 2300 | - break; |
|
| 2301 | - case "star": |
|
| 2302 | - |
|
| 2303 | - if ($commandpair[1]) { |
|
| 2304 | - if ($commandpair[1] == "true") |
|
| 2305 | - array_push($query_keywords, "($not (marked = true))"); |
|
| 2306 | - else |
|
| 2307 | - array_push($query_keywords, "($not (marked = false))"); |
|
| 2308 | - } else { |
|
| 2309 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
| 2298 | + if (!$not) array_push($search_words, $k); |
|
| 2299 | + } |
|
| 2300 | + break; |
|
| 2301 | + case "star": |
|
| 2302 | + |
|
| 2303 | + if ($commandpair[1]) { |
|
| 2304 | + if ($commandpair[1] == "true") |
|
| 2305 | + array_push($query_keywords, "($not (marked = true))"); |
|
| 2306 | + else |
|
| 2307 | + array_push($query_keywords, "($not (marked = false))"); |
|
| 2308 | + } else { |
|
| 2309 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
| 2310 | 2310 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2311 | - if (!$not) array_push($search_words, $k); |
|
| 2312 | - } |
|
| 2313 | - break; |
|
| 2314 | - case "pub": |
|
| 2315 | - if ($commandpair[1]) { |
|
| 2316 | - if ($commandpair[1] == "true") |
|
| 2317 | - array_push($query_keywords, "($not (published = true))"); |
|
| 2318 | - else |
|
| 2319 | - array_push($query_keywords, "($not (published = false))"); |
|
| 2320 | - |
|
| 2321 | - } else { |
|
| 2322 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
| 2311 | + if (!$not) array_push($search_words, $k); |
|
| 2312 | + } |
|
| 2313 | + break; |
|
| 2314 | + case "pub": |
|
| 2315 | + if ($commandpair[1]) { |
|
| 2316 | + if ($commandpair[1] == "true") |
|
| 2317 | + array_push($query_keywords, "($not (published = true))"); |
|
| 2318 | + else |
|
| 2319 | + array_push($query_keywords, "($not (published = false))"); |
|
| 2320 | + |
|
| 2321 | + } else { |
|
| 2322 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
| 2323 | 2323 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2324 | - if (!$not) array_push($search_words, $k); |
|
| 2325 | - } |
|
| 2326 | - break; |
|
| 2327 | - case "unread": |
|
| 2328 | - if ($commandpair[1]) { |
|
| 2329 | - if ($commandpair[1] == "true") |
|
| 2330 | - array_push($query_keywords, "($not (unread = true))"); |
|
| 2331 | - else |
|
| 2332 | - array_push($query_keywords, "($not (unread = false))"); |
|
| 2333 | - |
|
| 2334 | - } else { |
|
| 2335 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
| 2324 | + if (!$not) array_push($search_words, $k); |
|
| 2325 | + } |
|
| 2326 | + break; |
|
| 2327 | + case "unread": |
|
| 2328 | + if ($commandpair[1]) { |
|
| 2329 | + if ($commandpair[1] == "true") |
|
| 2330 | + array_push($query_keywords, "($not (unread = true))"); |
|
| 2331 | + else |
|
| 2332 | + array_push($query_keywords, "($not (unread = false))"); |
|
| 2333 | + |
|
| 2334 | + } else { |
|
| 2335 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
| 2336 | 2336 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2337 | - if (!$not) array_push($search_words, $k); |
|
| 2338 | - } |
|
| 2339 | - break; |
|
| 2340 | - default: |
|
| 2341 | - if (strpos($k, "@") === 0) { |
|
| 2342 | - |
|
| 2343 | - $user_tz_string = get_pref('USER_TIMEZONE', $_SESSION['uid']); |
|
| 2344 | - $orig_ts = strtotime(substr($k, 1)); |
|
| 2345 | - $k = date("Y-m-d", convert_timestamp($orig_ts, $user_tz_string, 'UTC')); |
|
| 2346 | - |
|
| 2347 | - //$k = date("Y-m-d", strtotime(substr($k, 1))); |
|
| 2348 | - |
|
| 2349 | - array_push($query_keywords, "(".SUBSTRING_FOR_DATE."(updated,1,LENGTH('$k')) $not = '$k')"); |
|
| 2350 | - } else { |
|
| 2351 | - |
|
| 2352 | - if (DB_TYPE == "pgsql") { |
|
| 2353 | - $k = mb_strtolower($k); |
|
| 2354 | - array_push($search_query_leftover, $not ? "!$k" : $k); |
|
| 2355 | - } else { |
|
| 2356 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
| 2337 | + if (!$not) array_push($search_words, $k); |
|
| 2338 | + } |
|
| 2339 | + break; |
|
| 2340 | + default: |
|
| 2341 | + if (strpos($k, "@") === 0) { |
|
| 2342 | + |
|
| 2343 | + $user_tz_string = get_pref('USER_TIMEZONE', $_SESSION['uid']); |
|
| 2344 | + $orig_ts = strtotime(substr($k, 1)); |
|
| 2345 | + $k = date("Y-m-d", convert_timestamp($orig_ts, $user_tz_string, 'UTC')); |
|
| 2346 | + |
|
| 2347 | + //$k = date("Y-m-d", strtotime(substr($k, 1))); |
|
| 2348 | + |
|
| 2349 | + array_push($query_keywords, "(".SUBSTRING_FOR_DATE."(updated,1,LENGTH('$k')) $not = '$k')"); |
|
| 2350 | + } else { |
|
| 2351 | + |
|
| 2352 | + if (DB_TYPE == "pgsql") { |
|
| 2353 | + $k = mb_strtolower($k); |
|
| 2354 | + array_push($search_query_leftover, $not ? "!$k" : $k); |
|
| 2355 | + } else { |
|
| 2356 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
| 2357 | 2357 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2358 | - } |
|
| 2358 | + } |
|
| 2359 | 2359 | |
| 2360 | - if (!$not) { |
|
| 2361 | - array_push($search_words, $k); |
|
| 2362 | - } |
|
| 2363 | - } |
|
| 2364 | - } |
|
| 2365 | - } |
|
| 2360 | + if (!$not) { |
|
| 2361 | + array_push($search_words, $k); |
|
| 2362 | + } |
|
| 2363 | + } |
|
| 2364 | + } |
|
| 2365 | + } |
|
| 2366 | 2366 | |
| 2367 | - if (count($search_query_leftover) > 0) { |
|
| 2367 | + if (count($search_query_leftover) > 0) { |
|
| 2368 | 2368 | |
| 2369 | - if (DB_TYPE == "pgsql") { |
|
| 2369 | + if (DB_TYPE == "pgsql") { |
|
| 2370 | 2370 | |
| 2371 | - // if there's no joiners consider this a "simple" search and |
|
| 2372 | - // concatenate everything with &, otherwise don't try to mess with tsquery syntax |
|
| 2373 | - if (preg_match("/[&|]/", implode(" ", $search_query_leftover))) { |
|
| 2374 | - $tsquery = $pdo->quote(implode(" ", $search_query_leftover)); |
|
| 2375 | - } else { |
|
| 2376 | - $tsquery = $pdo->quote(implode(" & ", $search_query_leftover)); |
|
| 2377 | - } |
|
| 2371 | + // if there's no joiners consider this a "simple" search and |
|
| 2372 | + // concatenate everything with &, otherwise don't try to mess with tsquery syntax |
|
| 2373 | + if (preg_match("/[&|]/", implode(" ", $search_query_leftover))) { |
|
| 2374 | + $tsquery = $pdo->quote(implode(" ", $search_query_leftover)); |
|
| 2375 | + } else { |
|
| 2376 | + $tsquery = $pdo->quote(implode(" & ", $search_query_leftover)); |
|
| 2377 | + } |
|
| 2378 | 2378 | |
| 2379 | - array_push($query_keywords, |
|
| 2380 | - "(tsvector_combined @@ to_tsquery($search_language, $tsquery))"); |
|
| 2381 | - } |
|
| 2379 | + array_push($query_keywords, |
|
| 2380 | + "(tsvector_combined @@ to_tsquery($search_language, $tsquery))"); |
|
| 2381 | + } |
|
| 2382 | 2382 | |
| 2383 | - } |
|
| 2383 | + } |
|
| 2384 | 2384 | |
| 2385 | - $search_query_part = implode("AND", $query_keywords); |
|
| 2385 | + $search_query_part = implode("AND", $query_keywords); |
|
| 2386 | 2386 | |
| 2387 | - return array($search_query_part, $search_words); |
|
| 2388 | - } |
|
| 2387 | + return array($search_query_part, $search_words); |
|
| 2388 | + } |
|
| 2389 | 2389 | } |
| 2390 | 2390 | |
@@ -412,21 +412,21 @@ discard block |
||
| 412 | 412 | $message = $query_error_override; |
| 413 | 413 | } else { |
| 414 | 414 | switch ($view_mode) { |
| 415 | - case "unread": |
|
| 416 | - $message = __("No unread articles found to display."); |
|
| 417 | - break; |
|
| 418 | - case "updated": |
|
| 419 | - $message = __("No updated articles found to display."); |
|
| 420 | - break; |
|
| 421 | - case "marked": |
|
| 422 | - $message = __("No starred articles found to display."); |
|
| 423 | - break; |
|
| 424 | - default: |
|
| 425 | - if ($feed < LABEL_BASE_INDEX) { |
|
| 426 | - $message = __("No articles found to display. You can assign articles to labels manually from article header context menu (applies to all selected articles) or use a filter."); |
|
| 427 | - } else { |
|
| 428 | - $message = __("No articles found to display."); |
|
| 429 | - } |
|
| 415 | + case "unread": |
|
| 416 | + $message = __("No unread articles found to display."); |
|
| 417 | + break; |
|
| 418 | + case "updated": |
|
| 419 | + $message = __("No updated articles found to display."); |
|
| 420 | + break; |
|
| 421 | + case "marked": |
|
| 422 | + $message = __("No starred articles found to display."); |
|
| 423 | + break; |
|
| 424 | + default: |
|
| 425 | + if ($feed < LABEL_BASE_INDEX) { |
|
| 426 | + $message = __("No articles found to display. You can assign articles to labels manually from article header context menu (applies to all selected articles) or use a filter."); |
|
| 427 | + } else { |
|
| 428 | + $message = __("No articles found to display."); |
|
| 429 | + } |
|
| 430 | 430 | } |
| 431 | 431 | } |
| 432 | 432 | |
@@ -893,29 +893,29 @@ discard block |
||
| 893 | 893 | // TODO: all this interval stuff needs some generic generator function |
| 894 | 894 | |
| 895 | 895 | switch ($mode) { |
| 896 | - case "1day": |
|
| 897 | - if (DB_TYPE == "pgsql") { |
|
| 898 | - $date_qpart = "date_entered < NOW() - INTERVAL '1 day' "; |
|
| 899 | - } else { |
|
| 900 | - $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY) "; |
|
| 901 | - } |
|
| 902 | - break; |
|
| 903 | - case "1week": |
|
| 904 | - if (DB_TYPE == "pgsql") { |
|
| 905 | - $date_qpart = "date_entered < NOW() - INTERVAL '1 week' "; |
|
| 906 | - } else { |
|
| 907 | - $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 WEEK) "; |
|
| 908 | - } |
|
| 909 | - break; |
|
| 910 | - case "2week": |
|
| 911 | - if (DB_TYPE == "pgsql") { |
|
| 912 | - $date_qpart = "date_entered < NOW() - INTERVAL '2 week' "; |
|
| 913 | - } else { |
|
| 914 | - $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 2 WEEK) "; |
|
| 915 | - } |
|
| 916 | - break; |
|
| 917 | - default: |
|
| 918 | - $date_qpart = "true"; |
|
| 896 | + case "1day": |
|
| 897 | + if (DB_TYPE == "pgsql") { |
|
| 898 | + $date_qpart = "date_entered < NOW() - INTERVAL '1 day' "; |
|
| 899 | + } else { |
|
| 900 | + $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY) "; |
|
| 901 | + } |
|
| 902 | + break; |
|
| 903 | + case "1week": |
|
| 904 | + if (DB_TYPE == "pgsql") { |
|
| 905 | + $date_qpart = "date_entered < NOW() - INTERVAL '1 week' "; |
|
| 906 | + } else { |
|
| 907 | + $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 WEEK) "; |
|
| 908 | + } |
|
| 909 | + break; |
|
| 910 | + case "2week": |
|
| 911 | + if (DB_TYPE == "pgsql") { |
|
| 912 | + $date_qpart = "date_entered < NOW() - INTERVAL '2 week' "; |
|
| 913 | + } else { |
|
| 914 | + $date_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 2 WEEK) "; |
|
| 915 | + } |
|
| 916 | + break; |
|
| 917 | + default: |
|
| 918 | + $date_qpart = "true"; |
|
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | if (is_numeric($feed)) { |
@@ -1237,28 +1237,28 @@ discard block |
||
| 1237 | 1237 | |
| 1238 | 1238 | public static function getFeedIcon($id) { |
| 1239 | 1239 | switch ($id) { |
| 1240 | - case 0: |
|
| 1241 | - return "archive"; |
|
| 1242 | - case -1: |
|
| 1243 | - return "star"; |
|
| 1244 | - case -2: |
|
| 1245 | - return "rss_feed"; |
|
| 1246 | - case -3: |
|
| 1247 | - return "whatshot"; |
|
| 1248 | - case -4: |
|
| 1249 | - return "inbox"; |
|
| 1250 | - case -6: |
|
| 1251 | - return "restore"; |
|
| 1252 | - default: |
|
| 1253 | - if ($id < LABEL_BASE_INDEX) { |
|
| 1254 | - return "label"; |
|
| 1255 | - } else { |
|
| 1256 | - $icon = self::getIconFile($id); |
|
| 1240 | + case 0: |
|
| 1241 | + return "archive"; |
|
| 1242 | + case -1: |
|
| 1243 | + return "star"; |
|
| 1244 | + case -2: |
|
| 1245 | + return "rss_feed"; |
|
| 1246 | + case -3: |
|
| 1247 | + return "whatshot"; |
|
| 1248 | + case -4: |
|
| 1249 | + return "inbox"; |
|
| 1250 | + case -6: |
|
| 1251 | + return "restore"; |
|
| 1252 | + default: |
|
| 1253 | + if ($id < LABEL_BASE_INDEX) { |
|
| 1254 | + return "label"; |
|
| 1255 | + } else { |
|
| 1256 | + $icon = self::getIconFile($id); |
|
| 1257 | 1257 | |
| 1258 | 1258 | if ($icon && file_exists($icon)) { |
| 1259 | - return ICONS_URL."/".basename($icon)."?".filemtime($icon); |
|
| 1260 | - } |
|
| 1259 | + return ICONS_URL."/".basename($icon)."?".filemtime($icon); |
|
| 1261 | 1260 | } |
| 1261 | + } |
|
| 1262 | 1262 | } |
| 1263 | 1263 | |
| 1264 | 1264 | return false; |
@@ -2263,104 +2263,104 @@ discard block |
||
| 2263 | 2263 | $commandpair = explode(":", mb_strtolower($k), 2); |
| 2264 | 2264 | |
| 2265 | 2265 | switch ($commandpair[0]) { |
| 2266 | - case "title": |
|
| 2267 | - if ($commandpair[1]) { |
|
| 2268 | - array_push($query_keywords, "($not (LOWER(ttrss_entries.title) LIKE ". |
|
| 2269 | - $pdo->quote('%'.mb_strtolower($commandpair[1]).'%')."))"); |
|
| 2270 | - } else { |
|
| 2271 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
| 2266 | + case "title": |
|
| 2267 | + if ($commandpair[1]) { |
|
| 2268 | + array_push($query_keywords, "($not (LOWER(ttrss_entries.title) LIKE ". |
|
| 2269 | + $pdo->quote('%'.mb_strtolower($commandpair[1]).'%')."))"); |
|
| 2270 | + } else { |
|
| 2271 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
| 2272 | 2272 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2273 | - array_push($search_words, $k); |
|
| 2274 | - } |
|
| 2275 | - break; |
|
| 2276 | - case "author": |
|
| 2277 | - if ($commandpair[1]) { |
|
| 2278 | - array_push($query_keywords, "($not (LOWER(author) LIKE ". |
|
| 2279 | - $pdo->quote('%'.mb_strtolower($commandpair[1]).'%')."))"); |
|
| 2280 | - } else { |
|
| 2281 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
| 2273 | + array_push($search_words, $k); |
|
| 2274 | + } |
|
| 2275 | + break; |
|
| 2276 | + case "author": |
|
| 2277 | + if ($commandpair[1]) { |
|
| 2278 | + array_push($query_keywords, "($not (LOWER(author) LIKE ". |
|
| 2279 | + $pdo->quote('%'.mb_strtolower($commandpair[1]).'%')."))"); |
|
| 2280 | + } else { |
|
| 2281 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
| 2282 | 2282 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2283 | - array_push($search_words, $k); |
|
| 2284 | - } |
|
| 2285 | - break; |
|
| 2286 | - case "note": |
|
| 2287 | - if ($commandpair[1]) { |
|
| 2288 | - if ($commandpair[1] == "true") |
|
| 2289 | - array_push($query_keywords, "($not (note IS NOT NULL AND note != ''))"); |
|
| 2290 | - else if ($commandpair[1] == "false") |
|
| 2291 | - array_push($query_keywords, "($not (note IS NULL OR note = ''))"); |
|
| 2292 | - else |
|
| 2293 | - array_push($query_keywords, "($not (LOWER(note) LIKE ". |
|
| 2294 | - $pdo->quote('%'.mb_strtolower($commandpair[1]).'%')."))"); |
|
| 2295 | - } else { |
|
| 2296 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
| 2283 | + array_push($search_words, $k); |
|
| 2284 | + } |
|
| 2285 | + break; |
|
| 2286 | + case "note": |
|
| 2287 | + if ($commandpair[1]) { |
|
| 2288 | + if ($commandpair[1] == "true") |
|
| 2289 | + array_push($query_keywords, "($not (note IS NOT NULL AND note != ''))"); |
|
| 2290 | + else if ($commandpair[1] == "false") |
|
| 2291 | + array_push($query_keywords, "($not (note IS NULL OR note = ''))"); |
|
| 2292 | + else |
|
| 2293 | + array_push($query_keywords, "($not (LOWER(note) LIKE ". |
|
| 2294 | + $pdo->quote('%'.mb_strtolower($commandpair[1]).'%')."))"); |
|
| 2295 | + } else { |
|
| 2296 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
| 2297 | 2297 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2298 | - if (!$not) array_push($search_words, $k); |
|
| 2299 | - } |
|
| 2300 | - break; |
|
| 2301 | - case "star": |
|
| 2302 | - |
|
| 2303 | - if ($commandpair[1]) { |
|
| 2304 | - if ($commandpair[1] == "true") |
|
| 2305 | - array_push($query_keywords, "($not (marked = true))"); |
|
| 2306 | - else |
|
| 2307 | - array_push($query_keywords, "($not (marked = false))"); |
|
| 2308 | - } else { |
|
| 2309 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
| 2298 | + if (!$not) array_push($search_words, $k); |
|
| 2299 | + } |
|
| 2300 | + break; |
|
| 2301 | + case "star": |
|
| 2302 | + |
|
| 2303 | + if ($commandpair[1]) { |
|
| 2304 | + if ($commandpair[1] == "true") |
|
| 2305 | + array_push($query_keywords, "($not (marked = true))"); |
|
| 2306 | + else |
|
| 2307 | + array_push($query_keywords, "($not (marked = false))"); |
|
| 2308 | + } else { |
|
| 2309 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
| 2310 | 2310 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2311 | - if (!$not) array_push($search_words, $k); |
|
| 2312 | - } |
|
| 2313 | - break; |
|
| 2314 | - case "pub": |
|
| 2315 | - if ($commandpair[1]) { |
|
| 2316 | - if ($commandpair[1] == "true") |
|
| 2317 | - array_push($query_keywords, "($not (published = true))"); |
|
| 2318 | - else |
|
| 2319 | - array_push($query_keywords, "($not (published = false))"); |
|
| 2311 | + if (!$not) array_push($search_words, $k); |
|
| 2312 | + } |
|
| 2313 | + break; |
|
| 2314 | + case "pub": |
|
| 2315 | + if ($commandpair[1]) { |
|
| 2316 | + if ($commandpair[1] == "true") |
|
| 2317 | + array_push($query_keywords, "($not (published = true))"); |
|
| 2318 | + else |
|
| 2319 | + array_push($query_keywords, "($not (published = false))"); |
|
| 2320 | 2320 | |
| 2321 | - } else { |
|
| 2322 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
| 2321 | + } else { |
|
| 2322 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
|
| 2323 | 2323 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2324 | - if (!$not) array_push($search_words, $k); |
|
| 2325 | - } |
|
| 2326 | - break; |
|
| 2327 | - case "unread": |
|
| 2328 | - if ($commandpair[1]) { |
|
| 2329 | - if ($commandpair[1] == "true") |
|
| 2330 | - array_push($query_keywords, "($not (unread = true))"); |
|
| 2331 | - else |
|
| 2332 | - array_push($query_keywords, "($not (unread = false))"); |
|
| 2324 | + if (!$not) array_push($search_words, $k); |
|
| 2325 | + } |
|
| 2326 | + break; |
|
| 2327 | + case "unread": |
|
| 2328 | + if ($commandpair[1]) { |
|
| 2329 | + if ($commandpair[1] == "true") |
|
| 2330 | + array_push($query_keywords, "($not (unread = true))"); |
|
| 2331 | + else |
|
| 2332 | + array_push($query_keywords, "($not (unread = false))"); |
|
| 2333 | 2333 | |
| 2334 | - } else { |
|
| 2335 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
| 2334 | + } else { |
|
| 2335 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
| 2336 | 2336 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2337 | - if (!$not) array_push($search_words, $k); |
|
| 2338 | - } |
|
| 2339 | - break; |
|
| 2340 | - default: |
|
| 2341 | - if (strpos($k, "@") === 0) { |
|
| 2337 | + if (!$not) array_push($search_words, $k); |
|
| 2338 | + } |
|
| 2339 | + break; |
|
| 2340 | + default: |
|
| 2341 | + if (strpos($k, "@") === 0) { |
|
| 2342 | 2342 | |
| 2343 | - $user_tz_string = get_pref('USER_TIMEZONE', $_SESSION['uid']); |
|
| 2344 | - $orig_ts = strtotime(substr($k, 1)); |
|
| 2345 | - $k = date("Y-m-d", convert_timestamp($orig_ts, $user_tz_string, 'UTC')); |
|
| 2343 | + $user_tz_string = get_pref('USER_TIMEZONE', $_SESSION['uid']); |
|
| 2344 | + $orig_ts = strtotime(substr($k, 1)); |
|
| 2345 | + $k = date("Y-m-d", convert_timestamp($orig_ts, $user_tz_string, 'UTC')); |
|
| 2346 | 2346 | |
| 2347 | - //$k = date("Y-m-d", strtotime(substr($k, 1))); |
|
| 2347 | + //$k = date("Y-m-d", strtotime(substr($k, 1))); |
|
| 2348 | 2348 | |
| 2349 | - array_push($query_keywords, "(".SUBSTRING_FOR_DATE."(updated,1,LENGTH('$k')) $not = '$k')"); |
|
| 2350 | - } else { |
|
| 2349 | + array_push($query_keywords, "(".SUBSTRING_FOR_DATE."(updated,1,LENGTH('$k')) $not = '$k')"); |
|
| 2350 | + } else { |
|
| 2351 | 2351 | |
| 2352 | - if (DB_TYPE == "pgsql") { |
|
| 2353 | - $k = mb_strtolower($k); |
|
| 2354 | - array_push($search_query_leftover, $not ? "!$k" : $k); |
|
| 2355 | - } else { |
|
| 2356 | - array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
| 2352 | + if (DB_TYPE == "pgsql") { |
|
| 2353 | + $k = mb_strtolower($k); |
|
| 2354 | + array_push($search_query_leftover, $not ? "!$k" : $k); |
|
| 2355 | + } else { |
|
| 2356 | + array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
|
| 2357 | 2357 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2358 | - } |
|
| 2358 | + } |
|
| 2359 | 2359 | |
| 2360 | - if (!$not) { |
|
| 2361 | - array_push($search_words, $k); |
|
| 2362 | - } |
|
| 2360 | + if (!$not) { |
|
| 2361 | + array_push($search_words, $k); |
|
| 2363 | 2362 | } |
| 2363 | + } |
|
| 2364 | 2364 | } |
| 2365 | 2365 | } |
| 2366 | 2366 | |
@@ -50,8 +50,9 @@ discard block |
||
| 50 | 50 | $reply .= strip_tags($feed_title); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - if ($error) |
|
| 54 | - $reply .= " <i title=\"".htmlspecialchars($error)."\" class='material-icons icon-error'>error</i>"; |
|
| 53 | + if ($error) { |
|
| 54 | + $reply .= " <i title=\"".htmlspecialchars($error)."\" class='material-icons icon-error'>error</i>"; |
|
| 55 | + } |
|
| 55 | 56 | |
| 56 | 57 | $reply .= "</span>"; |
| 57 | 58 | $reply .= "<span id='feed_current_unread' style='display: none'></span>"; |
@@ -2285,56 +2286,68 @@ discard block |
||
| 2285 | 2286 | break; |
| 2286 | 2287 | case "note": |
| 2287 | 2288 | if ($commandpair[1]) { |
| 2288 | - if ($commandpair[1] == "true") |
|
| 2289 | - array_push($query_keywords, "($not (note IS NOT NULL AND note != ''))"); |
|
| 2290 | - else if ($commandpair[1] == "false") |
|
| 2291 | - array_push($query_keywords, "($not (note IS NULL OR note = ''))"); |
|
| 2292 | - else |
|
| 2293 | - array_push($query_keywords, "($not (LOWER(note) LIKE ". |
|
| 2289 | + if ($commandpair[1] == "true") { |
|
| 2290 | + array_push($query_keywords, "($not (note IS NOT NULL AND note != ''))"); |
|
| 2291 | + } else if ($commandpair[1] == "false") { |
|
| 2292 | + array_push($query_keywords, "($not (note IS NULL OR note = ''))"); |
|
| 2293 | + } else { |
|
| 2294 | + array_push($query_keywords, "($not (LOWER(note) LIKE ". |
|
| 2294 | 2295 | $pdo->quote('%'.mb_strtolower($commandpair[1]).'%')."))"); |
| 2296 | + } |
|
| 2295 | 2297 | } else { |
| 2296 | 2298 | array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
| 2297 | 2299 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2298 | - if (!$not) array_push($search_words, $k); |
|
| 2300 | + if (!$not) { |
|
| 2301 | + array_push($search_words, $k); |
|
| 2302 | + } |
|
| 2299 | 2303 | } |
| 2300 | 2304 | break; |
| 2301 | 2305 | case "star": |
| 2302 | 2306 | |
| 2303 | 2307 | if ($commandpair[1]) { |
| 2304 | - if ($commandpair[1] == "true") |
|
| 2305 | - array_push($query_keywords, "($not (marked = true))"); |
|
| 2306 | - else |
|
| 2307 | - array_push($query_keywords, "($not (marked = false))"); |
|
| 2308 | + if ($commandpair[1] == "true") { |
|
| 2309 | + array_push($query_keywords, "($not (marked = true))"); |
|
| 2310 | + } else { |
|
| 2311 | + array_push($query_keywords, "($not (marked = false))"); |
|
| 2312 | + } |
|
| 2308 | 2313 | } else { |
| 2309 | 2314 | array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
| 2310 | 2315 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2311 | - if (!$not) array_push($search_words, $k); |
|
| 2316 | + if (!$not) { |
|
| 2317 | + array_push($search_words, $k); |
|
| 2318 | + } |
|
| 2312 | 2319 | } |
| 2313 | 2320 | break; |
| 2314 | 2321 | case "pub": |
| 2315 | 2322 | if ($commandpair[1]) { |
| 2316 | - if ($commandpair[1] == "true") |
|
| 2317 | - array_push($query_keywords, "($not (published = true))"); |
|
| 2318 | - else |
|
| 2319 | - array_push($query_keywords, "($not (published = false))"); |
|
| 2323 | + if ($commandpair[1] == "true") { |
|
| 2324 | + array_push($query_keywords, "($not (published = true))"); |
|
| 2325 | + } else { |
|
| 2326 | + array_push($query_keywords, "($not (published = false))"); |
|
| 2327 | + } |
|
| 2320 | 2328 | |
| 2321 | 2329 | } else { |
| 2322 | 2330 | array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%') |
| 2323 | 2331 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2324 | - if (!$not) array_push($search_words, $k); |
|
| 2332 | + if (!$not) { |
|
| 2333 | + array_push($search_words, $k); |
|
| 2334 | + } |
|
| 2325 | 2335 | } |
| 2326 | 2336 | break; |
| 2327 | 2337 | case "unread": |
| 2328 | 2338 | if ($commandpair[1]) { |
| 2329 | - if ($commandpair[1] == "true") |
|
| 2330 | - array_push($query_keywords, "($not (unread = true))"); |
|
| 2331 | - else |
|
| 2332 | - array_push($query_keywords, "($not (unread = false))"); |
|
| 2339 | + if ($commandpair[1] == "true") { |
|
| 2340 | + array_push($query_keywords, "($not (unread = true))"); |
|
| 2341 | + } else { |
|
| 2342 | + array_push($query_keywords, "($not (unread = false))"); |
|
| 2343 | + } |
|
| 2333 | 2344 | |
| 2334 | 2345 | } else { |
| 2335 | 2346 | array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER(".$pdo->quote("%$k%").") |
| 2336 | 2347 | OR UPPER(ttrss_entries.content) $not LIKE UPPER(".$pdo->quote("%$k%")."))"); |
| 2337 | - if (!$not) array_push($search_words, $k); |
|
| 2348 | + if (!$not) { |
|
| 2349 | + array_push($search_words, $k); |
|
| 2350 | + } |
|
| 2338 | 2351 | } |
| 2339 | 2352 | break; |
| 2340 | 2353 | default: |
@@ -1,55 +1,55 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | class Mailer { |
| 3 | - // TODO: support HTML mail (i.e. MIME messages) |
|
| 3 | + // TODO: support HTML mail (i.e. MIME messages) |
|
| 4 | 4 | |
| 5 | - private $last_error = "Unable to send mail: check local configuration."; |
|
| 5 | + private $last_error = "Unable to send mail: check local configuration."; |
|
| 6 | 6 | |
| 7 | - public function mail($params) { |
|
| 7 | + public function mail($params) { |
|
| 8 | 8 | |
| 9 | - $to_name = $params["to_name"]; |
|
| 10 | - $to_address = $params["to_address"]; |
|
| 11 | - $subject = $params["subject"]; |
|
| 12 | - $message = $params["message"]; |
|
| 13 | - $from_name = $params["from_name"] ? $params["from_name"] : SMTP_FROM_NAME; |
|
| 14 | - $from_address = $params["from_address"] ? $params["from_address"] : SMTP_FROM_ADDRESS; |
|
| 9 | + $to_name = $params["to_name"]; |
|
| 10 | + $to_address = $params["to_address"]; |
|
| 11 | + $subject = $params["subject"]; |
|
| 12 | + $message = $params["message"]; |
|
| 13 | + $from_name = $params["from_name"] ? $params["from_name"] : SMTP_FROM_NAME; |
|
| 14 | + $from_address = $params["from_address"] ? $params["from_address"] : SMTP_FROM_ADDRESS; |
|
| 15 | 15 | |
| 16 | - $additional_headers = $params["headers"] ? $params["headers"] : []; |
|
| 16 | + $additional_headers = $params["headers"] ? $params["headers"] : []; |
|
| 17 | 17 | |
| 18 | - $from_combined = $from_name ? "$from_name <$from_address>" : $from_address; |
|
| 19 | - $to_combined = $to_name ? "$to_name <$to_address>" : $to_address; |
|
| 18 | + $from_combined = $from_name ? "$from_name <$from_address>" : $from_address; |
|
| 19 | + $to_combined = $to_name ? "$to_name <$to_address>" : $to_address; |
|
| 20 | 20 | |
| 21 | - if (defined('_LOG_SENT_MAIL') && _LOG_SENT_MAIL) { |
|
| 22 | - Logger::get()->log("Sending mail from $from_combined to $to_combined [$subject]: $message"); |
|
| 23 | - } |
|
| 21 | + if (defined('_LOG_SENT_MAIL') && _LOG_SENT_MAIL) { |
|
| 22 | + Logger::get()->log("Sending mail from $from_combined to $to_combined [$subject]: $message"); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - // HOOK_SEND_MAIL plugin instructions: |
|
| 26 | - // 1. return 1 or true if mail is handled |
|
| 27 | - // 2. return -1 if there's been a fatal error and no further action is allowed |
|
| 28 | - // 3. any other return value will allow cycling to the next handler and, eventually, to default mail() function |
|
| 29 | - // 4. set error message if needed via passed Mailer instance function set_error() |
|
| 25 | + // HOOK_SEND_MAIL plugin instructions: |
|
| 26 | + // 1. return 1 or true if mail is handled |
|
| 27 | + // 2. return -1 if there's been a fatal error and no further action is allowed |
|
| 28 | + // 3. any other return value will allow cycling to the next handler and, eventually, to default mail() function |
|
| 29 | + // 4. set error message if needed via passed Mailer instance function set_error() |
|
| 30 | 30 | |
| 31 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEND_MAIL) as $p) { |
|
| 32 | - $rc = $p->hook_send_mail($this, $params); |
|
| 31 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEND_MAIL) as $p) { |
|
| 32 | + $rc = $p->hook_send_mail($this, $params); |
|
| 33 | 33 | |
| 34 | - if ($rc == 1) { |
|
| 35 | - return $rc; |
|
| 36 | - } |
|
| 34 | + if ($rc == 1) { |
|
| 35 | + return $rc; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - if ($rc == -1) { |
|
| 39 | - return 0; |
|
| 40 | - } |
|
| 41 | - } |
|
| 38 | + if ($rc == -1) { |
|
| 39 | + return 0; |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - $headers = ["From: $from_combined", "Content-Type: text/plain; charset=UTF-8"]; |
|
| 43 | + $headers = ["From: $from_combined", "Content-Type: text/plain; charset=UTF-8"]; |
|
| 44 | 44 | |
| 45 | - return mail($to_combined, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers))); |
|
| 46 | - } |
|
| 45 | + return mail($to_combined, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers))); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public function set_error($message) { |
|
| 49 | - $this->last_error = $message; |
|
| 50 | - } |
|
| 48 | + public function set_error($message) { |
|
| 49 | + $this->last_error = $message; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - public function error() { |
|
| 53 | - return $this->last_error; |
|
| 54 | - } |
|
| 52 | + public function error() { |
|
| 53 | + return $this->last_error; |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -1,206 +1,206 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | class Dlg extends Handler_Protected { |
| 3 | - private $param; |
|
| 3 | + private $param; |
|
| 4 | 4 | private $params; |
| 5 | 5 | |
| 6 | 6 | function before($method) { |
| 7 | - if (parent::before($method)) { |
|
| 8 | - header("Content-Type: text/html"); # required for iframe |
|
| 7 | + if (parent::before($method)) { |
|
| 8 | + header("Content-Type: text/html"); # required for iframe |
|
| 9 | 9 | |
| 10 | - $this->param = $_REQUEST["param"]; |
|
| 11 | - return true; |
|
| 12 | - } |
|
| 13 | - return false; |
|
| 14 | - } |
|
| 10 | + $this->param = $_REQUEST["param"]; |
|
| 11 | + return true; |
|
| 12 | + } |
|
| 13 | + return false; |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - public function importOpml() { |
|
| 17 | - print_notice("If you have imported labels and/or filters, you might need to reload preferences to see your new data."); |
|
| 16 | + public function importOpml() { |
|
| 17 | + print_notice("If you have imported labels and/or filters, you might need to reload preferences to see your new data."); |
|
| 18 | 18 | |
| 19 | - print "<div class='panel panel-scrollable'>"; |
|
| 19 | + print "<div class='panel panel-scrollable'>"; |
|
| 20 | 20 | |
| 21 | - $opml = new Opml($_REQUEST); |
|
| 21 | + $opml = new Opml($_REQUEST); |
|
| 22 | 22 | |
| 23 | - $opml->opml_import($_SESSION["uid"]); |
|
| 23 | + $opml->opml_import($_SESSION["uid"]); |
|
| 24 | 24 | |
| 25 | - print "</div>"; |
|
| 25 | + print "</div>"; |
|
| 26 | 26 | |
| 27 | - print "<footer class='text-center'>"; |
|
| 28 | - print "<button dojoType='dijit.form.Button' |
|
| 27 | + print "<footer class='text-center'>"; |
|
| 28 | + print "<button dojoType='dijit.form.Button' |
|
| 29 | 29 | onclick=\"dijit.byId('opmlImportDlg').execute()\">". |
| 30 | - __('Close this window')."</button>"; |
|
| 31 | - print "</footer>"; |
|
| 30 | + __('Close this window')."</button>"; |
|
| 31 | + print "</footer>"; |
|
| 32 | 32 | |
| 33 | - print "</div>"; |
|
| 33 | + print "</div>"; |
|
| 34 | 34 | |
| 35 | - //return; |
|
| 36 | - } |
|
| 35 | + //return; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - public function pubOPMLUrl() { |
|
| 39 | - $url_path = Opml::opml_publish_url(); |
|
| 38 | + public function pubOPMLUrl() { |
|
| 39 | + $url_path = Opml::opml_publish_url(); |
|
| 40 | 40 | |
| 41 | - print "<header>".__("Your Public OPML URL is:")."</header>"; |
|
| 41 | + print "<header>".__("Your Public OPML URL is:")."</header>"; |
|
| 42 | 42 | |
| 43 | - print "<section>"; |
|
| 43 | + print "<section>"; |
|
| 44 | 44 | |
| 45 | - print "<div class='panel text-center'>"; |
|
| 46 | - print "<a id='pub_opml_url' href='$url_path' target='_blank'>$url_path</a>"; |
|
| 47 | - print "</div>"; |
|
| 45 | + print "<div class='panel text-center'>"; |
|
| 46 | + print "<a id='pub_opml_url' href='$url_path' target='_blank'>$url_path</a>"; |
|
| 47 | + print "</div>"; |
|
| 48 | 48 | |
| 49 | - print "</section>"; |
|
| 49 | + print "</section>"; |
|
| 50 | 50 | |
| 51 | - print "<footer class='text-center'>"; |
|
| 51 | + print "<footer class='text-center'>"; |
|
| 52 | 52 | |
| 53 | - print "<button dojoType='dijit.form.Button' onclick=\"return Helpers.OPML.changeKey()\">". |
|
| 54 | - __('Generate new URL')."</button> "; |
|
| 53 | + print "<button dojoType='dijit.form.Button' onclick=\"return Helpers.OPML.changeKey()\">". |
|
| 54 | + __('Generate new URL')."</button> "; |
|
| 55 | 55 | |
| 56 | - print "<button dojoType='dijit.form.Button' onclick=\"return CommonDialogs.closeInfoBox()\">". |
|
| 57 | - __('Close this window')."</button>"; |
|
| 56 | + print "<button dojoType='dijit.form.Button' onclick=\"return CommonDialogs.closeInfoBox()\">". |
|
| 57 | + __('Close this window')."</button>"; |
|
| 58 | 58 | |
| 59 | - print "</footer>"; |
|
| 59 | + print "</footer>"; |
|
| 60 | 60 | |
| 61 | - //return; |
|
| 62 | - } |
|
| 61 | + //return; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - public function explainError() { |
|
| 65 | - print "<div class=\"errorExplained\">"; |
|
| 64 | + public function explainError() { |
|
| 65 | + print "<div class=\"errorExplained\">"; |
|
| 66 | 66 | |
| 67 | - if ($this->param == 1) { |
|
| 68 | - print __("Update daemon is enabled in configuration, but daemon process is not running, which prevents all feeds from updating. Please start the daemon process or contact instance owner."); |
|
| 67 | + if ($this->param == 1) { |
|
| 68 | + print __("Update daemon is enabled in configuration, but daemon process is not running, which prevents all feeds from updating. Please start the daemon process or contact instance owner."); |
|
| 69 | 69 | |
| 70 | - $stamp = (int) file_get_contents(LOCK_DIRECTORY."/update_daemon.stamp"); |
|
| 70 | + $stamp = (int) file_get_contents(LOCK_DIRECTORY."/update_daemon.stamp"); |
|
| 71 | 71 | |
| 72 | - print "<p>".__("Last update:")." ".date("Y.m.d, G:i", $stamp); |
|
| 72 | + print "<p>".__("Last update:")." ".date("Y.m.d, G:i", $stamp); |
|
| 73 | 73 | |
| 74 | - } |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - if ($this->param == 3) { |
|
| 77 | - print __("Update daemon is taking too long to perform a feed update. This could indicate a problem like crash or a hang. Please check the daemon process or contact instance owner."); |
|
| 76 | + if ($this->param == 3) { |
|
| 77 | + print __("Update daemon is taking too long to perform a feed update. This could indicate a problem like crash or a hang. Please check the daemon process or contact instance owner."); |
|
| 78 | 78 | |
| 79 | - $stamp = (int) file_get_contents(LOCK_DIRECTORY."/update_daemon.stamp"); |
|
| 79 | + $stamp = (int) file_get_contents(LOCK_DIRECTORY."/update_daemon.stamp"); |
|
| 80 | 80 | |
| 81 | - print "<p>".__("Last update:")." ".date("Y.m.d, G:i", $stamp); |
|
| 81 | + print "<p>".__("Last update:")." ".date("Y.m.d, G:i", $stamp); |
|
| 82 | 82 | |
| 83 | - } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - print "</div>"; |
|
| 85 | + print "</div>"; |
|
| 86 | 86 | |
| 87 | - print "<footer class='text-center'>"; |
|
| 88 | - print "<button onclick=\"return CommonDialogs.closeInfoBox()\">". |
|
| 89 | - __('Close this window')."</button>"; |
|
| 90 | - print "</footer>"; |
|
| 87 | + print "<footer class='text-center'>"; |
|
| 88 | + print "<button onclick=\"return CommonDialogs.closeInfoBox()\">". |
|
| 89 | + __('Close this window')."</button>"; |
|
| 90 | + print "</footer>"; |
|
| 91 | 91 | |
| 92 | - //return; |
|
| 93 | - } |
|
| 92 | + //return; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - public function printTagCloud() { |
|
| 96 | - print "<div class='panel text-center'>"; |
|
| 95 | + public function printTagCloud() { |
|
| 96 | + print "<div class='panel text-center'>"; |
|
| 97 | 97 | |
| 98 | - // from here: http://www.roscripts.com/Create_tag_cloud-71.html |
|
| 98 | + // from here: http://www.roscripts.com/Create_tag_cloud-71.html |
|
| 99 | 99 | |
| 100 | - $sth = $this->pdo->prepare("SELECT tag_name, COUNT(post_int_id) AS count |
|
| 100 | + $sth = $this->pdo->prepare("SELECT tag_name, COUNT(post_int_id) AS count |
|
| 101 | 101 | FROM ttrss_tags WHERE owner_uid = ? |
| 102 | 102 | GROUP BY tag_name ORDER BY count DESC LIMIT 50"); |
| 103 | - $sth->execute([$_SESSION['uid']]); |
|
| 103 | + $sth->execute([$_SESSION['uid']]); |
|
| 104 | 104 | |
| 105 | - $tags = array(); |
|
| 105 | + $tags = array(); |
|
| 106 | 106 | |
| 107 | - while ($line = $sth->fetch()) { |
|
| 108 | - $tags[$line["tag_name"]] = $line["count"]; |
|
| 109 | - } |
|
| 107 | + while ($line = $sth->fetch()) { |
|
| 108 | + $tags[$line["tag_name"]] = $line["count"]; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | 111 | if (count($tags) == 0) { return; } |
| 112 | 112 | |
| 113 | - ksort($tags); |
|
| 113 | + ksort($tags); |
|
| 114 | 114 | |
| 115 | - $max_size = 32; // max font size in pixels |
|
| 116 | - $min_size = 11; // min font size in pixels |
|
| 115 | + $max_size = 32; // max font size in pixels |
|
| 116 | + $min_size = 11; // min font size in pixels |
|
| 117 | 117 | |
| 118 | - // largest and smallest array values |
|
| 119 | - $max_qty = max(array_values($tags)); |
|
| 120 | - $min_qty = min(array_values($tags)); |
|
| 118 | + // largest and smallest array values |
|
| 119 | + $max_qty = max(array_values($tags)); |
|
| 120 | + $min_qty = min(array_values($tags)); |
|
| 121 | 121 | |
| 122 | - // find the range of values |
|
| 123 | - $spread = $max_qty - $min_qty; |
|
| 124 | - if ($spread == 0) { // we don't want to divide by zero |
|
| 125 | - $spread = 1; |
|
| 126 | - } |
|
| 122 | + // find the range of values |
|
| 123 | + $spread = $max_qty - $min_qty; |
|
| 124 | + if ($spread == 0) { // we don't want to divide by zero |
|
| 125 | + $spread = 1; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - // set the font-size increment |
|
| 129 | - $step = ($max_size - $min_size) / ($spread); |
|
| 128 | + // set the font-size increment |
|
| 129 | + $step = ($max_size - $min_size) / ($spread); |
|
| 130 | 130 | |
| 131 | - // loop through the tag array |
|
| 132 | - foreach ($tags as $key => $value) { |
|
| 133 | - // calculate font-size |
|
| 134 | - // find the $value in excess of $min_qty |
|
| 135 | - // multiply by the font-size increment ($size) |
|
| 136 | - // and add the $min_size set above |
|
| 137 | - $size = round($min_size + (($value - $min_qty) * $step)); |
|
| 131 | + // loop through the tag array |
|
| 132 | + foreach ($tags as $key => $value) { |
|
| 133 | + // calculate font-size |
|
| 134 | + // find the $value in excess of $min_qty |
|
| 135 | + // multiply by the font-size increment ($size) |
|
| 136 | + // and add the $min_size set above |
|
| 137 | + $size = round($min_size + (($value - $min_qty) * $step)); |
|
| 138 | 138 | |
| 139 | - $key_escaped = str_replace("'", "\\'", $key); |
|
| 139 | + $key_escaped = str_replace("'", "\\'", $key); |
|
| 140 | 140 | |
| 141 | - echo "<a href=\"#\" onclick=\"Feeds.open({feed:'$key_escaped'}) \" style=\"font-size: ". |
|
| 142 | - $size."px\" title=\"$value articles tagged with ". |
|
| 143 | - $key.'">'.$key.'</a> '; |
|
| 144 | - } |
|
| 141 | + echo "<a href=\"#\" onclick=\"Feeds.open({feed:'$key_escaped'}) \" style=\"font-size: ". |
|
| 142 | + $size."px\" title=\"$value articles tagged with ". |
|
| 143 | + $key.'">'.$key.'</a> '; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | 146 | |
| 147 | 147 | |
| 148 | - print "</div>"; |
|
| 148 | + print "</div>"; |
|
| 149 | 149 | |
| 150 | - print "<footer class='text-center'>"; |
|
| 151 | - print "<button dojoType='dijit.form.Button' |
|
| 150 | + print "<footer class='text-center'>"; |
|
| 151 | + print "<button dojoType='dijit.form.Button' |
|
| 152 | 152 | onclick=\"return CommonDialogs.closeInfoBox()\">". |
| 153 | - __('Close this window')."</button>"; |
|
| 154 | - print "</footer>"; |
|
| 153 | + __('Close this window')."</button>"; |
|
| 154 | + print "</footer>"; |
|
| 155 | 155 | |
| 156 | - } |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - public function generatedFeed() { |
|
| 158 | + public function generatedFeed() { |
|
| 159 | 159 | |
| 160 | - $this->params = explode(":", $this->param, 3); |
|
| 161 | - $feed_id = $this->params[0]; |
|
| 162 | - $is_cat = (bool) $this->params[1]; |
|
| 160 | + $this->params = explode(":", $this->param, 3); |
|
| 161 | + $feed_id = $this->params[0]; |
|
| 162 | + $is_cat = (bool) $this->params[1]; |
|
| 163 | 163 | |
| 164 | - $key = Feeds::get_feed_access_key($feed_id, $is_cat); |
|
| 164 | + $key = Feeds::get_feed_access_key($feed_id, $is_cat); |
|
| 165 | 165 | |
| 166 | - $url_path = htmlspecialchars($this->params[2])."&key=".$key; |
|
| 166 | + $url_path = htmlspecialchars($this->params[2])."&key=".$key; |
|
| 167 | 167 | |
| 168 | - $feed_title = Feeds::getFeedTitle($feed_id, $is_cat); |
|
| 168 | + $feed_title = Feeds::getFeedTitle($feed_id, $is_cat); |
|
| 169 | 169 | |
| 170 | - print "<header>".T_sprintf("%s can be accessed via the following secret URL:", $feed_title)."</header>"; |
|
| 170 | + print "<header>".T_sprintf("%s can be accessed via the following secret URL:", $feed_title)."</header>"; |
|
| 171 | 171 | |
| 172 | - print "<section>"; |
|
| 173 | - print "<div class='panel text-center'>"; |
|
| 174 | - print "<a id='gen_feed_url' href='$url_path' target='_blank'>$url_path</a>"; |
|
| 175 | - print "</div>"; |
|
| 176 | - print "</section>"; |
|
| 172 | + print "<section>"; |
|
| 173 | + print "<div class='panel text-center'>"; |
|
| 174 | + print "<a id='gen_feed_url' href='$url_path' target='_blank'>$url_path</a>"; |
|
| 175 | + print "</div>"; |
|
| 176 | + print "</section>"; |
|
| 177 | 177 | |
| 178 | - print "<footer>"; |
|
| 178 | + print "<footer>"; |
|
| 179 | 179 | |
| 180 | - print "<button dojoType='dijit.form.Button' style='float : left' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/GeneratedFeeds\")'> |
|
| 180 | + print "<button dojoType='dijit.form.Button' style='float : left' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/GeneratedFeeds\")'> |
|
| 181 | 181 | <i class='material-icons'>help</i> ".__("More info...")."</button>"; |
| 182 | 182 | |
| 183 | - print "<button dojoType='dijit.form.Button' onclick=\"return CommonDialogs.genUrlChangeKey('$feed_id', '$is_cat')\">". |
|
| 184 | - __('Generate new URL')."</button> "; |
|
| 183 | + print "<button dojoType='dijit.form.Button' onclick=\"return CommonDialogs.genUrlChangeKey('$feed_id', '$is_cat')\">". |
|
| 184 | + __('Generate new URL')."</button> "; |
|
| 185 | 185 | |
| 186 | - print "<button dojoType='dijit.form.Button' onclick=\"return CommonDialogs.closeInfoBox()\">". |
|
| 187 | - __('Close this window')."</button>"; |
|
| 186 | + print "<button dojoType='dijit.form.Button' onclick=\"return CommonDialogs.closeInfoBox()\">". |
|
| 187 | + __('Close this window')."</button>"; |
|
| 188 | 188 | |
| 189 | - print "</footer>"; |
|
| 189 | + print "</footer>"; |
|
| 190 | 190 | |
| 191 | - //return; |
|
| 192 | - } |
|
| 191 | + //return; |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - public function defaultPasswordWarning() { |
|
| 194 | + public function defaultPasswordWarning() { |
|
| 195 | 195 | |
| 196 | - print_warning(__("You are using default tt-rss password. Please change it in the Preferences (Personal data / Authentication).")); |
|
| 196 | + print_warning(__("You are using default tt-rss password. Please change it in the Preferences (Personal data / Authentication).")); |
|
| 197 | 197 | |
| 198 | - print "<footer class='text-center'>"; |
|
| 199 | - print "<button dojoType='dijit.form.Button' onclick=\"document.location.href = 'prefs.php'\">". |
|
| 200 | - __('Open Preferences')."</button> "; |
|
| 201 | - print "<button dojoType='dijit.form.Button' |
|
| 198 | + print "<footer class='text-center'>"; |
|
| 199 | + print "<button dojoType='dijit.form.Button' onclick=\"document.location.href = 'prefs.php'\">". |
|
| 200 | + __('Open Preferences')."</button> "; |
|
| 201 | + print "<button dojoType='dijit.form.Button' |
|
| 202 | 202 | onclick=\"return CommonDialogs.closeInfoBox()\">". |
| 203 | - __('Close this window')."</button>"; |
|
| 204 | - print "</footeer>"; |
|
| 205 | - } |
|
| 203 | + __('Close this window')."</button>"; |
|
| 204 | + print "</footeer>"; |
|
| 205 | + } |
|
| 206 | 206 | } |
@@ -1,641 +1,641 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | class Article extends Handler_Protected { |
| 3 | 3 | |
| 4 | - public function csrf_ignore($method) { |
|
| 5 | - $csrf_ignored = array("redirect", "editarticletags"); |
|
| 4 | + public function csrf_ignore($method) { |
|
| 5 | + $csrf_ignored = array("redirect", "editarticletags"); |
|
| 6 | 6 | |
| 7 | - return array_search($method, $csrf_ignored) !== false; |
|
| 8 | - } |
|
| 7 | + return array_search($method, $csrf_ignored) !== false; |
|
| 8 | + } |
|
| 9 | 9 | |
| 10 | - public function redirect() { |
|
| 11 | - $id = clean($_REQUEST['id']); |
|
| 10 | + public function redirect() { |
|
| 11 | + $id = clean($_REQUEST['id']); |
|
| 12 | 12 | |
| 13 | - $sth = $this->pdo->prepare("SELECT link FROM ttrss_entries, ttrss_user_entries |
|
| 13 | + $sth = $this->pdo->prepare("SELECT link FROM ttrss_entries, ttrss_user_entries |
|
| 14 | 14 | WHERE id = ? AND id = ref_id AND owner_uid = ? |
| 15 | 15 | LIMIT 1"); |
| 16 | 16 | $sth->execute([$id, $_SESSION['uid']]); |
| 17 | 17 | |
| 18 | - if ($row = $sth->fetch()) { |
|
| 19 | - $article_url = $row['link']; |
|
| 20 | - $article_url = str_replace("\n", "", $article_url); |
|
| 18 | + if ($row = $sth->fetch()) { |
|
| 19 | + $article_url = $row['link']; |
|
| 20 | + $article_url = str_replace("\n", "", $article_url); |
|
| 21 | 21 | |
| 22 | - header("Location: $article_url"); |
|
| 23 | - return; |
|
| 22 | + header("Location: $article_url"); |
|
| 23 | + return; |
|
| 24 | 24 | |
| 25 | - } else { |
|
| 26 | - print_error(__("Article not found.")); |
|
| 27 | - } |
|
| 28 | - } |
|
| 25 | + } else { |
|
| 26 | + print_error(__("Article not found.")); |
|
| 27 | + } |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public static function create_published_article($title, $url, $content, $labels_str, |
|
| 31 | - $owner_uid) { |
|
| 30 | + public static function create_published_article($title, $url, $content, $labels_str, |
|
| 31 | + $owner_uid) { |
|
| 32 | 32 | |
| 33 | - $guid = 'SHA1:'.sha1("ttshared:".$url.$owner_uid); // include owner_uid to prevent global GUID clash |
|
| 33 | + $guid = 'SHA1:'.sha1("ttshared:".$url.$owner_uid); // include owner_uid to prevent global GUID clash |
|
| 34 | 34 | |
| 35 | - if (!$content) { |
|
| 36 | - $pluginhost = new PluginHost(); |
|
| 37 | - $pluginhost->load_all(PluginHost::KIND_ALL, $owner_uid); |
|
| 38 | - $pluginhost->load_data(); |
|
| 35 | + if (!$content) { |
|
| 36 | + $pluginhost = new PluginHost(); |
|
| 37 | + $pluginhost->load_all(PluginHost::KIND_ALL, $owner_uid); |
|
| 38 | + $pluginhost->load_data(); |
|
| 39 | 39 | |
| 40 | - foreach ($pluginhost->get_hooks(PluginHost::HOOK_GET_FULL_TEXT) as $p) { |
|
| 41 | - $extracted_content = $p->hook_get_full_text($url); |
|
| 40 | + foreach ($pluginhost->get_hooks(PluginHost::HOOK_GET_FULL_TEXT) as $p) { |
|
| 41 | + $extracted_content = $p->hook_get_full_text($url); |
|
| 42 | 42 | |
| 43 | - if ($extracted_content) { |
|
| 44 | - $content = $extracted_content; |
|
| 45 | - break; |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - } |
|
| 43 | + if ($extracted_content) { |
|
| 44 | + $content = $extracted_content; |
|
| 45 | + break; |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - $content_hash = sha1($content); |
|
| 50 | + $content_hash = sha1($content); |
|
| 51 | 51 | |
| 52 | - if ($labels_str != "") { |
|
| 53 | - $labels = explode(",", $labels_str); |
|
| 54 | - } else { |
|
| 55 | - $labels = array(); |
|
| 56 | - } |
|
| 52 | + if ($labels_str != "") { |
|
| 53 | + $labels = explode(",", $labels_str); |
|
| 54 | + } else { |
|
| 55 | + $labels = array(); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $rc = false; |
|
| 58 | + $rc = false; |
|
| 59 | 59 | |
| 60 | - if (!$title) { |
|
| 61 | - $title = $url; |
|
| 62 | - } |
|
| 63 | - if (!$title && !$url) { |
|
| 64 | - return false; |
|
| 65 | - } |
|
| 60 | + if (!$title) { |
|
| 61 | + $title = $url; |
|
| 62 | + } |
|
| 63 | + if (!$title && !$url) { |
|
| 64 | + return false; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - if (filter_var($url, FILTER_VALIDATE_URL) === false) { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 67 | + if (filter_var($url, FILTER_VALIDATE_URL) === false) { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - $pdo = Db::pdo(); |
|
| 71 | + $pdo = Db::pdo(); |
|
| 72 | 72 | |
| 73 | - $pdo->beginTransaction(); |
|
| 73 | + $pdo->beginTransaction(); |
|
| 74 | 74 | |
| 75 | - // only check for our user data here, others might have shared this with different content etc |
|
| 76 | - $sth = $pdo->prepare("SELECT id FROM ttrss_entries, ttrss_user_entries WHERE |
|
| 75 | + // only check for our user data here, others might have shared this with different content etc |
|
| 76 | + $sth = $pdo->prepare("SELECT id FROM ttrss_entries, ttrss_user_entries WHERE |
|
| 77 | 77 | guid = ? AND ref_id = id AND owner_uid = ? LIMIT 1"); |
| 78 | - $sth->execute([$guid, $owner_uid]); |
|
| 78 | + $sth->execute([$guid, $owner_uid]); |
|
| 79 | 79 | |
| 80 | - if ($row = $sth->fetch()) { |
|
| 81 | - $ref_id = $row['id']; |
|
| 80 | + if ($row = $sth->fetch()) { |
|
| 81 | + $ref_id = $row['id']; |
|
| 82 | 82 | |
| 83 | - $sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
|
| 83 | + $sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
|
| 84 | 84 | ref_id = ? AND owner_uid = ? LIMIT 1"); |
| 85 | 85 | $sth->execute([$ref_id, $owner_uid]); |
| 86 | 86 | |
| 87 | - if ($row = $sth->fetch()) { |
|
| 88 | - $int_id = $row['int_id']; |
|
| 87 | + if ($row = $sth->fetch()) { |
|
| 88 | + $int_id = $row['int_id']; |
|
| 89 | 89 | |
| 90 | - $sth = $pdo->prepare("UPDATE ttrss_entries SET |
|
| 90 | + $sth = $pdo->prepare("UPDATE ttrss_entries SET |
|
| 91 | 91 | content = ?, content_hash = ? WHERE id = ?"); |
| 92 | - $sth->execute([$content, $content_hash, $ref_id]); |
|
| 92 | + $sth->execute([$content, $content_hash, $ref_id]); |
|
| 93 | 93 | |
| 94 | - if (DB_TYPE == "pgsql") { |
|
| 95 | - $sth = $pdo->prepare("UPDATE ttrss_entries |
|
| 94 | + if (DB_TYPE == "pgsql") { |
|
| 95 | + $sth = $pdo->prepare("UPDATE ttrss_entries |
|
| 96 | 96 | SET tsvector_combined = to_tsvector( :ts_content) |
| 97 | 97 | WHERE id = :id"); |
| 98 | - $params = [ |
|
| 99 | - ":ts_content" => mb_substr(strip_tags($content), 0, 900000), |
|
| 100 | - ":id" => $ref_id]; |
|
| 101 | - $sth->execute($params); |
|
| 102 | - } |
|
| 98 | + $params = [ |
|
| 99 | + ":ts_content" => mb_substr(strip_tags($content), 0, 900000), |
|
| 100 | + ":id" => $ref_id]; |
|
| 101 | + $sth->execute($params); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries SET published = true, |
|
| 104 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries SET published = true, |
|
| 105 | 105 | last_published = NOW() WHERE |
| 106 | 106 | int_id = ? AND owner_uid = ?"); |
| 107 | - $sth->execute([$int_id, $owner_uid]); |
|
| 107 | + $sth->execute([$int_id, $owner_uid]); |
|
| 108 | 108 | |
| 109 | - } else { |
|
| 109 | + } else { |
|
| 110 | 110 | |
| 111 | - $sth = $pdo->prepare("INSERT INTO ttrss_user_entries |
|
| 111 | + $sth = $pdo->prepare("INSERT INTO ttrss_user_entries |
|
| 112 | 112 | (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, |
| 113 | 113 | last_read, note, unread, last_published) |
| 114 | 114 | VALUES |
| 115 | 115 | (?, '', NULL, NULL, ?, true, '', '', NOW(), '', false, NOW())"); |
| 116 | - $sth->execute([$ref_id, $owner_uid]); |
|
| 117 | - } |
|
| 116 | + $sth->execute([$ref_id, $owner_uid]); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - if (count($labels) != 0) { |
|
| 120 | - foreach ($labels as $label) { |
|
| 121 | - Labels::add_article($ref_id, trim($label), $owner_uid); |
|
| 122 | - } |
|
| 123 | - } |
|
| 119 | + if (count($labels) != 0) { |
|
| 120 | + foreach ($labels as $label) { |
|
| 121 | + Labels::add_article($ref_id, trim($label), $owner_uid); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - $rc = true; |
|
| 125 | + $rc = true; |
|
| 126 | 126 | |
| 127 | - } else { |
|
| 128 | - $sth = $pdo->prepare("INSERT INTO ttrss_entries |
|
| 127 | + } else { |
|
| 128 | + $sth = $pdo->prepare("INSERT INTO ttrss_entries |
|
| 129 | 129 | (title, guid, link, updated, content, content_hash, date_entered, date_updated) |
| 130 | 130 | VALUES |
| 131 | 131 | (?, ?, ?, NOW(), ?, ?, NOW(), NOW())"); |
| 132 | - $sth->execute([$title, $guid, $url, $content, $content_hash]); |
|
| 132 | + $sth->execute([$title, $guid, $url, $content, $content_hash]); |
|
| 133 | 133 | |
| 134 | - $sth = $pdo->prepare("SELECT id FROM ttrss_entries WHERE guid = ?"); |
|
| 135 | - $sth->execute([$guid]); |
|
| 134 | + $sth = $pdo->prepare("SELECT id FROM ttrss_entries WHERE guid = ?"); |
|
| 135 | + $sth->execute([$guid]); |
|
| 136 | 136 | |
| 137 | - if ($row = $sth->fetch()) { |
|
| 138 | - $ref_id = $row["id"]; |
|
| 139 | - if (DB_TYPE == "pgsql") { |
|
| 140 | - $sth = $pdo->prepare("UPDATE ttrss_entries |
|
| 137 | + if ($row = $sth->fetch()) { |
|
| 138 | + $ref_id = $row["id"]; |
|
| 139 | + if (DB_TYPE == "pgsql") { |
|
| 140 | + $sth = $pdo->prepare("UPDATE ttrss_entries |
|
| 141 | 141 | SET tsvector_combined = to_tsvector( :ts_content) |
| 142 | 142 | WHERE id = :id"); |
| 143 | - $params = [ |
|
| 144 | - ":ts_content" => mb_substr(strip_tags($content), 0, 900000), |
|
| 145 | - ":id" => $ref_id]; |
|
| 146 | - $sth->execute($params); |
|
| 147 | - } |
|
| 148 | - $sth = $pdo->prepare("INSERT INTO ttrss_user_entries |
|
| 143 | + $params = [ |
|
| 144 | + ":ts_content" => mb_substr(strip_tags($content), 0, 900000), |
|
| 145 | + ":id" => $ref_id]; |
|
| 146 | + $sth->execute($params); |
|
| 147 | + } |
|
| 148 | + $sth = $pdo->prepare("INSERT INTO ttrss_user_entries |
|
| 149 | 149 | (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, |
| 150 | 150 | last_read, note, unread, last_published) |
| 151 | 151 | VALUES |
| 152 | 152 | (?, '', NULL, NULL, ?, true, '', '', NOW(), '', false, NOW())"); |
| 153 | - $sth->execute([$ref_id, $owner_uid]); |
|
| 153 | + $sth->execute([$ref_id, $owner_uid]); |
|
| 154 | 154 | |
| 155 | - if (count($labels) != 0) { |
|
| 156 | - foreach ($labels as $label) { |
|
| 157 | - Labels::add_article($ref_id, trim($label), $owner_uid); |
|
| 158 | - } |
|
| 159 | - } |
|
| 155 | + if (count($labels) != 0) { |
|
| 156 | + foreach ($labels as $label) { |
|
| 157 | + Labels::add_article($ref_id, trim($label), $owner_uid); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - $rc = true; |
|
| 162 | - } |
|
| 163 | - } |
|
| 161 | + $rc = true; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - $pdo->commit(); |
|
| 165 | + $pdo->commit(); |
|
| 166 | 166 | |
| 167 | - return $rc; |
|
| 168 | - } |
|
| 167 | + return $rc; |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - public function editArticleTags() { |
|
| 170 | + public function editArticleTags() { |
|
| 171 | 171 | |
| 172 | - $param = clean($_REQUEST['param']); |
|
| 172 | + $param = clean($_REQUEST['param']); |
|
| 173 | 173 | |
| 174 | - $tags = Article::get_article_tags($param); |
|
| 174 | + $tags = Article::get_article_tags($param); |
|
| 175 | 175 | |
| 176 | - $tags_str = join(", ", $tags); |
|
| 176 | + $tags_str = join(", ", $tags); |
|
| 177 | 177 | |
| 178 | - print_hidden("id", "$param"); |
|
| 179 | - print_hidden("op", "article"); |
|
| 180 | - print_hidden("method", "setArticleTags"); |
|
| 178 | + print_hidden("id", "$param"); |
|
| 179 | + print_hidden("op", "article"); |
|
| 180 | + print_hidden("method", "setArticleTags"); |
|
| 181 | 181 | |
| 182 | - print "<header class='horizontal'>".__("Tags for this article (separated by commas):")."</header>"; |
|
| 182 | + print "<header class='horizontal'>".__("Tags for this article (separated by commas):")."</header>"; |
|
| 183 | 183 | |
| 184 | - print "<section>"; |
|
| 185 | - print "<textarea dojoType='dijit.form.SimpleTextarea' rows='4' |
|
| 184 | + print "<section>"; |
|
| 185 | + print "<textarea dojoType='dijit.form.SimpleTextarea' rows='4' |
|
| 186 | 186 | style='height : 100px; font-size : 12px; width : 98%' id='tags_str' |
| 187 | 187 | name='tags_str'>$tags_str</textarea> |
| 188 | 188 | <div class='autocomplete' id='tags_choices' |
| 189 | 189 | style='display:none'></div>"; |
| 190 | - print "</section>"; |
|
| 190 | + print "</section>"; |
|
| 191 | 191 | |
| 192 | - print "<footer>"; |
|
| 193 | - print "<button dojoType='dijit.form.Button' |
|
| 192 | + print "<footer>"; |
|
| 193 | + print "<button dojoType='dijit.form.Button' |
|
| 194 | 194 | type='submit' class='alt-primary' onclick=\"dijit.byId('editTagsDlg').execute()\">".__('Save')."</button> "; |
| 195 | - print "<button dojoType='dijit.form.Button' |
|
| 195 | + print "<button dojoType='dijit.form.Button' |
|
| 196 | 196 | onclick=\"dijit.byId('editTagsDlg').hide()\">".__('Cancel')."</button>"; |
| 197 | - print "</footer>"; |
|
| 197 | + print "</footer>"; |
|
| 198 | 198 | |
| 199 | - } |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - public function setScore() { |
|
| 202 | - $ids = explode(",", clean($_REQUEST['id'])); |
|
| 203 | - $score = (int) clean($_REQUEST['score']); |
|
| 201 | + public function setScore() { |
|
| 202 | + $ids = explode(",", clean($_REQUEST['id'])); |
|
| 203 | + $score = (int) clean($_REQUEST['score']); |
|
| 204 | 204 | |
| 205 | - $ids_qmarks = arr_qmarks($ids); |
|
| 205 | + $ids_qmarks = arr_qmarks($ids); |
|
| 206 | 206 | |
| 207 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 207 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 208 | 208 | score = ? WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
| 209 | 209 | |
| 210 | - $sth->execute(array_merge([$score], $ids, [$_SESSION['uid']])); |
|
| 210 | + $sth->execute(array_merge([$score], $ids, [$_SESSION['uid']])); |
|
| 211 | 211 | |
| 212 | - print json_encode(["id" => $ids, "score" => (int) $score]); |
|
| 213 | - } |
|
| 212 | + print json_encode(["id" => $ids, "score" => (int) $score]); |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - public function getScore() { |
|
| 216 | - $id = clean($_REQUEST['id']); |
|
| 215 | + public function getScore() { |
|
| 216 | + $id = clean($_REQUEST['id']); |
|
| 217 | 217 | |
| 218 | - $sth = $this->pdo->prepare("SELECT score FROM ttrss_user_entries WHERE ref_id = ? AND owner_uid = ?"); |
|
| 219 | - $sth->execute([$id, $_SESSION['uid']]); |
|
| 220 | - $row = $sth->fetch(); |
|
| 218 | + $sth = $this->pdo->prepare("SELECT score FROM ttrss_user_entries WHERE ref_id = ? AND owner_uid = ?"); |
|
| 219 | + $sth->execute([$id, $_SESSION['uid']]); |
|
| 220 | + $row = $sth->fetch(); |
|
| 221 | 221 | |
| 222 | - $score = $row['score']; |
|
| 222 | + $score = $row['score']; |
|
| 223 | 223 | |
| 224 | - print json_encode(["id" => $id, "score" => (int) $score]); |
|
| 225 | - } |
|
| 224 | + print json_encode(["id" => $id, "score" => (int) $score]); |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | 227 | |
| 228 | - public function setArticleTags() { |
|
| 228 | + public function setArticleTags() { |
|
| 229 | 229 | |
| 230 | - $id = clean($_REQUEST["id"]); |
|
| 230 | + $id = clean($_REQUEST["id"]); |
|
| 231 | 231 | |
| 232 | - $tags_str = clean($_REQUEST["tags_str"]); |
|
| 233 | - $tags = array_unique(trim_array(explode(",", $tags_str))); |
|
| 232 | + $tags_str = clean($_REQUEST["tags_str"]); |
|
| 233 | + $tags = array_unique(trim_array(explode(",", $tags_str))); |
|
| 234 | 234 | |
| 235 | - $this->pdo->beginTransaction(); |
|
| 235 | + $this->pdo->beginTransaction(); |
|
| 236 | 236 | |
| 237 | - $sth = $this->pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
|
| 237 | + $sth = $this->pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
|
| 238 | 238 | ref_id = ? AND owner_uid = ? LIMIT 1"); |
| 239 | - $sth->execute([$id, $_SESSION['uid']]); |
|
| 239 | + $sth->execute([$id, $_SESSION['uid']]); |
|
| 240 | 240 | |
| 241 | - if ($row = $sth->fetch()) { |
|
| 241 | + if ($row = $sth->fetch()) { |
|
| 242 | 242 | |
| 243 | - $tags_to_cache = array(); |
|
| 243 | + $tags_to_cache = array(); |
|
| 244 | 244 | |
| 245 | - $int_id = $row['int_id']; |
|
| 245 | + $int_id = $row['int_id']; |
|
| 246 | 246 | |
| 247 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_tags WHERE |
|
| 247 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_tags WHERE |
|
| 248 | 248 | post_int_id = ? AND owner_uid = ?"); |
| 249 | - $sth->execute([$int_id, $_SESSION['uid']]); |
|
| 249 | + $sth->execute([$int_id, $_SESSION['uid']]); |
|
| 250 | 250 | |
| 251 | - $tags = FeedItem_Common::normalize_categories($tags); |
|
| 251 | + $tags = FeedItem_Common::normalize_categories($tags); |
|
| 252 | 252 | |
| 253 | - foreach ($tags as $tag) { |
|
| 254 | - if ($tag != '') { |
|
| 255 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_tags |
|
| 253 | + foreach ($tags as $tag) { |
|
| 254 | + if ($tag != '') { |
|
| 255 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_tags |
|
| 256 | 256 | (post_int_id, owner_uid, tag_name) |
| 257 | 257 | VALUES (?, ?, ?)"); |
| 258 | 258 | |
| 259 | - $sth->execute([$int_id, $_SESSION['uid'], $tag]); |
|
| 260 | - } |
|
| 259 | + $sth->execute([$int_id, $_SESSION['uid'], $tag]); |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - array_push($tags_to_cache, $tag); |
|
| 263 | - } |
|
| 262 | + array_push($tags_to_cache, $tag); |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - /* update tag cache */ |
|
| 265 | + /* update tag cache */ |
|
| 266 | 266 | |
| 267 | - $tags_str = join(",", $tags_to_cache); |
|
| 267 | + $tags_str = join(",", $tags_to_cache); |
|
| 268 | 268 | |
| 269 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries |
|
| 269 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries |
|
| 270 | 270 | SET tag_cache = ? WHERE ref_id = ? AND owner_uid = ?"); |
| 271 | - $sth->execute([$tags_str, $id, $_SESSION['uid']]); |
|
| 272 | - } |
|
| 271 | + $sth->execute([$tags_str, $id, $_SESSION['uid']]); |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - $this->pdo->commit(); |
|
| 274 | + $this->pdo->commit(); |
|
| 275 | 275 | |
| 276 | - $tags = Article::get_article_tags($id); |
|
| 277 | - $tags_str = $this->format_tags_string($tags); |
|
| 278 | - $tags_str_full = join(", ", $tags); |
|
| 276 | + $tags = Article::get_article_tags($id); |
|
| 277 | + $tags_str = $this->format_tags_string($tags); |
|
| 278 | + $tags_str_full = join(", ", $tags); |
|
| 279 | 279 | |
| 280 | - if (!$tags_str_full) { |
|
| 281 | - $tags_str_full = __("no tags"); |
|
| 282 | - } |
|
| 280 | + if (!$tags_str_full) { |
|
| 281 | + $tags_str_full = __("no tags"); |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - print json_encode([ |
|
| 285 | - "id" => (int) $id, |
|
| 286 | - "content" => $tags_str, |
|
| 287 | - "content_full" => $tags_str_full |
|
| 288 | - ]); |
|
| 289 | - } |
|
| 284 | + print json_encode([ |
|
| 285 | + "id" => (int) $id, |
|
| 286 | + "content" => $tags_str, |
|
| 287 | + "content_full" => $tags_str_full |
|
| 288 | + ]); |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | 291 | |
| 292 | - public function completeTags() { |
|
| 293 | - $search = clean($_REQUEST["search"]); |
|
| 292 | + public function completeTags() { |
|
| 293 | + $search = clean($_REQUEST["search"]); |
|
| 294 | 294 | |
| 295 | - $sth = $this->pdo->prepare("SELECT DISTINCT tag_name FROM ttrss_tags |
|
| 295 | + $sth = $this->pdo->prepare("SELECT DISTINCT tag_name FROM ttrss_tags |
|
| 296 | 296 | WHERE owner_uid = ? AND |
| 297 | 297 | tag_name LIKE ? ORDER BY tag_name |
| 298 | 298 | LIMIT 10"); |
| 299 | 299 | |
| 300 | - $sth->execute([$_SESSION['uid'], "$search%"]); |
|
| 300 | + $sth->execute([$_SESSION['uid'], "$search%"]); |
|
| 301 | 301 | |
| 302 | - print "<ul>"; |
|
| 303 | - while ($line = $sth->fetch()) { |
|
| 304 | - print "<li>".$line["tag_name"]."</li>"; |
|
| 305 | - } |
|
| 306 | - print "</ul>"; |
|
| 307 | - } |
|
| 302 | + print "<ul>"; |
|
| 303 | + while ($line = $sth->fetch()) { |
|
| 304 | + print "<li>".$line["tag_name"]."</li>"; |
|
| 305 | + } |
|
| 306 | + print "</ul>"; |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - public function assigntolabel() { |
|
| 310 | - return $this->labelops(true); |
|
| 311 | - } |
|
| 309 | + public function assigntolabel() { |
|
| 310 | + return $this->labelops(true); |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - public function removefromlabel() { |
|
| 314 | - return $this->labelops(false); |
|
| 315 | - } |
|
| 313 | + public function removefromlabel() { |
|
| 314 | + return $this->labelops(false); |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | - private function labelops($assign) { |
|
| 318 | - $reply = array(); |
|
| 317 | + private function labelops($assign) { |
|
| 318 | + $reply = array(); |
|
| 319 | 319 | |
| 320 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 321 | - $label_id = clean($_REQUEST["lid"]); |
|
| 320 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
| 321 | + $label_id = clean($_REQUEST["lid"]); |
|
| 322 | 322 | |
| 323 | - $label = Labels::find_caption($label_id, $_SESSION["uid"]); |
|
| 323 | + $label = Labels::find_caption($label_id, $_SESSION["uid"]); |
|
| 324 | 324 | |
| 325 | - $reply["info-for-headlines"] = array(); |
|
| 325 | + $reply["info-for-headlines"] = array(); |
|
| 326 | 326 | |
| 327 | - if ($label) { |
|
| 327 | + if ($label) { |
|
| 328 | 328 | |
| 329 | - foreach ($ids as $id) { |
|
| 329 | + foreach ($ids as $id) { |
|
| 330 | 330 | |
| 331 | - if ($assign) { |
|
| 332 | - Labels::add_article($id, $label, $_SESSION["uid"]); |
|
| 333 | - } else { |
|
| 334 | - Labels::remove_article($id, $label, $_SESSION["uid"]); |
|
| 335 | - } |
|
| 331 | + if ($assign) { |
|
| 332 | + Labels::add_article($id, $label, $_SESSION["uid"]); |
|
| 333 | + } else { |
|
| 334 | + Labels::remove_article($id, $label, $_SESSION["uid"]); |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | - $labels = $this->get_article_labels($id, $_SESSION["uid"]); |
|
| 337 | + $labels = $this->get_article_labels($id, $_SESSION["uid"]); |
|
| 338 | 338 | |
| 339 | - array_push($reply["info-for-headlines"], |
|
| 340 | - array("id" => $id, "labels" => $this->format_article_labels($labels))); |
|
| 339 | + array_push($reply["info-for-headlines"], |
|
| 340 | + array("id" => $id, "labels" => $this->format_article_labels($labels))); |
|
| 341 | 341 | |
| 342 | - } |
|
| 343 | - } |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - $reply["message"] = "UPDATE_COUNTERS"; |
|
| 345 | + $reply["message"] = "UPDATE_COUNTERS"; |
|
| 346 | 346 | |
| 347 | - print json_encode($reply); |
|
| 348 | - } |
|
| 347 | + print json_encode($reply); |
|
| 348 | + } |
|
| 349 | 349 | |
| 350 | - public function getArticleFeed($id) { |
|
| 351 | - $sth = $this->pdo->prepare("SELECT feed_id FROM ttrss_user_entries |
|
| 350 | + public function getArticleFeed($id) { |
|
| 351 | + $sth = $this->pdo->prepare("SELECT feed_id FROM ttrss_user_entries |
|
| 352 | 352 | WHERE ref_id = ? AND owner_uid = ?"); |
| 353 | - $sth->execute([$id, $_SESSION['uid']]); |
|
| 354 | - |
|
| 355 | - if ($row = $sth->fetch()) { |
|
| 356 | - return $row["feed_id"]; |
|
| 357 | - } else { |
|
| 358 | - return 0; |
|
| 359 | - } |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - public static function format_article_enclosures($id, $always_display_enclosures, |
|
| 363 | - $article_content, $hide_images = false) { |
|
| 364 | - |
|
| 365 | - $result = Article::get_article_enclosures($id); |
|
| 366 | - $rv = ''; |
|
| 367 | - |
|
| 368 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ENCLOSURES) as $plugin) { |
|
| 369 | - $retval = $plugin->hook_format_enclosures($rv, $result, $id, $always_display_enclosures, $article_content, $hide_images); |
|
| 370 | - if (is_array($retval)) { |
|
| 371 | - $rv = $retval[0]; |
|
| 372 | - $result = $retval[1]; |
|
| 373 | - } else { |
|
| 374 | - $rv = $retval; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - unset($retval); // Unset to prevent breaking render if there are no HOOK_RENDER_ENCLOSURE hooks below. |
|
| 378 | - |
|
| 379 | - if ($rv === '' && !empty($result)) { |
|
| 380 | - $entries_html = array(); |
|
| 381 | - $entries = array(); |
|
| 382 | - $entries_inline = array(); |
|
| 383 | - |
|
| 384 | - foreach ($result as $line) { |
|
| 385 | - |
|
| 386 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ENCLOSURE_ENTRY) as $plugin) { |
|
| 387 | - $line = $plugin->hook_enclosure_entry($line, $id); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - $url = $line["content_url"]; |
|
| 391 | - $ctype = $line["content_type"]; |
|
| 392 | - $title = $line["title"]; |
|
| 393 | - $width = $line["width"]; |
|
| 394 | - $height = $line["height"]; |
|
| 395 | - |
|
| 396 | - if (!$ctype) { |
|
| 397 | - $ctype = __("unknown type"); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - //$filename = substr($url, strrpos($url, "/")+1); |
|
| 401 | - $filename = basename($url); |
|
| 402 | - |
|
| 403 | - $player = format_inline_player($url, $ctype); |
|
| 404 | - |
|
| 405 | - if ($player) { |
|
| 406 | - array_push($entries_inline, $player); |
|
| 407 | - } |
|
| 353 | + $sth->execute([$id, $_SESSION['uid']]); |
|
| 354 | + |
|
| 355 | + if ($row = $sth->fetch()) { |
|
| 356 | + return $row["feed_id"]; |
|
| 357 | + } else { |
|
| 358 | + return 0; |
|
| 359 | + } |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + public static function format_article_enclosures($id, $always_display_enclosures, |
|
| 363 | + $article_content, $hide_images = false) { |
|
| 364 | + |
|
| 365 | + $result = Article::get_article_enclosures($id); |
|
| 366 | + $rv = ''; |
|
| 367 | + |
|
| 368 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ENCLOSURES) as $plugin) { |
|
| 369 | + $retval = $plugin->hook_format_enclosures($rv, $result, $id, $always_display_enclosures, $article_content, $hide_images); |
|
| 370 | + if (is_array($retval)) { |
|
| 371 | + $rv = $retval[0]; |
|
| 372 | + $result = $retval[1]; |
|
| 373 | + } else { |
|
| 374 | + $rv = $retval; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + unset($retval); // Unset to prevent breaking render if there are no HOOK_RENDER_ENCLOSURE hooks below. |
|
| 378 | + |
|
| 379 | + if ($rv === '' && !empty($result)) { |
|
| 380 | + $entries_html = array(); |
|
| 381 | + $entries = array(); |
|
| 382 | + $entries_inline = array(); |
|
| 383 | + |
|
| 384 | + foreach ($result as $line) { |
|
| 385 | + |
|
| 386 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ENCLOSURE_ENTRY) as $plugin) { |
|
| 387 | + $line = $plugin->hook_enclosure_entry($line, $id); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + $url = $line["content_url"]; |
|
| 391 | + $ctype = $line["content_type"]; |
|
| 392 | + $title = $line["title"]; |
|
| 393 | + $width = $line["width"]; |
|
| 394 | + $height = $line["height"]; |
|
| 395 | + |
|
| 396 | + if (!$ctype) { |
|
| 397 | + $ctype = __("unknown type"); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + //$filename = substr($url, strrpos($url, "/")+1); |
|
| 401 | + $filename = basename($url); |
|
| 402 | + |
|
| 403 | + $player = format_inline_player($url, $ctype); |
|
| 404 | + |
|
| 405 | + if ($player) { |
|
| 406 | + array_push($entries_inline, $player); |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | 409 | # $entry .= " <a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\" rel=\"noopener noreferrer\">" . |
| 410 | 410 | # $filename . " (" . $ctype . ")" . "</a>"; |
| 411 | 411 | |
| 412 | - $entry = "<div onclick=\"popupOpenUrl('".htmlspecialchars($url)."')\" |
|
| 412 | + $entry = "<div onclick=\"popupOpenUrl('".htmlspecialchars($url)."')\" |
|
| 413 | 413 | dojoType=\"dijit.MenuItem\">$filename ($ctype)</div>"; |
| 414 | 414 | |
| 415 | - array_push($entries_html, $entry); |
|
| 415 | + array_push($entries_html, $entry); |
|
| 416 | 416 | |
| 417 | - $entry = array(); |
|
| 417 | + $entry = array(); |
|
| 418 | 418 | |
| 419 | - $entry["type"] = $ctype; |
|
| 420 | - $entry["filename"] = $filename; |
|
| 421 | - $entry["url"] = $url; |
|
| 422 | - $entry["title"] = $title; |
|
| 423 | - $entry["width"] = $width; |
|
| 424 | - $entry["height"] = $height; |
|
| 419 | + $entry["type"] = $ctype; |
|
| 420 | + $entry["filename"] = $filename; |
|
| 421 | + $entry["url"] = $url; |
|
| 422 | + $entry["title"] = $title; |
|
| 423 | + $entry["width"] = $width; |
|
| 424 | + $entry["height"] = $height; |
|
| 425 | 425 | |
| 426 | - array_push($entries, $entry); |
|
| 427 | - } |
|
| 426 | + array_push($entries, $entry); |
|
| 427 | + } |
|
| 428 | 428 | |
| 429 | - if ($_SESSION['uid'] && !get_pref("STRIP_IMAGES") && !$_SESSION["bw_limit"]) { |
|
| 430 | - if ($always_display_enclosures || |
|
| 431 | - !preg_match("/<img/i", $article_content)) { |
|
| 429 | + if ($_SESSION['uid'] && !get_pref("STRIP_IMAGES") && !$_SESSION["bw_limit"]) { |
|
| 430 | + if ($always_display_enclosures || |
|
| 431 | + !preg_match("/<img/i", $article_content)) { |
|
| 432 | 432 | |
| 433 | - foreach ($entries as $entry) { |
|
| 433 | + foreach ($entries as $entry) { |
|
| 434 | 434 | |
| 435 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ENCLOSURE) as $plugin) { |
|
| 436 | - $retval = $plugin->hook_render_enclosure($entry, $hide_images); |
|
| 437 | - } |
|
| 435 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ENCLOSURE) as $plugin) { |
|
| 436 | + $retval = $plugin->hook_render_enclosure($entry, $hide_images); |
|
| 437 | + } |
|
| 438 | 438 | |
| 439 | 439 | |
| 440 | - if ($retval) { |
|
| 441 | - $rv .= $retval; |
|
| 442 | - } else { |
|
| 440 | + if ($retval) { |
|
| 441 | + $rv .= $retval; |
|
| 442 | + } else { |
|
| 443 | 443 | |
| 444 | - if (preg_match("/image/", $entry["type"])) { |
|
| 444 | + if (preg_match("/image/", $entry["type"])) { |
|
| 445 | 445 | |
| 446 | - if (!$hide_images) { |
|
| 447 | - $encsize = ''; |
|
| 448 | - if ($entry['height'] > 0) |
|
| 449 | - $encsize .= ' height="'.intval($entry['height']).'"'; |
|
| 450 | - if ($entry['width'] > 0) |
|
| 451 | - $encsize .= ' width="'.intval($entry['width']).'"'; |
|
| 452 | - $rv .= "<p><img |
|
| 446 | + if (!$hide_images) { |
|
| 447 | + $encsize = ''; |
|
| 448 | + if ($entry['height'] > 0) |
|
| 449 | + $encsize .= ' height="'.intval($entry['height']).'"'; |
|
| 450 | + if ($entry['width'] > 0) |
|
| 451 | + $encsize .= ' width="'.intval($entry['width']).'"'; |
|
| 452 | + $rv .= "<p><img |
|
| 453 | 453 | alt=\"".htmlspecialchars($entry["filename"])."\" |
| 454 | 454 | src=\"" .htmlspecialchars($entry["url"])."\" |
| 455 | 455 | " . $encsize." /></p>"; |
| 456 | - } else { |
|
| 457 | - $rv .= "<p><a target=\"_blank\" rel=\"noopener noreferrer\" |
|
| 456 | + } else { |
|
| 457 | + $rv .= "<p><a target=\"_blank\" rel=\"noopener noreferrer\" |
|
| 458 | 458 | href=\"".htmlspecialchars($entry["url"])."\" |
| 459 | 459 | >" .htmlspecialchars($entry["url"])."</a></p>"; |
| 460 | - } |
|
| 461 | - |
|
| 462 | - if ($entry['title']) { |
|
| 463 | - $rv .= "<div class=\"enclosure_title\">${entry['title']}</div>"; |
|
| 464 | - } |
|
| 465 | - } |
|
| 466 | - } |
|
| 467 | - } |
|
| 468 | - } |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - if (count($entries_inline) > 0) { |
|
| 472 | - //$rv .= "<hr clear='both'/>"; |
|
| 473 | - foreach ($entries_inline as $entry) { $rv .= $entry; }; |
|
| 474 | - $rv .= "<br clear='both'/>"; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - $rv .= "<div class=\"attachments\" dojoType=\"fox.form.DropDownButton\">". |
|
| 478 | - "<span>".__('Attachments')."</span>"; |
|
| 479 | - |
|
| 480 | - $rv .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
| 481 | - |
|
| 482 | - foreach ($entries as $entry) { |
|
| 483 | - if ($entry["title"]) |
|
| 484 | - $title = " — ".truncate_string($entry["title"], 30); |
|
| 485 | - else |
|
| 486 | - $title = ""; |
|
| 487 | - |
|
| 488 | - if ($entry["filename"]) |
|
| 489 | - $filename = truncate_middle(htmlspecialchars($entry["filename"]), 60); |
|
| 490 | - else |
|
| 491 | - $filename = ""; |
|
| 492 | - |
|
| 493 | - $rv .= "<div onclick='popupOpenUrl(\"".htmlspecialchars($entry["url"])."\")' |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + if ($entry['title']) { |
|
| 463 | + $rv .= "<div class=\"enclosure_title\">${entry['title']}</div>"; |
|
| 464 | + } |
|
| 465 | + } |
|
| 466 | + } |
|
| 467 | + } |
|
| 468 | + } |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + if (count($entries_inline) > 0) { |
|
| 472 | + //$rv .= "<hr clear='both'/>"; |
|
| 473 | + foreach ($entries_inline as $entry) { $rv .= $entry; }; |
|
| 474 | + $rv .= "<br clear='both'/>"; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + $rv .= "<div class=\"attachments\" dojoType=\"fox.form.DropDownButton\">". |
|
| 478 | + "<span>".__('Attachments')."</span>"; |
|
| 479 | + |
|
| 480 | + $rv .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
| 481 | + |
|
| 482 | + foreach ($entries as $entry) { |
|
| 483 | + if ($entry["title"]) |
|
| 484 | + $title = " — ".truncate_string($entry["title"], 30); |
|
| 485 | + else |
|
| 486 | + $title = ""; |
|
| 487 | + |
|
| 488 | + if ($entry["filename"]) |
|
| 489 | + $filename = truncate_middle(htmlspecialchars($entry["filename"]), 60); |
|
| 490 | + else |
|
| 491 | + $filename = ""; |
|
| 492 | + |
|
| 493 | + $rv .= "<div onclick='popupOpenUrl(\"".htmlspecialchars($entry["url"])."\")' |
|
| 494 | 494 | dojoType=\"dijit.MenuItem\">".$filename.$title."</div>"; |
| 495 | 495 | |
| 496 | - }; |
|
| 496 | + }; |
|
| 497 | 497 | |
| 498 | - $rv .= "</div>"; |
|
| 499 | - $rv .= "</div>"; |
|
| 500 | - } |
|
| 498 | + $rv .= "</div>"; |
|
| 499 | + $rv .= "</div>"; |
|
| 500 | + } |
|
| 501 | 501 | |
| 502 | - return $rv; |
|
| 503 | - } |
|
| 502 | + return $rv; |
|
| 503 | + } |
|
| 504 | 504 | |
| 505 | - public static function get_article_tags($id, $owner_uid = 0, $tag_cache = false) { |
|
| 505 | + public static function get_article_tags($id, $owner_uid = 0, $tag_cache = false) { |
|
| 506 | 506 | |
| 507 | - $a_id = $id; |
|
| 507 | + $a_id = $id; |
|
| 508 | 508 | |
| 509 | - if (!$owner_uid) { |
|
| 510 | - $owner_uid = $_SESSION["uid"]; |
|
| 511 | - } |
|
| 509 | + if (!$owner_uid) { |
|
| 510 | + $owner_uid = $_SESSION["uid"]; |
|
| 511 | + } |
|
| 512 | 512 | |
| 513 | - $pdo = Db::pdo(); |
|
| 513 | + $pdo = Db::pdo(); |
|
| 514 | 514 | |
| 515 | - $sth = $pdo->prepare("SELECT DISTINCT tag_name, |
|
| 515 | + $sth = $pdo->prepare("SELECT DISTINCT tag_name, |
|
| 516 | 516 | owner_uid as owner FROM ttrss_tags |
| 517 | 517 | WHERE post_int_id = (SELECT int_id FROM ttrss_user_entries WHERE |
| 518 | 518 | ref_id = ? AND owner_uid = ? LIMIT 1) ORDER BY tag_name"); |
| 519 | 519 | |
| 520 | - $tags = array(); |
|
| 520 | + $tags = array(); |
|
| 521 | 521 | |
| 522 | - /* check cache first */ |
|
| 522 | + /* check cache first */ |
|
| 523 | 523 | |
| 524 | - if ($tag_cache === false) { |
|
| 525 | - $csth = $pdo->prepare("SELECT tag_cache FROM ttrss_user_entries |
|
| 524 | + if ($tag_cache === false) { |
|
| 525 | + $csth = $pdo->prepare("SELECT tag_cache FROM ttrss_user_entries |
|
| 526 | 526 | WHERE ref_id = ? AND owner_uid = ?"); |
| 527 | - $csth->execute([$id, $owner_uid]); |
|
| 527 | + $csth->execute([$id, $owner_uid]); |
|
| 528 | 528 | |
| 529 | - if ($row = $csth->fetch()) { |
|
| 530 | - $tag_cache = $row["tag_cache"]; |
|
| 531 | - } |
|
| 532 | - } |
|
| 529 | + if ($row = $csth->fetch()) { |
|
| 530 | + $tag_cache = $row["tag_cache"]; |
|
| 531 | + } |
|
| 532 | + } |
|
| 533 | 533 | |
| 534 | - if ($tag_cache) { |
|
| 535 | - $tags = explode(",", $tag_cache); |
|
| 536 | - } else { |
|
| 534 | + if ($tag_cache) { |
|
| 535 | + $tags = explode(",", $tag_cache); |
|
| 536 | + } else { |
|
| 537 | 537 | |
| 538 | - /* do it the hard way */ |
|
| 538 | + /* do it the hard way */ |
|
| 539 | 539 | |
| 540 | - $sth->execute([$a_id, $owner_uid]); |
|
| 540 | + $sth->execute([$a_id, $owner_uid]); |
|
| 541 | 541 | |
| 542 | - while ($tmp_line = $sth->fetch()) { |
|
| 543 | - array_push($tags, $tmp_line["tag_name"]); |
|
| 544 | - } |
|
| 542 | + while ($tmp_line = $sth->fetch()) { |
|
| 543 | + array_push($tags, $tmp_line["tag_name"]); |
|
| 544 | + } |
|
| 545 | 545 | |
| 546 | - /* update the cache */ |
|
| 546 | + /* update the cache */ |
|
| 547 | 547 | |
| 548 | - $tags_str = join(",", $tags); |
|
| 548 | + $tags_str = join(",", $tags); |
|
| 549 | 549 | |
| 550 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 550 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
| 551 | 551 | SET tag_cache = ? WHERE ref_id = ? |
| 552 | 552 | AND owner_uid = ?"); |
| 553 | - $sth->execute([$tags_str, $id, $owner_uid]); |
|
| 554 | - } |
|
| 553 | + $sth->execute([$tags_str, $id, $owner_uid]); |
|
| 554 | + } |
|
| 555 | 555 | |
| 556 | - return $tags; |
|
| 557 | - } |
|
| 556 | + return $tags; |
|
| 557 | + } |
|
| 558 | 558 | |
| 559 | - public static function format_tags_string($tags) { |
|
| 560 | - if (!is_array($tags) || count($tags) == 0) { |
|
| 561 | - return __("no tags"); |
|
| 562 | - } else { |
|
| 563 | - $maxtags = min(5, count($tags)); |
|
| 564 | - $tags_str = ""; |
|
| 559 | + public static function format_tags_string($tags) { |
|
| 560 | + if (!is_array($tags) || count($tags) == 0) { |
|
| 561 | + return __("no tags"); |
|
| 562 | + } else { |
|
| 563 | + $maxtags = min(5, count($tags)); |
|
| 564 | + $tags_str = ""; |
|
| 565 | 565 | |
| 566 | - for ($i = 0; $i < $maxtags; $i++) { |
|
| 567 | - $tags_str .= "<a class=\"tag\" href=\"#\" onclick=\"Feeds.open({feed:'".$tags[$i]."'})\">".$tags[$i]."</a>, "; |
|
| 568 | - } |
|
| 566 | + for ($i = 0; $i < $maxtags; $i++) { |
|
| 567 | + $tags_str .= "<a class=\"tag\" href=\"#\" onclick=\"Feeds.open({feed:'".$tags[$i]."'})\">".$tags[$i]."</a>, "; |
|
| 568 | + } |
|
| 569 | 569 | |
| 570 | - $tags_str = mb_substr($tags_str, 0, mb_strlen($tags_str) - 2); |
|
| 570 | + $tags_str = mb_substr($tags_str, 0, mb_strlen($tags_str) - 2); |
|
| 571 | 571 | |
| 572 | - if (count($tags) > $maxtags) { |
|
| 573 | - $tags_str .= ", …"; |
|
| 574 | - } |
|
| 572 | + if (count($tags) > $maxtags) { |
|
| 573 | + $tags_str .= ", …"; |
|
| 574 | + } |
|
| 575 | 575 | |
| 576 | - return $tags_str; |
|
| 577 | - } |
|
| 578 | - } |
|
| 576 | + return $tags_str; |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | 579 | |
| 580 | - public static function format_article_labels($labels) { |
|
| 580 | + public static function format_article_labels($labels) { |
|
| 581 | 581 | |
| 582 | - if (!is_array($labels)) { |
|
| 583 | - return ''; |
|
| 584 | - } |
|
| 582 | + if (!is_array($labels)) { |
|
| 583 | + return ''; |
|
| 584 | + } |
|
| 585 | 585 | |
| 586 | - $labels_str = ""; |
|
| 586 | + $labels_str = ""; |
|
| 587 | 587 | |
| 588 | - foreach ($labels as $l) { |
|
| 589 | - $labels_str .= sprintf("<div class='label' |
|
| 588 | + foreach ($labels as $l) { |
|
| 589 | + $labels_str .= sprintf("<div class='label' |
|
| 590 | 590 | style='color : %s; background-color : %s'>%s</div>", |
| 591 | - $l[2], $l[3], $l[1]); |
|
| 592 | - } |
|
| 591 | + $l[2], $l[3], $l[1]); |
|
| 592 | + } |
|
| 593 | 593 | |
| 594 | - return $labels_str; |
|
| 594 | + return $labels_str; |
|
| 595 | 595 | |
| 596 | - } |
|
| 596 | + } |
|
| 597 | 597 | |
| 598 | - public static function format_article_note($id, $note, $allow_edit = true) { |
|
| 598 | + public static function format_article_note($id, $note, $allow_edit = true) { |
|
| 599 | 599 | |
| 600 | - if ($allow_edit) { |
|
| 601 | - $onclick = "onclick='Plugins.Note.edit($id)'"; |
|
| 602 | - $note_class = 'editable'; |
|
| 603 | - } else { |
|
| 604 | - $onclick = ''; |
|
| 605 | - $note_class = ''; |
|
| 606 | - } |
|
| 600 | + if ($allow_edit) { |
|
| 601 | + $onclick = "onclick='Plugins.Note.edit($id)'"; |
|
| 602 | + $note_class = 'editable'; |
|
| 603 | + } else { |
|
| 604 | + $onclick = ''; |
|
| 605 | + $note_class = ''; |
|
| 606 | + } |
|
| 607 | 607 | |
| 608 | - return "<div class='article-note $note_class'> |
|
| 608 | + return "<div class='article-note $note_class'> |
|
| 609 | 609 | <i class='material-icons'>note</i> |
| 610 | 610 | <div $onclick class='body'>$note</div> |
| 611 | 611 | </div>"; |
| 612 | - } |
|
| 612 | + } |
|
| 613 | 613 | |
| 614 | - public static function get_article_enclosures($id) { |
|
| 614 | + public static function get_article_enclosures($id) { |
|
| 615 | 615 | |
| 616 | - $pdo = Db::pdo(); |
|
| 616 | + $pdo = Db::pdo(); |
|
| 617 | 617 | |
| 618 | - $sth = $pdo->prepare("SELECT * FROM ttrss_enclosures |
|
| 618 | + $sth = $pdo->prepare("SELECT * FROM ttrss_enclosures |
|
| 619 | 619 | WHERE post_id = ? AND content_url != ''"); |
| 620 | - $sth->execute([$id]); |
|
| 620 | + $sth->execute([$id]); |
|
| 621 | 621 | |
| 622 | - $rv = array(); |
|
| 622 | + $rv = array(); |
|
| 623 | 623 | |
| 624 | - $cache = new DiskCache("images"); |
|
| 624 | + $cache = new DiskCache("images"); |
|
| 625 | 625 | |
| 626 | - while ($line = $sth->fetch()) { |
|
| 626 | + while ($line = $sth->fetch()) { |
|
| 627 | 627 | |
| 628 | - if ($cache->exists(sha1($line["content_url"]))) { |
|
| 629 | - $line["content_url"] = $cache->getUrl(sha1($line["content_url"])); |
|
| 630 | - } |
|
| 628 | + if ($cache->exists(sha1($line["content_url"]))) { |
|
| 629 | + $line["content_url"] = $cache->getUrl(sha1($line["content_url"])); |
|
| 630 | + } |
|
| 631 | 631 | |
| 632 | - array_push($rv, $line); |
|
| 633 | - } |
|
| 632 | + array_push($rv, $line); |
|
| 633 | + } |
|
| 634 | 634 | |
| 635 | - return $rv; |
|
| 636 | - } |
|
| 635 | + return $rv; |
|
| 636 | + } |
|
| 637 | 637 | |
| 638 | - public static function purge_orphans() { |
|
| 638 | + public static function purge_orphans() { |
|
| 639 | 639 | |
| 640 | 640 | // purge orphaned posts in main content table |
| 641 | 641 | |
@@ -655,180 +655,180 @@ discard block |
||
| 655 | 655 | } |
| 656 | 656 | } |
| 657 | 657 | |
| 658 | - public static function catchupArticlesById($ids, $cmode, $owner_uid = false) { |
|
| 658 | + public static function catchupArticlesById($ids, $cmode, $owner_uid = false) { |
|
| 659 | 659 | |
| 660 | - if (!$owner_uid) { |
|
| 661 | - $owner_uid = $_SESSION["uid"]; |
|
| 662 | - } |
|
| 660 | + if (!$owner_uid) { |
|
| 661 | + $owner_uid = $_SESSION["uid"]; |
|
| 662 | + } |
|
| 663 | 663 | |
| 664 | - $pdo = Db::pdo(); |
|
| 664 | + $pdo = Db::pdo(); |
|
| 665 | 665 | |
| 666 | - $ids_qmarks = arr_qmarks($ids); |
|
| 666 | + $ids_qmarks = arr_qmarks($ids); |
|
| 667 | 667 | |
| 668 | - if ($cmode == 1) { |
|
| 669 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 668 | + if ($cmode == 1) { |
|
| 669 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 670 | 670 | unread = true |
| 671 | 671 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
| 672 | - } else if ($cmode == 2) { |
|
| 673 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 672 | + } else if ($cmode == 2) { |
|
| 673 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 674 | 674 | unread = NOT unread,last_read = NOW() |
| 675 | 675 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
| 676 | - } else { |
|
| 677 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 676 | + } else { |
|
| 677 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
| 678 | 678 | unread = false,last_read = NOW() |
| 679 | 679 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
| 680 | - } |
|
| 680 | + } |
|
| 681 | 681 | |
| 682 | - $sth->execute(array_merge($ids, [$owner_uid])); |
|
| 682 | + $sth->execute(array_merge($ids, [$owner_uid])); |
|
| 683 | 683 | |
| 684 | - /* update ccache */ |
|
| 684 | + /* update ccache */ |
|
| 685 | 685 | |
| 686 | - $sth = $pdo->prepare("SELECT DISTINCT feed_id FROM ttrss_user_entries |
|
| 686 | + $sth = $pdo->prepare("SELECT DISTINCT feed_id FROM ttrss_user_entries |
|
| 687 | 687 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
| 688 | - $sth->execute(array_merge($ids, [$owner_uid])); |
|
| 688 | + $sth->execute(array_merge($ids, [$owner_uid])); |
|
| 689 | 689 | |
| 690 | - while ($line = $sth->fetch()) { |
|
| 691 | - CCache::update($line["feed_id"], $owner_uid); |
|
| 692 | - } |
|
| 693 | - } |
|
| 690 | + while ($line = $sth->fetch()) { |
|
| 691 | + CCache::update($line["feed_id"], $owner_uid); |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | 694 | |
| 695 | - public static function getLastArticleId() { |
|
| 696 | - $pdo = DB::pdo(); |
|
| 695 | + public static function getLastArticleId() { |
|
| 696 | + $pdo = DB::pdo(); |
|
| 697 | 697 | |
| 698 | - $sth = $pdo->prepare("SELECT ref_id AS id FROM ttrss_user_entries |
|
| 698 | + $sth = $pdo->prepare("SELECT ref_id AS id FROM ttrss_user_entries |
|
| 699 | 699 | WHERE owner_uid = ? ORDER BY ref_id DESC LIMIT 1"); |
| 700 | - $sth->execute([$_SESSION['uid']]); |
|
| 700 | + $sth->execute([$_SESSION['uid']]); |
|
| 701 | 701 | |
| 702 | - if ($row = $sth->fetch()) { |
|
| 703 | - return $row['id']; |
|
| 704 | - } else { |
|
| 705 | - return -1; |
|
| 706 | - } |
|
| 707 | - } |
|
| 702 | + if ($row = $sth->fetch()) { |
|
| 703 | + return $row['id']; |
|
| 704 | + } else { |
|
| 705 | + return -1; |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | 708 | |
| 709 | - public static function get_article_labels($id, $owner_uid = false) { |
|
| 710 | - $rv = array(); |
|
| 709 | + public static function get_article_labels($id, $owner_uid = false) { |
|
| 710 | + $rv = array(); |
|
| 711 | 711 | |
| 712 | - if (!$owner_uid) { |
|
| 713 | - $owner_uid = $_SESSION["uid"]; |
|
| 714 | - } |
|
| 712 | + if (!$owner_uid) { |
|
| 713 | + $owner_uid = $_SESSION["uid"]; |
|
| 714 | + } |
|
| 715 | 715 | |
| 716 | - $pdo = Db::pdo(); |
|
| 716 | + $pdo = Db::pdo(); |
|
| 717 | 717 | |
| 718 | - $sth = $pdo->prepare("SELECT label_cache FROM |
|
| 718 | + $sth = $pdo->prepare("SELECT label_cache FROM |
|
| 719 | 719 | ttrss_user_entries WHERE ref_id = ? AND owner_uid = ?"); |
| 720 | - $sth->execute([$id, $owner_uid]); |
|
| 720 | + $sth->execute([$id, $owner_uid]); |
|
| 721 | 721 | |
| 722 | - if ($row = $sth->fetch()) { |
|
| 723 | - $label_cache = $row["label_cache"]; |
|
| 722 | + if ($row = $sth->fetch()) { |
|
| 723 | + $label_cache = $row["label_cache"]; |
|
| 724 | 724 | |
| 725 | - if ($label_cache) { |
|
| 726 | - $tmp = json_decode($label_cache, true); |
|
| 725 | + if ($label_cache) { |
|
| 726 | + $tmp = json_decode($label_cache, true); |
|
| 727 | 727 | |
| 728 | - if (!$tmp || $tmp["no-labels"] == 1) { |
|
| 729 | - return $rv; |
|
| 730 | - } else { |
|
| 731 | - return $tmp; |
|
| 732 | - } |
|
| 733 | - } |
|
| 734 | - } |
|
| 728 | + if (!$tmp || $tmp["no-labels"] == 1) { |
|
| 729 | + return $rv; |
|
| 730 | + } else { |
|
| 731 | + return $tmp; |
|
| 732 | + } |
|
| 733 | + } |
|
| 734 | + } |
|
| 735 | 735 | |
| 736 | - $sth = $pdo->prepare("SELECT DISTINCT label_id,caption,fg_color,bg_color |
|
| 736 | + $sth = $pdo->prepare("SELECT DISTINCT label_id,caption,fg_color,bg_color |
|
| 737 | 737 | FROM ttrss_labels2, ttrss_user_labels2 |
| 738 | 738 | WHERE id = label_id |
| 739 | 739 | AND article_id = ? |
| 740 | 740 | AND owner_uid = ? |
| 741 | 741 | ORDER BY caption"); |
| 742 | - $sth->execute([$id, $owner_uid]); |
|
| 743 | - |
|
| 744 | - while ($line = $sth->fetch()) { |
|
| 745 | - $rk = array(Labels::label_to_feed_id($line["label_id"]), |
|
| 746 | - $line["caption"], $line["fg_color"], |
|
| 747 | - $line["bg_color"]); |
|
| 748 | - array_push($rv, $rk); |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - if (count($rv) > 0) { |
|
| 752 | - Labels::update_cache($owner_uid, $id, $rv); |
|
| 753 | - } else { |
|
| 754 | - Labels::update_cache($owner_uid, $id, array("no-labels" => 1)); |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - return $rv; |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - public static function get_article_image($enclosures, $content, $site_url) { |
|
| 761 | - |
|
| 762 | - $article_image = ""; |
|
| 763 | - $article_stream = ""; |
|
| 764 | - |
|
| 765 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_IMAGE) as $p) { |
|
| 766 | - list ($article_image, $article_stream, $content) = $p->hook_article_image($enclosures, $content, $site_url); |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - if (!$article_image && !$article_stream) { |
|
| 770 | - $tmpdoc = new DOMDocument(); |
|
| 771 | - |
|
| 772 | - if (@$tmpdoc->loadHTML('<?xml encoding="UTF-8">'.mb_substr($content, 0, 131070))) { |
|
| 773 | - $tmpxpath = new DOMXPath($tmpdoc); |
|
| 774 | - $elems = $tmpxpath->query('(//img[@src]|//video[@poster]|//iframe[contains(@src , "youtube.com/embed/")])'); |
|
| 775 | - |
|
| 776 | - foreach ($elems as $e) { |
|
| 777 | - if ($e->nodeName == "iframe") { |
|
| 778 | - $matches = []; |
|
| 779 | - if (preg_match("/\/embed\/([\w-]+)/", $e->getAttribute("src"), $matches)) { |
|
| 780 | - $article_image = "https://img.youtube.com/vi/".$matches[1]."/hqdefault.jpg"; |
|
| 781 | - $article_stream = "https://youtu.be/".$matches[1]; |
|
| 782 | - break; |
|
| 783 | - } |
|
| 784 | - } else if ($e->nodeName == "video") { |
|
| 785 | - $article_image = $e->getAttribute("poster"); |
|
| 786 | - |
|
| 787 | - $src = $tmpxpath->query("//source[@src]", $e)->item(0); |
|
| 788 | - |
|
| 789 | - if ($src) { |
|
| 790 | - $article_stream = $src->getAttribute("src"); |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - break; |
|
| 794 | - } else if ($e->nodeName == 'img') { |
|
| 795 | - if (mb_strpos($e->getAttribute("src"), "data:") !== 0) { |
|
| 796 | - $article_image = $e->getAttribute("src"); |
|
| 797 | - } |
|
| 798 | - break; |
|
| 799 | - } |
|
| 800 | - } |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - if (!$article_image) { |
|
| 804 | - foreach ($enclosures as $enc) { |
|
| 805 | - if (strpos($enc["content_type"], "image/") !== false) { |
|
| 806 | - $article_image = $enc["content_url"]; |
|
| 807 | - } |
|
| 808 | - break; |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - if ($article_image) { |
|
| 813 | - $article_image = rewrite_relative_url($site_url, $article_image); |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - if ($article_stream) { |
|
| 817 | - $article_stream = rewrite_relative_url($site_url, $article_stream); |
|
| 818 | - } |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - $cache = new DiskCache("images"); |
|
| 822 | - |
|
| 823 | - if ($article_image && $cache->exists(sha1($article_image))) { |
|
| 824 | - $article_image = $cache->getUrl(sha1($article_image)); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - if ($article_stream && $cache->exists(sha1($article_stream))) { |
|
| 828 | - $article_stream = $cache->getUrl(sha1($article_stream)); |
|
| 829 | - } |
|
| 830 | - |
|
| 831 | - return [$article_image, $article_stream]; |
|
| 832 | - } |
|
| 742 | + $sth->execute([$id, $owner_uid]); |
|
| 743 | + |
|
| 744 | + while ($line = $sth->fetch()) { |
|
| 745 | + $rk = array(Labels::label_to_feed_id($line["label_id"]), |
|
| 746 | + $line["caption"], $line["fg_color"], |
|
| 747 | + $line["bg_color"]); |
|
| 748 | + array_push($rv, $rk); |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + if (count($rv) > 0) { |
|
| 752 | + Labels::update_cache($owner_uid, $id, $rv); |
|
| 753 | + } else { |
|
| 754 | + Labels::update_cache($owner_uid, $id, array("no-labels" => 1)); |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + return $rv; |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + public static function get_article_image($enclosures, $content, $site_url) { |
|
| 761 | + |
|
| 762 | + $article_image = ""; |
|
| 763 | + $article_stream = ""; |
|
| 764 | + |
|
| 765 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_IMAGE) as $p) { |
|
| 766 | + list ($article_image, $article_stream, $content) = $p->hook_article_image($enclosures, $content, $site_url); |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + if (!$article_image && !$article_stream) { |
|
| 770 | + $tmpdoc = new DOMDocument(); |
|
| 771 | + |
|
| 772 | + if (@$tmpdoc->loadHTML('<?xml encoding="UTF-8">'.mb_substr($content, 0, 131070))) { |
|
| 773 | + $tmpxpath = new DOMXPath($tmpdoc); |
|
| 774 | + $elems = $tmpxpath->query('(//img[@src]|//video[@poster]|//iframe[contains(@src , "youtube.com/embed/")])'); |
|
| 775 | + |
|
| 776 | + foreach ($elems as $e) { |
|
| 777 | + if ($e->nodeName == "iframe") { |
|
| 778 | + $matches = []; |
|
| 779 | + if (preg_match("/\/embed\/([\w-]+)/", $e->getAttribute("src"), $matches)) { |
|
| 780 | + $article_image = "https://img.youtube.com/vi/".$matches[1]."/hqdefault.jpg"; |
|
| 781 | + $article_stream = "https://youtu.be/".$matches[1]; |
|
| 782 | + break; |
|
| 783 | + } |
|
| 784 | + } else if ($e->nodeName == "video") { |
|
| 785 | + $article_image = $e->getAttribute("poster"); |
|
| 786 | + |
|
| 787 | + $src = $tmpxpath->query("//source[@src]", $e)->item(0); |
|
| 788 | + |
|
| 789 | + if ($src) { |
|
| 790 | + $article_stream = $src->getAttribute("src"); |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + break; |
|
| 794 | + } else if ($e->nodeName == 'img') { |
|
| 795 | + if (mb_strpos($e->getAttribute("src"), "data:") !== 0) { |
|
| 796 | + $article_image = $e->getAttribute("src"); |
|
| 797 | + } |
|
| 798 | + break; |
|
| 799 | + } |
|
| 800 | + } |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + if (!$article_image) { |
|
| 804 | + foreach ($enclosures as $enc) { |
|
| 805 | + if (strpos($enc["content_type"], "image/") !== false) { |
|
| 806 | + $article_image = $enc["content_url"]; |
|
| 807 | + } |
|
| 808 | + break; |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + if ($article_image) { |
|
| 813 | + $article_image = rewrite_relative_url($site_url, $article_image); |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + if ($article_stream) { |
|
| 817 | + $article_stream = rewrite_relative_url($site_url, $article_stream); |
|
| 818 | + } |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + $cache = new DiskCache("images"); |
|
| 822 | + |
|
| 823 | + if ($article_image && $cache->exists(sha1($article_image))) { |
|
| 824 | + $article_image = $cache->getUrl(sha1($article_image)); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + if ($article_stream && $cache->exists(sha1($article_stream))) { |
|
| 828 | + $article_stream = $cache->getUrl(sha1($article_stream)); |
|
| 829 | + } |
|
| 830 | + |
|
| 831 | + return [$article_image, $article_stream]; |
|
| 832 | + } |
|
| 833 | 833 | |
| 834 | 834 | } |
@@ -445,10 +445,12 @@ discard block |
||
| 445 | 445 | |
| 446 | 446 | if (!$hide_images) { |
| 447 | 447 | $encsize = ''; |
| 448 | - if ($entry['height'] > 0) |
|
| 449 | - $encsize .= ' height="'.intval($entry['height']).'"'; |
|
| 450 | - if ($entry['width'] > 0) |
|
| 451 | - $encsize .= ' width="'.intval($entry['width']).'"'; |
|
| 448 | + if ($entry['height'] > 0) { |
|
| 449 | + $encsize .= ' height="'.intval($entry['height']).'"'; |
|
| 450 | + } |
|
| 451 | + if ($entry['width'] > 0) { |
|
| 452 | + $encsize .= ' width="'.intval($entry['width']).'"'; |
|
| 453 | + } |
|
| 452 | 454 | $rv .= "<p><img |
| 453 | 455 | alt=\"".htmlspecialchars($entry["filename"])."\" |
| 454 | 456 | src=\"" .htmlspecialchars($entry["url"])."\" |
@@ -480,15 +482,17 @@ discard block |
||
| 480 | 482 | $rv .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
| 481 | 483 | |
| 482 | 484 | foreach ($entries as $entry) { |
| 483 | - if ($entry["title"]) |
|
| 484 | - $title = " — ".truncate_string($entry["title"], 30); |
|
| 485 | - else |
|
| 486 | - $title = ""; |
|
| 487 | - |
|
| 488 | - if ($entry["filename"]) |
|
| 489 | - $filename = truncate_middle(htmlspecialchars($entry["filename"]), 60); |
|
| 490 | - else |
|
| 491 | - $filename = ""; |
|
| 485 | + if ($entry["title"]) { |
|
| 486 | + $title = " — ".truncate_string($entry["title"], 30); |
|
| 487 | + } else { |
|
| 488 | + $title = ""; |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + if ($entry["filename"]) { |
|
| 492 | + $filename = truncate_middle(htmlspecialchars($entry["filename"]), 60); |
|
| 493 | + } else { |
|
| 494 | + $filename = ""; |
|
| 495 | + } |
|
| 492 | 496 | |
| 493 | 497 | $rv .= "<div onclick='popupOpenUrl(\"".htmlspecialchars($entry["url"])."\")' |
| 494 | 498 | dojoType=\"dijit.MenuItem\">".$filename.$title."</div>"; |
@@ -1,50 +1,50 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | class Auth_Base { |
| 3 | - private $pdo; |
|
| 3 | + private $pdo; |
|
| 4 | 4 | |
| 5 | - const AUTH_SERVICE_API = '_api'; |
|
| 5 | + const AUTH_SERVICE_API = '_api'; |
|
| 6 | 6 | |
| 7 | - public function __construct() { |
|
| 8 | - $this->pdo = Db::pdo(); |
|
| 9 | - } |
|
| 7 | + public function __construct() { |
|
| 8 | + $this->pdo = Db::pdo(); |
|
| 9 | + } |
|
| 10 | 10 | |
| 11 | - // Auto-creates specified user if allowed by system configuration |
|
| 12 | - // Can be used instead of find_user_by_login() by external auth modules |
|
| 13 | - public function auto_create_user($login, $password = false) { |
|
| 14 | - if ($login && defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE) { |
|
| 15 | - $user_id = $this->find_user_by_login($login); |
|
| 11 | + // Auto-creates specified user if allowed by system configuration |
|
| 12 | + // Can be used instead of find_user_by_login() by external auth modules |
|
| 13 | + public function auto_create_user($login, $password = false) { |
|
| 14 | + if ($login && defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE) { |
|
| 15 | + $user_id = $this->find_user_by_login($login); |
|
| 16 | 16 | |
| 17 | - if (!$password) { |
|
| 18 | - $password = make_password(); |
|
| 19 | - } |
|
| 17 | + if (!$password) { |
|
| 18 | + $password = make_password(); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - if (!$user_id) { |
|
| 22 | - $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
| 23 | - $pwd_hash = encrypt_password($password, $salt, true); |
|
| 21 | + if (!$user_id) { |
|
| 22 | + $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); |
|
| 23 | + $pwd_hash = encrypt_password($password, $salt, true); |
|
| 24 | 24 | |
| 25 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_users |
|
| 25 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_users |
|
| 26 | 26 | (login,access_level,last_login,created,pwd_hash,salt) |
| 27 | 27 | VALUES (?, 0, null, NOW(), ?,?)"); |
| 28 | - $sth->execute([$login, $pwd_hash, $salt]); |
|
| 28 | + $sth->execute([$login, $pwd_hash, $salt]); |
|
| 29 | 29 | |
| 30 | - return $this->find_user_by_login($login); |
|
| 30 | + return $this->find_user_by_login($login); |
|
| 31 | 31 | |
| 32 | - } else { |
|
| 33 | - return $user_id; |
|
| 34 | - } |
|
| 35 | - } |
|
| 32 | + } else { |
|
| 33 | + return $user_id; |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - return $this->find_user_by_login($login); |
|
| 38 | - } |
|
| 37 | + return $this->find_user_by_login($login); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function find_user_by_login($login) { |
|
| 41 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?"); |
|
| 42 | - $sth->execute([$login]); |
|
| 40 | + public function find_user_by_login($login) { |
|
| 41 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?"); |
|
| 42 | + $sth->execute([$login]); |
|
| 43 | 43 | |
| 44 | - if ($row = $sth->fetch()) { |
|
| 45 | - return $row["id"]; |
|
| 46 | - } else { |
|
| 47 | - return false; |
|
| 48 | - } |
|
| 49 | - } |
|
| 44 | + if ($row = $sth->fetch()) { |
|
| 45 | + return $row["id"]; |
|
| 46 | + } else { |
|
| 47 | + return false; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | } |