]> git.wh0rd.org - tt-rss.git/commitdiff
add experimental support for pubsubhubbub in published feed, bump config version...
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Fri, 1 Apr 2011 05:36:29 +0000 (09:36 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Fri, 1 Apr 2011 05:36:29 +0000 (09:36 +0400)
config.php-dist
functions.php
lib/pubsubhubbub/README.txt [new file with mode: 0644]
lib/pubsubhubbub/publisher.php [new file with mode: 0644]
modules/backend-rpc.php
sanity_check.php
sanity_config.php

index 531ce20b325d02b8311f8db4c3785df7be7f6ef0..87429d1367257663940886ae95c64d79315f5143 100644 (file)
        // Please set this to true if you have read everything above and
        // finished setting configuration options.
 
-       define('CONFIG_VERSION', 21);
+       define('PUBSUBHUBBUB_HUB', '');
+       // URL to a PubSubHubbub-compatible hub server. If defined, Published
+       // articles generated feeds would automatically become PUSH-enabled.
+
+       define('CONFIG_VERSION', 22);
        // Expected config version. Please update this option in config.php
        // if necessary (after migrating all new options from this file).
 
index d33b30454d3aa797161b7337770605058dfff4bc..1e843dd1441ff07ae2c4d7fa3ca83448a571c6c5 100644 (file)
        require_once "lib/magpierss/rss_fetch.inc";
        require_once 'lib/magpierss/rss_utils.inc';
        require_once 'lib/htmlpurifier/library/HTMLPurifier.auto.php';
+       require_once 'lib/pubsubhubbub/publisher.php';
 
        $config = HTMLPurifier_Config::createDefault();
 
                $feed_site_url = $qfh_ret[2];
                $last_error = $qfh_ret[3];
 
-//             if (!$feed_site_url) $feed_site_url = "http://localhost/";
+               if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
 
                print "<?xml version=\"1.0\" encoding=\"utf-8\"?>
                        <?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\"?>
-                       <rss version=\"2.0\">
-                       <channel>
-                       <title>$feed_title</title>
+                       <rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
+                                 xmlns:atom=\"http://www.w3.org/2005/Atom\">
+                       <channel>";
+
+               if (PUBSUBHUBBUB_HUB && $feed == -2) {
+                       print "<atom:link rel='hub' href='".PUBSUBHUBBUB_HUB."'/>";
+               }
+
+               print "<title>$feed_title</title>
                        <link>$feed_site_url</link>
                        <description>Feed generated by Tiny Tiny RSS</description>";
 
                $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
                        "</option>";
 
+               if ($is_cat) $cat_q = "&is_cat=$is_cat";
+
                $rss_link = htmlspecialchars(get_self_url_prefix() .
-                       "/backend.php?op=rss&id=$feed_id&is_cat=$is_cat&view_mode=$view_mode$search_q");
+                       "/backend.php?op=rss&id=$feed_id$cat_q$search_q");
 
                $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";
 
