]>
git.wh0rd.org - tt-rss.git/blob - classes/article.php
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 $id = clean($_REQUEST['id']);
13 $sth = $this->pdo
->prepare("SELECT link FROM ttrss_entries, ttrss_user_entries
14 WHERE id = ? AND id = ref_id AND owner_uid = ?
16 $sth->execute([$id, $_SESSION['uid']]);
18 if ($row = $sth->fetch()) {
19 $article_url = $row['link'];
20 $article_url = str_replace("\n", "", $article_url);
22 header("Location: $article_url");
26 print_error(__("Article not found."));
31 $id = clean($_REQUEST["id"]);
32 $cids = explode(",", clean($_REQUEST["cids"]));
33 $mode = clean($_REQUEST["mode"]);
35 // in prefetch mode we only output requested cids, main article
36 // just gets marked as read (it already exists in client cache)
41 array_push($articles, $this->format_article($id, false));
42 } else if ($mode == "zoom") {
43 array_push($articles, $this->format_article($id, true, true));
44 } else if ($mode == "raw") {
45 if (isset($_REQUEST['html'])) {
46 header("Content-Type: text/html");
47 print '<link rel="stylesheet" type="text/css" href="css/default.css"/>';
50 $article = $this->format_article($id, false, isset($_REQUEST["zoom"]));
51 print $article['content'];
55 $this->catchupArticleById($id, 0);
57 if (!$_SESSION["bw_limit"]) {
58 foreach ($cids as $cid) {
60 array_push($articles, $this->format_article($cid, false, false));
65 print json_encode($articles);
68 private function catchupArticleById($id, $cmode) {
71 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET
72 unread = false,last_read = NOW()
73 WHERE ref_id = ? AND owner_uid = ?");
74 } else if ($cmode == 1) {
75 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET
77 WHERE ref_id = ? AND owner_uid = ?");
79 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET
80 unread = NOT unread,last_read = NOW()
81 WHERE ref_id = ? AND owner_uid = ?");
84 $sth->execute([$id, $_SESSION['uid']]);
86 $feed_id = $this->getArticleFeed($id);
87 CCache
::update($feed_id, $_SESSION["uid"]);
90 static function create_published_article($title, $url, $content, $labels_str,
93 $guid = 'SHA1:' . sha1("ttshared:" . $url . $owner_uid); // include owner_uid to prevent global GUID clash
96 $pluginhost = new PluginHost();
97 $pluginhost->load_all(PluginHost
::KIND_ALL
, $owner_uid);
98 $pluginhost->load_data();
100 $af_readability = $pluginhost->get_plugin("Af_Readability");
102 if ($af_readability) {
103 $enable_share_anything = $pluginhost->get($af_readability, "enable_share_anything");
105 if ($enable_share_anything) {
106 $extracted_content = $af_readability->extract_content($url);
108 if ($extracted_content) $content = $extracted_content;
113 $content_hash = sha1($content);
115 if ($labels_str != "") {
116 $labels = explode(",", $labels_str);
123 if (!$title) $title = $url;
124 if (!$title && !$url) return false;
126 if (filter_var($url, FILTER_VALIDATE_URL
) === FALSE) return false;
130 $pdo->beginTransaction();
132 // only check for our user data here, others might have shared this with different content etc
133 $sth = $pdo->prepare("SELECT id FROM ttrss_entries, ttrss_user_entries WHERE
134 guid = ? AND ref_id = id AND owner_uid = ? LIMIT 1");
135 $sth->execute([$guid, $owner_uid]);
137 if ($row = $sth->fetch()) {
138 $ref_id = $row['id'];
140 $sth = $pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE
141 ref_id = ? AND owner_uid = ? LIMIT 1");
142 $sth->execute([$ref_id, $owner_uid]);
144 if ($row = $sth->fetch()) {
145 $int_id = $row['int_id'];
147 $sth = $pdo->prepare("UPDATE ttrss_entries SET
148 content = ?, content_hash = ? WHERE id = ?");
149 $sth->execute([$content, $content_hash, $ref_id]);
151 $sth = $pdo->prepare("UPDATE ttrss_user_entries SET published = true,
152 last_published = NOW() WHERE
153 int_id = ? AND owner_uid = ?");
154 $sth->execute([$int_id, $owner_uid]);
158 $sth = $pdo->prepare("INSERT INTO ttrss_user_entries
159 (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache,
160 last_read, note, unread, last_published)
162 (?, '', NULL, NULL, ?, true, '', '', NOW(), '', false, NOW())");
163 $sth->execute([$ref_id, $owner_uid]);
166 if (count($labels) != 0) {
167 foreach ($labels as $label) {
168 Labels
::add_article($ref_id, trim($label), $owner_uid);
175 $sth = $pdo->prepare("INSERT INTO ttrss_entries
176 (title, guid, link, updated, content, content_hash, date_entered, date_updated)
178 (?, ?, ?, NOW(), ?, ?, NOW(), NOW())");
179 $sth->execute([$title, $guid, $url, $content, $content_hash]);
181 $sth = $pdo->prepare("SELECT id FROM ttrss_entries WHERE guid = ?");
182 $sth->execute([$guid]);
184 if ($row = $sth->fetch()) {
185 $ref_id = $row["id"];
187 $sth = $pdo->prepare("INSERT INTO ttrss_user_entries
188 (ref_id, uuid, feed_id, orig_feed_id, owner_uid, published, tag_cache, label_cache,
189 last_read, note, unread, last_published)
191 (?, '', NULL, NULL, ?, true, '', '', NOW(), '', false, NOW())");
192 $sth->execute([$ref_id, $owner_uid]);
194 if (count($labels) != 0) {
195 foreach ($labels as $label) {
196 Labels
::add_article($ref_id, trim($label), $owner_uid);
209 function editArticleTags() {
211 print __("Tags for this article (separated by commas):")."<br>";
213 $param = clean($_REQUEST['param']);
215 $tags = Article
::get_article_tags($param);
217 $tags_str = join(", ", $tags);
219 print_hidden("id", "$param");
220 print_hidden("op", "article");
221 print_hidden("method", "setArticleTags");
223 print "<table width='100%'><tr><td>";
225 print "<textarea dojoType=\"dijit.form.SimpleTextarea\" rows='4'
226 style='height : 100px; font-size : 12px; width : 98%' id=\"tags_str\"
227 name='tags_str'>$tags_str</textarea>
228 <div class=\"autocomplete\" id=\"tags_choices\"
229 style=\"display:none\"></div>";
231 print "</td></tr></table>";
233 print "<div class='dlgButtons'>";
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>";
243 function setScore() {
244 $ids = explode(",", clean($_REQUEST['id']));
245 $score = (int)clean($_REQUEST['score']);
247 $ids_qmarks = arr_qmarks($ids);
249 $sth = $this->pdo
->prepare("UPDATE ttrss_user_entries SET
250 score = ? WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
252 $sth->execute(array_merge([$score], $ids, [$_SESSION['uid']]));
254 print json_encode(array("id" => $ids,
255 "score" => (int)$score,
256 "score_pic" => get_score_pic($score)));
259 function getScore() {
260 $id = clean($_REQUEST['id']);
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();
266 $score = $row['score'];
268 print json_encode(array("id" => $id,
269 "score" => (int)$score,
270 "score_pic" => get_score_pic($score)));
274 function setArticleTags() {
276 $id = clean($_REQUEST["id"]);
278 $tags_str = clean($_REQUEST["tags_str"]);
279 $tags = array_unique(trim_array(explode(",", $tags_str)));
281 $this->pdo
->beginTransaction();
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']]);
287 if ($row = $sth->fetch()) {
289 $tags_to_cache = array();
291 $int_id = $row['int_id'];
293 $sth = $this->pdo
->prepare("DELETE FROM ttrss_tags WHERE
294 post_int_id = ? AND owner_uid = ?");
295 $sth->execute([$int_id, $_SESSION['uid']]);
297 foreach ($tags as $tag) {
298 $tag = sanitize_tag($tag);
300 if (!tag_is_valid($tag)) {
304 if (preg_match("/^[0-9]*$/", $tag)) {
308 // print "<!-- $id : $int_id : $tag -->";
311 $sth = $this->pdo
->prepare("INSERT INTO ttrss_tags
312 (post_int_id, owner_uid, tag_name)
315 $sth->execute([$int_id, $_SESSION['uid'], $tag]);
318 array_push($tags_to_cache, $tag);
321 /* update tag cache */
323 sort($tags_to_cache);
324 $tags_str = join(",", $tags_to_cache);
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']]);
331 $this->pdo
->commit();
333 $tags = Article
::get_article_tags($id);
334 $tags_str = $this->format_tags_string($tags, $id);
335 $tags_str_full = join(", ", $tags);
337 if (!$tags_str_full) $tags_str_full = __("no tags");
339 print json_encode(array("id" => (int)$id,
340 "content" => $tags_str, "content_full" => $tags_str_full));
344 function completeTags() {
345 $search = clean($_REQUEST["search"]);
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
352 $sth->execute([$_SESSION['uid'], "$search%"]);
355 while ($line = $sth->fetch()) {
356 print "<li>" . $line["tag_name"] . "</li>";
361 function assigntolabel() {
362 return $this->labelops(true);
365 function removefromlabel() {
366 return $this->labelops(false);
369 private function labelops($assign) {
372 $ids = explode(",", clean($_REQUEST["ids"]));
373 $label_id = clean($_REQUEST["lid"]);
375 $label = Labels
::find_caption($label_id, $_SESSION["uid"]);
377 $reply["info-for-headlines"] = array();
381 foreach ($ids as $id) {
384 Labels
::add_article($id, $label, $_SESSION["uid"]);
386 Labels
::remove_article($id, $label, $_SESSION["uid"]);
388 $labels = $this->get_article_labels($id, $_SESSION["uid"]);
390 array_push($reply["info-for-headlines"],
391 array("id" => $id, "labels" => $this->format_article_labels($labels)));
396 $reply["message"] = "UPDATE_COUNTERS";
398 print json_encode($reply);
401 function getArticleFeed($id) {
402 $sth = $this->pdo
->prepare("SELECT feed_id FROM ttrss_user_entries
403 WHERE ref_id = ? AND owner_uid = ?");
404 $sth->execute([$id, $_SESSION['uid']]);
406 if ($row = $sth->fetch()) {
407 return $row["feed_id"];
413 static function format_article_enclosures($id, $always_display_enclosures,
414 $article_content, $hide_images = false) {
416 $result = Article
::get_article_enclosures($id);
419 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_FORMAT_ENCLOSURES
) as $plugin) {
420 $retval = $plugin->hook_format_enclosures($rv, $result, $id, $always_display_enclosures, $article_content, $hide_images);
421 if (is_array($retval)) {
423 $result = $retval[1];
428 unset($retval); // Unset to prevent breaking render if there are no HOOK_RENDER_ENCLOSURE hooks below.
430 if ($rv === '' && !empty($result)) {
431 $entries_html = array();
433 $entries_inline = array();
435 foreach ($result as $line) {
437 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ENCLOSURE_ENTRY
) as $plugin) {
438 $line = $plugin->hook_enclosure_entry($line);
441 $url = $line["content_url"];
442 $ctype = $line["content_type"];
443 $title = $line["title"];
444 $width = $line["width"];
445 $height = $line["height"];
447 if (!$ctype) $ctype = __("unknown type");
449 //$filename = substr($url, strrpos($url, "/")+1);
450 $filename = basename($url);
452 $player = format_inline_player($url, $ctype);
454 if ($player) array_push($entries_inline, $player);
456 # $entry .= " <a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\" rel=\"noopener noreferrer\">" .
457 # $filename . " (" . $ctype . ")" . "</a>";
459 $entry = "<div onclick=\"openUrlPopup('".htmlspecialchars($url)."')\"
460 dojoType=\"dijit.MenuItem\">$filename ($ctype)</div>";
462 array_push($entries_html, $entry);
466 $entry["type"] = $ctype;
467 $entry["filename"] = $filename;
468 $entry["url"] = $url;
469 $entry["title"] = $title;
470 $entry["width"] = $width;
471 $entry["height"] = $height;
473 array_push($entries, $entry);
476 if ($_SESSION['uid'] && !get_pref("STRIP_IMAGES") && !$_SESSION["bw_limit"]) {
477 if ($always_display_enclosures ||
478 !preg_match("/<img/i", $article_content)) {
480 foreach ($entries as $entry) {
482 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_RENDER_ENCLOSURE
) as $plugin)
483 $retval = $plugin->hook_render_enclosure($entry, $hide_images);
490 if (preg_match("/image/", $entry["type"])) {
494 if ($entry['height'] > 0)
495 $encsize .= ' height="' . intval($entry['height']) . '"';
496 if ($entry['width'] > 0)
497 $encsize .= ' width="' . intval($entry['width']) . '"';
499 alt=\"".htmlspecialchars($entry["filename"])."\"
500 src=\"" .htmlspecialchars($entry["url"]) . "\"
501 " . $encsize . " /></p>";
503 $rv .= "<p><a target=\"_blank\" rel=\"noopener noreferrer\"
504 href=\"".htmlspecialchars($entry["url"])."\"
505 >" .htmlspecialchars($entry["url"]) . "</a></p>";
508 if ($entry['title']) {
509 $rv.= "<div class=\"enclosure_title\">${entry['title']}</div>";
517 if (count($entries_inline) > 0) {
518 $rv .= "<hr clear='both'/>";
519 foreach ($entries_inline as $entry) { $rv .= $entry; };
520 $rv .= "<hr clear='both'/>";
523 $rv .= "<div class=\"attachments\" dojoType=\"dijit.form.DropDownButton\">".
524 "<span>" . __('Attachments')."</span>";
526 $rv .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
528 foreach ($entries as $entry) {
530 $title = " — " . truncate_string($entry["title"], 30);
534 if ($entry["filename"])
535 $filename = truncate_middle(htmlspecialchars($entry["filename"]), 60);
539 $rv .= "<div onclick='openUrlPopup(\"".htmlspecialchars($entry["url"])."\")'
540 dojoType=\"dijit.MenuItem\">".$filename . $title."</div>";
551 static function format_article($id, $mark_as_read = true, $zoom_mode = false, $owner_uid = false) {
552 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
558 /* we can figure out feed_id from article id anyway, why do we
559 * pass feed_id here? let's ignore the argument :(*/
563 $sth = $pdo->prepare("SELECT feed_id FROM ttrss_user_entries
565 $sth->execute([$id]);
566 $row = $sth->fetch();
568 $feed_id = (int) $row["feed_id"];
570 $rv['feed_id'] = $feed_id;
572 //if (!$zoom_mode) { print "<article id='$id'><![CDATA["; };
575 $sth = $pdo->prepare("UPDATE ttrss_user_entries
576 SET unread = false,last_read = NOW()
577 WHERE ref_id = ? AND owner_uid = ?");
578 $sth->execute([$id, $owner_uid]);
580 CCache
::update($feed_id, $owner_uid);
583 $sth = $pdo->prepare("SELECT id,title,link,content,feed_id,comments,int_id,lang,
584 ".SUBSTRING_FOR_DATE
."(updated,1,16) as updated,
585 (SELECT site_url FROM ttrss_feeds WHERE id = feed_id) as site_url,
586 (SELECT title FROM ttrss_feeds WHERE id = feed_id) as feed_title,
587 (SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) as hide_images,
588 (SELECT always_display_enclosures FROM ttrss_feeds WHERE id = feed_id) as always_display_enclosures,
595 FROM ttrss_entries,ttrss_user_entries
596 WHERE id = ? AND ref_id = id AND owner_uid = ?");
597 $sth->execute([$id, $owner_uid]);
599 if ($line = $sth->fetch()) {
601 $line["tags"] = Article
::get_article_tags($id, $owner_uid, $line["tag_cache"]);
602 unset($line["tag_cache"]);
604 $line["content"] = sanitize($line["content"],
605 $line['hide_images'],
606 $owner_uid, $line["site_url"], false, $line["id"]);
608 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_RENDER_ARTICLE
) as $p) {
609 $line = $p->hook_render_article($line);
612 $line['content'] = rewrite_cached_urls($line['content']);
614 $num_comments = (int) $line["num_comments"];
615 $entry_comments = "";
617 if ($num_comments > 0) {
618 if ($line["comments"]) {
619 $comments_url = htmlspecialchars($line["comments"]);
621 $comments_url = htmlspecialchars($line["link"]);
623 $entry_comments = "<a class=\"postComments\"
624 target='_blank' rel=\"noopener noreferrer\" href=\"$comments_url\">$num_comments ".
625 _ngettext("comment", "comments", $num_comments)."</a>";
628 if ($line["comments"] && $line["link"] != $line["comments"]) {
629 $entry_comments = "<a class=\"postComments\" target='_blank' rel=\"noopener noreferrer\" href=\"".htmlspecialchars($line["comments"])."\">".__("comments")."</a>";
633 $enclosures = self
::get_article_enclosures($line["id"]);
636 header("Content-Type: text/html");
637 $rv['content'] .= "<!DOCTYPE html>
639 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
640 <title>".$line["title"]."</title>".
641 stylesheet_tag("css/default.css")."
642 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
643 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">";
645 $rv['content'] .= "<meta property=\"og:title\" content=\"".htmlspecialchars($line["title"])."\"/>\n";
646 $rv['content'] .= "<meta property=\"og:site_name\" content=\"".htmlspecialchars($line["feed_title"])."\"/>\n";
647 $rv['content'] .= "<meta property=\"og:description\" content=\"".
648 htmlspecialchars(truncate_string(strip_tags($line["content"]), 500, "..."))."\"/>\n";
650 $rv['content'] .= "</head>";
654 foreach ($enclosures as $enc) {
655 if (strpos($enc["content_type"], "image/") !== FALSE) {
656 $og_image = $enc["content_url"];
662 $tmpdoc = new DOMDocument();
664 if (@$tmpdoc->loadHTML(mb_substr($line["content"], 0, 131070))) {
665 $tmpxpath = new DOMXPath($tmpdoc);
666 $first_img = $tmpxpath->query("//img")->item(0);
669 $og_image = $first_img->getAttribute("src");
675 $rv['content'] .= "<meta property=\"og:image\" content=\"" . htmlspecialchars($og_image) . "\"/>";
678 $rv['content'] .= "<body class=\"claro ttrss_utility ttrss_zoom\">";
681 $rv['content'] .= "<div class=\"postReply\" id=\"POST-$id\">";
683 $rv['content'] .= "<div class=\"postHeader\" id=\"POSTHDR-$id\">";
685 $entry_author = $line["author"];
688 $entry_author = __(" - ") . $entry_author;
691 $parsed_updated = make_local_datetime($line["updated"], true,
695 $rv['content'] .= "<div class=\"postDate\">$parsed_updated</div>";
698 $rv['content'] .= "<div class='postTitle'><a target='_blank' rel='noopener noreferrer'
699 title=\"".htmlspecialchars($line['title'])."\"
701 htmlspecialchars($line["link"]) . "\">" .
702 $line["title"] . "</a>" .
703 "<span class='author'>$entry_author</span></div>";
705 $rv['content'] .= "<div class='postTitle'>" . $line["title"] . "$entry_author</div>";
709 $feed_title = htmlspecialchars($line["feed_title"]);
711 $rv['content'] .= "<div class=\"postFeedTitle\">$feed_title</div>";
713 $rv['content'] .= "<div class=\"postDate\">$parsed_updated</div>";
716 $tags_str = Article
::format_tags_string($line["tags"], $id);
717 $tags_str_full = join(", ", $line["tags"]);
719 if (!$tags_str_full) $tags_str_full = __("no tags");
721 if (!$entry_comments) $entry_comments = " "; # placeholder
723 $rv['content'] .= "<div class='postTags' style='float : right'>
724 <img src='images/tag.png'
725 class='tagsPic' alt='Tags' title='Tags'> ";
728 $rv['content'] .= "<span id=\"ATSTR-$id\">$tags_str</span>
729 <a title=\"".__('Edit tags for this article')."\"
730 href=\"#\" onclick=\"editArticleTags($id, $feed_id)\">(+)</a>";
732 $rv['content'] .= "<div dojoType=\"dijit.Tooltip\"
733 id=\"ATSTRTIP-$id\" connectId=\"ATSTR-$id\"
734 position=\"below\">$tags_str_full</div>";
736 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ARTICLE_BUTTON
) as $p) {
737 $rv['content'] .= $p->hook_article_button($line);
741 $tags_str = strip_tags($tags_str);
742 $rv['content'] .= "<span id=\"ATSTR-$id\">$tags_str</span>";
744 $rv['content'] .= "</div>";
745 $rv['content'] .= "<div clear='both'>";
747 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ARTICLE_LEFT_BUTTON
) as $p) {
748 $rv['content'] .= $p->hook_article_left_button($line);
751 $rv['content'] .= "$entry_comments</div>";
753 if ($line["orig_feed_id"]) {
755 $of_sth = $pdo->prepare("SELECT * FROM ttrss_archived_feeds
756 WHERE id = ? AND owner_uid = ?");
757 $of_sth->execute([$line["orig_feed_id"], $owner_uid]);
759 if ($tmp_line = $of_sth->fetch()) {
761 $rv['content'] .= "<div clear='both'>";
762 $rv['content'] .= __("Originally from:");
764 $rv['content'] .= " ";
766 $rv['content'] .= "<a target='_blank' rel='noopener noreferrer'
767 href=' " . htmlspecialchars($tmp_line['site_url']) . "'>" .
768 $tmp_line['title'] . "</a>";
770 $rv['content'] .= " ";
772 $rv['content'] .= "<a target='_blank' rel='noopener noreferrer' href='" . htmlspecialchars($tmp_line['feed_url']) . "'>";
773 $rv['content'] .= "<img title='".__('Feed URL')."' class='tinyFeedIcon' src='images/pub_set.png'></a>";
775 $rv['content'] .= "</div>";
779 $rv['content'] .= "</div>";
781 $rv['content'] .= "<div id=\"POSTNOTE-$id\">";
783 $rv['content'] .= Article
::format_article_note($id, $line['note'], !$zoom_mode);
785 $rv['content'] .= "</div>";
787 if (!$line['lang']) $line['lang'] = 'en';
789 $rv['content'] .= "<div class=\"postContent\" lang=\"".$line['lang']."\">";
791 $rv['content'] .= $line["content"];
794 $rv['content'] .= Article
::format_article_enclosures($id,
795 $line["always_display_enclosures"],
797 $line["hide_images"]);
800 $rv['content'] .= "</div>";
802 $rv['content'] .= "</div>";
809 <button onclick=\"return window.close()\">".
810 __("Close this window")."</button></div>";
811 $rv['content'] .= "</body></html>";
814 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_FORMAT_ARTICLE
) as $p) {
815 $rv['content'] = $p->hook_format_article($rv['content'], $line, $zoom_mode);
822 static function get_article_tags($id, $owner_uid = 0, $tag_cache = false) {
826 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
830 $sth = $pdo->prepare("SELECT DISTINCT tag_name,
831 owner_uid as owner FROM ttrss_tags
832 WHERE post_int_id = (SELECT int_id FROM ttrss_user_entries WHERE
833 ref_id = ? AND owner_uid = ? LIMIT 1) ORDER BY tag_name");
837 /* check cache first */
839 if ($tag_cache === false) {
840 $csth = $pdo->prepare("SELECT tag_cache FROM ttrss_user_entries
841 WHERE ref_id = ? AND owner_uid = ?");
842 $csth->execute([$id, $owner_uid]);
844 if ($row = $csth->fetch()) $tag_cache = $row["tag_cache"];
848 $tags = explode(",", $tag_cache);
851 /* do it the hard way */
853 $sth->execute([$a_id, $owner_uid]);
855 while ($tmp_line = $sth->fetch()) {
856 array_push($tags, $tmp_line["tag_name"]);
859 /* update the cache */
861 $tags_str = join(",", $tags);
863 $sth = $pdo->prepare("UPDATE ttrss_user_entries
864 SET tag_cache = ? WHERE ref_id = ?
866 $sth->execute([$tags_str, $id, $owner_uid]);
872 static function format_tags_string($tags) {
873 if (!is_array($tags) ||
count($tags) == 0) {
874 return __("no tags");
876 $maxtags = min(5, count($tags));
879 for ($i = 0; $i < $maxtags; $i++
) {
880 $tags_str .= "<a class=\"tag\" href=\"#\" onclick=\"viewfeed({feed:'".$tags[$i]."'})\">" . $tags[$i] . "</a>, ";
883 $tags_str = mb_substr($tags_str, 0, mb_strlen($tags_str)-2);
885 if (count($tags) > $maxtags)
886 $tags_str .= ", …";
892 static function format_article_labels($labels) {
894 if (!is_array($labels)) return '';
898 foreach ($labels as $l) {
899 $labels_str .= sprintf("<span class='hlLabelRef'
900 style='color : %s; background-color : %s'>%s</span>",
901 $l[2], $l[3], $l[1]);
908 static function format_article_note($id, $note, $allow_edit = true) {
910 $str = "<div class='articleNote' onclick=\"editArticleNote($id)\">
911 <div class='noteEdit' onclick=\"editArticleNote($id)\">".
912 ($allow_edit ?
__('(edit note)') : "")."</div>$note</div>";
917 static function get_article_enclosures($id) {
921 $sth = $pdo->prepare("SELECT * FROM ttrss_enclosures
922 WHERE post_id = ? AND content_url != ''");
923 $sth->execute([$id]);
927 while ($line = $sth->fetch()) {
929 if (file_exists(CACHE_DIR
. '/images/' . sha1($line["content_url"]))) {
930 $line["content_url"] = get_self_url_prefix() . '/public.php?op=cached_url&hash=' . sha1($line["content_url"]);
933 array_push($rv, $line);
939 static function purge_orphans($do_output = false) {
941 // purge orphaned posts in main content table
943 if (DB_TYPE
== "mysql")
944 $limit_qpart = "LIMIT 5000";
949 $res = $pdo->query("DELETE FROM ttrss_entries WHERE
950 NOT EXISTS (SELECT ref_id FROM ttrss_user_entries WHERE ref_id = id) $limit_qpart");
953 $rows = $res->rowCount();
954 _debug("Purged $rows orphaned posts.");
958 static function catchupArticlesById($ids, $cmode, $owner_uid = false) {
960 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
964 $ids_qmarks = arr_qmarks($ids);
967 $sth = $pdo->prepare("UPDATE ttrss_user_entries SET
968 unread = false,last_read = NOW()
969 WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
970 } else if ($cmode == 1) {
971 $sth = $pdo->prepare("UPDATE ttrss_user_entries SET
973 WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
975 $sth = $pdo->prepare("UPDATE ttrss_user_entries SET
976 unread = NOT unread,last_read = NOW()
977 WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
980 $sth->execute(array_merge($ids, [$owner_uid]));
984 $sth = $pdo->prepare("SELECT DISTINCT feed_id FROM ttrss_user_entries
985 WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
986 $sth->execute(array_merge($ids, [$owner_uid]));
988 while ($line = $sth->fetch()) {
989 CCache
::update($line["feed_id"], $owner_uid);
993 static function getLastArticleId() {
996 $sth = $pdo->prepare("SELECT ref_id AS id FROM ttrss_user_entries
997 WHERE owner_uid = ? ORDER BY ref_id DESC LIMIT 1");
998 $sth->execute([$_SESSION['uid']]);
1000 if ($row = $sth->fetch()) {
1007 static function get_article_labels($id, $owner_uid = false) {
1010 if (!$owner_uid) $owner_uid = $_SESSION["uid"];
1014 $sth = $pdo->prepare("SELECT label_cache FROM
1015 ttrss_user_entries WHERE ref_id = ? AND owner_uid = ?");
1016 $sth->execute([$id, $owner_uid]);
1018 if ($row = $sth->fetch()) {
1019 $label_cache = $row["label_cache"];
1022 $tmp = json_decode($label_cache, true);
1024 if (!$tmp ||
$tmp["no-labels"] == 1)
1031 $sth = $pdo->prepare("SELECT DISTINCT label_id,caption,fg_color,bg_color
1032 FROM ttrss_labels2, ttrss_user_labels2
1037 $sth->execute([$id, $owner_uid]);
1039 while ($line = $sth->fetch()) {
1040 $rk = array(Labels
::label_to_feed_id($line["label_id"]),
1041 $line["caption"], $line["fg_color"],
1043 array_push($rv, $rk);
1047 Labels
::update_cache($owner_uid, $id, $rv);
1049 Labels
::update_cache($owner_uid, $id, array("no-labels" => 1));