add experimental support for pubsubhubbub in published feed, bump config version (refs #251)

This commit is contained in:
Andrew Dolgov 2011-04-01 09:36:29 +04:00
parent 6f1c5d1760
commit b0f379dfff
7 changed files with 144 additions and 11 deletions

View file

@ -192,7 +192,11 @@
// Please set this to true if you have read everything above and // Please set this to true if you have read everything above and
// finished setting configuration options. // 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 // Expected config version. Please update this option in config.php
// if necessary (after migrating all new options from this file). // if necessary (after migrating all new options from this file).

View file

@ -110,6 +110,7 @@
require_once "lib/magpierss/rss_fetch.inc"; require_once "lib/magpierss/rss_fetch.inc";
require_once 'lib/magpierss/rss_utils.inc'; require_once 'lib/magpierss/rss_utils.inc';
require_once 'lib/htmlpurifier/library/HTMLPurifier.auto.php'; require_once 'lib/htmlpurifier/library/HTMLPurifier.auto.php';
require_once 'lib/pubsubhubbub/publisher.php';
$config = HTMLPurifier_Config::createDefault(); $config = HTMLPurifier_Config::createDefault();
@ -3583,13 +3584,19 @@
$feed_site_url = $qfh_ret[2]; $feed_site_url = $qfh_ret[2];
$last_error = $qfh_ret[3]; $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\"?> print "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\"?> <?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\"?>
<rss version=\"2.0\"> <rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
<channel> xmlns:atom=\"http://www.w3.org/2005/Atom\">
<title>$feed_title</title> <channel>";
if (PUBSUBHUBBUB_HUB && $feed == -2) {
print "<atom:link rel='hub' href='".PUBSUBHUBBUB_HUB."'/>";
}
print "<title>$feed_title</title>
<link>$feed_site_url</link> <link>$feed_site_url</link>
<description>Feed generated by Tiny Tiny RSS</description>"; <description>Feed generated by Tiny Tiny RSS</description>";
@ -4100,8 +4107,10 @@
$reply .= "<option value=\"emailArticle(false)\">".__('Forward by email'). $reply .= "<option value=\"emailArticle(false)\">".__('Forward by email').
"</option>"; "</option>";
if ($is_cat) $cat_q = "&is_cat=$is_cat";
$rss_link = htmlspecialchars(get_self_url_prefix() . $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>"; $reply .= "<option value=\"0\" disabled=\"1\">".__('Feed:')."</option>";

View file

@ -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());
}

View file

@ -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;
}
}
?>

View file

@ -211,7 +211,20 @@
published = $pub published = $pub
WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); 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; return;
} }

View file

@ -1,7 +1,7 @@
<?php <?php
require_once "functions.php"; require_once "functions.php";
define('EXPECTED_CONFIG_VERSION', 21); define('EXPECTED_CONFIG_VERSION', 22);
define('SCHEMA_VERSION', 83); define('SCHEMA_VERSION', 83);
if (!file_exists("config.php")) { if (!file_exists("config.php")) {

View file

@ -1,3 +1,3 @@
<?php # This file has been generated at: Fri Mar 18 19:24:44 MSK 2011 <?php # This file has been generated at: Fri Apr 1 09:34:52 MSD 2011
define('GENERATED_CONFIG_CHECK', 21); 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', 'CONFIG_VERSION'); ?> $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'); ?>