diff --git a/lib/pubsubhubbub/README.txt b/lib/pubsubhubbub/README.txt
new file mode 100644 (file)
index 0000000..3d27c40
--- /dev/null
@@ -0,0 +1,21 @@
+This PHP library for PubSubHubbub was written by Josh Fraser (joshfraser.com) and is released under the Apache 2.0 License
+
+Usage:
+// specify which hub you want to use. in this case we'll use the demo hub on app engine.
+$hub_url = "http://pubsubhubbub.appspot.com/";
+
+// create a new pubsubhubbub publisher
+$p = new Publisher($hub_url);
+
+// specify the feed that has been updated
+$topic_url = "http://www.onlineaspect.com";
+
+// notify the hub that the specified topic_url (ATOM feed) has been updated
+// alternatively, publish_update() also accepts an array of topic urls
+if ($p->publish_update($topic_url)) {
+    echo "$topic_url was successfully published to $hub_url";
+} else {
+    echo "Ooops...";
+    print_r($p->last_response());
+}
\ No newline at end of file
diff --git a/lib/pubsubhubbub/publisher.php b/lib/pubsubhubbub/publisher.php
new file mode 100644 (file)
index 0000000..f176a9b
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+
+// a PHP client library for pubsubhubbub
+// as defined at http://code.google.com/p/pubsubhubbub/
+// written by Josh Fraser | joshfraser.com | josh@eventvue.com
+// Released under Apache License 2.0
+
+class Publisher {
+    
+    protected $hub_url;
+    protected $last_response;
+    
+    // create a new Publisher
+    public function __construct($hub_url) {
+        
+        if (!isset($hub_url))
+            throw new Exception('Please specify a hub url');
+        
+        if (!preg_match("|^https?://|i",$hub_url)) 
+            throw new Exception('The specified hub url does not appear to be valid: '.$hub_url);
+            
+        $this->hub_url = $hub_url;
+    }
+
+    // accepts either a single url or an array of urls
+    public function publish_update($topic_urls, $http_function = false) {
+        if (!isset($topic_urls))
+            throw new Exception('Please specify a topic url');
+        
+        // check that we're working with an array
+        if (!is_array($topic_urls)) {
+            $topic_urls = array($topic_urls);
+        }
+        
+        // set the mode to publish
+        $post_string = "hub.mode=publish";
+        // loop through each topic url 
+        foreach ($topic_urls as $topic_url) {
+
+            // lightweight check that we're actually working w/ a valid url
+            if (!preg_match("|^https?://|i",$topic_url)) 
+                throw new Exception('The specified topic url does not appear to be valid: '.$topic_url);
+            
+            // append the topic url parameters
+            $post_string .= "&hub.url=".urlencode($topic_url);
+        }
+        
+        // make the http post request and return true/false
+        // easy to over-write to use your own http function
+        if ($http_function)
+            return $http_function($this->hub_url,$post_string);
+        else
+            return $this->http_post($this->hub_url,$post_string);
+    }
+
+    // returns any error message from the latest request
+    public function last_response() {
+        return $this->last_response;
+    }
+    
+    // default http function that uses curl to post to the hub endpoint
+    private function http_post($url, $post_string) {
+        
+        // add any additional curl options here
+        $options = array(CURLOPT_URL => $url,
+                         CURLOPT_POST => true,
+                         CURLOPT_POSTFIELDS => $post_string,
+                         CURLOPT_USERAGENT => "PubSubHubbub-Publisher-PHP/1.0");
+
+       $ch = curl_init();
+       curl_setopt_array($ch, $options);
+
+        $response = curl_exec($ch);
+        $this->last_response = $response;
+        $info = curl_getinfo($ch);
+
+        curl_close($ch);
+        
+        // all good
+        if ($info['http_code'] == 204) 
+            return true;
+        return false;  
+    }
+}
+
+?>
\ No newline at end of file
index 1810d585e75c8363d5cd150796710154d6865db5..abb04ab4683ea2c2719c576bb3ef902afa980f17 100644 (file)
                                published = $pub
                                WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
 
-                       print json_encode(array("message" => "UPDATE_COUNTERS"));
+                       $pubsub_result = false;
+
+                       if (PUBSUBHUBBUB_HUB) {
+                               $rss_link = get_self_url_prefix() .
+                                       "/backend.php?op=rss&id=-2&key=" .
+                                       get_feed_access_key($link, -2, false);
+
+                               $p = new Publisher(PUBSUBHUBBUB_HUB);
+
+                               $pubsub_result = $p->publish_update($rss_link);
+                       }
+
+                       print json_encode(array("message" => "UPDATE_COUNTERS",
+                               "pubsub_result" => $pubsub_result));
                        return;
                }
 
index 3b9de3478520891f6cbe175f610dc838acf8f0ae..4cb74259d997e51d5771544267ec1d0022f0ea9a 100644 (file)
@@ -1,7 +1,7 @@
 <?php
        require_once "functions.php";
 
-       define('EXPECTED_CONFIG_VERSION', 21);
+       define('EXPECTED_CONFIG_VERSION', 22);
        define('SCHEMA_VERSION', 83);
 
        if (!file_exists("config.php")) {
index f41beff474f4bd722c1d23a08c8f85c6a772b10c..fb51ffa0075f3aa7eabeadf9f21c2f30fde3289c 100644 (file)
@@ -1,3 +1,3 @@
-<?php # This file has been generated at:  Fri Mar 18 19:24:44 MSK 2011
-define('GENERATED_CONFIG_CHECK', 21);
-$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', 'CONFIG_VERSION'); ?>
+<?php # This file has been generated at:  Fri Apr 1 09:34:52 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'); ?>