WebSub/PubSubHubbub - Version 2.1.0

Version Description

  • save pinged URLs to add correct headers
Download this release

Release Info

Developer pfefferle
Plugin Icon 128x128 WebSub/PubSubHubbub
Version 2.1.0
Comparing to
See all releases

Code changes from version 2.0.1 to 2.1.0

Files changed (4) hide show
  1. .svnignore +30 -0
  2. includes/functions.php +31 -15
  3. pubsubhubbub.php +3 -5
  4. readme.txt +11 -3
.svnignore ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .DS_Store
2
+ .editorconfig
3
+ .git
4
+ .gitignore
5
+ .travis.yml
6
+ .codeclimate.yml
7
+ .data
8
+ Gruntfile.js
9
+ LINGUAS
10
+ Makefile
11
+ README.md
12
+ readme.md
13
+ CODE_OF_CONDUCT.md
14
+ LICENSE.md
15
+ _site
16
+ bin
17
+ composer.json
18
+ composer.lock
19
+ docker-compose.yml
20
+ gulpfile.js
21
+ package.json
22
+ node_modules
23
+ npm-debug.log
24
+ phpcs.xml
25
+ package.json
26
+ phpunit.xml
27
+ phpunit.xml.dist
28
+ tests
29
+ node_modules
30
+ vendor
includes/functions.php CHANGED
@@ -10,7 +10,7 @@ function pubsubhubbub_publish_to_hub( $feed_urls ) {
10
  // remove dups (ie. they all point to feedburner)
11
  $feed_urls = array_unique( $feed_urls );
12
 
13
- pubsubhubbub_update_pinged_urls( $feed_urls );
14
 
15
  // get the list of hubs
16
  $hub_urls = pubsubhubbub_get_hubs();
@@ -43,7 +43,7 @@ function pubsubhubbub_get_hubs() {
43
 
44
  // clean out any blank values
45
  foreach ( $hub_urls as $key => $value ) {
46
- if ( is_null( $value ) || '' == $value ) {
47
  unset( $hub_urls[ $key ] );
48
  } else {
49
  $hub_urls[ $key ] = trim( $hub_urls[ $key ] );
@@ -54,27 +54,27 @@ function pubsubhubbub_get_hubs() {
54
  }
55
 
56
  /**
57
- * Add new pinged urls
58
  *
59
  * @param array $urls list of urls
60
  */
61
- function pubsubhubbub_update_pinged_urls( $urls ) {
62
  if ( ! is_array( $urls ) ) {
63
  return;
64
  }
65
 
66
- $pinged_urls = pubsubhubbub_get_pinged_urls();
67
- $pinged_urls = array_merge( $pinged_urls, $urls );
68
 
69
- update_option( 'pubsubhubbub_pinged_urls', array_unique( $pinged_urls ) );
70
  }
71
 
72
  /**
73
- * Return already pinged urls
74
  *
75
  * @return array list of urls
76
  */
77
- function pubsubhubbub_get_pinged_urls() {
78
  $default_feeds = array(
79
  get_bloginfo( 'atom_url' ),
80
  get_bloginfo( 'rdf_url' ),
@@ -83,7 +83,7 @@ function pubsubhubbub_get_pinged_urls() {
83
  get_bloginfo( 'comments_rss2_url' ),
84
  );
85
 
86
- $feeds = get_option( 'pubsubhubbub_pinged_urls', $default_feeds );
87
 
88
  if ( is_array( $feeds ) ) {
89
  return $feeds;
@@ -98,15 +98,31 @@ function pubsubhubbub_get_pinged_urls() {
98
  * @return boolean
99
  */
100
  function pubsubhubbub_show_discovery() {
 
 
 
 
 
 
 
 
 
101
  // get current url
102
- $urls = pubsubhubbub_get_pinged_urls();
103
 
104
  $current_url = home_url( add_query_arg( null, null ) );
 
 
 
 
 
 
 
 
105
 
106
- // check if current url is one of the feed urls
107
- if ( in_array( $current_url, $urls ) ) {
108
- return true;
109
  }
110
 
111
- return false;
112
  }
10
  // remove dups (ie. they all point to feedburner)
11
  $feed_urls = array_unique( $feed_urls );
12
 
13
+ pubsubhubbub_update_topic_urls( $feed_urls );
14
 
15
  // get the list of hubs
16
  $hub_urls = pubsubhubbub_get_hubs();
43
 
44
  // clean out any blank values
45
  foreach ( $hub_urls as $key => $value ) {
46
+ if ( empty( $value ) ) {
47
  unset( $hub_urls[ $key ] );
48
  } else {
49
  $hub_urls[ $key ] = trim( $hub_urls[ $key ] );
54
  }
55
 
56
  /**
57
+ * Add new topic urls
58
  *
59
  * @param array $urls list of urls
60
  */
61
+ function pubsubhubbub_update_topic_urls( $urls ) {
62
  if ( ! is_array( $urls ) ) {
63
  return;
64
  }
65
 
66
+ $topic_urls = pubsubhubbub_get_topic_urls();
67
+ $topic_urls = array_merge( $topic_urls, $urls );
68
 
69
+ update_option( 'pubsubhubbub_topic_urls', array_unique( $topic_urls ) );
70
  }
71
 
72
  /**
73
+ * Return topic urls
74
  *
75
  * @return array list of urls
76
  */
77
+ function pubsubhubbub_get_topic_urls() {
78
  $default_feeds = array(
79
  get_bloginfo( 'atom_url' ),
80
  get_bloginfo( 'rdf_url' ),
83
  get_bloginfo( 'comments_rss2_url' ),
84
  );
85
 
86
+ $feeds = get_option( 'pubsubhubbub_topic_urls', $default_feeds );
87
 
88
  if ( is_array( $feeds ) ) {
89
  return $feeds;
98
  * @return boolean
99
  */
100
  function pubsubhubbub_show_discovery() {
101
+ return (boolean) pubsubhubbub_get_self_link();
102
+ }
103
+
104
+ /**
105
+ * Get the correct self URL
106
+ *
107
+ * @return boolean
108
+ */
109
+ function pubsubhubbub_get_self_link() {
110
  // get current url
111
+ $urls = pubsubhubbub_get_topic_urls();
112
 
113
  $current_url = home_url( add_query_arg( null, null ) );
114
+ $current_url = untrailingslashit( $current_url );
115
+ $current_url = preg_replace( '/^https?:\/\//i', '', $current_url );
116
+
117
+ $matches = preg_grep( '/^https?:\/\/' . preg_quote( $current_url, '/' ) . '\/?$/i', $urls );
118
+
119
+ if ( empty( $matches ) ) {
120
+ return false;
121
+ }
122
 
123
+ if ( count( $matches ) >= 2 ) {
124
+ return home_url( add_query_arg( null, null ) );
 
125
  }
126
 
127
+ return $matches[0];
128
  }
pubsubhubbub.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WebSub/PubSubHubbub
4
  * Plugin URI: https://github.com/pubsubhubbub/wordpress-pubsubhubbub/
5
  * Description: A better way to tell the world when your blog is updated.
6
- * Version: 2.0.1
7
  * Author: Matthias Pfefferle
8
  * Author URI: https://notiz.blog/
9
  * License: MIT
@@ -162,7 +162,7 @@ class PubSubHubbub_Plugin {
162
  public static function template_redirect() {
163
  // check if current url is one of the feed urls
164
  if ( ! pubsubhubbub_show_discovery() ) {
165
- return;
166
  }
167
 
168
  $hub_urls = pubsubhubbub_get_hubs();
@@ -171,10 +171,8 @@ class PubSubHubbub_Plugin {
171
  header( sprintf( 'Link: <%s>; rel="hub"', $hub_url ), false );
172
  }
173
 
174
- $current_url = home_url( add_query_arg( null, null ) );
175
-
176
  // add the "self" header
177
- header( sprintf( 'Link: <%s>; rel="self"', $current_url ), false );
178
  }
179
 
180
  /**
3
  * Plugin Name: WebSub/PubSubHubbub
4
  * Plugin URI: https://github.com/pubsubhubbub/wordpress-pubsubhubbub/
5
  * Description: A better way to tell the world when your blog is updated.
6
+ * Version: 2.1.0
7
  * Author: Matthias Pfefferle
8
  * Author URI: https://notiz.blog/
9
  * License: MIT
162
  public static function template_redirect() {
163
  // check if current url is one of the feed urls
164
  if ( ! pubsubhubbub_show_discovery() ) {
165
+ return false;
166
  }
167
 
168
  $hub_urls = pubsubhubbub_get_hubs();
171
  header( sprintf( 'Link: <%s>; rel="hub"', $hub_url ), false );
172
  }
173
 
 
 
174
  // add the "self" header
175
+ header( sprintf( 'Link: <%s>; rel="self"', pubsubhubbub_get_self_link() ), false );
176
  }
177
 
178
  /**
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: pfefferle, joshfraz
3
  Donate link: http://14101978.de
4
  Tags: webhooks, websub, puhsubhubbub, pubsub, ping, push, indieweb, openweb, ostatus
5
  Requires at least: 4.5
6
- Tested up to: 4.7.4
7
- Stable tag: 2.0.1
8
 
9
  A better way to tell the world when your blog is updated.
10
 
@@ -18,7 +18,9 @@ This plugin:
18
  * Supports multi-user installations (Wordpress MU)
19
  * Supports multiple hubs
20
  * Supports all of the feed formats used by WordPress, not just ATOM and RSS2
21
- * Supports latest spec ([Version 0.4](https://pubsubhubbub.github.io/PubSubHubbub/pubsubhubbub-core-0.4.html))
 
 
22
  * Announces which hubs you are using by adding `<link rel="hub" ...>` declarations to your template header and ATOM feed
23
  * Adds `<atom:link rel="hub" ...>` to your RSS feeds along with the necessary XMLNS declaration for RSS 0.92/1.0
24
 
@@ -53,11 +55,17 @@ You can visit [PubsSubHubbub on Github](https://github.com/pubsubhubbub "PubsSub
53
 
54
  Project maintained on github at [pubsubhubbub/wordpress-pubsubhubbub](https://github.com/pubsubhubbub/wordpress-pubsubhubbub).
55
 
 
 
 
 
56
  = 2.0.0 =
 
57
  * Complete rewrite
58
  * Support WebSub
59
 
60
  = 1.0.0 =
 
61
  * First attempt
62
 
63
  == Upgrade Notice ==
3
  Donate link: http://14101978.de
4
  Tags: webhooks, websub, puhsubhubbub, pubsub, ping, push, indieweb, openweb, ostatus
5
  Requires at least: 4.5
6
+ Tested up to: 4.8
7
+ Stable tag: 2.1.0
8
 
9
  A better way to tell the world when your blog is updated.
10
 
18
  * Supports multi-user installations (Wordpress MU)
19
  * Supports multiple hubs
20
  * Supports all of the feed formats used by WordPress, not just ATOM and RSS2
21
+ * Supports latest specs
22
+ * PubSubHubbub [Version 0.4](https://pubsubhubbub.github.io/PubSubHubbub/pubsubhubbub-core-0.4.html)
23
+ * WebSub [Dev Version](https://www.w3.org/TR/websub/)
24
  * Announces which hubs you are using by adding `<link rel="hub" ...>` declarations to your template header and ATOM feed
25
  * Adds `<atom:link rel="hub" ...>` to your RSS feeds along with the necessary XMLNS declaration for RSS 0.92/1.0
26
 
55
 
56
  Project maintained on github at [pubsubhubbub/wordpress-pubsubhubbub](https://github.com/pubsubhubbub/wordpress-pubsubhubbub).
57
 
58
+ = 2.1.0 =
59
+
60
+ * save pinged URLs to add correct headers
61
+
62
  = 2.0.0 =
63
+
64
  * Complete rewrite
65
  * Support WebSub
66
 
67
  = 1.0.0 =
68
+
69
  * First attempt
70
 
71
  == Upgrade Notice ==