WebSub/PubSubHubbub - Version 2.2.0

Version Description

  • fixed a discovery bug
  • changed http client
Download this release

Release Info

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

Code changes from version 2.1.0 to 2.2.0

includes/functions.php CHANGED
@@ -37,8 +37,10 @@ function pubsubhubbub_get_hubs() {
37
 
38
  // if no values have been set, revert to the defaults (websub on app engine & superfeedr)
39
  if ( ! $endpoints || ! $hub_urls || ! is_array( $hub_urls ) ) {
40
- $hub_urls[] = 'https://pubsubhubbub.appspot.com';
41
- $hub_urls[] = 'https://pubsubhubbub.superfeedr.com';
 
 
42
  }
43
 
44
  // clean out any blank values
@@ -124,5 +126,5 @@ function pubsubhubbub_get_self_link() {
124
  return home_url( add_query_arg( null, null ) );
125
  }
126
 
127
- return $matches[0];
128
  }
37
 
38
  // if no values have been set, revert to the defaults (websub on app engine & superfeedr)
39
  if ( ! $endpoints || ! $hub_urls || ! is_array( $hub_urls ) ) {
40
+ $hub_urls = array(
41
+ 'https://pubsubhubbub.appspot.com',
42
+ 'https://pubsubhubbub.superfeedr.com',
43
+ );
44
  }
45
 
46
  // clean out any blank values
126
  return home_url( add_query_arg( null, null ) );
127
  }
128
 
129
+ return current( $matches );
130
  }
includes/pubsubhubbub-publisher.php CHANGED
@@ -13,7 +13,6 @@
13
  */
14
  class PubSubHubbub_Publisher {
15
  protected $hub_url;
16
- protected $last_response;
17
 
18
  // create a new Publisher
19
  public function __construct( $hub_url ) {
@@ -29,8 +28,12 @@ class PubSubHubbub_Publisher {
29
  $this->hub_url = $hub_url;
30
  }
31
 
32
- // accepts either a single url or an array of urls
33
- public function publish_update( $topic_urls, $http_function = false ) {
 
 
 
 
34
  if ( ! isset( $topic_urls ) ) {
35
  throw new Exception( 'Please specify a topic url' );
36
  }
@@ -45,53 +48,23 @@ class PubSubHubbub_Publisher {
45
  // loop through each topic url
46
  foreach ( $topic_urls as $topic_url ) {
47
  // lightweight check that we're actually working w/ a valid url
48
- if ( ! preg_match( '|^https?://|i', $topic_url ) ) {
49
- throw new Exception( 'The specified topic url does not appear to be valid: ' . $topic_url );
 
50
  }
51
-
52
- // append the topic url parameters
53
- $post_string .= '&hub.url=' . urlencode( $topic_url );
54
- }
55
-
56
- // make the http post request and return true/false
57
- // easy to over-write to use your own http function
58
- if ( $http_function ) {
59
- return $http_function( $this->hub_url, $post_string );
60
- } else {
61
- return $this->http_post( $this->hub_url, $post_string );
62
  }
63
- }
64
-
65
- // returns any error message from the latest request
66
- public function last_response() {
67
- return $this->last_response;
68
- }
69
 
70
- // default http function that uses curl to post to the hub endpoint
71
- private function http_post( $url, $post_string ) {
72
- // add any additional curl options here
73
- $options = array(
74
- CURLOPT_URL => $url,
75
- CURLOPT_POST => true,
76
- CURLOPT_POSTFIELDS => $post_string,
77
- CURLOPT_RETURNTRANSFER => true,
78
- CURLOPT_USERAGENT => 'PubSubHubbub-Publisher-PHP/1.0',
79
  );
80
 
81
- $ch = curl_init();
82
- curl_setopt_array( $ch, $options );
83
-
84
- $response = curl_exec( $ch );
85
- $this->last_response = $response;
86
- $info = curl_getinfo( $ch );
87
-
88
- curl_close( $ch );
89
-
90
- // all good
91
- if ( 204 == $info['http_code'] ) {
92
- return true;
93
- }
94
-
95
- return false;
96
  }
97
  }
13
  */
14
  class PubSubHubbub_Publisher {
15
  protected $hub_url;
 
16
 
17
  // create a new Publisher
18
  public function __construct( $hub_url ) {
28
  $this->hub_url = $hub_url;
29
  }
30
 
31
+ /**
32
+ * accepts either a single url or an array of urls
33
+ *
34
+ * @param string|array $topic_urls a single topic url or an array of topic urls
35
+ */
36
+ public function publish_update( $topic_urls ) {
37
  if ( ! isset( $topic_urls ) ) {
38
  throw new Exception( 'Please specify a topic url' );
39
  }
48
  // loop through each topic url
49
  foreach ( $topic_urls as $topic_url ) {
50
  // lightweight check that we're actually working w/ a valid url
51
+ if ( preg_match( '|^https?://|i', $topic_url ) ) {
52
+ // append the topic url parameters
53
+ $post_string .= '&hub.url=' . esc_url( $topic_url );
54
  }
 
 
 
 
 
 
 
 
 
 
 
55
  }
 
 
 
 
 
 
56
 
57
+ $wp_version = get_bloginfo( 'version' );
58
+ $user_agent = apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
59
+ $args = array(
60
+ 'timeout' => 100,
61
+ 'limit_response_size' => 1048576,
62
+ 'redirection' => 20,
63
+ 'user-agent' => "$user_agent; PubSubHubbub/WebSub",
64
+ 'body' => $post_string,
 
65
  );
66
 
67
+ // make the http post request
68
+ return wp_remote_post( $this->hub_url, $args );
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  }
70
  }
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.1.0
7
  * Author: Matthias Pfefferle
8
  * Author URI: https://notiz.blog/
9
  * License: MIT
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.2.0
7
  * Author: Matthias Pfefferle
8
  * Author URI: https://notiz.blog/
9
  * License: MIT
readme.txt CHANGED
@@ -4,7 +4,7 @@ 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
 
@@ -55,6 +55,11 @@ You can visit [PubsSubHubbub on Github](https://github.com/pubsubhubbub "PubsSub
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
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.2.0
8
 
9
  A better way to tell the world when your blog is updated.
10
 
55
 
56
  Project maintained on github at [pubsubhubbub/wordpress-pubsubhubbub](https://github.com/pubsubhubbub/wordpress-pubsubhubbub).
57
 
58
+ = 2.2.0 =
59
+
60
+ * fixed a discovery bug
61
+ * changed http client
62
+
63
  = 2.1.0 =
64
 
65
  * save pinged URLs to add correct headers