Commit f1c5b764 authored by root's avatar root Committed by lechuck
Browse files

Import pubsubhubbub 1.5

parent 9540593a
......@@ -3,7 +3,7 @@
Plugin Name: PubSubHubbub
Plugin URI: http://code.google.com/p/pubsubhubbub/
Description: A better way to tell the world when your blog is updated.
Version: 1.3
Version: 1.5
Author: Josh Fraser
Author Email: josh@eventvue.com
Author URI: http://www.joshfraser.com
......@@ -11,60 +11,70 @@ Author URI: http://www.joshfraser.com
include("publisher.php");
/**
* beeing backwards compatible
* @deprecated
*/
function publish_to_hub($post_id, $feed_urls = null) {
pshb_publish_to_hub($post_id, $feed_urls);
}
// function that is called whenever a new post is published
// the ability for other plugins to hook into the PuSH code was added by Stephen Paul Weber (http://singpolyma.net)
function publish_to_hub($post_id,$feed_urls=NULL) {
function pshb_publish_to_hub($post_id, $feed_urls = null) {
// we want to notify the hub for every feed
if(!$feed_urls) {
if (!$feed_urls) {
$feed_urls = array();
$feed_urls[] = get_bloginfo('atom_url');
$feed_urls[] = get_bloginfo('rss_url');
$feed_urls[] = get_bloginfo('rdf_url');
$feed_urls[] = get_bloginfo('rss2_url');
// customize default feeds
$feed_urls = apply_filters('pshb_feed_urls', $feed_urls);
}
// remove dups (ie. they all point to feedburner)
$feed_urls = array_unique($feed_urls);
// get the list of hubs
$hub_urls = get_pubsub_endpoints();
$hub_urls = pshb_get_pubsub_endpoints();
// loop through each hub
foreach ($hub_urls as $hub_url) {
$p = new Publisher($hub_url);
// publish the update to each hub
if (!$p->publish_update($feed_urls, "http_post_wp")) {
if (!$p->publish_update($feed_urls)) {
// TODO: add better error handling here
}
}
return $post_id;
}
function add_atom_link_tag() {
$hub_urls = get_pubsub_endpoints();
function pshb_add_atom_link_tag() {
$hub_urls = pshb_get_pubsub_endpoints();
foreach ($hub_urls as $hub_url) {
echo '<link rel="hub" href="'.$hub_url.'" />';
}
}
function add_rss_link_tag() {
$hub_urls = get_pubsub_endpoints();
function pshb_add_rss_link_tag() {
$hub_urls = pshb_get_pubsub_endpoints();
foreach ($hub_urls as $hub_url) {
echo '<atom:link rel="hub" href="'.$hub_url.'"/>';
}
}
function add_rdf_ns_link() {
function pshb_add_rdf_ns_link() {
echo 'xmlns:atom="http://www.w3.org/2005/Atom"';
}
// hack to add the atom definition to the RSS feed
// start capturing the feed output. this is run at priority 9 (before output)
function start_rss_link_tag() {
function pshb_start_rss_link_tag() {
ob_start();
}
// this is run at priority 11 (after output)
// add in the xmlns atom definition link
function end_rss_link_tag() {
function pshb_end_rss_link_tag() {
$feed = ob_get_clean();
$pattern = '/<rss version="(.+)">/i';
$replacement = '<rss version="$1" xmlns:atom="http://www.w3.org/2005/Atom">';
......@@ -73,13 +83,13 @@ function end_rss_link_tag() {
}
// add a link to our settings page in the WP menu
function add_plugin_menu() {
add_options_page('PubSubHubbub Settings', 'PubSubHubbub', 8, __FILE__, 'add_settings_page');
function pshb_add_plugin_menu() {
add_options_page('PubSubHubbub Settings', 'PubSubHubbub', 8, __FILE__, 'pshb_add_settings_page');
}
// get the endpoints from the wordpress options table
// valid parameters are "publish" or "subscribe"
function get_pubsub_endpoints() {
function pshb_get_pubsub_endpoints() {
$endpoints = get_option('pubsub_endpoints');
$hub_urls = explode("\n",$endpoints);
......@@ -102,7 +112,7 @@ function get_pubsub_endpoints() {
}
// write the content for our settings page that allows you to define your endpoints
function add_settings_page() { ?>
function pshb_add_settings_page() { ?>
<div class="wrap">
<h2>Define custom hubs</h2>
......@@ -116,7 +126,7 @@ function add_settings_page() { ?>
<?php
// load the existing pubsub endpoint list from the wordpress options table
$pubsub_endpoints = trim(implode("\n",get_pubsub_endpoints()),"\n");
$pubsub_endpoints = trim(implode("\n",pshb_get_pubsub_endpoints()),"\n");
?>
......@@ -153,38 +163,8 @@ function add_settings_page() { ?>
<?php }
// helper function to use the WP-friendly snoopy library
if (!function_exists('get_snoopy')) {
function get_snoopy() {
include_once(ABSPATH.'/wp-includes/class-snoopy.php');
return new Snoopy;
}
}
// over-ride the default curl http function to post to the hub endpoints
function http_post_wp($url, $post_vars) {
// turn the query string into an array for snoopy
parse_str($post_vars);
$post_vars = array();
$post_vars['hub.mode'] = $hub_mode; // PHP converts the periods to underscores
$post_vars['hub.url'] = $hub_url;
// more universal than curl
$snoopy = get_snoopy();
$snoopy->agent = "(PubSubHubbub-Publisher-WP/1.0)";
$snoopy->submit($url,$post_vars);
$response = $snoopy->results;
// TODO: store the last_response. requires a litle refactoring work.
$response_code = $snoopy->response_code;
if ($response_code == 204)
return true;
return false;
}
// add a settings link next to deactive / edit
function add_settings_link( $links, $file ) {
function pshb_add_settings_link( $links, $file ) {
if( $file == 'pubsubhubbub/pubsubhubbub.php' && function_exists( "admin_url" ) ) {
$settings_link = '<a href="' . admin_url( 'options-general.php?page=pubsubhubbub/pubsubhubbub' ) . '">' . __('Settings') . '</a>';
array_unshift( $links, $settings_link ); // before other links
......@@ -193,32 +173,32 @@ function add_settings_link( $links, $file ) {
}
// attach the handler that gets called every time you publish a post
add_action('publish_post', 'publish_to_hub');
add_action('publish_post', 'pshb_publish_to_hub');
// add the link to our settings page in the WP menu structure
add_action('admin_menu', 'add_plugin_menu');
add_action('admin_menu', 'pshb_add_plugin_menu');
// keep WPMU happy
add_action('admin_init', 'register_my_settings');
function register_my_settings() {
add_action('admin_init', 'pshb_register_my_settings');
function pshb_register_my_settings() {
register_setting('my_settings_group','pubsub_endpoints');
}
// add the link tag that points to the hub in the header of our template...
// to our atom feed
add_action('atom_head', 'add_atom_link_tag');
add_action('atom_head', 'pshb_add_atom_link_tag');
// to our RSS 0.92 feed (requires a bit of a hack to include the ATOM namespace definition)
add_action('do_feed_rss', 'start_rss_link_tag', 9); // run before output
add_action('do_feed_rss', 'end_rss_link_tag', 11); // run after output
add_action('rss_head', 'add_rss_link_tag');
add_action('do_feed_rss', 'pshb_start_rss_link_tag', 9); // run before output
add_action('do_feed_rss', 'pshb_end_rss_link_tag', 11); // run after output
add_action('rss_head', 'pshb_add_rss_link_tag');
// to our RDF / RSS 1 feed
add_action('rdf_ns', 'add_rdf_ns_link');
add_action('rdf_header', 'add_rss_link_tag');
add_action('rdf_ns', 'pshb_add_rdf_ns_link');
add_action('rdf_header', 'pshb_add_rss_link_tag');
// to our RSS 2 feed
add_action('rss2_head', 'add_rss_link_tag');
add_action('rss2_head', 'pshb_add_rss_link_tag');
// to our main HTML header -- not sure if we want to include this long-term or not.
add_action('wp_head', 'add_atom_link_tag');
add_action('wp_head', 'pshb_add_atom_link_tag');
add_filter('plugin_action_links', 'add_settings_link', 10, 2);
add_filter('plugin_action_links', 'pshb_add_settings_link', 10, 2);
?>
\ No newline at end of file
=== Plugin Name ===
Contributors: joshfraz
Contributors: joshfraz, pfefferle
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5426516
Tags: pubsubhubbub
Requires at least: 2.5
Tested up to: 2.9.1
Stable tag: /trunk/
Tested up to: 3.0.4
Stable tag: 1.5
A better way to tell the world when your blog is updated.
......@@ -14,9 +14,7 @@ This [PubSubHubbub](http://code.google.com/p/pubsubhubbub/ "PubSubHubbub") plugi
This plugin:
* Supports multi-user installations
* Supports multiple hubs
* Offers hooks for other plugin developers to add PuSH support to their own custom feeds (NEW!)
* Now supports multiple hubs!
* Supports all of the feed formats used by WordPress, not just ATOM and RSS2
* Announces which hubs you are using by adding `<link rel="hub" ...>` declarations to your template header and ATOM feed
* Adds `<atom:link rel="hub" ...>` to your RSS feeds along with the necessary XMLNS declaration for RSS 0.92/1.0
......@@ -38,30 +36,41 @@ Note: PHP 5.0 or better is required.
== Frequently Asked Questions ==
= Where can I learn more about the PubSubHubbub (PuSH) protocol? =
= Where can I learn more about the PubSubHubbub protocol? =
You can visit [PubSubHubbb on Google Code](http://code.google.com/p/pubsubhubbub/ "PubSubHubbb on Google Code")
= Where can I learn more about the author of this plugin? =
You can learn more about Josh Fraser at [Online Aspect](http://www.onlineaspect.com "Online Aspect") or follow [@joshfraser on twitter](http://www.twitter.com/joshfraser "Josh Fraser on Twitter")
You can learn more about [Josh Fraser](http://www.joshfraser.com "Josh Fraser") at [Online Aspect](http://www.onlineaspect.com "Online Aspect")
and [Matthias Pfefferle](http://pfefferle.org "Matthias Pfefferle") at [Notizblog](http://notizblog.org/ "Notizblog")
= Does this plugin work with MU? =
== Screenshots ==
Multi-user support was added in version 1.3
1. The PubSubHubbub Settings page allows you to define which hubs you want to use
= Does this plugin work with PHP 4.x? =
== Changelog ==
Nope. Sorry. For now you must have PHP 5.0 or better.
= 1.5 =
* Added filter to modify $feed_urls
* Re-Added Stephen Paul Webers changes
= Blog posts don't show up right away in Google Reader. Is it broken? =
= 1.4 =
* Added name spacing to avoid conflicts with other plugins & added patch from pfefferle
Google Reader currently supports PuSH for shared items, but not general subscriptions. Hopefully they will add that functionality soon (I hear they're working on it). In the meantime, you can check that everything is working correctly by publishing a post and then checking the status at http://pubsubhubbub.appspot.com/topic-details?hub.url=URL-OF-YOUR-FEED
= 1.3 =
* Added multi-user support and now tested up to 2.9.1
= Got another question that isn't covered here? =
= 1.2 =
* Added support for multiple hubs
Visit [my contact page](http://onlineaspect.com/contact/ "Contact Josh Fraser") to see various ways to get in touch with me.
= 1.1 =
* Added RSS support
== Screenshots ==
= 1.0 =
* First attempt
1. The PubSubHubbub Settings page allows you to define which hubs you want to use
== Upgrade Notice ==
= 1.4 =
Upgrade eliminates conflicts with other Wordpress plugins
\ No newline at end of file
<?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
<?php
/*
Plugin Name: PubSubHubbub
Plugin URI: http://code.google.com/p/pubsubhubbub/
Description: A better way to tell the world when your blog is updated. Set a custom hub on the <a href="./options-general.php?page=pubsubhubbub/pubsubhubbub">PubSubHubbub settings page</a>
Version: 1.1
Author: Josh Fraser
Author Email: josh@eventvue.com
Author URI: http://www.joshfraser.com
*/
include("publisher.php");
// function that is called whenever a new post is published
function publish_to_hub($post_id) {
// we want to notify the hub for every feed
$feed_urls = array();
$feed_urls[] = get_bloginfo('atom_url');
$feed_urls[] = get_bloginfo('rss_url');
$feed_urls[] = get_bloginfo('rdf_url');
$feed_urls[] = get_bloginfo('rss2_url');
// remove dups (ie. they all point to feedburner)
$feed_urls = array_unique($feed_urls);
// get the address of the publish endpoint on the hub
$hub_url = get_pubsub_endpoint();
$p = new Publisher($hub_url);
// need better error handling
if (!$p->publish_update($feed_urls, "http_post_wp")) {
print_r($p->last_response());
}
return $post_id;
}
function add_atom_link_tag() {
$sub_url = get_pubsub_endpoint();
echo '<link rel="hub" href="'.$sub_url.'" />';
}
function add_rss_link_tag() {
$sub_url = get_pubsub_endpoint();
echo '<atom:link rel="hub" href="'.$sub_url.'"/>';
}
function add_rdf_ns_link() {
echo 'xmlns:atom="http://www.w3.org/2005/Atom"';
}
// hack to add the atom definition to the RSS feed
// start capturing the feed output. this is run at priority 9 (before output)
function start_rss_link_tag() {
ob_start();
}
// this is run at priority 11 (after output)
// add in the xmlns atom definition link
function end_rss_link_tag() {
$feed = ob_get_clean();
$pattern = '/<rss version="(.+)">/i';
$replacement = '<rss version="$1" xmlns:atom="http://www.w3.org/2005/Atom">';
// change <rss version="X.XX"> to <rss version="X.XX" xmlns:atom="http://www.w3.org/2005/Atom">
echo preg_replace($pattern, $replacement, $feed);
}
// add a link to our settings page in the WP menu
function add_plugin_menu() {
add_options_page('PubSubHubbub Settings', 'PubSubHubbub', 8, __FILE__, 'add_settings_page');
}
// get the endpoints from the wordpress options table
// valid parameters are "publish" or "subscribe"
function get_pubsub_endpoint() {
$endpoint = get_option('pubsub_endpoint');
// if no values have been set, revert to the defaults (pubsubhubbub on app engine)
if (!$endpoint) {
$endpoint = "http://pubsubhubbub.appspot.com";
}
return $endpoint;
}
// write the content for our settings page that allows you to define your endpoints
function add_settings_page() { ?>
<div class="wrap">
<h2>Define a custom endpoint</h2>
<form method="post" action="options.php">
<?php wp_nonce_field('update-options'); ?>
<?php
// load the existing pubsub endpoint value from the wordpress options table
$pubsub_endpoint = get_pubsub_endpoint();
?>
<table class="form-table">
<tr valign="top">
<th scope="row">Endpoint URL:</th>
<td><input type="text" name="pubsub_endpoint" value="<?php echo $pubsub_endpoint; ?>" size="50" /></td>
</tr>
</table>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="pubsub_endpoint" />
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
</p>
</form>
<br /><br />
Thanks for using PubSubHubbub. Learn more about PubSubHubbub and author of this plugin:
<ul>
<li><a href='http://www.onlineaspect.com'>Subscribe to Online Aspect</a></li>
<li><a href='http://www.twitter.com/joshfraser'>Follow Josh Fraser on twitter</a></li>
<li><a href='http://code.google.com/p/pubsubhubbub/'>Learn more about the PubSubHubbub protocol</a></li>
</ul>
</div>
<?php }
// helper function to use the WP-friendly snoopy library
if (!function_exists('get_snoopy')) {
function get_snoopy() {
include_once(ABSPATH.'/wp-includes/class-snoopy.php');
return new Snoopy;
}
}
// over-ride the default curl http function to post to the hub endpoint
function http_post_wp($url, $post_vars) {
// turn the query string into an array for snoopy
parse_str($post_vars);
$post_vars = array();
$post_vars['hub.mode'] = $hub_mode; // PHP converts the periods to underscores
$post_vars['hub.url'] = $hub_url;
// more universal than curl
$snoopy = get_snoopy();
$snoopy->agent = "(PubSubHubbub-Publisher-WP/1.0)";
$snoopy->submit($url,$post_vars);
$response = $snoopy->results;
// TODO: store the last_response. requires a litle refactoring work.
$response_code = $snoopy->response_code;
if ($response_code == 204)
return true;
return false;
}
// attach the handler that gets called every time you publish a post
add_action('publish_post', 'publish_to_hub');
// add the link to our settings page in the WP menu structure
add_action('admin_menu', 'add_plugin_menu');
// add the link tag that points to the hub in the header of our template...
// to our atom feed
add_action('atom_head', 'add_atom_link_tag');
// to our RSS 0.92 feed (requires a bit of a hack to include the ATOM namespace definition)
add_action('do_feed_rss', 'start_rss_link_tag', 9); // run before output
add_action('do_feed_rss', 'end_rss_link_tag', 11); // run after output
add_action('rss_head', 'add_rss_link_tag');
// to our RDF / RSS 1 feed
add_action('rdf_ns', 'add_rdf_ns_link');
add_action('rdf_header', 'add_rss_link_tag');
// to our RSS 2 feed
add_action('rss2_head', 'add_rss_link_tag');
// to our main HTML header -- not sure if we want to include this long-term or not.
add_action('wp_head', 'add_atom_link_tag');
?>
\ No newline at end of file
=== Plugin Name ===
Contributors: joshfraz
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5426516
Tags: pubsubhubbub
Requires at least: 2.5
Tested up to: 2.7
Stable tag: /trunk/
A better way to tell the world when your blog is updated.
== Description ==
This plugin that implements [the PubSubHubbub protocol](http://pubsubhubbub.googlecode.com/svn/trunk/pubsubhubbub-core-0.1.html "the PubSubHubbub protocol"). [PubSubHubbub](http://code.google.com/p/pubsubhubbub/ "PubSubHubbub") is a simple, open, server-to-server web-hook-based pubsub (publish/subscribe) protocol as a simple extension to Atom and RSS.
Parties (servers) speaking the PubSubHubbub protocol can get near-instant notifications (via webhook callbacks) when a topic (feed URL) they're interested in is updated.
This plugin:
* Notifies your specified hub each time you publish a new post
* Announces your specified hub by adding `<link rel="hub" ...>` to your template header and ATOM feed
* Adds `<atom:link rel="hub" ...>` to your RSS feeds along with the necessary XMLNS declaration for RSS 0.92/1.0
The PubSubHubbub protocol is decentralized and free. No company is at the center of this controlling it. Anybody can run a hub, or anybody can ping (publish) or subscribe using open hubs. If no custom hub is specified, this plugin will use the demonstration hub that is running on Google App Engine.
== Installation ==
1. Upload the `pubsubhubbub` directory to your `/wp-content/plugins/` directory
2. Activate the plugin through the 'Plugins' menu in WordPress
3. Select a custom hub under your PubSubHubbub Settings (optional)
== Frequently Asked Questions ==
= Where can I learn more about the PubSubHubbub protocol? =
You can visit [PubSubHubbb on Google Code](http://code.google.com/p/pubsubhubbub/ "PubSubHubbb on Google Code")
= Where can I learn more about the author of this plugin? =
You can learn more about [Josh Fraser](http://www.joshfraser.com "Josh Fraser") at [Online Aspect](http://www.onlineaspect.com "Online Aspect")
== Screenshots ==
1. The PubSubHubbub Settings page allows you to define custom endpoints for your chosen hub
<?php
// a PHP client library for pubsubhubbub