]>
Commit | Line | Data |
---|---|---|
6afcbcd1 AD |
1 | <?php |
2 | class Article extends Handler_Protected { | |
3 | ||
4 | function csrf_ignore($method) { | |
1c9bda91 | 5 | $csrf_ignored = array("redirect", "editarticletags"); |
6afcbcd1 AD |
6 | |
7 | return array_search($method, $csrf_ignored) !== false; | |
8 | } | |
9 | ||
10 | function redirect() { | |
e6532439 | 11 | $id = clean($_REQUEST['id']); |
187abfe7 | 12 | |
c39ee272 AD |
13 | $sth = $this->pdo->prepare("SELECT link FROM ttrss_entries, ttrss_user_entries |
14 | WHERE id = ? AND id = ref_id AND owner_uid = ? | |
6afcbcd1 | 15 | LIMIT 1"); |
c39ee272 | 16 | $sth->execute([$id, $_SESSION['uid']]); |
6afcbcd1 | 17 | |
c39ee272 AD |
18 | if ($row = $sth->fetch()) { |
19 | $article_url = $row['link']; | |
6afcbcd1 AD |
20 | $article_url = str_replace("\n", "", $article_url); |
21 | ||
22 | header("Location: $article_url"); | |
23 | return; | |
24 | ||
25 | } else { | |
26 | print_error(__("Article not found.")); | |
27 | } | |
28 | } | |
29 | ||
30 | function view() { | |
e6532439 AD |
31 | $id = clean($_REQUEST["id"]); |
32 | $cids = explode(",", clean($_REQUEST["cids"])); | |
33 | $mode = clean($_REQUEST["mode"]); | |
6afcbcd1 AD |
34 | |
35 | // in prefetch mode we only output requested cids, main article | |
36 | // just gets marked as read (it already exists in client cache) | |
37 | ||
38 | $articles = array(); | |
39 | ||
40 | if ($mode == "") { | |
7e5f8d9f | 41 | array_push($articles, $this->format_article($id, false)); |
6afcbcd1 | 42 | } else if ($mode == "zoom") { |
7e5f8d9f | 43 | array_push($articles, $this->format_article($id, true, true)); |
6afcbcd1 | 44 | } else if ($mode == "raw") { |
f48f292d | 45 | if (isset($_REQUEST['html'])) { |
6afcbcd1 | 46 | header("Content-Type: text/html"); |
9dd336a2 | 47 | print '<link rel="stylesheet" type="text/css" href="css/default.css"/>'; |
6afcbcd1 AD |
48 | } |
49 | ||
7e5f8d9f | 50 | $article = $this->format_article($id, false, isset($_REQUEST["zoom"])); |
6afcbcd1 AD |
51 | print $article['content']; |
52 | return; | |
53 | } | |
54 | ||
a42c55f0 | 55 | $this->catchupArticleById($id, 0); |
6afcbcd1 AD |
56 | |
57 | if (!$_SESSION["bw_limit"]) { | |
58 | foreach ($cids as $cid) { | |
59 | if ($cid) { | |
7e5f8d9f | 60 | array_push($articles, $this->format_article($cid, false, false)); |
6afcbcd1 AD |
61 | } |
62 | } | |
63 | } | |
64 | ||
65 | print json_encode($articles); | |
66 | } | |
67 | ||
a42c55f0 | 68 | private function catchupArticleById($id, $cmode) { |
6afcbcd1 AD |
69 | |
70 | if ($cmode == 0) { | |
c39ee272 | 71 | $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
6afcbcd1 | 72 | unread = false,last_read = NOW() |
c39ee272 | 73 | WHERE ref_id = ? AND owner_uid = ?"); |
6afcbcd1 | 74 | } else if ($cmode == 1) { |
c39ee272 | 75 | $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
6afcbcd1 | 76 | unread = true |
c39ee272 | 77 | WHERE ref_id = ? AND owner_uid = ?"); |
6afcbcd1 | 78 | } else { |
c39ee272 | 79 | $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET |
6afcbcd1 | 80 | unread = NOT unread,last_read = NOW() |
c39ee272 | 81 | WHERE ref_id = ? AND owner_uid = ?"); |
6afcbcd1 AD |
82 | } |
83 | ||
c39ee272 AD |
84 | $sth->execute([$id, $_SESSION['uid']]); |
85 | ||
4122da02 | 86 | $feed_id = $this->getArticleFeed($id); |
2ed0d6c4 | 87 | CCache::update($feed_id, $_SESSION["uid"]); |
6afcbcd1 AD |
88 | } |
89 | ||
a42c55f0 | 90 | static function create_published_article($title, $url, $content, $labels_str, |
6afcbcd1 AD |
91 | $owner_uid) { |
92 | ||
5e3d5480 | 93 | $guid = 'SHA1:' . sha1("ttshared:" . $url . $owner_uid); // include owner_uid to prevent global GUID clash |
666cd333 AD |
94 | |
95 | if (!$content) { | |
96 | $pluginhost = new PluginHost(); | |
97 | $pluginhost->load_all(PluginHost::KIND_ALL, $owner_uid); | |
7af2e795 | 98 | $pluginhost->load_data(); |
666cd333 AD |
99 | |
100 | $af_readability = $pluginhost->get_plugin("Af_Readability"); | |
101 | ||
102 | if ($af_readability) { | |
7af2e795 | 103 | $enable_share_anything = $pluginhost->get($af_readability, "enable_share_anything"); |
666cd333 | 104 | |
7af2e795 AD |
105 | if ($enable_share_anything) { |
106 | $extracted_content = $af_readability->extract_content($url); | |
107 | ||
2c57df75 | 108 | if ($extracted_content) $content = $extracted_content; |
7af2e795 | 109 | } |
666cd333 AD |
110 | } |
111 | } | |
112 | ||
6afcbcd1 AD |
113 | $content_hash = sha1($content); |
114 | ||
115 | if ($labels_str != "") { | |
116 | $labels = explode(",", $labels_str); | |
117 | } else { | |
118 | $labels = array(); | |
119 | } | |
120 | ||
121 | $rc = false; | |
122 | ||
123 | if (!$title) $title = $url; | |
124 | if (!$title && !$url) return false; | |
125 | ||
126 | if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) return false; | |
127 | ||
d0e73ed8 AD |
128 | $pdo = Db::pdo(); |
129 | ||
130 | $pdo->beginTransaction(); | |
6afcbcd1 AD |
131 | |
132 | // only check for our user data here, others might have shared this with different content etc | |
d0e73ed8 | 133 | $sth = $pdo->prepare("SELECT id FROM ttrss_entries, ttrss_user_entries WHERE |
c39ee272 AD |
134 | guid = ? AND ref_id = id AND owner_uid = ? LIMIT 1"); |
135 | $sth->execute([$guid, $owner_uid]); | |
6afcbcd1 | 136 | |
c39ee272 AD |
137 | if ($row = $sth->fetch()) { |
138 | $ref_id = $row['id']; | |
6afcbcd1 | 139 | |
d0e73ed8 | 140 | $sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
c39ee272 AD |
141 | ref_id = ? AND owner_uid = ? LIMIT 1"); |
142 | $sth->execute([$ref_id, $owner_uid]); | |
6afcbcd1 | 143 | |
c39ee272 AD |
144 | if ($row = $sth->fetch()) { |
145 | $int_id = $row['int_id']; | |
6afcbcd1 | 146 | |
d0e73ed8 | 147 | $sth = $pdo->prepare("UPDATE ttrss_entries SET |
c39ee272 AD |
148 | content = ?, content_hash = ? WHERE id = ?"); |
149 | $sth->execute([$content, $content_hash, $ref_id]); | |
6afcbcd1 | 150 | |
d0e73ed8 | 151 | $sth = $pdo->prepare("UPDATE ttrss_user_entries SET published = true, |
d2888e88 | 152 | last_published = NOW() WHERE |
c39ee272 AD |
153 | int_id = ? AND owner_uid = ?"); |
154 | $sth->execute([$int_id, $owner_uid]); | |
155 | ||
6afcbcd1 AD |
156 | } else { |
157 | ||
d0e73ed8 | 158 | $sth = $pdo->prepare("INSERT INTO ttrss_user_entries |
d2888e88 AD |
159 | (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, |
160 | last_read, note, unread, last_published) | |
6afcbcd1 | 161 | VALUES |
c39ee272 AD |
162 | (?, '', NULL, NULL, ?, true, '', '', NOW(), '', false, NOW())"); |
163 | $sth->execute([$ref_id, $owner_uid]); | |
6afcbcd1 AD |
164 | } |
165 | ||
166 | if (count($labels) != 0) { | |
167 | foreach ($labels as $label) { | |
7c9b5a3f | 168 | Labels::add_article($ref_id, trim($label), $owner_uid); |
6afcbcd1 AD |
169 | } |
170 | } | |
171 | ||
172 | $rc = true; | |
173 | ||
174 | } else { | |
d0e73ed8 | 175 | $sth = $pdo->prepare("INSERT INTO ttrss_entries |
6afcbcd1 AD |
176 | (title, guid, link, updated, content, content_hash, date_entered, date_updated) |
177 | VALUES | |
c39ee272 AD |
178 | (?, ?, ?, NOW(), ?, ?, NOW(), NOW())"); |
179 | $sth->execute([$title, $guid, $url, $content, $content_hash]); | |
6afcbcd1 | 180 | |
d0e73ed8 | 181 | $sth = $pdo->prepare("SELECT id FROM ttrss_entries WHERE guid = ?"); |
c39ee272 | 182 | $sth->execute([$guid]); |
6afcbcd1 | 183 | |
c39ee272 AD |
184 | if ($row = $sth->fetch()) { |
185 | $ref_id = $row["id"]; | |
6afcbcd1 | 186 | |
d0e73ed8 | 187 | $sth = $pdo->prepare("INSERT INTO ttrss_user_entries |
d2888e88 AD |
188 | (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache, |
189 | last_read, note, unread, last_published) | |
6afcbcd1 | 190 | VALUES |
c39ee272 AD |
191 | (?, '', NULL, NULL, ?, true, '', '', NOW(), '', false, NOW())"); |
192 | $sth->execute([$ref_id, $owner_uid]); | |
6afcbcd1 AD |
193 | |
194 | if (count($labels) != 0) { | |
195 | foreach ($labels as $label) { | |
7c9b5a3f | 196 | Labels::add_article($ref_id, trim($label), $owner_uid); |
6afcbcd1 AD |
197 | } |
198 | } | |
199 | ||
200 | $rc = true; | |
201 | } | |
202 | } | |
203 | ||
d0e73ed8 | 204 | $pdo->commit(); |
6afcbcd1 AD |
205 | |
206 | return $rc; | |
207 | } | |
208 | ||
1c9bda91 AD |
209 | function editArticleTags() { |
210 | ||
211 | print __("Tags for this article (separated by commas):")."<br>"; | |
212 | ||
e6532439 | 213 | $param = clean($_REQUEST['param']); |
1c9bda91 | 214 | |
2c57df75 | 215 | $tags = Article::get_article_tags($param); |
1c9bda91 AD |
216 | |
217 | $tags_str = join(", ", $tags); | |
218 | ||
328118d1 AD |
219 | print_hidden("id", "$param"); |
220 | print_hidden("op", "article"); | |
221 | print_hidden("method", "setArticleTags"); | |
1c9bda91 AD |
222 | |
223 | print "<table width='100%'><tr><td>"; | |
224 | ||
225 | print "<textarea dojoType=\"dijit.form.SimpleTextarea\" rows='4' | |
8b8568e9 | 226 | style='height : 100px; font-size : 12px; width : 98%' id=\"tags_str\" |
1c9bda91 AD |
227 | name='tags_str'>$tags_str</textarea> |
228 | <div class=\"autocomplete\" id=\"tags_choices\" | |
229 | style=\"display:none\"></div>"; | |
230 | ||
231 | print "</td></tr></table>"; | |
232 | ||
233 | print "<div class='dlgButtons'>"; | |
234 | ||
235 | print "<button dojoType=\"dijit.form.Button\" | |
236 | onclick=\"dijit.byId('editTagsDlg').execute()\">".__('Save')."</button> "; | |
237 | print "<button dojoType=\"dijit.form.Button\" | |
238 | onclick=\"dijit.byId('editTagsDlg').hide()\">".__('Cancel')."</button>"; | |
239 | print "</div>"; | |
240 | ||
241 | } | |
6afcbcd1 | 242 | |
d719b062 | 243 | function setScore() { |
e6532439 AD |
244 | $ids = explode(",", clean($_REQUEST['id'])); |
245 | $score = (int)clean($_REQUEST['score']); | |
d719b062 | 246 | |
c39ee272 AD |
247 | $ids_qmarks = arr_qmarks($ids); |
248 | ||
249 | $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET | |
250 | score = ? WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); | |
251 | ||
252 | $sth->execute(array_merge([$score], $ids, [$_SESSION['uid']])); | |
d719b062 | 253 | |
6f7798b6 | 254 | print json_encode(array("id" => $ids, |
a72cd54c AD |
255 | "score" => (int)$score, |
256 | "score_pic" => get_score_pic($score))); | |
257 | } | |
258 | ||
259 | function getScore() { | |
e6532439 | 260 | $id = clean($_REQUEST['id']); |
c39ee272 AD |
261 | |
262 | $sth = $this->pdo->prepare("SELECT score FROM ttrss_user_entries WHERE ref_id = ? AND owner_uid = ?"); | |
263 | $sth->execute([$id, $_SESSION['uid']]); | |
264 | $row = $sth->fetch(); | |
a72cd54c | 265 | |
c39ee272 | 266 | $score = $row['score']; |
a72cd54c AD |
267 | |
268 | print json_encode(array("id" => $id, | |
269 | "score" => (int)$score, | |
d719b062 AD |
270 | "score_pic" => get_score_pic($score))); |
271 | } | |
272 | ||
6afcbcd1 | 273 | |
5df8be5c AD |
274 | function setArticleTags() { |
275 | ||
e6532439 | 276 | $id = clean($_REQUEST["id"]); |
5df8be5c | 277 | |
e6532439 | 278 | $tags_str = clean($_REQUEST["tags_str"]); |
5df8be5c AD |
279 | $tags = array_unique(trim_array(explode(",", $tags_str))); |
280 | ||
2e46b434 | 281 | $this->pdo->beginTransaction(); |
5df8be5c | 282 | |
d0e73ed8 AD |
283 | $sth = $this->pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE |
284 | ref_id = ? AND owner_uid = ? LIMIT 1"); | |
285 | $sth->execute([$id, $_SESSION['uid']]); | |
5df8be5c | 286 | |
d0e73ed8 | 287 | if ($row = $sth->fetch()) { |
5df8be5c AD |
288 | |
289 | $tags_to_cache = array(); | |
290 | ||
d0e73ed8 | 291 | $int_id = $row['int_id']; |
5df8be5c | 292 | |
d0e73ed8 AD |
293 | $sth = $this->pdo->prepare("DELETE FROM ttrss_tags WHERE |
294 | post_int_id = ? AND owner_uid = ?"); | |
295 | $sth->execute([$int_id, $_SESSION['uid']]); | |
5df8be5c AD |
296 | |
297 | foreach ($tags as $tag) { | |
298 | $tag = sanitize_tag($tag); | |
299 | ||
300 | if (!tag_is_valid($tag)) { | |
301 | continue; | |
302 | } | |
303 | ||
304 | if (preg_match("/^[0-9]*$/", $tag)) { | |
305 | continue; | |
306 | } | |
307 | ||
308 | // print "<!-- $id : $int_id : $tag -->"; | |
309 | ||
310 | if ($tag != '') { | |
d0e73ed8 AD |
311 | $sth = $this->pdo->prepare("INSERT INTO ttrss_tags |
312 | (post_int_id, owner_uid, tag_name) | |
313 | VALUES (?, ?, ?)"); | |
314 | ||
315 | $sth->execute([$int_id, $_SESSION['uid'], $tag]); | |
5df8be5c AD |
316 | } |
317 | ||
318 | array_push($tags_to_cache, $tag); | |
319 | } | |
320 | ||
321 | /* update tag cache */ | |
322 | ||
323 | sort($tags_to_cache); | |
324 | $tags_str = join(",", $tags_to_cache); | |
325 | ||
d0e73ed8 AD |
326 | $sth = $this->pdo->prepare("UPDATE ttrss_user_entries |
327 | SET tag_cache = ? WHERE ref_id = ? AND owner_uid = ?"); | |
328 | $sth->execute([$tags_str, $id, $_SESSION['uid']]); | |
5df8be5c AD |
329 | } |
330 | ||
2e46b434 | 331 | $this->pdo->commit(); |
5df8be5c | 332 | |
7e5f8d9f AD |
333 | $tags = Article::get_article_tags($id); |
334 | $tags_str = $this->format_tags_string($tags, $id); | |
5df8be5c AD |
335 | $tags_str_full = join(", ", $tags); |
336 | ||
337 | if (!$tags_str_full) $tags_str_full = __("no tags"); | |
338 | ||
339 | print json_encode(array("id" => (int)$id, | |
340 | "content" => $tags_str, "content_full" => $tags_str_full)); | |
341 | } | |
342 | ||
c83554bd AD |
343 | |
344 | function completeTags() { | |
e6532439 | 345 | $search = clean($_REQUEST["search"]); |
c83554bd | 346 | |
d0e73ed8 AD |
347 | $sth = $this->pdo->prepare("SELECT DISTINCT tag_name FROM ttrss_tags |
348 | WHERE owner_uid = ? AND | |
349 | tag_name LIKE ? ORDER BY tag_name | |
c83554bd AD |
350 | LIMIT 10"); |
351 | ||
d0e73ed8 AD |
352 | $sth->execute([$_SESSION['uid'], "$search%"]); |
353 | ||
c83554bd | 354 | print "<ul>"; |
d0e73ed8 | 355 | while ($line = $sth->fetch()) { |
c83554bd AD |
356 | print "<li>" . $line["tag_name"] . "</li>"; |
357 | } | |
358 | print "</ul>"; | |
359 | } | |
360 | ||
4b7726f0 AD |
361 | function assigntolabel() { |
362 | return $this->labelops(true); | |
363 | } | |
364 | ||
365 | function removefromlabel() { | |
366 | return $this->labelops(false); | |
367 | } | |
368 | ||
369 | private function labelops($assign) { | |
370 | $reply = array(); | |
371 | ||
e6532439 AD |
372 | $ids = explode(",", clean($_REQUEST["ids"])); |
373 | $label_id = clean($_REQUEST["lid"]); | |
4b7726f0 | 374 | |
c39ee272 | 375 | $label = db_escape_string(Labels::find_caption($label_id, |
4b7726f0 AD |
376 | $_SESSION["uid"])); |
377 | ||
378 | $reply["info-for-headlines"] = array(); | |
379 | ||
380 | if ($label) { | |
381 | ||
382 | foreach ($ids as $id) { | |
383 | ||
384 | if ($assign) | |
7c9b5a3f | 385 | Labels::add_article($id, $label, $_SESSION["uid"]); |
4b7726f0 | 386 | else |
7c9b5a3f | 387 | Labels::remove_article($id, $label, $_SESSION["uid"]); |
4b7726f0 | 388 | |
4a0da0e5 | 389 | $labels = $this->get_article_labels($id, $_SESSION["uid"]); |
4b7726f0 AD |
390 | |
391 | array_push($reply["info-for-headlines"], | |
7e5f8d9f | 392 | array("id" => $id, "labels" => $this->format_article_labels($labels))); |
4b7726f0 AD |
393 | |
394 | } | |
395 | } | |
396 | ||
397 | $reply["message"] = "UPDATE_COUNTERS"; | |
398 | ||
399 | print json_encode($reply); | |
400 | } | |
401 | ||
4122da02 | 402 | function getArticleFeed($id) { |
d0e73ed8 AD |
403 | $sth = $this->pdo->prepare("SELECT feed_id FROM ttrss_user_entries |
404 | WHERE ref_id = ? AND owner_uid = ?"); | |
405 | $sth->execute([$id, $_SESSION['uid']]); | |
4122da02 | 406 | |
d0e73ed8 AD |
407 | if ($row = $sth->fetch()) { |
408 | return $row["feed_id"]; | |
4122da02 AD |
409 | } else { |
410 | return 0; | |
411 | } | |
412 | } | |
4b7726f0 | 413 | |
7e5f8d9f AD |
414 | static function format_article_enclosures($id, $always_display_enclosures, |
415 | $article_content, $hide_images = false) { | |
416 | ||
417 | $result = Article::get_article_enclosures($id); | |
418 | $rv = ''; | |
419 | ||
420 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ENCLOSURES) as $plugin) { | |
421 | $retval = $plugin->hook_format_enclosures($rv, $result, $id, $always_display_enclosures, $article_content, $hide_images); | |
422 | if (is_array($retval)) { | |
423 | $rv = $retval[0]; | |
424 | $result = $retval[1]; | |
425 | } else { | |
426 | $rv = $retval; | |
427 | } | |
428 | } | |
429 | unset($retval); // Unset to prevent breaking render if there are no HOOK_RENDER_ENCLOSURE hooks below. | |
430 | ||
431 | if ($rv === '' && !empty($result)) { | |
432 | $entries_html = array(); | |
433 | $entries = array(); | |
434 | $entries_inline = array(); | |
435 | ||
436 | foreach ($result as $line) { | |
437 | ||
438 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ENCLOSURE_ENTRY) as $plugin) { | |
439 | $line = $plugin->hook_enclosure_entry($line); | |
440 | } | |
441 | ||
442 | $url = $line["content_url"]; | |
443 | $ctype = $line["content_type"]; | |
444 | $title = $line["title"]; | |
445 | $width = $line["width"]; | |
446 | $height = $line["height"]; | |
447 | ||
448 | if (!$ctype) $ctype = __("unknown type"); | |
449 | ||
450 | //$filename = substr($url, strrpos($url, "/")+1); | |
451 | $filename = basename($url); | |
452 | ||
453 | $player = format_inline_player($url, $ctype); | |
454 | ||
455 | if ($player) array_push($entries_inline, $player); | |
456 | ||
457 | # $entry .= " <a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\" rel=\"noopener noreferrer\">" . | |
458 | # $filename . " (" . $ctype . ")" . "</a>"; | |
459 | ||
460 | $entry = "<div onclick=\"openUrlPopup('".htmlspecialchars($url)."')\" | |
461 | dojoType=\"dijit.MenuItem\">$filename ($ctype)</div>"; | |
462 | ||
463 | array_push($entries_html, $entry); | |
464 | ||
465 | $entry = array(); | |
466 | ||
467 | $entry["type"] = $ctype; | |
468 | $entry["filename"] = $filename; | |
469 | $entry["url"] = $url; | |
470 | $entry["title"] = $title; | |
471 | $entry["width"] = $width; | |
472 | $entry["height"] = $height; | |
473 | ||
474 | array_push($entries, $entry); | |
475 | } | |
476 | ||
477 | if ($_SESSION['uid'] && !get_pref("STRIP_IMAGES") && !$_SESSION["bw_limit"]) { | |
478 | if ($always_display_enclosures || | |
479 | !preg_match("/<img/i", $article_content)) { | |
480 | ||
481 | foreach ($entries as $entry) { | |
482 | ||
483 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ENCLOSURE) as $plugin) | |
484 | $retval = $plugin->hook_render_enclosure($entry, $hide_images); | |
485 | ||
486 | ||
487 | if ($retval) { | |
488 | $rv .= $retval; | |
489 | } else { | |
490 | ||
491 | if (preg_match("/image/", $entry["type"])) { | |
492 | ||
493 | if (!$hide_images) { | |
494 | $encsize = ''; | |
495 | if ($entry['height'] > 0) | |
496 | $encsize .= ' height="' . intval($entry['height']) . '"'; | |
497 | if ($entry['width'] > 0) | |
498 | $encsize .= ' width="' . intval($entry['width']) . '"'; | |
499 | $rv .= "<p><img | |
500 | alt=\"".htmlspecialchars($entry["filename"])."\" | |
501 | src=\"" .htmlspecialchars($entry["url"]) . "\" | |
502 | " . $encsize . " /></p>"; | |
503 | } else { | |
504 | $rv .= "<p><a target=\"_blank\" rel=\"noopener noreferrer\" | |
505 | href=\"".htmlspecialchars($entry["url"])."\" | |
506 | >" .htmlspecialchars($entry["url"]) . "</a></p>"; | |
507 | } | |
508 | ||
509 | if ($entry['title']) { | |
510 | $rv.= "<div class=\"enclosure_title\">${entry['title']}</div>"; | |
511 | } | |
512 | } | |
513 | } | |
514 | } | |
515 | } | |
516 | } | |
517 | ||
518 | if (count($entries_inline) > 0) { | |
519 | $rv .= "<hr clear='both'/>"; | |
520 | foreach ($entries_inline as $entry) { $rv .= $entry; }; | |
521 | $rv .= "<hr clear='both'/>"; | |
522 | } | |
523 | ||
524 | $rv .= "<div class=\"attachments\" dojoType=\"dijit.form.DropDownButton\">". | |
525 | "<span>" . __('Attachments')."</span>"; | |
526 | ||
527 | $rv .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
528 | ||
529 | foreach ($entries as $entry) { | |
530 | if ($entry["title"]) | |
531 | $title = " — " . truncate_string($entry["title"], 30); | |
532 | else | |
533 | $title = ""; | |
534 | ||
535 | if ($entry["filename"]) | |
536 | $filename = truncate_middle(htmlspecialchars($entry["filename"]), 60); | |
537 | else | |
538 | $filename = ""; | |
539 | ||
540 | $rv .= "<div onclick='openUrlPopup(\"".htmlspecialchars($entry["url"])."\")' | |
541 | dojoType=\"dijit.MenuItem\">".$filename . $title."</div>"; | |
542 | ||
543 | }; | |
544 | ||
545 | $rv .= "</div>"; | |
546 | $rv .= "</div>"; | |
547 | } | |
548 | ||
549 | return $rv; | |
550 | } | |
551 | ||
552 | static function format_article($id, $mark_as_read = true, $zoom_mode = false, $owner_uid = false) { | |
553 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; | |
554 | ||
555 | $rv = array(); | |
556 | ||
557 | $rv['id'] = $id; | |
558 | ||
559 | /* we can figure out feed_id from article id anyway, why do we | |
560 | * pass feed_id here? let's ignore the argument :(*/ | |
561 | ||
d0e73ed8 AD |
562 | $pdo = Db::pdo(); |
563 | ||
564 | $sth = $pdo->prepare("SELECT feed_id FROM ttrss_user_entries | |
565 | WHERE ref_id = ?"); | |
566 | $sth->execute([$id]); | |
567 | $row = $sth->fetch(); | |
7e5f8d9f | 568 | |
d0e73ed8 | 569 | $feed_id = (int) $row["feed_id"]; |
7e5f8d9f AD |
570 | |
571 | $rv['feed_id'] = $feed_id; | |
572 | ||
573 | //if (!$zoom_mode) { print "<article id='$id'><![CDATA["; }; | |
574 | ||
575 | if ($mark_as_read) { | |
d0e73ed8 | 576 | $sth = $pdo->prepare("UPDATE ttrss_user_entries |
7e5f8d9f | 577 | SET unread = false,last_read = NOW() |
d0e73ed8 AD |
578 | WHERE ref_id = ? AND owner_uid = ?"); |
579 | $sth->execute([$id, $owner_uid]); | |
7e5f8d9f | 580 | |
2ed0d6c4 | 581 | CCache::update($feed_id, $owner_uid); |
7e5f8d9f AD |
582 | } |
583 | ||
d0e73ed8 | 584 | $sth = $pdo->prepare("SELECT id,title,link,content,feed_id,comments,int_id,lang, |
7e5f8d9f AD |
585 | ".SUBSTRING_FOR_DATE."(updated,1,16) as updated, |
586 | (SELECT site_url FROM ttrss_feeds WHERE id = feed_id) as site_url, | |
587 | (SELECT title FROM ttrss_feeds WHERE id = feed_id) as feed_title, | |
588 | (SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) as hide_images, | |
589 | (SELECT always_display_enclosures FROM ttrss_feeds WHERE id = feed_id) as always_display_enclosures, | |
590 | num_comments, | |
591 | tag_cache, | |
592 | author, | |
593 | guid, | |
594 | orig_feed_id, | |
595 | note | |
596 | FROM ttrss_entries,ttrss_user_entries | |
d0e73ed8 AD |
597 | WHERE id = ? AND ref_id = id AND owner_uid = ?"); |
598 | $sth->execute([$id, $owner_uid]); | |
7e5f8d9f | 599 | |
d0e73ed8 | 600 | if ($line = $sth->fetch()) { |
7e5f8d9f AD |
601 | |
602 | $line["tags"] = Article::get_article_tags($id, $owner_uid, $line["tag_cache"]); | |
603 | unset($line["tag_cache"]); | |
604 | ||
605 | $line["content"] = sanitize($line["content"], | |
187abfe7 | 606 | $line['hide_images'], |
7e5f8d9f AD |
607 | $owner_uid, $line["site_url"], false, $line["id"]); |
608 | ||
609 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) { | |
610 | $line = $p->hook_render_article($line); | |
611 | } | |
612 | ||
613 | $num_comments = (int) $line["num_comments"]; | |
614 | $entry_comments = ""; | |
615 | ||
616 | if ($num_comments > 0) { | |
617 | if ($line["comments"]) { | |
618 | $comments_url = htmlspecialchars($line["comments"]); | |
619 | } else { | |
620 | $comments_url = htmlspecialchars($line["link"]); | |
621 | } | |
622 | $entry_comments = "<a class=\"postComments\" | |
623 | target='_blank' rel=\"noopener noreferrer\" href=\"$comments_url\">$num_comments ". | |
624 | _ngettext("comment", "comments", $num_comments)."</a>"; | |
625 | ||
626 | } else { | |
627 | if ($line["comments"] && $line["link"] != $line["comments"]) { | |
628 | $entry_comments = "<a class=\"postComments\" target='_blank' rel=\"noopener noreferrer\" href=\"".htmlspecialchars($line["comments"])."\">".__("comments")."</a>"; | |
629 | } | |
630 | } | |
631 | ||
632 | if ($zoom_mode) { | |
633 | header("Content-Type: text/html"); | |
634 | $rv['content'] .= "<html><head> | |
635 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/> | |
8f0a59f3 | 636 | <title>".$line["title"]."</title>". |
5e68e246 | 637 | stylesheet_tag("css/default.css")." |
7e5f8d9f AD |
638 | <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\"> |
639 | <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\"> | |
640 | ||
31e2811a | 641 | </head><body class=\"claro ttrss_utility ttrss_zoom\">"; |
7e5f8d9f AD |
642 | } |
643 | ||
644 | $rv['content'] .= "<div class=\"postReply\" id=\"POST-$id\">"; | |
645 | ||
646 | $rv['content'] .= "<div class=\"postHeader\" id=\"POSTHDR-$id\">"; | |
647 | ||
648 | $entry_author = $line["author"]; | |
649 | ||
650 | if ($entry_author) { | |
651 | $entry_author = __(" - ") . $entry_author; | |
652 | } | |
653 | ||
654 | $parsed_updated = make_local_datetime($line["updated"], true, | |
655 | $owner_uid, true); | |
656 | ||
657 | if (!$zoom_mode) | |
658 | $rv['content'] .= "<div class=\"postDate\">$parsed_updated</div>"; | |
659 | ||
660 | if ($line["link"]) { | |
661 | $rv['content'] .= "<div class='postTitle'><a target='_blank' rel='noopener noreferrer' | |
662 | title=\"".htmlspecialchars($line['title'])."\" | |
663 | href=\"" . | |
664 | htmlspecialchars($line["link"]) . "\">" . | |
665 | $line["title"] . "</a>" . | |
666 | "<span class='author'>$entry_author</span></div>"; | |
667 | } else { | |
668 | $rv['content'] .= "<div class='postTitle'>" . $line["title"] . "$entry_author</div>"; | |
669 | } | |
670 | ||
671 | if ($zoom_mode) { | |
672 | $feed_title = htmlspecialchars($line["feed_title"]); | |
673 | ||
674 | $rv['content'] .= "<div class=\"postFeedTitle\">$feed_title</div>"; | |
675 | ||
676 | $rv['content'] .= "<div class=\"postDate\">$parsed_updated</div>"; | |
677 | } | |
678 | ||
679 | $tags_str = Article::format_tags_string($line["tags"], $id); | |
680 | $tags_str_full = join(", ", $line["tags"]); | |
681 | ||
682 | if (!$tags_str_full) $tags_str_full = __("no tags"); | |
683 | ||
684 | if (!$entry_comments) $entry_comments = " "; # placeholder | |
685 | ||
686 | $rv['content'] .= "<div class='postTags' style='float : right'> | |
687 | <img src='images/tag.png' | |
688 | class='tagsPic' alt='Tags' title='Tags'> "; | |
689 | ||
690 | if (!$zoom_mode) { | |
691 | $rv['content'] .= "<span id=\"ATSTR-$id\">$tags_str</span> | |
692 | <a title=\"".__('Edit tags for this article')."\" | |
693 | href=\"#\" onclick=\"editArticleTags($id, $feed_id)\">(+)</a>"; | |
694 | ||
695 | $rv['content'] .= "<div dojoType=\"dijit.Tooltip\" | |
696 | id=\"ATSTRTIP-$id\" connectId=\"ATSTR-$id\" | |
697 | position=\"below\">$tags_str_full</div>"; | |
698 | ||
699 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_BUTTON) as $p) { | |
700 | $rv['content'] .= $p->hook_article_button($line); | |
701 | } | |
702 | ||
703 | } else { | |
704 | $tags_str = strip_tags($tags_str); | |
705 | $rv['content'] .= "<span id=\"ATSTR-$id\">$tags_str</span>"; | |
706 | } | |
707 | $rv['content'] .= "</div>"; | |
708 | $rv['content'] .= "<div clear='both'>"; | |
709 | ||
710 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_LEFT_BUTTON) as $p) { | |
711 | $rv['content'] .= $p->hook_article_left_button($line); | |
712 | } | |
713 | ||
714 | $rv['content'] .= "$entry_comments</div>"; | |
715 | ||
716 | if ($line["orig_feed_id"]) { | |
717 | ||
d0e73ed8 AD |
718 | $of_sth = $pdo->prepare("SELECT * FROM ttrss_archived_feeds |
719 | WHERE id = ? AND owner_uid = ?"); | |
720 | $of_sth->execute([$line["orig_feed_id"], $owner_uid]); | |
7e5f8d9f | 721 | |
d0e73ed8 | 722 | if ($tmp_line = $of_sth->fetch()) { |
7e5f8d9f AD |
723 | |
724 | $rv['content'] .= "<div clear='both'>"; | |
725 | $rv['content'] .= __("Originally from:"); | |
726 | ||
727 | $rv['content'] .= " "; | |
728 | ||
7e5f8d9f AD |
729 | $rv['content'] .= "<a target='_blank' rel='noopener noreferrer' |
730 | href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" . | |
731 | $tmp_line['title'] . "</a>"; | |
732 | ||
733 | $rv['content'] .= " "; | |
734 | ||
735 | $rv['content'] .= "<a target='_blank' rel='noopener noreferrer' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>"; | |
736 | $rv['content'] .= "<img title='".__('Feed URL')."' class='tinyFeedIcon' src='images/pub_set.png'></a>"; | |
737 | ||
738 | $rv['content'] .= "</div>"; | |
739 | } | |
740 | } | |
741 | ||
742 | $rv['content'] .= "</div>"; | |
743 | ||
744 | $rv['content'] .= "<div id=\"POSTNOTE-$id\">"; | |
745 | if ($line['note']) { | |
746 | $rv['content'] .= Article::format_article_note($id, $line['note'], !$zoom_mode); | |
747 | } | |
748 | $rv['content'] .= "</div>"; | |
749 | ||
750 | if (!$line['lang']) $line['lang'] = 'en'; | |
751 | ||
752 | $rv['content'] .= "<div class=\"postContent\" lang=\"".$line['lang']."\">"; | |
753 | ||
754 | $rv['content'] .= $line["content"]; | |
755 | ||
756 | if (!$zoom_mode) { | |
757 | $rv['content'] .= Article::format_article_enclosures($id, | |
187abfe7 | 758 | $line["always_display_enclosures"], |
7e5f8d9f | 759 | $line["content"], |
187abfe7 | 760 | $line["hide_images"]); |
7e5f8d9f AD |
761 | } |
762 | ||
763 | $rv['content'] .= "</div>"; | |
764 | ||
765 | $rv['content'] .= "</div>"; | |
766 | ||
767 | } | |
768 | ||
769 | if ($zoom_mode) { | |
770 | $rv['content'] .= " | |
771 | <div class='footer'> | |
772 | <button onclick=\"return window.close()\">". | |
773 | __("Close this window")."</button></div>"; | |
774 | $rv['content'] .= "</body></html>"; | |
775 | } | |
776 | ||
e50a6479 AD |
777 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ARTICLE) as $p) { |
778 | $rv['content'] = $p->hook_format_article($rv['content'], $line, $zoom_mode); | |
779 | } | |
780 | ||
7e5f8d9f AD |
781 | return $rv; |
782 | ||
783 | } | |
784 | ||
785 | static function get_article_tags($id, $owner_uid = 0, $tag_cache = false) { | |
786 | ||
2c57df75 | 787 | $a_id = $id; |
7e5f8d9f AD |
788 | |
789 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; | |
790 | ||
d0e73ed8 AD |
791 | $pdo = Db::pdo(); |
792 | ||
793 | $sth = $pdo->prepare("SELECT DISTINCT tag_name, | |
794 | owner_uid as owner FROM ttrss_tags | |
795 | WHERE post_int_id = (SELECT int_id FROM ttrss_user_entries WHERE | |
796 | ref_id = ? AND owner_uid = ? LIMIT 1) ORDER BY tag_name"); | |
7e5f8d9f AD |
797 | |
798 | $tags = array(); | |
799 | ||
800 | /* check cache first */ | |
801 | ||
802 | if ($tag_cache === false) { | |
d0e73ed8 AD |
803 | $csth = $pdo->prepare("SELECT tag_cache FROM ttrss_user_entries |
804 | WHERE ref_id = ? AND owner_uid = ?"); | |
805 | $csth->execute([$id, $owner_uid]); | |
7e5f8d9f | 806 | |
d0e73ed8 | 807 | if ($row = $csth->fetch()) $tag_cache = $row["tag_cache"]; |
7e5f8d9f AD |
808 | } |
809 | ||
810 | if ($tag_cache) { | |
811 | $tags = explode(",", $tag_cache); | |
812 | } else { | |
813 | ||
814 | /* do it the hard way */ | |
815 | ||
d0e73ed8 | 816 | $sth->execute([$a_id, $owner_uid]); |
7e5f8d9f | 817 | |
d0e73ed8 | 818 | while ($tmp_line = $sth->fetch()) { |
7e5f8d9f AD |
819 | array_push($tags, $tmp_line["tag_name"]); |
820 | } | |
821 | ||
822 | /* update the cache */ | |
823 | ||
2c57df75 | 824 | $tags_str = join(",", $tags); |
7e5f8d9f | 825 | |
d0e73ed8 AD |
826 | $sth = $pdo->prepare("UPDATE ttrss_user_entries |
827 | SET tag_cache = ? WHERE ref_id = ? | |
828 | AND owner_uid = ?"); | |
829 | $sth->execute([$tags_str, $id, $owner_uid]); | |
7e5f8d9f AD |
830 | } |
831 | ||
832 | return $tags; | |
833 | } | |
834 | ||
835 | static function format_tags_string($tags) { | |
836 | if (!is_array($tags) || count($tags) == 0) { | |
837 | return __("no tags"); | |
838 | } else { | |
839 | $maxtags = min(5, count($tags)); | |
840 | $tags_str = ""; | |
841 | ||
842 | for ($i = 0; $i < $maxtags; $i++) { | |
843 | $tags_str .= "<a class=\"tag\" href=\"#\" onclick=\"viewfeed({feed:'".$tags[$i]."'})\">" . $tags[$i] . "</a>, "; | |
844 | } | |
845 | ||
846 | $tags_str = mb_substr($tags_str, 0, mb_strlen($tags_str)-2); | |
847 | ||
848 | if (count($tags) > $maxtags) | |
849 | $tags_str .= ", …"; | |
850 | ||
851 | return $tags_str; | |
852 | } | |
853 | } | |
854 | ||
855 | static function format_article_labels($labels) { | |
856 | ||
857 | if (!is_array($labels)) return ''; | |
858 | ||
859 | $labels_str = ""; | |
860 | ||
861 | foreach ($labels as $l) { | |
862 | $labels_str .= sprintf("<span class='hlLabelRef' | |
863 | style='color : %s; background-color : %s'>%s</span>", | |
864 | $l[2], $l[3], $l[1]); | |
865 | } | |
866 | ||
867 | return $labels_str; | |
868 | ||
869 | } | |
870 | ||
871 | static function format_article_note($id, $note, $allow_edit = true) { | |
872 | ||
873 | $str = "<div class='articleNote' onclick=\"editArticleNote($id)\"> | |
874 | <div class='noteEdit' onclick=\"editArticleNote($id)\">". | |
875 | ($allow_edit ? __('(edit note)') : "")."</div>$note</div>"; | |
876 | ||
877 | return $str; | |
878 | } | |
879 | ||
880 | static function get_article_enclosures($id) { | |
881 | ||
d0e73ed8 | 882 | $pdo = Db::pdo(); |
7e5f8d9f | 883 | |
d0e73ed8 AD |
884 | $sth = $pdo->prepare("SELECT * FROM ttrss_enclosures |
885 | WHERE post_id = ? AND content_url != ''"); | |
886 | $sth->execute([$id]); | |
7e5f8d9f | 887 | |
d0e73ed8 | 888 | $rv = array(); |
7e5f8d9f | 889 | |
d0e73ed8 | 890 | while ($line = $sth->fetch()) { |
7e5f8d9f | 891 | |
d0e73ed8 AD |
892 | if (file_exists(CACHE_DIR . '/images/' . sha1($line["content_url"]))) { |
893 | $line["content_url"] = get_self_url_prefix() . '/public.php?op=cached_url&hash=' . sha1($line["content_url"]); | |
7e5f8d9f | 894 | } |
d0e73ed8 AD |
895 | |
896 | array_push($rv, $line); | |
7e5f8d9f AD |
897 | } |
898 | ||
899 | return $rv; | |
900 | } | |
c83554bd | 901 | |
a230bf88 AD |
902 | static function purge_orphans($do_output = false) { |
903 | ||
904 | // purge orphaned posts in main content table | |
d0e73ed8 | 905 | |
8e1450aa AD |
906 | if (DB_TYPE == "mysql") |
907 | $limit_qpart = "LIMIT 5000"; | |
908 | else | |
909 | $limit_qpart = ""; | |
910 | ||
d0e73ed8 AD |
911 | $pdo = Db::pdo(); |
912 | $res = $pdo->query("DELETE FROM ttrss_entries WHERE | |
8e1450aa | 913 | NOT EXISTS (SELECT ref_id FROM ttrss_user_entries WHERE ref_id = id) $limit_qpart"); |
a230bf88 AD |
914 | |
915 | if ($do_output) { | |
d0e73ed8 | 916 | $rows = $res->rowCount(); |
a230bf88 AD |
917 | _debug("Purged $rows orphaned posts."); |
918 | } | |
919 | } | |
920 | ||
aeb1abed AD |
921 | static function catchupArticlesById($ids, $cmode, $owner_uid = false) { |
922 | ||
923 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; | |
aeb1abed | 924 | |
d0e73ed8 | 925 | $pdo = Db::pdo(); |
aeb1abed | 926 | |
d0e73ed8 | 927 | $ids_qmarks = arr_qmarks($ids); |
aeb1abed AD |
928 | |
929 | if ($cmode == 0) { | |
d0e73ed8 | 930 | $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
aeb1abed | 931 | unread = false,last_read = NOW() |
d0e73ed8 | 932 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
aeb1abed | 933 | } else if ($cmode == 1) { |
d0e73ed8 | 934 | $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
aeb1abed | 935 | unread = true |
d0e73ed8 | 936 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); |
aeb1abed | 937 | } else { |
d0e73ed8 AD |
938 | $sth = $pdo->prepare("UPDATE ttrss_user_entries SET |
939 | unread = NOT unread,last_read = NOW() | |
940 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); | |
aeb1abed AD |
941 | } |
942 | ||
d0e73ed8 AD |
943 | $sth->execute(array_merge($ids, [$owner_uid])); |
944 | ||
aeb1abed AD |
945 | /* update ccache */ |
946 | ||
d0e73ed8 AD |
947 | $sth = $pdo->prepare("SELECT DISTINCT feed_id FROM ttrss_user_entries |
948 | WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?"); | |
949 | $sth->execute(array_merge($ids, [$owner_uid])); | |
aeb1abed | 950 | |
d0e73ed8 | 951 | while ($line = $sth->fetch()) { |
2ed0d6c4 | 952 | CCache::update($line["feed_id"], $owner_uid); |
aeb1abed AD |
953 | } |
954 | } | |
955 | ||
956 | static function getLastArticleId() { | |
d0e73ed8 AD |
957 | $pdo = DB::pdo(); |
958 | ||
959 | $sth = $pdo->prepare("SELECT ref_id AS id FROM ttrss_user_entries | |
960 | WHERE owner_uid = ? ORDER BY ref_id DESC LIMIT 1"); | |
961 | $sth->execute([$_SESSION['uid']]); | |
aeb1abed | 962 | |
d0e73ed8 AD |
963 | if ($row = $sth->fetch()) { |
964 | return $row['id']; | |
aeb1abed AD |
965 | } else { |
966 | return -1; | |
967 | } | |
968 | } | |
a230bf88 | 969 | |
4a0da0e5 AD |
970 | static function get_article_labels($id, $owner_uid = false) { |
971 | $rv = array(); | |
972 | ||
973 | if (!$owner_uid) $owner_uid = $_SESSION["uid"]; | |
974 | ||
d0e73ed8 AD |
975 | $pdo = Db::pdo(); |
976 | ||
977 | $sth = $pdo->prepare("SELECT label_cache FROM | |
978 | ttrss_user_entries WHERE ref_id = ? AND owner_uid = ?"); | |
979 | $sth->execute([$id, $owner_uid]); | |
4a0da0e5 | 980 | |
d0e73ed8 AD |
981 | if ($row = $sth->fetch()) { |
982 | $label_cache = $row["label_cache"]; | |
4a0da0e5 AD |
983 | |
984 | if ($label_cache) { | |
e4befe6b | 985 | $tmp = json_decode($label_cache, true); |
4a0da0e5 | 986 | |
e4befe6b | 987 | if (!$tmp || $tmp["no-labels"] == 1) |
4a0da0e5 AD |
988 | return $rv; |
989 | else | |
e4befe6b | 990 | return $tmp; |
4a0da0e5 AD |
991 | } |
992 | } | |
993 | ||
d0e73ed8 | 994 | $sth = $pdo->prepare("SELECT DISTINCT label_id,caption,fg_color,bg_color |
4a0da0e5 AD |
995 | FROM ttrss_labels2, ttrss_user_labels2 |
996 | WHERE id = label_id | |
d0e73ed8 AD |
997 | AND article_id = ? |
998 | AND owner_uid = ? | |
4a0da0e5 | 999 | ORDER BY caption"); |
d0e73ed8 | 1000 | $sth->execute([$id, $owner_uid]); |
4a0da0e5 | 1001 | |
d0e73ed8 | 1002 | while ($line = $sth->fetch()) { |
7c9b5a3f | 1003 | $rk = array(Labels::label_to_feed_id($line["label_id"]), |
4a0da0e5 AD |
1004 | $line["caption"], $line["fg_color"], |
1005 | $line["bg_color"]); | |
1006 | array_push($rv, $rk); | |
1007 | } | |
1008 | ||
1009 | if (count($rv) > 0) | |
7c9b5a3f | 1010 | Labels::update_cache($owner_uid, $id, $rv); |
4a0da0e5 | 1011 | else |
7c9b5a3f | 1012 | Labels::update_cache($owner_uid, $id, array("no-labels" => 1)); |
4a0da0e5 AD |
1013 | |
1014 | return $rv; | |
1015 | } | |
1016 | ||
6afcbcd1 | 1017 | } |