function handle_rpc_request($link) {
$subop = $_REQUEST["subop"];
+ $seq = (int) $_REQUEST["seq"];
+ // Silent
if ($subop == "setprofile") {
$id = db_escape_string($_REQUEST["id"]);
return;
}
+ // Silent
if ($subop == "remprofiles") {
- $ids = split(",", db_escape_string(trim($_REQUEST["ids"])));
+ $ids = explode(",", db_escape_string(trim($_REQUEST["ids"])));
foreach ($ids as $id) {
if ($_SESSION["profile"] != $id) {
return;
}
+ // Silent
if ($subop == "addprofile") {
$title = db_escape_string(trim($_REQUEST["title"]));
if ($title) {
db_query($link, "INSERT INTO ttrss_settings_profiles (title, owner_uid)
VALUES ('$title', ".$_SESSION["uid"] .")");
-
+
$result = db_query($link, "SELECT id FROM ttrss_settings_profiles WHERE
title = '$title'");
-
+
if (db_num_rows($result) != 0) {
$profile_id = db_fetch_result($result, 0, "id");
-
+
if ($profile_id) {
- initialize_user_prefs($link, $_SESSION["uid"], $profile_id);
+ initialize_user_prefs($link, $_SESSION["uid"], $profile_id);
}
}
}
return;
}
+ // Silent
if ($subop == "saveprofile") {
$id = db_escape_string($_REQUEST["id"]);
$title = db_escape_string(trim($_REQUEST["value"]));
}
db_query($link, "COMMIT");
- }
+ }
return;
}
+ // Silent
if ($subop == "remarchive") {
- $ids = split(",", db_escape_string($_REQUEST["ids"]));
-
- print "<rpc-reply>";
+ $ids = explode(",", db_escape_string($_REQUEST["ids"]));
foreach ($ids as $id) {
$result = db_query($link, "DELETE FROM ttrss_archived_feeds WHERE
- (SELECT COUNT(*) FROM ttrss_user_entries
+ (SELECT COUNT(*) FROM ttrss_user_entries
WHERE orig_feed_id = '$id') = 0 AND
id = '$id' AND owner_uid = ".$_SESSION["uid"]);
$rc = db_affected_rows($link, $result);
-
- print "<feed id='$id' rc='$rc'/>";
-
}
-
- print "</rpc-reply>";
-
return;
}
if ($subop == "addfeed") {
-
$feed = db_escape_string($_REQUEST['feed']);
$cat = db_escape_string($_REQUEST['cat']);
$login = db_escape_string($_REQUEST['login']);
$rc = subscribe_to_feed($link, $feed, $cat, $login, $pass);
- print "<rpc-reply>";
- print "<result code='$rc'/>";
- print "</rpc-reply>";
+ print json_encode(array("result" => $rc));
return;
}
- if ($subop == "togglepref") {
- print "<rpc-reply>";
+ if ($subop == "extractfeedurls") {
- $key = db_escape_string($_REQUEST["key"]);
+ $urls = get_feeds_from_html($_REQUEST['url']);
- set_pref($link, $key, !get_pref($link, $key));
+ print json_encode(array("urls" => $urls));
+ return;
+ }
+ if ($subop == "togglepref") {
+ $key = db_escape_string($_REQUEST["key"]);
+ set_pref($link, $key, !get_pref($link, $key));
$value = get_pref($link, $key);
- print "<param-set key=\"$key\" value=\"$value\"/>";
-
- print "</rpc-reply>";
-
+ print json_encode(array("param" =>$key, "value" => $value));
return;
}
if ($subop == "setpref") {
- print "<rpc-reply>";
+ $value = str_replace("\n", "<br/>", $_REQUEST['value']);
$key = db_escape_string($_REQUEST["key"]);
- $value = db_escape_string($_REQUEST["value"]);
+ $value = db_escape_string($value);
set_pref($link, $key, $value);
- print "<param-set key=\"$key\" value=\"$value\"/>";
-
- print "</rpc-reply>";
-
- return;
- }
-
- if ($subop == "getAllCounters") {
- print "<rpc-reply>";
- print "<counters>";
-
- $omode = $_REQUEST["omode"];
-
- getAllCounters($link, $omode);
- print "</counters>";
- print_runtime_info($link);
- print "</rpc-reply>";
-
+ print json_encode(array("param" =>$key, "value" => $value));
return;
}
$mark = "false";
}
- // FIXME this needs collision testing
-
$result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
- print "<rpc-reply><counters>";
- getGlobalCounters($link);
- getVirtCounters($link);
- getLabelCounters($link);
- if (get_pref($link, 'ENABLE_FEED_CATS')) {
- getCategoryCounters($link);
- }
- print "</counters></rpc-reply>";
-
+ print json_encode(array("message" => "UPDATE_COUNTERS"));
return;
}
if ($subop == "delete") {
$ids = db_escape_string($_REQUEST["ids"]);
- $result = db_query($link, "DELETE FROM ttrss_user_entries
+ $result = db_query($link, "DELETE FROM ttrss_user_entries
WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
- print "<rpc-reply><counters>";
- getGlobalCounters($link);
- getVirtCounters($link);
- if (get_pref($link, 'ENABLE_FEED_CATS')) {
- getCategoryCounters($link);
- }
- print "</counters></rpc-reply>";
-
+ print json_encode(array("message" => "UPDATE_COUNTERS"));
return;
}
if ($subop == "unarchive") {
$ids = db_escape_string($_REQUEST["ids"]);
- $result = db_query($link, "UPDATE ttrss_user_entries
+ $result = db_query($link, "UPDATE ttrss_user_entries
SET feed_id = orig_feed_id, orig_feed_id = NULL
WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]);
- print "<rpc-reply><counters>";
- getGlobalCounters($link);
- getVirtCounters($link);
- if (get_pref($link, 'ENABLE_FEED_CATS')) {
- getCategoryCounters($link);
- }
- print "</counters></rpc-reply>";
-
+ print json_encode(array("message" => "UPDATE_COUNTERS"));
return;
}
if ($subop == "archive") {
- $ids = split(",", db_escape_string($_REQUEST["ids"]));
+ $ids = explode(",", db_escape_string($_REQUEST["ids"]));
foreach ($ids as $id) {
archive_article($link, $id, $_SESSION["uid"]);
}
- print "<rpc-reply><counters>";
- getGlobalCounters($link);
- getVirtCounters($link);
- if (get_pref($link, 'ENABLE_FEED_CATS')) {
- getCategoryCounters($link);
- }
- print "</counters></rpc-reply>";
-
+ print json_encode(array("message" => "UPDATE_COUNTERS"));
return;
}
-
if ($subop == "publ") {
$pub = $_REQUEST["pub"];
$id = db_escape_string($_REQUEST["id"]);
$pub = "false";
}
- if ($note != 'undefined') {
- $note_qpart = "note = '$note',";
- }
-
- // FIXME this needs collision testing
-
- $result = db_query($link, "UPDATE ttrss_user_entries SET
- $note_qpart
+ $result = db_query($link, "UPDATE ttrss_user_entries SET
published = $pub
WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
+ $pubsub_result = false;
- print "<rpc-reply>";
-
- print "<counters>";
- getGlobalCounters($link);
- getVirtCounters($link);
- getLabelCounters($link);
- if (get_pref($link, 'ENABLE_FEED_CATS')) {
- getCategoryCounters($link);
- }
- print "</counters>";
+ if (PUBSUBHUBBUB_HUB) {
+ $rss_link = get_self_url_prefix() .
+ "/backend.php?op=rss&id=-2&key=" .
+ get_feed_access_key($link, -2, false);
- if ($note != 'undefined') {
- $note_size = strlen($note);
- print "<note id=\"$id\" size=\"$note_size\">";
- print "<![CDATA[" . format_article_note($id, $note) . "]]>";
- print "</note>";
- }
+ $p = new Publisher(PUBSUBHUBBUB_HUB);
- print "</rpc-reply>";
+ $pubsub_result = $p->publish_update($rss_link);
+ }
+ print json_encode(array("message" => "UPDATE_COUNTERS",
+ "pubsub_result" => $pubsub_result));
return;
}
- if ($subop == "updateFeed") {
+ // Silent
+ /* if ($subop == "update") {
$feed_id = db_escape_string($_REQUEST["feed"]);
-
update_rss_feed($link, $feed_id);
-
- print "<rpc-reply>";
- print "<counters>";
- getFeedCounter($link, $feed_id);
- print "</counters>";
- print "</rpc-reply>";
-
return;
- }
-
- if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
-
- $global_unread_caller = sprintf("%d", $_REQUEST["uctr"]);
- $global_unread = getGlobalUnread($link);
-
- print "<rpc-reply>";
-
- print "<counters>";
-
- if ($global_unread_caller != $global_unread) {
-
- $omode = $_REQUEST["omode"];
-
- if (!$omode) $omode = "tflc";
+ } */
- getVirtCounters($link);
+ if ($subop == "updateAllFeeds" || $subop == "getAllCounters") {
+ $last_article_id = (int) $_REQUEST["last_article_id"];
- if (strchr($omode, "l")) getLabelCounters($link);
+ $reply = array();
- if (strchr($omode, "c")) {
- if (get_pref($link, 'ENABLE_FEED_CATS')) {
- getCategoryCounters($link);
- }
- }
+ if ($seq) $reply['seq'] = $seq;
- if (strchr($omode, "f")) getFeedCounters($link);
- if (strchr($omode, "t")) getTagCounters($link);
+ if ($last_article_id != getLastArticleId($link)) {
+ $omode = $_REQUEST["omode"];
- getGlobalCounters($link, $global_unread);
+ if ($omode != "T")
+ $reply['counters'] = getAllCounters($link, $omode);
+ else
+ $reply['counters'] = getGlobalCounters($link);
}
-
- print "</counters>";
- print_runtime_info($link);
+ $reply['runtime-info'] = make_runtime_info($link);
- print "</rpc-reply>";
+ print json_encode($reply);
return;
}
/* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
if ($subop == "catchupSelected") {
-
- $ids = split(",", db_escape_string($_REQUEST["ids"]));
+ $ids = explode(",", db_escape_string($_REQUEST["ids"]));
$cmode = sprintf("%d", $_REQUEST["cmode"]);
catchupArticlesById($link, $ids, $cmode);
- print "<rpc-reply>";
- print "<counters>";
- getAllCounters($link, $_REQUEST["omode"]);
- print "</counters>";
- print_runtime_info($link);
- print "</rpc-reply>";
-
+ print json_encode(array("message" => "UPDATE_COUNTERS"));
return;
}
if ($subop == "markSelected") {
-
- $ids = split(",", db_escape_string($_REQUEST["ids"]));
+ $ids = explode(",", db_escape_string($_REQUEST["ids"]));
$cmode = sprintf("%d", $_REQUEST["cmode"]);
markArticlesById($link, $ids, $cmode);
- print "<rpc-reply>";
- print "<counters>";
- getAllCounters($link, $_REQUEST["omode"]);
- print "</counters>";
- print_runtime_info($link);
- print "</rpc-reply>";
-
+ print json_encode(array("message" => "UPDATE_COUNTERS"));
return;
}
if ($subop == "publishSelected") {
-
- $ids = split(",", db_escape_string($_REQUEST["ids"]));
+ $ids = explode(",", db_escape_string($_REQUEST["ids"]));
$cmode = sprintf("%d", $_REQUEST["cmode"]);
publishArticlesById($link, $ids, $cmode);
- print "<rpc-reply>";
- print "<counters>";
- getAllCounters($link, $_REQUEST["omode"]);
- print "</counters>";
- print_runtime_info($link);
- print "</rpc-reply>";
-
+ print json_encode(array("message" => "UPDATE_COUNTERS"));
return;
}
if ($subop == "sanityCheck") {
- print "<rpc-reply>";
- if (sanity_check($link)) {
- print "<error error-code=\"0\"/>";
- print_init_params($link);
- print_runtime_info($link);
+ $_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true";
- # assign client-passed params to session
- $_SESSION["client.userAgent"] = $_REQUEST["ua"];
+ $reply = array();
+ $reply['error'] = sanity_check($link);
+
+ if ($reply['error']['code'] == 0) {
+ $reply['init-params'] = make_init_params($link);
+ $reply['runtime-info'] = make_runtime_info($link);
}
- print "</rpc-reply>";
+ print json_encode($reply);
return;
- }
+ }
- if ($subop == "globalPurge") {
+/* if ($subop == "globalPurge") {
print "<rpc-reply>";
global_purge_old_posts($link, true);
print "</rpc-reply>";
return;
- }
-
- if ($subop == "getArticleLink") {
-
- $id = db_escape_string($_REQUEST["id"]);
-
- $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries
- WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."'");
-
- if (db_num_rows($result) == 1) {
- $link = htmlspecialchars(strip_tags(db_fetch_result($result, 0, "link")));
- print "<rpc-reply><link>$link</link><id>$id</id></rpc-reply>";
- } else {
- print "<rpc-reply><error>Article not found</error></rpc-reply>";
- }
-
- return;
- }
+ } */
if ($subop == "setArticleTags") {
-
global $memcache;
$id = db_escape_string($_REQUEST["id"]);
$tags_str = db_escape_string($_REQUEST["tags_str"]);
-
- $tags = array_unique(trim_array(split(",", $tags_str)));
+ $tags = array_unique(trim_array(explode(",", $tags_str)));
db_query($link, "BEGIN");
if (db_num_rows($result) == 1) {
+ $tags_to_cache = array();
+
$int_id = db_fetch_result($result, 0, "int_id");
- db_query($link, "DELETE FROM ttrss_tags WHERE
+ db_query($link, "DELETE FROM ttrss_tags WHERE
post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'");
foreach ($tags as $tag) {
- $tag = sanitize_tag($tag);
+ $tag = sanitize_tag($tag);
if (!tag_is_valid($tag)) {
continue;
}
// print "<!-- $id : $int_id : $tag -->";
-
+
if ($tag != '') {
- db_query($link, "INSERT INTO ttrss_tags
+ db_query($link, "INSERT INTO ttrss_tags
(post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')");
}
+
+ array_push($tags_to_cache, $tag);
}
+
+ /* update tag cache */
+
+ sort($tags_to_cache);
+ $tags_str = join(",", $tags_to_cache);
+
+ db_query($link, "UPDATE ttrss_user_entries
+ SET tag_cache = '$tags_str' WHERE ref_id = '$id'
+ AND owner_uid = " . $_SESSION["uid"]);
}
db_query($link, "COMMIT");
$memcache->delete($obj_id);
}
- $tags_str = format_tags_string(get_article_tags($link, $id), $id);
+ $tags = get_article_tags($link, $id);
+ $tags_str = format_tags_string($tags, $id);
+ $tags_str_full = join(", ", $tags);
- print "<rpc-reply>
- <tags-str id=\"$id\"><![CDATA[$tags_str]]></tags-str>
- </rpc-reply>";
+ if (!$tags_str_full) $tags_str_full = __("no tags");
+
+ print json_encode(array("tags_str" => array("id" => $id,
+ "content" => $tags_str, "content_full" => $tags_str_full)));
return;
}
- if ($subop == "regenPubKey") {
+ if ($subop == "regenOPMLKey") {
+ update_feed_access_key($link, 'OPML:Publish',
+ false, $_SESSION["uid"]);
- print "<rpc-reply>";
+ $new_link = opml_publish_url($link);
- set_pref($link, "_PREFS_PUBLISH_KEY", generate_publish_key(), $_SESSION["uid"]);
-
- $new_link = article_publish_url($link);
-
- print "<link><![CDATA[$new_link]]></link>";
-
- print "</rpc-reply>";
-
- return;
- }
-
- if ($subop == "logout") {
- logout_user();
- print_error_xml(6);
+ print json_encode(array("link" => $new_link));
return;
}
if ($subop == "completeTags") {
-
$search = db_escape_string($_REQUEST["search"]);
- $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags
+ $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags
WHERE owner_uid = '".$_SESSION["uid"]."' AND
tag_name LIKE '$search%' ORDER BY tag_name
LIMIT 10");
}
if ($subop == "purge") {
- $ids = split(",", db_escape_string($_REQUEST["ids"]));
+ $ids = explode(",", db_escape_string($_REQUEST["ids"]));
$days = sprintf("%d", $_REQUEST["days"]);
- print "<rpc-reply>";
-
- print "<message><![CDATA[";
-
foreach ($ids as $id) {
$result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
id = '$id' AND owner_uid = ".$_SESSION["uid"]);
if (db_num_rows($result) == 1) {
- purge_feed($link, $id, $days, true);
+ purge_feed($link, $id, $days);
}
}
- print "]]></message>";
-
- print "</rpc-reply>";
-
return;
}
} */
if ($subop == "getArticles") {
- $ids = split(",", db_escape_string($_REQUEST["ids"]));
-
- print "<rpc-reply>";
+ $ids = explode(",", db_escape_string($_REQUEST["ids"]));
+ $articles = array();
foreach ($ids as $id) {
if ($id) {
- outputArticleXML($link, $id, 0, false);
+ array_push($articles, format_article($link, $id, 0, false));
}
}
- print "</rpc-reply>";
+ print json_encode($articles);
return;
}
if ($subop == "checkDate") {
-
$date = db_escape_string($_REQUEST["date"]);
$date_parsed = strtotime($date);
- print "<rpc-reply>";
-
- if ($date_parsed) {
- print "<result>1</result>";
- } else {
- print "<result>0</result>";
- }
-
- print "</rpc-reply>";
-
+ print json_encode(array("result" => (bool)$date_parsed,
+ "date" => date("c", $date_parsed)));
return;
}
- if ($subop == "removeFromLabel") {
+ if ($subop == "assignToLabel" || $subop == "removeFromLabel") {
+ $reply = array();
- $ids = split(",", db_escape_string($_REQUEST["ids"]));
+ $ids = explode(",", db_escape_string($_REQUEST["ids"]));
$label_id = db_escape_string($_REQUEST["lid"]);
- $label = db_escape_string(label_find_caption($link, $label_id,
+ $label = db_escape_string(label_find_caption($link, $label_id,
$_SESSION["uid"]));
- print "<rpc-reply>";
- print "<info-for-headlines>";
+ $reply["info-for-headlines"] = array();
if ($label) {
foreach ($ids as $id) {
- label_remove_article($link, $id, $label, $_SESSION["uid"]);
- print "<entry id=\"$id\"><![CDATA[";
+ if ($subop == "assignToLabel")
+ label_add_article($link, $id, $label, $_SESSION["uid"]);
+ else
+ label_remove_article($link, $id, $label, $_SESSION["uid"]);
$labels = get_article_labels($link, $id, $_SESSION["uid"]);
- print format_article_labels($labels, $id);
- print "]]></entry>";
+ array_push($reply["info-for-headlines"],
+ array("id" => $id, "labels" => format_article_labels($labels, $id)));
}
}
- print "</info-for-headlines>";
+ $reply["message"] = "UPDATE_COUNTERS";
- print "<counters>";
- getAllCounters($link, $omode);
- print "</counters>";
- print "</rpc-reply>";
+ print json_encode($reply);
return;
}
- if ($subop == "assignToLabel") {
-
- $ids = split(",", db_escape_string($_REQUEST["ids"]));
- $label_id = db_escape_string($_REQUEST["lid"]);
+ if ($subop == "updateFeedBrowser") {
+ $search = db_escape_string($_REQUEST["search"]);
+ $limit = db_escape_string($_REQUEST["limit"]);
+ $mode = (int) db_escape_string($_REQUEST["mode"]);
- $label = db_escape_string(label_find_caption($link, $label_id,
- $_SESSION["uid"]));
+ print json_encode(array("content" =>
+ make_feed_browser($link, $search, $limit, $mode),
+ "mode" => $mode));
+ return;
+ }
- print "<rpc-reply>";
+ // Silent
+ if ($subop == "massSubscribe") {
- print "<info-for-headlines>";
+ $payload = json_decode($_REQUEST["payload"], false);
+ $mode = $_REQUEST["mode"];
- if ($label) {
+ if (!$payload || !is_array($payload)) return;
- foreach ($ids as $id) {
- label_add_article($link, $id, $label, $_SESSION["uid"]);
+ if ($mode == 1) {
+ foreach ($payload as $feed) {
- print "<entry id=\"$id\"><![CDATA[";
+ $title = db_escape_string($feed[0]);
+ $feed_url = db_escape_string($feed[1]);
- $labels = get_article_labels($link, $id, $_SESSION["uid"]);
- print format_article_labels($labels, $id);
+ $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
+ feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
- print "]]></entry>";
+ if (db_num_rows($result) == 0) {
+ $result = db_query($link, "INSERT INTO ttrss_feeds
+ (owner_uid,feed_url,title,cat_id,site_url)
+ VALUES ('".$_SESSION["uid"]."',
+ '$feed_url', '$title', NULL, '')");
+ }
+ }
+ } else if ($mode == 2) {
+ // feed archive
+ foreach ($payload as $id) {
+ $result = db_query($link, "SELECT * FROM ttrss_archived_feeds
+ WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
+ if (db_num_rows($result) != 0) {
+ $site_url = db_escape_string(db_fetch_result($result, 0, "site_url"));
+ $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
+ $title = db_escape_string(db_fetch_result($result, 0, "title"));
+
+ $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
+ feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
+
+ if (db_num_rows($result) == 0) {
+ $result = db_query($link, "INSERT INTO ttrss_feeds
+ (owner_uid,feed_url,title,cat_id,site_url)
+ VALUES ('$id','".$_SESSION["uid"]."',
+ '$feed_url', '$title', NULL, '$site_url')");
+ }
+ }
}
}
- print "</info-for-headlines>";
-
- print "<counters>";
- getAllCounters($link, $omode);
- print "</counters>";
- print "</rpc-reply>";
-
- return;
- }
-
- if ($subop == "updateFeedBrowser") {
-
- $search = db_escape_string($_REQUEST["search"]);
- $limit = db_escape_string($_REQUEST["limit"]);
- $mode = db_escape_string($_REQUEST["mode"]);
-
- print "<rpc-reply>";
- print "<content>";
- print "<![CDATA[";
- $ctr = print_feed_browser($link, $search, $limit, $mode);
- print "]]>";
- print "</content>";
- print "<num-results value=\"$ctr\"/>";
- print "<mode value=\"$mode\"/>";
- print "</rpc-reply>";
-
- return;
- }
-
-
- if ($subop == "massSubscribe") {
-
- $ids = split(",", db_escape_string($_REQUEST["ids"]));
- $mode = $_REQUEST["mode"];
+/* $ids = explode(",", db_escape_string($_REQUEST["ids"]));
$subscribed = array();
$orig_id = db_escape_string(db_fetch_result($result, 0, "id"));
$site_url = db_escape_string(db_fetch_result($result, 0, "site_url"));
}
-
+
$feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
$title = db_escape_string(db_fetch_result($result, 0, "title"));
-
+
$title_orig = db_fetch_result($result, 0, "title");
-
+
$result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
-
- if (db_num_rows($result) == 0) {
+
+ if (db_num_rows($result) == 0) {
if ($mode == 1) {
$result = db_query($link,
- "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
+ "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
} else if ($mode == 2) {
$result = db_query($link,
- "INSERT INTO ttrss_feeds (id,owner_uid,feed_url,title,cat_id,site_url)
+ "INSERT INTO ttrss_feeds (id,owner_uid,feed_url,title,cat_id,site_url)
VALUES ('$orig_id','".$_SESSION["uid"]."', '$feed_url', '$title', NULL, '$site_url')");
}
array_push($subscribed, $title_orig);
}
- }
+ } */
- $num_feeds = count($subscribed);
+ return;
+ }
- print "<rpc-reply>";
- print "<num-feeds value='$num_feeds'/>";
- print "</rpc-reply>";
+ if ($subop == "digest-get-contents") {
+ $article_id = db_escape_string($_REQUEST['article_id']);
+ $result = db_query($link, "SELECT content
+ FROM ttrss_entries, ttrss_user_entries
+ WHERE id = '$article_id' AND ref_id = id AND owner_uid = ".$_SESSION['uid']);
+
+ $content = sanitize_rss($link, db_fetch_result($result, 0, "content"));
+
+ print json_encode(array("article" =>
+ array("id" => $id, "content" => $content)));
return;
- }
+ }
- if ($subop == "download") {
- $stage = (int) $_REQUEST["stage"];
- $cidt = (int)db_escape_string($_REQUEST["cidt"]);
- $cidb = (int)db_escape_string($_REQUEST["cidb"]);
- $sync = db_escape_string($_REQUEST["sync"]);
- //$amount = (int) $_REQUEST["amount"];
- //$unread_only = db_escape_string($_REQUEST["unread_only"]);
- //if (!$amount) $amount = 50;
+ if ($subop == "digest-update") {
+ $feed_id = db_escape_string($_REQUEST['feed_id']);
+ $offset = db_escape_string($_REQUEST['offset']);
+ $seq = db_escape_string($_REQUEST['seq']);
- /* Amount is not used by the frontend offline.js anymore, it goes by
- * date_qpart below + cidb/cidt IDs */
+ if (!$feed_id) $feed_id = -4;
+ if (!$offset) $offset = 0;
- $amount = 2000;
- $unread_only = true;
+ $reply = array();
- print "<rpc-reply>";
+ $reply['seq'] = $seq;
- $sync = split(";", $sync);
+ $headlines = api_get_headlines($link, $feed_id, 10, $offset,
+ '', ($feed_id == -4), true, false, "unread", "updated DESC");
- print "<sync>";
+ //function api_get_headlines($link, $feed_id, $limit, $offset,
+ // $filter, $is_cat, $show_excerpt, $show_content, $view_mode) {
- if (count($sync) > 0) {
- if (strtotime($sync[0])) {
- $last_online = db_escape_string($sync[0]);
+ $reply['headlines'] = array();
+ $reply['headlines']['title'] = getFeedTitle($link, $feed_id);
+ $reply['headlines']['content'] = $headlines;
- print "<sync-point><![CDATA[$last_online]]></sync-point>";
-
- for ($i = 1; $i < count($sync); $i++) {
- $e = split(",", $sync[$i]);
+ print json_encode($reply);
+ return;
+ }
- if (count($e) == 3) {
+ if ($subop == "digest-init") {
+ $tmp_feeds = api_get_feeds($link, -3, true, false, 0);
- $id = (int) $e[0];
- $unread = bool_to_sql_bool((bool) $e[1]);
- $marked = (bool)$e[2];
+ $feeds = array();
- if ($marked) {
- $marked = bool_to_sql_bool($marked);
- $marked_qpart = "marked = $marked,";
- }
+ foreach ($tmp_feeds as $f) {
+ if ($f['id'] > 0 || $f['id'] == -4) array_push($feeds, $f);
+ }
- $query = "UPDATE ttrss_user_entries SET
- $marked_qpart
- unread = $unread,
- last_read = '$last_online'
- WHERE ref_id = '$id' AND
- (last_read IS NULL OR last_read < '$last_online') AND
- owner_uid = ".$_SESSION["uid"];
+ print json_encode(array("feeds" => $feeds));
- $result = db_query($link, $query);
+ return;
+ }
- print "<sync-ok id=\"$id\"/>";
+ if ($subop == "catchupFeed") {
+ $feed_id = db_escape_string($_REQUEST['feed_id']);
+ $is_cat = db_escape_string($_REQUEST['is_cat']);
- }
- }
+ catchup_feed($link, $feed_id, $is_cat);
- /* Maybe we need to further update local DB for this client */
+ return;
+ }
- $query = "SELECT ref_id,unread,marked FROM ttrss_user_entries
- WHERE last_read >= '$last_online' AND
- owner_uid = ".$_SESSION["uid"] . " LIMIT 1000";
+ if ($subop == "sendEmail") {
+ $secretkey = $_REQUEST['secretkey'];
- $result = db_query($link, $query);
+ $reply = array();
- while ($line = db_fetch_assoc($result)) {
- $unread = (int) sql_bool_to_bool($line["unread"]);
- $marked = (int) sql_bool_to_bool($line["marked"]);
+ if (DIGEST_ENABLE && $_SESSION['email_secretkey'] &&
+ $secretkey == $_SESSION['email_secretkey']) {
- print "<sync-ok unread=\"$unread\" marked=\"$marked\"
- id=\"".$line["ref_id"]."\"/>";
- }
+ $_SESSION['email_secretkey'] = '';
- }
- }
+ $destination = $_REQUEST['destination'];
+ $subject = $_REQUEST['subject'];
+ $content = $_REQUEST['content'];
- print "</sync>";
+ $replyto = strip_tags($_SESSION['email_replyto']);
+ $fromname = strip_tags($_SESSION['email_fromname']);
- if ($stage == 0) {
- print "<feeds>";
+ $mail = new PHPMailer();
- $result = db_query($link, "SELECT id, title, cat_id FROM
- ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
+ $mail->PluginDir = "lib/phpmailer/";
+ $mail->SetLanguage("en", "lib/phpmailer/language/");
- while ($line = db_fetch_assoc($result)) {
+ $mail->CharSet = "UTF-8";
- $has_icon = (int) feed_has_icon($line["id"]);
+ $mail->From = $replyto;
+ $mail->FromName = $fromname;
+ $mail->AddAddress($destination);
- print "<feed has_icon=\"$has_icon\"
- cat_id=\"".(int)$line["cat_id"]."\" id=\"".$line["id"]."\"><![CDATA[";
- print $line["title"];
- print "]]></feed>";
+ if (DIGEST_SMTP_HOST) {
+ $mail->Host = DIGEST_SMTP_HOST;
+ $mail->Mailer = "smtp";
+ $mail->SMTPAuth = DIGEST_SMTP_LOGIN != '';
+ $mail->Username = DIGEST_SMTP_LOGIN;
+ $mail->Password = DIGEST_SMTP_PASSWORD;
}
- print "</feeds>";
+ $mail->IsHTML(false);
+ $mail->Subject = $subject;
+ $mail->Body = $content;
- print "<feed-categories>";
+ $rc = $mail->Send();
- $result = db_query($link, "SELECT id, title, collapsed FROM
- ttrss_feed_categories WHERE owner_uid = ".$_SESSION["uid"]);
+ if (!$rc) {
+ $reply['error'] = $mail->ErrorInfo;
+ } else {
+ save_email_address($link, db_escape_string($destination));
+ $reply['message'] = "UPDATE_COUNTERS";
+ }
- print "<category id=\"0\" collapsed=\"".
- (int)get_pref($link, "_COLLAPSED_UNCAT")."\"><![CDATA[";
- print __("Uncategorized");
- print "]]></category>";
+ } else {
+ $reply['error'] = "Not authorized.";
+ }
- print "<category id=\"-1\" collapsed=\"".
- (int)get_pref($link, "_COLLAPSED_SPECIAL")."\"><![CDATA[";
- print __("Special");
- print "]]></category>";
+ print json_encode($reply);
+ return;
+ }
- print "<category id=\"-2\" collapsed=\"".
- (int)get_pref($link, "_COLLAPSED_LABELS")."\"><![CDATA[";
- print __("Labels");
- print "]]></category>";
+ if ($subop == "completeEmails") {
+ $search = db_escape_string($_REQUEST["search"]);
- while ($line = db_fetch_assoc($result)) {
- print "<category
- id=\"".$line["id"]."\"
- collapsed=\"".(int)sql_bool_to_bool($line["collapsed"])."\"><![CDATA[";
- print $line["title"];
- print "]]></category>";
- }
+ print "<ul>";
- print "</feed-categories>";
+ foreach ($_SESSION['stored_emails'] as $email) {
+ if (strpos($email, $search) !== false) {
+ print "<li>$email</li>";
+ }
+ }
- print "<labels>";
+ print "</ul>";
- $result = db_query($link, "SELECT * FROM
- ttrss_labels2 WHERE owner_uid = ".$_SESSION["uid"]);
+ return;
+ }
- while ($line = db_fetch_assoc($result)) {
- print "<label
- id=\"".$line["id"]."\"
- fg_color=\"".$line["fg_color"]."\"
- bg_color=\"".$line["bg_color"]."\"
- ><![CDATA[";
- print $line["caption"];
- print "]]></label>";
- }
+ if ($subop == "quickAddCat") {
+ $cat = db_escape_string($_REQUEST["cat"]);
+ add_feed_category($link, $cat);
- print "</labels>";
+ $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE
+ title = '$cat' AND owner_uid = " . $_SESSION["uid"]);
+ if (db_num_rows($result) == 1) {
+ $id = db_fetch_result($result, 0, "id");
+ } else {
+ $id = 0;
}
- if ($stage > 0) {
- print "<articles>";
+ print_feed_cat_select($link, "cat_id", $id);
+
+ return;
+ }
- $limit = 10;
- $skip = $limit*($stage-1);
+ if ($subop == "regenFeedKey") {
+ $feed_id = db_escape_string($_REQUEST['id']);
+ $is_cat = (bool) db_escape_string($_REQUEST['is_cat']);
- print "<limit value=\"$limit\"/>";
+ $new_key = update_feed_access_key($link, $feed_id, $is_cat);
- if ($amount > 0) $amount -= $skip;
+ print json_encode(array("link" => $new_key));
+ return;
+ }
- if ($amount > 0) {
+ // Silent
+ if ($subop == "clearKeys") {
+ db_query($link, "DELETE FROM ttrss_access_keys WHERE
+ owner_uid = " . $_SESSION["uid"]);
- $limit = min($limit, $amount);
+ return;
+ }
- if ($unread_only) {
- $unread_qpart = "(unread = true OR marked = true) AND ";
- }
+ if ($subop == "verifyRegexp") {
+ $reg_exp = $_REQUEST["reg_exp"];
- if ($cidt && $cidb) {
- $cid_qpart = "(ttrss_entries.id > $cidt OR ttrss_entries.id < $cidb) AND ";
- }
+ $status = @preg_match("/$reg_exp/i", "TEST") !== false;
- if (DB_TYPE == "pgsql") {
- $date_qpart = "updated >= NOW() - INTERVAL '1 week' AND";
- } else {
- $date_qpart = "updated >= DATE_SUB(NOW(), INTERVAL 1 WEEK) AND";
- }
-
- $result = db_query($link,
- "SELECT DISTINCT ttrss_entries.id,ttrss_entries.title,
- guid,link,comments,
- feed_id,content,updated,unread,marked FROM
- ttrss_user_entries,ttrss_entries,ttrss_feeds
- WHERE $unread_qpart $cid_qpart $date_qpart
- ttrss_feeds.id = feed_id AND
- ref_id = ttrss_entries.id AND
- ttrss_user_entries.owner_uid = ".$_SESSION["uid"]."
- ORDER BY updated DESC LIMIT $limit OFFSET $skip");
-
- if (function_exists('json_encode')) {
-
- while ($line = db_fetch_assoc($result)) {
- print "<article><![CDATA[";
-
- $line["marked"] = (int)sql_bool_to_bool($line["marked"]);
- $line["unread"] = (int)sql_bool_to_bool($line["unread"]);
-
- $line["labels"] = get_article_labels($link, $line["id"]);
-
-// too slow :(
-// $line["tags"] = format_tags_string(
-// get_article_tags($link, $line["id"]), $line["id"]);
-
- print json_encode($line);
- print "]]></article>";
- }
- }
+ print json_encode(array("status" => $status));
+ return;
+ }
+
+ // TODO: unify with digest-get-contents?
+ if ($subop == "cdmGetArticle") {
+ $id = db_escape_string($_REQUEST["id"]);
+ $result = db_query($link, "SELECT content,
+ ttrss_feeds.site_url AS site_url FROM ttrss_user_entries, ttrss_feeds,
+ ttrss_entries
+ WHERE feed_id = ttrss_feeds.id AND ref_id = '$id' AND
+ ttrss_entries.id = ref_id AND
+ ttrss_user_entries.owner_uid = ".$_SESSION["uid"]);
+
+ if (db_num_rows($result) != 0) {
+ $line = db_fetch_assoc($result);
+
+ $article_content = sanitize_rss($link, $line["content"],
+ false, false, $line['site_url']);
+
+ } else {
+ $article_content = '';
+ }
+
+ print json_encode(array("article" =>
+ array("id" => $id, "content" => $article_content)));
+
+ return;
+ }
+
+ if ($subop == "scheduleFeedUpdate") {
+ $feed_id = db_escape_string($_REQUEST["id"]);
+ $is_cat = db_escape_string($_REQUEST['is_cat']) == 'true';
+
+ $message = __("Your request could not be completed.");
+
+ if ($feed_id >= 0) {
+ if (!$is_cat) {
+ $message = __("Feed update has been scheduled.");
+
+ db_query($link, "UPDATE ttrss_feeds SET
+ last_update_started = '1970-01-01',
+ last_updated = '1970-01-01' WHERE id = '$feed_id' AND
+ owner_uid = ".$_SESSION["uid"]);
+
+ } else {
+ $message = __("Category update has been scheduled.");
+
+ if ($feed_id)
+ $cat_query = "cat_id = '$feed_id'";
+ else
+ $cat_query = "cat_id IS NULL";
+
+ db_query($link, "UPDATE ttrss_feeds SET
+ last_update_started = '1970-01-01',
+ last_updated = '1970-01-01' WHERE $cat_query AND
+ owner_uid = ".$_SESSION["uid"]);
}
+ } else {
+ $message = __("Can't update this kind of feed.");
+ }
- print "</articles>";
+ print json_encode(array("message" => $message));
+ return;
+ }
+ if ($subop == "getTweetInfo") {
+ $id = db_escape_string($_REQUEST['id']);
+
+ $result = db_query($link, "SELECT title, link
+ FROM ttrss_entries, ttrss_user_entries
+ WHERE id = '$id' AND ref_id = id AND owner_uid = " .$_SESSION['uid']);
+
+ if (db_num_rows($result) != 0) {
+ $title = truncate_string(strip_tags(db_fetch_result($result, 0, 'title')),
+ 100, '...');
+ $article_link = db_fetch_result($result, 0, 'link');
}
- print "</rpc-reply>";
+ print json_encode(array("title" => $title, "link" => $article_link,
+ "id" => $id));
+
+ return;
+ }
+
+ if ($subop == "setNote") {
+ $id = db_escape_string($_REQUEST["id"]);
+ $note = trim(strip_tags(db_escape_string($_REQUEST["note"])));
+
+ db_query($link, "UPDATE ttrss_user_entries SET note = '$note'
+ WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
+
+ $formatted_note = format_article_note($id, $note);
+
+ print json_encode(array("note" => $formatted_note,
+ "raw_length" => mb_strlen($note)));
+ return;
+ }
+
+ if ($subop == "genHash") {
+ $hash = sha1(uniqid(rand(), true));
+ print json_encode(array("hash" => $hash));
return;
}
- print "<rpc-reply><error>Unknown method: $subop</error></rpc-reply>";
+ print json_encode(array("error" => array("code" => 7,
+ "message" => "Unknown method: $subop")));
}
?>