summaryrefslogtreecommitdiff
path: root/backend.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2011-04-01 13:39:58 +0400
committerAndrew Dolgov <[email protected]>2011-04-01 13:55:39 +0400
commit5ab9791f34d395104b4857b0979ae9aa5c138878 (patch)
tree4a6d51e55bc2f4034d6409a3e59899e4a9ab471f /backend.php
parente2bcd11bb1f5427af08f97fe04afc63d73efce7e (diff)
implement pubsubhubbub subscriber (update schema)
Diffstat (limited to 'backend.php')
-rw-r--r--backend.php41
1 files changed, 39 insertions, 2 deletions
diff --git a/backend.php b/backend.php
index fd5ad6e7d..d62b2db2d 100644
--- a/backend.php
+++ b/backend.php
@@ -61,7 +61,8 @@
}
if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds" &&
- $op != "rss" && $op != "getUnread" && $op != "getProfiles") {
+ $op != "rss" && $op != "getUnread" && $op != "getProfiles" &&
+ $op != "pubsub") {
header("Content-Type: text/plain");
print json_encode(array("error" => array("code" => 6)));
@@ -524,8 +525,44 @@
}
break;
- } // Select action according to $op value.
+ case "pubsub":
+ $mode = db_escape_string($_REQUEST['hub_mode']);
+ $feed_id = db_escape_string($_REQUEST['id']);
+ $feed_url = db_escape_string($_REQUEST['hub_topic']);
+
+ // TODO: implement hub_verifytoken checking
+
+ $result = db_query($link, "SELECT feed_url FROM ttrss_feeds
+ WHERE id = '$feed_id'");
+
+ $check_feed_url = db_fetch_result($result, 0, "feed_url");
+
+ if ($check_feed_url && ($check_feed_url == $feed_url || !$feed_url)) {
+ if ($mode == "subscribe") {
+
+ db_query($link, "UPDATE ttrss_feeds SET pubsub_state = 2
+ WHERE id = '$feed_id'");
+
+ echo $_REQUEST['hub_challenge'];
+ } else if ($mode == "unsubscribe") {
+
+ db_query($link, "UPDATE ttrss_feeds SET pubsub_state = 0
+ WHERE id = '$feed_id'");
+
+ echo $_REQUEST['hub_challenge'];
+ } else if (!$mode) {
+ // Received update ping, schedule feed update.
+
+ update_rss_feed($link, $feed_id, true, true);
+
+ }
+ } else {
+ header('HTTP/1.0 404 Not Found');
+ }
+
+ break;
+ } // Select action according to $op value.
// We close the connection to database.
db_close($link);