]> git.wh0rd.org Git - tt-rss.git/commitdiff
implement pubsubhubbub subscriber (update schema)
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Fri, 1 Apr 2011 09:39:58 +0000 (13:39 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Fri, 1 Apr 2011 09:55:39 +0000 (13:55 +0400)
backend.php
config.php-dist
functions.php
modules/backend-rpc.php
sanity_config.php
schema/ttrss_schema_mysql.sql
schema/ttrss_schema_pgsql.sql
schema/versions/mysql/83.sql
schema/versions/pgsql/83.sql

index fd5ad6e7d5587f0e24a2d6c6aa15715ab66d4d3d..d62b2db2d3e95a26573766ee6daf10839b9f735c 100644 (file)
@@ -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)));
                        }
                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);
index e9ea0a67aa43e61a56ee8298bb83e6ddc227c2e8..8b01aeb898c23e4fe5e4e736442de2d2f18aa9de 100644 (file)
        define('MAGPIE_CACHE_DIR', 'cache/magpie');
        // Local cache directory for RSS feeds
 
-       define('MAGPIE_CACHE_AGE', 60*30); 
-       // How long to store cached RSS objects? In seconds.
-       // Defaults to 30 minutes
-
        define('ICONS_DIR', "icons");
        define('ICONS_URL', "icons");
        // Local and URL path to the directory, where feed favicons are stored.
index 1e843dd1441ff07ae2c4d7fa3ca83448a571c6c5..5adf46cdf2f868379b5fef7b8c30607ce2fd5c56 100644 (file)
@@ -99,7 +99,6 @@
 
        //define('MAGPIE_USER_AGENT_EXT', ' (Tiny Tiny RSS/' . VERSION . ')');
        define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
-       define('MAGPIE_CACHE_AGE', 60*15); // 15 minutes
 
        define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . VERSION . ' (http://tt-rss.org/)');
        define('MAGPIE_USER_AGENT', SELF_USER_AGENT);
        require_once 'lib/magpierss/rss_utils.inc';
        require_once 'lib/htmlpurifier/library/HTMLPurifier.auto.php';
        require_once 'lib/pubsubhubbub/publisher.php';
+       require_once 'lib/pubsubhubbub/subscriber.php';
 
        $config = HTMLPurifier_Config::createDefault();
 
                }
        }
 
-       function update_rss_feed($link, $feed, $ignore_daemon = false) {
+       function update_rss_feed($link, $feed, $ignore_daemon = false, $no_cache = false) {
 
                global $memcache;
 
                                WHERE   f2.feed_url = f1.feed_url AND f2.id = '$feed'");
 
                        while ($line = db_fetch_assoc($result)) {
-                               update_rss_feed_real($link, $line["id"], $ignore_daemon);
+                               update_rss_feed_real($link, $line["id"], $ignore_daemon, $no_cache);
                        }
                } else {
-                       update_rss_feed_real($link, $feed, $ignore_daemon);
+                       update_rss_feed_real($link, $feed, $ignore_daemon, $no_cache);
                }
        }
 
-       function update_rss_feed_real($link, $feed, $ignore_daemon = false) {
+       function update_rss_feed_real($link, $feed, $ignore_daemon = false, $no_cache = false) {
 
                global $memcache;
 
 
                        $result = db_query($link, "SELECT id,update_interval,auth_login,
                                feed_url,auth_pass,cache_images,update_method,last_updated,
-                               mark_unread_on_update, owner_uid, update_on_checksum_change
+                               mark_unread_on_update, owner_uid, update_on_checksum_change,
+                               pubsub_state
                                FROM ttrss_feeds WHERE id = '$feed'");
 
                }
                        0, "mark_unread_on_update"));
                $update_on_checksum_change = sql_bool_to_bool(db_fetch_result($result,
                        0, "update_on_checksum_change"));
