added first version which works with Mr.Reader 2.0

This commit is contained in:
Torsten Stelling
2013-06-27 22:38:38 +02:00
parent 28ecc6ab70
commit c11edb8149
2 changed files with 152 additions and 124 deletions

View File

@@ -30,6 +30,10 @@ Full Support
* Reeder - iPhone * Reeder - iPhone
Limited support
* Mr.Reader - iPad - can currently only load and show items, can **not** read/star items
## <a name="installation">Installation</a> ## <a name="installation">Installation</a>
Upload the ```fever``` folder in the ```plugins``` folder of your TinyTinyRSS installation. Enable the plugin in the preferences and set your password for the Fever API. Upload the ```fever``` folder in the ```plugins``` folder of your TinyTinyRSS installation. Enable the plugin in the preferences and set your password for the Fever API.
@@ -45,3 +49,9 @@ Licensed under GNU GPL version 2 (<- I think this is okay for this plugin…)
v1.0-v1.2 - 2013/5/27 - DigitalDJ version v1.0-v1.2 - 2013/5/27 - DigitalDJ version
* see this [thread](http://tt-rss.org/forum/viewtopic.php?f=22&t=1981) in the TinyTinyRSS Forum * see this [thread](http://tt-rss.org/forum/viewtopic.php?f=22&t=1981) in the TinyTinyRSS Forum
v1.3 - 2013/6/27
* fixed several bugs in json output from the plugin
* added a small fix for Mr.Reader 2.0 so it can complete loading of all items
* added first Mr.Reader compatiblity without marking items read/starred

View File

@@ -1,27 +1,32 @@
<?php <?php
class FeverAPI extends Handler { class FeverAPI extends Handler {
const API_LEVEL = 3; const API_LEVEL = 3;
const STATUS_OK = 1; const STATUS_OK = 1;
const STATUS_ERR = 0; const STATUS_ERR = 0;
// debugging only function with JSON
const DEBUG = 0; // enable if you need some debug output in your tinytinyrss root
const DEBUG_USER = 1; // your user id you need to debug - look it up in your mysql database
private $xml; private $xml;
// always include api_version, status as 'auth' // always include api_version, status as 'auth'
// output json/xml // output json/xml
function wrap($status, $reply) function wrap($status, $reply)
{ {
$arr = array("api_version" => self::API_LEVEL, $arr = array("api_version" => self::API_LEVEL,
"auth" => $status); "auth" => $status);
if ($status == self::STATUS_OK) if ($status == self::STATUS_OK)
{ {
$arr["last_refreshed_on_time"] = $this->lastRefreshedOnTime()."";
if (!empty($reply) && is_array($reply)) if (!empty($reply) && is_array($reply))
$arr = array_merge($arr, $reply); $arr = array_merge($arr, $reply);
$arr["last_refreshed_on_time"] = $this->lastRefreshedOnTime();
} }
if ($this->xml) if ($this->xml)
{ {
print $this->array_to_xml($arr); print $this->array_to_xml($arr);
@@ -29,16 +34,20 @@ class FeverAPI extends Handler {
else else
{ {
print json_encode($arr); print json_encode($arr);
} if (DEBUG==1) {
// debug output
file_put_contents('./debug_fever.txt','answer : '.json_encode($arr)."\n",FILE_APPEND);
}
}
} }
// fever supports xml wrapped in <response> tags // fever supports xml wrapped in <response> tags
private function array_to_xml($array, $container = 'response', $is_root = true) private function array_to_xml($array, $container = 'response', $is_root = true)
{ {
if (!is_array($array)) return array_to_xml(array($array)); if (!is_array($array)) return array_to_xml(array($array));
$xml = ''; $xml = '';
if ($is_root) if ($is_root)
{ {
$xml .= '<?xml version="1.0" encoding="utf-8"?>'; $xml .= '<?xml version="1.0" encoding="utf-8"?>';
@@ -49,14 +58,14 @@ class FeverAPI extends Handler {
{ {
// make sure key is a string // make sure key is a string
$elem = $key; $elem = $key;
if (!is_string($key) && !empty($container)) if (!is_string($key) && !empty($container))
{ {
$elem = $container; $elem = $container;
} }
$xml .= "<{$elem}>"; $xml .= "<{$elem}>";
if (is_array($value)) if (is_array($value))
{ {
if (array_keys($value) !== array_keys(array_keys($value))) if (array_keys($value) !== array_keys(array_keys($value)))
@@ -72,18 +81,18 @@ class FeverAPI extends Handler {
{ {
$xml .= (htmlspecialchars($value, ENT_COMPAT, 'ISO-8859-1') != $value) ? "<![CDATA[{$value}]]>" : $value; $xml .= (htmlspecialchars($value, ENT_COMPAT, 'ISO-8859-1') != $value) ? "<![CDATA[{$value}]]>" : $value;
} }
$xml .= "</{$elem}>"; $xml .= "</{$elem}>";
} }
if ($is_root) if ($is_root)
{ {
$xml .= "</{$container}>"; $xml .= "</{$container}>";
} }
return preg_replace('/[\x00-\x1F\x7F]/', '', $xml); return preg_replace('/[\x00-\x1F\x7F]/', '', $xml);
} }
// every authenticated method includes last_refreshed_on_time // every authenticated method includes last_refreshed_on_time
private function lastRefreshedOnTime() private function lastRefreshedOnTime()
{ {
@@ -91,19 +100,19 @@ class FeverAPI extends Handler {
FROM ttrss_feeds FROM ttrss_feeds
WHERE owner_uid = " . $_SESSION["uid"] . " WHERE owner_uid = " . $_SESSION["uid"] . "
ORDER BY last_updated DESC"); ORDER BY last_updated DESC");
if ($this->dbh->num_rows($result) > 0) if ($this->dbh->num_rows($result) > 0)
{ {
$last_refreshed_on_time = strtotime($this->dbh->fetch_result($result, 0, "last_updated")); $last_refreshed_on_time = strtotime($this->dbh->fetch_result($result, 0, "last_updated"));
} }
else else
{ {
$last_refreshed_on_time = 0; $last_refreshed_on_time = 0;
} }
return $last_refreshed_on_time; return $last_refreshed_on_time;
} }
// find the user in the db with a particular api key // find the user in the db with a particular api key
private function setUser() private function setUser()
{ {
@@ -112,14 +121,18 @@ class FeverAPI extends Handler {
$result = $this->dbh->query("SELECT owner_uid $result = $this->dbh->query("SELECT owner_uid
FROM ttrss_plugin_storage FROM ttrss_plugin_storage
WHERE content = '" . db_escape_string('a:1:{s:8:"password";s:32:"') . db_escape_string(strtolower($_REQUEST["api_key"])) . db_escape_string('";}') . "'"); WHERE content = '" . db_escape_string('a:1:{s:8:"password";s:32:"') . db_escape_string(strtolower($_REQUEST["api_key"])) . db_escape_string('";}') . "'");
if ($this->dbh->num_rows($result) > 0) if ($this->dbh->num_rows($result) > 0)
{ {
$_SESSION["uid"] = $this->dbh->fetch_result($result, 0, "owner_uid"); $_SESSION["uid"] = $this->dbh->fetch_result($result, 0, "owner_uid");
} }
if (DEBUG==1) {
$_SESSION["uid"] = DEBUG_USER; // always authenticate and set debug user
}
} }
} }
// set whether xml or json // set whether xml or json
private function setXml() private function setXml()
{ {
@@ -130,31 +143,31 @@ class FeverAPI extends Handler {
$this->xml = true; $this->xml = true;
} }
} }
private function flattenGroups(&$groupsToGroups, &$groups, &$groupsToTitle, $index) private function flattenGroups(&$groupsToGroups, &$groups, &$groupsToTitle, $index)
{ {
foreach ($groupsToGroups[$index] as $item) foreach ($groupsToGroups[$index] as $item)
{ {
$id = substr($item, strpos($item, "-") + 1); $id = substr($item, strpos($item, "-") + 1);
array_push($groups, array("id" => $id, "title" => $groupsToTitle[$id])); array_push($groups, array("id" => intval($id), "title" => $groupsToTitle[$id]));
if (isset($groupsToGroups[$id])) if (isset($groupsToGroups[$id]))
$this->flattenGroups($groupsToGroups, $groups, $groupsToTitle, $id); $this->flattenGroups($groupsToGroups, $groups, $groupsToTitle, $id);
} }
} }
function getGroups() function getGroups()
{ {
// TODO: ordering of child categories etc // TODO: ordering of child categories etc
$groups = array(); $groups = array();
$result = $this->dbh->query("SELECT id, title, parent_cat $result = $this->dbh->query("SELECT id, title, parent_cat
FROM ttrss_feed_categories FROM ttrss_feed_categories
WHERE owner_uid = '" . db_escape_string($_SESSION["uid"]) . "' WHERE owner_uid = '" . db_escape_string($_SESSION["uid"]) . "'
ORDER BY order_id ASC"); ORDER BY order_id ASC");
$groupsToGroups = array(); $groupsToGroups = array();
$groupsToTitle = array(); $groupsToTitle = array();
while ($line = $this->dbh->fetch_assoc($result)) while ($line = $this->dbh->fetch_assoc($result))
{ {
if ($line["parent_cat"] === NULL) if ($line["parent_cat"] === NULL)
@@ -163,7 +176,7 @@ class FeverAPI extends Handler {
{ {
$groupsToGroups[-1] = array(); $groupsToGroups[-1] = array();
} }
array_push($groupsToGroups[-1], $line["order_id"] . "-" . $line["id"]); array_push($groupsToGroups[-1], $line["order_id"] . "-" . $line["id"]);
} }
else else
@@ -172,84 +185,84 @@ class FeverAPI extends Handler {
{ {
$groupsToGroups[$line["parent_cat"]] = array(); $groupsToGroups[$line["parent_cat"]] = array();
} }
array_push($groupsToGroups[$line["parent_cat"]], $line["order_id"] . "-" . $line["id"]); array_push($groupsToGroups[$line["parent_cat"]], $line["order_id"] . "-" . $line["id"]);
} }
$groupsToTitle[$line["id"]] = $line["title"]; $groupsToTitle[$line["id"]] = $line["title"];
} }
foreach ($groupsToGroups as $key => $value) foreach ($groupsToGroups as $key => $value)
{ {
sort($value); sort($value);
} }
if (isset($groupsToGroups[-1])) if (isset($groupsToGroups[-1]))
$this->flattenGroups($groupsToGroups, $groups, $groupsToTitle, -1); $this->flattenGroups($groupsToGroups, $groups, $groupsToTitle, -1);
return $groups; return $groups;
} }
function getFeeds() function getFeeds()
{ {
$feeds = array(); $feeds = array();
$result = $this->dbh->query("SELECT id, title, feed_url, site_url, last_updated $result = $this->dbh->query("SELECT id, title, feed_url, site_url, last_updated
FROM ttrss_feeds FROM ttrss_feeds
WHERE owner_uid = '" . db_escape_string($_SESSION["uid"]) . "' WHERE owner_uid = '" . db_escape_string($_SESSION["uid"]) . "'
ORDER BY order_id ASC"); ORDER BY order_id ASC");
while ($line = $this->dbh->fetch_assoc($result)) while ($line = $this->dbh->fetch_assoc($result))
{ {
array_push($feeds, array("id" => $line["id"], array_push($feeds, array("id" => intval($line["id"]),
"favicon_id" => $line["id"], "favicon_id" => intval($line["id"]),
"title" => $line["title"], "title" => $line["title"],
"url" => $line["feed_url"], "url" => $line["feed_url"],
"site_url" => $line["site_url"], "site_url" => $line["site_url"],
"is_spark" => 0, // unsported "is_spark" => 0, // unsported
"last_updated_on_time" => strtotime($line["last_updated"]) "last_updated_on_time" => strtotime($line["last_updated"])
)); ));
} }
return $feeds; return $feeds;
} }
function getFavicons() function getFavicons()
{ {
$favicons = array(); $favicons = array();
$result = $this->dbh->query("SELECT id $result = $this->dbh->query("SELECT id
FROM ttrss_feeds FROM ttrss_feeds
WHERE owner_uid = '" . db_escape_string($_SESSION["uid"]) . "' WHERE owner_uid = '" . db_escape_string($_SESSION["uid"]) . "'
ORDER BY order_id ASC"); ORDER BY order_id ASC");
// data = "image/gif;base64,<base64 encoded image> // data = "image/gif;base64,<base64 encoded image>
while ($line = $this->dbh->fetch_assoc($result)) while ($line = $this->dbh->fetch_assoc($result))
{ {
$filename = "feed-icons/" . $line["id"] . ".ico"; $filename = "feed-icons/" . $line["id"] . ".ico";
if (file_exists($filename)) if (file_exists($filename))
{ {
array_push($favicons, array("id" => $line["id"], array_push($favicons, array("id" => intval($line["id"]),
"data" => image_type_to_mime_type(exif_imagetype($filename)) . ";base64," . base64_encode(file_get_contents($filename)) "data" => image_type_to_mime_type(exif_imagetype($filename)) . ";base64," . base64_encode(file_get_contents($filename))
)); ));
} }
} }
return $favicons; return $favicons;
} }
function getLinks() function getLinks()
{ {
// TODO: is there a 'hot links' alternative in ttrss? // TODO: is there a 'hot links' alternative in ttrss?
$links = array(); $links = array();
return $links; return $links;
} }
function getItems() function getItems()
{ {
// items from specific groups, feeds // items from specific groups, feeds
$items = array(); $items = array();
$item_limit = 50; $item_limit = 50;
$where = " owner_uid = '" . db_escape_string($_SESSION["uid"]) . "' AND ref_id = id "; $where = " owner_uid = '" . db_escape_string($_SESSION["uid"]) . "' AND ref_id = id ";
@@ -280,16 +293,16 @@ class FeverAPI extends Handler {
$feeds_in_group_result = $this->dbh->query("SELECT id $feeds_in_group_result = $this->dbh->query("SELECT id
FROM ttrss_feeds FROM ttrss_feeds
WHERE owner_uid = '" . db_escape_string($_SESSION["uid"]) . "' " . $groups_query); WHERE owner_uid = '" . db_escape_string($_SESSION["uid"]) . "' " . $groups_query);
$group_feed_ids = array(); $group_feed_ids = array();
while ($line = $this->dbh->fetch_assoc($feeds_in_group_result)) while ($line = $this->dbh->fetch_assoc($feeds_in_group_result))
{ {
array_push($group_feed_ids, $line["id"]); array_push($group_feed_ids, $line["id"]);
} }
$feed_ids = array_unique(array_merge($feed_ids, $group_feed_ids)); $feed_ids = array_unique(array_merge($feed_ids, $group_feed_ids));
} }
$query = " feed_id IN ("; $query = " feed_id IN (";
$num_feed_ids = sizeof($feed_ids); $num_feed_ids = sizeof($feed_ids);
foreach ($feed_ids as $feed_id) foreach ($feed_ids as $feed_id)
@@ -299,16 +312,16 @@ class FeverAPI extends Handler {
else else
$num_feed_ids--; $num_feed_ids--;
} }
if ($num_feed_ids <= 0) if ($num_feed_ids <= 0)
$query = " feed_id IN ('') "; $query = " feed_id IN ('') ";
else else
$query = trim($query, ",") . ")"; $query = trim($query, ",") . ")";
if (!empty($where)) $where .= " AND "; if (!empty($where)) $where .= " AND ";
$where .= $query; $where .= $query;
} }
if (isset($_REQUEST["max_id"])) // descending from most recently added if (isset($_REQUEST["max_id"])) // descending from most recently added
{ {
// use the max_id argument to request the previous $item_limit items // use the max_id argument to request the previous $item_limit items
@@ -324,14 +337,14 @@ class FeverAPI extends Handler {
{ {
$where .= "1"; $where .= "1";
} }
$where .= " ORDER BY id DESC"; $where .= " ORDER BY id DESC";
} }
} }
else if (isset($_REQUEST["with_ids"])) // selective else if (isset($_REQUEST["with_ids"])) // selective
{ {
if (!empty($where)) $where .= " AND "; // group_ids & feed_ids don't make sense with this query but just in case if (!empty($where)) $where .= " AND "; // group_ids & feed_ids don't make sense with this query but just in case
$item_ids = explode(",", $_REQUEST["with_ids"]); $item_ids = explode(",", $_REQUEST["with_ids"]);
$query = "id IN ("; $query = "id IN (";
$num_ids = sizeof($item_ids); $num_ids = sizeof($item_ids);
@@ -342,12 +355,12 @@ class FeverAPI extends Handler {
else else
$num_ids--; $num_ids--;
} }
if ($num_ids <= 0) if ($num_ids <= 0)
$query = "id IN ('') "; $query = "id IN ('') ";
else else
$query = trim($query, ",") . ") "; $query = trim($query, ",") . ") ";
$where .= $query; $where .= $query;
} }
else // ascending from first added else // ascending from first added
@@ -360,7 +373,8 @@ class FeverAPI extends Handler {
if ($since_id) if ($since_id)
{ {
if (!empty($where)) $where .= " AND "; if (!empty($where)) $where .= " AND ";
$where .= "id > " . db_escape_string($since_id) . " "; //$where .= "id > " . db_escape_string($since_id) . " ";
$where .= "id > " . db_escape_string($since_id*1000) . " "; // NASTY hack for Mr. Reader 2.0 on iOS and TinyTiny RSS Fever
} }
else if (empty($where)) else if (empty($where))
{ {
@@ -370,116 +384,116 @@ class FeverAPI extends Handler {
$where .= " ORDER BY id ASC"; $where .= " ORDER BY id ASC";
} }
} }
$where .= " LIMIT " . $item_limit; $where .= " LIMIT " . $item_limit;
// id, feed_id, title, author, html, url, is_saved, is_read, created_on_time // id, feed_id, title, author, html, url, is_saved, is_read, created_on_time
$result = $this->dbh->query("SELECT ref_id, feed_id, title, link, content, id, marked, unread, author, date_entered $result = $this->dbh->query("SELECT ref_id, feed_id, title, link, content, id, marked, unread, author, updated
FROM ttrss_entries, ttrss_user_entries FROM ttrss_entries, ttrss_user_entries
WHERE " . $where); WHERE " . $where);
while ($line = $this->dbh->fetch_assoc($result)) while ($line = $this->dbh->fetch_assoc($result))
{ {
array_push($items, array("id" => $line["id"], array_push($items, array("id" => intval($line["id"]),
"feed_id" => $line["feed_id"], "feed_id" => intval($line["feed_id"]),
"title" => $line["title"], "title" => $line["title"],
"author" => $line["author"], "author" => $line["author"],
"html" => $line["content"], "html" => $line["content"],
"url" => $line["link"], "url" => $line["link"],
"is_saved" => (sql_bool_to_bool($line["marked"]) ? 1 : 0), "is_saved" => (sql_bool_to_bool($line["marked"]) ? 1 : 0),
"is_read" => ( (!sql_bool_to_bool($line["unread"])) ? 1 : 0), "is_read" => ( (!sql_bool_to_bool($line["unread"])) ? 1 : 0),
"created_on_time" => strtotime($line["date_entered"]) "created_on_time" => strtotime($line["updated"])
)); ));
} }
return $items; return $items;
} }
function getTotalItems() function getTotalItems()
{ {
// number of total items // number of total items
$total_items = 0; $total_items = 0;
$where = " owner_uid = '" . db_escape_string($_SESSION["uid"]) . "'"; $where = " owner_uid = '" . db_escape_string($_SESSION["uid"]) . "'";
$result = $this->dbh->query("SELECT COUNT(ref_id) as total_items $result = $this->dbh->query("SELECT COUNT(ref_id) as total_items
FROM ttrss_user_entries FROM ttrss_user_entries
WHERE " . $where); WHERE " . $where);
if ($this->dbh->num_rows($result) > 0) if ($this->dbh->num_rows($result) > 0)
{ {
$total_items = $this->dbh->fetch_result($result, 0, "total_items"); $total_items = $this->dbh->fetch_result($result, 0, "total_items");
} }
return $total_items; return $total_items;
} }
function getFeedsGroup() function getFeedsGroup()
{ {
$feeds_groups = array(); $feeds_groups = array();
$result = $this->dbh->query("SELECT id, cat_id $result = $this->dbh->query("SELECT id, cat_id
FROM ttrss_feeds FROM ttrss_feeds
WHERE owner_uid = '" . db_escape_string($_SESSION["uid"]) . "' WHERE owner_uid = '" . db_escape_string($_SESSION["uid"]) . "'
AND cat_id IS NOT NULL AND cat_id IS NOT NULL
ORDER BY id ASC"); ORDER BY id ASC");
$groupsToFeeds = array(); $groupsToFeeds = array();
while ($line = $this->dbh->fetch_assoc($result)) while ($line = $this->dbh->fetch_assoc($result))
{ {
if (!array_key_exists($line["cat_id"], $groupsToFeeds)) if (!array_key_exists($line["cat_id"], $groupsToFeeds))
$groupsToFeeds[$line["cat_id"]] = array(); $groupsToFeeds[$line["cat_id"]] = array();
array_push($groupsToFeeds[$line["cat_id"]], $line["id"]); array_push($groupsToFeeds[$line["cat_id"]], $line["id"]);
} }
foreach ($groupsToFeeds as $group => $feeds) foreach ($groupsToFeeds as $group => $feeds)
{ {
$feedsStr = ""; $feedsStr = "";
foreach ($feeds as $feed) foreach ($feeds as $feed)
$feedsStr .= $feed . ","; $feedsStr .= $feed . ",";
$feedsStr = trim($feedsStr, ","); $feedsStr = trim($feedsStr, ",");
array_push($feeds_groups, array("group_id" => $group, array_push($feeds_groups, array("group_id" => $group,
"feed_ids" => $feedsStr)); "feed_ids" => $feedsStr));
} }
return $feeds_groups; return $feeds_groups;
} }
function getUnreadItemIds() function getUnreadItemIds()
{ {
$unreadItemIdsCSV = ""; $unreadItemIdsCSV = "";
$result = $this->dbh->query("SELECT ref_id, unread $result = $this->dbh->query("SELECT ref_id, unread
FROM ttrss_user_entries FROM ttrss_user_entries
WHERE owner_uid = '" . db_escape_string($_SESSION["uid"]) . "'"); WHERE owner_uid = '" . db_escape_string($_SESSION["uid"]) . "'"); // ORDER BY red_id DESC
while ($line = $this->dbh->fetch_assoc($result)) while ($line = $this->dbh->fetch_assoc($result))
{ {
if (sql_bool_to_bool($line["unread"])) if (sql_bool_to_bool($line["unread"]))
$unreadItemIdsCSV .= $line["ref_id"] . ","; $unreadItemIdsCSV .= $line["ref_id"] . ",";
} }
$unreadItemIdsCSV = trim($unreadItemIdsCSV, ","); $unreadItemIdsCSV = trim($unreadItemIdsCSV, ",");
return $unreadItemIdsCSV; return $unreadItemIdsCSV;
} }
function getSavedItemIds() function getSavedItemIds()
{ {
$savedItemIdsCSV = ""; $savedItemIdsCSV = "";
$result = $this->dbh->query("SELECT ref_id, marked $result = $this->dbh->query("SELECT ref_id, marked
FROM ttrss_user_entries FROM ttrss_user_entries
WHERE owner_uid = '" . db_escape_string($_SESSION["uid"]) . "'"); WHERE owner_uid = '" . db_escape_string($_SESSION["uid"]) . "'");
while ($line = $this->dbh->fetch_assoc($result)) while ($line = $this->dbh->fetch_assoc($result))
{ {
if (sql_bool_to_bool($line["marked"])) if (sql_bool_to_bool($line["marked"]))
$savedItemIdsCSV .= $line["ref_id"] . ","; $savedItemIdsCSV .= $line["ref_id"] . ",";
} }
$savedItemIdsCSV = trim($savedItemIdsCSV, ","); $savedItemIdsCSV = trim($savedItemIdsCSV, ",");
return $savedItemIdsCSV; return $savedItemIdsCSV;
} }
function setItem($id, $field_raw, $mode, $before = 0) function setItem($id, $field_raw, $mode, $before = 0)
{ {
$field = ""; $field = "";
@@ -505,7 +519,7 @@ class FeverAPI extends Handler {
break; break;
} }
if ($field && $set_to) if ($field && $set_to)
{ {
$article_ids = db_escape_string($id); $article_ids = db_escape_string($id);
@@ -523,40 +537,40 @@ class FeverAPI extends Handler {
} }
} }
} }
function setItemAsRead($id) function setItemAsRead($id)
{ {
$this->setItem($id, 1, 0); $this->setItem($id, 1, 0);
} }
function setItemAsUnread($id) function setItemAsUnread($id)
{ {
$this->setItem($id, 1, 1); $this->setItem($id, 1, 1);
} }
function setItemAsSaved($id) function setItemAsSaved($id)
{ {
$this->setItem($id, 0, 1); $this->setItem($id, 0, 1);
} }
function setItemAsUnsaved($id) function setItemAsUnsaved($id)
{ {
$this->setItem($id, 0, 0); $this->setItem($id, 0, 0);
} }
function setFeed($id, $cat, $before=0) function setFeed($id, $cat, $before=0)
{ {
// if before is zero, set it to now so feeds all items are read from before this point in time // if before is zero, set it to now so feeds all items are read from before this point in time
if ($before == 0) if ($before == 0)
$before = time(); $before = time();
if (is_numeric($id)) if (is_numeric($id))
{ {
// this is a category // this is a category
if ($cat) if ($cat)
{ {
// if not special feed // if not special feed
if ($id > 0) if ($id > 0)
{ {
db_query("UPDATE ttrss_user_entries db_query("UPDATE ttrss_user_entries
SET unread = false, last_read = NOW() WHERE ref_id IN SET unread = false, last_read = NOW() WHERE ref_id IN
@@ -578,7 +592,7 @@ class FeverAPI extends Handler {
} }
} }
// not a category // not a category
else if ($id > 0) else if ($id > 0)
{ {
db_query("UPDATE ttrss_user_entries db_query("UPDATE ttrss_user_entries
SET unread = false, last_read = NOW() WHERE ref_id IN SET unread = false, last_read = NOW() WHERE ref_id IN
@@ -588,24 +602,24 @@ class FeverAPI extends Handler {
} }
ccache_update($id,$_SESSION["uid"], $cat); ccache_update($id,$_SESSION["uid"], $cat);
} }
} }
function setFeedAsRead($id, $before) function setFeedAsRead($id, $before)
{ {
$this->setFeed($id, false, $before); $this->setFeed($id, false, $before);
} }
function setGroupAsRead($id, $before) function setGroupAsRead($id, $before)
{ {
$this->setFeed($id, true, $before); $this->setFeed($id, true, $before);
} }
// this does all the processing, since the fever api does not have a specific variable that specifies the operation // this does all the processing, since the fever api does not have a specific variable that specifies the operation
function index() function index()
{ {
$response_arr = array(); $response_arr = array();
if (isset($_REQUEST["groups"])) if (isset($_REQUEST["groups"]))
{ {
$response_arr["groups"] = $this->getGroups(); $response_arr["groups"] = $this->getGroups();
@@ -638,14 +652,14 @@ class FeverAPI extends Handler {
{ {
$response_arr["saved_item_ids"] = $this->getSavedItemIds(); $response_arr["saved_item_ids"] = $this->getSavedItemIds();
} }
if (isset($_REQUEST["mark"], $_REQUEST["as"], $_REQUEST["id"])) if (isset($_REQUEST["mark"], $_REQUEST["as"], $_REQUEST["id"]))
{ {
if (is_numeric($_REQUEST["id"])) if (is_numeric($_REQUEST["id"]))
{ {
$before = (isset($_REQUEST["before"])) ? $_REQUEST["before"] : null; $before = (isset($_REQUEST["before"])) ? $_REQUEST["before"] : null;
$method_name = "set" . ucfirst($_REQUEST["mark"]) . "As" . ucfirst($_REQUEST["as"]); $method_name = "set" . ucfirst($_REQUEST["mark"]) . "As" . ucfirst($_REQUEST["as"]);
if (method_exists($this, $method_name)) if (method_exists($this, $method_name))
{ {
$id = intval($_REQUEST["id"]); $id = intval($_REQUEST["id"]);
@@ -665,25 +679,29 @@ class FeverAPI extends Handler {
} }
} }
} }
if ($_SESSION["uid"]) if ($_SESSION["uid"])
$this->wrap(self::STATUS_OK, $response_arr); $this->wrap(self::STATUS_OK, $response_arr);
else if (!$_SESSION["uid"]) else if (!$_SESSION["uid"])
$this->wrap(self::STATUS_ERR, NULL); $this->wrap(self::STATUS_ERR, NULL);
} }
// validate the api_key, user preferences // validate the api_key, user preferences
function before($method) { function before($method) {
if (parent::before($method)) { if (parent::before($method)) {
if (DEBUG==1) {
// add request to debug log
file_put_contents('./debug_fever.txt','parameter: '.json_encode($_REQUEST)."\n",FILE_APPEND);
}
// set the user from the db // set the user from the db
$this->setUser(); $this->setUser();
// are we xml or json? // are we xml or json?
$this->setXml(); $this->setXml();
if ($this->xml) if ($this->xml)
header("Content-Type: text/xml"); header("Content-Type: text/xml");
else else
header("Content-Type: text/json"); header("Content-Type: text/json");