Commit 8e7f35bf authored by lucha's avatar lucha

[auto] Plugin: pubsubhubbub 1.7.2

parent 7f89eb38
# Copyright (C) 2015 Josh Fraser, Matthias Pfefferle
# This file is distributed under the same license as the PubSubHubbub package.
msgid ""
msgstr ""
"Project-Id-Version: PubSubHubbub 1.7.2\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/pubsubhubbub\n"
"POT-Creation-Date: 2015-11-03 10:40:52+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"X-Generator: grunt-wp-i18n 0.5.3\n"
#: pubsubhubbub.php:198
msgid "Define custom hubs"
msgstr ""
#: pubsubhubbub.php:214
msgid "Hubs (one per line)"
msgstr ""
#: pubsubhubbub.php:223
msgid "Thanks for using PubSubHubbub!"
msgstr ""
#: pubsubhubbub.php:225
msgid ""
"Visit these links to learn more about PubSubHubbub and the author of this "
"plugin:"
msgstr ""
#: pubsubhubbub.php:227
msgid "Subscribe to %s or %s (german)"
msgstr ""
#: pubsubhubbub.php:228
msgid "Follow %s or %s on twitter"
msgstr ""
#: pubsubhubbub.php:229
msgid "Learn more about the PubSubHubbub protocol"
msgstr ""
#: pubsubhubbub.php:240
msgid "Settings"
msgstr ""
#. Plugin Name of the plugin/theme
msgid "PubSubHubbub"
msgstr ""
#. Plugin URI of the plugin/theme
msgid "https://github.com/pubsubhubbub/"
msgstr ""
#. Description of the plugin/theme
msgid "A better way to tell the world when your blog is updated."
msgstr ""
#. Author of the plugin/theme
msgid "Josh Fraser, Matthias Pfefferle"
msgstr ""
#. Author URI of the plugin/theme
msgid "https://wordpress.org/plugins/pubsubhubbub/"
msgstr ""
\ No newline at end of file
......@@ -12,79 +12,86 @@
* @author Matthias Pfefferle
*/
class PshbPublisher {
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_RETURNTRANSFER => true,
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;
}
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_RETURNTRANSFER => true,
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 ( 204 == $info['http_code'] ) {
return true;
}
return false;
}
}
?>
<?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.
Version: 1.6.5
Author: Josh Fraser, Matthias Pfefferle
Author Email: joshfraz@gmail.com
Author URI: http://wordpress.org/extend/plugins/pubsubhubbub/
*/
include("publisher.php");
// the ability for other plugins to hook into the PuSH code based on a
// fix by Stephen Paul Weber (http://singpolyma.net)
function pshb_publish_to_hub($feed_urls) {
// remove dups (ie. they all point to feedburner)
$feed_urls = array_unique($feed_urls);
// get the list of hubs
$hub_urls = pshb_get_pubsub_endpoints();
// loop through each hub
foreach ($hub_urls as $hub_url) {
$p = new PshbPublisher($hub_url);
// publish the update to each hub
if (!$p->publish_update($feed_urls)) {
// TODO: add better error handling here
}
}
}
// function that is called whenever a new post is published
function pshb_publish_post($post_id) {
// customize default feeds
$feed_urls = pshb_get_feed_urls();
pshb_publish_to_hub($feed_urls);
return $post_id;
}
add_action('publish_post', 'pshb_publish_post');
// function that is called whenever a new comment is published
function pshb_publish_comment($comment_id) {
// customize default feeds
$feed_urls = pshb_get_comment_feed_urls();
pshb_publish_to_hub($feed_urls);
return $comment_id;
}
add_action('comment_post', 'pshb_publish_comment');
// to our atom feed
/**
* Plugin Name: PubSubHubbub
* Plugin URI: https://github.com/pubsubhubbub/
* Description: A better way to tell the world when your blog is updated.
* Version: 1.7.2
* Author: Josh Fraser, Matthias Pfefferle
* Author Email: joshfraz@gmail.com
* Author URI: https://wordpress.org/plugins/pubsubhubbub/
* Domain Path: /languages
*/
include( 'publisher.php' );
/**
* the ability for other plugins to hook into the PuSH code
*
* @param array $feed_urls a list of feed urls you want to publish
*/
function pshb_publish_to_hub( $feed_urls ) {
// remove dups (ie. they all point to feedburner)
$feed_urls = array_unique( $feed_urls );
// get the list of hubs
$hub_urls = pshb_get_pubsub_endpoints();
// loop through each hub
foreach ( $hub_urls as $hub_url ) {
$p = new PshbPublisher( $hub_url );
// publish the update to each hub
if ( ! $p->publish_update( $feed_urls ) ) {
// TODO: add better error handling here
}
}
}
/**
* function that is called whenever a new post is published
*
* @param int $post_id the post-id
* @return int the post-id
*/
function pshb_publish_post( $post_id ) {
// get default feeds
$feed_urls = pshb_get_feed_urls();
// publish them
pshb_publish_to_hub( $feed_urls );
return $post_id;
}
add_action( 'publish_post', 'pshb_publish_post' );
/**
* function that is called whenever a new comment is published
*
* @param int $comment_id the comment-id
* @return int the comment-id
*/
function pshb_publish_comment( $comment_id ) {
// get default comment-feeds
$feed_urls = pshb_get_comment_feed_urls();
// publish them
pshb_publish_to_hub( $feed_urls );
return $comment_id;
}
add_action( 'comment_post', 'pshb_publish_comment' );
/**
* add hub-<link> to the atom feed
*/
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.'" />';
}
$hub_urls = pshb_get_pubsub_endpoints();
foreach ( $hub_urls as $hub_url ) {
echo '<link rel="hub" href="'.$hub_url.'" />';
}
}
add_action('atom_head', 'pshb_add_atom_link_tag');
add_action('comments_atom_head', 'pshb_add_atom_link_tag');
//add_action('wp_head', 'pshb_add_atom_link_tag');
add_action( 'atom_head', 'pshb_add_atom_link_tag' );
add_action( 'comments_atom_head', 'pshb_add_atom_link_tag' );
/**
* add hub-<link> to the rss/rdf feed
*/
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.'"/>';
}
$hub_urls = pshb_get_pubsub_endpoints();
foreach ( $hub_urls as $hub_url ) {
echo '<atom:link rel="hub" href="'.$hub_url.'"/>';
}
}
add_action('rss_head', 'pshb_add_rss_link_tag');
add_action('rdf_header', 'pshb_add_rss_link_tag');
add_action('rss2_head', 'pshb_add_rss_link_tag');
add_action('commentsrss2_head', 'pshb_add_rss_link_tag');
add_action( 'rss_head', 'pshb_add_rss_link_tag' );
add_action( 'rdf_header', 'pshb_add_rss_link_tag' );
add_action( 'rss2_head', 'pshb_add_rss_link_tag' );
add_action( 'commentsrss2_head', 'pshb_add_rss_link_tag' );
/**
* add atom namespace to rdf-feed
*/
function pshb_add_rdf_ns_link() {
echo 'xmlns:atom="http://www.w3.org/2005/Atom"';
echo ' xmlns:atom="http://www.w3.org/2005/Atom" ' . PHP_EOL;
}
add_action('rdf_ns', 'pshb_add_rdf_ns_link');
add_action( 'rdf_ns', 'pshb_add_rdf_ns_link' );
// hack to add the atom definition to the RSS feed
// start capturing the feed output. this is run at priority 9 (before output)
/**
* hack to add the atom definition to the RSS feed
* start capturing the feed output. this is run at priority 9 (before output)
*/
function pshb_start_rss_link_tag() {
ob_start();
ob_start();
}
add_action('do_feed_rss', 'pshb_start_rss_link_tag', 9); // run before output
add_action( 'do_feed_rss', 'pshb_start_rss_link_tag', 9 ); // run before output
// this is run at priority 11 (after output)
// add in the xmlns atom definition link
/**
* this is run at priority 11 (after output)
* add in the xmlns atom definition link
*/
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">';
// change <rss version="X.XX"> to <rss version="X.XX" xmlns:atom="http://www.w3.org/2005/Atom">
echo preg_replace($pattern, $replacement, $feed);
$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_action('do_feed_rss', 'pshb_end_rss_link_tag', 11); // run after output
add_action( 'do_feed_rss', 'pshb_end_rss_link_tag', 11 ); // run after output
// add a link to our settings page in the WP menu
/**
* add a link to our settings page in the WP menu
*/
function pshb_add_plugin_menu() {
add_options_page('PubSubHubbub Settings', 'PubSubHubbub', 'administrator', 'pubsubhubbub', 'pshb_add_settings_page');
add_options_page( 'PubSubHubbub Settings', 'PubSubHubbub', 'administrator', 'pubsubhubbub', 'pshb_add_settings_page' );
}
add_action('admin_menu', 'pshb_add_plugin_menu');
add_action( 'admin_menu', 'pshb_add_plugin_menu' );
// get the endpoints from the wordpress options table
// valid parameters are "publish" or "subscribe"
/**
* get the endpoints from the wordpress options table
* valid parameters are "publish" or "subscribe"
*
* @uses apply_filters() Calls 'pshb_hub_urls' filter
*/
function pshb_get_pubsub_endpoints() {
$endpoints = get_option('pubsub_endpoints');
$hub_urls = explode("\n",$endpoints);
// if no values have been set, revert to the defaults (pubsubhubbub on app engine & superfeedr)
if (!$endpoints) {
$hub_urls[] = "http://pubsubhubbub.appspot.com";
$hub_urls[] = "http://pubsubhubbub.superfeedr.com";
}
// clean out any blank values
foreach ($hub_urls as $key => $value) {
if (is_null($value) || $value=="") {
unset($hub_urls[$key]);
} else {
$hub_urls[$key] = trim($hub_urls[$key]);
}
}
return $hub_urls;
$endpoints = get_option( 'pubsub_endpoints' );
$hub_urls = explode( PHP_EOL, $endpoints );
// if no values have been set, revert to the defaults (pubsubhubbub on app engine & superfeedr)
if ( ! $endpoints ) {
$hub_urls[] = 'https://pubsubhubbub.appspot.com';
$hub_urls[] = 'https://pubsubhubbub.superfeedr.com';
}
// clean out any blank values
foreach ( $hub_urls as $key => $value ) {
if ( is_null( $value ) || '' == $value ) {
unset( $hub_urls[ $key ] );
} else {
$hub_urls[ $key ] = trim( $hub_urls[ $key ] );
}
}
return apply_filters( 'pshb_hub_urls', $hub_urls );
}
// helper function to get feed urls
/**
* helper function to get feed urls
*
* @uses apply_filters() Calls 'pshb_feed_urls' filter
*/
function pshb_get_feed_urls() {
// 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');
return apply_filters('pshb_feed_urls', $feed_urls);
// 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' );
return apply_filters( 'pshb_feed_urls', $feed_urls );
}
// helper function to get comment-feed urls
/**
* helper function to get comment-feed urls
*
* @uses apply_filters() Calls 'pshb_comment_feed_urls' filter
*/
function pshb_get_comment_feed_urls() {
// we want to notify the hub for every feed
$feed_urls = array();
$feed_urls[] = get_bloginfo('comments_atom_url');
$feed_urls[] = get_bloginfo('comments_rss2_url');
return apply_filters('pshb_comment_feed_urls', $feed_urls);
}
// write the content for our settings page that allows you to define your endpoints
function pshb_add_settings_page() { ?>
<div class="wrap">
<h2>Define custom hubs</h2>
<form method="post" action="options.php">
<?php //wp_nonce_field('update-options'); ?>
<!-- starting -->
<?php settings_fields('my_settings_group'); ?>
<?php do_settings_sections('my_settings_section'); ?>
<!-- ending -->
<?php
// load the existing pubsub endpoint list from the wordpress options table
$pubsub_endpoints = trim(implode("\n",pshb_get_pubsub_endpoints()),"\n");
?>
<table class="form-table">
<tr valign="top">
<th scope="row">Hubs (one per line)</th>
<td><textarea name="pubsub_endpoints" style='width:600px;height:100px'><?php echo $pubsub_endpoints; ?></textarea></td>
</tr>
</table>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="pubsub_endpoints" />
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
</p>
</form>
<br /><br />
<div style='background-color:#FFFEEB;border:1px solid #CCCCCC;padding:12px'>
<strong>Thanks for using PubSubHubbub!</strong><br />
Visit these links to learn more about PubSubHubbub and the author of this plugin:<br />
<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>
// we want to notify the hub for every feed
$feed_urls = array();
$feed_urls[] = get_bloginfo( 'comments_atom_url' );
$feed_urls[] = get_bloginfo( 'comments_rss2_url' );
return apply_filters( 'pshb_comment_feed_urls', $feed_urls );
}
/**
* write the content for our settings page that allows you to
* define your endpoints
*/
function pshb_add_settings_page() {
?>
<div class="wrap">
<h2><?php _e( 'Define custom hubs', 'pubsubhubbub' ); ?></h2>
<form method="post" action="options.php">
<?php //wp_nonce_field('update-options'); ?>
<!-- starting -->
<?php settings_fields( 'pubsubhubbub_options' ); ?>
<?php do_settings_sections( 'pubsubhubbub_options' ); ?>
<!-- ending -->
<?php
// load the existing pubsub endpoint list from the wordpress options table
$pubsub_endpoints = trim( implode( PHP_EOL, pshb_get_pubsub_endpoints() ), PHP_EOL );
?>