WebSub/PubSubHubbub - Version 1.6.4

Version Description

  • removed pubsubhubbub client
  • improvements for a better PuSH v0.4 support
  • fixed small bugs
Download this release

Release Info

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

Code changes from version 1.6.3 to 1.6.4

pubsubhubbub-php/publisher.php → publisher.php RENAMED
@@ -1,7 +1,7 @@
1
  <?php
2
  // a PHP client library for pubsubhubbub
3
  // as defined at http://code.google.com/p/pubsubhubbub/
4
- // written by Josh Fraser | joshfraser.com | joshfraz@gmail.com
5
  // modified by Matthias Pfefferle | notizblog.org | matthias@pfefferle.org
6
  // Released under Apache License 2.0
7
 
1
  <?php
2
  // a PHP client library for pubsubhubbub
3
  // as defined at http://code.google.com/p/pubsubhubbub/
4
+ // written by Josh Fraser | joshfraser.com | josh@eventvue.com
5
  // modified by Matthias Pfefferle | notizblog.org | matthias@pfefferle.org
6
  // Released under Apache License 2.0
7
 
pubsubhubbub-php/subscriber.php DELETED
@@ -1,153 +0,0 @@
1
- <?php
2
- // a PHP client library for pubsubhubbub
3
- // as defined at http://code.google.com/p/pubsubhubbub/
4
- // written by Josh Fraser | joshfraser.com | joshfraz@gmail.com
5
- // modified by Matthias Pfefferle | notizblog.org | matthias@pfefferle.org
6
- // Released under Apache License 2.0
7
-
8
- /**
9
- * a pubsubhubbub subscriber
10
- *
11
- * @author Josh Fraser
12
- * @author Matthias Pfefferle
13
- */
14
- class PshbSubscriber {
15
- protected $hub_url;
16
- protected $topic_url;
17
- protected $callback_url;
18
- protected $credentials;
19
- // accepted values are "async" and "sync"
20
- protected $verify = "async";
21
- protected $verify_token;
22
- protected $lease_seconds;
23
-
24
- // create a new Subscriber (credentials added for SuperFeedr support)
25
- public function __construct($callback_url, $hub_url = null, $credentials = false) {
26
- if ($hub_url && !preg_match("|^https?://|i",$hub_url))
27
- throw new Exception('The specified hub url does not appear to be valid: '.$hub_url);
28
-
29
- if (!isset($callback_url))
30
- throw new Exception('Please specify a callback');
31
-
32
- $this->hub_url = $hub_url;
33
- $this->callback_url = $callback_url;
34
- $this->credentials = $credentials;
35
- }
36
-
37
- public function subscribe($topic_url, $http_function = false) {
38
- if (!$this->hub_url) {
39
- $this->find_hub($topic_url);
40
- }
41
-
42
- return $this->change_subscription("subscribe", $topic_url, $http_function = false);
43
- }
44
-
45
- public function unsubscribe($topic_url, $http_function = false) {
46
- return $this->change_subscription("unsubscribe", $topic_url, $http_function = false);
47
- }
48
-
49
- // helper function since sub/unsub are handled the same way
50
- private function change_subscription($mode, $topic_url, $http_function = false) {
51
- if (!isset($topic_url))
52
- throw new Exception('Please specify a topic url');
53
-
54
- // lightweight check that we're actually working w/ a valid url
55
- if (!preg_match("|^https?://|i",$topic_url))
56
- throw new Exception('The specified topic url does not appear to be valid: '.$topic_url);
57
-
58
- // set the mode subscribe/unsubscribe
59
- $post_string = "hub.mode=".$mode;
60
- $post_string .= "&hub.callback=".urlencode($this->callback_url);
61
- $post_string .= "&hub.verify=".$this->verify;
62
- $post_string .= "&hub.verify_token=".$this->verify_token;
63
- $post_string .= "&hub.lease_seconds=".$this->lease_seconds;
64
-
65
- // append the topic url parameters
66
- $post_string .= "&hub.topic=".urlencode($topic_url);
67
-
68
- // make the http post request and return true/false
69
- // easy to over-write to use your own http function
70
- if ($http_function)
71
- return $http_function($this->hub_url,$post_string);
72
- else
73
- return $this->http($this->hub_url,$post_string);
74
- }
75
-
76
- // default http function that uses curl to post to the hub endpoint
77
- private function http($url, $post_string = null) {
78
-
79
- // add any additional curl options here
80
- $options = array(CURLOPT_URL => $url,
81
- CURLOPT_USERAGENT => "PubSubHubbub-Subscriber-PHP/1.0",
82
- CURLOPT_RETURNTRANSFER => true,
83
- CURLOPT_FOLLOWLOCATION => true);
84
-
85
- if ($post_string) {
86
- $options[CURLOPT_POST] = true;
87
- $options[CURLOPT_POSTFIELDS] = $post_string;
88
- }
89
-
90
- if ($this->credentials)
91
- $options[CURLOPT_USERPWD] = $this->credentials;
92
-
93
- $ch = curl_init();
94
- curl_setopt_array($ch, $options);
95
-
96
- $response = curl_exec($ch);
97
- $info = curl_getinfo($ch);
98
-
99
- // all good -- anything in the 200 range
100
- if (substr($info['http_code'],0,1) == "2") {
101
- return $response;
102
- }
103
-
104
- return false;
105
- }
106
-
107
- // discover the hub url
108
- public function find_hub($topic_url) {
109
- $self = $topic_url;
110
- $xml = $this->http($topic_url);
111
- if (!$xml)
112
- throw new Exception('Please enter a valid URL');
113
-
114
- $xml_parser = xml_parser_create('');
115
- $xml_values = array();
116
- $xml_tags = array();
117
-
118
- if(!$xml_parser)
119
- throw new Exception('Your webserver doesn\'t support xml-parsing');
120
-
121
- xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
122
- xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
123
- xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 1);
124
- xml_parse_into_struct($xml_parser, trim($xml), $xml_values);
125
- xml_parser_free($xml_parser);
126
-
127
- $hubs = array();
128
-
129
- foreach ($xml_values as $value) {
130
- // get hubs
131
- if ($value['attributes']['rel'] == 'hub') {
132
- $hubs[] = $value['attributes']['href'];
133
- }
134
- // get self url
135
- if ($value['attributes']['rel'] == 'self') {
136
- $self = $value['attributes']['href'];
137
- }
138
- }
139
-
140
- if (count($hubs) >= 1)
141
- $this->hub_url = $hubs[0];
142
- else
143
- throw new Exception('This feed doesn\'t reference a hub url');
144
-
145
- $this->topic_url = $self;
146
- }
147
-
148
- // getter
149
- public function get_topic_url() {
150
- return $this->topic_url;
151
- }
152
- }
153
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pubsubhubbub.php CHANGED
@@ -3,14 +3,13 @@
3
  Plugin Name: PubSubHubbub