+               $pubsub_state = db_fetch_result($result, 0, "pubsub_state");
 
                db_query($link, "UPDATE ttrss_feeds SET last_update_started = NOW()
                        WHERE id = '$feed'");
 
                        if ($update_method == 3) {
                                $rss = fetch_twitter_rss($link, $fetch_url, $owner_uid);
-                                       } else if ($update_method == 1) {
+                       } else if ($update_method == 1) {
+
+                               define('MAGPIE_CACHE_AGE', get_feed_update_interval($link, $feed) * 60);
+                               define('MAGPIE_CACHE_ON', !$no_cache);
+
                                $rss = @fetch_rss($fetch_url);
                        } else {
                                if (!is_dir(SIMPLEPIE_CACHE_DIR)) {
                                                get_feed_update_interval($link, $feed)*60);
                                }
 
-                               if (is_dir(SIMPLEPIE_CACHE_DIR)) {
+                               $rss->enable_cache(!$no_cache);
+
+                               if (!$no_cache) {
                                        $rss->set_cache_location(SIMPLEPIE_CACHE_DIR);
                                        $rss->set_cache_duration(get_feed_update_interval($link, $feed) * 60);
                                }
 
                        $filters = load_filters($link, $feed, $owner_uid);
 
-                       if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
+                       if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug'] == 2) {
                                print_r($filters);
                        }
 
                                return; // no articles
                        }
 
+                       if (PUBSUBHUBBUB_HUB && $pubsub_state != 2) {
+
+                               $feed_hub_url = false;
+                               if ($use_simplepie) {
+                                       $links = $rss->get_links('hub');
+
+                                       foreach ($links as $l) {
+                                               $feed_hub_url = $l;
+                                               break;
+                                       }
+
+                               } else {
+                                       $atom = $rss->channel['atom'];
+
+                                       if ($atom) {
+                                               if ($atom['link@rel'] == 'hub') {
+                                                       $feed_hub_url = $atom['link@href'];
+                                               }
+
+                                               if (!$feed_hub_url && $atom['link#'] > 1) {
+                                                       for ($i = 2; $i <= $atom['link#']; $i++) {
+                                                               if ($atom["link#$i@rel"] == 'hub') {
+                                                                       $feed_hub_url = $atom["link#$i@href"];
+                                                               }
+                                                       }
+                                               }
+                                       } else {
+                                               $feed_hub_url = $rss->channel['link_hub'];
+                                       }
+                               }
+
+                               if ($feed_hub_url) {
+                                       $callback_url = get_self_url_prefix() .
+                                               "/backend.php?op=pubsub&id=$feed";
+
+                                       $s = new Subscriber($feed_hub_url, $callback_url);
+
+                                       $s->subscribe($fetch_url);
+
+                                       db_query($link, "UPDATE ttrss_feeds SET pubsub_state = 1
+                                               WHERE id = '$feed'");
+                               }
+                       }
+
                        if (defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']) {
                                _debug("update_rss_feed: processing articles...");
                        }
 
                                $content = $tmhOAuth->response['response'];
 
+                               define('MAGPIE_CACHE_ON', false);
+
                                $rss = new MagpieRSS($content, MAGPIE_OUTPUT_ENCODING,
                                        MAGPIE_INPUT_ENCODING, MAGPIE_DETECT_ENCODING );
 
index abb04ab4683ea2c2719c576bb3ef902afa980f17..4f2ba252f1399d627767dd988b212f9a7cd28fb8 100644 (file)
                        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 "<message>UPDATE_COUNTERS</message>";
-                       print "</rpc-reply>";
-
                        return;
                } */
 
index fb51ffa0075f3aa7eabeadf9f21c2f30fde3289c..22598d3d9e51849972ac0ebbac949a324af867ed 100644 (file)
@@ -1,3 +1,3 @@
-<?php # This file has been generated at:  Fri Apr 1 09:34:52 MSD 2011
+<?php # This file has been generated at:  Fri Apr 1 13:36:01 MSD 2011
 define('GENERATED_CONFIG_CHECK', 22);
