Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hot links feature / mark items w/ identical link as read #1

Merged
merged 3 commits into from
Jan 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 111 additions & 3 deletions fever/fever_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,90 @@ function getFavicons()
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;
}

Expand Down Expand Up @@ -625,6 +706,30 @@ function getSavedItemIds()
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 */
Expand Down Expand Up @@ -680,12 +785,15 @@ function setItem($id, $field_raw, $mode)

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)
Expand Down
4 changes: 2 additions & 2 deletions fever/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down