4
  Plugin URI: http://code.google.com/p/pubsubhubbub/
5
  Description: A better way to tell the world when your blog is updated.
6
- Version: 1.6.3
7
  Author: Josh Fraser, Matthias Pfefferle
8
  Author Email: joshfraz@gmail.com
9
  Author URI: http://wordpress.org/extend/plugins/pubsubhubbub/
10
  */
11
 
12
- include("pubsubhubbub-php/publisher.php");
13
- include("pubsubhubbub-php/subscriber.php");
14
 
15
  // the ability for other plugins to hook into the PuSH code based on a
16
  // fix by Stephen Paul Weber (http://singpolyma.net)
@@ -29,58 +28,10 @@ function pshb_publish_to_hub($feed_urls) {
29
  }
30
  }
31
 
32
- // subscribe to a feed
33
- // NOTE! THIS IS BETA STATE
34
- function pshb_subscribe($url) {
35
- try {
36
- $s = new PshbSubscriber(site_url("/?pubsubhubbub=endpoint"));
37
- $s->find_hub($url);
38
-
39
- $subscriptions = get_option('pubsub_subscribe');
40
- $subscriptions[] = $s->get_topic_url();
41
- update_option('pubsub_subscribe', array_unique($subscriptions));
42
-
43
- if ($s->subscribe($s->get_topic_url()) !== false) {
44
- return true;
45
- }
46
- } catch (Exception $e) {
47
- return $e->getMessage();
48
- }
49
-
50
- return false;
51
- }
52
-
53
- // unsubscribe from a feed
54
- // NOTE! THIS IS BETA STATE
55
- function pshb_unsubscribe($url) {
56
- try {
57
- $s = new PshbSubscriber(site_url("/?pubsubhubbub=endpoint"));
58
- $s->find_hub($url);
59
-
60
- $to_unsubscribe = get_option('pubsub_unsubscribe');
61
- $to_unsubscribe[] = $s->get_topic_url();
62
- update_option('pubsub_unsubscribe', array_unique($to_unsubscribe));
63
-
64
- if ($s->unsubscribe($s->get_topic_url()) !== false) {
65
- return true;
66
- }
67
- } catch (Exception $e) {
68
- return $e->getMessage();
69
- }
70
-
71
- return false;
72
- }
73
-
74
  // function that is called whenever a new post is published
