@@ -1,435 +1,435 @@ 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"]) $_SESSION["profile"] = null; |
|
15 | - } |
|
13 | + // default value |
|
14 | + if (!$_SESSION["profile"]) $_SESSION["profile"] = null; |
|
15 | + } |
|
16 | 16 | |
17 | - public function remprofiles() { |
|
18 | - $ids = explode(",", trim(clean($_REQUEST["ids"]))); |
|
17 | + public function remprofiles() { |
|
18 | + $ids = explode(",", trim(clean($_REQUEST["ids"]))); |
|
19 | 19 | |
20 | - foreach ($ids as $id) { |
|
21 | - if ($_SESSION["profile"] != $id) { |
|
22 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_settings_profiles WHERE id = ? AND |
|
20 | + foreach ($ids as $id) { |
|
21 | + if ($_SESSION["profile"] != $id) { |
|
22 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_settings_profiles WHERE id = ? AND |
|
23 | 23 | owner_uid = ?"); |
24 | - $sth->execute([$id, $_SESSION['uid']]); |
|
25 | - } |
|
26 | - } |
|
27 | - } |
|
24 | + $sth->execute([$id, $_SESSION['uid']]); |
|
25 | + } |
|
26 | + } |
|
27 | + } |
|
28 | 28 | |
29 | - // Silent |
|
30 | - public function addprofile() { |
|
31 | - $title = trim(clean($_REQUEST["title"])); |
|
29 | + // Silent |
|
30 | + public function addprofile() { |
|
31 | + $title = trim(clean($_REQUEST["title"])); |
|
32 | 32 | |
33 | - if ($title) { |
|
34 | - $this->pdo->beginTransaction(); |
|
33 | + if ($title) { |
|
34 | + $this->pdo->beginTransaction(); |
|
35 | 35 | |
36 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles |
|
36 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles |
|
37 | 37 | WHERE title = ? AND owner_uid = ?"); |
38 | - $sth->execute([$title, $_SESSION['uid']]); |
|
38 | + $sth->execute([$title, $_SESSION['uid']]); |
|
39 | 39 | |
40 | - if (!$sth->fetch()) { |
|
40 | + if (!$sth->fetch()) { |
|
41 | 41 | |
42 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_settings_profiles (title, owner_uid) |
|
42 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_settings_profiles (title, owner_uid) |
|
43 | 43 | VALUES (?, ?)"); |
44 | 44 | |
45 | - $sth->execute([$title, $_SESSION['uid']]); |
|
45 | + $sth->execute([$title, $_SESSION['uid']]); |
|
46 | 46 | |
47 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles WHERE |
|
47 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles WHERE |
|
48 | 48 | title = ? AND owner_uid = ?"); |
49 | - $sth->execute([$title, $_SESSION['uid']]); |
|
49 | + $sth->execute([$title, $_SESSION['uid']]); |
|
50 | 50 | |
51 | - if ($row = $sth->fetch()) { |
|
52 | - $profile_id = $row['id']; |
|
51 | + if ($row = $sth->fetch()) { |
|
52 | + $profile_id = $row['id']; |
|
53 | 53 | |
54 | - if ($profile_id) { |
|
55 | - initialize_user_prefs($_SESSION["uid"], $profile_id); |
|
56 | - } |
|
57 | - } |
|
58 | - } |
|
54 | + if ($profile_id) { |
|
55 | + initialize_user_prefs($_SESSION["uid"], $profile_id); |
|
56 | + } |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - $this->pdo->commit(); |
|
61 | - } |
|
62 | - } |
|
60 | + $this->pdo->commit(); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | - public function saveprofile() { |
|
65 | - $id = clean($_REQUEST["id"]); |
|
66 | - $title = trim(clean($_REQUEST["value"])); |
|
64 | + public function saveprofile() { |
|
65 | + $id = clean($_REQUEST["id"]); |
|
66 | + $title = trim(clean($_REQUEST["value"])); |
|
67 | 67 | |
68 | - if ($id == 0) { |
|
69 | - print __("Default profile"); |
|
70 | - return; |
|
71 | - } |
|
68 | + if ($id == 0) { |
|
69 | + print __("Default profile"); |
|
70 | + return; |
|
71 | + } |
|
72 | 72 | |
73 | - if ($title) { |
|
74 | - $sth = $this->pdo->prepare("UPDATE ttrss_settings_profiles |
|
73 | + if ($title) { |
|
74 | + $sth = $this->pdo->prepare("UPDATE ttrss_settings_profiles |
|
75 | 75 | SET title = ? WHERE id = ? AND |
76 | 76 | owner_uid = ?"); |
77 | 77 | |
78 | - $sth->execute([$title, $id, $_SESSION['uid']]); |
|
79 | - print $title; |
|
80 | - } |
|
81 | - } |
|
78 | + $sth->execute([$title, $id, $_SESSION['uid']]); |
|
79 | + print $title; |
|
80 | + } |
|
81 | + } |
|
82 | 82 | |
83 | - // Silent |
|
84 | - public function remarchive() { |
|
85 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
83 | + // Silent |
|
84 | + public function remarchive() { |
|
85 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
86 | 86 | |
87 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_archived_feeds WHERE |
|
87 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_archived_feeds WHERE |
|
88 | 88 | (SELECT COUNT(*) FROM ttrss_user_entries |
89 | 89 | WHERE orig_feed_id = :id) = 0 AND |
90 | 90 | id = :id AND owner_uid = :uid"); |
91 | 91 | |
92 | - foreach ($ids as $id) { |
|
93 | - $sth->execute([":id" => $id, ":uid" => $_SESSION['uid']]); |
|
94 | - } |
|
95 | - } |
|
92 | + foreach ($ids as $id) { |
|
93 | + $sth->execute([":id" => $id, ":uid" => $_SESSION['uid']]); |
|
94 | + } |
|
95 | + } |
|
96 | 96 | |
97 | - public function addfeed() { |
|
98 | - $feed = clean($_REQUEST['feed']); |
|
99 | - $cat = clean($_REQUEST['cat']); |
|
100 | - $need_auth = isset($_REQUEST['need_auth']); |
|
101 | - $login = $need_auth ? clean($_REQUEST['login']) : ''; |
|
102 | - $pass = $need_auth ? trim(clean($_REQUEST['pass'])) : ''; |
|
97 | + public function addfeed() { |
|
98 | + $feed = clean($_REQUEST['feed']); |
|
99 | + $cat = clean($_REQUEST['cat']); |
|
100 | + $need_auth = isset($_REQUEST['need_auth']); |
|
101 | + $login = $need_auth ? clean($_REQUEST['login']) : ''; |
|
102 | + $pass = $need_auth ? trim(clean($_REQUEST['pass'])) : ''; |
|
103 | 103 | |
104 | - $rc = Feeds::subscribe_to_feed($feed, $cat, $login, $pass); |
|
104 | + $rc = Feeds::subscribe_to_feed($feed, $cat, $login, $pass); |
|
105 | 105 | |
106 | - print json_encode(array("result" => $rc)); |
|
107 | - } |
|
106 | + print json_encode(array("result" => $rc)); |
|
107 | + } |
|
108 | 108 | |
109 | - public function togglepref() { |
|
110 | - $key = clean($_REQUEST["key"]); |
|
111 | - set_pref($key, !get_pref($key)); |
|
112 | - $value = get_pref($key); |
|
109 | + public function togglepref() { |
|
110 | + $key = clean($_REQUEST["key"]); |
|
111 | + set_pref($key, !get_pref($key)); |
|
112 | + $value = get_pref($key); |
|
113 | 113 | |
114 | - print json_encode(array("param" =>$key, "value" => $value)); |
|
115 | - } |
|
114 | + print json_encode(array("param" =>$key, "value" => $value)); |
|
115 | + } |
|
116 | 116 | |
117 | - public function setpref() { |
|
118 | - // set_pref escapes input, so no need to double escape it here |
|
119 | - $key = clean($_REQUEST['key']); |
|
120 | - $value = $_REQUEST['value']; |
|
117 | + public function setpref() { |
|
118 | + // set_pref escapes input, so no need to double escape it here |
|
119 | + $key = clean($_REQUEST['key']); |
|
120 | + $value = $_REQUEST['value']; |
|
121 | 121 | |
122 | - set_pref($key, $value, false, $key != 'USER_STYLESHEET'); |
|
122 | + set_pref($key, $value, false, $key != 'USER_STYLESHEET'); |
|
123 | 123 | |
124 | - print json_encode(array("param" =>$key, "value" => $value)); |
|
125 | - } |
|
124 | + print json_encode(array("param" =>$key, "value" => $value)); |
|
125 | + } |
|
126 | 126 | |
127 | - public function mark() { |
|
128 | - $mark = clean($_REQUEST["mark"]); |
|
129 | - $id = clean($_REQUEST["id"]); |
|
127 | + public function mark() { |
|
128 | + $mark = clean($_REQUEST["mark"]); |
|
129 | + $id = clean($_REQUEST["id"]); |
|
130 | 130 | |
131 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET marked = ?, |
|
131 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET marked = ?, |
|
132 | 132 | last_marked = NOW() |
133 | 133 | WHERE ref_id = ? AND owner_uid = ?"); |
134 | 134 | |
135 | - $sth->execute([$mark, $id, $_SESSION['uid']]); |
|
135 | + $sth->execute([$mark, $id, $_SESSION['uid']]); |
|
136 | 136 | |
137 | - print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
138 | - } |
|
137 | + print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
138 | + } |
|
139 | 139 | |
140 | - public function delete() { |
|
141 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
142 | - $ids_qmarks = arr_qmarks($ids); |
|
140 | + public function delete() { |
|
141 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
142 | + $ids_qmarks = arr_qmarks($ids); |
|
143 | 143 | |
144 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_user_entries |
|
144 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_user_entries |
|
145 | 145 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
146 | - $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
146 | + $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
147 | 147 | |
148 | - Article::purge_orphans(); |
|
148 | + Article::purge_orphans(); |
|
149 | 149 | |
150 | - print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
151 | - } |
|
150 | + print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
151 | + } |
|
152 | 152 | |
153 | - public function unarchive() { |
|
154 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
153 | + public function unarchive() { |
|
154 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
155 | 155 | |
156 | - foreach ($ids as $id) { |
|
157 | - $this->pdo->beginTransaction(); |
|
156 | + foreach ($ids as $id) { |
|
157 | + $this->pdo->beginTransaction(); |
|
158 | 158 | |
159 | - $sth = $this->pdo->prepare("SELECT feed_url,site_url,title FROM ttrss_archived_feeds |
|
159 | + $sth = $this->pdo->prepare("SELECT feed_url,site_url,title FROM ttrss_archived_feeds |
|
160 | 160 | WHERE id = (SELECT orig_feed_id FROM ttrss_user_entries WHERE ref_id = :id |
161 | 161 | AND owner_uid = :uid) AND owner_uid = :uid"); |
162 | - $sth->execute([":uid" => $_SESSION['uid'], ":id" => $id]); |
|
162 | + $sth->execute([":uid" => $_SESSION['uid'], ":id" => $id]); |
|
163 | 163 | |
164 | - if ($row = $sth->fetch()) { |
|
165 | - $feed_url = $row['feed_url']; |
|
166 | - $site_url = $row['site_url']; |
|
167 | - $title = $row['title']; |
|
164 | + if ($row = $sth->fetch()) { |
|
165 | + $feed_url = $row['feed_url']; |
|
166 | + $site_url = $row['site_url']; |
|
167 | + $title = $row['title']; |
|
168 | 168 | |
169 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ? |
|
169 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ? |
|
170 | 170 | AND owner_uid = ?"); |
171 | - $sth->execute([$feed_url, $_SESSION['uid']]); |
|
171 | + $sth->execute([$feed_url, $_SESSION['uid']]); |
|
172 | 172 | |
173 | - if ($row = $sth->fetch()) { |
|
174 | - $feed_id = $row["id"]; |
|
175 | - } else { |
|
176 | - if (!$title) $title = '[Unknown]'; |
|
173 | + if ($row = $sth->fetch()) { |
|
174 | + $feed_id = $row["id"]; |
|
175 | + } else { |
|
176 | + if (!$title) $title = '[Unknown]'; |
|
177 | 177 | |
178 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
178 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
179 | 179 | (owner_uid,feed_url,site_url,title,cat_id,auth_login,auth_pass,update_method) |
180 | 180 | VALUES (?, ?, ?, ?, NULL, '', '', 0)"); |
181 | - $sth->execute([$_SESSION['uid'], $feed_url, $site_url, $title]); |
|
181 | + $sth->execute([$_SESSION['uid'], $feed_url, $site_url, $title]); |
|
182 | 182 | |
183 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ? |
|
183 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE feed_url = ? |
|
184 | 184 | AND owner_uid = ?"); |
185 | - $sth->execute([$feed_url, $_SESSION['uid']]); |
|
185 | + $sth->execute([$feed_url, $_SESSION['uid']]); |
|
186 | 186 | |
187 | - if ($row = $sth->fetch()) { |
|
188 | - $feed_id = $row['id']; |
|
189 | - } |
|
190 | - } |
|
187 | + if ($row = $sth->fetch()) { |
|
188 | + $feed_id = $row['id']; |
|
189 | + } |
|
190 | + } |
|
191 | 191 | |
192 | - if ($feed_id) { |
|
193 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries |
|
192 | + if ($feed_id) { |
|
193 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries |
|
194 | 194 | SET feed_id = ?, orig_feed_id = NULL |
195 | 195 | WHERE ref_id = ? AND owner_uid = ?"); |
196 | - $sth->execute([$feed_id, $id, $_SESSION['uid']]); |
|
197 | - } |
|
198 | - } |
|
196 | + $sth->execute([$feed_id, $id, $_SESSION['uid']]); |
|
197 | + } |
|
198 | + } |
|
199 | 199 | |
200 | - $this->pdo->commit(); |
|
201 | - } |
|
200 | + $this->pdo->commit(); |
|
201 | + } |
|
202 | 202 | |
203 | - print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
204 | - } |
|
203 | + print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
204 | + } |
|
205 | 205 | |
206 | - public function archive() { |
|
207 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
206 | + public function archive() { |
|
207 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
208 | 208 | |
209 | - foreach ($ids as $id) { |
|
210 | - $this->archive_article($id, $_SESSION["uid"]); |
|
211 | - } |
|
209 | + foreach ($ids as $id) { |
|
210 | + $this->archive_article($id, $_SESSION["uid"]); |
|
211 | + } |
|
212 | 212 | |
213 | - print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
214 | - } |
|
213 | + print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
214 | + } |
|
215 | 215 | |
216 | - private function archive_article($id, $owner_uid) { |
|
217 | - $this->pdo->beginTransaction(); |
|
216 | + private function archive_article($id, $owner_uid) { |
|
217 | + $this->pdo->beginTransaction(); |
|
218 | 218 | |
219 | - if (!$owner_uid) $owner_uid = $_SESSION['uid']; |
|
219 | + if (!$owner_uid) $owner_uid = $_SESSION['uid']; |
|
220 | 220 | |
221 | - $sth = $this->pdo->prepare("SELECT feed_id FROM ttrss_user_entries |
|
221 | + $sth = $this->pdo->prepare("SELECT feed_id FROM ttrss_user_entries |
|
222 | 222 | WHERE ref_id = ? AND owner_uid = ?"); |
223 | - $sth->execute([$id, $owner_uid]); |
|
223 | + $sth->execute([$id, $owner_uid]); |
|
224 | 224 | |
225 | - if ($row = $sth->fetch()) { |
|
225 | + if ($row = $sth->fetch()) { |
|
226 | 226 | |
227 | - /* prepare the archived table */ |
|
227 | + /* prepare the archived table */ |
|
228 | 228 | |
229 | - $feed_id = (int) $row['feed_id']; |
|
229 | + $feed_id = (int) $row['feed_id']; |
|
230 | 230 | |
231 | - if ($feed_id) { |
|
232 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_archived_feeds |
|
231 | + if ($feed_id) { |
|
232 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_archived_feeds |
|
233 | 233 | WHERE id = ? AND owner_uid = ?"); |
234 | - $sth->execute([$feed_id, $owner_uid]); |
|
234 | + $sth->execute([$feed_id, $owner_uid]); |
|
235 | 235 | |
236 | - if ($row = $sth->fetch()) { |
|
237 | - $new_feed_id = $row['id']; |
|
238 | - } else { |
|
239 | - $row = $this->pdo->query("SELECT MAX(id) AS id FROM ttrss_archived_feeds")->fetch(); |
|
240 | - $new_feed_id = (int)$row['id'] + 1; |
|
236 | + if ($row = $sth->fetch()) { |
|
237 | + $new_feed_id = $row['id']; |
|
238 | + } else { |
|
239 | + $row = $this->pdo->query("SELECT MAX(id) AS id FROM ttrss_archived_feeds")->fetch(); |
|
240 | + $new_feed_id = (int)$row['id'] + 1; |
|
241 | 241 | |
242 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_archived_feeds |
|
242 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_archived_feeds |
|
243 | 243 | (id, owner_uid, title, feed_url, site_url, created) |
244 | 244 | SELECT ?, owner_uid, title, feed_url, site_url, NOW() from ttrss_feeds |
245 | 245 | WHERE id = ?"); |
246 | 246 | |
247 | - $sth->execute([$new_feed_id, $feed_id]); |
|
248 | - } |
|
247 | + $sth->execute([$new_feed_id, $feed_id]); |
|
248 | + } |
|
249 | 249 | |
250 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries |
|
250 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries |
|
251 | 251 | SET orig_feed_id = ?, feed_id = NULL |
252 | 252 | WHERE ref_id = ? AND owner_uid = ?"); |
253 | - $sth->execute([$new_feed_id, $id, $owner_uid]); |
|
254 | - } |
|
255 | - } |
|
253 | + $sth->execute([$new_feed_id, $id, $owner_uid]); |
|
254 | + } |
|
255 | + } |
|
256 | 256 | |
257 | - $this->pdo->commit(); |
|
258 | - } |
|
257 | + $this->pdo->commit(); |
|
258 | + } |
|
259 | 259 | |
260 | - public function publ() { |
|
261 | - $pub = clean($_REQUEST["pub"]); |
|
262 | - $id = clean($_REQUEST["id"]); |
|
260 | + public function publ() { |
|
261 | + $pub = clean($_REQUEST["pub"]); |
|
262 | + $id = clean($_REQUEST["id"]); |
|
263 | 263 | |
264 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
264 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
265 | 265 | published = ?, last_published = NOW() |
266 | 266 | WHERE ref_id = ? AND owner_uid = ?"); |
267 | 267 | |
268 | - $sth->execute([$pub, $id, $_SESSION['uid']]); |
|
268 | + $sth->execute([$pub, $id, $_SESSION['uid']]); |
|
269 | 269 | |
270 | - print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
271 | - } |
|
270 | + print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
271 | + } |
|
272 | 272 | |
273 | - public function getAllCounters() { |
|
274 | - @$seq = (int) $_REQUEST['seq']; |
|
273 | + public function getAllCounters() { |
|
274 | + @$seq = (int) $_REQUEST['seq']; |
|
275 | 275 | |
276 | - $reply = [ |
|
277 | - 'counters' => Counters::getAllCounters(), |
|
278 | - 'seq' => $seq |
|
279 | - ]; |
|
276 | + $reply = [ |
|
277 | + 'counters' => Counters::getAllCounters(), |
|
278 | + 'seq' => $seq |
|
279 | + ]; |
|
280 | 280 | |
281 | - if ($seq % 2 == 0) |
|
282 | - $reply['runtime-info'] = make_runtime_info(); |
|
281 | + if ($seq % 2 == 0) |
|
282 | + $reply['runtime-info'] = make_runtime_info(); |
|
283 | 283 | |
284 | - print json_encode($reply); |
|
285 | - } |
|
284 | + print json_encode($reply); |
|
285 | + } |
|
286 | 286 | |
287 | - /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ |
|
288 | - public function catchupSelected() { |
|
289 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
290 | - $cmode = (int)clean($_REQUEST["cmode"]); |
|
287 | + /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ |
|
288 | + public function catchupSelected() { |
|
289 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
290 | + $cmode = (int)clean($_REQUEST["cmode"]); |
|
291 | 291 | |
292 | - Article::catchupArticlesById($ids, $cmode); |
|
292 | + Article::catchupArticlesById($ids, $cmode); |
|
293 | 293 | |
294 | - print json_encode(array("message" => "UPDATE_COUNTERS", "ids" => $ids)); |
|
295 | - } |
|
294 | + print json_encode(array("message" => "UPDATE_COUNTERS", "ids" => $ids)); |
|
295 | + } |
|
296 | 296 | |
297 | - public function markSelected() { |
|
298 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
299 | - $cmode = (int)clean($_REQUEST["cmode"]); |
|
297 | + public function markSelected() { |
|
298 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
299 | + $cmode = (int)clean($_REQUEST["cmode"]); |
|
300 | 300 | |
301 | - $this->markArticlesById($ids, $cmode); |
|
301 | + $this->markArticlesById($ids, $cmode); |
|
302 | 302 | |
303 | - print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
304 | - } |
|
303 | + print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
304 | + } |
|
305 | 305 | |
306 | - public function publishSelected() { |
|
307 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
308 | - $cmode = (int)clean($_REQUEST["cmode"]); |
|
306 | + public function publishSelected() { |
|
307 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
308 | + $cmode = (int)clean($_REQUEST["cmode"]); |
|
309 | 309 | |
310 | - $this->publishArticlesById($ids, $cmode); |
|
310 | + $this->publishArticlesById($ids, $cmode); |
|
311 | 311 | |
312 | - print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
313 | - } |
|
312 | + print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
313 | + } |
|
314 | 314 | |
315 | - public function sanityCheck() { |
|
316 | - $_SESSION["hasAudio"] = clean($_REQUEST["hasAudio"]) === "true"; |
|
317 | - $_SESSION["hasSandbox"] = clean($_REQUEST["hasSandbox"]) === "true"; |
|
318 | - $_SESSION["hasMp3"] = clean($_REQUEST["hasMp3"]) === "true"; |
|
319 | - $_SESSION["clientTzOffset"] = clean($_REQUEST["clientTzOffset"]); |
|
315 | + public function sanityCheck() { |
|
316 | + $_SESSION["hasAudio"] = clean($_REQUEST["hasAudio"]) === "true"; |
|
317 | + $_SESSION["hasSandbox"] = clean($_REQUEST["hasSandbox"]) === "true"; |
|
318 | + $_SESSION["hasMp3"] = clean($_REQUEST["hasMp3"]) === "true"; |
|
319 | + $_SESSION["clientTzOffset"] = clean($_REQUEST["clientTzOffset"]); |
|
320 | 320 | |
321 | - $reply = array(); |
|
321 | + $reply = array(); |
|
322 | 322 | |
323 | - $reply['error'] = sanity_check(); |
|
323 | + $reply['error'] = sanity_check(); |
|
324 | 324 | |
325 | - if ($reply['error']['code'] == 0) { |
|
326 | - $reply['init-params'] = make_init_params(); |
|
327 | - $reply['runtime-info'] = make_runtime_info(); |
|
328 | - } |
|
325 | + if ($reply['error']['code'] == 0) { |
|
326 | + $reply['init-params'] = make_init_params(); |
|
327 | + $reply['runtime-info'] = make_runtime_info(); |
|
328 | + } |
|
329 | 329 | |
330 | - print json_encode($reply); |
|
331 | - } |
|
330 | + print json_encode($reply); |
|
331 | + } |
|
332 | 332 | |
333 | - public function completeLabels() { |
|
334 | - $search = clean($_REQUEST["search"]); |
|
333 | + public function completeLabels() { |
|
334 | + $search = clean($_REQUEST["search"]); |
|
335 | 335 | |
336 | - $sth = $this->pdo->prepare("SELECT DISTINCT caption FROM |
|
336 | + $sth = $this->pdo->prepare("SELECT DISTINCT caption FROM |
|
337 | 337 | ttrss_labels2 |
338 | 338 | WHERE owner_uid = ? AND |
339 | 339 | LOWER(caption) LIKE LOWER(?) ORDER BY caption |
340 | 340 | LIMIT 5"); |
341 | - $sth->execute([$_SESSION['uid'], "%$search%"]); |
|
341 | + $sth->execute([$_SESSION['uid'], "%$search%"]); |
|
342 | 342 | |
343 | - print "<ul>"; |
|
344 | - while ($line = $sth->fetch()) { |
|
345 | - print "<li>" . $line["caption"] . "</li>"; |
|
346 | - } |
|
347 | - print "</ul>"; |
|
348 | - } |
|
343 | + print "<ul>"; |
|
344 | + while ($line = $sth->fetch()) { |
|
345 | + print "<li>" . $line["caption"] . "</li>"; |
|
346 | + } |
|
347 | + print "</ul>"; |
|
348 | + } |
|
349 | 349 | |
350 | - // Silent |
|
351 | - public function massSubscribe() { |
|
350 | + // Silent |
|
351 | + public function massSubscribe() { |
|
352 | 352 | |
353 | - $payload = json_decode(clean($_REQUEST["payload"]), false); |
|
354 | - $mode = clean($_REQUEST["mode"]); |
|
353 | + $payload = json_decode(clean($_REQUEST["payload"]), false); |
|
354 | + $mode = clean($_REQUEST["mode"]); |
|
355 | 355 | |
356 | - if (!$payload || !is_array($payload)) return; |
|
356 | + if (!$payload || !is_array($payload)) return; |
|
357 | 357 | |
358 | - if ($mode == 1) { |
|
359 | - foreach ($payload as $feed) { |
|
358 | + if ($mode == 1) { |
|
359 | + foreach ($payload as $feed) { |
|
360 | 360 | |
361 | - $title = $feed[0]; |
|
362 | - $feed_url = $feed[1]; |
|
361 | + $title = $feed[0]; |
|
362 | + $feed_url = $feed[1]; |
|
363 | 363 | |
364 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
364 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
365 | 365 | feed_url = ? AND owner_uid = ?"); |
366 | - $sth->execute([$feed_url, $_SESSION['uid']]); |
|
366 | + $sth->execute([$feed_url, $_SESSION['uid']]); |
|
367 | 367 | |
368 | - if (!$sth->fetch()) { |
|
369 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
368 | + if (!$sth->fetch()) { |
|
369 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
370 | 370 | (owner_uid,feed_url,title,cat_id,site_url) |
371 | 371 | VALUES (?, ?, ?, NULL, '')"); |
372 | 372 | |
373 | - $sth->execute([$_SESSION['uid'], $feed_url, $title]); |
|
374 | - } |
|
375 | - } |
|
376 | - } else if ($mode == 2) { |
|
377 | - // feed archive |
|
378 | - foreach ($payload as $id) { |
|
379 | - $sth = $this->pdo->prepare("SELECT * FROM ttrss_archived_feeds |
|
373 | + $sth->execute([$_SESSION['uid'], $feed_url, $title]); |
|
374 | + } |
|
375 | + } |
|
376 | + } else if ($mode == 2) { |
|
377 | + // feed archive |
|
378 | + foreach ($payload as $id) { |
|
379 | + $sth = $this->pdo->prepare("SELECT * FROM ttrss_archived_feeds |
|
380 | 380 | WHERE id = ? AND owner_uid = ?"); |
381 | - $sth->execute([$id, $_SESSION['uid']]); |
|
381 | + $sth->execute([$id, $_SESSION['uid']]); |
|
382 | 382 | |
383 | - if ($row = $sth->fetch()) { |
|
384 | - $site_url = $row['site_url']; |
|
385 | - $feed_url = $row['feed_url']; |
|
386 | - $title = $row['title']; |
|
383 | + if ($row = $sth->fetch()) { |
|
384 | + $site_url = $row['site_url']; |
|
385 | + $feed_url = $row['feed_url']; |
|
386 | + $title = $row['title']; |
|
387 | 387 | |
388 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
388 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
389 | 389 | feed_url = ? AND owner_uid = ?"); |
390 | - $sth->execute([$feed_url, $_SESSION['uid']]); |
|
390 | + $sth->execute([$feed_url, $_SESSION['uid']]); |
|
391 | 391 | |
392 | - if (!$sth->fetch()) { |
|
393 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
392 | + if (!$sth->fetch()) { |
|
393 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_feeds |
|
394 | 394 | (owner_uid,feed_url,title,cat_id,site_url) |
395 | 395 | VALUES (?, ?, ?, NULL, ?)"); |
396 | 396 | |
397 | - $sth->execute([$_SESSION['uid'], $feed_url, $title, $site_url]); |
|
398 | - } |
|
399 | - } |
|
400 | - } |
|
401 | - } |
|
402 | - } |
|
397 | + $sth->execute([$_SESSION['uid'], $feed_url, $title, $site_url]); |
|
398 | + } |
|
399 | + } |
|
400 | + } |
|
401 | + } |
|
402 | + } |
|
403 | 403 | |
404 | - public function catchupFeed() { |
|
405 | - $feed_id = clean($_REQUEST['feed_id']); |
|
406 | - $is_cat = clean($_REQUEST['is_cat']) == "true"; |
|
407 | - $mode = clean($_REQUEST['mode']); |
|
408 | - $search_query = clean($_REQUEST['search_query']); |
|
409 | - $search_lang = clean($_REQUEST['search_lang']); |
|
404 | + public function catchupFeed() { |
|
405 | + $feed_id = clean($_REQUEST['feed_id']); |
|
406 | + $is_cat = clean($_REQUEST['is_cat']) == "true"; |
|
407 | + $mode = clean($_REQUEST['mode']); |
|
408 | + $search_query = clean($_REQUEST['search_query']); |
|
409 | + $search_lang = clean($_REQUEST['search_lang']); |
|
410 | 410 | |
411 | - Feeds::catchup_feed($feed_id, $is_cat, false, $mode, [$search_query, $search_lang]); |
|
411 | + Feeds::catchup_feed($feed_id, $is_cat, false, $mode, [$search_query, $search_lang]); |
|
412 | 412 | |
413 | - // return counters here synchronously so that frontend can figure out next unread feed properly |
|
414 | - print json_encode(['counters' => Counters::getAllCounters()]); |
|
413 | + // return counters here synchronously so that frontend can figure out next unread feed properly |
|
414 | + print json_encode(['counters' => Counters::getAllCounters()]); |
|
415 | 415 | |
416 | - //print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
417 | - } |
|
416 | + //print json_encode(array("message" => "UPDATE_COUNTERS")); |
|
417 | + } |
|
418 | 418 | |
419 | - public function setpanelmode() { |
|
420 | - $wide = (int) clean($_REQUEST["wide"]); |
|
419 | + public function setpanelmode() { |
|
420 | + $wide = (int) clean($_REQUEST["wide"]); |
|
421 | 421 | |
422 | - setcookie("ttrss_widescreen", $wide, |
|
423 | - time() + COOKIE_LIFETIME_LONG); |
|
422 | + setcookie("ttrss_widescreen", $wide, |
|
423 | + time() + COOKIE_LIFETIME_LONG); |
|
424 | 424 | |
425 | - print json_encode(array("wide" => $wide)); |
|
426 | - } |
|
425 | + print json_encode(array("wide" => $wide)); |
|
426 | + } |
|
427 | 427 | |
428 | - public static function updaterandomfeed_real() { |
|
428 | + public static function updaterandomfeed_real() { |
|
429 | 429 | |
430 | - // Test if the feed need a update (update interval exceded). |
|
431 | - if (DB_TYPE == "pgsql") { |
|
432 | - $update_limit_qpart = "AND (( |
|
430 | + // Test if the feed need a update (update interval exceded). |
|
431 | + if (DB_TYPE == "pgsql") { |
|
432 | + $update_limit_qpart = "AND (( |
|
433 | 433 | ttrss_feeds.update_interval = 0 |
434 | 434 | AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL) |
435 | 435 | ) OR ( |
@@ -437,8 +437,8 @@ discard block |
||
437 | 437 | AND ttrss_feeds.last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL) |
438 | 438 | ) OR ttrss_feeds.last_updated IS NULL |
439 | 439 | OR last_updated = '1970-01-01 00:00:00')"; |
440 | - } else { |
|
441 | - $update_limit_qpart = "AND (( |
|
440 | + } else { |
|
441 | + $update_limit_qpart = "AND (( |
|
442 | 442 | ttrss_feeds.update_interval = 0 |
443 | 443 | AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE) |
444 | 444 | ) OR ( |
@@ -446,28 +446,28 @@ discard block |
||
446 | 446 | AND ttrss_feeds.last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE) |
447 | 447 | ) OR ttrss_feeds.last_updated IS NULL |
448 | 448 | OR last_updated = '1970-01-01 00:00:00')"; |
449 | - } |
|
449 | + } |
|
450 | 450 | |
451 | - // Test if feed is currently being updated by another process. |
|
452 | - if (DB_TYPE == "pgsql") { |
|
453 | - $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')"; |
|
454 | - } else { |
|
455 | - $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))"; |
|
456 | - } |
|
451 | + // Test if feed is currently being updated by another process. |
|
452 | + if (DB_TYPE == "pgsql") { |
|
453 | + $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '5 minutes')"; |
|
454 | + } else { |
|
455 | + $updstart_thresh_qpart = "AND (ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 5 MINUTE))"; |
|
456 | + } |
|
457 | 457 | |
458 | - $random_qpart = sql_random_function(); |
|
458 | + $random_qpart = sql_random_function(); |
|
459 | 459 | |
460 | - $pdo = Db::pdo(); |
|
460 | + $pdo = Db::pdo(); |
|
461 | 461 | |
462 | - // we could be invoked from public.php with no active session |
|
463 | - if ($_SESSION["uid"]) { |
|
464 | - $owner_check_qpart = "AND ttrss_feeds.owner_uid = ".$pdo->quote($_SESSION["uid"]); |
|
465 | - } else { |
|
466 | - $owner_check_qpart = ""; |
|
467 | - } |
|
462 | + // we could be invoked from public.php with no active session |
|
463 | + if ($_SESSION["uid"]) { |
|
464 | + $owner_check_qpart = "AND ttrss_feeds.owner_uid = ".$pdo->quote($_SESSION["uid"]); |
|
465 | + } else { |
|
466 | + $owner_check_qpart = ""; |
|
467 | + } |
|
468 | 468 | |
469 | - // We search for feed needing update. |
|
470 | - $res = $pdo->query("SELECT ttrss_feeds.feed_url,ttrss_feeds.id |
|
469 | + // We search for feed needing update. |
|
470 | + $res = $pdo->query("SELECT ttrss_feeds.feed_url,ttrss_feeds.id |
|
471 | 471 | FROM |
472 | 472 | ttrss_feeds, ttrss_users, ttrss_user_prefs |
473 | 473 | WHERE |
@@ -479,139 +479,139 @@ discard block |
||
479 | 479 | $updstart_thresh_qpart |
480 | 480 | ORDER BY $random_qpart LIMIT 30"); |
481 | 481 | |
482 | - $num_updated = 0; |
|
482 | + $num_updated = 0; |
|
483 | 483 | |
484 | - $tstart = time(); |
|
484 | + $tstart = time(); |
|
485 | 485 | |
486 | - while ($line = $res->fetch()) { |
|
487 | - $feed_id = $line["id"]; |
|
486 | + while ($line = $res->fetch()) { |
|
487 | + $feed_id = $line["id"]; |
|
488 | 488 | |
489 | - if (time() - $tstart < ini_get("max_execution_time") * 0.7) { |
|
490 | - RSSUtils::update_rss_feed($feed_id, true); |
|
491 | - ++$num_updated; |
|
492 | - } else { |
|
493 | - break; |
|
494 | - } |
|
495 | - } |
|
489 | + if (time() - $tstart < ini_get("max_execution_time") * 0.7) { |
|
490 | + RSSUtils::update_rss_feed($feed_id, true); |
|
491 | + ++$num_updated; |
|
492 | + } else { |
|
493 | + break; |
|
494 | + } |
|
495 | + } |
|
496 | 496 | |
497 | - // Purge orphans and cleanup tags |
|
498 | - Article::purge_orphans(); |
|
499 | - //cleanup_tags(14, 50000); |
|
497 | + // Purge orphans and cleanup tags |
|
498 | + Article::purge_orphans(); |
|
499 | + //cleanup_tags(14, 50000); |
|
500 | 500 | |
501 | - if ($num_updated > 0) { |
|
502 | - print json_encode(array("message" => "UPDATE_COUNTERS", |
|
503 | - "num_updated" => $num_updated)); |
|
504 | - } else { |
|
505 | - print json_encode(array("message" => "NOTHING_TO_UPDATE")); |
|
506 | - } |
|
501 | + if ($num_updated > 0) { |
|
502 | + print json_encode(array("message" => "UPDATE_COUNTERS", |
|
503 | + "num_updated" => $num_updated)); |
|
504 | + } else { |
|
505 | + print json_encode(array("message" => "NOTHING_TO_UPDATE")); |
|
506 | + } |
|
507 | 507 | |
508 | - } |
|
508 | + } |
|
509 | 509 | |
510 | - public function updaterandomfeed() { |
|
511 | - RPC::updaterandomfeed_real(); |
|
512 | - } |
|
510 | + public function updaterandomfeed() { |
|
511 | + RPC::updaterandomfeed_real(); |
|
512 | + } |
|
513 | 513 | |
514 | - private function markArticlesById($ids, $cmode) { |
|
514 | + private function markArticlesById($ids, $cmode) { |
|
515 | 515 | |
516 | - $ids_qmarks = arr_qmarks($ids); |
|
516 | + $ids_qmarks = arr_qmarks($ids); |
|
517 | 517 | |
518 | - if ($cmode == 0) { |
|
519 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
518 | + if ($cmode == 0) { |
|
519 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
520 | 520 | marked = false, last_marked = NOW() |
521 | 521 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
522 | - } else if ($cmode == 1) { |
|
523 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
522 | + } else if ($cmode == 1) { |
|
523 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
524 | 524 | marked = true, last_marked = NOW() |
525 | 525 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
526 | - } else { |
|
527 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
526 | + } else { |
|
527 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
528 | 528 | marked = NOT marked,last_marked = NOW() |
529 | 529 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
530 | - } |
|
530 | + } |
|
531 | 531 | |
532 | - $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
533 | - } |
|
532 | + $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
533 | + } |
|
534 | 534 | |
535 | - private function publishArticlesById($ids, $cmode) { |
|
535 | + private function publishArticlesById($ids, $cmode) { |
|
536 | 536 | |
537 | - $ids_qmarks = arr_qmarks($ids); |
|
537 | + $ids_qmarks = arr_qmarks($ids); |
|
538 | 538 | |
539 | - if ($cmode == 0) { |
|
540 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
539 | + if ($cmode == 0) { |
|
540 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
541 | 541 | published = false, last_published = NOW() |
542 | 542 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
543 | - } else if ($cmode == 1) { |
|
544 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
543 | + } else if ($cmode == 1) { |
|
544 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
545 | 545 | published = true, last_published = NOW() |
546 | 546 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
547 | - } else { |
|
548 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
547 | + } else { |
|
548 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
549 | 549 | published = NOT published,last_published = NOW() |
550 | 550 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
551 | - } |
|
551 | + } |
|
552 | 552 | |
553 | - $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
554 | - } |
|
553 | + $sth->execute(array_merge($ids, [$_SESSION['uid']])); |
|
554 | + } |
|
555 | 555 | |
556 | - public function getlinktitlebyid() { |
|
557 | - $id = clean($_REQUEST['id']); |
|
556 | + public function getlinktitlebyid() { |
|
557 | + $id = clean($_REQUEST['id']); |
|
558 | 558 | |
559 | - $sth = $this->pdo->prepare("SELECT link, title FROM ttrss_entries, ttrss_user_entries |
|
559 | + $sth = $this->pdo->prepare("SELECT link, title FROM ttrss_entries, ttrss_user_entries |
|
560 | 560 | WHERE ref_id = ? AND ref_id = id AND owner_uid = ?"); |
561 | - $sth->execute([$id, $_SESSION['uid']]); |
|
561 | + $sth->execute([$id, $_SESSION['uid']]); |
|
562 | 562 | |
563 | - if ($row = $sth->fetch()) { |
|
564 | - $link = $row['link']; |
|
565 | - $title = $row['title']; |
|
563 | + if ($row = $sth->fetch()) { |
|
564 | + $link = $row['link']; |
|
565 | + $title = $row['title']; |
|
566 | 566 | |
567 | - echo json_encode(array("link" => $link, "title" => $title)); |
|
568 | - } else { |
|
569 | - echo json_encode(array("error" => "ARTICLE_NOT_FOUND")); |
|
570 | - } |
|
571 | - } |
|
567 | + echo json_encode(array("link" => $link, "title" => $title)); |
|
568 | + } else { |
|
569 | + echo json_encode(array("error" => "ARTICLE_NOT_FOUND")); |
|
570 | + } |
|
571 | + } |
|
572 | 572 | |
573 | - public function log() { |
|
574 | - $msg = clean($_REQUEST['msg']); |
|
575 | - $file = clean_filename($_REQUEST['file']); |
|
576 | - $line = (int) clean($_REQUEST['line']); |
|
577 | - $context = clean($_REQUEST['context']); |
|
573 | + public function log() { |
|
574 | + $msg = clean($_REQUEST['msg']); |
|
575 | + $file = clean_filename($_REQUEST['file']); |
|
576 | + $line = (int) clean($_REQUEST['line']); |
|
577 | + $context = clean($_REQUEST['context']); |
|
578 | 578 | |
579 | - if ($msg) { |
|
580 | - Logger::get()->log_error(E_USER_WARNING, |
|
581 | - $msg, 'client-js:' . $file, $line, $context); |
|
579 | + if ($msg) { |
|
580 | + Logger::get()->log_error(E_USER_WARNING, |
|
581 | + $msg, 'client-js:' . $file, $line, $context); |
|
582 | 582 | |
583 | - echo json_encode(array("message" => "HOST_ERROR_LOGGED")); |
|
584 | - } else { |
|
585 | - echo json_encode(array("error" => "MESSAGE_NOT_FOUND")); |
|
586 | - } |
|
583 | + echo json_encode(array("message" => "HOST_ERROR_LOGGED")); |
|
584 | + } else { |
|
585 | + echo json_encode(array("error" => "MESSAGE_NOT_FOUND")); |
|
586 | + } |
|
587 | 587 | |
588 | - } |
|
588 | + } |
|
589 | 589 | |
590 | - public function checkforupdates() { |
|
591 | - $rv = []; |
|
590 | + public function checkforupdates() { |
|
591 | + $rv = []; |
|
592 | 592 | |
593 | - $git_timestamp = false; |
|
594 | - $git_commit = false; |
|
593 | + $git_timestamp = false; |
|
594 | + $git_commit = false; |
|
595 | 595 | |
596 | - get_version($git_commit, $git_timestamp); |
|
596 | + get_version($git_commit, $git_timestamp); |
|
597 | 597 | |
598 | - if (CHECK_FOR_UPDATES && $_SESSION["access_level"] >= 10 && $git_timestamp) { |
|
599 | - $content = @fetch_file_contents(["url" => "https://srv.tt-rss.org/version.json"]); |
|
598 | + if (CHECK_FOR_UPDATES && $_SESSION["access_level"] >= 10 && $git_timestamp) { |
|
599 | + $content = @fetch_file_contents(["url" => "https://srv.tt-rss.org/version.json"]); |
|
600 | 600 | |
601 | - if ($content) { |
|
602 | - $content = json_decode($content, true); |
|
601 | + if ($content) { |
|
602 | + $content = json_decode($content, true); |
|
603 | 603 | |
604 | - if ($content && isset($content["changeset"])) { |
|
605 | - if ($git_timestamp < (int)$content["changeset"]["timestamp"] && |
|
606 | - $git_commit != $content["changeset"]["id"]) { |
|
604 | + if ($content && isset($content["changeset"])) { |
|
605 | + if ($git_timestamp < (int)$content["changeset"]["timestamp"] && |
|
606 | + $git_commit != $content["changeset"]["id"]) { |
|
607 | 607 | |
608 | - $rv = $content["changeset"]; |
|
609 | - } |
|
610 | - } |
|
611 | - } |
|
612 | - } |
|
608 | + $rv = $content["changeset"]; |
|
609 | + } |
|
610 | + } |
|
611 | + } |
|
612 | + } |
|
613 | 613 | |
614 | - print json_encode($rv); |
|
615 | - } |
|
614 | + print json_encode($rv); |
|
615 | + } |
|
616 | 616 | |
617 | 617 | } |
@@ -1,52 +1,52 @@ |
||
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"); |
|
21 | + if (defined('_LOG_SENT_MAIL') && _LOG_SENT_MAIL) |
|
22 | + Logger::get()->log("Sending mail from $from_combined to $to_combined [$subject]: $message"); |
|
23 | 23 | |
24 | - // HOOK_SEND_MAIL plugin instructions: |
|
25 | - // 1. return 1 or true if mail is handled |
|
26 | - // 2. return -1 if there's been a fatal error and no further action is allowed |
|
27 | - // 3. any other return value will allow cycling to the next handler and, eventually, to default mail() function |
|
28 | - // 4. set error message if needed via passed Mailer instance function set_error() |
|
24 | + // HOOK_SEND_MAIL plugin instructions: |
|
25 | + // 1. return 1 or true if mail is handled |
|
26 | + // 2. return -1 if there's been a fatal error and no further action is allowed |
|
27 | + // 3. any other return value will allow cycling to the next handler and, eventually, to default mail() function |
|
28 | + // 4. set error message if needed via passed Mailer instance function set_error() |
|
29 | 29 | |
30 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEND_MAIL) as $p) { |
|
31 | - $rc = $p->hook_send_mail($this, $params); |
|
30 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEND_MAIL) as $p) { |
|
31 | + $rc = $p->hook_send_mail($this, $params); |
|
32 | 32 | |
33 | - if ($rc == 1) |
|
34 | - return $rc; |
|
33 | + if ($rc == 1) |
|
34 | + return $rc; |
|
35 | 35 | |
36 | - if ($rc == -1) |
|
37 | - return 0; |
|
38 | - } |
|
36 | + if ($rc == -1) |
|
37 | + return 0; |
|
38 | + } |
|
39 | 39 | |
40 | - $headers = [ "From: $from_combined", "Content-Type: text/plain; charset=UTF-8" ]; |
|
40 | + $headers = [ "From: $from_combined", "Content-Type: text/plain; charset=UTF-8" ]; |
|
41 | 41 | |
42 | - return mail($to_combined, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers))); |
|
43 | - } |
|
42 | + return mail($to_combined, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers))); |
|
43 | + } |
|
44 | 44 | |
45 | - public function set_error($message) { |
|
46 | - $this->last_error = $message; |
|
47 | - } |
|
45 | + public function set_error($message) { |
|
46 | + $this->last_error = $message; |
|
47 | + } |
|
48 | 48 | |
49 | - public function error() { |
|
50 | - return $this->last_error; |
|
51 | - } |
|
49 | + public function error() { |
|
50 | + return $this->last_error; |
|
51 | + } |
|
52 | 52 | } |
@@ -1,16 +1,16 @@ |
||
1 | 1 | <?php |
2 | 2 | abstract class FeedItem { |
3 | - abstract function get_id(); |
|
4 | - abstract function get_date(); |
|
5 | - abstract function get_link(); |
|
6 | - abstract function get_title(); |
|
7 | - abstract function get_description(); |
|
8 | - abstract function get_content(); |
|
9 | - abstract function get_comments_url(); |
|
10 | - abstract function get_comments_count(); |
|
11 | - abstract function get_categories(); |
|
12 | - abstract function get_enclosures(); |
|
13 | - abstract function get_author(); |
|
14 | - abstract function get_language(); |
|
3 | + abstract function get_id(); |
|
4 | + abstract function get_date(); |
|
5 | + abstract function get_link(); |
|
6 | + abstract function get_title(); |
|
7 | + abstract function get_description(); |
|
8 | + abstract function get_content(); |
|
9 | + abstract function get_comments_url(); |
|
10 | + abstract function get_comments_count(); |
|
11 | + abstract function get_categories(); |
|
12 | + abstract function get_enclosures(); |
|
13 | + abstract function get_author(); |
|
14 | + abstract function get_language(); |
|
15 | 15 | } |
16 | 16 |
@@ -1,620 +1,620 @@ 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) $title = $url; |
|
61 | - if (!$title && !$url) return false; |
|
60 | + if (!$title) $title = $url; |
|
61 | + if (!$title && !$url) return false; |
|
62 | 62 | |
63 | - if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) return false; |
|
63 | + if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) return false; |
|
64 | 64 | |
65 | - $pdo = Db::pdo(); |
|
65 | + $pdo = Db::pdo(); |
|
66 | 66 | |
67 | - $pdo->beginTransaction(); |
|
67 | + $pdo->beginTransaction(); |
|
68 | 68 | |
69 | - // only check for our user data here, others might have shared this with different content etc |
|
70 | - $sth = $pdo->prepare("SELECT id FROM ttrss_entries, ttrss_user_entries WHERE |
|
69 | + // only check for our user data here, others might have shared this with different content etc |
|
70 | + $sth = $pdo->prepare("SELECT id FROM ttrss_entries, ttrss_user_entries WHERE |
|
71 | 71 | guid = ? AND ref_id = id AND owner_uid = ? LIMIT 1"); |
72 | - $sth->execute([$guid, $owner_uid]); |
|
72 | + $sth->execute([$guid, $owner_uid]); |
|
73 | 73 | |
74 | - if ($row = $sth->fetch()) { |
|
75 | - $ref_id = $row['id']; |
|
74 | + if ($row = $sth->fetch()) { |
|
75 | + $ref_id = $row['id']; |
|
76 | 76 | |
77 | - $sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
|
77 | + $sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
|
78 | 78 | ref_id = ? AND owner_uid = ? LIMIT 1"); |
79 | 79 | $sth->execute([$ref_id, $owner_uid]); |
80 | 80 | |
81 | - if ($row = $sth->fetch()) { |
|
82 | - $int_id = $row['int_id']; |
|
81 | + if ($row = $sth->fetch()) { |
|
82 | + $int_id = $row['int_id']; |
|
83 | 83 | |
84 | - $sth = $pdo->prepare("UPDATE ttrss_entries SET |
|
84 | + $sth = $pdo->prepare("UPDATE ttrss_entries SET |
|
85 | 85 | content = ?, content_hash = ? WHERE id = ?"); |
86 | - $sth->execute([$content, $content_hash, $ref_id]); |
|
86 | + $sth->execute([$content, $content_hash, $ref_id]); |
|
87 | 87 | |
88 | - if (DB_TYPE == "pgsql"){ |
|
89 | - $sth = $pdo->prepare("UPDATE ttrss_entries |
|
88 | + if (DB_TYPE == "pgsql"){ |
|
89 | + $sth = $pdo->prepare("UPDATE ttrss_entries |
|
90 | 90 | SET tsvector_combined = to_tsvector( :ts_content) |
91 | 91 | WHERE id = :id"); |
92 | - $params = [ |
|
93 | - ":ts_content" => mb_substr(strip_tags($content ), 0, 900000), |
|
94 | - ":id" => $ref_id]; |
|
95 | - $sth->execute($params); |
|
96 | - } |
|
92 | + $params = [ |
|
93 | + ":ts_content" => mb_substr(strip_tags($content ), 0, 900000), |
|
94 | + ":id" => $ref_id]; |
|
95 | + $sth->execute($params); |
|
96 | + } |
|
97 | 97 | |
98 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries SET published = true, |
|
98 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries SET published = true, |
|
99 | 99 | last_published = NOW() WHERE |
100 | 100 | int_id = ? AND owner_uid = ?"); |
101 | - $sth->execute([$int_id, $owner_uid]); |
|
101 | + $sth->execute([$int_id, $owner_uid]); |
|
102 | 102 | |
103 | - } else { |
|
103 | + } else { |
|
104 | 104 | |
105 | - $sth = $pdo->prepare("INSERT INTO ttrss_user_entries |
|
105 | + $sth = $pdo->prepare("INSERT INTO ttrss_user_entries |
|
106 | 106 | (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, |
107 | 107 | last_read, note, unread, last_published) |
108 | 108 | VALUES |
109 | 109 | (?, '', NULL, NULL, ?, true, '', '', NOW(), '', false, NOW())"); |
110 | - $sth->execute([$ref_id, $owner_uid]); |
|
111 | - } |
|
110 | + $sth->execute([$ref_id, $owner_uid]); |
|
111 | + } |
|
112 | 112 | |
113 | - if (count($labels) != 0) { |
|
114 | - foreach ($labels as $label) { |
|
115 | - Labels::add_article($ref_id, trim($label), $owner_uid); |
|
116 | - } |
|
117 | - } |
|
113 | + if (count($labels) != 0) { |
|
114 | + foreach ($labels as $label) { |
|
115 | + Labels::add_article($ref_id, trim($label), $owner_uid); |
|
116 | + } |
|
117 | + } |
|
118 | 118 | |
119 | - $rc = true; |
|
119 | + $rc = true; |
|
120 | 120 | |
121 | - } else { |
|
122 | - $sth = $pdo->prepare("INSERT INTO ttrss_entries |
|
121 | + } else { |
|
122 | + $sth = $pdo->prepare("INSERT INTO ttrss_entries |
|
123 | 123 | (title, guid, link, updated, content, content_hash, date_entered, date_updated) |
124 | 124 | VALUES |
125 | 125 | (?, ?, ?, NOW(), ?, ?, NOW(), NOW())"); |
126 | - $sth->execute([$title, $guid, $url, $content, $content_hash]); |
|
126 | + $sth->execute([$title, $guid, $url, $content, $content_hash]); |
|
127 | 127 | |
128 | - $sth = $pdo->prepare("SELECT id FROM ttrss_entries WHERE guid = ?"); |
|
129 | - $sth->execute([$guid]); |
|
128 | + $sth = $pdo->prepare("SELECT id FROM ttrss_entries WHERE guid = ?"); |
|
129 | + $sth->execute([$guid]); |
|
130 | 130 | |
131 | - if ($row = $sth->fetch()) { |
|
132 | - $ref_id = $row["id"]; |
|
133 | - if (DB_TYPE == "pgsql"){ |
|
134 | - $sth = $pdo->prepare("UPDATE ttrss_entries |
|
131 | + if ($row = $sth->fetch()) { |
|
132 | + $ref_id = $row["id"]; |
|
133 | + if (DB_TYPE == "pgsql"){ |
|
134 | + $sth = $pdo->prepare("UPDATE ttrss_entries |
|
135 | 135 | SET tsvector_combined = to_tsvector( :ts_content) |
136 | 136 | WHERE id = :id"); |
137 | - $params = [ |
|
138 | - ":ts_content" => mb_substr(strip_tags($content ), 0, 900000), |
|
139 | - ":id" => $ref_id]; |
|
140 | - $sth->execute($params); |
|
141 | - } |
|
142 | - $sth = $pdo->prepare("INSERT INTO ttrss_user_entries |
|
137 | + $params = [ |
|
138 | + ":ts_content" => mb_substr(strip_tags($content ), 0, 900000), |
|
139 | + ":id" => $ref_id]; |
|
140 | + $sth->execute($params); |
|
141 | + } |
|
142 | + $sth = $pdo->prepare("INSERT INTO ttrss_user_entries |
|
143 | 143 | (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, |
144 | 144 | last_read, note, unread, last_published) |
145 | 145 | VALUES |
146 | 146 | (?, '', NULL, NULL, ?, true, '', '', NOW(), '', false, NOW())"); |
147 | - $sth->execute([$ref_id, $owner_uid]); |
|
147 | + $sth->execute([$ref_id, $owner_uid]); |
|
148 | 148 | |
149 | - if (count($labels) != 0) { |
|
150 | - foreach ($labels as $label) { |
|
151 | - Labels::add_article($ref_id, trim($label), $owner_uid); |
|
152 | - } |
|
153 | - } |
|
149 | + if (count($labels) != 0) { |
|
150 | + foreach ($labels as $label) { |
|
151 | + Labels::add_article($ref_id, trim($label), $owner_uid); |
|
152 | + } |
|
153 | + } |
|
154 | 154 | |
155 | - $rc = true; |
|
156 | - } |
|
157 | - } |
|
155 | + $rc = true; |
|
156 | + } |
|
157 | + } |
|
158 | 158 | |
159 | - $pdo->commit(); |
|
159 | + $pdo->commit(); |
|
160 | 160 | |
161 | - return $rc; |
|
162 | - } |
|
161 | + return $rc; |
|
162 | + } |
|
163 | 163 | |
164 | - public function editArticleTags() { |
|
164 | + public function editArticleTags() { |
|
165 | 165 | |
166 | - $param = clean($_REQUEST['param']); |
|
166 | + $param = clean($_REQUEST['param']); |
|
167 | 167 | |
168 | - $tags = Article::get_article_tags($param); |
|
168 | + $tags = Article::get_article_tags($param); |
|
169 | 169 | |
170 | - $tags_str = join(", ", $tags); |
|
170 | + $tags_str = join(", ", $tags); |
|
171 | 171 | |
172 | - print_hidden("id", "$param"); |
|
173 | - print_hidden("op", "article"); |
|
174 | - print_hidden("method", "setArticleTags"); |
|
172 | + print_hidden("id", "$param"); |
|
173 | + print_hidden("op", "article"); |
|
174 | + print_hidden("method", "setArticleTags"); |
|
175 | 175 | |
176 | - print "<header class='horizontal'>" . __("Tags for this article (separated by commas):")."</header>"; |
|
176 | + print "<header class='horizontal'>" . __("Tags for this article (separated by commas):")."</header>"; |
|
177 | 177 | |
178 | - print "<section>"; |
|
179 | - print "<textarea dojoType='dijit.form.SimpleTextarea' rows='4' |
|
178 | + print "<section>"; |
|
179 | + print "<textarea dojoType='dijit.form.SimpleTextarea' rows='4' |
|
180 | 180 | style='height : 100px; font-size : 12px; width : 98%' id='tags_str' |
181 | 181 | name='tags_str'>$tags_str</textarea> |
182 | 182 | <div class='autocomplete' id='tags_choices' |
183 | 183 | style='display:none'></div>"; |
184 | - print "</section>"; |
|
184 | + print "</section>"; |
|
185 | 185 | |
186 | - print "<footer>"; |
|
187 | - print "<button dojoType='dijit.form.Button' |
|
186 | + print "<footer>"; |
|
187 | + print "<button dojoType='dijit.form.Button' |
|
188 | 188 | type='submit' class='alt-primary' onclick=\"dijit.byId('editTagsDlg').execute()\">".__('Save')."</button> "; |
189 | - print "<button dojoType='dijit.form.Button' |
|
189 | + print "<button dojoType='dijit.form.Button' |
|
190 | 190 | onclick=\"dijit.byId('editTagsDlg').hide()\">".__('Cancel')."</button>"; |
191 | - print "</footer>"; |
|
191 | + print "</footer>"; |
|
192 | 192 | |
193 | - } |
|
193 | + } |
|
194 | 194 | |
195 | - public function setScore() { |
|
196 | - $ids = explode(",", clean($_REQUEST['id'])); |
|
197 | - $score = (int)clean($_REQUEST['score']); |
|
195 | + public function setScore() { |
|
196 | + $ids = explode(",", clean($_REQUEST['id'])); |
|
197 | + $score = (int)clean($_REQUEST['score']); |
|
198 | 198 | |
199 | - $ids_qmarks = arr_qmarks($ids); |
|
199 | + $ids_qmarks = arr_qmarks($ids); |
|
200 | 200 | |
201 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
201 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
202 | 202 | score = ? WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
203 | 203 | |
204 | - $sth->execute(array_merge([$score], $ids, [$_SESSION['uid']])); |
|
204 | + $sth->execute(array_merge([$score], $ids, [$_SESSION['uid']])); |
|
205 | 205 | |
206 | - print json_encode(["id" => $ids, "score" => (int)$score]); |
|
207 | - } |
|
206 | + print json_encode(["id" => $ids, "score" => (int)$score]); |
|
207 | + } |
|
208 | 208 | |
209 | - public function getScore() { |
|
210 | - $id = clean($_REQUEST['id']); |
|
209 | + public function getScore() { |
|
210 | + $id = clean($_REQUEST['id']); |
|
211 | 211 | |
212 | - $sth = $this->pdo->prepare("SELECT score FROM ttrss_user_entries WHERE ref_id = ? AND owner_uid = ?"); |
|
213 | - $sth->execute([$id, $_SESSION['uid']]); |
|
214 | - $row = $sth->fetch(); |
|
212 | + $sth = $this->pdo->prepare("SELECT score FROM ttrss_user_entries WHERE ref_id = ? AND owner_uid = ?"); |
|
213 | + $sth->execute([$id, $_SESSION['uid']]); |
|
214 | + $row = $sth->fetch(); |
|
215 | 215 | |
216 | - $score = $row['score']; |
|
216 | + $score = $row['score']; |
|
217 | 217 | |
218 | - print json_encode(["id" => $id, "score" => (int)$score]); |
|
219 | - } |
|
218 | + print json_encode(["id" => $id, "score" => (int)$score]); |
|
219 | + } |
|
220 | 220 | |
221 | 221 | |
222 | - public function setArticleTags() { |
|
222 | + public function setArticleTags() { |
|
223 | 223 | |
224 | - $id = clean($_REQUEST["id"]); |
|
224 | + $id = clean($_REQUEST["id"]); |
|
225 | 225 | |
226 | - $tags_str = clean($_REQUEST["tags_str"]); |
|
227 | - $tags = array_unique(trim_array(explode(",", $tags_str))); |
|
226 | + $tags_str = clean($_REQUEST["tags_str"]); |
|
227 | + $tags = array_unique(trim_array(explode(",", $tags_str))); |
|
228 | 228 | |
229 | - $this->pdo->beginTransaction(); |
|
229 | + $this->pdo->beginTransaction(); |
|
230 | 230 | |
231 | - $sth = $this->pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
|
231 | + $sth = $this->pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
|
232 | 232 | ref_id = ? AND owner_uid = ? LIMIT 1"); |
233 | - $sth->execute([$id, $_SESSION['uid']]); |
|
233 | + $sth->execute([$id, $_SESSION['uid']]); |
|
234 | 234 | |
235 | - if ($row = $sth->fetch()) { |
|
235 | + if ($row = $sth->fetch()) { |
|
236 | 236 | |
237 | - $tags_to_cache = array(); |
|
237 | + $tags_to_cache = array(); |
|
238 | 238 | |
239 | - $int_id = $row['int_id']; |
|
239 | + $int_id = $row['int_id']; |
|
240 | 240 | |
241 | - $sth = $this->pdo->prepare("DELETE FROM ttrss_tags WHERE |
|
241 | + $sth = $this->pdo->prepare("DELETE FROM ttrss_tags WHERE |
|
242 | 242 | post_int_id = ? AND owner_uid = ?"); |
243 | - $sth->execute([$int_id, $_SESSION['uid']]); |
|
243 | + $sth->execute([$int_id, $_SESSION['uid']]); |
|
244 | 244 | |
245 | - $tags = FeedItem_Common::normalize_categories($tags); |
|
245 | + $tags = FeedItem_Common::normalize_categories($tags); |
|
246 | 246 | |
247 | - foreach ($tags as $tag) { |
|
248 | - if ($tag != '') { |
|
249 | - $sth = $this->pdo->prepare("INSERT INTO ttrss_tags |
|
247 | + foreach ($tags as $tag) { |
|
248 | + if ($tag != '') { |
|
249 | + $sth = $this->pdo->prepare("INSERT INTO ttrss_tags |
|
250 | 250 | (post_int_id, owner_uid, tag_name) |
251 | 251 | VALUES (?, ?, ?)"); |
252 | 252 | |
253 | - $sth->execute([$int_id, $_SESSION['uid'], $tag]); |
|
254 | - } |
|
253 | + $sth->execute([$int_id, $_SESSION['uid'], $tag]); |
|
254 | + } |
|
255 | 255 | |
256 | - array_push($tags_to_cache, $tag); |
|
257 | - } |
|
256 | + array_push($tags_to_cache, $tag); |
|
257 | + } |
|
258 | 258 | |
259 | - /* update tag cache */ |
|
259 | + /* update tag cache */ |
|
260 | 260 | |
261 | - $tags_str = join(",", $tags_to_cache); |
|
261 | + $tags_str = join(",", $tags_to_cache); |
|
262 | 262 | |
263 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries |
|
263 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries |
|
264 | 264 | SET tag_cache = ? WHERE ref_id = ? AND owner_uid = ?"); |
265 | - $sth->execute([$tags_str, $id, $_SESSION['uid']]); |
|
266 | - } |
|
265 | + $sth->execute([$tags_str, $id, $_SESSION['uid']]); |
|
266 | + } |
|
267 | 267 | |
268 | - $this->pdo->commit(); |
|
268 | + $this->pdo->commit(); |
|
269 | 269 | |
270 | - $tags = Article::get_article_tags($id); |
|
271 | - $tags_str = $this->format_tags_string($tags); |
|
272 | - $tags_str_full = join(", ", $tags); |
|
270 | + $tags = Article::get_article_tags($id); |
|
271 | + $tags_str = $this->format_tags_string($tags); |
|
272 | + $tags_str_full = join(", ", $tags); |
|
273 | 273 | |
274 | - if (!$tags_str_full) $tags_str_full = __("no tags"); |
|
274 | + if (!$tags_str_full) $tags_str_full = __("no tags"); |
|
275 | 275 | |
276 | - print json_encode([ |
|
277 | - "id" => (int) $id, |
|
278 | - "content" => $tags_str, |
|
279 | - "content_full" => $tags_str_full |
|
280 | - ]); |
|
281 | - } |
|
276 | + print json_encode([ |
|
277 | + "id" => (int) $id, |
|
278 | + "content" => $tags_str, |
|
279 | + "content_full" => $tags_str_full |
|
280 | + ]); |
|
281 | + } |
|
282 | 282 | |
283 | 283 | |
284 | - public function completeTags() { |
|
285 | - $search = clean($_REQUEST["search"]); |
|
284 | + public function completeTags() { |
|
285 | + $search = clean($_REQUEST["search"]); |
|
286 | 286 | |
287 | - $sth = $this->pdo->prepare("SELECT DISTINCT tag_name FROM ttrss_tags |
|
287 | + $sth = $this->pdo->prepare("SELECT DISTINCT tag_name FROM ttrss_tags |
|
288 | 288 | WHERE owner_uid = ? AND |
289 | 289 | tag_name LIKE ? ORDER BY tag_name |
290 | 290 | LIMIT 10"); |
291 | 291 | |
292 | - $sth->execute([$_SESSION['uid'], "$search%"]); |
|
292 | + $sth->execute([$_SESSION['uid'], "$search%"]); |
|
293 | 293 | |
294 | - print "<ul>"; |
|
295 | - while ($line = $sth->fetch()) { |
|
296 | - print "<li>" . $line["tag_name"] . "</li>"; |
|
297 | - } |
|
298 | - print "</ul>"; |
|
299 | - } |
|
294 | + print "<ul>"; |
|
295 | + while ($line = $sth->fetch()) { |
|
296 | + print "<li>" . $line["tag_name"] . "</li>"; |
|
297 | + } |
|
298 | + print "</ul>"; |
|
299 | + } |
|
300 | 300 | |
301 | - public function assigntolabel() { |
|
302 | - return $this->labelops(true); |
|
303 | - } |
|
301 | + public function assigntolabel() { |
|
302 | + return $this->labelops(true); |
|
303 | + } |
|
304 | 304 | |
305 | - public function removefromlabel() { |
|
306 | - return $this->labelops(false); |
|
307 | - } |
|
305 | + public function removefromlabel() { |
|
306 | + return $this->labelops(false); |
|
307 | + } |
|
308 | 308 | |
309 | - private function labelops($assign) { |
|
310 | - $reply = array(); |
|
309 | + private function labelops($assign) { |
|
310 | + $reply = array(); |
|
311 | 311 | |
312 | - $ids = explode(",", clean($_REQUEST["ids"])); |
|
313 | - $label_id = clean($_REQUEST["lid"]); |
|
312 | + $ids = explode(",", clean($_REQUEST["ids"])); |
|
313 | + $label_id = clean($_REQUEST["lid"]); |
|
314 | 314 | |
315 | - $label = Labels::find_caption($label_id, $_SESSION["uid"]); |
|
315 | + $label = Labels::find_caption($label_id, $_SESSION["uid"]); |
|
316 | 316 | |
317 | - $reply["info-for-headlines"] = array(); |
|
317 | + $reply["info-for-headlines"] = array(); |
|
318 | 318 | |
319 | - if ($label) { |
|
319 | + if ($label) { |
|
320 | 320 | |
321 | - foreach ($ids as $id) { |
|
321 | + foreach ($ids as $id) { |
|
322 | 322 | |
323 | - if ($assign) |
|
324 | - Labels::add_article($id, $label, $_SESSION["uid"]); |
|
325 | - else |
|
326 | - Labels::remove_article($id, $label, $_SESSION["uid"]); |
|
323 | + if ($assign) |
|
324 | + Labels::add_article($id, $label, $_SESSION["uid"]); |
|
325 | + else |
|
326 | + Labels::remove_article($id, $label, $_SESSION["uid"]); |
|
327 | 327 | |
328 | - $labels = $this->get_article_labels($id, $_SESSION["uid"]); |
|
328 | + $labels = $this->get_article_labels($id, $_SESSION["uid"]); |
|
329 | 329 | |
330 | - array_push($reply["info-for-headlines"], |
|
331 | - array("id" => $id, "labels" => $this->format_article_labels($labels))); |
|
330 | + array_push($reply["info-for-headlines"], |
|
331 | + array("id" => $id, "labels" => $this->format_article_labels($labels))); |
|
332 | 332 | |
333 | - } |
|
334 | - } |
|
333 | + } |
|
334 | + } |
|
335 | 335 | |
336 | - $reply["message"] = "UPDATE_COUNTERS"; |
|
336 | + $reply["message"] = "UPDATE_COUNTERS"; |
|
337 | 337 | |
338 | - print json_encode($reply); |
|
339 | - } |
|
338 | + print json_encode($reply); |
|
339 | + } |
|
340 | 340 | |
341 | - public function getArticleFeed($id) { |
|
342 | - $sth = $this->pdo->prepare("SELECT feed_id FROM ttrss_user_entries |
|
341 | + public function getArticleFeed($id) { |
|
342 | + $sth = $this->pdo->prepare("SELECT feed_id FROM ttrss_user_entries |
|
343 | 343 | WHERE ref_id = ? AND owner_uid = ?"); |
344 | - $sth->execute([$id, $_SESSION['uid']]); |
|
344 | + $sth->execute([$id, $_SESSION['uid']]); |
|
345 | 345 | |
346 | - if ($row = $sth->fetch()) { |
|
347 | - return $row["feed_id"]; |
|
348 | - } else { |
|
349 | - return 0; |
|
350 | - } |
|
351 | - } |
|
346 | + if ($row = $sth->fetch()) { |
|
347 | + return $row["feed_id"]; |
|
348 | + } else { |
|
349 | + return 0; |
|
350 | + } |
|
351 | + } |
|
352 | 352 | |
353 | - public static function format_article_enclosures($id, $always_display_enclosures, |
|
354 | - $article_content, $hide_images = false) { |
|
353 | + public static function format_article_enclosures($id, $always_display_enclosures, |
|
354 | + $article_content, $hide_images = false) { |
|
355 | 355 | |
356 | - $result = Article::get_article_enclosures($id); |
|
357 | - $rv = ''; |
|
356 | + $result = Article::get_article_enclosures($id); |
|
357 | + $rv = ''; |
|
358 | 358 | |
359 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ENCLOSURES) as $plugin) { |
|
360 | - $retval = $plugin->hook_format_enclosures($rv, $result, $id, $always_display_enclosures, $article_content, $hide_images); |
|
361 | - if (is_array($retval)) { |
|
362 | - $rv = $retval[0]; |
|
363 | - $result = $retval[1]; |
|
364 | - } else { |
|
365 | - $rv = $retval; |
|
366 | - } |
|
367 | - } |
|
368 | - unset($retval); // Unset to prevent breaking render if there are no HOOK_RENDER_ENCLOSURE hooks below. |
|
359 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ENCLOSURES) as $plugin) { |
|
360 | + $retval = $plugin->hook_format_enclosures($rv, $result, $id, $always_display_enclosures, $article_content, $hide_images); |
|
361 | + if (is_array($retval)) { |
|
362 | + $rv = $retval[0]; |
|
363 | + $result = $retval[1]; |
|
364 | + } else { |
|
365 | + $rv = $retval; |
|
366 | + } |
|
367 | + } |
|
368 | + unset($retval); // Unset to prevent breaking render if there are no HOOK_RENDER_ENCLOSURE hooks below. |
|
369 | 369 | |
370 | - if ($rv === '' && !empty($result)) { |
|
371 | - $entries_html = array(); |
|
372 | - $entries = array(); |
|
373 | - $entries_inline = array(); |
|
370 | + if ($rv === '' && !empty($result)) { |
|
371 | + $entries_html = array(); |
|
372 | + $entries = array(); |
|
373 | + $entries_inline = array(); |
|
374 | 374 | |
375 | - foreach ($result as $line) { |
|
375 | + foreach ($result as $line) { |
|
376 | 376 | |
377 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ENCLOSURE_ENTRY) as $plugin) { |
|
378 | - $line = $plugin->hook_enclosure_entry($line, $id); |
|
379 | - } |
|
377 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ENCLOSURE_ENTRY) as $plugin) { |
|
378 | + $line = $plugin->hook_enclosure_entry($line, $id); |
|
379 | + } |
|
380 | 380 | |
381 | - $url = $line["content_url"]; |
|
382 | - $ctype = $line["content_type"]; |
|
383 | - $title = $line["title"]; |
|
384 | - $width = $line["width"]; |
|
385 | - $height = $line["height"]; |
|
381 | + $url = $line["content_url"]; |
|
382 | + $ctype = $line["content_type"]; |
|
383 | + $title = $line["title"]; |
|
384 | + $width = $line["width"]; |
|
385 | + $height = $line["height"]; |
|
386 | 386 | |
387 | - if (!$ctype) $ctype = __("unknown type"); |
|
387 | + if (!$ctype) $ctype = __("unknown type"); |
|
388 | 388 | |
389 | - //$filename = substr($url, strrpos($url, "/")+1); |
|
390 | - $filename = basename($url); |
|
389 | + //$filename = substr($url, strrpos($url, "/")+1); |
|
390 | + $filename = basename($url); |
|
391 | 391 | |
392 | - $player = format_inline_player($url, $ctype); |
|
392 | + $player = format_inline_player($url, $ctype); |
|
393 | 393 | |
394 | - if ($player) array_push($entries_inline, $player); |
|
394 | + if ($player) array_push($entries_inline, $player); |
|
395 | 395 | |
396 | 396 | # $entry .= " <a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\" rel=\"noopener noreferrer\">" . |
397 | 397 | # $filename . " (" . $ctype . ")" . "</a>"; |
398 | 398 | |
399 | - $entry = "<div onclick=\"popupOpenUrl('".htmlspecialchars($url)."')\" |
|
399 | + $entry = "<div onclick=\"popupOpenUrl('".htmlspecialchars($url)."')\" |
|
400 | 400 | dojoType=\"dijit.MenuItem\">$filename ($ctype)</div>"; |
401 | 401 | |
402 | - array_push($entries_html, $entry); |
|
402 | + array_push($entries_html, $entry); |
|
403 | 403 | |
404 | - $entry = array(); |
|
404 | + $entry = array(); |
|
405 | 405 | |
406 | - $entry["type"] = $ctype; |
|
407 | - $entry["filename"] = $filename; |
|
408 | - $entry["url"] = $url; |
|
409 | - $entry["title"] = $title; |
|
410 | - $entry["width"] = $width; |
|
411 | - $entry["height"] = $height; |
|
406 | + $entry["type"] = $ctype; |
|
407 | + $entry["filename"] = $filename; |
|
408 | + $entry["url"] = $url; |
|
409 | + $entry["title"] = $title; |
|
410 | + $entry["width"] = $width; |
|
411 | + $entry["height"] = $height; |
|
412 | 412 | |
413 | - array_push($entries, $entry); |
|
414 | - } |
|
413 | + array_push($entries, $entry); |
|
414 | + } |
|
415 | 415 | |
416 | - if ($_SESSION['uid'] && !get_pref("STRIP_IMAGES") && !$_SESSION["bw_limit"]) { |
|
417 | - if ($always_display_enclosures || |
|
418 | - !preg_match("/<img/i", $article_content)) { |
|
416 | + if ($_SESSION['uid'] && !get_pref("STRIP_IMAGES") && !$_SESSION["bw_limit"]) { |
|
417 | + if ($always_display_enclosures || |
|
418 | + !preg_match("/<img/i", $article_content)) { |
|
419 | 419 | |
420 | - foreach ($entries as $entry) { |
|
420 | + foreach ($entries as $entry) { |
|
421 | 421 | |
422 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ENCLOSURE) as $plugin) |
|
423 | - $retval = $plugin->hook_render_enclosure($entry, $hide_images); |
|
422 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ENCLOSURE) as $plugin) |
|
423 | + $retval = $plugin->hook_render_enclosure($entry, $hide_images); |
|
424 | 424 | |
425 | 425 | |
426 | - if ($retval) { |
|
427 | - $rv .= $retval; |
|
428 | - } else { |
|
426 | + if ($retval) { |
|
427 | + $rv .= $retval; |
|
428 | + } else { |
|
429 | 429 | |
430 | - if (preg_match("/image/", $entry["type"])) { |
|
430 | + if (preg_match("/image/", $entry["type"])) { |
|
431 | 431 | |
432 | - if (!$hide_images) { |
|
433 | - $encsize = ''; |
|
434 | - if ($entry['height'] > 0) |
|
435 | - $encsize .= ' height="' . intval($entry['height']) . '"'; |
|
436 | - if ($entry['width'] > 0) |
|
437 | - $encsize .= ' width="' . intval($entry['width']) . '"'; |
|
438 | - $rv .= "<p><img |
|
432 | + if (!$hide_images) { |
|
433 | + $encsize = ''; |
|
434 | + if ($entry['height'] > 0) |
|
435 | + $encsize .= ' height="' . intval($entry['height']) . '"'; |
|
436 | + if ($entry['width'] > 0) |
|
437 | + $encsize .= ' width="' . intval($entry['width']) . '"'; |
|
438 | + $rv .= "<p><img |
|
439 | 439 | alt=\"".htmlspecialchars($entry["filename"])."\" |
440 | 440 | src=\"" .htmlspecialchars($entry["url"]) . "\" |
441 | 441 | " . $encsize . " /></p>"; |
442 | - } else { |
|
443 | - $rv .= "<p><a target=\"_blank\" rel=\"noopener noreferrer\" |
|
442 | + } else { |
|
443 | + $rv .= "<p><a target=\"_blank\" rel=\"noopener noreferrer\" |
|
444 | 444 | href=\"".htmlspecialchars($entry["url"])."\" |
445 | 445 | >" .htmlspecialchars($entry["url"]) . "</a></p>"; |
446 | - } |
|
447 | - |
|
448 | - if ($entry['title']) { |
|
449 | - $rv.= "<div class=\"enclosure_title\">${entry['title']}</div>"; |
|
450 | - } |
|
451 | - } |
|
452 | - } |
|
453 | - } |
|
454 | - } |
|
455 | - } |
|
456 | - |
|
457 | - if (count($entries_inline) > 0) { |
|
458 | - //$rv .= "<hr clear='both'/>"; |
|
459 | - foreach ($entries_inline as $entry) { $rv .= $entry; }; |
|
460 | - $rv .= "<br clear='both'/>"; |
|
461 | - } |
|
462 | - |
|
463 | - $rv .= "<div class=\"attachments\" dojoType=\"fox.form.DropDownButton\">". |
|
464 | - "<span>" . __('Attachments')."</span>"; |
|
465 | - |
|
466 | - $rv .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
467 | - |
|
468 | - foreach ($entries as $entry) { |
|
469 | - if ($entry["title"]) |
|
470 | - $title = " — " . truncate_string($entry["title"], 30); |
|
471 | - else |
|
472 | - $title = ""; |
|
473 | - |
|
474 | - if ($entry["filename"]) |
|
475 | - $filename = truncate_middle(htmlspecialchars($entry["filename"]), 60); |
|
476 | - else |
|
477 | - $filename = ""; |
|
478 | - |
|
479 | - $rv .= "<div onclick='popupOpenUrl(\"".htmlspecialchars($entry["url"])."\")' |
|
446 | + } |
|
447 | + |
|
448 | + if ($entry['title']) { |
|
449 | + $rv.= "<div class=\"enclosure_title\">${entry['title']}</div>"; |
|
450 | + } |
|
451 | + } |
|
452 | + } |
|
453 | + } |
|
454 | + } |
|
455 | + } |
|
456 | + |
|
457 | + if (count($entries_inline) > 0) { |
|
458 | + //$rv .= "<hr clear='both'/>"; |
|
459 | + foreach ($entries_inline as $entry) { $rv .= $entry; }; |
|
460 | + $rv .= "<br clear='both'/>"; |
|
461 | + } |
|
462 | + |
|
463 | + $rv .= "<div class=\"attachments\" dojoType=\"fox.form.DropDownButton\">". |
|
464 | + "<span>" . __('Attachments')."</span>"; |
|
465 | + |
|
466 | + $rv .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; |
|
467 | + |
|
468 | + foreach ($entries as $entry) { |
|
469 | + if ($entry["title"]) |
|
470 | + $title = " — " . truncate_string($entry["title"], 30); |
|
471 | + else |
|
472 | + $title = ""; |
|
473 | + |
|
474 | + if ($entry["filename"]) |
|
475 | + $filename = truncate_middle(htmlspecialchars($entry["filename"]), 60); |
|
476 | + else |
|
477 | + $filename = ""; |
|
478 | + |
|
479 | + $rv .= "<div onclick='popupOpenUrl(\"".htmlspecialchars($entry["url"])."\")' |
|
480 | 480 | dojoType=\"dijit.MenuItem\">".$filename . $title."</div>"; |
481 | 481 | |
482 | - }; |
|
482 | + }; |
|
483 | 483 | |
484 | - $rv .= "</div>"; |
|
485 | - $rv .= "</div>"; |
|
486 | - } |
|
484 | + $rv .= "</div>"; |
|
485 | + $rv .= "</div>"; |
|
486 | + } |
|
487 | 487 | |
488 | - return $rv; |
|
489 | - } |
|
488 | + return $rv; |
|
489 | + } |
|
490 | 490 | |
491 | - public static function get_article_tags($id, $owner_uid = 0, $tag_cache = false) { |
|
491 | + public static function get_article_tags($id, $owner_uid = 0, $tag_cache = false) { |
|
492 | 492 | |
493 | - $a_id = $id; |
|
493 | + $a_id = $id; |
|
494 | 494 | |
495 | - if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
|
495 | + if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
|
496 | 496 | |
497 | - $pdo = Db::pdo(); |
|
497 | + $pdo = Db::pdo(); |
|
498 | 498 | |
499 | - $sth = $pdo->prepare("SELECT DISTINCT tag_name, |
|
499 | + $sth = $pdo->prepare("SELECT DISTINCT tag_name, |
|
500 | 500 | owner_uid as owner FROM ttrss_tags |
501 | 501 | WHERE post_int_id = (SELECT int_id FROM ttrss_user_entries WHERE |
502 | 502 | ref_id = ? AND owner_uid = ? LIMIT 1) ORDER BY tag_name"); |
503 | 503 | |
504 | - $tags = array(); |
|
504 | + $tags = array(); |
|
505 | 505 | |
506 | - /* check cache first */ |
|
506 | + /* check cache first */ |
|
507 | 507 | |
508 | - if ($tag_cache === false) { |
|
509 | - $csth = $pdo->prepare("SELECT tag_cache FROM ttrss_user_entries |
|
508 | + if ($tag_cache === false) { |
|
509 | + $csth = $pdo->prepare("SELECT tag_cache FROM ttrss_user_entries |
|
510 | 510 | WHERE ref_id = ? AND owner_uid = ?"); |
511 | - $csth->execute([$id, $owner_uid]); |
|
511 | + $csth->execute([$id, $owner_uid]); |
|
512 | 512 | |
513 | - if ($row = $csth->fetch()) $tag_cache = $row["tag_cache"]; |
|
514 | - } |
|
513 | + if ($row = $csth->fetch()) $tag_cache = $row["tag_cache"]; |
|
514 | + } |
|
515 | 515 | |
516 | - if ($tag_cache) { |
|
517 | - $tags = explode(",", $tag_cache); |
|
518 | - } else { |
|
516 | + if ($tag_cache) { |
|
517 | + $tags = explode(",", $tag_cache); |
|
518 | + } else { |
|
519 | 519 | |
520 | - /* do it the hard way */ |
|
520 | + /* do it the hard way */ |
|
521 | 521 | |
522 | - $sth->execute([$a_id, $owner_uid]); |
|
522 | + $sth->execute([$a_id, $owner_uid]); |
|
523 | 523 | |
524 | - while ($tmp_line = $sth->fetch()) { |
|
525 | - array_push($tags, $tmp_line["tag_name"]); |
|
526 | - } |
|
524 | + while ($tmp_line = $sth->fetch()) { |
|
525 | + array_push($tags, $tmp_line["tag_name"]); |
|
526 | + } |
|
527 | 527 | |
528 | - /* update the cache */ |
|
528 | + /* update the cache */ |
|
529 | 529 | |
530 | - $tags_str = join(",", $tags); |
|
530 | + $tags_str = join(",", $tags); |
|
531 | 531 | |
532 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
532 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries |
|
533 | 533 | SET tag_cache = ? WHERE ref_id = ? |
534 | 534 | AND owner_uid = ?"); |
535 | - $sth->execute([$tags_str, $id, $owner_uid]); |
|
536 | - } |
|
535 | + $sth->execute([$tags_str, $id, $owner_uid]); |
|
536 | + } |
|
537 | 537 | |
538 | - return $tags; |
|
539 | - } |
|
538 | + return $tags; |
|
539 | + } |
|
540 | 540 | |
541 | - public static function format_tags_string($tags) { |
|
542 | - if (!is_array($tags) || count($tags) == 0) { |
|
543 | - return __("no tags"); |
|
544 | - } else { |
|
545 | - $maxtags = min(5, count($tags)); |
|
546 | - $tags_str = ""; |
|
541 | + public static function format_tags_string($tags) { |
|
542 | + if (!is_array($tags) || count($tags) == 0) { |
|
543 | + return __("no tags"); |
|
544 | + } else { |
|
545 | + $maxtags = min(5, count($tags)); |
|
546 | + $tags_str = ""; |
|
547 | 547 | |
548 | - for ($i = 0; $i < $maxtags; $i++) { |
|
549 | - $tags_str .= "<a class=\"tag\" href=\"#\" onclick=\"Feeds.open({feed:'".$tags[$i]."'})\">" . $tags[$i] . "</a>, "; |
|
550 | - } |
|
548 | + for ($i = 0; $i < $maxtags; $i++) { |
|
549 | + $tags_str .= "<a class=\"tag\" href=\"#\" onclick=\"Feeds.open({feed:'".$tags[$i]."'})\">" . $tags[$i] . "</a>, "; |
|
550 | + } |
|
551 | 551 | |
552 | - $tags_str = mb_substr($tags_str, 0, mb_strlen($tags_str)-2); |
|
552 | + $tags_str = mb_substr($tags_str, 0, mb_strlen($tags_str)-2); |
|
553 | 553 | |
554 | - if (count($tags) > $maxtags) |
|
555 | - $tags_str .= ", …"; |
|
554 | + if (count($tags) > $maxtags) |
|
555 | + $tags_str .= ", …"; |
|
556 | 556 | |
557 | - return $tags_str; |
|
558 | - } |
|
559 | - } |
|
557 | + return $tags_str; |
|
558 | + } |
|
559 | + } |
|
560 | 560 | |
561 | - public static function format_article_labels($labels) { |
|
561 | + public static function format_article_labels($labels) { |
|
562 | 562 | |
563 | - if (!is_array($labels)) return ''; |
|
563 | + if (!is_array($labels)) return ''; |
|
564 | 564 | |
565 | - $labels_str = ""; |
|
565 | + $labels_str = ""; |
|
566 | 566 | |
567 | - foreach ($labels as $l) { |
|
568 | - $labels_str .= sprintf("<div class='label' |
|
567 | + foreach ($labels as $l) { |
|
568 | + $labels_str .= sprintf("<div class='label' |
|
569 | 569 | style='color : %s; background-color : %s'>%s</div>", |
570 | - $l[2], $l[3], $l[1]); |
|
571 | - } |
|
570 | + $l[2], $l[3], $l[1]); |
|
571 | + } |
|
572 | 572 | |
573 | - return $labels_str; |
|
573 | + return $labels_str; |
|
574 | 574 | |
575 | - } |
|
575 | + } |
|
576 | 576 | |
577 | - public static function format_article_note($id, $note, $allow_edit = true) { |
|
577 | + public static function format_article_note($id, $note, $allow_edit = true) { |
|
578 | 578 | |
579 | - if ($allow_edit) { |
|
580 | - $onclick = "onclick='Plugins.Note.edit($id)'"; |
|
581 | - $note_class = 'editable'; |
|
582 | - } else { |
|
583 | - $onclick = ''; |
|
584 | - $note_class = ''; |
|
585 | - } |
|
579 | + if ($allow_edit) { |
|
580 | + $onclick = "onclick='Plugins.Note.edit($id)'"; |
|
581 | + $note_class = 'editable'; |
|
582 | + } else { |
|
583 | + $onclick = ''; |
|
584 | + $note_class = ''; |
|
585 | + } |
|
586 | 586 | |
587 | - return "<div class='article-note $note_class'> |
|
587 | + return "<div class='article-note $note_class'> |
|
588 | 588 | <i class='material-icons'>note</i> |
589 | 589 | <div $onclick class='body'>$note</div> |
590 | 590 | </div>"; |
591 | - } |
|
591 | + } |
|
592 | 592 | |
593 | - public static function get_article_enclosures($id) { |
|
593 | + public static function get_article_enclosures($id) { |
|
594 | 594 | |
595 | - $pdo = Db::pdo(); |
|
595 | + $pdo = Db::pdo(); |
|
596 | 596 | |
597 | - $sth = $pdo->prepare("SELECT * FROM ttrss_enclosures |
|
597 | + $sth = $pdo->prepare("SELECT * FROM ttrss_enclosures |
|
598 | 598 | WHERE post_id = ? AND content_url != ''"); |
599 | - $sth->execute([$id]); |
|
599 | + $sth->execute([$id]); |
|
600 | 600 | |
601 | - $rv = array(); |
|
601 | + $rv = array(); |
|
602 | 602 | |
603 | - $cache = new DiskCache("images"); |
|
603 | + $cache = new DiskCache("images"); |
|
604 | 604 | |
605 | - while ($line = $sth->fetch()) { |
|
605 | + while ($line = $sth->fetch()) { |
|
606 | 606 | |
607 | - if ($cache->exists(sha1($line["content_url"]))) { |
|
608 | - $line["content_url"] = $cache->getUrl(sha1($line["content_url"])); |
|
609 | - } |
|
607 | + if ($cache->exists(sha1($line["content_url"]))) { |
|
608 | + $line["content_url"] = $cache->getUrl(sha1($line["content_url"])); |
|
609 | + } |
|
610 | 610 | |
611 | - array_push($rv, $line); |
|
612 | - } |
|
611 | + array_push($rv, $line); |
|
612 | + } |
|
613 | 613 | |
614 | - return $rv; |
|
615 | - } |
|
614 | + return $rv; |
|
615 | + } |
|
616 | 616 | |
617 | - public static function purge_orphans() { |
|
617 | + public static function purge_orphans() { |
|
618 | 618 | |
619 | 619 | // purge orphaned posts in main content table |
620 | 620 | |
@@ -633,169 +633,169 @@ discard block |
||
633 | 633 | } |
634 | 634 | } |
635 | 635 | |
636 | - public static function catchupArticlesById($ids, $cmode, $owner_uid = false) { |
|
636 | + public static function catchupArticlesById($ids, $cmode, $owner_uid = false) { |
|
637 | 637 | |
638 | - if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
|
638 | + if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
|
639 | 639 | |
640 | - $pdo = Db::pdo(); |
|
640 | + $pdo = Db::pdo(); |
|
641 | 641 | |
642 | - $ids_qmarks = arr_qmarks($ids); |
|
642 | + $ids_qmarks = arr_qmarks($ids); |
|
643 | 643 | |
644 | - if ($cmode == 1) { |
|
645 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
644 | + if ($cmode == 1) { |
|
645 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
646 | 646 | unread = true |
647 | 647 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
648 | - } else if ($cmode == 2) { |
|
649 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
648 | + } else if ($cmode == 2) { |
|
649 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
650 | 650 | unread = NOT unread,last_read = NOW() |
651 | 651 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
652 | - } else { |
|
653 | - $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
652 | + } else { |
|
653 | + $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
|
654 | 654 | unread = false,last_read = NOW() |
655 | 655 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
656 | - } |
|
656 | + } |
|
657 | 657 | |
658 | - $sth->execute(array_merge($ids, [$owner_uid])); |
|
658 | + $sth->execute(array_merge($ids, [$owner_uid])); |
|
659 | 659 | |
660 | - /* update ccache */ |
|
660 | + /* update ccache */ |
|
661 | 661 | |
662 | - $sth = $pdo->prepare("SELECT DISTINCT feed_id FROM ttrss_user_entries |
|
662 | + $sth = $pdo->prepare("SELECT DISTINCT feed_id FROM ttrss_user_entries |
|
663 | 663 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
664 | - $sth->execute(array_merge($ids, [$owner_uid])); |
|
664 | + $sth->execute(array_merge($ids, [$owner_uid])); |
|
665 | 665 | |
666 | - while ($line = $sth->fetch()) { |
|
667 | - CCache::update($line["feed_id"], $owner_uid); |
|
668 | - } |
|
669 | - } |
|
666 | + while ($line = $sth->fetch()) { |
|
667 | + CCache::update($line["feed_id"], $owner_uid); |
|
668 | + } |
|
669 | + } |
|
670 | 670 | |
671 | - public static function getLastArticleId() { |
|
672 | - $pdo = DB::pdo(); |
|
671 | + public static function getLastArticleId() { |
|
672 | + $pdo = DB::pdo(); |
|
673 | 673 | |
674 | - $sth = $pdo->prepare("SELECT ref_id AS id FROM ttrss_user_entries |
|
674 | + $sth = $pdo->prepare("SELECT ref_id AS id FROM ttrss_user_entries |
|
675 | 675 | WHERE owner_uid = ? ORDER BY ref_id DESC LIMIT 1"); |
676 | - $sth->execute([$_SESSION['uid']]); |
|
676 | + $sth->execute([$_SESSION['uid']]); |
|
677 | 677 | |
678 | - if ($row = $sth->fetch()) { |
|
679 | - return $row['id']; |
|
680 | - } else { |
|
681 | - return -1; |
|
682 | - } |
|
683 | - } |
|
678 | + if ($row = $sth->fetch()) { |
|
679 | + return $row['id']; |
|
680 | + } else { |
|
681 | + return -1; |
|
682 | + } |
|
683 | + } |
|
684 | 684 | |
685 | - public static function get_article_labels($id, $owner_uid = false) { |
|
686 | - $rv = array(); |
|
685 | + public static function get_article_labels($id, $owner_uid = false) { |
|
686 | + $rv = array(); |
|
687 | 687 | |
688 | - if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
|
688 | + if (!$owner_uid) $owner_uid = $_SESSION["uid"]; |
|
689 | 689 | |
690 | - $pdo = Db::pdo(); |
|
690 | + $pdo = Db::pdo(); |
|
691 | 691 | |
692 | - $sth = $pdo->prepare("SELECT label_cache FROM |
|
692 | + $sth = $pdo->prepare("SELECT label_cache FROM |
|
693 | 693 | ttrss_user_entries WHERE ref_id = ? AND owner_uid = ?"); |
694 | - $sth->execute([$id, $owner_uid]); |
|
694 | + $sth->execute([$id, $owner_uid]); |
|
695 | 695 | |
696 | - if ($row = $sth->fetch()) { |
|
697 | - $label_cache = $row["label_cache"]; |
|
696 | + if ($row = $sth->fetch()) { |
|
697 | + $label_cache = $row["label_cache"]; |
|
698 | 698 | |
699 | - if ($label_cache) { |
|
700 | - $tmp = json_decode($label_cache, true); |
|
699 | + if ($label_cache) { |
|
700 | + $tmp = json_decode($label_cache, true); |
|
701 | 701 | |
702 | - if (!$tmp || $tmp["no-labels"] == 1) |
|
703 | - return $rv; |
|
704 | - else |
|
705 | - return $tmp; |
|
706 | - } |
|
707 | - } |
|
702 | + if (!$tmp || $tmp["no-labels"] == 1) |
|
703 | + return $rv; |
|
704 | + else |
|
705 | + return $tmp; |
|
706 | + } |
|
707 | + } |
|
708 | 708 | |
709 | - $sth = $pdo->prepare("SELECT DISTINCT label_id,caption,fg_color,bg_color |
|
709 | + $sth = $pdo->prepare("SELECT DISTINCT label_id,caption,fg_color,bg_color |
|
710 | 710 | FROM ttrss_labels2, ttrss_user_labels2 |
711 | 711 | WHERE id = label_id |
712 | 712 | AND article_id = ? |
713 | 713 | AND owner_uid = ? |
714 | 714 | ORDER BY caption"); |
715 | - $sth->execute([$id, $owner_uid]); |
|
716 | - |
|
717 | - while ($line = $sth->fetch()) { |
|
718 | - $rk = array(Labels::label_to_feed_id($line["label_id"]), |
|
719 | - $line["caption"], $line["fg_color"], |
|
720 | - $line["bg_color"]); |
|
721 | - array_push($rv, $rk); |
|
722 | - } |
|
723 | - |
|
724 | - if (count($rv) > 0) |
|
725 | - Labels::update_cache($owner_uid, $id, $rv); |
|
726 | - else |
|
727 | - Labels::update_cache($owner_uid, $id, array("no-labels" => 1)); |
|
728 | - |
|
729 | - return $rv; |
|
730 | - } |
|
731 | - |
|
732 | - public static function get_article_image($enclosures, $content, $site_url) { |
|
733 | - |
|
734 | - $article_image = ""; |
|
735 | - $article_stream = ""; |
|
736 | - |
|
737 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_IMAGE) as $p) { |
|
738 | - list ($article_image, $article_stream, $content) = $p->hook_article_image($enclosures, $content, $site_url); |
|
739 | - } |
|
740 | - |
|
741 | - if (!$article_image && !$article_stream) { |
|
742 | - $tmpdoc = new DOMDocument(); |
|
743 | - |
|
744 | - if (@$tmpdoc->loadHTML('<?xml encoding="UTF-8">' . mb_substr($content, 0, 131070))) { |
|
745 | - $tmpxpath = new DOMXPath($tmpdoc); |
|
746 | - $elems = $tmpxpath->query('(//img[@src]|//video[@poster]|//iframe[contains(@src , "youtube.com/embed/")])'); |
|
747 | - |
|
748 | - foreach ($elems as $e) { |
|
749 | - if ($e->nodeName == "iframe") { |
|
750 | - $matches = []; |
|
751 | - if (preg_match("/\/embed\/([\w-]+)/", $e->getAttribute("src"), $matches)) { |
|
752 | - $article_image = "https://img.youtube.com/vi/" . $matches[1] . "/hqdefault.jpg"; |
|
753 | - $article_stream = "https://youtu.be/" . $matches[1]; |
|
754 | - break; |
|
755 | - } |
|
756 | - } else if ($e->nodeName == "video") { |
|
757 | - $article_image = $e->getAttribute("poster"); |
|
758 | - |
|
759 | - $src = $tmpxpath->query("//source[@src]", $e)->item(0); |
|
760 | - |
|
761 | - if ($src) { |
|
762 | - $article_stream = $src->getAttribute("src"); |
|
763 | - } |
|
764 | - |
|
765 | - break; |
|
766 | - } else if ($e->nodeName == 'img') { |
|
767 | - if (mb_strpos($e->getAttribute("src"), "data:") !== 0) { |
|
768 | - $article_image = $e->getAttribute("src"); |
|
769 | - } |
|
770 | - break; |
|
771 | - } |
|
772 | - } |
|
773 | - } |
|
774 | - |
|
775 | - if (!$article_image) |
|
776 | - foreach ($enclosures as $enc) { |
|
777 | - if (strpos($enc["content_type"], "image/") !== FALSE) { |
|
778 | - $article_image = $enc["content_url"]; |
|
779 | - break; |
|
780 | - } |
|
781 | - } |
|
782 | - |
|
783 | - if ($article_image) |
|
784 | - $article_image = rewrite_relative_url($site_url, $article_image); |
|
785 | - |
|
786 | - if ($article_stream) |
|
787 | - $article_stream = rewrite_relative_url($site_url, $article_stream); |
|
788 | - } |
|
789 | - |
|
790 | - $cache = new DiskCache("images"); |
|
791 | - |
|
792 | - if ($article_image && $cache->exists(sha1($article_image))) |
|
793 | - $article_image = $cache->getUrl(sha1($article_image)); |
|
794 | - |
|
795 | - if ($article_stream && $cache->exists(sha1($article_stream))) |
|
796 | - $article_stream = $cache->getUrl(sha1($article_stream)); |
|
797 | - |
|
798 | - return [$article_image, $article_stream]; |
|
799 | - } |
|
715 | + $sth->execute([$id, $owner_uid]); |
|
716 | + |
|
717 | + while ($line = $sth->fetch()) { |
|
718 | + $rk = array(Labels::label_to_feed_id($line["label_id"]), |
|
719 | + $line["caption"], $line["fg_color"], |
|
720 | + $line["bg_color"]); |
|
721 | + array_push($rv, $rk); |
|
722 | + } |
|
723 | + |
|
724 | + if (count($rv) > 0) |
|
725 | + Labels::update_cache($owner_uid, $id, $rv); |
|
726 | + else |
|
727 | + Labels::update_cache($owner_uid, $id, array("no-labels" => 1)); |
|
728 | + |
|
729 | + return $rv; |
|
730 | + } |
|
731 | + |
|
732 | + public static function get_article_image($enclosures, $content, $site_url) { |
|
733 | + |
|
734 | + $article_image = ""; |
|
735 | + $article_stream = ""; |
|
736 | + |
|
737 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_IMAGE) as $p) { |
|
738 | + list ($article_image, $article_stream, $content) = $p->hook_article_image($enclosures, $content, $site_url); |
|
739 | + } |
|
740 | + |
|
741 | + if (!$article_image && !$article_stream) { |
|
742 | + $tmpdoc = new DOMDocument(); |
|
743 | + |
|
744 | + if (@$tmpdoc->loadHTML('<?xml encoding="UTF-8">' . mb_substr($content, 0, 131070))) { |
|
745 | + $tmpxpath = new DOMXPath($tmpdoc); |
|
746 | + $elems = $tmpxpath->query('(//img[@src]|//video[@poster]|//iframe[contains(@src , "youtube.com/embed/")])'); |
|
747 | + |
|
748 | + foreach ($elems as $e) { |
|
749 | + if ($e->nodeName == "iframe") { |
|
750 | + $matches = []; |
|
751 | + if (preg_match("/\/embed\/([\w-]+)/", $e->getAttribute("src"), $matches)) { |
|
752 | + $article_image = "https://img.youtube.com/vi/" . $matches[1] . "/hqdefault.jpg"; |
|
753 | + $article_stream = "https://youtu.be/" . $matches[1]; |
|
754 | + break; |
|
755 | + } |
|
756 | + } else if ($e->nodeName == "video") { |
|
757 | + $article_image = $e->getAttribute("poster"); |
|
758 | + |
|
759 | + $src = $tmpxpath->query("//source[@src]", $e)->item(0); |
|
760 | + |
|
761 | + if ($src) { |
|
762 | + $article_stream = $src->getAttribute("src"); |
|
763 | + } |
|
764 | + |
|
765 | + break; |
|
766 | + } else if ($e->nodeName == 'img') { |
|
767 | + if (mb_strpos($e->getAttribute("src"), "data:") !== 0) { |
|
768 | + $article_image = $e->getAttribute("src"); |
|
769 | + } |
|
770 | + break; |
|
771 | + } |
|
772 | + } |
|
773 | + } |
|
774 | + |
|
775 | + if (!$article_image) |
|
776 | + foreach ($enclosures as $enc) { |
|
777 | + if (strpos($enc["content_type"], "image/") !== FALSE) { |
|
778 | + $article_image = $enc["content_url"]; |
|
779 | + break; |
|
780 | + } |
|
781 | + } |
|
782 | + |
|
783 | + if ($article_image) |
|
784 | + $article_image = rewrite_relative_url($site_url, $article_image); |
|
785 | + |
|
786 | + if ($article_stream) |
|
787 | + $article_stream = rewrite_relative_url($site_url, $article_stream); |
|
788 | + } |
|
789 | + |
|
790 | + $cache = new DiskCache("images"); |
|
791 | + |
|
792 | + if ($article_image && $cache->exists(sha1($article_image))) |
|
793 | + $article_image = $cache->getUrl(sha1($article_image)); |
|
794 | + |
|
795 | + if ($article_stream && $cache->exists(sha1($article_stream))) |
|
796 | + $article_stream = $cache->getUrl(sha1($article_stream)); |
|
797 | + |
|
798 | + return [$article_image, $article_stream]; |
|
799 | + } |
|
800 | 800 | |
801 | 801 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | interface IHandler { |
3 | - public function csrf_ignore($method); |
|
4 | - public function before($method); |
|
5 | - public function after(); |
|
3 | + public function csrf_ignore($method); |
|
4 | + public function before($method); |
|
5 | + public function after(); |
|
6 | 6 | } |
@@ -1,145 +1,145 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class API extends Handler { |
3 | 3 | |
4 | - const API_LEVEL = 14; |
|
5 | - |
|
6 | - const STATUS_OK = 0; |
|
7 | - const STATUS_ERR = 1; |
|
8 | - |
|
9 | - private $seq; |
|
10 | - |
|
11 | - public static function param_to_bool($p) { |
|
12 | - return $p && ($p !== "f" && $p !== "false"); |
|
13 | - } |
|
14 | - |
|
15 | - public function before($method) { |
|
16 | - if (parent::before($method)) { |
|
17 | - header("Content-Type: text/json"); |
|
18 | - |
|
19 | - if (!$_SESSION["uid"] && $method != "login" && $method != "isloggedin") { |
|
20 | - $this->wrap(self::STATUS_ERR, array("error" => 'NOT_LOGGED_IN')); |
|
21 | - return false; |
|
22 | - } |
|
23 | - |
|
24 | - if ($_SESSION["uid"] && $method != "logout" && !get_pref('ENABLE_API_ACCESS')) { |
|
25 | - $this->wrap(self::STATUS_ERR, array("error" => 'API_DISABLED')); |
|
26 | - return false; |
|
27 | - } |
|
28 | - |
|
29 | - $this->seq = (int) clean($_REQUEST['seq']); |
|
30 | - |
|
31 | - return true; |
|
32 | - } |
|
33 | - return false; |
|
34 | - } |
|
35 | - |
|
36 | - public function wrap($status, $reply) { |
|
37 | - print json_encode(array("seq" => $this->seq, |
|
38 | - "status" => $status, |
|
39 | - "content" => $reply)); |
|
40 | - } |
|
41 | - |
|
42 | - public function getVersion() { |
|
43 | - $rv = array("version" => VERSION); |
|
44 | - $this->wrap(self::STATUS_OK, $rv); |
|
45 | - } |
|
46 | - |
|
47 | - public function getApiLevel() { |
|
48 | - $rv = array("level" => self::API_LEVEL); |
|
49 | - $this->wrap(self::STATUS_OK, $rv); |
|
50 | - } |
|
51 | - |
|
52 | - public function login() { |
|
53 | - @session_destroy(); |
|
54 | - @session_start(); |
|
55 | - |
|
56 | - $login = clean($_REQUEST["user"]); |
|
57 | - $password = clean($_REQUEST["password"]); |
|
58 | - $password_base64 = base64_decode(clean($_REQUEST["password"])); |
|
59 | - |
|
60 | - if (SINGLE_USER_MODE) $login = "admin"; |
|
61 | - |
|
62 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?"); |
|
63 | - $sth->execute([$login]); |
|
64 | - |
|
65 | - if ($row = $sth->fetch()) { |
|
66 | - $uid = $row["id"]; |
|
67 | - } else { |
|
68 | - $uid = 0; |
|
69 | - } |
|
70 | - |
|
71 | - if (!$uid) { |
|
72 | - $this->wrap(self::STATUS_ERR, array("error" => "LOGIN_ERROR")); |
|
73 | - return; |
|
74 | - } |
|
75 | - |
|
76 | - if (get_pref("ENABLE_API_ACCESS", $uid)) { |
|
77 | - if (authenticate_user($login, $password, false, Auth_Base::AUTH_SERVICE_API)) { // try login with normal password |
|
78 | - $this->wrap(self::STATUS_OK, array("session_id" => session_id(), |
|
79 | - "api_level" => self::API_LEVEL)); |
|
80 | - } else if (authenticate_user($login, $password_base64, false, Auth_Base::AUTH_SERVICE_API)) { // else try with base64_decoded password |
|
81 | - $this->wrap(self::STATUS_OK, array("session_id" => session_id(), |
|
82 | - "api_level" => self::API_LEVEL)); |
|
83 | - } else { // else we are not logged in |
|
84 | - user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING); |
|
85 | - $this->wrap(self::STATUS_ERR, array("error" => "LOGIN_ERROR")); |
|
86 | - } |
|
87 | - } else { |
|
88 | - $this->wrap(self::STATUS_ERR, array("error" => "API_DISABLED")); |
|
89 | - } |
|
90 | - |
|
91 | - } |
|
92 | - |
|
93 | - public function logout() { |
|
94 | - logout_user(); |
|
95 | - $this->wrap(self::STATUS_OK, array("status" => "OK")); |
|
96 | - } |
|
97 | - |
|
98 | - public function isLoggedIn() { |
|
99 | - $this->wrap(self::STATUS_OK, array("status" => $_SESSION["uid"] != '')); |
|
100 | - } |
|
101 | - |
|
102 | - public function getUnread() { |
|
103 | - $feed_id = clean($_REQUEST["feed_id"]); |
|
104 | - $is_cat = clean($_REQUEST["is_cat"]); |
|
105 | - |
|
106 | - if ($feed_id) { |
|
107 | - $this->wrap(self::STATUS_OK, array("unread" => getFeedUnread($feed_id, $is_cat))); |
|
108 | - } else { |
|
109 | - $this->wrap(self::STATUS_OK, array("unread" => Feeds::getGlobalUnread())); |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - /* Method added for ttrss-reader for Android */ |
|
114 | - public function getCounters() { |
|
115 | - $this->wrap(self::STATUS_OK, Counters::getAllCounters()); |
|
116 | - } |
|
117 | - |
|
118 | - public function getFeeds() { |
|
119 | - $cat_id = clean($_REQUEST["cat_id"]); |
|
120 | - $unread_only = API::param_to_bool(clean($_REQUEST["unread_only"])); |
|
121 | - $limit = (int) clean($_REQUEST["limit"]); |
|
122 | - $offset = (int) clean($_REQUEST["offset"]); |
|
123 | - $include_nested = API::param_to_bool(clean($_REQUEST["include_nested"])); |
|
124 | - |
|
125 | - $feeds = $this->api_get_feeds($cat_id, $unread_only, $limit, $offset, $include_nested); |
|
126 | - |
|
127 | - $this->wrap(self::STATUS_OK, $feeds); |
|
128 | - } |
|
129 | - |
|
130 | - public function getCategories() { |
|
131 | - $unread_only = API::param_to_bool(clean($_REQUEST["unread_only"])); |
|
132 | - $enable_nested = API::param_to_bool(clean($_REQUEST["enable_nested"])); |
|
133 | - $include_empty = API::param_to_bool(clean($_REQUEST['include_empty'])); |
|
134 | - |
|
135 | - // TODO do not return empty categories, return Uncategorized and standard virtual cats |
|
136 | - |
|
137 | - if ($enable_nested) |
|
138 | - $nested_qpart = "parent_cat IS NULL"; |
|
139 | - else |
|
140 | - $nested_qpart = "true"; |
|
141 | - |
|
142 | - $sth = $this->pdo->prepare("SELECT |
|
4 | + const API_LEVEL = 14; |
|
5 | + |
|
6 | + const STATUS_OK = 0; |
|
7 | + const STATUS_ERR = 1; |
|
8 | + |
|
9 | + private $seq; |
|
10 | + |
|
11 | + public static function param_to_bool($p) { |
|
12 | + return $p && ($p !== "f" && $p !== "false"); |
|
13 | + } |
|
14 | + |
|
15 | + public function before($method) { |
|
16 | + if (parent::before($method)) { |
|
17 | + header("Content-Type: text/json"); |
|
18 | + |
|
19 | + if (!$_SESSION["uid"] && $method != "login" && $method != "isloggedin") { |
|
20 | + $this->wrap(self::STATUS_ERR, array("error" => 'NOT_LOGGED_IN')); |
|
21 | + return false; |
|
22 | + } |
|
23 | + |
|
24 | + if ($_SESSION["uid"] && $method != "logout" && !get_pref('ENABLE_API_ACCESS')) { |
|
25 | + $this->wrap(self::STATUS_ERR, array("error" => 'API_DISABLED')); |
|
26 | + return false; |
|
27 | + } |
|
28 | + |
|
29 | + $this->seq = (int) clean($_REQUEST['seq']); |
|
30 | + |
|
31 | + return true; |
|
32 | + } |
|
33 | + return false; |
|
34 | + } |
|
35 | + |
|
36 | + public function wrap($status, $reply) { |
|
37 | + print json_encode(array("seq" => $this->seq, |
|
38 | + "status" => $status, |
|
39 | + "content" => $reply)); |
|
40 | + } |
|
41 | + |
|
42 | + public function getVersion() { |
|
43 | + $rv = array("version" => VERSION); |
|
44 | + $this->wrap(self::STATUS_OK, $rv); |
|
45 | + } |
|
46 | + |
|
47 | + public function getApiLevel() { |
|
48 | + $rv = array("level" => self::API_LEVEL); |
|
49 | + $this->wrap(self::STATUS_OK, $rv); |
|
50 | + } |
|
51 | + |
|
52 | + public function login() { |
|
53 | + @session_destroy(); |
|
54 | + @session_start(); |
|
55 | + |
|
56 | + $login = clean($_REQUEST["user"]); |
|
57 | + $password = clean($_REQUEST["password"]); |
|
58 | + $password_base64 = base64_decode(clean($_REQUEST["password"])); |
|
59 | + |
|
60 | + if (SINGLE_USER_MODE) $login = "admin"; |
|
61 | + |
|
62 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?"); |
|
63 | + $sth->execute([$login]); |
|
64 | + |
|
65 | + if ($row = $sth->fetch()) { |
|
66 | + $uid = $row["id"]; |
|
67 | + } else { |
|
68 | + $uid = 0; |
|
69 | + } |
|
70 | + |
|
71 | + if (!$uid) { |
|
72 | + $this->wrap(self::STATUS_ERR, array("error" => "LOGIN_ERROR")); |
|
73 | + return; |
|
74 | + } |
|
75 | + |
|
76 | + if (get_pref("ENABLE_API_ACCESS", $uid)) { |
|
77 | + if (authenticate_user($login, $password, false, Auth_Base::AUTH_SERVICE_API)) { // try login with normal password |
|
78 | + $this->wrap(self::STATUS_OK, array("session_id" => session_id(), |
|
79 | + "api_level" => self::API_LEVEL)); |
|
80 | + } else if (authenticate_user($login, $password_base64, false, Auth_Base::AUTH_SERVICE_API)) { // else try with base64_decoded password |
|
81 | + $this->wrap(self::STATUS_OK, array("session_id" => session_id(), |
|
82 | + "api_level" => self::API_LEVEL)); |
|
83 | + } else { // else we are not logged in |
|
84 | + user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING); |
|
85 | + $this->wrap(self::STATUS_ERR, array("error" => "LOGIN_ERROR")); |
|
86 | + } |
|
87 | + } else { |
|
88 | + $this->wrap(self::STATUS_ERR, array("error" => "API_DISABLED")); |
|
89 | + } |
|
90 | + |
|
91 | + } |
|
92 | + |
|
93 | + public function logout() { |
|
94 | + logout_user(); |
|
95 | + $this->wrap(self::STATUS_OK, array("status" => "OK")); |
|
96 | + } |
|
97 | + |
|
98 | + public function isLoggedIn() { |
|
99 | + $this->wrap(self::STATUS_OK, array("status" => $_SESSION["uid"] != '')); |
|
100 | + } |
|
101 | + |
|
102 | + public function getUnread() { |
|
103 | + $feed_id = clean($_REQUEST["feed_id"]); |
|
104 | + $is_cat = clean($_REQUEST["is_cat"]); |
|
105 | + |
|
106 | + if ($feed_id) { |
|
107 | + $this->wrap(self::STATUS_OK, array("unread" => getFeedUnread($feed_id, $is_cat))); |
|
108 | + } else { |
|
109 | + $this->wrap(self::STATUS_OK, array("unread" => Feeds::getGlobalUnread())); |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + /* Method added for ttrss-reader for Android */ |
|
114 | + public function getCounters() { |
|
115 | + $this->wrap(self::STATUS_OK, Counters::getAllCounters()); |
|
116 | + } |
|
117 | + |
|
118 | + public function getFeeds() { |
|
119 | + $cat_id = clean($_REQUEST["cat_id"]); |
|
120 | + $unread_only = API::param_to_bool(clean($_REQUEST["unread_only"])); |
|
121 | + $limit = (int) clean($_REQUEST["limit"]); |
|
122 | + $offset = (int) clean($_REQUEST["offset"]); |
|
123 | + $include_nested = API::param_to_bool(clean($_REQUEST["include_nested"])); |
|
124 | + |
|
125 | + $feeds = $this->api_get_feeds($cat_id, $unread_only, $limit, $offset, $include_nested); |
|
126 | + |
|
127 | + $this->wrap(self::STATUS_OK, $feeds); |
|
128 | + } |
|
129 | + |
|
130 | + public function getCategories() { |
|
131 | + $unread_only = API::param_to_bool(clean($_REQUEST["unread_only"])); |
|
132 | + $enable_nested = API::param_to_bool(clean($_REQUEST["enable_nested"])); |
|
133 | + $include_empty = API::param_to_bool(clean($_REQUEST['include_empty'])); |
|
134 | + |
|
135 | + // TODO do not return empty categories, return Uncategorized and standard virtual cats |
|
136 | + |
|
137 | + if ($enable_nested) |
|
138 | + $nested_qpart = "parent_cat IS NULL"; |
|
139 | + else |
|
140 | + $nested_qpart = "true"; |
|
141 | + |
|
142 | + $sth = $this->pdo->prepare("SELECT |
|
143 | 143 | id, title, order_id, (SELECT COUNT(id) FROM |
144 | 144 | ttrss_feeds WHERE |
145 | 145 | ttrss_feed_categories.id IS NOT NULL AND cat_id = ttrss_feed_categories.id) AS num_feeds, |
@@ -148,188 +148,188 @@ discard block |
||
148 | 148 | c2.parent_cat = ttrss_feed_categories.id) AS num_cats |
149 | 149 | FROM ttrss_feed_categories |
150 | 150 | WHERE $nested_qpart AND owner_uid = ?"); |
151 | - $sth->execute([$_SESSION['uid']]); |
|
152 | - |
|
153 | - $cats = array(); |
|
154 | - |
|
155 | - while ($line = $sth->fetch()) { |
|
156 | - if ($include_empty || $line["num_feeds"] > 0 || $line["num_cats"] > 0) { |
|
157 | - $unread = getFeedUnread($line["id"], true); |
|
158 | - |
|
159 | - if ($enable_nested) |
|
160 | - $unread += Feeds::getCategoryChildrenUnread($line["id"]); |
|
161 | - |
|
162 | - if ($unread || !$unread_only) { |
|
163 | - array_push($cats, array("id" => $line["id"], |
|
164 | - "title" => $line["title"], |
|
165 | - "unread" => $unread, |
|
166 | - "order_id" => (int) $line["order_id"], |
|
167 | - )); |
|
168 | - } |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - foreach (array(-2,-1,0) as $cat_id) { |
|
173 | - if ($include_empty || !$this->isCategoryEmpty($cat_id)) { |
|
174 | - $unread = getFeedUnread($cat_id, true); |
|
175 | - |
|
176 | - if ($unread || !$unread_only) { |
|
177 | - array_push($cats, array("id" => $cat_id, |
|
178 | - "title" => Feeds::getCategoryTitle($cat_id), |
|
179 | - "unread" => $unread)); |
|
180 | - } |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - $this->wrap(self::STATUS_OK, $cats); |
|
185 | - } |
|
186 | - |
|
187 | - public function getHeadlines() { |
|
188 | - $feed_id = clean($_REQUEST["feed_id"]); |
|
189 | - if ($feed_id !== "") { |
|
190 | - |
|
191 | - if (is_numeric($feed_id)) $feed_id = (int) $feed_id; |
|
192 | - |
|
193 | - $limit = (int)clean($_REQUEST["limit"]); |
|
194 | - |
|
195 | - if (!$limit || $limit >= 200) $limit = 200; |
|
196 | - |
|
197 | - $offset = (int)clean($_REQUEST["skip"]); |
|
198 | - $filter = clean($_REQUEST["filter"]); |
|
199 | - $is_cat = API::param_to_bool(clean($_REQUEST["is_cat"])); |
|
200 | - $show_excerpt = API::param_to_bool(clean($_REQUEST["show_excerpt"])); |
|
201 | - $show_content = API::param_to_bool(clean($_REQUEST["show_content"])); |
|
202 | - /* all_articles, unread, adaptive, marked, updated */ |
|
203 | - $view_mode = clean($_REQUEST["view_mode"]); |
|
204 | - $include_attachments = API::param_to_bool(clean($_REQUEST["include_attachments"])); |
|
205 | - $since_id = (int)clean($_REQUEST["since_id"]); |
|
206 | - $include_nested = API::param_to_bool(clean($_REQUEST["include_nested"])); |
|
207 | - $sanitize_content = !isset($_REQUEST["sanitize"]) || |
|
208 | - API::param_to_bool($_REQUEST["sanitize"]); |
|
209 | - $force_update = API::param_to_bool(clean($_REQUEST["force_update"])); |
|
210 | - $has_sandbox = API::param_to_bool(clean($_REQUEST["has_sandbox"])); |
|
211 | - $excerpt_length = (int)clean($_REQUEST["excerpt_length"]); |
|
212 | - $check_first_id = (int)clean($_REQUEST["check_first_id"]); |
|
213 | - $include_header = API::param_to_bool(clean($_REQUEST["include_header"])); |
|
214 | - |
|
215 | - $_SESSION['hasSandbox'] = $has_sandbox; |
|
216 | - |
|
217 | - $skip_first_id_check = false; |
|
218 | - |
|
219 | - $override_order = false; |
|
220 | - switch (clean($_REQUEST["order_by"])) { |
|
221 | - case "title": |
|
222 | - $override_order = "ttrss_entries.title, date_entered, updated"; |
|
223 | - break; |
|
224 | - case "date_reverse": |
|
225 | - $override_order = "score DESC, date_entered, updated"; |
|
226 | - $skip_first_id_check = true; |
|
227 | - break; |
|
228 | - case "feed_dates": |
|
229 | - $override_order = "updated DESC"; |
|
230 | - break; |
|
231 | - } |
|
232 | - |
|
233 | - /* do not rely on params below */ |
|
234 | - |
|
235 | - $search = clean($_REQUEST["search"]); |
|
236 | - |
|
237 | - list($headlines, $headlines_header) = $this->api_get_headlines($feed_id, $limit, $offset, |
|
238 | - $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $override_order, |
|
239 | - $include_attachments, $since_id, $search, |
|
240 | - $include_nested, $sanitize_content, $force_update, $excerpt_length, $check_first_id, $skip_first_id_check); |
|
241 | - |
|
242 | - if ($include_header) { |
|
243 | - $this->wrap(self::STATUS_OK, array($headlines_header, $headlines)); |
|
244 | - } else { |
|
245 | - $this->wrap(self::STATUS_OK, $headlines); |
|
246 | - } |
|
247 | - } else { |
|
248 | - $this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE')); |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - public function updateArticle() { |
|
253 | - $article_ids = explode(",", clean($_REQUEST["article_ids"])); |
|
254 | - $mode = (int) clean($_REQUEST["mode"]); |
|
255 | - $data = clean($_REQUEST["data"]); |
|
256 | - $field_raw = (int)clean($_REQUEST["field"]); |
|
257 | - |
|
258 | - $field = ""; |
|
259 | - $set_to = ""; |
|
260 | - |
|
261 | - switch ($field_raw) { |
|
262 | - case 0: |
|
263 | - $field = "marked"; |
|
264 | - $additional_fields = ",last_marked = NOW()"; |
|
265 | - break; |
|
266 | - case 1: |
|
267 | - $field = "published"; |
|
268 | - $additional_fields = ",last_published = NOW()"; |
|
269 | - break; |
|
270 | - case 2: |
|
271 | - $field = "unread"; |
|
272 | - $additional_fields = ",last_read = NOW()"; |
|
273 | - break; |
|
274 | - case 3: |
|
275 | - $field = "note"; |
|
276 | - }; |
|
277 | - |
|
278 | - switch ($mode) { |
|
279 | - case 1: |
|
280 | - $set_to = "true"; |
|
281 | - break; |
|
282 | - case 0: |
|
283 | - $set_to = "false"; |
|
284 | - break; |
|
285 | - case 2: |
|
286 | - $set_to = "NOT $field"; |
|
287 | - break; |
|
288 | - } |
|
289 | - |
|
290 | - if ($field == "note") $set_to = $this->pdo->quote($data); |
|
291 | - |
|
292 | - if ($field && $set_to && count($article_ids) > 0) { |
|
293 | - |
|
294 | - $article_qmarks = arr_qmarks($article_ids); |
|
295 | - |
|
296 | - $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
151 | + $sth->execute([$_SESSION['uid']]); |
|
152 | + |
|
153 | + $cats = array(); |
|
154 | + |
|
155 | + while ($line = $sth->fetch()) { |
|
156 | + if ($include_empty || $line["num_feeds"] > 0 || $line["num_cats"] > 0) { |
|
157 | + $unread = getFeedUnread($line["id"], true); |
|
158 | + |
|
159 | + if ($enable_nested) |
|
160 | + $unread += Feeds::getCategoryChildrenUnread($line["id"]); |
|
161 | + |
|
162 | + if ($unread || !$unread_only) { |
|
163 | + array_push($cats, array("id" => $line["id"], |
|
164 | + "title" => $line["title"], |
|
165 | + "unread" => $unread, |
|
166 | + "order_id" => (int) $line["order_id"], |
|
167 | + )); |
|
168 | + } |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + foreach (array(-2,-1,0) as $cat_id) { |
|
173 | + if ($include_empty || !$this->isCategoryEmpty($cat_id)) { |
|
174 | + $unread = getFeedUnread($cat_id, true); |
|
175 | + |
|
176 | + if ($unread || !$unread_only) { |
|
177 | + array_push($cats, array("id" => $cat_id, |
|
178 | + "title" => Feeds::getCategoryTitle($cat_id), |
|
179 | + "unread" => $unread)); |
|
180 | + } |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + $this->wrap(self::STATUS_OK, $cats); |
|
185 | + } |
|
186 | + |
|
187 | + public function getHeadlines() { |
|
188 | + $feed_id = clean($_REQUEST["feed_id"]); |
|
189 | + if ($feed_id !== "") { |
|
190 | + |
|
191 | + if (is_numeric($feed_id)) $feed_id = (int) $feed_id; |
|
192 | + |
|
193 | + $limit = (int)clean($_REQUEST["limit"]); |
|
194 | + |
|
195 | + if (!$limit || $limit >= 200) $limit = 200; |
|
196 | + |
|
197 | + $offset = (int)clean($_REQUEST["skip"]); |
|
198 | + $filter = clean($_REQUEST["filter"]); |
|
199 | + $is_cat = API::param_to_bool(clean($_REQUEST["is_cat"])); |
|
200 | + $show_excerpt = API::param_to_bool(clean($_REQUEST["show_excerpt"])); |
|
201 | + $show_content = API::param_to_bool(clean($_REQUEST["show_content"])); |
|
202 | + /* all_articles, unread, adaptive, marked, updated */ |
|
203 | + $view_mode = clean($_REQUEST["view_mode"]); |
|
204 | + $include_attachments = API::param_to_bool(clean($_REQUEST["include_attachments"])); |
|
205 | + $since_id = (int)clean($_REQUEST["since_id"]); |
|
206 | + $include_nested = API::param_to_bool(clean($_REQUEST["include_nested"])); |
|
207 | + $sanitize_content = !isset($_REQUEST["sanitize"]) || |
|
208 | + API::param_to_bool($_REQUEST["sanitize"]); |
|
209 | + $force_update = API::param_to_bool(clean($_REQUEST["force_update"])); |
|
210 | + $has_sandbox = API::param_to_bool(clean($_REQUEST["has_sandbox"])); |
|
211 | + $excerpt_length = (int)clean($_REQUEST["excerpt_length"]); |
|
212 | + $check_first_id = (int)clean($_REQUEST["check_first_id"]); |
|
213 | + $include_header = API::param_to_bool(clean($_REQUEST["include_header"])); |
|
214 | + |
|
215 | + $_SESSION['hasSandbox'] = $has_sandbox; |
|
216 | + |
|
217 | + $skip_first_id_check = false; |
|
218 | + |
|
219 | + $override_order = false; |
|
220 | + switch (clean($_REQUEST["order_by"])) { |
|
221 | + case "title": |
|
222 | + $override_order = "ttrss_entries.title, date_entered, updated"; |
|
223 | + break; |
|
224 | + case "date_reverse": |
|
225 | + $override_order = "score DESC, date_entered, updated"; |
|
226 | + $skip_first_id_check = true; |
|
227 | + break; |
|
228 | + case "feed_dates": |
|
229 | + $override_order = "updated DESC"; |
|
230 | + break; |
|
231 | + } |
|
232 | + |
|
233 | + /* do not rely on params below */ |
|
234 | + |
|
235 | + $search = clean($_REQUEST["search"]); |
|
236 | + |
|
237 | + list($headlines, $headlines_header) = $this->api_get_headlines($feed_id, $limit, $offset, |
|
238 | + $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $override_order, |
|
239 | + $include_attachments, $since_id, $search, |
|
240 | + $include_nested, $sanitize_content, $force_update, $excerpt_length, $check_first_id, $skip_first_id_check); |
|
241 | + |
|
242 | + if ($include_header) { |
|
243 | + $this->wrap(self::STATUS_OK, array($headlines_header, $headlines)); |
|
244 | + } else { |
|
245 | + $this->wrap(self::STATUS_OK, $headlines); |
|
246 | + } |
|
247 | + } else { |
|
248 | + $this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE')); |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + public function updateArticle() { |
|
253 | + $article_ids = explode(",", clean($_REQUEST["article_ids"])); |
|
254 | + $mode = (int) clean($_REQUEST["mode"]); |
|
255 | + $data = clean($_REQUEST["data"]); |
|
256 | + $field_raw = (int)clean($_REQUEST["field"]); |
|
257 | + |
|
258 | + $field = ""; |
|
259 | + $set_to = ""; |
|
260 | + |
|
261 | + switch ($field_raw) { |
|
262 | + case 0: |
|
263 | + $field = "marked"; |
|
264 | + $additional_fields = ",last_marked = NOW()"; |
|
265 | + break; |
|
266 | + case 1: |
|
267 | + $field = "published"; |
|
268 | + $additional_fields = ",last_published = NOW()"; |
|
269 | + break; |
|
270 | + case 2: |
|
271 | + $field = "unread"; |
|
272 | + $additional_fields = ",last_read = NOW()"; |
|
273 | + break; |
|
274 | + case 3: |
|
275 | + $field = "note"; |
|
276 | + }; |
|
277 | + |
|
278 | + switch ($mode) { |
|
279 | + case 1: |
|
280 | + $set_to = "true"; |
|
281 | + break; |
|
282 | + case 0: |
|
283 | + $set_to = "false"; |
|
284 | + break; |
|
285 | + case 2: |
|
286 | + $set_to = "NOT $field"; |
|
287 | + break; |
|
288 | + } |
|
289 | + |
|
290 | + if ($field == "note") $set_to = $this->pdo->quote($data); |
|
291 | + |
|
292 | + if ($field && $set_to && count($article_ids) > 0) { |
|
293 | + |
|
294 | + $article_qmarks = arr_qmarks($article_ids); |
|
295 | + |
|
296 | + $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
|
297 | 297 | $field = $set_to $additional_fields |
298 | 298 | WHERE ref_id IN ($article_qmarks) AND owner_uid = ?"); |
299 | - $sth->execute(array_merge($article_ids, [$_SESSION['uid']])); |
|
299 | + $sth->execute(array_merge($article_ids, [$_SESSION['uid']])); |
|
300 | 300 | |
301 | - $num_updated = $sth->rowCount(); |
|
301 | + $num_updated = $sth->rowCount(); |
|
302 | 302 | |
303 | - if ($num_updated > 0 && $field == "unread") { |
|
304 | - $sth = $this->pdo->prepare("SELECT DISTINCT feed_id FROM ttrss_user_entries |
|
303 | + if ($num_updated > 0 && $field == "unread") { |
|
304 | + $sth = $this->pdo->prepare("SELECT DISTINCT feed_id FROM ttrss_user_entries |
|
305 | 305 | WHERE ref_id IN ($article_qmarks)"); |
306 | - $sth->execute($article_ids); |
|
306 | + $sth->execute($article_ids); |
|
307 | 307 | |
308 | - while ($line = $sth->fetch()) { |
|
309 | - CCache::update($line["feed_id"], $_SESSION["uid"]); |
|
310 | - } |
|
311 | - } |
|
308 | + while ($line = $sth->fetch()) { |
|
309 | + CCache::update($line["feed_id"], $_SESSION["uid"]); |
|
310 | + } |
|
311 | + } |
|
312 | 312 | |
313 | - $this->wrap(self::STATUS_OK, array("status" => "OK", |
|
314 | - "updated" => $num_updated)); |
|
313 | + $this->wrap(self::STATUS_OK, array("status" => "OK", |
|
314 | + "updated" => $num_updated)); |
|
315 | 315 | |
316 | - } else { |
|
317 | - $this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE')); |
|
318 | - } |
|
316 | + } else { |
|
317 | + $this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE')); |
|
318 | + } |
|
319 | 319 | |
320 | - } |
|
320 | + } |
|
321 | 321 | |
322 | - public function getArticle() { |
|
322 | + public function getArticle() { |
|
323 | 323 | |
324 | - $article_ids = explode(",", clean($_REQUEST["article_id"])); |
|
325 | - $sanitize_content = !isset($_REQUEST["sanitize"]) || |
|
326 | - API::param_to_bool($_REQUEST["sanitize"]); |
|
324 | + $article_ids = explode(",", clean($_REQUEST["article_id"])); |
|
325 | + $sanitize_content = !isset($_REQUEST["sanitize"]) || |
|
326 | + API::param_to_bool($_REQUEST["sanitize"]); |
|
327 | 327 | |
328 | - if ($article_ids) { |
|
328 | + if ($article_ids) { |
|
329 | 329 | |
330 | - $article_qmarks = arr_qmarks($article_ids); |
|
330 | + $article_qmarks = arr_qmarks($article_ids); |
|
331 | 331 | |
332 | - $sth = $this->pdo->prepare("SELECT id,guid,title,link,content,feed_id,comments,int_id, |
|
332 | + $sth = $this->pdo->prepare("SELECT id,guid,title,link,content,feed_id,comments,int_id, |
|
333 | 333 | marked,unread,published,score,note,lang, |
334 | 334 | ".SUBSTRING_FOR_DATE."(updated,1,16) as updated, |
335 | 335 | author,(SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title, |
@@ -338,559 +338,559 @@ discard block |
||
338 | 338 | FROM ttrss_entries,ttrss_user_entries |
339 | 339 | WHERE id IN ($article_qmarks) AND ref_id = id AND owner_uid = ?"); |
340 | 340 | |
341 | - $sth->execute(array_merge($article_ids, [$_SESSION['uid']])); |
|
342 | - |
|
343 | - $articles = array(); |
|
344 | - |
|
345 | - while ($line = $sth->fetch()) { |
|
346 | - |
|
347 | - $attachments = Article::get_article_enclosures($line['id']); |
|
348 | - |
|
349 | - $article = array( |
|
350 | - "id" => $line["id"], |
|
351 | - "guid" => $line["guid"], |
|
352 | - "title" => $line["title"], |
|
353 | - "link" => $line["link"], |
|
354 | - "labels" => Article::get_article_labels($line['id']), |
|
355 | - "unread" => API::param_to_bool($line["unread"]), |
|
356 | - "marked" => API::param_to_bool($line["marked"]), |
|
357 | - "published" => API::param_to_bool($line["published"]), |
|
358 | - "comments" => $line["comments"], |
|
359 | - "author" => $line["author"], |
|
360 | - "updated" => (int) strtotime($line["updated"]), |
|
361 | - "feed_id" => $line["feed_id"], |
|
362 | - "attachments" => $attachments, |
|
363 | - "score" => (int)$line["score"], |
|
364 | - "feed_title" => $line["feed_title"], |
|
365 | - "note" => $line["note"], |
|
366 | - "lang" => $line["lang"] |
|
367 | - ); |
|
368 | - |
|
369 | - if ($sanitize_content) { |
|
370 | - $article["content"] = sanitize( |
|
371 | - $line["content"], |
|
372 | - API::param_to_bool($line['hide_images']), |
|
373 | - false, $line["site_url"], false, $line["id"]); |
|
374 | - } else { |
|
375 | - $article["content"] = $line["content"]; |
|
376 | - } |
|
377 | - |
|
378 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_API) as $p) { |
|
379 | - $article = $p->hook_render_article_api(array("article" => $article)); |
|
380 | - } |
|
381 | - |
|
382 | - $article['content'] = DiskCache::rewriteUrls($article['content']); |
|
383 | - |
|
384 | - array_push($articles, $article); |
|
385 | - |
|
386 | - } |
|
387 | - |
|
388 | - $this->wrap(self::STATUS_OK, $articles); |
|
389 | - } else { |
|
390 | - $this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE')); |
|
391 | - } |
|
392 | - } |
|
393 | - |
|
394 | - public function getConfig() { |
|
395 | - $config = array( |
|
396 | - "icons_dir" => ICONS_DIR, |
|
397 | - "icons_url" => ICONS_URL); |
|
398 | - |
|
399 | - $config["daemon_is_running"] = file_is_locked("update_daemon.lock"); |
|
400 | - |
|
401 | - $sth = $this->pdo->prepare("SELECT COUNT(*) AS cf FROM |
|
341 | + $sth->execute(array_merge($article_ids, [$_SESSION['uid']])); |
|
342 | + |
|
343 | + $articles = array(); |
|
344 | + |
|
345 | + while ($line = $sth->fetch()) { |
|
346 | + |
|
347 | + $attachments = Article::get_article_enclosures($line['id']); |
|
348 | + |
|
349 | + $article = array( |
|
350 | + "id" => $line["id"], |
|
351 | + "guid" => $line["guid"], |
|
352 | + "title" => $line["title"], |
|
353 | + "link" => $line["link"], |
|
354 | + "labels" => Article::get_article_labels($line['id']), |
|
355 | + "unread" => API::param_to_bool($line["unread"]), |
|
356 | + "marked" => API::param_to_bool($line["marked"]), |
|
357 | + "published" => API::param_to_bool($line["published"]), |
|
358 | + "comments" => $line["comments"], |
|
359 | + "author" => $line["author"], |
|
360 | + "updated" => (int) strtotime($line["updated"]), |
|
361 | + "feed_id" => $line["feed_id"], |
|
362 | + "attachments" => $attachments, |
|
363 | + "score" => (int)$line["score"], |
|
364 | + "feed_title" => $line["feed_title"], |
|
365 | + "note" => $line["note"], |
|
366 | + "lang" => $line["lang"] |
|
367 | + ); |
|
368 | + |
|
369 | + if ($sanitize_content) { |
|
370 | + $article["content"] = sanitize( |
|
371 | + $line["content"], |
|
372 | + API::param_to_bool($line['hide_images']), |
|
373 | + false, $line["site_url"], false, $line["id"]); |
|
374 | + } else { |
|
375 | + $article["content"] = $line["content"]; |
|
376 | + } |
|
377 | + |
|
378 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_API) as $p) { |
|
379 | + $article = $p->hook_render_article_api(array("article" => $article)); |
|
380 | + } |
|
381 | + |
|
382 | + $article['content'] = DiskCache::rewriteUrls($article['content']); |
|
383 | + |
|
384 | + array_push($articles, $article); |
|
385 | + |
|
386 | + } |
|
387 | + |
|
388 | + $this->wrap(self::STATUS_OK, $articles); |
|
389 | + } else { |
|
390 | + $this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE')); |
|
391 | + } |
|
392 | + } |
|
393 | + |
|
394 | + public function getConfig() { |
|
395 | + $config = array( |
|
396 | + "icons_dir" => ICONS_DIR, |
|
397 | + "icons_url" => ICONS_URL); |
|
398 | + |
|
399 | + $config["daemon_is_running"] = file_is_locked("update_daemon.lock"); |
|
400 | + |
|
401 | + $sth = $this->pdo->prepare("SELECT COUNT(*) AS cf FROM |
|
402 | 402 | ttrss_feeds WHERE owner_uid = ?"); |
403 | - $sth->execute([$_SESSION['uid']]); |
|
404 | - $row = $sth->fetch(); |
|
403 | + $sth->execute([$_SESSION['uid']]); |
|
404 | + $row = $sth->fetch(); |
|
405 | 405 | |
406 | - $config["num_feeds"] = $row["cf"]; |
|
406 | + $config["num_feeds"] = $row["cf"]; |
|
407 | 407 | |
408 | - $this->wrap(self::STATUS_OK, $config); |
|
409 | - } |
|
408 | + $this->wrap(self::STATUS_OK, $config); |
|
409 | + } |
|
410 | 410 | |
411 | - public function updateFeed() { |
|
412 | - $feed_id = (int) clean($_REQUEST["feed_id"]); |
|
411 | + public function updateFeed() { |
|
412 | + $feed_id = (int) clean($_REQUEST["feed_id"]); |
|
413 | 413 | |
414 | - if (!ini_get("open_basedir")) { |
|
415 | - RSSUtils::update_rss_feed($feed_id); |
|
416 | - } |
|
414 | + if (!ini_get("open_basedir")) { |
|
415 | + RSSUtils::update_rss_feed($feed_id); |
|
416 | + } |
|
417 | 417 | |
418 | - $this->wrap(self::STATUS_OK, array("status" => "OK")); |
|
419 | - } |
|
418 | + $this->wrap(self::STATUS_OK, array("status" => "OK")); |
|
419 | + } |
|
420 | 420 | |
421 | - public function catchupFeed() { |
|
422 | - $feed_id = clean($_REQUEST["feed_id"]); |
|
423 | - $is_cat = clean($_REQUEST["is_cat"]); |
|
421 | + public function catchupFeed() { |
|
422 | + $feed_id = clean($_REQUEST["feed_id"]); |
|
423 | + $is_cat = clean($_REQUEST["is_cat"]); |
|
424 | 424 | |
425 | - Feeds::catchup_feed($feed_id, $is_cat); |
|
425 | + Feeds::catchup_feed($feed_id, $is_cat); |
|
426 | 426 | |
427 | - $this->wrap(self::STATUS_OK, array("status" => "OK")); |
|
428 | - } |
|
427 | + $this->wrap(self::STATUS_OK, array("status" => "OK")); |
|
428 | + } |
|
429 | 429 | |
430 | - public function getPref() { |
|
431 | - $pref_name = clean($_REQUEST["pref_name"]); |
|
430 | + public function getPref() { |
|
431 | + $pref_name = clean($_REQUEST["pref_name"]); |
|
432 | 432 | |
433 | - $this->wrap(self::STATUS_OK, array("value" => get_pref($pref_name))); |
|
434 | - } |
|
433 | + $this->wrap(self::STATUS_OK, array("value" => get_pref($pref_name))); |
|
434 | + } |
|
435 | 435 | |
436 | - public function getLabels() { |
|
437 | - $article_id = (int)clean($_REQUEST['article_id']); |
|
436 | + public function getLabels() { |
|
437 | + $article_id = (int)clean($_REQUEST['article_id']); |
|
438 | 438 | |
439 | - $rv = array(); |
|
439 | + $rv = array(); |
|
440 | 440 | |
441 | - $sth = $this->pdo->prepare("SELECT id, caption, fg_color, bg_color |
|
441 | + $sth = $this->pdo->prepare("SELECT id, caption, fg_color, bg_color |
|
442 | 442 | FROM ttrss_labels2 |
443 | 443 | WHERE owner_uid = ? ORDER BY caption"); |
444 | - $sth->execute([$_SESSION['uid']]); |
|
444 | + $sth->execute([$_SESSION['uid']]); |
|
445 | 445 | |
446 | - if ($article_id) |
|
447 | - $article_labels = Article::get_article_labels($article_id); |
|
448 | - else |
|
449 | - $article_labels = array(); |
|
446 | + if ($article_id) |
|
447 | + $article_labels = Article::get_article_labels($article_id); |
|
448 | + else |
|
449 | + $article_labels = array(); |
|
450 | 450 | |
451 | - while ($line = $sth->fetch()) { |
|
451 | + while ($line = $sth->fetch()) { |
|
452 | 452 | |
453 | - $checked = false; |
|
454 | - foreach ($article_labels as $al) { |
|
455 | - if (Labels::feed_to_label_id($al[0]) == $line['id']) { |
|
456 | - $checked = true; |
|
457 | - break; |
|
458 | - } |
|
459 | - } |
|
453 | + $checked = false; |
|
454 | + foreach ($article_labels as $al) { |
|
455 | + if (Labels::feed_to_label_id($al[0]) == $line['id']) { |
|
456 | + $checked = true; |
|
457 | + break; |
|
458 | + } |
|
459 | + } |
|
460 | 460 | |
461 | - array_push($rv, array( |
|
462 | - "id" => (int)Labels::label_to_feed_id($line['id']), |
|
463 | - "caption" => $line['caption'], |
|
464 | - "fg_color" => $line['fg_color'], |
|
465 | - "bg_color" => $line['bg_color'], |
|
466 | - "checked" => $checked)); |
|
467 | - } |
|
461 | + array_push($rv, array( |
|
462 | + "id" => (int)Labels::label_to_feed_id($line['id']), |
|
463 | + "caption" => $line['caption'], |
|
464 | + "fg_color" => $line['fg_color'], |
|
465 | + "bg_color" => $line['bg_color'], |
|
466 | + "checked" => $checked)); |
|
467 | + } |
|
468 | 468 | |
469 | - $this->wrap(self::STATUS_OK, $rv); |
|
470 | - } |
|
469 | + $this->wrap(self::STATUS_OK, $rv); |
|
470 | + } |
|
471 | 471 | |
472 | - public function setArticleLabel() { |
|
472 | + public function setArticleLabel() { |
|
473 | 473 | |
474 | - $article_ids = explode(",", clean($_REQUEST["article_ids"])); |
|
475 | - $label_id = (int) clean($_REQUEST['label_id']); |
|
476 | - $assign = API::param_to_bool(clean($_REQUEST['assign'])); |
|
474 | + $article_ids = explode(",", clean($_REQUEST["article_ids"])); |
|
475 | + $label_id = (int) clean($_REQUEST['label_id']); |
|
476 | + $assign = API::param_to_bool(clean($_REQUEST['assign'])); |
|
477 | 477 | |
478 | - $label = Labels::find_caption(Labels::feed_to_label_id($label_id), $_SESSION["uid"]); |
|
478 | + $label = Labels::find_caption(Labels::feed_to_label_id($label_id), $_SESSION["uid"]); |
|
479 | 479 | |
480 | - $num_updated = 0; |
|
480 | + $num_updated = 0; |
|
481 | 481 | |
482 | - if ($label) { |
|
482 | + if ($label) { |
|
483 | 483 | |
484 | - foreach ($article_ids as $id) { |
|
484 | + foreach ($article_ids as $id) { |
|
485 | 485 | |
486 | - if ($assign) |
|
487 | - Labels::add_article($id, $label, $_SESSION["uid"]); |
|
488 | - else |
|
489 | - Labels::remove_article($id, $label, $_SESSION["uid"]); |
|
486 | + if ($assign) |
|
487 | + Labels::add_article($id, $label, $_SESSION["uid"]); |
|
488 | + else |
|
489 | + Labels::remove_article($id, $label, $_SESSION["uid"]); |
|
490 | 490 | |
491 | - ++$num_updated; |
|
491 | + ++$num_updated; |
|
492 | 492 | |
493 | - } |
|
494 | - } |
|
493 | + } |
|
494 | + } |
|
495 | 495 | |
496 | - $this->wrap(self::STATUS_OK, array("status" => "OK", |
|
497 | - "updated" => $num_updated)); |
|
496 | + $this->wrap(self::STATUS_OK, array("status" => "OK", |
|
497 | + "updated" => $num_updated)); |
|
498 | 498 | |
499 | - } |
|
499 | + } |
|
500 | 500 | |
501 | - public function index($method) { |
|
502 | - $plugin = PluginHost::getInstance()->get_api_method(strtolower($method)); |
|
501 | + public function index($method) { |
|
502 | + $plugin = PluginHost::getInstance()->get_api_method(strtolower($method)); |
|
503 | 503 | |
504 | - if ($plugin && method_exists($plugin, $method)) { |
|
505 | - $reply = $plugin->$method(); |
|
504 | + if ($plugin && method_exists($plugin, $method)) { |
|
505 | + $reply = $plugin->$method(); |
|
506 | 506 | |
507 | - $this->wrap($reply[0], $reply[1]); |
|
507 | + $this->wrap($reply[0], $reply[1]); |
|
508 | 508 | |
509 | - } else { |
|
510 | - $this->wrap(self::STATUS_ERR, array("error" => 'UNKNOWN_METHOD', "method" => $method)); |
|
511 | - } |
|
512 | - } |
|
509 | + } else { |
|
510 | + $this->wrap(self::STATUS_ERR, array("error" => 'UNKNOWN_METHOD', "method" => $method)); |
|
511 | + } |
|
512 | + } |
|
513 | 513 | |
514 | - public function shareToPublished() { |
|
515 | - $title = strip_tags(clean($_REQUEST["title"])); |
|
516 | - $url = strip_tags(clean($_REQUEST["url"])); |
|
517 | - $content = strip_tags(clean($_REQUEST["content"])); |
|
514 | + public function shareToPublished() { |
|
515 | + $title = strip_tags(clean($_REQUEST["title"])); |
|
516 | + $url = strip_tags(clean($_REQUEST["url"])); |
|
517 | + $content = strip_tags(clean($_REQUEST["content"])); |
|
518 | 518 | |
519 | - if (Article::create_published_article($title, $url, $content, "", $_SESSION["uid"])) { |
|
520 | - $this->wrap(self::STATUS_OK, array("status" => 'OK')); |
|
521 | - } else { |
|
522 | - $this->wrap(self::STATUS_ERR, array("error" => 'Publishing failed')); |
|
523 | - } |
|
524 | - } |
|
519 | + if (Article::create_published_article($title, $url, $content, "", $_SESSION["uid"])) { |
|
520 | + $this->wrap(self::STATUS_OK, array("status" => 'OK')); |
|
521 | + } else { |
|
522 | + $this->wrap(self::STATUS_ERR, array("error" => 'Publishing failed')); |
|
523 | + } |
|
524 | + } |
|
525 | 525 | |
526 | - public static function api_get_feeds($cat_id, $unread_only, $limit, $offset, $include_nested = false) { |
|
526 | + public static function api_get_feeds($cat_id, $unread_only, $limit, $offset, $include_nested = false) { |
|
527 | 527 | |
528 | - $feeds = array(); |
|
528 | + $feeds = array(); |
|
529 | 529 | |
530 | - $pdo = Db::pdo(); |
|
530 | + $pdo = Db::pdo(); |
|
531 | 531 | |
532 | - $limit = (int) $limit; |
|
533 | - $offset = (int) $offset; |
|
534 | - $cat_id = (int) $cat_id; |
|
532 | + $limit = (int) $limit; |
|
533 | + $offset = (int) $offset; |
|
534 | + $cat_id = (int) $cat_id; |
|
535 | 535 | |
536 | - /* Labels */ |
|
536 | + /* Labels */ |
|
537 | 537 | |
538 | - /* API only: -4 All feeds, including virtual feeds */ |
|
539 | - if ($cat_id == -4 || $cat_id == -2) { |
|
540 | - $counters = Counters::getLabelCounters(true); |
|
538 | + /* API only: -4 All feeds, including virtual feeds */ |
|
539 | + if ($cat_id == -4 || $cat_id == -2) { |
|
540 | + $counters = Counters::getLabelCounters(true); |
|
541 | 541 | |
542 | - foreach (array_values($counters) as $cv) { |
|
542 | + foreach (array_values($counters) as $cv) { |
|
543 | 543 | |
544 | - $unread = $cv["counter"]; |
|
544 | + $unread = $cv["counter"]; |
|
545 | 545 | |
546 | - if ($unread || !$unread_only) { |
|
546 | + if ($unread || !$unread_only) { |
|
547 | 547 | |
548 | - $row = array( |
|
549 | - "id" => (int) $cv["id"], |
|
550 | - "title" => $cv["description"], |
|
551 | - "unread" => $cv["counter"], |
|
552 | - "cat_id" => -2, |
|
553 | - ); |
|
548 | + $row = array( |
|
549 | + "id" => (int) $cv["id"], |
|
550 | + "title" => $cv["description"], |
|
551 | + "unread" => $cv["counter"], |
|
552 | + "cat_id" => -2, |
|
553 | + ); |
|
554 | 554 | |
555 | - array_push($feeds, $row); |
|
556 | - } |
|
557 | - } |
|
558 | - } |
|
555 | + array_push($feeds, $row); |
|
556 | + } |
|
557 | + } |
|
558 | + } |
|
559 | 559 | |
560 | - /* Virtual feeds */ |
|
560 | + /* Virtual feeds */ |
|
561 | 561 | |
562 | - if ($cat_id == -4 || $cat_id == -1) { |
|
563 | - foreach (array(-1, -2, -3, -4, -6, 0) as $i) { |
|
564 | - $unread = getFeedUnread($i); |
|
562 | + if ($cat_id == -4 || $cat_id == -1) { |
|
563 | + foreach (array(-1, -2, -3, -4, -6, 0) as $i) { |
|
564 | + $unread = getFeedUnread($i); |
|
565 | 565 | |
566 | - if ($unread || !$unread_only) { |
|
567 | - $title = Feeds::getFeedTitle($i); |
|
566 | + if ($unread || !$unread_only) { |
|
567 | + $title = Feeds::getFeedTitle($i); |
|
568 | 568 | |
569 | - $row = array( |
|
570 | - "id" => $i, |
|
571 | - "title" => $title, |
|
572 | - "unread" => $unread, |
|
573 | - "cat_id" => -1, |
|
574 | - ); |
|
575 | - array_push($feeds, $row); |
|
576 | - } |
|
569 | + $row = array( |
|
570 | + "id" => $i, |
|
571 | + "title" => $title, |
|
572 | + "unread" => $unread, |
|
573 | + "cat_id" => -1, |
|
574 | + ); |
|
575 | + array_push($feeds, $row); |
|
576 | + } |
|
577 | 577 | |
578 | - } |
|
579 | - } |
|
578 | + } |
|
579 | + } |
|
580 | 580 | |
581 | - /* Child cats */ |
|
581 | + /* Child cats */ |
|
582 | 582 | |
583 | - if ($include_nested && $cat_id) { |
|
584 | - $sth = $pdo->prepare("SELECT |
|
583 | + if ($include_nested && $cat_id) { |
|
584 | + $sth = $pdo->prepare("SELECT |
|
585 | 585 | id, title, order_id FROM ttrss_feed_categories |
586 | 586 | WHERE parent_cat = ? AND owner_uid = ? ORDER BY order_id, title"); |
587 | 587 | |
588 | - $sth->execute([$cat_id, $_SESSION['uid']]); |
|
588 | + $sth->execute([$cat_id, $_SESSION['uid']]); |
|
589 | 589 | |
590 | - while ($line = $sth->fetch()) { |
|
591 | - $unread = getFeedUnread($line["id"], true) + |
|
592 | - Feeds::getCategoryChildrenUnread($line["id"]); |
|
590 | + while ($line = $sth->fetch()) { |
|
591 | + $unread = getFeedUnread($line["id"], true) + |
|
592 | + Feeds::getCategoryChildrenUnread($line["id"]); |
|
593 | 593 | |
594 | - if ($unread || !$unread_only) { |
|
595 | - $row = array( |
|
596 | - "id" => (int) $line["id"], |
|
597 | - "title" => $line["title"], |
|
598 | - "unread" => $unread, |
|
599 | - "is_cat" => true, |
|
594 | + if ($unread || !$unread_only) { |
|
595 | + $row = array( |
|
596 | + "id" => (int) $line["id"], |
|
597 | + "title" => $line["title"], |
|
598 | + "unread" => $unread, |
|
599 | + "is_cat" => true, |
|
600 | 600 | "order_id" => (int) $line["order_id"] |
601 | - ); |
|
602 | - array_push($feeds, $row); |
|
603 | - } |
|
604 | - } |
|
605 | - } |
|
606 | - |
|
607 | - /* Real feeds */ |
|
608 | - |
|
609 | - if ($limit) { |
|
610 | - $limit_qpart = "LIMIT $limit OFFSET $offset"; |
|
611 | - } else { |
|
612 | - $limit_qpart = ""; |
|
613 | - } |
|
614 | - |
|
615 | - /* API only: -3 All feeds, excluding virtual feeds (e.g. Labels and such) */ |
|
616 | - if ($cat_id == -4 || $cat_id == -3) { |
|
617 | - $sth = $pdo->prepare("SELECT |
|
601 | + ); |
|
602 | + array_push($feeds, $row); |
|
603 | + } |
|
604 | + } |
|
605 | + } |
|
606 | + |
|
607 | + /* Real feeds */ |
|
608 | + |
|
609 | + if ($limit) { |
|
610 | + $limit_qpart = "LIMIT $limit OFFSET $offset"; |
|
611 | + } else { |
|
612 | + $limit_qpart = ""; |
|
613 | + } |
|
614 | + |
|
615 | + /* API only: -3 All feeds, excluding virtual feeds (e.g. Labels and such) */ |
|
616 | + if ($cat_id == -4 || $cat_id == -3) { |
|
617 | + $sth = $pdo->prepare("SELECT |
|
618 | 618 | id, feed_url, cat_id, title, order_id, ". |
619 | - SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated |
|
619 | + SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated |
|
620 | 620 | FROM ttrss_feeds WHERE owner_uid = ? |
621 | 621 | ORDER BY order_id, title " . $limit_qpart); |
622 | - $sth->execute([$_SESSION['uid']]); |
|
622 | + $sth->execute([$_SESSION['uid']]); |
|
623 | 623 | |
624 | - } else { |
|
624 | + } else { |
|
625 | 625 | |
626 | - $sth = $pdo->prepare("SELECT |
|
626 | + $sth = $pdo->prepare("SELECT |
|
627 | 627 | id, feed_url, cat_id, title, order_id, ". |
628 | - SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated |
|
628 | + SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated |
|
629 | 629 | FROM ttrss_feeds WHERE |
630 | 630 | (cat_id = :cat OR (:cat = 0 AND cat_id IS NULL)) |
631 | 631 | AND owner_uid = :uid |
632 | 632 | ORDER BY order_id, title " . $limit_qpart); |
633 | - $sth->execute([":uid" => $_SESSION['uid'], ":cat" => $cat_id]); |
|
634 | - } |
|
633 | + $sth->execute([":uid" => $_SESSION['uid'], ":cat" => $cat_id]); |
|
634 | + } |
|
635 | 635 | |
636 | - while ($line = $sth->fetch()) { |
|
636 | + while ($line = $sth->fetch()) { |
|
637 | 637 | |
638 | - $unread = getFeedUnread($line["id"]); |
|
638 | + $unread = getFeedUnread($line["id"]); |
|
639 | 639 | |
640 | - $has_icon = Feeds::feedHasIcon($line['id']); |
|
640 | + $has_icon = Feeds::feedHasIcon($line['id']); |
|
641 | 641 | |
642 | - if ($unread || !$unread_only) { |
|
642 | + if ($unread || !$unread_only) { |
|
643 | 643 | |
644 | - $row = array( |
|
645 | - "feed_url" => $line["feed_url"], |
|
646 | - "title" => $line["title"], |
|
647 | - "id" => (int)$line["id"], |
|
648 | - "unread" => (int)$unread, |
|
649 | - "has_icon" => $has_icon, |
|
650 | - "cat_id" => (int)$line["cat_id"], |
|
651 | - "last_updated" => (int) strtotime($line["last_updated"]), |
|
652 | - "order_id" => (int) $line["order_id"], |
|
653 | - ); |
|
644 | + $row = array( |
|
645 | + "feed_url" => $line["feed_url"], |
|
646 | + "title" => $line["title"], |
|
647 | + "id" => (int)$line["id"], |
|
648 | + "unread" => (int)$unread, |
|
649 | + "has_icon" => $has_icon, |
|
650 | + "cat_id" => (int)$line["cat_id"], |
|
651 | + "last_updated" => (int) strtotime($line["last_updated"]), |
|
652 | + "order_id" => (int) $line["order_id"], |
|
653 | + ); |
|
654 | 654 | |
655 | - array_push($feeds, $row); |
|
656 | - } |
|
657 | - } |
|
655 | + array_push($feeds, $row); |
|
656 | + } |
|
657 | + } |
|
658 | 658 | |
659 | - return $feeds; |
|
660 | - } |
|
659 | + return $feeds; |
|
660 | + } |
|
661 | 661 | |
662 | - /** |
|
663 | - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
664 | - */ |
|
665 | - public static function api_get_headlines($feed_id, $limit, $offset, |
|
666 | - $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order, |
|
667 | - $include_attachments, $since_id, |
|
668 | - $search = "", $include_nested = false, $sanitize_content = true, |
|
669 | - $force_update = false, $excerpt_length = 100, $check_first_id = false, $skip_first_id_check = false) { |
|
662 | + /** |
|
663 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
664 | + */ |
|
665 | + public static function api_get_headlines($feed_id, $limit, $offset, |
|
666 | + $filter, $is_cat, $show_excerpt, $show_content, $view_mode, $order, |
|
667 | + $include_attachments, $since_id, |
|
668 | + $search = "", $include_nested = false, $sanitize_content = true, |
|
669 | + $force_update = false, $excerpt_length = 100, $check_first_id = false, $skip_first_id_check = false) { |
|
670 | 670 | |
671 | - $pdo = Db::pdo(); |
|
671 | + $pdo = Db::pdo(); |
|
672 | 672 | |
673 | - if ($force_update && $feed_id > 0 && is_numeric($feed_id)) { |
|
674 | - // Update the feed if required with some basic flood control |
|
673 | + if ($force_update && $feed_id > 0 && is_numeric($feed_id)) { |
|
674 | + // Update the feed if required with some basic flood control |
|
675 | 675 | |
676 | - $sth = $pdo->prepare( |
|
677 | - "SELECT cache_images,".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated |
|
676 | + $sth = $pdo->prepare( |
|
677 | + "SELECT cache_images,".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated |
|
678 | 678 | FROM ttrss_feeds WHERE id = ?"); |
679 | - $sth->execute([$feed_id]); |
|
679 | + $sth->execute([$feed_id]); |
|
680 | 680 | |
681 | - if ($row = $sth->fetch()) { |
|
682 | - $last_updated = strtotime($row["last_updated"]); |
|
683 | - $cache_images = API::param_to_bool($row["cache_images"]); |
|
681 | + if ($row = $sth->fetch()) { |
|
682 | + $last_updated = strtotime($row["last_updated"]); |
|
683 | + $cache_images = API::param_to_bool($row["cache_images"]); |
|
684 | 684 | |
685 | - if (!$cache_images && time() - $last_updated > 120) { |
|
686 | - RSSUtils::update_rss_feed($feed_id, true); |
|
687 | - } else { |
|
688 | - $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01' |
|
685 | + if (!$cache_images && time() - $last_updated > 120) { |
|
686 | + RSSUtils::update_rss_feed($feed_id, true); |
|
687 | + } else { |
|
688 | + $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_updated = '1970-01-01', last_update_started = '1970-01-01' |
|
689 | 689 | WHERE id = ?"); |
690 | - $sth->execute([$feed_id]); |
|
691 | - } |
|
692 | - } |
|
693 | - } |
|
694 | - |
|
695 | - $params = array( |
|
696 | - "feed" => $feed_id, |
|
697 | - "limit" => $limit, |
|
698 | - "view_mode" => $view_mode, |
|
699 | - "cat_view" => $is_cat, |
|
700 | - "search" => $search, |
|
701 | - "override_order" => $order, |
|
702 | - "offset" => $offset, |
|
703 | - "since_id" => $since_id, |
|
704 | - "include_children" => $include_nested, |
|
705 | - "check_first_id" => $check_first_id, |
|
706 | - "skip_first_id_check" => $skip_first_id_check |
|
707 | - ); |
|
708 | - |
|
709 | - $qfh_ret = Feeds::queryFeedHeadlines($params); |
|
710 | - |
|
711 | - $result = $qfh_ret[0]; |
|
712 | - $feed_title = $qfh_ret[1]; |
|
713 | - $first_id = $qfh_ret[6]; |
|
714 | - |
|
715 | - $headlines = array(); |
|
716 | - |
|
717 | - $headlines_header = array( |
|
718 | - 'id' => $feed_id, |
|
719 | - 'first_id' => $first_id, |
|
720 | - 'is_cat' => $is_cat); |
|
721 | - |
|
722 | - if (!is_numeric($result)) { |
|
723 | - while ($line = $result->fetch()) { |
|
724 | - $line["content_preview"] = truncate_string(strip_tags($line["content"]), $excerpt_length); |
|
725 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
726 | - $line = $p->hook_query_headlines($line, $excerpt_length, true); |
|
727 | - } |
|
728 | - |
|
729 | - $is_updated = ($line["last_read"] == "" && |
|
730 | - ($line["unread"] != "t" && $line["unread"] != "1")); |
|
731 | - |
|
732 | - $tags = explode(",", $line["tag_cache"]); |
|
733 | - |
|
734 | - $label_cache = $line["label_cache"]; |
|
735 | - $labels = false; |
|
736 | - |
|
737 | - if ($label_cache) { |
|
738 | - $label_cache = json_decode($label_cache, true); |
|
739 | - |
|
740 | - if ($label_cache) { |
|
741 | - if ($label_cache["no-labels"] == 1) |
|
742 | - $labels = array(); |
|
743 | - else |
|
744 | - $labels = $label_cache; |
|
745 | - } |
|
746 | - } |
|
747 | - |
|
748 | - if (!is_array($labels)) $labels = Article::get_article_labels($line["id"]); |
|
749 | - |
|
750 | - $headline_row = array( |
|
751 | - "id" => (int)$line["id"], |
|
752 | - "guid" => $line["guid"], |
|
753 | - "unread" => API::param_to_bool($line["unread"]), |
|
754 | - "marked" => API::param_to_bool($line["marked"]), |
|
755 | - "published" => API::param_to_bool($line["published"]), |
|
756 | - "updated" => (int)strtotime($line["updated"]), |
|
757 | - "is_updated" => $is_updated, |
|
758 | - "title" => $line["title"], |
|
759 | - "link" => $line["link"], |
|
760 | - "feed_id" => $line["feed_id"] ? $line['feed_id'] : 0, |
|
761 | - "tags" => $tags, |
|
762 | - ); |
|
763 | - |
|
764 | - $enclosures = Article::get_article_enclosures($line['id']); |
|
765 | - |
|
766 | - if ($include_attachments) |
|
767 | - $headline_row['attachments'] = $enclosures; |
|
768 | - |
|
769 | - if ($show_excerpt) |
|
770 | - $headline_row["excerpt"] = $line["content_preview"]; |
|
771 | - |
|
772 | - if ($show_content) { |
|
773 | - |
|
774 | - if ($sanitize_content) { |
|
775 | - $headline_row["content"] = sanitize( |
|
776 | - $line["content"], |
|
777 | - API::param_to_bool($line['hide_images']), |
|
778 | - false, $line["site_url"], false, $line["id"]); |
|
779 | - } else { |
|
780 | - $headline_row["content"] = $line["content"]; |
|
781 | - } |
|
782 | - } |
|
783 | - |
|
784 | - // unify label output to ease parsing |
|
785 | - if ($labels["no-labels"] == 1) $labels = array(); |
|
786 | - |
|
787 | - $headline_row["labels"] = $labels; |
|
788 | - |
|
789 | - $headline_row["feed_title"] = $line["feed_title"] ? $line["feed_title"] : |
|
790 | - $feed_title; |
|
791 | - |
|
792 | - $headline_row["comments_count"] = (int)$line["num_comments"]; |
|
793 | - $headline_row["comments_link"] = $line["comments"]; |
|
690 | + $sth->execute([$feed_id]); |
|
691 | + } |
|
692 | + } |
|
693 | + } |
|
694 | + |
|
695 | + $params = array( |
|
696 | + "feed" => $feed_id, |
|
697 | + "limit" => $limit, |
|
698 | + "view_mode" => $view_mode, |
|
699 | + "cat_view" => $is_cat, |
|
700 | + "search" => $search, |
|
701 | + "override_order" => $order, |
|
702 | + "offset" => $offset, |
|
703 | + "since_id" => $since_id, |
|
704 | + "include_children" => $include_nested, |
|
705 | + "check_first_id" => $check_first_id, |
|
706 | + "skip_first_id_check" => $skip_first_id_check |
|
707 | + ); |
|
708 | + |
|
709 | + $qfh_ret = Feeds::queryFeedHeadlines($params); |
|
710 | + |
|
711 | + $result = $qfh_ret[0]; |
|
712 | + $feed_title = $qfh_ret[1]; |
|
713 | + $first_id = $qfh_ret[6]; |
|
714 | + |
|
715 | + $headlines = array(); |
|
716 | + |
|
717 | + $headlines_header = array( |
|
718 | + 'id' => $feed_id, |
|
719 | + 'first_id' => $first_id, |
|
720 | + 'is_cat' => $is_cat); |
|
721 | + |
|
722 | + if (!is_numeric($result)) { |
|
723 | + while ($line = $result->fetch()) { |
|
724 | + $line["content_preview"] = truncate_string(strip_tags($line["content"]), $excerpt_length); |
|
725 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
726 | + $line = $p->hook_query_headlines($line, $excerpt_length, true); |
|
727 | + } |
|
728 | + |
|
729 | + $is_updated = ($line["last_read"] == "" && |
|
730 | + ($line["unread"] != "t" && $line["unread"] != "1")); |
|
731 | + |
|
732 | + $tags = explode(",", $line["tag_cache"]); |
|
733 | + |
|
734 | + $label_cache = $line["label_cache"]; |
|
735 | + $labels = false; |
|
736 | + |
|
737 | + if ($label_cache) { |
|
738 | + $label_cache = json_decode($label_cache, true); |
|
739 | + |
|
740 | + if ($label_cache) { |
|
741 | + if ($label_cache["no-labels"] == 1) |
|
742 | + $labels = array(); |
|
743 | + else |
|
744 | + $labels = $label_cache; |
|
745 | + } |
|
746 | + } |
|
747 | + |
|
748 | + if (!is_array($labels)) $labels = Article::get_article_labels($line["id"]); |
|
749 | + |
|
750 | + $headline_row = array( |
|
751 | + "id" => (int)$line["id"], |
|
752 | + "guid" => $line["guid"], |
|
753 | + "unread" => API::param_to_bool($line["unread"]), |
|
754 | + "marked" => API::param_to_bool($line["marked"]), |
|
755 | + "published" => API::param_to_bool($line["published"]), |
|
756 | + "updated" => (int)strtotime($line["updated"]), |
|
757 | + "is_updated" => $is_updated, |
|
758 | + "title" => $line["title"], |
|
759 | + "link" => $line["link"], |
|
760 | + "feed_id" => $line["feed_id"] ? $line['feed_id'] : 0, |
|
761 | + "tags" => $tags, |
|
762 | + ); |
|
763 | + |
|
764 | + $enclosures = Article::get_article_enclosures($line['id']); |
|
765 | + |
|
766 | + if ($include_attachments) |
|
767 | + $headline_row['attachments'] = $enclosures; |
|
768 | + |
|
769 | + if ($show_excerpt) |
|
770 | + $headline_row["excerpt"] = $line["content_preview"]; |
|
771 | + |
|
772 | + if ($show_content) { |
|
773 | + |
|
774 | + if ($sanitize_content) { |
|
775 | + $headline_row["content"] = sanitize( |
|
776 | + $line["content"], |
|
777 | + API::param_to_bool($line['hide_images']), |
|
778 | + false, $line["site_url"], false, $line["id"]); |
|
779 | + } else { |
|
780 | + $headline_row["content"] = $line["content"]; |
|
781 | + } |
|
782 | + } |
|
783 | + |
|
784 | + // unify label output to ease parsing |
|
785 | + if ($labels["no-labels"] == 1) $labels = array(); |
|
786 | + |
|
787 | + $headline_row["labels"] = $labels; |
|
788 | + |
|
789 | + $headline_row["feed_title"] = $line["feed_title"] ? $line["feed_title"] : |
|
790 | + $feed_title; |
|
791 | + |
|
792 | + $headline_row["comments_count"] = (int)$line["num_comments"]; |
|
793 | + $headline_row["comments_link"] = $line["comments"]; |
|
794 | 794 | |
795 | - $headline_row["always_display_attachments"] = API::param_to_bool($line["always_display_enclosures"]); |
|
795 | + $headline_row["always_display_attachments"] = API::param_to_bool($line["always_display_enclosures"]); |
|
796 | 796 | |
797 | - $headline_row["author"] = $line["author"]; |
|
797 | + $headline_row["author"] = $line["author"]; |
|
798 | 798 | |
799 | - $headline_row["score"] = (int)$line["score"]; |
|
800 | - $headline_row["note"] = $line["note"]; |
|
801 | - $headline_row["lang"] = $line["lang"]; |
|
799 | + $headline_row["score"] = (int)$line["score"]; |
|
800 | + $headline_row["note"] = $line["note"]; |
|
801 | + $headline_row["lang"] = $line["lang"]; |
|
802 | 802 | |
803 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_API) as $p) { |
|
804 | - $headline_row = $p->hook_render_article_api(array("headline" => $headline_row)); |
|
805 | - } |
|
803 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_API) as $p) { |
|
804 | + $headline_row = $p->hook_render_article_api(array("headline" => $headline_row)); |
|
805 | + } |
|
806 | 806 | |
807 | - $headline_row["content"] = DiskCache::rewriteUrls($headline_row['content']); |
|
807 | + $headline_row["content"] = DiskCache::rewriteUrls($headline_row['content']); |
|
808 | 808 | |
809 | - list ($flavor_image, $flavor_stream) = Article::get_article_image($enclosures, $line["content"], $line["site_url"]); |
|
809 | + list ($flavor_image, $flavor_stream) = Article::get_article_image($enclosures, $line["content"], $line["site_url"]); |
|
810 | 810 | |
811 | - $headline_row["flavor_image"] = $flavor_image; |
|
812 | - $headline_row["flavor_stream"] = $flavor_stream; |
|
811 | + $headline_row["flavor_image"] = $flavor_image; |
|
812 | + $headline_row["flavor_stream"] = $flavor_stream; |
|
813 | 813 | |
814 | - array_push($headlines, $headline_row); |
|
815 | - } |
|
816 | - } else if (is_numeric($result) && $result == -1) { |
|
817 | - $headlines_header['first_id_changed'] = true; |
|
818 | - } |
|
814 | + array_push($headlines, $headline_row); |
|
815 | + } |
|
816 | + } else if (is_numeric($result) && $result == -1) { |
|
817 | + $headlines_header['first_id_changed'] = true; |
|
818 | + } |
|
819 | 819 | |
820 | - return array($headlines, $headlines_header); |
|
821 | - } |
|
820 | + return array($headlines, $headlines_header); |
|
821 | + } |
|
822 | 822 | |
823 | - public function unsubscribeFeed() { |
|
824 | - $feed_id = (int) clean($_REQUEST["feed_id"]); |
|
823 | + public function unsubscribeFeed() { |
|
824 | + $feed_id = (int) clean($_REQUEST["feed_id"]); |
|
825 | 825 | |
826 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
826 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
827 | 827 | id = ? AND owner_uid = ?"); |
828 | - $sth->execute([$feed_id, $_SESSION['uid']]); |
|
829 | - |
|
830 | - if ($sth->fetch()) { |
|
831 | - Pref_Feeds::remove_feed($feed_id, $_SESSION["uid"]); |
|
832 | - $this->wrap(self::STATUS_OK, array("status" => "OK")); |
|
833 | - } else { |
|
834 | - $this->wrap(self::STATUS_ERR, array("error" => "FEED_NOT_FOUND")); |
|
835 | - } |
|
836 | - } |
|
837 | - |
|
838 | - public function subscribeToFeed() { |
|
839 | - $feed_url = clean($_REQUEST["feed_url"]); |
|
840 | - $category_id = (int) clean($_REQUEST["category_id"]); |
|
841 | - $login = clean($_REQUEST["login"]); |
|
842 | - $password = clean($_REQUEST["password"]); |
|
843 | - |
|
844 | - if ($feed_url) { |
|
845 | - $rc = Feeds::subscribe_to_feed($feed_url, $category_id, $login, $password); |
|
846 | - |
|
847 | - $this->wrap(self::STATUS_OK, array("status" => $rc)); |
|
848 | - } else { |
|
849 | - $this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE')); |
|
850 | - } |
|
851 | - } |
|
852 | - |
|
853 | - public function getFeedTree() { |
|
854 | - $include_empty = API::param_to_bool(clean($_REQUEST['include_empty'])); |
|
855 | - |
|
856 | - $pf = new Pref_Feeds($_REQUEST); |
|
857 | - |
|
858 | - $_REQUEST['mode'] = 2; |
|
859 | - $_REQUEST['force_show_empty'] = $include_empty; |
|
860 | - |
|
861 | - if ($pf){ |
|
862 | - $data = $pf->makefeedtree(); |
|
863 | - $this->wrap(self::STATUS_OK, array("categories" => $data)); |
|
864 | - } else { |
|
865 | - $this->wrap(self::STATUS_ERR, array("error" => |
|
866 | - 'UNABLE_TO_INSTANTIATE_OBJECT')); |
|
867 | - } |
|
868 | - |
|
869 | - } |
|
870 | - |
|
871 | - // only works for labels or uncategorized for the time being |
|
872 | - private function isCategoryEmpty($id) { |
|
873 | - |
|
874 | - if ($id == -2) { |
|
875 | - $sth = $this->pdo->prepare("SELECT COUNT(id) AS count FROM ttrss_labels2 |
|
828 | + $sth->execute([$feed_id, $_SESSION['uid']]); |
|
829 | + |
|
830 | + if ($sth->fetch()) { |
|
831 | + Pref_Feeds::remove_feed($feed_id, $_SESSION["uid"]); |
|
832 | + $this->wrap(self::STATUS_OK, array("status" => "OK")); |
|
833 | + } else { |
|
834 | + $this->wrap(self::STATUS_ERR, array("error" => "FEED_NOT_FOUND")); |
|
835 | + } |
|
836 | + } |
|
837 | + |
|
838 | + public function subscribeToFeed() { |
|
839 | + $feed_url = clean($_REQUEST["feed_url"]); |
|
840 | + $category_id = (int) clean($_REQUEST["category_id"]); |
|
841 | + $login = clean($_REQUEST["login"]); |
|
842 | + $password = clean($_REQUEST["password"]); |
|
843 | + |
|
844 | + if ($feed_url) { |
|
845 | + $rc = Feeds::subscribe_to_feed($feed_url, $category_id, $login, $password); |
|
846 | + |
|
847 | + $this->wrap(self::STATUS_OK, array("status" => $rc)); |
|
848 | + } else { |
|
849 | + $this->wrap(self::STATUS_ERR, array("error" => 'INCORRECT_USAGE')); |
|
850 | + } |
|
851 | + } |
|
852 | + |
|
853 | + public function getFeedTree() { |
|
854 | + $include_empty = API::param_to_bool(clean($_REQUEST['include_empty'])); |
|
855 | + |
|
856 | + $pf = new Pref_Feeds($_REQUEST); |
|
857 | + |
|
858 | + $_REQUEST['mode'] = 2; |
|
859 | + $_REQUEST['force_show_empty'] = $include_empty; |
|
860 | + |
|
861 | + if ($pf){ |
|
862 | + $data = $pf->makefeedtree(); |
|
863 | + $this->wrap(self::STATUS_OK, array("categories" => $data)); |
|
864 | + } else { |
|
865 | + $this->wrap(self::STATUS_ERR, array("error" => |
|
866 | + 'UNABLE_TO_INSTANTIATE_OBJECT')); |
|
867 | + } |
|
868 | + |
|
869 | + } |
|
870 | + |
|
871 | + // only works for labels or uncategorized for the time being |
|
872 | + private function isCategoryEmpty($id) { |
|
873 | + |
|
874 | + if ($id == -2) { |
|
875 | + $sth = $this->pdo->prepare("SELECT COUNT(id) AS count FROM ttrss_labels2 |
|
876 | 876 | WHERE owner_uid = ?"); |
877 | - $sth->execute([$_SESSION['uid']]); |
|
878 | - $row = $sth->fetch(); |
|
877 | + $sth->execute([$_SESSION['uid']]); |
|
878 | + $row = $sth->fetch(); |
|
879 | 879 | |
880 | - return $row["count"] == 0; |
|
880 | + return $row["count"] == 0; |
|
881 | 881 | |
882 | - } else if ($id == 0) { |
|
883 | - $sth = $this->pdo->prepare("SELECT COUNT(id) AS count FROM ttrss_feeds |
|
882 | + } else if ($id == 0) { |
|
883 | + $sth = $this->pdo->prepare("SELECT COUNT(id) AS count FROM ttrss_feeds |
|
884 | 884 | WHERE cat_id IS NULL AND owner_uid = ?"); |
885 | - $sth->execute([$_SESSION['uid']]); |
|
886 | - $row = $sth->fetch(); |
|
885 | + $sth->execute([$_SESSION['uid']]); |
|
886 | + $row = $sth->fetch(); |
|
887 | 887 | |
888 | - return $row["count"] == 0; |
|
888 | + return $row["count"] == 0; |
|
889 | 889 | |
890 | - } |
|
890 | + } |
|
891 | 891 | |
892 | - return false; |
|
893 | - } |
|
892 | + return false; |
|
893 | + } |
|
894 | 894 | |
895 | 895 | |
896 | 896 | } |
@@ -2,59 +2,59 @@ |
||
2 | 2 | |
3 | 3 | abstract class Plugin { |
4 | 4 | |
5 | - const API_VERSION_COMPAT = 1; |
|
5 | + const API_VERSION_COMPAT = 1; |
|
6 | 6 | |
7 | - /** |
|
8 | - * @var PDO |
|
9 | - */ |
|
10 | - protected $pdo; |
|
7 | + /** |
|
8 | + * @var PDO |
|
9 | + */ |
|
10 | + protected $pdo; |
|
11 | 11 | |
12 | - abstract function init(PluginHost $host); |
|
12 | + abstract function init(PluginHost $host); |
|
13 | 13 | |
14 | - /** |
|
15 | - * @return array(version, name, description, author, false) |
|
16 | - */ |
|
17 | - abstract function about(); |
|
14 | + /** |
|
15 | + * @return array(version, name, description, author, false) |
|
16 | + */ |
|
17 | + abstract function about(); |
|
18 | 18 | |
19 | - public function __construct() { |
|
20 | - $this->pdo = Db::pdo(); |
|
21 | - } |
|
19 | + public function __construct() { |
|
20 | + $this->pdo = Db::pdo(); |
|
21 | + } |
|
22 | 22 | |
23 | - public function flags() { |
|
24 | - /* associative array, possible keys: |
|
23 | + public function flags() { |
|
24 | + /* associative array, possible keys: |
|
25 | 25 | needs_curl = boolean |
26 | 26 | */ |
27 | - return array(); |
|
28 | - } |
|
27 | + return array(); |
|
28 | + } |
|
29 | 29 | |
30 | - public function is_public_method() { |
|
31 | - return false; |
|
32 | - } |
|
30 | + public function is_public_method() { |
|
31 | + return false; |
|
32 | + } |
|
33 | 33 | |
34 | - public function get_js() { |
|
35 | - return ""; |
|
36 | - } |
|
34 | + public function get_js() { |
|
35 | + return ""; |
|
36 | + } |
|
37 | 37 | |
38 | - public function get_prefs_js() { |
|
39 | - return ""; |
|
40 | - } |
|
38 | + public function get_prefs_js() { |
|
39 | + return ""; |
|
40 | + } |
|
41 | 41 | |
42 | - public function api_version() { |
|
43 | - return Plugin::API_VERSION_COMPAT; |
|
44 | - } |
|
42 | + public function api_version() { |
|
43 | + return Plugin::API_VERSION_COMPAT; |
|
44 | + } |
|
45 | 45 | |
46 | - public function __($msgid) { |
|
47 | - return _dgettext(PluginHost::object_to_domain($this), $msgid); |
|
48 | - } |
|
46 | + public function __($msgid) { |
|
47 | + return _dgettext(PluginHost::object_to_domain($this), $msgid); |
|
48 | + } |
|
49 | 49 | |
50 | - public function _ngettext($singular, $plural, $number) { |
|
51 | - return _dngettext(PluginHost::object_to_domain($this), $singular, $plural, $number); |
|
52 | - } |
|
50 | + public function _ngettext($singular, $plural, $number) { |
|
51 | + return _dngettext(PluginHost::object_to_domain($this), $singular, $plural, $number); |
|
52 | + } |
|
53 | 53 | |
54 | - public function T_sprintf() { |
|
55 | - $args = func_get_args(); |
|
56 | - $msgid = array_shift($args); |
|
54 | + public function T_sprintf() { |
|
55 | + $args = func_get_args(); |
|
56 | + $msgid = array_shift($args); |
|
57 | 57 | |
58 | - return vsprintf($this->__($msgid), $args); |
|
59 | - } |
|
58 | + return vsprintf($this->__($msgid), $args); |
|
59 | + } |
|
60 | 60 | } |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | class Handler_Protected extends Handler { |
3 | 3 | |
4 | - public function before($method) { |
|
5 | - return parent::before($method) && $_SESSION['uid']; |
|
6 | - } |
|
4 | + public function before($method) { |
|
5 | + return parent::before($method) && $_SESSION['uid']; |
|
6 | + } |
|
7 | 7 | } |
@@ -1,329 +1,329 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class Handler_Public extends Handler { |
3 | 3 | |
4 | - private function generate_syndicated_feed($owner_uid, $feed, $is_cat, |
|
5 | - $limit, $offset, $search, |
|
6 | - $view_mode = false, $format = 'atom', $order = false, $orig_guid = false, $start_ts = false) { |
|
4 | + private function generate_syndicated_feed($owner_uid, $feed, $is_cat, |
|
5 | + $limit, $offset, $search, |
|
6 | + $view_mode = false, $format = 'atom', $order = false, $orig_guid = false, $start_ts = false) { |
|
7 | 7 | |
8 | - require_once "lib/MiniTemplator.class.php"; |
|
8 | + require_once "lib/MiniTemplator.class.php"; |
|
9 | 9 | |
10 | - $note_style = "background-color : #fff7d5; |
|
10 | + $note_style = "background-color : #fff7d5; |
|
11 | 11 | border-width : 1px; ". |
12 | - "padding : 5px; border-style : dashed; border-color : #e7d796;". |
|
13 | - "margin-bottom : 1em; color : #9a8c59;"; |
|
14 | - |
|
15 | - if (!$limit) $limit = 60; |
|
16 | - |
|
17 | - $date_sort_field = "date_entered DESC, updated DESC"; |
|
18 | - |
|
19 | - if ($feed == -2 && !$is_cat) { |
|
20 | - $date_sort_field = "last_published DESC"; |
|
21 | - } else if ($feed == -1 && !$is_cat) { |
|
22 | - $date_sort_field = "last_marked DESC"; |
|
23 | - } |
|
24 | - |
|
25 | - switch ($order) { |
|
26 | - case "title": |
|
27 | - $date_sort_field = "ttrss_entries.title, date_entered, updated"; |
|
28 | - break; |
|
29 | - case "date_reverse": |
|
30 | - $date_sort_field = "date_entered, updated"; |
|
31 | - break; |
|
32 | - case "feed_dates": |
|
33 | - $date_sort_field = "updated DESC"; |
|
34 | - break; |
|
35 | - } |
|
36 | - |
|
37 | - $params = array( |
|
38 | - "owner_uid" => $owner_uid, |
|
39 | - "feed" => $feed, |
|
40 | - "limit" => $limit, |
|
41 | - "view_mode" => $view_mode, |
|
42 | - "cat_view" => $is_cat, |
|
43 | - "search" => $search, |
|
44 | - "override_order" => $date_sort_field, |
|
45 | - "include_children" => true, |
|
46 | - "ignore_vfeed_group" => true, |
|
47 | - "offset" => $offset, |
|
48 | - "start_ts" => $start_ts |
|
49 | - ); |
|
50 | - |
|
51 | - if (!$is_cat && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) { |
|
52 | - |
|
53 | - $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); |
|
54 | - |
|
55 | - $tmppluginhost = new PluginHost(); |
|
56 | - $tmppluginhost->load(PLUGINS, PluginHost::KIND_ALL); |
|
57 | - $tmppluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); |
|
58 | - $tmppluginhost->load_data(); |
|
59 | - |
|
60 | - $handler = $tmppluginhost->get_feed_handler( |
|
61 | - PluginHost::feed_to_pfeed_id($feed)); |
|
62 | - |
|
63 | - if ($handler) { |
|
64 | - $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed), $params); |
|
65 | - } |
|
66 | - |
|
67 | - } else { |
|
68 | - $qfh_ret = Feeds::queryFeedHeadlines($params); |
|
69 | - } |
|
70 | - |
|
71 | - $result = $qfh_ret[0]; |
|
72 | - $feed_title = htmlspecialchars($qfh_ret[1]); |
|
73 | - $feed_site_url = $qfh_ret[2]; |
|
74 | - /* $last_error = $qfh_ret[3]; */ |
|
75 | - |
|
76 | - $feed_self_url = get_self_url_prefix() . |
|
77 | - "/public.php?op=rss&id=$feed&key=" . |
|
78 | - Feeds::get_feed_access_key($feed, false, $owner_uid); |
|
79 | - |
|
80 | - if (!$feed_site_url) $feed_site_url = get_self_url_prefix(); |
|
81 | - |
|
82 | - if ($format == 'atom') { |
|
83 | - $tpl = new MiniTemplator; |
|
84 | - |
|
85 | - $tpl->readTemplateFromFile("templates/generated_feed.txt"); |
|
86 | - |
|
87 | - $tpl->setVariable('FEED_TITLE', $feed_title, true); |
|
88 | - $tpl->setVariable('VERSION', get_version(), true); |
|
89 | - $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true); |
|
90 | - |
|
91 | - $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true); |
|
92 | - while ($line = $result->fetch()) { |
|
93 | - |
|
94 | - $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content"]), 100, '...')); |
|
95 | - |
|
96 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
97 | - $line = $p->hook_query_headlines($line); |
|
98 | - } |
|
12 | + "padding : 5px; border-style : dashed; border-color : #e7d796;". |
|
13 | + "margin-bottom : 1em; color : #9a8c59;"; |
|
14 | + |
|
15 | + if (!$limit) $limit = 60; |
|
16 | + |
|
17 | + $date_sort_field = "date_entered DESC, updated DESC"; |
|
18 | + |
|
19 | + if ($feed == -2 && !$is_cat) { |
|
20 | + $date_sort_field = "last_published DESC"; |
|
21 | + } else if ($feed == -1 && !$is_cat) { |
|
22 | + $date_sort_field = "last_marked DESC"; |
|
23 | + } |
|
24 | + |
|
25 | + switch ($order) { |
|
26 | + case "title": |
|
27 | + $date_sort_field = "ttrss_entries.title, date_entered, updated"; |
|
28 | + break; |
|
29 | + case "date_reverse": |
|
30 | + $date_sort_field = "date_entered, updated"; |
|
31 | + break; |
|
32 | + case "feed_dates": |
|
33 | + $date_sort_field = "updated DESC"; |
|
34 | + break; |
|
35 | + } |
|
36 | + |
|
37 | + $params = array( |
|
38 | + "owner_uid" => $owner_uid, |
|
39 | + "feed" => $feed, |
|
40 | + "limit" => $limit, |
|
41 | + "view_mode" => $view_mode, |
|
42 | + "cat_view" => $is_cat, |
|
43 | + "search" => $search, |
|
44 | + "override_order" => $date_sort_field, |
|
45 | + "include_children" => true, |
|
46 | + "ignore_vfeed_group" => true, |
|
47 | + "offset" => $offset, |
|
48 | + "start_ts" => $start_ts |
|
49 | + ); |
|
50 | + |
|
51 | + if (!$is_cat && is_numeric($feed) && $feed < PLUGIN_FEED_BASE_INDEX && $feed > LABEL_BASE_INDEX) { |
|
52 | + |
|
53 | + $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid); |
|
54 | + |
|
55 | + $tmppluginhost = new PluginHost(); |
|
56 | + $tmppluginhost->load(PLUGINS, PluginHost::KIND_ALL); |
|
57 | + $tmppluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid); |
|
58 | + $tmppluginhost->load_data(); |
|
59 | + |
|
60 | + $handler = $tmppluginhost->get_feed_handler( |
|
61 | + PluginHost::feed_to_pfeed_id($feed)); |
|
62 | + |
|
63 | + if ($handler) { |
|
64 | + $qfh_ret = $handler->get_headlines(PluginHost::feed_to_pfeed_id($feed), $params); |
|
65 | + } |
|
99 | 66 | |
100 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) { |
|
101 | - $line = $p->hook_article_export_feed($line, $feed, $is_cat); |
|
102 | - } |
|
67 | + } else { |
|
68 | + $qfh_ret = Feeds::queryFeedHeadlines($params); |
|
69 | + } |
|
103 | 70 | |
104 | - $tpl->setVariable('ARTICLE_ID', |
|
105 | - htmlspecialchars($orig_guid ? $line['link'] : |
|
106 | - $this->make_article_tag_uri($line['id'], $line['date_entered'])), true); |
|
107 | - $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true); |
|
108 | - $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true); |
|
109 | - $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true); |
|
71 | + $result = $qfh_ret[0]; |
|
72 | + $feed_title = htmlspecialchars($qfh_ret[1]); |
|
73 | + $feed_site_url = $qfh_ret[2]; |
|
74 | + /* $last_error = $qfh_ret[3]; */ |
|
110 | 75 | |
111 | - $content = sanitize($line["content"], false, $owner_uid, |
|
112 | - $feed_site_url, false, $line["id"]); |
|
76 | + $feed_self_url = get_self_url_prefix() . |
|
77 | + "/public.php?op=rss&id=$feed&key=" . |
|
78 | + Feeds::get_feed_access_key($feed, false, $owner_uid); |
|
113 | 79 | |
114 | - if ($line['note']) { |
|
115 | - $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" . |
|
116 | - $content; |
|
117 | - $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true); |
|
118 | - } |
|
80 | + if (!$feed_site_url) $feed_site_url = get_self_url_prefix(); |
|
119 | 81 | |
120 | - $tpl->setVariable('ARTICLE_CONTENT', $content, true); |
|
82 | + if ($format == 'atom') { |
|
83 | + $tpl = new MiniTemplator; |
|
121 | 84 | |
122 | - $tpl->setVariable('ARTICLE_UPDATED_ATOM', |
|
123 | - date('c', strtotime($line["updated"])), true); |
|
124 | - $tpl->setVariable('ARTICLE_UPDATED_RFC822', |
|
125 | - date(DATE_RFC822, strtotime($line["updated"])), true); |
|
85 | + $tpl->readTemplateFromFile("templates/generated_feed.txt"); |
|
126 | 86 | |
127 | - $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true); |
|
87 | + $tpl->setVariable('FEED_TITLE', $feed_title, true); |
|
88 | + $tpl->setVariable('VERSION', get_version(), true); |
|
89 | + $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true); |
|
128 | 90 | |
129 | - $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url'] ? $line["site_url"] : get_self_url_prefix()), true); |
|
130 | - $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ? $line['feed_title'] : $feed_title), true); |
|
91 | + $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true); |
|
92 | + while ($line = $result->fetch()) { |
|
131 | 93 | |
132 | - $tags = Article::get_article_tags($line["id"], $owner_uid); |
|
94 | + $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content"]), 100, '...')); |
|
133 | 95 | |
134 | - foreach ($tags as $tag) { |
|
135 | - $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true); |
|
136 | - $tpl->addBlock('category'); |
|
137 | - } |
|
96 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
97 | + $line = $p->hook_query_headlines($line); |
|
98 | + } |
|
138 | 99 | |
139 | - $enclosures = Article::get_article_enclosures($line["id"]); |
|
100 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) { |
|
101 | + $line = $p->hook_article_export_feed($line, $feed, $is_cat); |
|
102 | + } |
|
140 | 103 | |
141 | - if (count($enclosures) > 0) { |
|
142 | - foreach ($enclosures as $e) { |
|
143 | - $type = htmlspecialchars($e['content_type']); |
|
144 | - $url = htmlspecialchars($e['content_url']); |
|
145 | - $length = $e['duration'] ? $e['duration'] : 1; |
|
104 | + $tpl->setVariable('ARTICLE_ID', |
|
105 | + htmlspecialchars($orig_guid ? $line['link'] : |
|
106 | + $this->make_article_tag_uri($line['id'], $line['date_entered'])), true); |
|
107 | + $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true); |
|
108 | + $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true); |
|
109 | + $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true); |
|
146 | 110 | |
147 | - $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true); |
|
148 | - $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true); |
|
149 | - $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true); |
|
111 | + $content = sanitize($line["content"], false, $owner_uid, |
|
112 | + $feed_site_url, false, $line["id"]); |
|
150 | 113 | |
151 | - $tpl->addBlock('enclosure'); |
|
152 | - } |
|
153 | - } else { |
|
154 | - $tpl->setVariable('ARTICLE_ENCLOSURE_URL', null, true); |
|
155 | - $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', null, true); |
|
156 | - $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', null, true); |
|
157 | - } |
|
114 | + if ($line['note']) { |
|
115 | + $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" . |
|
116 | + $content; |
|
117 | + $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true); |
|
118 | + } |
|
158 | 119 | |
159 | - list ($og_image, $og_stream) = Article::get_article_image($enclosures, $line['content'], $feed_site_url); |
|
120 | + $tpl->setVariable('ARTICLE_CONTENT', $content, true); |
|
160 | 121 | |
161 | - $tpl->setVariable('ARTICLE_OG_IMAGE', $og_image, true); |
|
122 | + $tpl->setVariable('ARTICLE_UPDATED_ATOM', |
|
123 | + date('c', strtotime($line["updated"])), true); |
|
124 | + $tpl->setVariable('ARTICLE_UPDATED_RFC822', |
|
125 | + date(DATE_RFC822, strtotime($line["updated"])), true); |
|
162 | 126 | |
163 | - $tpl->addBlock('entry'); |
|
164 | - } |
|
127 | + $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true); |
|
165 | 128 | |
166 | - $tmp = ""; |
|
129 | + $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url'] ? $line["site_url"] : get_self_url_prefix()), true); |
|
130 | + $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ? $line['feed_title'] : $feed_title), true); |
|
167 | 131 | |
168 | - $tpl->addBlock('feed'); |
|
169 | - $tpl->generateOutputToString($tmp); |
|
132 | + $tags = Article::get_article_tags($line["id"], $owner_uid); |
|
170 | 133 | |
171 | - if (@!clean($_REQUEST["noxml"])) { |
|
172 | - header("Content-Type: text/xml; charset=utf-8"); |
|
173 | - } else { |
|
174 | - header("Content-Type: text/plain; charset=utf-8"); |
|
175 | - } |
|
134 | + foreach ($tags as $tag) { |
|
135 | + $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true); |
|
136 | + $tpl->addBlock('category'); |
|
137 | + } |
|
176 | 138 | |
177 | - print $tmp; |
|
178 | - } else if ($format == 'json') { |
|
139 | + $enclosures = Article::get_article_enclosures($line["id"]); |
|
179 | 140 | |
180 | - $feed = array(); |
|
141 | + if (count($enclosures) > 0) { |
|
142 | + foreach ($enclosures as $e) { |
|
143 | + $type = htmlspecialchars($e['content_type']); |
|
144 | + $url = htmlspecialchars($e['content_url']); |
|
145 | + $length = $e['duration'] ? $e['duration'] : 1; |
|
181 | 146 | |
182 | - $feed['title'] = $feed_title; |
|
183 | - $feed['feed_url'] = $feed_self_url; |
|
147 | + $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true); |
|
148 | + $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true); |
|
149 | + $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true); |
|
184 | 150 | |
185 | - $feed['self_url'] = get_self_url_prefix(); |
|
151 | + $tpl->addBlock('enclosure'); |
|
152 | + } |
|
153 | + } else { |
|
154 | + $tpl->setVariable('ARTICLE_ENCLOSURE_URL', null, true); |
|
155 | + $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', null, true); |
|
156 | + $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', null, true); |
|
157 | + } |
|
186 | 158 | |
187 | - $feed['articles'] = array(); |
|
159 | + list ($og_image, $og_stream) = Article::get_article_image($enclosures, $line['content'], $feed_site_url); |
|
188 | 160 | |
189 | - while ($line = $result->fetch()) { |
|
161 | + $tpl->setVariable('ARTICLE_OG_IMAGE', $og_image, true); |
|
190 | 162 | |
191 | - $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content_preview"]), 100, '...')); |
|
163 | + $tpl->addBlock('entry'); |
|
164 | + } |
|
192 | 165 | |
193 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
194 | - $line = $p->hook_query_headlines($line, 100); |
|
195 | - } |
|
166 | + $tmp = ""; |
|
196 | 167 | |
197 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) { |
|
198 | - $line = $p->hook_article_export_feed($line, $feed, $is_cat); |
|
199 | - } |
|
168 | + $tpl->addBlock('feed'); |
|
169 | + $tpl->generateOutputToString($tmp); |
|
200 | 170 | |
201 | - $article = array(); |
|
171 | + if (@!clean($_REQUEST["noxml"])) { |
|
172 | + header("Content-Type: text/xml; charset=utf-8"); |
|
173 | + } else { |
|
174 | + header("Content-Type: text/plain; charset=utf-8"); |
|
175 | + } |
|
202 | 176 | |
203 | - $article['id'] = $line['link']; |
|
204 | - $article['link'] = $line['link']; |
|
205 | - $article['title'] = $line['title']; |
|
206 | - $article['excerpt'] = $line["content_preview"]; |
|
207 | - $article['content'] = sanitize($line["content"], false, $owner_uid, $feed_site_url, false, $line["id"]); |
|
208 | - $article['updated'] = date('c', strtotime($line["updated"])); |
|
177 | + print $tmp; |
|
178 | + } else if ($format == 'json') { |
|
209 | 179 | |
210 | - if ($line['note']) $article['note'] = $line['note']; |
|
211 | - if ($article['author']) $article['author'] = $line['author']; |
|
180 | + $feed = array(); |
|
212 | 181 | |
213 | - $tags = Article::get_article_tags($line["id"], $owner_uid); |
|
182 | + $feed['title'] = $feed_title; |
|
183 | + $feed['feed_url'] = $feed_self_url; |
|
214 | 184 | |
215 | - if (count($tags) > 0) { |
|
216 | - $article['tags'] = array(); |
|
185 | + $feed['self_url'] = get_self_url_prefix(); |
|
217 | 186 | |
218 | - foreach ($tags as $tag) { |
|
219 | - array_push($article['tags'], $tag); |
|
220 | - } |
|
221 | - } |
|
187 | + $feed['articles'] = array(); |
|
222 | 188 | |
223 | - $enclosures = Article::get_article_enclosures($line["id"]); |
|
189 | + while ($line = $result->fetch()) { |
|
224 | 190 | |
225 | - if (count($enclosures) > 0) { |
|
226 | - $article['enclosures'] = array(); |
|
191 | + $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content_preview"]), 100, '...')); |
|
227 | 192 | |
228 | - foreach ($enclosures as $e) { |
|
229 | - $type = $e['content_type']; |
|
230 | - $url = $e['content_url']; |
|
231 | - $length = $e['duration']; |
|
193 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
|
194 | + $line = $p->hook_query_headlines($line, 100); |
|
195 | + } |
|
232 | 196 | |
233 | - array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length)); |
|
234 | - } |
|
235 | - } |
|
197 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_EXPORT_FEED) as $p) { |
|
198 | + $line = $p->hook_article_export_feed($line, $feed, $is_cat); |
|
199 | + } |
|
200 | + |
|
201 | + $article = array(); |
|
202 | + |
|
203 | + $article['id'] = $line['link']; |
|
204 | + $article['link'] = $line['link']; |
|
205 | + $article['title'] = $line['title']; |
|
206 | + $article['excerpt'] = $line["content_preview"]; |
|
207 | + $article['content'] = sanitize($line["content"], false, $owner_uid, $feed_site_url, false, $line["id"]); |
|
208 | + $article['updated'] = date('c', strtotime($line["updated"])); |
|
209 | + |
|
210 | + if ($line['note']) $article['note'] = $line['note']; |
|
211 | + if ($article['author']) $article['author'] = $line['author']; |
|
212 | + |
|
213 | + $tags = Article::get_article_tags($line["id"], $owner_uid); |
|
214 | + |
|
215 | + if (count($tags) > 0) { |
|
216 | + $article['tags'] = array(); |
|
236 | 217 | |
237 | - array_push($feed['articles'], $article); |
|
238 | - } |
|
218 | + foreach ($tags as $tag) { |
|
219 | + array_push($article['tags'], $tag); |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + $enclosures = Article::get_article_enclosures($line["id"]); |
|
239 | 224 | |
240 | - header("Content-Type: text/json; charset=utf-8"); |
|
241 | - print json_encode($feed); |
|
225 | + if (count($enclosures) > 0) { |
|
226 | + $article['enclosures'] = array(); |
|
242 | 227 | |
243 | - } else { |
|
244 | - header("Content-Type: text/plain; charset=utf-8"); |
|
245 | - print json_encode(array("error" => array("message" => "Unknown format"))); |
|
246 | - } |
|
247 | - } |
|
228 | + foreach ($enclosures as $e) { |
|
229 | + $type = $e['content_type']; |
|
230 | + $url = $e['content_url']; |
|
231 | + $length = $e['duration']; |
|
248 | 232 | |
249 | - public function getUnread() { |
|
250 | - $login = clean($_REQUEST["login"]); |
|
251 | - $fresh = clean($_REQUEST["fresh"]) == "1"; |
|
233 | + array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length)); |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + array_push($feed['articles'], $article); |
|
238 | + } |
|
252 | 239 | |
253 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?"); |
|
254 | - $sth->execute([$login]); |
|
240 | + header("Content-Type: text/json; charset=utf-8"); |
|
241 | + print json_encode($feed); |
|
255 | 242 | |
256 | - if ($row = $sth->fetch()) { |
|
257 | - $uid = $row["id"]; |
|
243 | + } else { |
|
244 | + header("Content-Type: text/plain; charset=utf-8"); |
|
245 | + print json_encode(array("error" => array("message" => "Unknown format"))); |
|
246 | + } |
|
247 | + } |
|
258 | 248 | |
259 | - print Feeds::getGlobalUnread($uid); |
|
249 | + public function getUnread() { |
|
250 | + $login = clean($_REQUEST["login"]); |
|
251 | + $fresh = clean($_REQUEST["fresh"]) == "1"; |
|
260 | 252 | |
261 | - if ($fresh) { |
|
262 | - print ";"; |
|
263 | - print Feeds::getFeedArticles(-3, false, true, $uid); |
|
264 | - } |
|
253 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?"); |
|
254 | + $sth->execute([$login]); |
|
255 | + |
|
256 | + if ($row = $sth->fetch()) { |
|
257 | + $uid = $row["id"]; |
|
258 | + |
|
259 | + print Feeds::getGlobalUnread($uid); |
|
260 | + |
|
261 | + if ($fresh) { |
|
262 | + print ";"; |
|
263 | + print Feeds::getFeedArticles(-3, false, true, $uid); |
|
264 | + } |
|
265 | 265 | |
266 | - } else { |
|
267 | - print "-1;User not found"; |
|
268 | - } |
|
269 | - } |
|
266 | + } else { |
|
267 | + print "-1;User not found"; |
|
268 | + } |
|
269 | + } |
|
270 | 270 | |
271 | - public function getProfiles() { |
|
272 | - $login = clean($_REQUEST["login"]); |
|
273 | - $rv = []; |
|
271 | + public function getProfiles() { |
|
272 | + $login = clean($_REQUEST["login"]); |
|
273 | + $rv = []; |
|
274 | 274 | |
275 | - if ($login) { |
|
276 | - $sth = $this->pdo->prepare("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users |
|
275 | + if ($login) { |
|
276 | + $sth = $this->pdo->prepare("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users |
|
277 | 277 | WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = ? ORDER BY title"); |
278 | - $sth->execute([$login]); |
|
278 | + $sth->execute([$login]); |
|
279 | 279 | |
280 | - $rv = [ [ "value" => 0, "label" => __("Default profile") ] ]; |
|
280 | + $rv = [ [ "value" => 0, "label" => __("Default profile") ] ]; |
|
281 | 281 | |
282 | - while ($line = $sth->fetch()) { |
|
283 | - $id = $line["id"]; |
|
284 | - $title = $line["title"]; |
|
282 | + while ($line = $sth->fetch()) { |
|
283 | + $id = $line["id"]; |
|
284 | + $title = $line["title"]; |
|
285 | 285 | |
286 | - array_push($rv, [ "label" => $title, "value" => $id ]); |
|
287 | - } |
|
288 | - } |
|
286 | + array_push($rv, [ "label" => $title, "value" => $id ]); |
|
287 | + } |
|
288 | + } |
|
289 | 289 | |
290 | - print json_encode($rv); |
|
291 | - } |
|
290 | + print json_encode($rv); |
|
291 | + } |
|
292 | 292 | |
293 | - public function logout() { |
|
294 | - logout_user(); |
|
295 | - header("Location: index.php"); |
|
296 | - } |
|
293 | + public function logout() { |
|
294 | + logout_user(); |
|
295 | + header("Location: index.php"); |
|
296 | + } |
|
297 | 297 | |
298 | - public function share() { |
|
299 | - $uuid = clean($_REQUEST["key"]); |
|
298 | + public function share() { |
|
299 | + $uuid = clean($_REQUEST["key"]); |
|
300 | 300 | |
301 | - if ($uuid) { |
|
302 | - $sth = $this->pdo->prepare("SELECT ref_id, owner_uid |
|
301 | + if ($uuid) { |
|
302 | + $sth = $this->pdo->prepare("SELECT ref_id, owner_uid |
|
303 | 303 | FROM ttrss_user_entries WHERE uuid = ?"); |
304 | - $sth->execute([$uuid]); |
|
304 | + $sth->execute([$uuid]); |
|
305 | 305 | |
306 | - if ($row = $sth->fetch()) { |
|
307 | - header("Content-Type: text/html"); |
|
306 | + if ($row = $sth->fetch()) { |
|
307 | + header("Content-Type: text/html"); |
|
308 | 308 | |
309 | - $id = $row["ref_id"]; |
|
310 | - $owner_uid = $row["owner_uid"]; |
|
309 | + $id = $row["ref_id"]; |
|
310 | + $owner_uid = $row["owner_uid"]; |
|
311 | 311 | |
312 | - print $this->format_article($id, $owner_uid); |
|
312 | + print $this->format_article($id, $owner_uid); |
|
313 | 313 | |
314 | - return; |
|
315 | - } |
|
316 | - } |
|
314 | + return; |
|
315 | + } |
|
316 | + } |
|
317 | 317 | |
318 | - header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); |
|
319 | - print "Article not found."; |
|
320 | - } |
|
318 | + header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); |
|
319 | + print "Article not found."; |
|
320 | + } |
|
321 | 321 | |
322 | - private function format_article($id, $owner_uid) { |
|
322 | + private function format_article($id, $owner_uid) { |
|
323 | 323 | |
324 | - $pdo = Db::pdo(); |
|
324 | + $pdo = Db::pdo(); |
|
325 | 325 | |
326 | - $sth = $pdo->prepare("SELECT id,title,link,content,feed_id,comments,int_id,lang, |
|
326 | + $sth = $pdo->prepare("SELECT id,title,link,content,feed_id,comments,int_id,lang, |
|
327 | 327 | ".SUBSTRING_FOR_DATE."(updated,1,16) as updated, |
328 | 328 | (SELECT site_url FROM ttrss_feeds WHERE id = feed_id) as site_url, |
329 | 329 | (SELECT title FROM ttrss_feeds WHERE id = feed_id) as feed_title, |
@@ -337,26 +337,26 @@ discard block |
||
337 | 337 | note |
338 | 338 | FROM ttrss_entries,ttrss_user_entries |
339 | 339 | WHERE id = ? AND ref_id = id AND owner_uid = ?"); |
340 | - $sth->execute([$id, $owner_uid]); |
|
340 | + $sth->execute([$id, $owner_uid]); |
|
341 | 341 | |
342 | - $rv = ''; |
|
342 | + $rv = ''; |
|
343 | 343 | |
344 | - if ($line = $sth->fetch()) { |
|
344 | + if ($line = $sth->fetch()) { |
|
345 | 345 | |
346 | - $line["tags"] = Article::get_article_tags($id, $owner_uid, $line["tag_cache"]); |
|
347 | - unset($line["tag_cache"]); |
|
346 | + $line["tags"] = Article::get_article_tags($id, $owner_uid, $line["tag_cache"]); |
|
347 | + unset($line["tag_cache"]); |
|
348 | 348 | |
349 | - $line["content"] = sanitize($line["content"], |
|
350 | - $line['hide_images'], |
|
351 | - $owner_uid, $line["site_url"], false, $line["id"]); |
|
349 | + $line["content"] = sanitize($line["content"], |
|
350 | + $line['hide_images'], |
|
351 | + $owner_uid, $line["site_url"], false, $line["id"]); |
|
352 | 352 | |
353 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) { |
|
354 | - $line = $p->hook_render_article($line); |
|
355 | - } |
|
353 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) { |
|
354 | + $line = $p->hook_render_article($line); |
|
355 | + } |
|
356 | 356 | |
357 | - $line['content'] = DiskCache::rewriteUrls($line['content']); |
|
357 | + $line['content'] = DiskCache::rewriteUrls($line['content']); |
|
358 | 358 | |
359 | - $enclosures = Article::get_article_enclosures($line["id"]); |
|
359 | + $enclosures = Article::get_article_enclosures($line["id"]); |
|
360 | 360 | |
361 | 361 | header("Content-Type: text/html"); |
362 | 362 | |
@@ -371,13 +371,13 @@ discard block |
||
371 | 371 | $rv .= "<meta property='og:title' content=\"".htmlspecialchars(html_entity_decode($line["title"], ENT_NOQUOTES | ENT_HTML401))."\"/>\n"; |
372 | 372 | $rv .= "<meta property='og:description' content=\"". |
373 | 373 | htmlspecialchars( |
374 | - truncate_string( |
|
375 | - preg_replace("/[\r\n\t]/", "", |
|
376 | - preg_replace("/ {1,}/", " ", |
|
377 | - strip_tags(html_entity_decode($line["content"], ENT_NOQUOTES | ENT_HTML401)) |
|
378 | - ) |
|
379 | - ), 500, "...") |
|
380 | - )."\"/>\n"; |
|
374 | + truncate_string( |
|
375 | + preg_replace("/[\r\n\t]/", "", |
|
376 | + preg_replace("/ {1,}/", " ", |
|
377 | + strip_tags(html_entity_decode($line["content"], ENT_NOQUOTES | ENT_HTML401)) |
|
378 | + ) |
|
379 | + ), 500, "...") |
|
380 | + )."\"/>\n"; |
|
381 | 381 | |
382 | 382 | $rv .= "</head>"; |
383 | 383 | |
@@ -390,132 +390,132 @@ discard block |
||
390 | 390 | $rv .= "<body class='flat ttrss_utility ttrss_zoom'>"; |
391 | 391 | $rv .= "<div class='container'>"; |
392 | 392 | |
393 | - if ($line["link"]) { |
|
394 | - $rv .= "<h1><a target='_blank' rel='noopener noreferrer' |
|
393 | + if ($line["link"]) { |
|
394 | + $rv .= "<h1><a target='_blank' rel='noopener noreferrer' |
|
395 | 395 | title=\"".htmlspecialchars($line['title'])."\" |
396 | 396 | href=\"" .htmlspecialchars($line["link"]) . "\">" . $line["title"] . "</a></h1>"; |
397 | - } else { |
|
398 | - $rv .= "<h1>" . $line["title"] . "</h1>"; |
|
399 | - } |
|
397 | + } else { |
|
398 | + $rv .= "<h1>" . $line["title"] . "</h1>"; |
|
399 | + } |
|
400 | 400 | |
401 | - $rv .= "<div class='content post'>"; |
|
401 | + $rv .= "<div class='content post'>"; |
|
402 | 402 | |
403 | - /* header */ |
|
403 | + /* header */ |
|
404 | 404 | |
405 | - $rv .= "<div class='header'>"; |
|
406 | - $rv .= "<div class='row'>"; # row |
|
405 | + $rv .= "<div class='header'>"; |
|
406 | + $rv .= "<div class='row'>"; # row |
|
407 | 407 | |
408 | - //$entry_author = $line["author"] ? " - " . $line["author"] : ""; |
|
409 | - $parsed_updated = make_local_datetime($line["updated"], true, |
|
410 | - $owner_uid, true); |
|
408 | + //$entry_author = $line["author"] ? " - " . $line["author"] : ""; |
|
409 | + $parsed_updated = make_local_datetime($line["updated"], true, |
|
410 | + $owner_uid, true); |
|
411 | 411 | |
412 | - $rv .= "<div>".$line['author']."</div>"; |
|
412 | + $rv .= "<div>".$line['author']."</div>"; |
|
413 | 413 | $rv .= "<div>$parsed_updated</div>"; |
414 | 414 | |
415 | - $rv .= "</div>"; # row |
|
415 | + $rv .= "</div>"; # row |
|
416 | 416 | |
417 | - $rv .= "</div>"; # header |
|
417 | + $rv .= "</div>"; # header |
|
418 | 418 | |
419 | - /* content */ |
|
419 | + /* content */ |
|
420 | 420 | |
421 | - $lang = $line['lang'] ? $line['lang'] : "en"; |
|
422 | - $rv .= "<div class='content' lang='$lang'>"; |
|
421 | + $lang = $line['lang'] ? $line['lang'] : "en"; |
|
422 | + $rv .= "<div class='content' lang='$lang'>"; |
|
423 | 423 | |
424 | - /* content body */ |
|
424 | + /* content body */ |
|
425 | 425 | |
426 | - $rv .= $line["content"]; |
|
426 | + $rv .= $line["content"]; |
|
427 | 427 | |
428 | 428 | $rv .= Article::format_article_enclosures($id, |
429 | 429 | $line["always_display_enclosures"], |
430 | 430 | $line["content"], |
431 | 431 | $line["hide_images"]); |
432 | 432 | |
433 | - $rv .= "</div>"; # content |
|
433 | + $rv .= "</div>"; # content |
|
434 | 434 | |
435 | - $rv .= "</div>"; # post |
|
435 | + $rv .= "</div>"; # post |
|
436 | 436 | |
437 | - } |
|
437 | + } |
|
438 | 438 | |
439 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ARTICLE) as $p) { |
|
440 | - $rv = $p->hook_format_article($rv, $line, true); |
|
441 | - } |
|
439 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ARTICLE) as $p) { |
|
440 | + $rv = $p->hook_format_article($rv, $line, true); |
|
441 | + } |
|
442 | 442 | |
443 | - return $rv; |
|
443 | + return $rv; |
|
444 | 444 | |
445 | - } |
|
445 | + } |
|
446 | 446 | |
447 | - public function rss() { |
|
448 | - $feed = clean($_REQUEST["id"]); |
|
449 | - $key = clean($_REQUEST["key"]); |
|
450 | - $is_cat = clean($_REQUEST["is_cat"]); |
|
451 | - $limit = (int)clean($_REQUEST["limit"]); |
|
452 | - $offset = (int)clean($_REQUEST["offset"]); |
|
447 | + public function rss() { |
|
448 | + $feed = clean($_REQUEST["id"]); |
|
449 | + $key = clean($_REQUEST["key"]); |
|
450 | + $is_cat = clean($_REQUEST["is_cat"]); |
|
451 | + $limit = (int)clean($_REQUEST["limit"]); |
|
452 | + $offset = (int)clean($_REQUEST["offset"]); |
|
453 | 453 | |
454 | - $search = clean($_REQUEST["q"]); |
|
455 | - $view_mode = clean($_REQUEST["view-mode"]); |
|
456 | - $order = clean($_REQUEST["order"]); |
|
457 | - $start_ts = clean($_REQUEST["ts"]); |
|
454 | + $search = clean($_REQUEST["q"]); |
|
455 | + $view_mode = clean($_REQUEST["view-mode"]); |
|
456 | + $order = clean($_REQUEST["order"]); |
|
457 | + $start_ts = clean($_REQUEST["ts"]); |
|
458 | 458 | |
459 | - $format = clean($_REQUEST['format']); |
|
460 | - $orig_guid = clean($_REQUEST["orig_guid"]); |
|
459 | + $format = clean($_REQUEST['format']); |
|
460 | + $orig_guid = clean($_REQUEST["orig_guid"]); |
|
461 | 461 | |
462 | - if (!$format) $format = 'atom'; |
|
462 | + if (!$format) $format = 'atom'; |
|
463 | 463 | |
464 | - if (SINGLE_USER_MODE) { |
|
465 | - authenticate_user("admin", null); |
|
466 | - } |
|
464 | + if (SINGLE_USER_MODE) { |
|
465 | + authenticate_user("admin", null); |
|
466 | + } |
|
467 | 467 | |
468 | - $owner_id = false; |
|
468 | + $owner_id = false; |
|
469 | 469 | |
470 | - if ($key) { |
|
471 | - $sth = $this->pdo->prepare("SELECT owner_uid FROM |
|
470 | + if ($key) { |
|
471 | + $sth = $this->pdo->prepare("SELECT owner_uid FROM |
|
472 | 472 | ttrss_access_keys WHERE access_key = ? AND feed_id = ?"); |
473 | - $sth->execute([$key, $feed]); |
|
473 | + $sth->execute([$key, $feed]); |
|
474 | 474 | |
475 | - if ($row = $sth->fetch()) |
|
476 | - $owner_id = $row["owner_uid"]; |
|
477 | - } |
|
475 | + if ($row = $sth->fetch()) |
|
476 | + $owner_id = $row["owner_uid"]; |
|
477 | + } |
|
478 | 478 | |
479 | - if ($owner_id) { |
|
480 | - $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit, |
|
481 | - $offset, $search, $view_mode, $format, $order, $orig_guid, $start_ts); |
|
482 | - } else { |
|
483 | - header('HTTP/1.1 403 Forbidden'); |
|
484 | - } |
|
485 | - } |
|
479 | + if ($owner_id) { |
|
480 | + $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit, |
|
481 | + $offset, $search, $view_mode, $format, $order, $orig_guid, $start_ts); |
|
482 | + } else { |
|
483 | + header('HTTP/1.1 403 Forbidden'); |
|
484 | + } |
|
485 | + } |
|
486 | 486 | |
487 | - public function updateTask() { |
|
488 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false); |
|
489 | - } |
|
487 | + public function updateTask() { |
|
488 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false); |
|
489 | + } |
|
490 | 490 | |
491 | - public function housekeepingTask() { |
|
492 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", false); |
|
493 | - } |
|
491 | + public function housekeepingTask() { |
|
492 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", false); |
|
493 | + } |
|
494 | 494 | |
495 | - public function globalUpdateFeeds() { |
|
496 | - RPC::updaterandomfeed_real(); |
|
495 | + public function globalUpdateFeeds() { |
|
496 | + RPC::updaterandomfeed_real(); |
|
497 | 497 | |
498 | - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false); |
|
499 | - } |
|
498 | + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false); |
|
499 | + } |
|
500 | 500 | |
501 | - public function sharepopup() { |
|
502 | - if (SINGLE_USER_MODE) { |
|
503 | - login_sequence(); |
|
504 | - } |
|
501 | + public function sharepopup() { |
|
502 | + if (SINGLE_USER_MODE) { |
|
503 | + login_sequence(); |
|
504 | + } |
|
505 | 505 | |
506 | - header('Content-Type: text/html; charset=utf-8'); |
|
507 | - ?> |
|
506 | + header('Content-Type: text/html; charset=utf-8'); |
|
507 | + ?> |
|
508 | 508 | <!DOCTYPE html> |
509 | 509 | <html> |
510 | 510 | <head> |
511 | 511 | <title><?php echo __("Share with Tiny Tiny RSS") ?></title> |
512 | 512 | <?php |
513 | - echo stylesheet_tag("css/default.css"); |
|
514 | - echo javascript_tag("lib/prototype.js"); |
|
515 | - echo javascript_tag("lib/dojo/dojo.js"); |
|
516 | - echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
517 | - echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls") |
|
518 | - ?> |
|
513 | + echo stylesheet_tag("css/default.css"); |
|
514 | + echo javascript_tag("lib/prototype.js"); |
|
515 | + echo javascript_tag("lib/dojo/dojo.js"); |
|
516 | + echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
517 | + echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls") |
|
518 | + ?> |
|
519 | 519 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
520 | 520 | <link rel="shortcut icon" type="image/png" href="images/favicon.png"> |
521 | 521 | <link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png"> |
@@ -537,29 +537,29 @@ discard block |
||
537 | 537 | |
538 | 538 | <?php |
539 | 539 | |
540 | - $action = clean($_REQUEST["action"]); |
|
540 | + $action = clean($_REQUEST["action"]); |
|
541 | 541 | |
542 | - if ($_SESSION["uid"]) { |
|
542 | + if ($_SESSION["uid"]) { |
|
543 | 543 | |
544 | - if ($action == 'share') { |
|
544 | + if ($action == 'share') { |
|
545 | 545 | |
546 | - $title = strip_tags(clean($_REQUEST["title"])); |
|
547 | - $url = strip_tags(clean($_REQUEST["url"])); |
|
548 | - $content = strip_tags(clean($_REQUEST["content"])); |
|
549 | - $labels = strip_tags(clean($_REQUEST["labels"])); |
|
546 | + $title = strip_tags(clean($_REQUEST["title"])); |
|
547 | + $url = strip_tags(clean($_REQUEST["url"])); |
|
548 | + $content = strip_tags(clean($_REQUEST["content"])); |
|
549 | + $labels = strip_tags(clean($_REQUEST["labels"])); |
|
550 | 550 | |
551 | - Article::create_published_article($title, $url, $content, $labels, |
|
552 | - $_SESSION["uid"]); |
|
551 | + Article::create_published_article($title, $url, $content, $labels, |
|
552 | + $_SESSION["uid"]); |
|
553 | 553 | |
554 | - print "<script type='text/javascript'>"; |
|
555 | - print "window.close();"; |
|
556 | - print "</script>"; |
|
554 | + print "<script type='text/javascript'>"; |
|
555 | + print "window.close();"; |
|
556 | + print "</script>"; |
|
557 | 557 | |
558 | - } else { |
|
559 | - $title = htmlspecialchars(clean($_REQUEST["title"])); |
|
560 | - $url = htmlspecialchars(clean($_REQUEST["url"])); |
|
558 | + } else { |
|
559 | + $title = htmlspecialchars(clean($_REQUEST["title"])); |
|
560 | + $url = htmlspecialchars(clean($_REQUEST["url"])); |
|
561 | 561 | |
562 | - ?> |
|
562 | + ?> |
|
563 | 563 | <form id='share_form' name='share_form'> |
564 | 564 | |
565 | 565 | <input type="hidden" name="op" value="sharepopup"> |
@@ -599,12 +599,12 @@ discard block |
||
599 | 599 | </form> |
600 | 600 | <?php |
601 | 601 | |
602 | - } |
|
602 | + } |
|
603 | 603 | |
604 | - } else { |
|
604 | + } else { |
|
605 | 605 | |
606 | - $return = urlencode(make_self_url()); |
|
607 | - print_error("Not logged in"); ?> |
|
606 | + $return = urlencode(make_self_url()); |
|
607 | + print_error("Not logged in"); ?> |
|
608 | 608 | |
609 | 609 | <form action="public.php?return=<?php echo $return ?>" method="post"> |
610 | 610 | |
@@ -636,90 +636,90 @@ discard block |
||
636 | 636 | |
637 | 637 | </form> |
638 | 638 | <?php |
639 | - } |
|
639 | + } |
|
640 | 640 | |
641 | - print "</div></body></html>"; |
|
642 | - } |
|
641 | + print "</div></body></html>"; |
|
642 | + } |
|
643 | 643 | |
644 | - public function login() { |
|
645 | - if (!SINGLE_USER_MODE) { |
|
644 | + public function login() { |
|
645 | + if (!SINGLE_USER_MODE) { |
|
646 | 646 | |
647 | - $login = clean($_POST["login"]); |
|
648 | - $password = clean($_POST["password"]); |
|
649 | - $remember_me = clean($_POST["remember_me"]); |
|
647 | + $login = clean($_POST["login"]); |
|
648 | + $password = clean($_POST["password"]); |
|
649 | + $remember_me = clean($_POST["remember_me"]); |
|
650 | 650 | |
651 | - if ($remember_me) { |
|
652 | - session_set_cookie_params(SESSION_COOKIE_LIFETIME); |
|
653 | - } else { |
|
654 | - session_set_cookie_params(0); |
|
655 | - } |
|
651 | + if ($remember_me) { |
|
652 | + session_set_cookie_params(SESSION_COOKIE_LIFETIME); |
|
653 | + } else { |
|
654 | + session_set_cookie_params(0); |
|
655 | + } |
|
656 | 656 | |
657 | - if (authenticate_user($login, $password)) { |
|
658 | - $_POST["password"] = ""; |
|
657 | + if (authenticate_user($login, $password)) { |
|
658 | + $_POST["password"] = ""; |
|
659 | 659 | |
660 | - if (get_schema_version() >= 120) { |
|
661 | - $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]); |
|
662 | - } |
|
660 | + if (get_schema_version() >= 120) { |
|
661 | + $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]); |
|
662 | + } |
|
663 | 663 | |
664 | - $_SESSION["ref_schema_version"] = get_schema_version(true); |
|
665 | - $_SESSION["bw_limit"] = !!clean($_POST["bw_limit"]); |
|
664 | + $_SESSION["ref_schema_version"] = get_schema_version(true); |
|
665 | + $_SESSION["bw_limit"] = !!clean($_POST["bw_limit"]); |
|
666 | 666 | |
667 | - if (clean($_POST["profile"])) { |
|
667 | + if (clean($_POST["profile"])) { |
|
668 | 668 | |
669 | - $profile = (int) clean($_POST["profile"]); |
|
669 | + $profile = (int) clean($_POST["profile"]); |
|
670 | 670 | |
671 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles |
|
671 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles |
|
672 | 672 | WHERE id = ? AND owner_uid = ?"); |
673 | - $sth->execute([$profile, $_SESSION['uid']]); |
|
673 | + $sth->execute([$profile, $_SESSION['uid']]); |
|
674 | 674 | |
675 | - if ($sth->fetch()) { |
|
676 | - $_SESSION["profile"] = $profile; |
|
677 | - } else { |
|
678 | - $_SESSION["profile"] = null; |
|
675 | + if ($sth->fetch()) { |
|
676 | + $_SESSION["profile"] = $profile; |
|
677 | + } else { |
|
678 | + $_SESSION["profile"] = null; |
|
679 | 679 | } |
680 | - } |
|
681 | - } else { |
|
680 | + } |
|
681 | + } else { |
|
682 | 682 | |
683 | - // start an empty session to deliver login error message |
|
684 | - @session_start(); |
|
683 | + // start an empty session to deliver login error message |
|
684 | + @session_start(); |
|
685 | 685 | |
686 | - if (!isset($_SESSION["login_error_msg"])) |
|
687 | - $_SESSION["login_error_msg"] = __("Incorrect username or password"); |
|
686 | + if (!isset($_SESSION["login_error_msg"])) |
|
687 | + $_SESSION["login_error_msg"] = __("Incorrect username or password"); |
|
688 | 688 | |
689 | - user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING); |
|
690 | - } |
|
689 | + user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING); |
|
690 | + } |
|
691 | 691 | |
692 | - $return = clean($_REQUEST['return']); |
|
692 | + $return = clean($_REQUEST['return']); |
|
693 | 693 | |
694 | - if ($_REQUEST['return'] && mb_strpos($return, SELF_URL_PATH) === 0) { |
|
695 | - header("Location: " . clean($_REQUEST['return'])); |
|
696 | - } else { |
|
697 | - header("Location: " . get_self_url_prefix()); |
|
698 | - } |
|
699 | - } |
|
700 | - } |
|
694 | + if ($_REQUEST['return'] && mb_strpos($return, SELF_URL_PATH) === 0) { |
|
695 | + header("Location: " . clean($_REQUEST['return'])); |
|
696 | + } else { |
|
697 | + header("Location: " . get_self_url_prefix()); |
|
698 | + } |
|
699 | + } |
|
700 | + } |
|
701 | 701 | |
702 | - public function subscribe() { |
|
703 | - if (SINGLE_USER_MODE) { |
|
704 | - login_sequence(); |
|
705 | - } |
|
702 | + public function subscribe() { |
|
703 | + if (SINGLE_USER_MODE) { |
|
704 | + login_sequence(); |
|
705 | + } |
|
706 | 706 | |
707 | - if ($_SESSION["uid"]) { |
|
707 | + if ($_SESSION["uid"]) { |
|
708 | 708 | |
709 | - $feed_url = trim(clean($_REQUEST["feed_url"])); |
|
709 | + $feed_url = trim(clean($_REQUEST["feed_url"])); |
|
710 | 710 | |
711 | - header('Content-Type: text/html; charset=utf-8'); |
|
712 | - ?> |
|
711 | + header('Content-Type: text/html; charset=utf-8'); |
|
712 | + ?> |
|
713 | 713 | <!DOCTYPE html> |
714 | 714 | <html> |
715 | 715 | <head> |
716 | 716 | <title>Tiny Tiny RSS</title> |
717 | 717 | <?php |
718 | - echo stylesheet_tag("css/default.css"); |
|
719 | - echo javascript_tag("lib/prototype.js"); |
|
720 | - echo javascript_tag("lib/dojo/dojo.js"); |
|
721 | - echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
722 | - ?> |
|
718 | + echo stylesheet_tag("css/default.css"); |
|
719 | + echo javascript_tag("lib/prototype.js"); |
|
720 | + echo javascript_tag("lib/dojo/dojo.js"); |
|
721 | + echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
722 | + ?> |
|
723 | 723 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
724 | 724 | <link rel="shortcut icon" type="image/png" href="images/favicon.png"> |
725 | 725 | <link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png"> |
@@ -738,8 +738,8 @@ discard block |
||
738 | 738 | <div class='content'> |
739 | 739 | <?php |
740 | 740 | |
741 | - if (!$feed_url) { |
|
742 | - ?> |
|
741 | + if (!$feed_url) { |
|
742 | + ?> |
|
743 | 743 | <form method="post"> |
744 | 744 | <input type="hidden" name="op" value="subscribe"> |
745 | 745 | <fieldset> |
@@ -754,101 +754,101 @@ discard block |
||
754 | 754 | <a href="index.php"><?php echo __("Return to Tiny Tiny RSS") ?></a> |
755 | 755 | </form> |
756 | 756 | <?php |
757 | - } else { |
|
758 | - |
|
759 | - $rc = Feeds::subscribe_to_feed($feed_url); |
|
760 | - $feed_urls = false; |
|
761 | - |
|
762 | - switch ($rc['code']) { |
|
763 | - case 0: |
|
764 | - print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url)); |
|
765 | - break; |
|
766 | - case 1: |
|
767 | - print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url)); |
|
768 | - break; |
|
769 | - case 2: |
|
770 | - print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url)); |
|
771 | - break; |
|
772 | - case 3: |
|
773 | - print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url)); |
|
774 | - break; |
|
775 | - case 4: |
|
776 | - $feed_urls = $rc["feeds"]; |
|
777 | - break; |
|
778 | - case 5: |
|
779 | - print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url)); |
|
780 | - break; |
|
781 | - } |
|
782 | - |
|
783 | - if ($feed_urls) { |
|
784 | - |
|
785 | - print "<form action='public.php'>"; |
|
786 | - print "<input type='hidden' name='op' value='subscribe'>"; |
|
787 | - |
|
788 | - print "<fieldset>"; |
|
789 | - print "<label style='display : inline'>" . __("Multiple feed URLs found:") . "</label>"; |
|
790 | - print "<select name='feed_url' dojoType='dijit.form.Select'>"; |
|
791 | - |
|
792 | - foreach ($feed_urls as $url => $name) { |
|
793 | - $url = htmlspecialchars($url); |
|
794 | - $name = htmlspecialchars($name); |
|
795 | - |
|
796 | - print "<option value=\"$url\">$name</option>"; |
|
797 | - } |
|
757 | + } else { |
|
758 | + |
|
759 | + $rc = Feeds::subscribe_to_feed($feed_url); |
|
760 | + $feed_urls = false; |
|
761 | + |
|
762 | + switch ($rc['code']) { |
|
763 | + case 0: |
|
764 | + print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url)); |
|
765 | + break; |
|
766 | + case 1: |
|
767 | + print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url)); |
|
768 | + break; |
|
769 | + case 2: |
|
770 | + print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url)); |
|
771 | + break; |
|
772 | + case 3: |
|
773 | + print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url)); |
|
774 | + break; |
|
775 | + case 4: |
|
776 | + $feed_urls = $rc["feeds"]; |
|
777 | + break; |
|
778 | + case 5: |
|
779 | + print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url)); |
|
780 | + break; |
|
781 | + } |
|
782 | + |
|
783 | + if ($feed_urls) { |
|
784 | + |
|
785 | + print "<form action='public.php'>"; |
|
786 | + print "<input type='hidden' name='op' value='subscribe'>"; |
|
787 | + |
|
788 | + print "<fieldset>"; |
|
789 | + print "<label style='display : inline'>" . __("Multiple feed URLs found:") . "</label>"; |
|
790 | + print "<select name='feed_url' dojoType='dijit.form.Select'>"; |
|
791 | + |
|
792 | + foreach ($feed_urls as $url => $name) { |
|
793 | + $url = htmlspecialchars($url); |
|
794 | + $name = htmlspecialchars($name); |
|
795 | + |
|
796 | + print "<option value=\"$url\">$name</option>"; |
|
797 | + } |
|
798 | 798 | |
799 | - print "</select>"; |
|
800 | - print "</fieldset>"; |
|
799 | + print "</select>"; |
|
800 | + print "</fieldset>"; |
|
801 | 801 | |
802 | - print "<button class='alt-primary' dojoType='dijit.form.Button' type='submit'>".__("Subscribe to selected feed")."</button>"; |
|
803 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
802 | + print "<button class='alt-primary' dojoType='dijit.form.Button' type='submit'>".__("Subscribe to selected feed")."</button>"; |
|
803 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
804 | 804 | |
805 | - print "</form>"; |
|
806 | - } |
|
805 | + print "</form>"; |
|
806 | + } |
|
807 | 807 | |
808 | - $tp_uri = get_self_url_prefix() . "/prefs.php"; |
|
808 | + $tp_uri = get_self_url_prefix() . "/prefs.php"; |
|
809 | 809 | |
810 | - if ($rc['code'] <= 2){ |
|
811 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
810 | + if ($rc['code'] <= 2){ |
|
811 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE |
|
812 | 812 | feed_url = ? AND owner_uid = ?"); |
813 | - $sth->execute([$feed_url, $_SESSION['uid']]); |
|
814 | - $row = $sth->fetch(); |
|
813 | + $sth->execute([$feed_url, $_SESSION['uid']]); |
|
814 | + $row = $sth->fetch(); |
|
815 | 815 | |
816 | - $feed_id = $row["id"]; |
|
817 | - } else { |
|
818 | - $feed_id = 0; |
|
819 | - } |
|
816 | + $feed_id = $row["id"]; |
|
817 | + } else { |
|
818 | + $feed_id = 0; |
|
819 | + } |
|
820 | 820 | |
821 | - if ($feed_id) { |
|
822 | - print "<form method='GET' action=\"$tp_uri\"> |
|
821 | + if ($feed_id) { |
|
822 | + print "<form method='GET' action=\"$tp_uri\"> |
|
823 | 823 | <input type='hidden' name='tab' value='feedConfig'> |
824 | 824 | <input type='hidden' name='method' value='editfeed'> |
825 | 825 | <input type='hidden' name='methodparam' value='$feed_id'> |
826 | 826 | <button dojoType='dijit.form.Button' class='alt-info' type='submit'>".__("Edit subscription options")."</button> |
827 | 827 | <a href='index.php'>".__("Return to Tiny Tiny RSS")."</a> |
828 | 828 | </form>"; |
829 | - } |
|
830 | - } |
|
829 | + } |
|
830 | + } |
|
831 | 831 | |
832 | - print "</div></div></body></html>"; |
|
832 | + print "</div></div></body></html>"; |
|
833 | 833 | |
834 | - } else { |
|
835 | - render_login_form(); |
|
836 | - } |
|
837 | - } |
|
834 | + } else { |
|
835 | + render_login_form(); |
|
836 | + } |
|
837 | + } |
|
838 | 838 | |
839 | - public function index() { |
|
840 | - header("Content-Type: text/plain"); |
|
841 | - print error_json(13); |
|
842 | - } |
|
839 | + public function index() { |
|
840 | + header("Content-Type: text/plain"); |
|
841 | + print error_json(13); |
|
842 | + } |
|
843 | 843 | |
844 | - public function forgotpass() { |
|
845 | - startup_gettext(); |
|
846 | - session_start(); |
|
844 | + public function forgotpass() { |
|
845 | + startup_gettext(); |
|
846 | + session_start(); |
|
847 | 847 | |
848 | - @$hash = clean($_REQUEST["hash"]); |
|
848 | + @$hash = clean($_REQUEST["hash"]); |
|
849 | 849 | |
850 | - header('Content-Type: text/html; charset=utf-8'); |
|
851 | - ?> |
|
850 | + header('Content-Type: text/html; charset=utf-8'); |
|
851 | + ?> |
|
852 | 852 | <!DOCTYPE html> |
853 | 853 | <html> |
854 | 854 | <head> |
@@ -857,11 +857,11 @@ discard block |
||
857 | 857 | <link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png"> |
858 | 858 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
859 | 859 | <?php |
860 | - echo stylesheet_tag("css/default.css"); |
|
861 | - echo javascript_tag("lib/prototype.js"); |
|
862 | - echo javascript_tag("lib/dojo/dojo.js"); |
|
863 | - echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
864 | - ?> |
|
860 | + echo stylesheet_tag("css/default.css"); |
|
861 | + echo javascript_tag("lib/prototype.js"); |
|
862 | + echo javascript_tag("lib/dojo/dojo.js"); |
|
863 | + echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
864 | + ?> |
|
865 | 865 | </head> |
866 | 866 | <body class='flat ttrss_utility'> |
867 | 867 | <div class='container'> |
@@ -876,52 +876,52 @@ discard block |
||
876 | 876 | </script> |
877 | 877 | <?php |
878 | 878 | |
879 | - print "<h1>".__("Password recovery")."</h1>"; |
|
880 | - print "<div class='content'>"; |
|
879 | + print "<h1>".__("Password recovery")."</h1>"; |
|
880 | + print "<div class='content'>"; |
|
881 | 881 | |
882 | - @$method = clean($_POST['method']); |
|
882 | + @$method = clean($_POST['method']); |
|
883 | 883 | |
884 | - if ($hash) { |
|
885 | - $login = clean($_REQUEST["login"]); |
|
884 | + if ($hash) { |
|
885 | + $login = clean($_REQUEST["login"]); |
|
886 | 886 | |
887 | - if ($login) { |
|
888 | - $sth = $this->pdo->prepare("SELECT id, resetpass_token FROM ttrss_users |
|
887 | + if ($login) { |
|
888 | + $sth = $this->pdo->prepare("SELECT id, resetpass_token FROM ttrss_users |
|
889 | 889 | WHERE login = ?"); |
890 | - $sth->execute([$login]); |
|
890 | + $sth->execute([$login]); |
|
891 | 891 | |
892 | - if ($row = $sth->fetch()) { |
|
893 | - $id = $row["id"]; |
|
894 | - $resetpass_token_full = $row["resetpass_token"]; |
|
895 | - list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full); |
|
892 | + if ($row = $sth->fetch()) { |
|
893 | + $id = $row["id"]; |
|
894 | + $resetpass_token_full = $row["resetpass_token"]; |
|
895 | + list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full); |
|
896 | 896 | |
897 | - if ($timestamp && $resetpass_token && |
|
898 | - $timestamp >= time() - 15*60*60 && |
|
899 | - $resetpass_token == $hash) { |
|
897 | + if ($timestamp && $resetpass_token && |
|
898 | + $timestamp >= time() - 15*60*60 && |
|
899 | + $resetpass_token == $hash) { |
|
900 | 900 | |
901 | - $sth = $this->pdo->prepare("UPDATE ttrss_users SET resetpass_token = NULL |
|
901 | + $sth = $this->pdo->prepare("UPDATE ttrss_users SET resetpass_token = NULL |
|
902 | 902 | WHERE id = ?"); |
903 | - $sth->execute([$id]); |
|
903 | + $sth->execute([$id]); |
|
904 | 904 | |
905 | - Pref_Users::resetUserPassword($id, true); |
|
905 | + Pref_Users::resetUserPassword($id, true); |
|
906 | 906 | |
907 | - print "<p>"."Completed."."</p>"; |
|
907 | + print "<p>"."Completed."."</p>"; |
|
908 | 908 | |
909 | - } else { |
|
910 | - print_error("Some of the information provided is missing or incorrect."); |
|
911 | - } |
|
912 | - } else { |
|
913 | - print_error("Some of the information provided is missing or incorrect."); |
|
914 | - } |
|
915 | - } else { |
|
916 | - print_error("Some of the information provided is missing or incorrect."); |
|
917 | - } |
|
909 | + } else { |
|
910 | + print_error("Some of the information provided is missing or incorrect."); |
|
911 | + } |
|
912 | + } else { |
|
913 | + print_error("Some of the information provided is missing or incorrect."); |
|
914 | + } |
|
915 | + } else { |
|
916 | + print_error("Some of the information provided is missing or incorrect."); |
|
917 | + } |
|
918 | 918 | |
919 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
919 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
920 | 920 | |
921 | - } else if (!$method) { |
|
922 | - print_notice(__("You will need to provide valid account name and email. Password reset link will be sent to your email address.")); |
|
921 | + } else if (!$method) { |
|
922 | + print_notice(__("You will need to provide valid account name and email. Password reset link will be sent to your email address.")); |
|
923 | 923 | |
924 | - print "<form method='POST' action='public.php'> |
|
924 | + print "<form method='POST' action='public.php'> |
|
925 | 925 | <input type='hidden' name='method' value='do'> |
926 | 926 | <input type='hidden' name='op' value='forgotpass'> |
927 | 927 | |
@@ -935,10 +935,10 @@ discard block |
||
935 | 935 | <input dojoType='dijit.form.TextBox' type='email' name='email' value='' required> |
936 | 936 | </fieldset>"; |
937 | 937 | |
938 | - $_SESSION["pwdreset:testvalue1"] = rand(1,10); |
|
939 | - $_SESSION["pwdreset:testvalue2"] = rand(1,10); |
|
938 | + $_SESSION["pwdreset:testvalue1"] = rand(1,10); |
|
939 | + $_SESSION["pwdreset:testvalue2"] = rand(1,10); |
|
940 | 940 | |
941 | - print "<fieldset> |
|
941 | + print "<fieldset> |
|
942 | 942 | <label>".T_sprintf("How much is %d + %d:", $_SESSION["pwdreset:testvalue1"], $_SESSION["pwdreset:testvalue2"])."</label> |
943 | 943 | <input dojoType='dijit.form.TextBox' type='text' name='test' value='' required> |
944 | 944 | </fieldset> |
@@ -950,109 +950,109 @@ discard block |
||
950 | 950 | </fieldset> |
951 | 951 | |
952 | 952 | </form>"; |
953 | - } else if ($method == 'do') { |
|
953 | + } else if ($method == 'do') { |
|
954 | 954 | |
955 | - $login = clean($_POST["login"]); |
|
956 | - $email = clean($_POST["email"]); |
|
957 | - $test = clean($_POST["test"]); |
|
955 | + $login = clean($_POST["login"]); |
|
956 | + $email = clean($_POST["email"]); |
|
957 | + $test = clean($_POST["test"]); |
|
958 | 958 | |
959 | - if ($test != ($_SESSION["pwdreset:testvalue1"] + $_SESSION["pwdreset:testvalue2"]) || !$email || !$login) { |
|
960 | - print_error(__('Some of the required form parameters are missing or incorrect.')); |
|
959 | + if ($test != ($_SESSION["pwdreset:testvalue1"] + $_SESSION["pwdreset:testvalue2"]) || !$email || !$login) { |
|
960 | + print_error(__('Some of the required form parameters are missing or incorrect.')); |
|
961 | 961 | |
962 | - print "<form method='GET' action='public.php'> |
|
962 | + print "<form method='GET' action='public.php'> |
|
963 | 963 | <input type='hidden' name='op' value='forgotpass'> |
964 | 964 | <button dojoType='dijit.form.Button' type='submit' class='alt-primary'>".__("Go back")."</button> |
965 | 965 | </form>"; |
966 | 966 | |
967 | - } else { |
|
967 | + } else { |
|
968 | 968 | |
969 | - // prevent submitting this form multiple times |
|
970 | - $_SESSION["pwdreset:testvalue1"] = rand(1, 1000); |
|
971 | - $_SESSION["pwdreset:testvalue2"] = rand(1, 1000); |
|
969 | + // prevent submitting this form multiple times |
|
970 | + $_SESSION["pwdreset:testvalue1"] = rand(1, 1000); |
|
971 | + $_SESSION["pwdreset:testvalue2"] = rand(1, 1000); |
|
972 | 972 | |
973 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_users |
|
973 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_users |
|
974 | 974 | WHERE login = ? AND email = ?"); |
975 | - $sth->execute([$login, $email]); |
|
975 | + $sth->execute([$login, $email]); |
|
976 | 976 | |
977 | - if ($row = $sth->fetch()) { |
|
978 | - print_notice("Password reset instructions are being sent to your email address."); |
|
977 | + if ($row = $sth->fetch()) { |
|
978 | + print_notice("Password reset instructions are being sent to your email address."); |
|
979 | 979 | |
980 | - $id = $row["id"]; |
|
980 | + $id = $row["id"]; |
|
981 | 981 | |
982 | - if ($id) { |
|
983 | - $resetpass_token = sha1(get_random_bytes(128)); |
|
984 | - $resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token . |
|
985 | - "&login=" . urlencode($login); |
|
982 | + if ($id) { |
|
983 | + $resetpass_token = sha1(get_random_bytes(128)); |
|
984 | + $resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token . |
|
985 | + "&login=" . urlencode($login); |
|
986 | 986 | |
987 | - require_once "lib/MiniTemplator.class.php"; |
|
987 | + require_once "lib/MiniTemplator.class.php"; |
|
988 | 988 | |
989 | - $tpl = new MiniTemplator; |
|
989 | + $tpl = new MiniTemplator; |
|
990 | 990 | |
991 | - $tpl->readTemplateFromFile("templates/resetpass_link_template.txt"); |
|
991 | + $tpl->readTemplateFromFile("templates/resetpass_link_template.txt"); |
|
992 | 992 | |
993 | - $tpl->setVariable('LOGIN', $login); |
|
994 | - $tpl->setVariable('RESETPASS_LINK', $resetpass_link); |
|
995 | - $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
993 | + $tpl->setVariable('LOGIN', $login); |
|
994 | + $tpl->setVariable('RESETPASS_LINK', $resetpass_link); |
|
995 | + $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); |
|
996 | 996 | |
997 | - $tpl->addBlock('message'); |
|
997 | + $tpl->addBlock('message'); |
|
998 | 998 | |
999 | - $message = ""; |
|
999 | + $message = ""; |
|
1000 | 1000 | |
1001 | - $tpl->generateOutputToString($message); |
|
1001 | + $tpl->generateOutputToString($message); |
|
1002 | 1002 | |
1003 | - $mailer = new Mailer(); |
|
1003 | + $mailer = new Mailer(); |
|
1004 | 1004 | |
1005 | - $rc = $mailer->mail(["to_name" => $login, |
|
1006 | - "to_address" => $email, |
|
1007 | - "subject" => __("[tt-rss] Password reset request"), |
|
1008 | - "message" => $message]); |
|
1005 | + $rc = $mailer->mail(["to_name" => $login, |
|
1006 | + "to_address" => $email, |
|
1007 | + "subject" => __("[tt-rss] Password reset request"), |
|
1008 | + "message" => $message]); |
|
1009 | 1009 | |
1010 | - if (!$rc) print_error($mailer->error()); |
|
1010 | + if (!$rc) print_error($mailer->error()); |
|
1011 | 1011 | |
1012 | - $resetpass_token_full = time() . ":" . $resetpass_token; |
|
1012 | + $resetpass_token_full = time() . ":" . $resetpass_token; |
|
1013 | 1013 | |
1014 | - $sth = $this->pdo->prepare("UPDATE ttrss_users |
|
1014 | + $sth = $this->pdo->prepare("UPDATE ttrss_users |
|
1015 | 1015 | SET resetpass_token = ? |
1016 | 1016 | WHERE login = ? AND email = ?"); |
1017 | 1017 | |
1018 | - $sth->execute([$resetpass_token_full, $login, $email]); |
|
1018 | + $sth->execute([$resetpass_token_full, $login, $email]); |
|
1019 | 1019 | |
1020 | - } else { |
|
1021 | - print_error("User ID not found."); |
|
1022 | - } |
|
1020 | + } else { |
|
1021 | + print_error("User ID not found."); |
|
1022 | + } |
|
1023 | 1023 | |
1024 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
1024 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
1025 | 1025 | |
1026 | - } else { |
|
1027 | - print_error(__("Sorry, login and email combination not found.")); |
|
1026 | + } else { |
|
1027 | + print_error(__("Sorry, login and email combination not found.")); |
|
1028 | 1028 | |
1029 | - print "<form method='GET' action='public.php'> |
|
1029 | + print "<form method='GET' action='public.php'> |
|
1030 | 1030 | <input type='hidden' name='op' value='forgotpass'> |
1031 | 1031 | <button dojoType='dijit.form.Button' type='submit'>".__("Go back")."</button> |
1032 | 1032 | </form>"; |
1033 | 1033 | |
1034 | - } |
|
1035 | - } |
|
1034 | + } |
|
1035 | + } |
|
1036 | 1036 | |
1037 | - } |
|
1037 | + } |
|
1038 | 1038 | |
1039 | - print "</div>"; |
|
1040 | - print "</div>"; |
|
1041 | - print "</body>"; |
|
1042 | - print "</html>"; |
|
1039 | + print "</div>"; |
|
1040 | + print "</div>"; |
|
1041 | + print "</body>"; |
|
1042 | + print "</html>"; |
|
1043 | 1043 | |
1044 | - } |
|
1044 | + } |
|
1045 | 1045 | |
1046 | - public function dbupdate() { |
|
1047 | - startup_gettext(); |
|
1046 | + public function dbupdate() { |
|
1047 | + startup_gettext(); |
|
1048 | 1048 | |
1049 | - if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) { |
|
1050 | - $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script."); |
|
1051 | - render_login_form(); |
|
1052 | - exit; |
|
1053 | - } |
|
1049 | + if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) { |
|
1050 | + $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script."); |
|
1051 | + render_login_form(); |
|
1052 | + exit; |
|
1053 | + } |
|
1054 | 1054 | |
1055 | - ?> |
|
1055 | + ?> |
|
1056 | 1056 | <!DOCTYPE html> |
1057 | 1057 | <html> |
1058 | 1058 | <head> |
@@ -1062,11 +1062,11 @@ discard block |
||
1062 | 1062 | <link rel="shortcut icon" type="image/png" href="images/favicon.png"> |
1063 | 1063 | <link rel="icon" type="image/png" sizes="72x72" href="images/favicon-72px.png"> |
1064 | 1064 | <?php |
1065 | - echo stylesheet_tag("css/default.css"); |
|
1066 | - echo javascript_tag("lib/prototype.js"); |
|
1067 | - echo javascript_tag("lib/dojo/dojo.js"); |
|
1068 | - echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
1069 | - ?> |
|
1065 | + echo stylesheet_tag("css/default.css"); |
|
1066 | + echo javascript_tag("lib/prototype.js"); |
|
1067 | + echo javascript_tag("lib/dojo/dojo.js"); |
|
1068 | + echo javascript_tag("lib/dojo/tt-rss-layer.js"); |
|
1069 | + ?> |
|
1070 | 1070 | <style type="text/css"> |
1071 | 1071 | span.ok { color : #009000; font-weight : bold; } |
1072 | 1072 | span.err { color : #ff0000; font-weight : bold; } |
@@ -1093,139 +1093,139 @@ discard block |
||
1093 | 1093 | <div class="content"> |
1094 | 1094 | |
1095 | 1095 | <?php |
1096 | - @$op = clean($_REQUEST["subop"]); |
|
1097 | - $updater = new DbUpdater(DB_TYPE, SCHEMA_VERSION); |
|
1096 | + @$op = clean($_REQUEST["subop"]); |
|
1097 | + $updater = new DbUpdater(DB_TYPE, SCHEMA_VERSION); |
|
1098 | 1098 | |
1099 | - if ($op == "performupdate") { |
|
1100 | - if ($updater->isUpdateRequired()) { |
|
1099 | + if ($op == "performupdate") { |
|
1100 | + if ($updater->isUpdateRequired()) { |
|
1101 | 1101 | |
1102 | - print "<h2>" . T_sprintf("Performing updates to version %d", SCHEMA_VERSION) . "</h2>"; |
|
1102 | + print "<h2>" . T_sprintf("Performing updates to version %d", SCHEMA_VERSION) . "</h2>"; |
|
1103 | 1103 | |
1104 | - for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) { |
|
1105 | - print "<ul>"; |
|
1104 | + for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) { |
|
1105 | + print "<ul>"; |
|
1106 | 1106 | |
1107 | - print "<li class='text-info'>" . T_sprintf("Updating to version %d", $i) . "</li>"; |
|
1107 | + print "<li class='text-info'>" . T_sprintf("Updating to version %d", $i) . "</li>"; |
|
1108 | 1108 | |
1109 | - print "<li>"; |
|
1110 | - $result = $updater->performUpdateTo($i, true); |
|
1111 | - print "</li>"; |
|
1109 | + print "<li>"; |
|
1110 | + $result = $updater->performUpdateTo($i, true); |
|
1111 | + print "</li>"; |
|
1112 | 1112 | |
1113 | - if (!$result) { |
|
1114 | - print "</ul>"; |
|
1113 | + if (!$result) { |
|
1114 | + print "</ul>"; |
|
1115 | 1115 | |
1116 | - print_error("One of the updates failed. Either retry the process or perform updates manually."); |
|
1116 | + print_error("One of the updates failed. Either retry the process or perform updates manually."); |
|
1117 | 1117 | |
1118 | - print "<form method='POST'> |
|
1118 | + print "<form method='POST'> |
|
1119 | 1119 | <input type='hidden' name='subop' value='performupdate'> |
1120 | 1120 | <button type='submit' dojoType='dijit.form.Button' class='alt-danger' onclick='return confirmOP()'>".__("Try again")."</button> |
1121 | 1121 | <a href='index.php'>".__("Return to Tiny Tiny RSS")."</a> |
1122 | 1122 | </form>"; |
1123 | 1123 | |
1124 | - return; |
|
1125 | - } else { |
|
1126 | - print "<li class='text-success'>" . __("Completed.") . "</li>"; |
|
1127 | - print "</ul>"; |
|
1128 | - } |
|
1129 | - } |
|
1124 | + return; |
|
1125 | + } else { |
|
1126 | + print "<li class='text-success'>" . __("Completed.") . "</li>"; |
|
1127 | + print "</ul>"; |
|
1128 | + } |
|
1129 | + } |
|
1130 | 1130 | |
1131 | - print_notice("Your Tiny Tiny RSS database is now updated to the latest version."); |
|
1131 | + print_notice("Your Tiny Tiny RSS database is now updated to the latest version."); |
|
1132 | 1132 | |
1133 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
1133 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
1134 | 1134 | |
1135 | - } else { |
|
1136 | - print_notice("Tiny Tiny RSS database is up to date."); |
|
1135 | + } else { |
|
1136 | + print_notice("Tiny Tiny RSS database is up to date."); |
|
1137 | 1137 | |
1138 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
1139 | - } |
|
1140 | - } else { |
|
1141 | - if ($updater->isUpdateRequired()) { |
|
1138 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
1139 | + } |
|
1140 | + } else { |
|
1141 | + if ($updater->isUpdateRequired()) { |
|
1142 | 1142 | |
1143 | - print "<h2>".T_sprintf("Tiny Tiny RSS database needs update to the latest version (%d to %d).", |
|
1144 | - $updater->getSchemaVersion(), SCHEMA_VERSION)."</h2>"; |
|
1143 | + print "<h2>".T_sprintf("Tiny Tiny RSS database needs update to the latest version (%d to %d).", |
|
1144 | + $updater->getSchemaVersion(), SCHEMA_VERSION)."</h2>"; |
|
1145 | 1145 | |
1146 | - if (DB_TYPE == "mysql") { |
|
1147 | - print_error("<strong>READ THIS:</strong> Due to MySQL limitations, your database is not completely protected while updating. ". |
|
1148 | - "Errors may put it in an inconsistent state requiring manual rollback. <strong>BACKUP YOUR DATABASE BEFORE CONTINUING.</strong>"); |
|
1149 | - } else { |
|
1150 | - print_warning("Please backup your database before proceeding."); |
|
1151 | - } |
|
1146 | + if (DB_TYPE == "mysql") { |
|
1147 | + print_error("<strong>READ THIS:</strong> Due to MySQL limitations, your database is not completely protected while updating. ". |
|
1148 | + "Errors may put it in an inconsistent state requiring manual rollback. <strong>BACKUP YOUR DATABASE BEFORE CONTINUING.</strong>"); |
|
1149 | + } else { |
|
1150 | + print_warning("Please backup your database before proceeding."); |
|
1151 | + } |
|
1152 | 1152 | |
1153 | - print "<form method='POST'> |
|
1153 | + print "<form method='POST'> |
|
1154 | 1154 | <input type='hidden' name='subop' value='performupdate'> |
1155 | 1155 | <button type='submit' dojoType='dijit.form.Button' class='alt-danger' onclick='return confirmOP()'>".__("Perform updates")."</button> |
1156 | 1156 | </form>"; |
1157 | 1157 | |
1158 | - } else { |
|
1158 | + } else { |
|
1159 | 1159 | |
1160 | - print_notice("Tiny Tiny RSS database is up to date."); |
|
1160 | + print_notice("Tiny Tiny RSS database is up to date."); |
|
1161 | 1161 | |
1162 | - print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
1163 | - } |
|
1164 | - } |
|
1165 | - ?> |
|
1162 | + print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; |
|
1163 | + } |
|
1164 | + } |
|
1165 | + ?> |
|
1166 | 1166 | |
1167 | 1167 | </div> |
1168 | 1168 | </div> |
1169 | 1169 | </body> |
1170 | 1170 | </html> |
1171 | 1171 | <?php |
1172 | - } |
|
1173 | - |
|
1174 | - public function cached_url() { |
|
1175 | - list ($cache_dir, $filename) = explode("/", $_GET["file"], 2); |
|
1176 | - |
|
1177 | - // we do not allow files with extensions at the moment |
|
1178 | - $filename = str_replace(".", "", $filename); |
|
1179 | - |
|
1180 | - $cache = new DiskCache($cache_dir); |
|
1181 | - |
|
1182 | - if ($cache->exists($filename)) { |
|
1183 | - $cache->send($filename); |
|
1184 | - } else { |
|
1185 | - header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); |
|
1186 | - echo "File not found."; |
|
1187 | - } |
|
1188 | - } |
|
1189 | - |
|
1190 | - private function make_article_tag_uri($id, $timestamp) { |
|
1191 | - |
|
1192 | - $timestamp = date("Y-m-d", strtotime($timestamp)); |
|
1193 | - |
|
1194 | - return "tag:" . parse_url(get_self_url_prefix(), PHP_URL_HOST) . ",$timestamp:/$id"; |
|
1195 | - } |
|
1196 | - |
|
1197 | - // this should be used very carefully because this endpoint is exposed to unauthenticated users |
|
1198 | - // plugin data is not loaded because there's no user context and owner_uid/session may or may not be available |
|
1199 | - // in general, don't do anything user-related in here and do not modify $_SESSION |
|
1200 | - public function pluginhandler() { |
|
1201 | - $host = new PluginHost(); |
|
1202 | - |
|
1203 | - $plugin_name = clean_filename($_REQUEST["plugin"]); |
|
1204 | - $method = clean($_REQUEST["pmethod"]); |
|
1205 | - |
|
1206 | - $host->load($plugin_name, PluginHost::KIND_USER, 0); |
|
1207 | - $host->load_data(); |
|
1208 | - |
|
1209 | - $plugin = $host->get_plugin($plugin_name); |
|
1210 | - |
|
1211 | - if ($plugin) { |
|
1212 | - if (method_exists($plugin, $method)) { |
|
1213 | - if ($plugin->is_public_method($method)) { |
|
1214 | - $plugin->$method(); |
|
1215 | - } else { |
|
1216 | - user_error("PluginHandler[PUBLIC]: Requested private method '$method' of plugin '$plugin_name'.", E_USER_WARNING); |
|
1217 | - header("Content-Type: text/json"); |
|
1218 | - print error_json(6); |
|
1219 | - } |
|
1220 | - } else { |
|
1221 | - user_error("PluginHandler[PUBLIC]: Requested unknown method '$method' of plugin '$plugin_name'.", E_USER_WARNING); |
|
1222 | - header("Content-Type: text/json"); |
|
1223 | - print error_json(13); |
|
1224 | - } |
|
1225 | - } else { |
|
1226 | - user_error("PluginHandler[PUBLIC]: Requested method '$method' of unknown plugin '$plugin_name'.", E_USER_WARNING); |
|
1227 | - header("Content-Type: text/json"); |
|
1228 | - print error_json(14); |
|
1229 | - } |
|
1230 | - } |
|
1172 | + } |
|
1173 | + |
|
1174 | + public function cached_url() { |
|
1175 | + list ($cache_dir, $filename) = explode("/", $_GET["file"], 2); |
|
1176 | + |
|
1177 | + // we do not allow files with extensions at the moment |
|
1178 | + $filename = str_replace(".", "", $filename); |
|
1179 | + |
|
1180 | + $cache = new DiskCache($cache_dir); |
|
1181 | + |
|
1182 | + if ($cache->exists($filename)) { |
|
1183 | + $cache->send($filename); |
|
1184 | + } else { |
|
1185 | + header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); |
|
1186 | + echo "File not found."; |
|
1187 | + } |
|
1188 | + } |
|
1189 | + |
|
1190 | + private function make_article_tag_uri($id, $timestamp) { |
|
1191 | + |
|
1192 | + $timestamp = date("Y-m-d", strtotime($timestamp)); |
|
1193 | + |
|
1194 | + return "tag:" . parse_url(get_self_url_prefix(), PHP_URL_HOST) . ",$timestamp:/$id"; |
|
1195 | + } |
|
1196 | + |
|
1197 | + // this should be used very carefully because this endpoint is exposed to unauthenticated users |
|
1198 | + // plugin data is not loaded because there's no user context and owner_uid/session may or may not be available |
|
1199 | + // in general, don't do anything user-related in here and do not modify $_SESSION |
|
1200 | + public function pluginhandler() { |
|
1201 | + $host = new PluginHost(); |
|
1202 | + |
|
1203 | + $plugin_name = clean_filename($_REQUEST["plugin"]); |
|
1204 | + $method = clean($_REQUEST["pmethod"]); |
|
1205 | + |
|
1206 | + $host->load($plugin_name, PluginHost::KIND_USER, 0); |
|
1207 | + $host->load_data(); |
|
1208 | + |
|
1209 | + $plugin = $host->get_plugin($plugin_name); |
|
1210 | + |
|
1211 | + if ($plugin) { |
|
1212 | + if (method_exists($plugin, $method)) { |
|
1213 | + if ($plugin->is_public_method($method)) { |
|
1214 | + $plugin->$method(); |
|
1215 | + } else { |
|
1216 | + user_error("PluginHandler[PUBLIC]: Requested private method '$method' of plugin '$plugin_name'.", E_USER_WARNING); |
|
1217 | + header("Content-Type: text/json"); |
|
1218 | + print error_json(6); |
|
1219 | + } |
|
1220 | + } else { |
|
1221 | + user_error("PluginHandler[PUBLIC]: Requested unknown method '$method' of plugin '$plugin_name'.", E_USER_WARNING); |
|
1222 | + header("Content-Type: text/json"); |
|
1223 | + print error_json(13); |
|
1224 | + } |
|
1225 | + } else { |
|
1226 | + user_error("PluginHandler[PUBLIC]: Requested method '$method' of unknown plugin '$plugin_name'.", E_USER_WARNING); |
|
1227 | + header("Content-Type: text/json"); |
|
1228 | + print error_json(14); |
|
1229 | + } |
|
1230 | + } |
|
1231 | 1231 | } |