]>
git.wh0rd.org - tt-rss.git/blob - classes/article.php
8fb863ef240381852bd7055327dab8f03a11fc8d
2 class Article
extends Handler_Protected
{
4 function csrf_ignore($method) {
5 $csrf_ignored = array("redirect", "editarticletags");
7 return array_search($method, $csrf_ignored) !== false;
11 $sth = $this->pdo
->prepare("SELECT link FROM ttrss_entries, ttrss_user_entries
12 WHERE id = ? AND id = ref_id AND owner_uid = ?
14 $sth->execute([$id, $_SESSION['uid']]);
16 if ($row = $sth->fetch()) {
17 $article_url = $row['link'];
18 $article_url = str_replace("\n", "", $article_url);
20 header("Location: $article_url");
24 print_error(__("Article not found."));
29 $id = db_escape_string($_REQUEST["id"]);
30 $cids = explode(",", db_escape_string($_REQUEST["cids"]));
31 $mode = db_escape_string($_REQUEST["mode"]);
33 // in prefetch mode we only output requested cids, main article
34 // just gets marked as read (it already exists in client cache)
39 array_push($articles, $this->format_article($id, false));
40 } else if ($mode == "zoom") {
41 array_push($articles, $this->format_article($id, true, true));
42 } else if ($mode == "raw") {
43 if (isset($_REQUEST['html'])) {
44 header("Content-Type: text/html");
45 print '<link rel="stylesheet" type="text/css" href="css/default.css"/>';
48 $article = $this->format_article($id, false, isset($_REQUEST["zoom"]));
49 print $article['content'];
53 $this->catchupArticleById($id, 0);
55 if (!$_SESSION["bw_limit"]) {
56 foreach ($cids as $cid) {
58 array_push($articles, $this->format_article($cid, false, false));
63 print json_encode($articles);
66 private function catchupArticleById($id, $cmode) {
69 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET
70 unread = false,last_read = NOW()
71 WHERE ref_id = ? AND owner_uid = ?");
72 } else if ($cmode == 1) {
73 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET
75 WHERE ref_id = ? AND owner_uid = ?");
77 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET
78 unread = NOT unread,last_read = NOW()
79 WHERE ref_id = ? AND owner_uid = ?");
82 $sth->execute([$id, $_SESSION['uid']]);
84 $feed_id = $this->getArticleFeed($id);
85 CCache
::update($feed_id, $_SESSION["uid"]);
88 static function create_published_article($title, $url, $content, $labels_str,
91 $guid = 'SHA1:' . sha1("ttshared:" . $url . $owner_uid); // include owner_uid to prevent global GUID clash
94 $pluginhost = new PluginHost();
95 $pluginhost->load_all(PluginHost
::KIND_ALL
, $owner_uid);
96 $pluginhost->load_data();
98 $af_readability = $pluginhost->get_plugin("Af_Readability");
100 if ($af_readability) {
101 $enable_share_anything = $pluginhost->get($af_readability, "enable_share_anything");
103 if ($enable_share_anything) {
104 $extracted_content = $af_readability->extract_content($url);
106 if ($extracted_content) $content = db_escape_string($extracted_content);
111 $content_hash = sha1($content);
113 if ($labels_str != "") {
114 $labels = explode(",", $labels_str);
121 if (!$title) $title = $url;
122 if (!$title && !$url) return false;
124 if (filter_var($url, FILTER_VALIDATE_URL
) === FALSE) return false;
126 $this->pdo
->beginTransaction();
128 // only check for our user data here, others might have shared this with different content etc
129 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_entries, ttrss_user_entries WHERE
130 guid = ? AND ref_id = id AND owner_uid = ? LIMIT 1");
131 $sth->execute([$guid, $owner_uid]);
133 if ($row = $sth->fetch()) {
134 $ref_id = $row['id'];
136 $sth = $this->pdo
->prepare("SELECT int_id FROM ttrss_user_entries WHERE
137 ref_id = ? AND owner_uid = ? LIMIT 1");
138 $sth->execute([$ref_id, $owner_uid]);
140 if ($row = $sth->fetch()) {
141 $int_id = $row['int_id'];
143 $sth = $this->pdo
->prepare("UPDATE ttrss_entries SET
144 content = ?, content_hash = ? WHERE id = ?");
145 $sth->execute([$content, $content_hash, $ref_id]);
147 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET published = true,
148 last_published = NOW() WHERE
149 int_id = ? AND owner_uid = ?");
150 $sth->execute([$int_id, $owner_uid]);
154 $sth = $this->pdo
->prepare("INSERT INTO ttrss_user_entries
155 (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache,
156 last_read, note, unread, last_published)
158 (?, '', NULL, NULL, ?, true, '', '', NOW(), '', false, NOW())");
159 $sth->execute([$ref_id, $owner_uid]);
162 if (count($labels) != 0) {
163 foreach ($labels as $label) {
164 Labels
::add_article($ref_id, trim($label), $owner_uid);
171 $sth = $this->pdo
->prepare("INSERT INTO ttrss_entries
172 (title, guid, link, updated, content, content_hash, date_entered, date_updated)
174 (?, ?, ?, NOW(), ?, ?, NOW(), NOW())");
175 $sth->execute([$title, $guid, $url, $content, $content_hash]);
177 $sth = $this->pdo
->prepare("SELECT id FROM ttrss_entries WHERE guid = ?");
178 $sth->execute([$guid]);
180 if ($row = $sth->fetch()) {
181 $ref_id = $row["id"];
183 $sth = $this->pdo
->prepare("INSERT INTO ttrss_user_entries
184 (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache,
185 last_read, note, unread, last_published)
187 (?, '', NULL, NULL, ?, true, '', '', NOW(), '', false, NOW())");
188 $sth->execute([$ref_id, $owner_uid]);
190 if (count($labels) != 0) {
191 foreach ($labels as $label) {
192 Labels
::add_article($ref_id, trim($label), $owner_uid);
200 $this->pdo
->commit();
205 function editArticleTags() {
207 print __("Tags for this article (separated by commas):")."<br>";
209 $param = db_escape_string($_REQUEST['param']);
211 $tags = Article
::get_article_tags(db_escape_string($param));
213 $tags_str = join(", ", $tags);
215 print_hidden("id", "$param");
216 print_hidden("op", "article");
217 print_hidden("method", "setArticleTags");
219 print "<table width='100%'><tr><td>";
221 print "<textarea dojoType=\"dijit.form.SimpleTextarea\" rows='4'
222 style='height : 100px; font-size : 12px; width : 98%' id=\"tags_str\"
223 name='tags_str'>$tags_str</textarea>
224 <div class=\"autocomplete\" id=\"tags_choices\"
225 style=\"display:none\"></div>";
227 print "</td></tr></table>";
229 print "<div class='dlgButtons'>";
231 print "<button dojoType=\"dijit.form.Button\"
232 onclick=\"dijit.byId('editTagsDlg').execute()\">".__('Save')."</button> ";
233 print "<button dojoType=\"dijit.form.Button\"
234 onclick=\"dijit.byId('editTagsDlg').hide()\">".__('Cancel')."</button>";
239 function setScore() {
240 $ids = explode(",", $_REQUEST['id']);
241 $score = (int)$_REQUEST['score'];
243 $ids_qmarks = arr_qmarks($ids);
245 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET
246 score = ? WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
248 $sth->execute(array_merge([$score], $ids, [$_SESSION['uid']]));
250 print json_encode(array("id" => $ids,
251 "score" => (int)$score,
252 "score_pic" => get_score_pic($score)));
255 function getScore() {
256 $id = $_REQUEST['id'];
258 $sth = $this->pdo
->prepare("SELECT score FROM ttrss_user_entries WHERE ref_id = ? AND owner_uid = ?");
259 $sth->execute([$id, $_SESSION['uid']]);
260 $row = $sth->fetch();
262 $score = $row['score'];
264 print json_encode(array("id" => $id,
265 "score" => (int)$score,
266 "score_pic" => get_score_pic($score)));
270 function setArticleTags() {
272 $id = db_escape_string($_REQUEST["id"]);
274 $tags_str = db_escape_string($_REQUEST["tags_str"]);
275 $tags = array_unique(trim_array(explode(",", $tags_str)));
279 $result = db_query("SELECT int_id FROM ttrss_user_entries WHERE
280 ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1");
282 if (db_num_rows($result) == 1) {
284 $tags_to_cache = array();
286 $int_id = db_fetch_result($result, 0, "int_id");
288 db_query("DELETE FROM ttrss_tags WHERE
289 post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'");
291 foreach ($tags as $tag) {
292 $tag = sanitize_tag($tag);
294 if (!tag_is_valid($tag)) {
298 if (preg_match("/^[0-9]*$/", $tag)) {
302 // print "<!-- $id : $int_id : $tag -->";
305 db_query("INSERT INTO ttrss_tags
306 (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')");
309 array_push($tags_to_cache, $tag);
312 /* update tag cache */
314 sort($tags_to_cache);
315 $tags_str = join(",", $tags_to_cache);
317 db_query("UPDATE ttrss_user_entries
318 SET tag_cache = '$tags_str' WHERE ref_id = '$id'
319 AND owner_uid = " . $_SESSION["uid"]);
324 $tags = Article
::get_article_tags($id);
325 $tags_str = $this->format_tags_string($tags, $id);
326 $tags_str_full = join(", ", $tags);
328 if (!$tags_str_full) $tags_str_full = __("no tags");
330 print json_encode(array("id" => (int)$id,
331 "content" => $tags_str, "content_full" => $tags_str_full));
335 function completeTags() {
336 $search = db_escape_string($_REQUEST["search"]);
338 $result = db_query("SELECT DISTINCT tag_name FROM ttrss_tags
339 WHERE owner_uid = '".$_SESSION["uid"]."' AND
340 tag_name LIKE '$search%' ORDER BY tag_name
344 while ($line = db_fetch_assoc($result)) {
345 print "<li>" . $line["tag_name"] . "</li>";
350 function assigntolabel() {
351 return $this->labelops(true);
354 function removefromlabel() {
355 return $this->labelops(false);
358 private function labelops($assign) {
361 $ids = explode(",", db_escape_string($_REQUEST["ids"]));
362 $label_id = db_escape_string($_REQUEST["lid"]);
364 $label = db_escape_string(Labels
::find_caption($label_id,
367 $reply["info-for-headlines"] = array();
371 foreach ($ids as $id) {
374 Labels
::add_article($id, $label, $_SESSION["uid"]);
376 Labels
::remove_article($id, $label, $_SESSION["uid"]);
378 $labels = $this->get_article_labels($id, $_SESSION["uid"]);
380 array_push($reply["info-for-headlines"],
381 array("id" => $id, "labels" => $this->format_article_labels($labels)));
386 $reply["message"] = "UPDATE_COUNTERS";
388 print json_encode($reply);
391 function getArticleFeed($id) {
392 $result = db_query("SELECT feed_id FROM ttrss_user_entries
393 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
395 if (db_num_rows($result) != 0) {
396 return db_fetch_result($result, 0, "feed_id");
402 static function format_article_enclosures($id, $always_display_enclosures,
403 $article_content, $hide_images = false) {
405 $result = Article
::get_article_enclosures($id);
408 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_FORMAT_ENCLOSURES
) as $plugin) {
409 $retval = $plugin->hook_format_enclosures($rv, $result, $id, $always_display_enclosures, $article_content, $hide_images);
410 if (is_array($retval)) {
412 $result = $retval[1];
417 unset($retval); // Unset to prevent breaking render if there are no HOOK_RENDER_ENCLOSURE hooks below.
419 if ($rv === '' && !empty($result)) {
420 $entries_html = array();
422 $entries_inline = array();
424 foreach ($result as $line) {
426 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ENCLOSURE_ENTRY
) as $plugin) {
427 $line = $plugin->hook_enclosure_entry($line);
430 $url = $line["content_url"];
431 $ctype = $line["content_type"];
432 $title = $line["title"];
433 $width = $line["width"];
434 $height = $line["height"];
436 if (!$ctype) $ctype = __("unknown type");
438 //$filename = substr($url, strrpos($url, "/")+1);
439 $filename = basename($url);
441 $player = format_inline_player($url, $ctype);
443 if ($player) array_push($entries_inline, $player);
445 # $entry .= " <a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\" rel=\"noopener noreferrer\">" .
446 # $filename . " (" . $ctype . ")" . "</a>";
448 $entry = "<div onclick=\"openUrlPopup('".htmlspecialchars($url)."')\"
449 dojoType=\"dijit.MenuItem\">$filename ($ctype)</div>";
451 array_push($entries_html, $entry);
455 $entry["type"] = $ctype;
456 $entry["filename"] = $filename;
457 $entry["url"] = $url;
458 $entry["title"] = $title;
459 $entry["width"] = $width;
460 $entry["height"] = $height;
462 array_push($entries, $entry);
465 if ($_SESSION['uid'] && !get_pref("STRIP_IMAGES") && !$_SESSION["bw_limit"]) {
466 if ($always_display_enclosures ||
467 !preg_match("/<img/i", $article_content)) {
469 foreach ($entries as $entry) {
471 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_RENDER_ENCLOSURE
) as $plugin)
472 $retval = $plugin->hook_render_enclosure($entry, $hide_images);
479 if (preg_match("/image/", $entry["type"])) {
483 if ($entry['height'] > 0)
484 $encsize .= ' height="' . intval($entry['height']) . '"';
485 if ($entry['width'] > 0)
486 $encsize .= ' width="' . intval($entry['width']) . '"';
488 alt=\"".htmlspecialchars($entry["filename"])."\"
489 src=\"" .htmlspecialchars($entry["url"]) . "\"
490 " . $encsize . " /></p>";
492 $rv .= "<p><a target=\"_blank\" rel=\"noopener noreferrer\"
493 href=\"".htmlspecialchars($entry["url"])."\"
494 >" .htmlspecialchars($entry["url"]) . "</a></p>";
497 if ($entry['title']) {
498 $rv.= "<div class=\"enclosure_title\">${entry['title']}</div>";
506 if (count($entries_inline) > 0) {
507 $rv .= "<hr clear='both'/>";
508 foreach ($entries_inline as $entry) { $rv .= $entry; };
509 $rv .= "<hr clear='both'/>";
512 $rv .= "<div class=\"attachments\" dojoType=\"dijit.form.DropDownButton\">".
513 "<span>" . __('Attachments')."</span>";
515 $rv .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
517 foreach ($entries as $entry) {
519 $title = " — " . truncate_string($entry["title"], 30);
523 if ($entry["filename"])
524 $filename = truncate_middle(htmlspecialchars($entry["filename"]), 60);
528 $rv .= "<div onclick='openUrlPopup(\"".htmlspecialchars($entry["url"])."\")'
529 dojoType=\"dijit.MenuItem\">".$filename . $title."</div>";
540 static function format_article($id, $mark_as_read = true, $zoom_mode = false, $owner_uid = false) {
541 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
547 /* we can figure out feed_id from article id anyway, why do we
548 * pass feed_id here? let's ignore the argument :(*/
550 $result = db_query("SELECT feed_id FROM ttrss_user_entries
551 WHERE ref_id = '$id'");
553 $feed_id = (int) db_fetch_result($result, 0, "feed_id");
555 $rv['feed_id'] = $feed_id;
557 //if (!$zoom_mode) { print "<article id='$id'><![CDATA["; };
560 $result = db_query("UPDATE ttrss_user_entries
561 SET unread = false,last_read = NOW()
562 WHERE ref_id = '$id' AND owner_uid = $owner_uid");
564 CCache
::update($feed_id, $owner_uid);
567 $result = db_query("SELECT id,title,link,content,feed_id,comments,int_id,lang,
568 ".SUBSTRING_FOR_DATE
."(updated,1,16) as updated,
569 (SELECT site_url FROM ttrss_feeds WHERE id = feed_id) as site_url,
570 (SELECT title FROM ttrss_feeds WHERE id = feed_id) as feed_title,
571 (SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) as hide_images,
572 (SELECT always_display_enclosures FROM ttrss_feeds WHERE id = feed_id) as always_display_enclosures,
579 FROM ttrss_entries,ttrss_user_entries
580 WHERE id = '$id' AND ref_id = id AND owner_uid = $owner_uid");
584 $line = db_fetch_assoc($result);
586 $line["tags"] = Article
::get_article_tags($id, $owner_uid, $line["tag_cache"]);
587 unset($line["tag_cache"]);
589 $line["content"] = sanitize($line["content"],
590 sql_bool_to_bool($line['hide_images']),
591 $owner_uid, $line["site_url"], false, $line["id"]);
593 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_RENDER_ARTICLE
) as $p) {
594 $line = $p->hook_render_article($line);
597 $num_comments = (int) $line["num_comments"];
598 $entry_comments = "";
600 if ($num_comments > 0) {
601 if ($line["comments"]) {
602 $comments_url = htmlspecialchars($line["comments"]);
604 $comments_url = htmlspecialchars($line["link"]);
606 $entry_comments = "<a class=\"postComments\"
607 target='_blank' rel=\"noopener noreferrer\" href=\"$comments_url\">$num_comments ".
608 _ngettext("comment", "comments", $num_comments)."</a>";
611 if ($line["comments"] && $line["link"] != $line["comments"]) {
612 $entry_comments = "<a class=\"postComments\" target='_blank' rel=\"noopener noreferrer\" href=\"".htmlspecialchars($line["comments"])."\">".__("comments")."</a>";
617 header("Content-Type: text/html");
618 $rv['content'] .= "<html><head>
619 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
620 <title>".$line["title"]."</title>".
621 stylesheet_tag("css/default.css")."
623 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
624 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">
626 </head><body id=\"ttrssZoom\">";
629 $rv['content'] .= "<div class=\"postReply\" id=\"POST-$id\">";
631 $rv['content'] .= "<div class=\"postHeader\" id=\"POSTHDR-$id\">";
633 $entry_author = $line["author"];
636 $entry_author = __(" - ") . $entry_author;
639 $parsed_updated = make_local_datetime($line["updated"], true,
643 $rv['content'] .= "<div class=\"postDate\">$parsed_updated</div>";
646 $rv['content'] .= "<div class='postTitle'><a target='_blank' rel='noopener noreferrer'
647 title=\"".htmlspecialchars($line['title'])."\"
649 htmlspecialchars($line["link"]) . "\">" .
650 $line["title"] . "</a>" .
651 "<span class='author'>$entry_author</span></div>";
653 $rv['content'] .= "<div class='postTitle'>" . $line["title"] . "$entry_author</div>";
657 $feed_title = htmlspecialchars($line["feed_title"]);
659 $rv['content'] .= "<div class=\"postFeedTitle\">$feed_title</div>";
661 $rv['content'] .= "<div class=\"postDate\">$parsed_updated</div>";
664 $tags_str = Article
::format_tags_string($line["tags"], $id);
665 $tags_str_full = join(", ", $line["tags"]);
667 if (!$tags_str_full) $tags_str_full = __("no tags");
669 if (!$entry_comments) $entry_comments = " "; # placeholder
671 $rv['content'] .= "<div class='postTags' style='float : right'>
672 <img src='images/tag.png'
673 class='tagsPic' alt='Tags' title='Tags'> ";
676 $rv['content'] .= "<span id=\"ATSTR-$id\">$tags_str</span>
677 <a title=\"".__('Edit tags for this article')."\"
678 href=\"#\" onclick=\"editArticleTags($id, $feed_id)\">(+)</a>";
680 $rv['content'] .= "<div dojoType=\"dijit.Tooltip\"
681 id=\"ATSTRTIP-$id\" connectId=\"ATSTR-$id\"
682 position=\"below\">$tags_str_full</div>";
684 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ARTICLE_BUTTON
) as $p) {
685 $rv['content'] .= $p->hook_article_button($line);
689 $tags_str = strip_tags($tags_str);
690 $rv['content'] .= "<span id=\"ATSTR-$id\">$tags_str</span>";
692 $rv['content'] .= "</div>";
693 $rv['content'] .= "<div clear='both'>";
695 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ARTICLE_LEFT_BUTTON
) as $p) {
696 $rv['content'] .= $p->hook_article_left_button($line);
699 $rv['content'] .= "$entry_comments</div>";
701 if ($line["orig_feed_id"]) {
703 $tmp_result = db_query("SELECT * FROM ttrss_archived_feeds
704 WHERE id = ".$line["orig_feed_id"] . " AND owner_uid = " . $_SESSION["uid"]);
706 if (db_num_rows($tmp_result) != 0) {
708 $rv['content'] .= "<div clear='both'>";
709 $rv['content'] .= __("Originally from:");
711 $rv['content'] .= " ";
713 $tmp_line = db_fetch_assoc($tmp_result);
715 $rv['content'] .= "<a target='_blank' rel='noopener noreferrer'
716 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
717 $tmp_line['title'] . "</a>";
719 $rv['content'] .= " ";
721 $rv['content'] .= "<a target='_blank' rel='noopener noreferrer' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
722 $rv['content'] .= "<img title='".__('Feed URL')."' class='tinyFeedIcon' src='images/pub_set.png'></a>";
724 $rv['content'] .= "</div>";
728 $rv['content'] .= "</div>";
730 $rv['content'] .= "<div id=\"POSTNOTE-$id\">";
732 $rv['content'] .= Article
::format_article_note($id, $line['note'], !$zoom_mode);
734 $rv['content'] .= "</div>";
736 if (!$line['lang']) $line['lang'] = 'en';
738 $rv['content'] .= "<div class=\"postContent\" lang=\"".$line['lang']."\">";
740 $rv['content'] .= $line["content"];
743 $rv['content'] .= Article
::format_article_enclosures($id,
744 sql_bool_to_bool($line["always_display_enclosures"]),
746 sql_bool_to_bool($line["hide_images"]));
749 $rv['content'] .= "</div>";
751 $rv['content'] .= "</div>";
758 <button onclick=\"return window.close()\">".
759 __("Close this window")."</button></div>";
760 $rv['content'] .= "</body></html>";
763 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_FORMAT_ARTICLE
) as $p) {
764 $rv['content'] = $p->hook_format_article($rv['content'], $line, $zoom_mode);
771 static function get_article_tags($id, $owner_uid = 0, $tag_cache = false) {
773 $a_id = db_escape_string($id);
775 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
777 $query = "SELECT DISTINCT tag_name,
778 owner_uid as owner FROM
779 ttrss_tags WHERE post_int_id = (SELECT int_id FROM ttrss_user_entries WHERE
780 ref_id = '$a_id' AND owner_uid = '$owner_uid' LIMIT 1) ORDER BY tag_name";
784 /* check cache first */
786 if ($tag_cache === false) {
787 $result = db_query("SELECT tag_cache FROM ttrss_user_entries
788 WHERE ref_id = '$id' AND owner_uid = $owner_uid");
790 if (db_num_rows($result) != 0)
791 $tag_cache = db_fetch_result($result, 0, "tag_cache");
795 $tags = explode(",", $tag_cache);
798 /* do it the hard way */
800 $tmp_result = db_query($query);
802 while ($tmp_line = db_fetch_assoc($tmp_result)) {
803 array_push($tags, $tmp_line["tag_name"]);
806 /* update the cache */
808 $tags_str = db_escape_string(join(",", $tags));
810 db_query("UPDATE ttrss_user_entries
811 SET tag_cache = '$tags_str' WHERE ref_id = '$id'
812 AND owner_uid = $owner_uid");
818 static function format_tags_string($tags) {
819 if (!is_array($tags) ||
count($tags) == 0) {
820 return __("no tags");
822 $maxtags = min(5, count($tags));
825 for ($i = 0; $i < $maxtags; $i++
) {
826 $tags_str .= "<a class=\"tag\" href=\"#\" onclick=\"viewfeed({feed:'".$tags[$i]."'})\">" . $tags[$i] . "</a>, ";
829 $tags_str = mb_substr($tags_str, 0, mb_strlen($tags_str)-2);
831 if (count($tags) > $maxtags)
832 $tags_str .= ", …";
838 static function format_article_labels($labels) {
840 if (!is_array($labels)) return '';
844 foreach ($labels as $l) {
845 $labels_str .= sprintf("<span class='hlLabelRef'
846 style='color : %s; background-color : %s'>%s</span>",
847 $l[2], $l[3], $l[1]);
854 static function format_article_note($id, $note, $allow_edit = true) {
856 $str = "<div class='articleNote' onclick=\"editArticleNote($id)\">
857 <div class='noteEdit' onclick=\"editArticleNote($id)\">".
858 ($allow_edit ?
__('(edit note)') : "")."</div>$note</div>";
863 static function get_article_enclosures($id) {
865 $query = "SELECT * FROM ttrss_enclosures
866 WHERE post_id = '$id' AND content_url != ''";
870 $result = db_query($query);
872 if (db_num_rows($result) > 0) {
873 while ($line = db_fetch_assoc($result)) {
875 if (file_exists(CACHE_DIR
. '/images/' . sha1($line["content_url"]))) {
876 $line["content_url"] = get_self_url_prefix() . '/public.php?op=cached_url&hash=' . sha1($line["content_url"]);
879 array_push($rv, $line);
886 static function purge_orphans($do_output = false) {
888 // purge orphaned posts in main content table
889 $result = db_query("DELETE FROM ttrss_entries WHERE
890 NOT EXISTS (SELECT ref_id FROM ttrss_user_entries WHERE ref_id = id)");
893 $rows = db_affected_rows($result);
894 _debug("Purged $rows orphaned posts.");
898 static function catchupArticlesById($ids, $cmode, $owner_uid = false) {
900 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
901 if (count($ids) == 0) return;
905 foreach ($ids as $id) {
906 array_push($tmp_ids, "ref_id = '$id'");
909 $ids_qpart = join(" OR ", $tmp_ids);
912 db_query("UPDATE ttrss_user_entries SET
913 unread = false,last_read = NOW()
914 WHERE ($ids_qpart) AND owner_uid = $owner_uid");
915 } else if ($cmode == 1) {
916 db_query("UPDATE ttrss_user_entries SET
918 WHERE ($ids_qpart) AND owner_uid = $owner_uid");
920 db_query("UPDATE ttrss_user_entries SET
921 unread = NOT unread,last_read = NOW()
922 WHERE ($ids_qpart) AND owner_uid = $owner_uid");
927 $result = db_query("SELECT DISTINCT feed_id FROM ttrss_user_entries
928 WHERE ($ids_qpart) AND owner_uid = $owner_uid");
930 while ($line = db_fetch_assoc($result)) {
931 CCache
::update($line["feed_id"], $owner_uid);
935 static function getLastArticleId() {
936 $result = db_query("SELECT ref_id AS id FROM ttrss_user_entries
937 WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY ref_id DESC LIMIT 1");
939 if (db_num_rows($result) == 1) {
940 return db_fetch_result($result, 0, "id");
946 static function get_article_labels($id, $owner_uid = false) {
949 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
951 $result = db_query("SELECT label_cache FROM
952 ttrss_user_entries WHERE ref_id = '$id' AND owner_uid = " .
955 if (db_num_rows($result) > 0) {
956 $label_cache = db_fetch_result($result, 0, "label_cache");
959 $label_cache = json_decode($label_cache, true);
961 if ($label_cache["no-labels"] == 1)
969 "SELECT DISTINCT label_id,caption,fg_color,bg_color
970 FROM ttrss_labels2, ttrss_user_labels2
972 AND article_id = '$id'
973 AND owner_uid = ". $owner_uid . "
976 while ($line = db_fetch_assoc($result)) {
977 $rk = array(Labels
::label_to_feed_id($line["label_id"]),
978 $line["caption"], $line["fg_color"],
980 array_push($rv, $rk);
984 Labels
::update_cache($owner_uid, $id, $rv);
986 Labels
::update_cache($owner_uid, $id, array("no-labels" => 1));