Commit 3f5992e3 authored by lucha's avatar lucha
Browse files

[auto] plugin: pubsubhubbub 3.0.0

parent ec890f4a
......@@ -5,6 +5,7 @@
.travis.yml
.codeclimate.yml
.data
.svnignore
Gruntfile.js
LINGUAS
Makefile
......
<?php
/**
* The WebSub/PubSubHubbub admin class
*/
class Pubsubhubbub_Admin {
/**
* Add a link to our settings page in the WP menu
*/
public static function add_plugin_menu() {
$options_page = add_options_page(
'WebSub/PubSubHubbub Settings',
'WebSub/PubSubHubbub',
'administrator',
'pubsubhubbub',
array(
'Pubsubhubbub_Admin',
'add_settings_page',
)
);
add_action( 'load-' . $options_page, array( 'Pubsubhubbub_Admin', 'add_help_tab' ) );
}
/**
* Write the content for our settings page that allows you to
* define your endpoints
*/
public static function add_settings_page() {
load_template( plugin_dir_path( __FILE__ ) . '../templates/settings-page.php' );
}
/**
* Register PubSubHubbub settings
*/
public static function register_settings() {
register_setting(
'pubsubhubbub', 'pubsubhubbub_endpoints', array(
'type' => 'string',
'description' => __( 'The WebSub/PubSubHubbub endpoints', 'pubsubhubbub' ),
'show_in_rest' => true,
'default' => '',
)
);
}
public static function add_help_tab() {
get_current_screen()->add_help_tab(
array(
'id' => 'overview',
'title' => __( 'Overview', 'pubsubhubbub' ),
'content' => '<p>' . __( 'WebSub provides a common mechanism for communication between publishers of any kind of Web content and their subscribers, based on HTTP web hooks. Subscription requests are relayed through hubs, which validate and verify the request. Hubs then distribute new and updated content to subscribers when it becomes available. WebSub was previously known as PubSubHubbub.', 'pubsubhubbub' ) . '</p>',
)
);
get_current_screen()->add_help_tab(
array(
'id' => 'screencast',
'title' => __( 'Terms', 'pubsubhubbub' ),
'content' =>
'<p>
<strong>' . __( 'Publisher', 'pubsubhubbub' ) . '</strong><br />' .
__( 'A WebSub Publisher is an implementation that advertises a topic and hub URL on one or more resource URLs.', 'pubsubhubbub' ) .
'</p>' .
'<p>
<strong>' . __( 'Subscriber', 'pubsubhubbub' ) . '</strong><br />' .
__( 'A WebSub Subscriber is an implementation that discovers the hub and topic URL given a resource URL, subscribes to updates at the hub, and accepts content distribution requests from the hub. The subscriber MAY support authenticated content distribution.', 'pubsubhubbub' ) .
'</p>' .
'<p>
<strong>' . __( 'Hub', 'pubsubhubbub' ) . '</strong><br />' .
__( 'A WebSub Hub is an implementation that handles subscription requests and distributes the content to subscribers when the corresponding topic URL has been updated. Hubs MUST support subscription requests with a secret and deliver authenticated requests when requested. Hubs MUST deliver the full contents of the topic URL in the request, and MAY reduce the payload to a diff if the content type supports it.', 'pubsubhubbub' ) .
'</p>',
)
);
get_current_screen()->add_help_tab(
array(
'id' => 'indieweb',
'title' => __( 'The IndieWeb', 'pubsubhubbub' ),
'content' =>
'<p>' . __( 'The IndieWeb is a people-focused alternative to the "corporate web".', 'pubsubhubbub' ) . '</p>' .
'<p>
<strong>' . __( 'Your content is yours', 'pubsubhubbub' ) . '</strong><br />' .
__( 'When you post something on the web, it should belong to you, not a corporation. Too many companies have gone out of business and lost all of their users’ data. By joining the IndieWeb, your content stays yours and in your control.', 'pubsubhubbub' ) .
'</p>' .
'<p>
<strong>' . __( 'You are better connected', 'pubsubhubbub' ) . '</strong><br />' .
__( 'Your articles and status messages can go to all services, not just one, allowing you to engage with everyone. Even replies and likes on other services can come back to your site so they’re all in one place.', 'pubsubhubbub' ) .
'</p>' .
'<p>
<strong>' . __( 'You are in control', 'pubsubhubbub' ) . '</strong><br />' .
__( 'You can post anything you want, in any format you want, with no one monitoring you. In addition, you share simple readable links such as example.com/ideas. These links are permanent and will always work.', 'pubsubhubbub' ) .
'</p>',
)
);
get_current_screen()->set_help_sidebar(
'<p><strong>' . __( 'For more information:', 'pubsubhubbub' ) . '</strong></p>' .
'<p>' . __( '<a href="https://indieweb.org/WebSub">IndieWeb Wiki page</a>', 'pubsubhubbub' ) . '</p>' .
'<p>' . __( '<a href="https://websub.rocks/">Test suite</a>', 'pubsubhubbub' ) . '</p>' .
'<p>' . __( '<a href="https://www.w3.org/TR/websub/">W3C Spec</a>', 'pubsubhubbub' ) . '</p>'
);
}
}
<?php
/**
* The WebSub/PubSubHubbub publisher class
*/
class PubSubHubbub_Publisher {
/**
* 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' );
if ( current_theme_supports( 'microformats2' ) ) {
$feed_urls[] = site_url( '/' );
}
$feed_urls = apply_filters( 'pubsubhubbub_feed_urls', $feed_urls, $post_id );
// publish them
self::publish_to_hub( $feed_urls );
}
/**
* 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
self::publish_to_hub( $feed_urls );
}
/**
* 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 static function publish_update( $topic_urls, $hub_url ) {
if ( ! isset( $hub_url ) ) {
return new WP_Error( 'missing_hub_url', __( 'Please specify a hub url', 'pubsubhubbub' ) );
}
if ( ! preg_match( '|^https?://|i', $hub_url ) ) {
/* translators: %s is the $hub_url */
return new WP_Error( 'invalid_hub_url', sprintf( __( 'The specified hub url does not appear to be valid: %s', 'pubsubhubbub' ), $hub_url ) );
}
if ( ! isset( $topic_urls ) ) {
return new WP_Error( 'missing_topic_url', __( 'Please specify a topic url', 'pubsubhubbub' ) );
}
// 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( $hub_url, $args );
}
/**
* The ability for other plugins to hook into the PuSH code
*
* @param array $feed_urls a list of feed urls you want to publish
*/
public static function 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 = self::get_hubs();
// loop through each hub
foreach ( $hub_urls as $hub_url ) {
// publish the update to each hub
$response = self::publish_update( $feed_urls, $hub_url );
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
*/
public static function 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 );
}
}
<?php
/**
* The WebSub/PubSubHubbub topics class
*/
class Pubsubhubbub_Topics {
/**
* 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;
}
$hub_urls = pubsubhubbub_get_hubs();
foreach ( $hub_urls as $hub_url ) {
printf( '<link rel="hub" href="%s" />', $hub_url ) . PHP_EOL;
}
}
/**
* 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;
}
$hub_urls = pubsubhubbub_get_hubs();
foreach ( $hub_urls as $hub_url ) {
printf( '<atom:link rel="hub" href="%s"/>', $hub_url ) . PHP_EOL;
}
}
/**
* Add Atom namespace to rdf-feed
*/
public static function add_rss_ns_link() {
echo ' xmlns:atom="http://www.w3.org/2005/Atom" ' . PHP_EOL;
}
/**
* Adds link headers as defined in the current v0.4 draft
*/
public static function template_redirect() {
// check if current url is one of the feed urls
if ( ! pubsubhubbub_show_discovery() ) {
return false;
}
$hub_urls = pubsubhubbub_get_hubs();
// add all "hub" headers
foreach ( $hub_urls as $hub_url ) {
header( sprintf( 'Link: <%s>; rel="hub"', $hub_url ), false );
}
// add the "self" header
header( sprintf( 'Link: <%s>; rel="self"', pubsubhubbub_get_self_link() ), false );
}
}
<?php
/**
* The WebSub/PubSubHubbub class
*/
class Pubsubhubbub {
/**
* Load the plugin textdomain.
*/
public static function load_textdomain() {
load_plugin_textdomain( 'pubsubhubbub', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
}
......@@ -6,7 +6,7 @@
* @deprecated
*/
function publish_to_hub( $deprecated = null, $feed_urls ) {
pubsubhubbub_publish_to_hub( $feed_urls );
PubSubHubbub_Publisher::publish_to_hub( $feed_urls );
}
/**
......@@ -17,7 +17,7 @@ function publish_to_hub( $deprecated = null, $feed_urls ) {
* @deprecated
*/
function pshb_publish_to_hub( $feed_urls ) {
pubsubhubbub_publish_to_hub( $feed_urls );
PubSubHubbub_Publisher::publish_to_hub( $feed_urls );
}
/**
......
......@@ -5,102 +5,45 @@
* @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 );
}
PubSubHubbub_Publisher::publish_to_hub( $feed_urls );
}
/**
* get the endpoints from the wordpress options table
* Get the endpoints from the WordPress options table
* valid parameters are "publish" or "subscribe"
*
* @uses apply_filters() Calls 'pubsubhubbub_hub_urls' filter
* @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 );
return PubSubHubbub_Publisher::get_hubs();
}
/**
* Add new topic urls
* Check if link supports PubSubHubbub or WebSub
*
* @param array $urls list of urls
* @return boolean
*/
function pubsubhubbub_update_topic_urls( $urls ) {
if ( ! is_array( $urls ) ) {
return;
}
$topic_urls = pubsubhubbub_get_topic_urls();
$topic_urls = array_merge( $topic_urls, $urls );
function pubsubhubbub_show_discovery() {
global $withcomments;
update_option( 'pubsubhubbub_topic_urls', array_unique( $topic_urls ) );
}
if ( ! $withcomments ) {
$withcomments = 0;
}
/**
* 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' ),
);
$show_discovery = false;
$feeds = get_option( 'pubsubhubbub_topic_urls', $default_feeds );
$supported_feed_types = apply_filters( 'pubsubhubbub_show_discovery_for_feed_types', array( 'atom', 'rss2', 'rdf' ) );
$supported_comment_feed_types = apply_filters( 'pubsubhubbub_show_discovery_for_comment_feed_types', array( 'atom', 'rss2' ) );
if ( is_array( $feeds ) ) {
return $feeds;
if (
( is_feed( $supported_feed_types ) && ! is_archive() && ! is_singular() && 0 == $withcomments ) ||
( is_feed( $supported_comment_feed_types ) && 1 == $withcomments ) ||
( is_home() && current_theme_supports( 'microformats2' ) )
) {
$show_discovery = true;
}
return $default_feeds;
}
/**
* Check if link supports PubSubHubbub or WebSub
*
* @return boolean
*/
function pubsubhubbub_show_discovery() {
return (boolean) pubsubhubbub_get_self_link();
return apply_filters( 'pubsubhubbub_show_discovery', $show_discovery );
}
/**
......@@ -109,22 +52,5 @@ function pubsubhubbub_show_discovery() {
* @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 );
return trailingslashit( home_url( add_query_arg( null, null ) ) );
}
......@@ -2,9 +2,9 @@
# This file is distributed under the MIT.
msgid ""
msgstr ""
"Project-Id-Version: WebSub/PubSubHubbub 2.2.1\n"
"Project-Id-Version: WebSub/PubSubHubbub 3.0.0\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/pubsubhubbub\n"
"POT-Creation-Date: 2018-02-04 19:41:40+00:00\n"
"POT-Creation-Date: 2018-07-02 15:10:24+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
......@@ -13,34 +13,144 @@ msgstr ""
"Language-Team: LANGUAGE <LL@li.org>\n"
"X-Generator: grunt-wp-i18n 0.5.4\n"
#: pubsubhubbub.php:153
msgid "Settings"
#: includes/class-pubsubhubbub-admin.php:39
msgid "The WebSub/PubSubHubbub endpoints"
msgstr ""
#. Plugin Name of the plugin/theme
msgid "WebSub/PubSubHubbub"
#: includes/class-pubsubhubbub-admin.php:50
msgid "Overview"
msgstr ""
#: includes/class-pubsubhubbub-admin.php:51
msgid ""
"WebSub provides a common mechanism for communication between publishers of "
"any kind of Web content and their subscribers, based on HTTP web hooks. "
"Subscription requests are relayed through hubs, which validate and verify "
"the request. Hubs then distribute new and updated content to subscribers "
"when it becomes available. WebSub was previously known as PubSubHubbub."
msgstr ""
#: includes/class-pubsubhubbub-admin.php:58
msgid "Terms"
msgstr ""
#: includes/class-pubsubhubbub-admin.php:61
msgid "Publisher"
msgstr ""
#: includes/class-pubsubhubbub-admin.php:62 templates/settings-page.php:9
msgid ""
"A WebSub Publisher is an implementation that advertises a topic and hub URL "
"on one or more resource URLs."
msgstr ""
#: includes/class-pubsubhubbub-admin.php:65
msgid "Subscriber"
msgstr ""
#: includes/class-pubsubhubbub-admin.php:66
msgid ""
"A WebSub Subscriber is an implementation that discovers the hub and topic "
"URL given a resource URL, subscribes to updates at the hub, and accepts "
"content distribution requests from the hub. The subscriber MAY support "
"authenticated content distribution."
msgstr ""
#: includes/class-pubsubhubbub-admin.php:69
msgid "Hub"
msgstr ""
#: includes/class-pubsubhubbub-admin.php:70
msgid ""
"A WebSub Hub is an implementation that handles subscription requests and "
"distributes the content to subscribers when the corresponding topic URL has "
"been updated. Hubs MUST support subscription requests with a secret and "
"deliver authenticated requests when requested. Hubs MUST deliver the full "
"contents of the topic URL in the request, and MAY reduce the payload to a "
"diff if the content type supports it."
msgstr ""
#: includes/class-pubsubhubbub-admin.php:78
msgid "The IndieWeb"
msgstr ""
#: includes/class-pubsubhubbub-admin.php:80
msgid "The IndieWeb is a people-focused alternative to the \"corporate web\"."
msgstr ""
#: templates/settings-page.php:4
msgid "Define custom hubs"
#: includes/class-pubsubhubbub-admin.php:82
msgid "Your content is yours"
msgstr ""
#: templates/settings-page.php:19
msgid "Hubs (one per line)"
#: includes/class-pubsubhubbub-admin.php:83
msgid ""
"When you post something on the web, it should belong to you, not a "
"corporation. Too many companies have gone out of business and lost all of "
"their users’ data. By joining the IndieWeb, your content stays yours and in "