-$requred_defines = array( 'DB_TYPE', 'DB_HOST', 'DB_USER', 'DB_NAME', 'DB_PASS', 'MAGPIE_FETCH_TIME_OUT', 'MAGPIE_CACHE_DIR', 'MAGPIE_CACHE_AGE', 'ICONS_DIR', 'ICONS_URL', 'SINGLE_USER_MODE', 'TMP_DIRECTORY', 'ENABLE_UPDATE_DAEMON', 'DAEMON_SLEEP_INTERVAL', 'DATABASE_BACKED_SESSIONS', 'SESSION_CHECK_ADDRESS', 'SESSION_COOKIE_LIFETIME', 'SESSION_EXPIRE_TIME', 'DAEMON_UPDATE_LOGIN_LIMIT', 'CHECK_FOR_NEW_VERSION', 'DIGEST_ENABLE', 'DIGEST_EMAIL_LIMIT', 'DAEMON_SENDS_DIGESTS', 'MYSQL_CHARSET', 'DEFAULT_UPDATE_METHOD', 'SIMPLEPIE_CACHE_DIR', 'SIMPLEPIE_CACHE_IMAGES', 'COUNTERS_MAX_AGE', 'DIGEST_FROM_NAME', 'DIGEST_FROM_ADDRESS', 'DIGEST_SUBJECT', 'DIGEST_SMTP_HOST', 'DIGEST_SMTP_LOGIN', 'DIGEST_SMTP_PASSWORD', 'DAEMON_FEED_LIMIT', 'ALLOW_REMOTE_USER_AUTH', 'AUTO_LOGIN', 'LOCK_DIRECTORY', 'ENABLE_GZIP_OUTPUT', 'PHP_EXECUTABLE', 'ENABLE_REGISTRATION', 'REG_NOTIFY_ADDRESS', 'REG_MAX_USERS', 'FEEDBACK_URL', 'FORCE_ARTICLE_PURGE', 'SPHINX_ENABLED', 'SPHINX_INDEX', 'ENABLE_TWEET_BUTTON', 'CONSUMER_KEY', 'CONSUMER_SECRET', 'ISCONFIGURED', 'PUBSUBHUBBUB_HUB', 'CONFIG_VERSION'); ?>
+$requred_defines = array( 'DB_TYPE', 'DB_HOST', 'DB_USER', 'DB_NAME', 'DB_PASS', 'MAGPIE_FETCH_TIME_OUT', 'MAGPIE_CACHE_DIR', 'ICONS_DIR', 'ICONS_URL', 'SINGLE_USER_MODE', 'TMP_DIRECTORY', 'ENABLE_UPDATE_DAEMON', 'DAEMON_SLEEP_INTERVAL', 'DATABASE_BACKED_SESSIONS', 'SESSION_CHECK_ADDRESS', 'SESSION_COOKIE_LIFETIME', 'SESSION_EXPIRE_TIME', 'DAEMON_UPDATE_LOGIN_LIMIT', 'CHECK_FOR_NEW_VERSION', 'DIGEST_ENABLE', 'DIGEST_EMAIL_LIMIT', 'DAEMON_SENDS_DIGESTS', 'MYSQL_CHARSET', 'DEFAULT_UPDATE_METHOD', 'SIMPLEPIE_CACHE_DIR', 'SIMPLEPIE_CACHE_IMAGES', 'COUNTERS_MAX_AGE', 'DIGEST_FROM_NAME', 'DIGEST_FROM_ADDRESS', 'DIGEST_SUBJECT', 'DIGEST_SMTP_HOST', 'DIGEST_SMTP_LOGIN', 'DIGEST_SMTP_PASSWORD', 'DAEMON_FEED_LIMIT', 'ALLOW_REMOTE_USER_AUTH', 'AUTO_LOGIN', 'LOCK_DIRECTORY', 'ENABLE_GZIP_OUTPUT', 'PHP_EXECUTABLE', 'ENABLE_REGISTRATION', 'REG_NOTIFY_ADDRESS', 'REG_MAX_USERS', 'FEEDBACK_URL', 'FORCE_ARTICLE_PURGE', 'SPHINX_ENABLED', 'SPHINX_INDEX', 'ENABLE_TWEET_BUTTON', 'CONSUMER_KEY', 'CONSUMER_SECRET', 'PUBSUBHUBBUB_HUB', 'ISCONFIGURED', 'CONFIG_VERSION'); ?>
index 46e08dea450f36fee6d3e850d679d89ae919cf1d..4b528f946402725a9f129a1b09476ae54a7745c1 100644 (file)
@@ -125,6 +125,7 @@ create table ttrss_feeds (id integer not null auto_increment primary key,
        mark_unread_on_update boolean not null default false,
        update_on_checksum_change boolean not null default false,
        strip_images boolean not null default false,
+       pubsub_state integer not null default 0,
        index(owner_uid),
        foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE,
        index(cat_id),
index 8d87663d5ccad0bb2ce757facdb164e252537707..bb870703cc0a0e0f172ef9ffc25da6f80ba4e602 100644 (file)
@@ -88,6 +88,7 @@ create table ttrss_feeds (id serial not null primary key,
        mark_unread_on_update boolean not null default false,
        update_on_checksum_change boolean not null default false,
        strip_images boolean not null default false,
+       pubsub_state integer not null default 0,
        auth_pass_encrypted boolean not null default false);    
 
 create index ttrss_feeds_owner_uid_index on ttrss_feeds(owner_uid);
index b86091532ba3b4a9c8ad6446fabe8c02746c45af..6457539a1ed9cdffb08fe290f099e99a7a9fd56b 100644 (file)
@@ -19,6 +19,11 @@ DELETE FROM ttrss_user_prefs WHERE pref_name IN ('HIDE_FEEDLIST', 'SYNC_COUNTERS
 
 DELETE FROM ttrss_prefs WHERE pref_name IN ('HIDE_FEEDLIST', 'SYNC_COUNTERS', 'ENABLE_LABELS', 'ENABLE_SEARCH_TOOLBAR', 'ENABLE_FEED_ICONS', 'ENABLE_OFFLINE_READING', 'EXTENDED_FEEDLIST', 'OPEN_LINKS_IN_NEW_WINDOW', 'ENABLE_FLASH_PLAYER', 'HEADLINES_SMART_DATE', 'MARK_UNREAD_ON_UPDATE', 'UPDATE_POST_ON_CHECKSUM_CHANGE');
 
+alter table ttrss_feeds add column pubsub_state integer;
+update ttrss_feeds set pubsub_state = 0;
+alter table ttrss_feeds change pubsub_state pubsub_state integer not null;
+alter table ttrss_feeds alter column pubsub_state set default 0;
+
 update ttrss_version set schema_version = 83;
 
 commit;
index 12ffb17332241758025e143f0f2318370b0a7794..c622f81372602939c95de4219b57210afd9f1893 100644 (file)
@@ -19,6 +19,11 @@ DELETE FROM ttrss_user_prefs WHERE pref_name IN ('HIDE_FEEDLIST', 'SYNC_COUNTERS
 
 DELETE FROM ttrss_prefs WHERE pref_name IN ('HIDE_FEEDLIST', 'SYNC_COUNTERS', 'ENABLE_LABELS', 'ENABLE_SEARCH_TOOLBAR', 'ENABLE_FEED_ICONS', 'ENABLE_OFFLINE_READING', 'EXTENDED_FEEDLIST', 'OPEN_LINKS_IN_NEW_WINDOW', 'ENABLE_FLASH_PLAYER', 'HEADLINES_SMART_DATE', 'MARK_UNREAD_ON_UPDATE', 'UPDATE_POST_ON_CHECKSUM_CHANGE');
 
+alter table ttrss_feeds add column pubsub_state integer;
+update ttrss_feeds set pubsub_state = 0;
+alter table ttrss_feeds alter column pubsub_state set not null;
+alter table ttrss_feeds alter column pubsub_state set default 0;
+
 update ttrss_version set schema_version = 83;
 
 commit;