Commit f6451567 authored by lucha's avatar lucha
Browse files

[auto] plugin: pubsubhubbub 2.2.0

parent a4d019ac
.DS_Store
.editorconfig
.git
.gitignore
.travis.yml
.codeclimate.yml
.data
Gruntfile.js
LINGUAS
Makefile
README.md
readme.md
CODE_OF_CONDUCT.md
LICENSE.md
_site
bin
composer.json
composer.lock
docker-compose.yml
gulpfile.js
package.json
node_modules
npm-debug.log
phpcs.xml
package.json
phpunit.xml
phpunit.xml.dist
tests
node_modules
vendor
<?php
/**
* Beeing backwards compatible
* based on a fix by Stephen Paul Weber (http://singpolyma.net)
*
* @deprecated
*/
function publish_to_hub( $deprecated = null, $feed_urls ) {
pubsubhubbub_publish_to_hub( $feed_urls );
}
/**
* The ability for other plugins to hook into the PuSH code
*
* @param array $feed_urls a list of feed urls you want to publish
*
* @deprecated
*/
function pshb_publish_to_hub( $feed_urls ) {
pubsubhubbub_publish_to_hub( $feed_urls );
}
/**
* Map old filter to new filter
*
* @param array $feed_urls the list of feed urls
*
* @return array filtered list
*
* @deprecated
*/
function pshb_feed_urls( $feed_urls ) {
return apply_filters( 'pshb_feed_urls', $feed_urls );
}
add_filter( 'pubsubhubbub_feed_urls', 'pshb_feed_urls' );
<?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 pubsubhubbub_publish_to_hub( $feed_urls ) {
require_once( dirname( __FILE__ ) . '/pubsubhubbub-publisher.php' );
// remove dups (ie. they all point to feedburner)
$feed_urls = array_unique( $feed_urls );
pubsubhubbub_update_topic_urls( $feed_urls );
// get the list of hubs
$hub_urls = pubsubhubbub_get_hubs();
// loop through each hub
foreach ( $hub_urls as $hub_url ) {
$p = new PubSubHubbub_Publisher( $hub_url );
// publish the update to each hub
$response = $p->publish_update( $feed_urls );
do_action( 'pubsubhubbub_publish_update_response', $response );
}
}
/**
* get the endpoints from the wordpress options table
* valid parameters are "publish" or "subscribe"
*
* @uses apply_filters() Calls 'pubsubhubbub_hub_urls' filter
*/
function pubsubhubbub_get_hubs() {
$endpoints = get_option( 'pubsubhubbub_endpoints' );
$hub_urls = explode( PHP_EOL, $endpoints );
// if no values have been set, revert to the defaults (websub on app engine & superfeedr)
if ( ! $endpoints || ! $hub_urls || ! is_array( $hub_urls ) ) {
$hub_urls = array(
'https://pubsubhubbub.appspot.com',
'https://pubsubhubbub.superfeedr.com',
);
}
// clean out any blank values
foreach ( $hub_urls as $key => $value ) {
if ( empty( $value ) ) {
unset( $hub_urls[ $key ] );
} else {
$hub_urls[ $key ] = trim( $hub_urls[ $key ] );
}
}
return apply_filters( 'pubsubhubbub_hub_urls', $hub_urls );
}
/**
* Add new topic urls
*
* @param array $urls list of urls
*/
function pubsubhubbub_update_topic_urls( $urls ) {
if ( ! is_array( $urls ) ) {
return;
}
$topic_urls = pubsubhubbub_get_topic_urls();
$topic_urls = array_merge( $topic_urls, $urls );
update_option( 'pubsubhubbub_topic_urls', array_unique( $topic_urls ) );
}
/**
* Return topic urls
*
* @return array list of urls
*/
function pubsubhubbub_get_topic_urls() {
$default_feeds = array(
get_bloginfo( 'atom_url' ),
get_bloginfo( 'rdf_url' ),
get_bloginfo( 'rss2_url' ),
get_bloginfo( 'comments_atom_url' ),
get_bloginfo( 'comments_rss2_url' ),
);
$feeds = get_option( 'pubsubhubbub_topic_urls', $default_feeds );
if ( is_array( $feeds ) ) {
return $feeds;
}
return $default_feeds;
}
/**
* Check if link supports PubSubHubbub or WebSub
*
* @return boolean
*/
function pubsubhubbub_show_discovery() {
return (boolean) pubsubhubbub_get_self_link();
}
/**
* Get the correct self URL
*
* @return boolean
*/
function pubsubhubbub_get_self_link() {
// get current url
$urls = pubsubhubbub_get_topic_urls();
$current_url = home_url( add_query_arg( null, null ) );
$current_url = untrailingslashit( $current_url );
$current_url = preg_replace( '/^https?:\/\//i', '', $current_url );
$matches = preg_grep( '/^https?:\/\/' . preg_quote( $current_url, '/' ) . '\/?$/i', $urls );
if ( empty( $matches ) ) {
return false;
}
if ( count( $matches ) >= 2 ) {
return home_url( add_query_arg( null, null ) );
}
return current( $matches );
}
<?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
// modified by Matthias Pfefferle | notizblog.org | matthias@pfefferle.org
// Released under Apache License 2.0
/**
* A pubsubhubbub publisher
*
* @author Josh Fraser
* @author Matthias Pfefferle
*/
class PubSubHubbub_Publisher {
protected $hub_url;
// 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
*
* @param string|array $topic_urls a single topic url or an array of topic urls
*/
public function publish_update( $topic_urls ) {
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 ) ) {
// append the topic url parameters
$post_string .= '&hub.url=' . esc_url( $topic_url );
}
}
$wp_version = get_bloginfo( 'version' );
$user_agent = apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
$args = array(
'timeout' => 100,
'limit_response_size' => 1048576,
'redirection' => 20,
'user-agent' => "$user_agent; PubSubHubbub/WebSub",
'body' => $post_string,
);
// make the http post request
return wp_remote_post( $this->hub_url, $args );
}
}
# Copyright (C) 2015 Josh Fraser, Matthias Pfefferle
# This file is distributed under the same license as the PubSubHubbub package.
# Copyright (C) 2017 Matthias Pfefferle
# This file is distributed under the same license as the WebSub/PubSubHubbub package.
msgid ""
msgstr ""
"Project-Id-Version: PubSubHubbub 1.7.2\n"
"Project-Id-Version: WebSub/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"
"POT-Creation-Date: 2017-05-01 20:24:15+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"
"PO-Revision-Date: 2017-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"
"X-Generator: grunt-wp-i18n 0.5.4\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)"
#: pubsubhubbub.php:152
msgid "Settings"
msgstr ""
#: pubsubhubbub.php:228
msgid "Follow %s or %s on twitter"
#: templates/settings-page.php:2
msgid "Define custom hubs"
msgstr ""
#: pubsubhubbub.php:229
msgid "Learn more about the PubSubHubbub protocol"
#: templates/settings-page.php:17
msgid "Hubs (one per line)"
msgstr ""
#: pubsubhubbub.php:240
msgid "Settings"
#: templates/settings-page.php:26
msgid "Thanks for using WebSub/PubSubHubbub!"
msgstr ""
#. Plugin Name of the plugin/theme
msgid "PubSubHubbub"
msgid "WebSub/PubSubHubbub"
msgstr ""
#. Plugin URI of the plugin/theme
msgid "https://github.com/pubsubhubbub/"
msgid "https://github.com/pubsubhubbub/wordpress-pubsubhubbub/"
msgstr ""
#. Description of the plugin/theme
......@@ -60,7 +42,7 @@ msgid "A better way to tell the world when your blog is updated."
msgstr ""
#. Author of the plugin/theme
msgid "Josh Fraser, Matthias Pfefferle"
msgid "Matthias Pfefferle"
msgstr ""
#. Author URI of the plugin/theme
......
<?php
/**
* Plugin Name: PubSubHubbub
* Plugin URI: https://github.com/pubsubhubbub/
* Plugin Name: WebSub/PubSubHubbub
* Plugin URI: https://github.com/pubsubhubbub/wordpress-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/
* Version: 2.2.0
* Author: Matthias Pfefferle
* Author URI: https://notiz.blog/
* License: MIT
* License URI: http://opensource.org/licenses/MIT
* Text Domain: pubsubhubbub
* Domain Path: /languages
*/
include( 'publisher.php' );
add_action( 'init', array( 'PubSubHubbub_Plugin', 'load_textdomain' ) );
add_action( 'plugins_loaded', array( 'PubSubHubbub_Plugin', 'init' ) );
/**
* 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
}
}
}
class PubSubHubbub_Plugin {
/**
* 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();
/**
* Initialize plugin
*/
public static function init() {
require_once( dirname( __FILE__ ) . '/includes/functions.php' );
// publish them
pshb_publish_to_hub( $feed_urls );
add_action( 'publish_post', array( 'PubSubHubbub_Plugin', 'publish_post' ) );
add_action( 'comment_post', array( 'PubSubHubbub_Plugin', 'publish_comment' ) );
return $post_id;
}
add_action( 'publish_post', 'pshb_publish_post' );
add_action( 'atom_head', array( 'PubSubHubbub_Plugin', 'add_atom_link_tag' ) );
add_action( 'comments_atom_head', array( 'PubSubHubbub_Plugin', 'add_atom_link_tag' ) );
/**
* 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();
add_action( 'rdf_header', array( 'PubSubHubbub_Plugin', 'add_rss_link_tag' ) );
add_action( 'rss2_head', array( 'PubSubHubbub_Plugin', 'add_rss_link_tag' ) );
add_action( 'commentsrss2_head', array( 'PubSubHubbub_Plugin', 'add_rss_link_tag' ) );
// publish them
pshb_publish_to_hub( $feed_urls );
add_action( 'rdf_ns', array( 'PubSubHubbub_Plugin', 'add_rss_ns_link' ) );
return $comment_id;
}
add_action( 'comment_post', 'pshb_publish_comment' );
add_action( 'admin_menu', array( 'PubSubHubbub_Plugin', 'add_plugin_menu' ) );
add_action( 'admin_init', array( 'PubSubHubbub_Plugin', 'register_settings' ) );
/**
* 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.'" />';
}
}
add_action( 'atom_head', 'pshb_add_atom_link_tag' );
add_action( 'comments_atom_head', 'pshb_add_atom_link_tag' );
add_filter( 'plugin_action_links', array( 'PubSubHubbub_Plugin', 'add_settings_link' ), 10, 2 );
/**
* 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.'"/>';
add_action( 'template_redirect', array( 'PubSubHubbub_Plugin', 'template_redirect' ) );
require_once( dirname( __FILE__ ) . '/includes/deprecated.php' );
}
}
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" ' . PHP_EOL;
}
add_action( 'rdf_ns', 'pshb_add_rdf_ns_link' );
/**
* Function that is called whenever a new post is published
*
* @param int $post_id the post-id
* @return int the post-id
*/
public static function publish_post( $post_id ) {
// we want to notify the hub for every feed
$feed_urls = array();
$feed_urls[] = get_bloginfo( 'atom_url' );
$feed_urls[] = get_bloginfo( 'rdf_url' );
$feed_urls[] = get_bloginfo( 'rss2_url' );
$feed_urls = apply_filters( 'pubsubhubbub_feed_urls', $feed_urls, $post_id );
// publish them
pubsubhubbub_publish_to_hub( $feed_urls );
}
/**
* 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();
}
add_action( 'do_feed_rss', 'pshb_start_rss_link_tag', 9 ); // run before output
/**
* Function that is called whenever a new comment is published
*
* @param int $comment_id the comment-id
* @return int the comment-id
*/
public static function publish_comment( $comment_id ) {
// get default comment-feeds
$feed_urls = array();
$feed_urls[] = get_bloginfo( 'comments_atom_url' );
$feed_urls[] = get_bloginfo( 'comments_rss2_url' );
$feed_urls = apply_filters( 'pubsubhubbub_comment_feed_urls', $feed_urls, $comment_id );
// publish them
pubsubhubbub_publish_to_hub( $feed_urls );
}
/**
* 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 );
}
add_action( 'do_feed_rss', 'pshb_end_rss_link_tag', 11 ); // run after output
/**
* Add hub-<link> to the atom feed
*/
public static function add_atom_link_tag() {
// check if current url is one of the feed urls
if ( ! pubsubhubbub_show_discovery() ) {
return;
}
/**
* 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_action( 'admin_menu', 'pshb_add_plugin_menu' );
$hub_urls = pubsubhubbub_get_hubs();
/**
* 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( 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';
foreach ( $hub_urls as $hub_url ) {
printf( '<link rel="hub" href="%s" />', $hub_url ) . PHP_EOL;
}
}
// 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 ] );
/**
* Add hub-<link> to the rss/rdf feed
*/
public static function add_rss_link_tag() {
// check if current url is one of the feed urls
if ( ! pubsubhubbub_show_discovery() ) {
return;
}
}
return apply_filters( 'pshb_hub_urls', $hub_urls );
}
$hub_urls = pubsubhubbub_get_hubs();
/**
* 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 );