-<?
+<?php
require "xmlrpc/lib/xmlrpc.inc";
require "xmlrpc/lib/xmlrpcs.inc";
- $xmlrpc_defencoding = "UTF8";
-
require_once "sanity_check.php";
require_once "config.php";
pg_query("set client_encoding = 'utf-8'");
}
+ function getVirtualFeeds($msg) {
+ global $link;
+
+ $error_code = 0;
+
+ $login_o = $msg->getParam(0);
+ $pass_o = $msg->getParam(1);
+
+ $login = $login_o->scalarval();
+ $pass = $pass_o->scalarval();
+
+ $user_id = authenticate_user($link, $login, $pass);
+
+ $counters_ret = array();
+
+ if (authenticate_user($link, $login, $pass)) {
+
+ $counters = getLabelCounters($link, false, true);
+
+ foreach (array_keys($counters) as $id) {
+ $line_struct = new xmlrpcval(
+ array(
+ "id" => new xmlrpcval($id, "int"),
+ "title" => new xmlrpcval($counters[$id]["description"]),
+ "unread" => new xmlrpcval($counters[$id]["counter"], "int")
+ ),
+ "struct");
+
+ array_push($counters_ret, $line_struct);
+ }
+
+ $reply = new xmlrpcval($counters_ret, "array");
+
+ } else {
+ $reply_msg = "Login failed.";
+ $error_code = 1;
+ }
+
+ if ($error_code != 0) {
+ return new xmlrpcresp(0, $error_code, $reply_msg);
+ } else {
+ return new xmlrpcresp($reply);
+ }
+
+ }
+
+ function getCategories($msg) {
+ global $link;
+
+ $login_o = $msg->getParam(0);
+ $pass_o = $msg->getParam(1);
+
+ $login = $login_o->scalarval();
+ $pass = $pass_o->scalarval();
+
+ $user_id = authenticate_user($link, $login, $pass);
+
+ $error_code = 0;
+
+ if (authenticate_user($link, $login, $pass)) {
+
+ $result = db_query($link, "SELECT
+ id, title FROM ttrss_feed_categories
+ WHERE owner_uid = " .
+ $_SESSION["uid"]);
+
+ $feeds = array();
+
+ while ($line = db_fetch_assoc($result)) {
+
+ $unread = getFeedUnread($link, $line["id"]);
+
+ $line_struct = new xmlrpcval(
+ array(
+ "title" => new xmlrpcval($line["title"]),
+ "id" => new xmlrpcval($line["id"], "int")
+ ),
+ "struct");
+
+ array_push($feeds, $line_struct);
+ }
+
+ $reply = new xmlrpcval($feeds, "array");
+
+ } else {
+ $reply = "Login failed.";
+ $error_code = 1;
+ }
+
+ if ($error_code != 0) {
+ return new xmlrpcresp(0, $error_code, $reply_msg);
+ } else {
+ return new xmlrpcresp($reply);
+ }
+
+ }
+
+ function getTotalUnread($msg) {
+ global $link;
+
+ $error_code = 0;
+
+ $login_o = $msg->getParam(0);
+ $pass_o = $msg->getParam(1);
+
+ $login = $login_o->scalarval();
+ $pass = $pass_o->scalarval();
+
+ $user_id = authenticate_user($link, $login, $pass);
+
+
+ if (authenticate_user($link, $login, $pass)) {
+
+ $reply_msg = getGlobalUnread($link);
+
+ } else {
+ $reply_msg = "Login failed.";
+ $error_code = 1;
+ }
+
+ if ($error_code != 0) {
+ return new xmlrpcresp(0, $error_code, $reply_msg);
+ } else {
+ return new xmlrpcresp(new xmlrpcval($reply_msg));
+ }
+
+ }
+
+ function getVersion() {
+ return new xmlrpcval(VERSION);
+ }
+
function getSubscribedFeeds($msg) {
global $link;
if (authenticate_user($link, $login, $pass)) {
$result = db_query($link, "SELECT
- id, feed_url, title, SUBSTRING(last_updated,1,19) AS last_updated
+ id, feed_url, cat_id, title, SUBSTRING(last_updated,1,19) AS last_updated
FROM ttrss_feeds WHERE owner_uid = " .
$_SESSION["uid"]);
$feeds = array();
while ($line = db_fetch_assoc($result)) {
+
+ $unread = getFeedUnread($link, $line["id"]);
$line_struct = new xmlrpcval(
array(
"feed_url" => new xmlrpcval($line["feed_url"]),
"title" => new xmlrpcval($line["title"]),
"id" => new xmlrpcval($line["id"], "int"),
+ "unread" => new xmlrpcval($unread, "int"),
+ "cat_id" => new xmlrpcval($line["cat_id"], "int"),
"last_updated" => new xmlrpcval(strtotime($line["last_updated"]), "int")
),
"struct");
if (authenticate_user($link, $login, $pass)) {
- if ($limit > 0) {
- $limit_query_part = "LIMIT $limit";
- }
-
if ($filter == 1) {
- $query_strategy_part = "unread = true";
+ $view_mode = "unread";
} else if ($filter == 2) {
- $query_strategy_part = "marked = true";
- } else {
- $query_strategy_part = "ttrss_entries.id > 0";
+ $view_mode = "marked";
+ } else if ($filter == 3) {
+ $view_mode = "adaptive";
}
+
+ $cat_view = false;
+ $search = "";
+ $search_mode = "";
+ $match_on = "";
+
+ $qfh_ret = queryFeedHeadlines($link, $feed_id, $limit,
+ $view_mode, $cat_view, $search, $search_mode, $match_on);
- $query = "SELECT
- ttrss_entries.id,ttrss_entries.title,
- SUBSTRING(updated,1,16) as updated,
- unread,feed_id,marked,link,last_read,
- SUBSTRING(last_read,1,19) as last_read_noms,
- SUBSTRING(updated,1,19) as updated_noms
- FROM
- ttrss_entries,ttrss_user_entries,ttrss_feeds
- WHERE
- ttrss_feeds.id = '$feed_id' AND
- ttrss_user_entries.feed_id = ttrss_feeds.id AND
- ttrss_user_entries.ref_id = ttrss_entries.id AND
- ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
- $query_strategy_part ORDER BY updated
- $limit_query_part";
-
- $result = db_query($link, $query);
-
+ $result = $qfh_ret[0];
+ $feed_title = $qfh_ret[1];
+
$articles = array();
while ($line = db_fetch_assoc($result)) {
+ $is_updated = ($line["last_read"] == "" && ($line["unread"] != "t" && $line["unread"] != "1"));
- $line_struct = new xmlrpcval(
- array(
+ $headline_items = array(
"id" => new xmlrpcval($line["id"], "int"),
"unread" => new xmlrpcval(sql_bool_to_bool($line["unread"]), "boolean"),
"marked" => new xmlrpcval(sql_bool_to_bool($line["marked"]), "boolean"),
"updated" => new xmlrpcval(strtotime($line["updated"]), "int"),
+ "is_updated" => new xmlrpcval($is_updated, "boolean"),
+
"title" => new xmlrpcval($line["title"])
- ),
+ );
+
+ if ($feed_id < 0) {
+ $headline_items["feed_id"] = new xmlrpcval($line["feed_id"], "int");
+ }
+
+ $line_struct = new xmlrpcval($headline_items,
"struct");
array_push($articles, $line_struct);
-
}
- $reply = new xmlrpcval($articles, "array");
+ $reply = new xmlrpcval(
+ array(
+ "title" => new xmlrpcval($feed_title),
+ "headlines" => new xmlrpcval($articles, "array")
+ ),
+ "struct");
} else {
$reply_msg = "Login failed.";
$setArticleUnread_sig = array(array($xmlrpcString,
$xmlrpcString, $xmlrpcString, $xmlrpcInt, $xmlrpcInt));
+ $getVersion_sig = array(array($xmlrpcString));
+
+ $getTotalUnread_sig = array(array($xmlrpcInt, $xmlrpcString,
+ $xmlrpcString));
+
+ $getCategories_sig = array(array($xmlrpcString,
+ $xmlrpcString, $xmlrpcString));
+
+ $getVirtualFeeds_sig = array(array($xmlrpcInt, $xmlrpcString,
+ $xmlrpcString));
+
$s = new xmlrpc_server(
array(
+ "rss.getVirtualFeeds" => array("function" => "getVirtualFeeds",
+ "signature" => $getVirtualFeeds_sig),
+ "rss.getCategories" => array("function" => "getCategories",
+ "signature" => $getCategories_sig),
+ "rss.getTotalUnread" => array("function" => "getTotalUnread",
+ "signature" => $getTotalUnread_sig),
+ "rss.getVersion" => array("function" => "getVersion",
+ "signature" => $getVersion_sig),
"rss.setArticleRead" => array("function" => "setArticleRead",
"signature" => $setArticleRead_sig),
"rss.setArticleMarked" => array("function" => "setArticleMarked",
"rss.getSubscribedFeeds" => array("function" => "getSubscribedFeeds",
"signature" => $getSubscribedFeeds_sig),
"rss.subscribeToFeed" => array("function" => "subscribeToFeed",
- "signature" => $subscribeToFeed_sig))
+ "signature" => $subscribeToFeed_sig)), 0
);
+ $s->response_charset_encoding = "UTF-8";
+ $s->service();
?>