+ function editArticleTags() {
+
+ print __("Tags for this article (separated by commas):")."<br>";
+
+ $param = clean($_REQUEST['param']);
+
+ $tags = Article::get_article_tags($param);
+
+ $tags_str = join(", ", $tags);
+
+ print_hidden("id", "$param");
+ print_hidden("op", "article");
+ print_hidden("method", "setArticleTags");
+
+ print "<table width='100%'><tr><td>";
+
+ print "<textarea dojoType=\"dijit.form.SimpleTextarea\" rows='4'
+ style='height : 100px; font-size : 12px; width : 98%' id=\"tags_str\"
+ name='tags_str'>$tags_str</textarea>
+ <div class=\"autocomplete\" id=\"tags_choices\"
+ style=\"display:none\"></div>";
+
+ print "</td></tr></table>";
+
+ print "<div class='dlgButtons'>";
+
+ print "<button dojoType=\"dijit.form.Button\"
+ onclick=\"dijit.byId('editTagsDlg').execute()\">".__('Save')."</button> ";
+ print "<button dojoType=\"dijit.form.Button\"
+ onclick=\"dijit.byId('editTagsDlg').hide()\">".__('Cancel')."</button>";
+ print "</div>";
+
+ }
+
+ function setScore() {
+ $ids = explode(",", clean($_REQUEST['id']));
+ $score = (int)clean($_REQUEST['score']);
+
+ $ids_qmarks = arr_qmarks($ids);
+
+ $sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET
+ score = ? WHERE ref_id IN ($ids_qmarks) AND owner_uid = ?");
+
+ $sth->execute(array_merge([$score], $ids, [$_SESSION['uid']]));
+
+ print json_encode(array("id" => $ids,
+ "score" => (int)$score,
+ "score_pic" => get_score_pic($score)));
+ }
+
+ function getScore() {
+ $id = clean($_REQUEST['id']);
+
+ $sth = $this->pdo->prepare("SELECT score FROM ttrss_user_entries WHERE ref_id = ? AND owner_uid = ?");
+ $sth->execute([$id, $_SESSION['uid']]);
+ $row = $sth->fetch();
+
+ $score = $row['score'];
+
+ print json_encode(array("id" => $id,
+ "score" => (int)$score,
+ "score_pic" => get_score_pic($score)));
+ }
+
+
+ function setArticleTags() {
+
+ $id = clean($_REQUEST["id"]);
+
+ $tags_str = clean($_REQUEST["tags_str"]);
+ $tags = array_unique(trim_array(explode(",", $tags_str)));
+
+ $this->pdo->beginTransaction();
+
+ $sth = $this->pdo->prepare("SELECT int_id FROM ttrss_user_entries WHERE
+ ref_id = ? AND owner_uid = ? LIMIT 1");
+ $sth->execute([$id, $_SESSION['uid']]);
+
+ if ($row = $sth->fetch()) {
+
+ $tags_to_cache = array();
+
+ $int_id = $row['int_id'];
+
+ $sth = $this->pdo->prepare("DELETE FROM ttrss_tags WHERE
+ post_int_id = ? AND owner_uid = ?");
+ $sth->execute([$int_id, $_SESSION['uid']]);
+
+ foreach ($tags as $tag) {
+ $tag = sanitize_tag($tag);
+
+ if (!tag_is_valid($tag)) {
+ continue;
+ }
+
+ if (preg_match("/^[0-9]*$/", $tag)) {
+ continue;
+ }
+
+ // print "<!-- $id : $int_id : $tag -->";
+
+ if ($tag != '') {
+ $sth = $this->pdo->prepare("INSERT INTO ttrss_tags
+ (post_int_id, owner_uid, tag_name)
+ VALUES (?, ?, ?)");
+
+ $sth->execute([$int_id, $_SESSION['uid'], $tag]);
+ }
+
+ array_push($tags_to_cache, $tag);
+ }
+
+ /* update tag cache */
+
+ sort($tags_to_cache);
+ $tags_str = join(",", $tags_to_cache);
+
+ $sth = $this->pdo->prepare("UPDATE ttrss_user_entries
+ SET tag_cache = ? WHERE ref_id = ? AND owner_uid = ?");
+ $sth->execute([$tags_str, $id, $_SESSION['uid']]);
+ }
+
+ $this->pdo->commit();
+
+ $tags = Article::get_article_tags($id);
+ $tags_str = $this->format_tags_string($tags, $id);
+ $tags_str_full = join(", ", $tags);
+
+ if (!$tags_str_full) $tags_str_full = __("no tags");
+
+ print json_encode(array("id" => (int)$id,
+ "content" => $tags_str, "content_full" => $tags_str_full));
+ }
+
+
+ function completeTags() {
+ $search = clean($_REQUEST["search"]);
+
+ $sth = $this->pdo->prepare("SELECT DISTINCT tag_name FROM ttrss_tags
+ WHERE owner_uid = ? AND
+ tag_name LIKE ? ORDER BY tag_name
+ LIMIT 10");
+
+ $sth->execute([$_SESSION['uid'], "$search%"]);
+
+ print "<ul>";
+ while ($line = $sth->fetch()) {
+ print "<li>" . $line["tag_name"] . "</li>";
+ }
+ print "</ul>";
+ }
+
+ function assigntolabel() {
+ return $this->labelops(true);
+ }
+
+ function removefromlabel() {
+ return $this->labelops(false);
+ }
+
+ private function labelops($assign) {
+ $reply = array();
+
+ $ids = explode(",", clean($_REQUEST["ids"]));
+ $label_id = clean($_REQUEST["lid"]);
+
+ $label = Labels::find_caption($label_id, $_SESSION["uid"]);
+
+ $reply["info-for-headlines"] = array();
+
+ if ($label) {
+
+ foreach ($ids as $id) {
+
+ if ($assign)
+ Labels::add_article($id, $label, $_SESSION["uid"]);
+ else
+ Labels::remove_article($id, $label, $_SESSION["uid"]);
+
+ $labels = $this->get_article_labels($id, $_SESSION["uid"]);
+
+ array_push($reply["info-for-headlines"],
+ array("id" => $id, "labels" => $this->format_article_labels($labels)));
+
+ }
+ }
+
+ $reply["message"] = "UPDATE_COUNTERS";
+
+ print json_encode($reply);
+ }
+
+ function getArticleFeed($id) {
+ $sth = $this->pdo->prepare("SELECT feed_id FROM ttrss_user_entries
+ WHERE ref_id = ? AND owner_uid = ?");
+ $sth->execute([$id, $_SESSION['uid']]);
+
+ if ($row = $sth->fetch()) {
+ return $row["feed_id"];
+ } else {
+ return 0;
+ }
+ }
+
+ static function format_article_enclosures($id, $always_display_enclosures,
+ $article_content, $hide_images = false) {
+
+ $result = Article::get_article_enclosures($id);
+ $rv = '';
+
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FORMAT_ENCLOSURES) as $plugin) {
+ $retval = $plugin->hook_format_enclosures($rv, $result, $id, $always_display_enclosures, $article_content, $hide_images);
+ if (is_array($retval)) {
+ $rv = $retval[0];
+ $result = $retval[1];
+ } else {
+ $rv = $retval;
+ }
+ }
+ unset($retval); // Unset to prevent breaking render if there are no HOOK_RENDER_ENCLOSURE hooks below.
+
+ if ($rv === '' && !empty($result)) {
+ $entries_html = array();
+ $entries = array();
+ $entries_inline = array();
+
+ foreach ($result as $line) {
+
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ENCLOSURE_ENTRY) as $plugin) {
+ $line = $plugin->hook_enclosure_entry($line);
+ }
+
+ $url = $line["content_url"];
+ $ctype = $line["content_type"];
+ $title = $line["title"];
+ $width = $line["width"];
+ $height = $line["height"];
+
+ if (!$ctype) $ctype = __("unknown type");
+
+ //$filename = substr($url, strrpos($url, "/")+1);
+ $filename = basename($url);
+
+ $player = format_inline_player($url, $ctype);
+
+ if ($player) array_push($entries_inline, $player);
+
+# $entry .= " <a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\" rel=\"noopener noreferrer\">" .
+# $filename . " (" . $ctype . ")" . "</a>";
+
+ $entry = "<div onclick=\"openUrlPopup('".htmlspecialchars($url)."')\"
+ dojoType=\"dijit.MenuItem\">$filename ($ctype)</div>";
+
+ array_push($entries_html, $entry);
+
+ $entry = array();
+
+ $entry["type"] = $ctype;
+ $entry["filename"] = $filename;
+ $entry["url"] = $url;
+ $entry["title"] = $title;
+ $entry["width"] = $width;
+ $entry["height"] = $height;
+
+ array_push($entries, $entry);
+ }
+
+ if ($_SESSION['uid'] && !get_pref("STRIP_IMAGES") && !$_SESSION["bw_limit"]) {
+ if ($always_display_enclosures ||
+ !preg_match("/<img/i", $article_content)) {
+
+ foreach ($entries as $entry) {
+
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ENCLOSURE) as $plugin)
+ $retval = $plugin->hook_render_enclosure($entry, $hide_images);
+
+
+ if ($retval) {
+ $rv .= $retval;
+ } else {
+
+ if (preg_match("/image/", $entry["type"])) {
+
+ if (!$hide_images) {
+ $encsize = '';
+ if ($entry['height'] > 0)
+ $encsize .= ' height="' . intval($entry['height']) . '"';
+ if ($entry['width'] > 0)
+ $encsize .= ' width="' . intval($entry['width']) . '"';
+ $rv .= "<p><img
+ alt=\"".htmlspecialchars($entry["filename"])."\"
+ src=\"" .htmlspecialchars($entry["url"]) . "\"
+ " . $encsize . " /></p>";
+ } else {
+ $rv .= "<p><a target=\"_blank\" rel=\"noopener noreferrer\"
+ href=\"".htmlspecialchars($entry["url"])."\"
+ >" .htmlspecialchars($entry["url"]) . "</a></p>";
+ }
+
+ if ($entry['title']) {
+ $rv.= "<div class=\"enclosure_title\">${entry['title']}</div>";
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (count($entries_inline) > 0) {
+ $rv .= "<hr clear='both'/>";
+ foreach ($entries_inline as $entry) { $rv .= $entry; };
+ $rv .= "<hr clear='both'/>";
+ }
+
+ $rv .= "<div class=\"attachments\" dojoType=\"dijit.form.DropDownButton\">".
+ "<span>" . __('Attachments')."</span>";
+
+ $rv .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
+
+ foreach ($entries as $entry) {
+ if ($entry["title"])
+ $title = " — " . truncate_string($entry["title"], 30);
+ else
+ $title = "";
+
+ if ($entry["filename"])
+ $filename = truncate_middle(htmlspecialchars($entry["filename"]), 60);
+ else
+ $filename = "";
+
+ $rv .= "<div onclick='openUrlPopup(\"".htmlspecialchars($entry["url"])."\")'
+ dojoType=\"dijit.MenuItem\">".$filename . $title."</div>";
+
+ };
+
+ $rv .= "</div>";
+ $rv .= "</div>";
+ }
+
+ return $rv;
+ }
+
+ static function format_article($id, $mark_as_read = true, $zoom_mode = false, $owner_uid = false) {
+ if (!$owner_uid) $owner_uid = $_SESSION["uid"];
+
+ $rv = array();
+
+ $rv['id'] = $id;
+
+ /* we can figure out feed_id from article id anyway, why do we
+ * pass feed_id here? let's ignore the argument :(*/
+
+ $pdo = Db::pdo();
+
+ $sth = $pdo->prepare("SELECT feed_id FROM ttrss_user_entries
+ WHERE ref_id = ?");
+ $sth->execute([$id]);
+ $row = $sth->fetch();
+
+ $feed_id = (int) $row["feed_id"];
+
+ $rv['feed_id'] = $feed_id;
+
+ //if (!$zoom_mode) { print "<article id='$id'><![CDATA["; };
+
+ if ($mark_as_read) {
+ $sth = $pdo->prepare("UPDATE ttrss_user_entries
+ SET unread = false,last_read = NOW()
+ WHERE ref_id = ? AND owner_uid = ?");
+ $sth->execute([$id, $owner_uid]);
+
+ CCache::update($feed_id, $owner_uid);
+ }
+
+ $sth = $pdo->prepare("SELECT id,title,link,content,feed_id,comments,int_id,lang,
+ ".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
+ (SELECT site_url FROM ttrss_feeds WHERE id = feed_id) as site_url,
+ (SELECT title FROM ttrss_feeds WHERE id = feed_id) as feed_title,
+ (SELECT hide_images FROM ttrss_feeds WHERE id = feed_id) as hide_images,
+ (SELECT always_display_enclosures FROM ttrss_feeds WHERE id = feed_id) as always_display_enclosures,
+ num_comments,
+ tag_cache,
+ author,
+ guid,
+ orig_feed_id,
+ note
+ FROM ttrss_entries,ttrss_user_entries
+ WHERE id = ? AND ref_id = id AND owner_uid = ?");
+ $sth->execute([$id, $owner_uid]);
+
+ if ($line = $sth->fetch()) {
+
+ $line["tags"] = Article::get_article_tags($id, $owner_uid, $line["tag_cache"]);
+ unset($line["tag_cache"]);
+
+ $line["content"] = sanitize($line["content"],
+ $line['hide_images'],
+ $owner_uid, $line["site_url"], false, $line["id"]);
+
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) {
+ $line = $p->hook_render_article($line);
+ }
+
+ $line['content'] = rewrite_cached_urls($line['content']);
+
+ $num_comments = (int) $line["num_comments"];
+ $entry_comments = "";
+
+ if ($num_comments > 0) {
+ if ($line["comments"]) {
+ $comments_url = htmlspecialchars($line["comments"]);
+ } else {
+ $comments_url = htmlspecialchars($line["link"]);
+ }
+ $entry_comments = "<a class=\"postComments\"
+ target='_blank' rel=\"noopener noreferrer\" href=\"$comments_url\">$num_comments ".
+ _ngettext("comment", "comments", $num_comments)."</a>";
+
+ } else {
+ if ($line["comments"] && $line["link"] != $line["comments"]) {
+ $entry_comments = "<a class=\"postComments\" target='_blank' rel=\"noopener noreferrer\" href=\"".htmlspecialchars($line["comments"])."\">".__("comments")."</a>";
+ }
+ }
+
+ $enclosures = self::get_article_enclosures($line["id"]);
+
+ if ($zoom_mode) {
+ header("Content-Type: text/html");
+ $rv['content'] .= "<!DOCTYPE html>
+ <html><head>
+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
+ <title>".$line["title"]."</title>".
+ stylesheet_tag("css/default.css")."
+ <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
+ <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">";
+
+ $rv['content'] .= "<meta property=\"og:title\" content=\"".htmlspecialchars($line["title"])."\"/>\n";
+ $rv['content'] .= "<meta property=\"og:site_name\" content=\"".htmlspecialchars($line["feed_title"])."\"/>\n";
+ $rv['content'] .= "<meta property=\"og:description\" content=\"".
+ htmlspecialchars(truncate_string(strip_tags($line["content"]), 500, "..."))."\"/>\n";