75
  function pshb_publish_post($post_id) {
76
- // we want to notify the hub for every feed
77
- $feed_urls = array();
78
- $feed_urls[] = get_bloginfo('atom_url');
79
- $feed_urls[] = get_bloginfo('rss_url');
80
- $feed_urls[] = get_bloginfo('rdf_url');
81
- $feed_urls[] = get_bloginfo('rss2_url');
82
  // customize default feeds
83
- $feed_urls = apply_filters('pshb_feed_urls', $feed_urls);
84
 
85
  pshb_publish_to_hub($feed_urls);
86
 
@@ -90,12 +41,8 @@ add_action('publish_post', 'pshb_publish_post');
90
 
91
  // function that is called whenever a new comment is published
92
  function pshb_publish_comment($comment_id) {
93
- // we want to notify the hub for every feed
94
- $feed_urls = array();
95
- $feed_urls[] = get_bloginfo('comments_atom_url');
96
- $feed_urls[] = get_bloginfo('comments_rss2_url');
97
  // customize default feeds
98
- $feed_urls = apply_filters('pshb_comment_feed_urls', $feed_urls);
99
 
100
  pshb_publish_to_hub($feed_urls);
101
 
@@ -130,7 +77,6 @@ function pshb_add_rdf_ns_link() {
130
  }
131
  add_action('rdf_ns', 'pshb_add_rdf_ns_link');
132
 
133
-
134
  // hack to add the atom definition to the RSS feed
135
  // start capturing the feed output. this is run at priority 9 (before output)
136
  function pshb_start_rss_link_tag() {
@@ -151,7 +97,7 @@ add_action('do_feed_rss', 'pshb_end_rss_link_tag', 11); // run after output
151
 
152
  // add a link to our settings page in the WP menu
153
  function pshb_add_plugin_menu() {
154
- add_options_page('PubSubHubbub Settings', 'PubSubHubbub', 'administrator', __FILE__, 'pshb_add_settings_page');
155
  }
156
  add_action('admin_menu', 'pshb_add_plugin_menu');
157
 
@@ -179,6 +125,28 @@ function pshb_get_pubsub_endpoints() {
179
  return $hub_urls;
180
  }
181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  // write the content for our settings page that allows you to define your endpoints
183
  function pshb_add_settings_page() { ?>
184
  <div class="wrap">
@@ -249,57 +217,23 @@ function pshb_query_var($vars) {
249
  }
250
  add_filter('query_vars', 'pshb_query_var');
251
 
252
- // parses the request
253
- function pshb_parse_request() {
254
- global $wp_query, $wp;
255
- $query_vars = $wp->query_vars;
256
-
257
- // handle (un)subscribe requests
258
- if (array_key_exists('hub_mode', $query_vars)
259
- && in_array($query_vars['hub_mode'], array("subscribe", "unsubscribe"))
260
- && isset($query_vars['hub_challenge'])) {
261
- $list = get_option('pubsub_'.$query_vars['hub_mode']);
262
- if (is_array($list) && in_array($query_vars['hub_topic'], $list)) {
263
- // remove urls from option lists when unsubscribing
264
- if ($query_vars['hub_mode'] == "unsubscribe") {
265
- pshb_remove_from_option($query_vars['hub_topic'], "unsubscribe");
266
- pshb_remove_from_option($query_vars['hub_topic'], "subscribe");
267
- }
268
- echo $query_vars['hub_challenge'];
269
- exit;
270
- }
271
- // handle pushes
272
- } elseif (array_key_exists('pubsubhubbub', $query_vars)
273
- && $query_vars['pubsubhubbub'] == "endpoint"
274
- && $request_body = @file_get_contents('php://input')) {
275
- do_action('pshb_push', $request_body);
276
- exit;
277
- }
278
- }
279
- add_action('parse_request', 'pshb_parse_request');
280
-
281
- // remove something from the option list
282
- function pshb_remove_from_option($url, $option) {
283
- if (!in_array($option, array("subscribe", "unsubscribe"))) {
284
- return false;
285
- }
286
-
287
- $list = get_option('pubsub_'.$option);
288
- $key = array_search($url, $list);
289
- unset($list[$key]);
290
- update_option('pubsub_'.$option, $list);
291
- }
292
-
293
  // adds link headers as defined in the curren v0.4 draft
294
  // https://github.com/pubsubhubbub/PubSubHubbub/issues/2
295
  function pshb_template_redirect() {
296
- if ((is_comment_feed() && !is_singular())
297
- || (is_feed() && !is_comment_feed() && !is_archive())) {
 
 
 
 
 
 
 
298
  $hub_urls = pshb_get_pubsub_endpoints();
299
  foreach ($hub_urls as $hub_url) {
300
- header('Link: <'.$hub_url.'>; rel=hub', false);
301
  }
302
- header('Link: <'.( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'].'>; rel=self', false);
303
  }
304
  }
305
  add_action('template_redirect', 'pshb_template_redirect');
3
  Plugin Name: PubSubHubbub
4
  Plugin URI: http://code.google.com/p/pubsubhubbub/
5
  Description: A better way to tell the world when your blog is updated.
6
+ Version: 1.6.4
7
  Author: Josh Fraser, Matthias Pfefferle
8
  Author Email: joshfraz@gmail.com
9
  Author URI: http://wordpress.org/extend/plugins/pubsubhubbub/
10
  */
11
 
12
+ include("publisher.php");
 
13
 
14
  // the ability for other plugins to hook into the PuSH code based on a
15
  // fix by Stephen Paul Weber (http://singpolyma.net)
28
  }
29
  }
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  // function that is called whenever a new post is published
32
  function pshb_publish_post($post_id) {
 
 
 
 
 
 
33
  // customize default feeds
34
+ $feed_urls = pshb_get_feed_urls();
35
 
36
  pshb_publish_to_hub($feed_urls);
37
 
41
 
42
  // function that is called whenever a new comment is published
43
  function pshb_publish_comment($comment_id) {
 
 
 
 
44
  // customize default feeds
45
+ $feed_urls = pshb_get_comment_feed_urls();
46
 
47
  pshb_publish_to_hub($feed_urls);
48
 
77
  }
78
  add_action('rdf_ns', 'pshb_add_rdf_ns_link');
79
 
 
80
  // hack to add the atom definition to the RSS feed
81
  // start capturing the feed output. this is run at priority 9 (before output)
82
  function pshb_start_rss_link_tag() {
97
 
98
  // add a link to our settings page in the WP menu
99
  function pshb_add_plugin_menu() {
100
+ add_options_page('PubSubHubbub Settings', 'PubSubHubbub', 'administrator', 'pubsubhubbub', 'pshb_add_settings_page');
101
  }
102
  add_action('admin_menu', 'pshb_add_plugin_menu');
103
 
125
  return $hub_urls;
126
  }
127
 
128
+ // helper function to get feed urls
129
+ function pshb_get_feed_urls() {
130
+ // we want to notify the hub for every feed
131
+ $feed_urls = array();
132
+ $feed_urls[] = get_bloginfo('atom_url');
133
+ $feed_urls[] = get_bloginfo('rss_url');
134
+ $feed_urls[] = get_bloginfo('rdf_url');
135
+ $feed_urls[] = get_bloginfo('rss2_url');
136
+
137
+ return apply_filters('pshb_feed_urls', $feed_urls);
138
+ }
139
+
140
+ // helper function to get comment-feed urls
141
+ function pshb_get_comment_feed_urls() {
142
+ // we want to notify the hub for every feed
143
+ $feed_urls = array();
144
+ $feed_urls[] = get_bloginfo('comments_atom_url');
145
+ $feed_urls[] = get_bloginfo('comments_rss2_url');
146
+
147
+ return apply_filters('pshb_comment_feed_urls', $feed_urls);
148
+ }
149
+
150
  // write the content for our settings page that allows you to define your endpoints
151
  function pshb_add_settings_page() { ?>
152
  <div class="wrap">
217
  }
218
  add_filter('query_vars', 'pshb_query_var');
219
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
  // adds link headers as defined in the curren v0.4 draft
221
  // https://github.com/pubsubhubbub/PubSubHubbub/issues/2
222
  function pshb_template_redirect() {
223
+ global $wp;
224
+
225
+ $feed_urls = pshb_get_feed_urls();
226
+ $comment_feed_urls = pshb_get_comment_feed_urls();
227
+
228
+ $urls = array_unique(array_merge($feed_urls, $comment_feed_urls));
229
+ $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
230
+
231
+ if (in_array($current_url, $urls)) {
232
  $hub_urls = pshb_get_pubsub_endpoints();
233
  foreach ($hub_urls as $hub_url) {
234
+ header('Link: <'.$hub_url.'>; rel="hub"', false);
235
  }
236
+ header('Link: <'.$current_url.'>; rel="self"', false);
237
  }
238
  }
239
  add_action('template_redirect', 'pshb_template_redirect');
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: joshfraz, pfefferle
3
  Tags: pubsubhubbub
4
  Requires at least: 2.5
5
  Tested up to: 3.5.1
6
- Stable tag: 1.6.3
7
 
8
  A better way to tell the world when your blog is updated.
9
 
@@ -17,6 +17,7 @@ This plugin:
17
  * Supports multi-user installations (Wordpress MU)
18
  * Supports multiple hubs
19
  * Supports all of the feed formats used by WordPress, not just ATOM and RSS2
 
20
  * Announces which hubs you are using by adding `<link rel="hub" ...>` declarations to your template header and ATOM feed
21
  * Adds `<atom:link rel="hub" ...>` to your RSS feeds along with the necessary XMLNS declaration for RSS 0.92/1.0
22
 
@@ -50,6 +51,11 @@ and [Matthias Pfefferle](http://pfefferle.org "Matthias Pfefferle") at [Notizblo
50
 
51
  == Changelog ==
52
 
 
 
 
 
 
53
  = 1.6.3 =
54
  * Update hub URL for SuperFeedr (now pubsubhubbub.superfeedr.com)
55
  * Update credits and documentation
3
  Tags: pubsubhubbub
4
  Requires at least: 2.5
5
  Tested up to: 3.5.1
6
+ Stable tag: 1.6.4
7
 
8
  A better way to tell the world when your blog is updated.
9
 
17
  * Supports multi-user installations (Wordpress MU)
18
  * Supports multiple hubs
19
  * Supports all of the feed formats used by WordPress, not just ATOM and RSS2
20
+ * Supports latest spec ([Version 0.4](https://pubsubhubbub.googlecode.com/git/pubsubhubbub-core-0.4.html))
21
  * Announces which hubs you are using by adding `<link rel="hub" ...>` declarations to your template header and ATOM feed
22
  * Adds `<atom:link rel="hub" ...>` to your RSS feeds along with the necessary XMLNS declaration for RSS 0.92/1.0
23
 
51
 
52
  == Changelog ==
53
 
54
+ = 1.6.4 =
55
+ * removed pubsubhubbub client
56
+ * improvements for a better PuSH v0.4 support
57
+ * fixed small bugs
58
+
59
  = 1.6.3 =
60
  * Update hub URL for SuperFeedr (now pubsubhubbub.superfeedr.com)
61
  * Update credits and documentation