From cb6f31bfa51ca2ca316c1b64f5a78b7d245d0a20 Mon Sep 17 00:00:00 2001 From: mestrode <35630715+mestrode@users.noreply.github.com> Date: Sat, 20 Jan 2018 15:20:13 +0100 Subject: [PATCH 1/3] hot links feature --- fever/fever_api.php | 83 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/fever/fever_api.php b/fever/fever_api.php index 7490488..dc93bb6 100644 --- a/fever/fever_api.php +++ b/fever/fever_api.php @@ -369,9 +369,90 @@ class FeverAPI extends Handler { function getLinks() { // TODO: is there a 'hot links' alternative in ttrss? - // use ttrss_user_entries / score>0 + // use ttrss_user_entries / score > 0 / unread $links = array(); + $item_limit = 50; + $where = "owner_uid = ? AND ref_id = id AND score > 0 AND unread = true"; + $where_items = array(); + array_push($where_items, clean($_SESSION["uid"])); + + if (isset($_REQUEST["range"])) + { + // use the range argument to request a limited "updated" items + if (is_numeric($_REQUEST["range"])) + { + $range = ($_REQUEST["range"] > 0) ? intval(clean($_REQUEST["range"])) : 0; + if ($range) + { + + $offset = 0; + if (isset($_REQUEST["offset"])) + { + // use the range argument to request a limited "updated" items + if (is_numeric($_REQUEST["offset"])) + { + $offset = ($_REQUEST["offset"] > 0) ? intval(clean($_REQUEST["offset"])) : 0; + } + } + + if ($range) { + if ($offset == 0) { + //range > 1 AND offset = 0 + $where .= " AND updated < NOW()"; + $where .= " AND updated > NOW()-INTERVAL ? DAY"; + array_push($where_items, $range); + } else { + //range > 1 AND offset > 0 + $where .= " AND updated < NOW()-INTERVAL ? DAY"; + $where .= " AND updated > NOW()-INTERVAL ? DAY"; + array_push($where_items, $offset, $offset+$range); + } + } + } + } + } + + $where .= " ORDER BY score DESC, updated DESC" ; + + if (is_numeric($_REQUEST["page"])) + { + // use the page argument to request the next $item_limit items + // page = 1 --> 1st Page will be convertet to 0 + $page = isset($_REQUEST["page"]) ? intval(clean($_REQUEST["page"]))-1 : 0; + $page = ($page<0) ? 0 : $page; + + $where .= " LIMIT " . intval($page * $item_limit) . ", " . $item_limit; + // array_push($where_items, $item_limit); + // array_push($where_items, ($page * $item_limit)); + } else { + $where .= " LIMIT ?"; + array_push($where_items, $item_limit); + } + + /* classes/api.php getLinks */ + + // id, feed_id, title, author, html, url, is_saved, is_read, created_on_time + $sth = $this->pdo->prepare("SELECT ref_id, feed_id, title, link, score, id, marked, unread, updated + FROM ttrss_entries, ttrss_user_entries + WHERE " . $where); + $sth->execute($where_items); + + while ($line = $sth->fetch()) + { + array_push($links, array("id" => intval($line["id"]), + "feed_id" => intval($line["feed_id"]), + "item_id" => intval($line["ref_id"]), + "temperature" => intval($line["score"]), + "is_item" => 1, + "is_local" => 1, + "is_saved" => (API::param_to_bool($line["marked"]) ? 1 : 0), + "title" => $line["title"], + "url" => $line["link"], + "item_ids" => "" + )); + } + return $links; } From 72d22b2b3b28a0786a51deb6a35b6b73a1af295f Mon Sep 17 00:00:00 2001 From: mestrode <35630715+mestrode@users.noreply.github.com> Date: Sat, 20 Jan 2018 15:21:25 +0100 Subject: [PATCH 2/3] mark all item w/ equal links as read/unread --- fever/fever_api.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/fever/fever_api.php b/fever/fever_api.php index dc93bb6..5354004 100644 --- a/fever/fever_api.php +++ b/fever/fever_api.php @@ -706,6 +706,30 @@ class FeverAPI extends Handler { return $savedItemIdsCSV; } + function getEqualItems($id) + { + //get all ids which have identical links (Reference is found by id) + $sth = $this->pdo->prepare("SELECT id + FROM ttrss_entries,ttrss_user_entries + WHERE id=ref_id AND owner_uid = ? + AND link=(SELECT link FROM ttrss_entries WHERE id = ?)"); + $sth->execute(array_merge([clean($_SESSION["uid"]), $id])); + + $ids = ""; + while ($line = $sth->fetch()) + { + $ids .= $line["id"] . ","; + } + $ids = trim($ids, ","); + + if (self::DEBUG) { + // add request to debug log + error_log(print_r($ids, true)); + } + + return $ids; + } + function setItem($id, $field_raw, $mode) { /* classes/api.php updateArticle */ @@ -761,12 +785,15 @@ class FeverAPI extends Handler { function setItemAsRead($id) { - $this->setItem($id, 1, 0); + //action is true for all Equal Items + $ids = $this->getEqualItems($id); + $this->setItem($ids, 1, 0); } function setItemAsUnread($id) { - $this->setItem($id, 1, 1); + $ids = $this->getEqualItems($id); + $this->setItem($ids, 1, 1); } function setItemAsSaved($id) From c8eb8437aa53bc74be04c1c0d57ed14822c00ffb Mon Sep 17 00:00:00 2001 From: mestrode <35630715+mestrode@users.noreply.github.com> Date: Sat, 20 Jan 2018 15:24:19 +0100 Subject: [PATCH 3/3] version / credits --- fever/init.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fever/init.php b/fever/init.php index 62f34bf..a6424cd 100644 --- a/fever/init.php +++ b/fever/init.php @@ -3,9 +3,9 @@ class Fever extends Plugin { private $host; function about() { - return array(2.1, + return array(2.2, "Emulates the Fever API for Tiny Tiny RSS", - "DigitalDJ & murphy"); + "DigitalDJ, mestrode & murphy"); } function init($host) {