diff --git a/wp-content/plugins/pubsubhubbub/publisher.php b/wp-content/plugins/pubsubhubbub/publisher.php index f176a9b8a4cb552feb52296168c3270da3f91ed6..1d8e7a65b917532a342f078d1e4b21549c713b5f 100644 --- a/wp-content/plugins/pubsubhubbub/publisher.php +++ b/wp-content/plugins/pubsubhubbub/publisher.php @@ -1,86 +1,89 @@ <?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 -class Publisher { - - protected $hub_url; - protected $last_response; - - // 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; - } +/** + * a pubsubhubbub publisher + * + * @author Josh Fraser + * @author Matthias Pfefferle + */ +class PshbPublisher { + protected $hub_url; + protected $last_response; - // accepts either a single url or an array of urls - public function publish_update($topic_urls, $http_function = false) { - 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)) - throw new Exception('The specified topic url does not appear to be valid: '.$topic_url); - - // append the topic url parameters - $post_string .= "&hub.url=".urlencode($topic_url); - } - - // make the http post request and return true/false - // easy to over-write to use your own http function - if ($http_function) - return $http_function($this->hub_url,$post_string); - else - return $this->http_post($this->hub_url,$post_string); - } + // create a new Publisher + public function __construct($hub_url) { - // returns any error message from the latest request - public function last_response() { - return $this->last_response; - } - - // default http function that uses curl to post to the hub endpoint - private function http_post($url, $post_string) { - - // add any additional curl options here - $options = array(CURLOPT_URL => $url, - CURLOPT_POST => true, - CURLOPT_POSTFIELDS => $post_string, - CURLOPT_USERAGENT => "PubSubHubbub-Publisher-PHP/1.0"); - - $ch = curl_init(); - curl_setopt_array($ch, $options); - - $response = curl_exec($ch); - $this->last_response = $response; - $info = curl_getinfo($ch); - - curl_close($ch); - - // all good - if ($info['http_code'] == 204) - return true; - return false; + 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 + public function publish_update($topic_urls, $http_function = false) { + 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)) + throw new Exception('The specified topic url does not appear to be valid: '.$topic_url); + + // append the topic url parameters + $post_string .= "&hub.url=".urlencode($topic_url); + } + + // make the http post request and return true/false + // easy to over-write to use your own http function + if ($http_function) + return $http_function($this->hub_url,$post_string); + else + return $this->http_post($this->hub_url,$post_string); + } + + // returns any error message from the latest request + public function last_response() { + return $this->last_response; + } + + // default http function that uses curl to post to the hub endpoint + private function http_post($url, $post_string) { + // add any additional curl options here + $options = array(CURLOPT_URL => $url, + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $post_string, + CURLOPT_USERAGENT => "PubSubHubbub-Publisher-PHP/1.0"); + + $ch = curl_init(); + curl_setopt_array($ch, $options); + + $response = curl_exec($ch); + $this->last_response = $response; + $info = curl_getinfo($ch); + + curl_close($ch); + + // all good + if ($info['http_code'] == 204) + return true; + + return false; + } +} ?> \ No newline at end of file diff --git a/wp-content/plugins/pubsubhubbub/pubsubhubbub.php b/wp-content/plugins/pubsubhubbub/pubsubhubbub.php old mode 100644 new mode 100755 index 4029b443b698aaca74f78233603f8b58179c2504..bd7d62cb9db7cbc924ee83db308f60a29e18db95 --- a/wp-content/plugins/pubsubhubbub/pubsubhubbub.php +++ b/wp-content/plugins/pubsubhubbub/pubsubhubbub.php @@ -2,191 +2,307 @@ /* Plugin Name: PubSubHubbub Plugin URI: http://code.google.com/p/pubsubhubbub/ -Description: A better way to tell the world when your blog is updated. -Version: 1.5 -Author: Josh Fraser +Description: A better way to tell the world when your blog is updated. +Version: 1.6 +Author: Josh Fraser, Matthias Pfefferle Author Email: josh@eventvue.com -Author URI: http://www.joshfraser.com +Author URI: http://wordpress.org/extend/plugins/pubsubhubbub/ */ include("publisher.php"); +include("subscriber.php"); -/** - * beeing backwards compatible - * @deprecated - */ -function publish_to_hub($post_id, $feed_urls = null) { - pshb_publish_to_hub($post_id, $feed_urls); +// the ability for other plugins to hook into the PuSH code based on a +// fix by Stephen Paul Weber (http://singpolyma.net) +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 + } + } } -// function that is called whenever a new post is published -// the ability for other plugins to hook into the PuSH code was added by Stephen Paul Weber (http://singpolyma.net) -function pshb_publish_to_hub($post_id, $feed_urls = null) { - - // we want to notify the hub for every feed - if (!$feed_urls) { - $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'); - // customize default feeds - $feed_urls = apply_filters('pshb_feed_urls', $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 Publisher($hub_url); - // publish the update to each hub - if (!$p->publish_update($feed_urls)) { - // TODO: add better error handling here - } +// subscribe to a feed +// NOTE! THIS IS BETA STATE +function pshb_subscribe($url) { + try { + $s = new PshbSubscriber(site_url("/?pubsubhubbub=endpoint")); + $s->find_hub($url); + + $subscriptions = get_option('pubsub_subscribe'); + $subscriptions[] = $s->get_topic_url(); + update_option('pubsub_subscribe', array_unique($subscriptions)); + + if ($s->subscribe($s->get_topic_url()) !== false) { + return true; } - return $post_id; + } catch (Exception $e) { + return $e->getMessage(); + } + + return false; } -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.'" />'; +// unsubscribe from a feed +// NOTE! THIS IS BETA STATE +function pshb_unsubscribe($url) { + try { + $s = new PshbSubscriber(site_url("/?pubsubhubbub=endpoint")); + $s->find_hub($url); + + $to_unsubscribe = get_option('pubsub_unsubscribe'); + $to_unsubscribe[] = $s->get_topic_url(); + update_option('pubsub_unsubscribe', array_unique($to_unsubscribe)); + + if ($s->unsubscribe($s->get_topic_url()) !== false) { + return true; } + } catch (Exception $e) { + return $e->getMessage(); + } + + return false; } -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.'"/>'; - } +// function that is called whenever a new post is published +function pshb_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('rss_url'); + $feed_urls[] = get_bloginfo('rdf_url'); + $feed_urls[] = get_bloginfo('rss2_url'); + // customize default feeds + $feed_urls = apply_filters('pshb_feed_urls', $feed_urls); + + pshb_publish_to_hub($feed_urls); + + return $post_id; +} + +// function that is called whenever a new comment is published +function pshb_publish_comment($comment_id) { + // we want to notify the hub for every feed + $feed_urls = array(); + $feed_urls[] = get_bloginfo('comments_atom_url'); + $feed_urls[] = get_bloginfo('comments_rss2_url'); + // customize default feeds + $feed_urls = apply_filters('pshb_comment_feed_urls', $feed_urls); + + pshb_publish_to_hub($feed_urls); + + return $comment_id; +} + +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.'" />'; + } +} + +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.'"/>'; + } } function pshb_add_rdf_ns_link() { - echo 'xmlns:atom="http://www.w3.org/2005/Atom"'; + echo 'xmlns:atom="http://www.w3.org/2005/Atom"'; } // 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(); +function pshb_start_rss_link_tag() { + ob_start(); } // 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); +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 a link to our settings page in the WP menu function pshb_add_plugin_menu() { - add_options_page('PubSubHubbub Settings', 'PubSubHubbub', 8, __FILE__, 'pshb_add_settings_page'); + add_options_page('PubSubHubbub Settings', 'PubSubHubbub', 'administrator', __FILE__, 'pshb_add_settings_page'); } // get the endpoints from the wordpress options table // valid parameters are "publish" or "subscribe" function pshb_get_pubsub_endpoints() { - $endpoints = get_option('pubsub_endpoints'); - $hub_urls = explode("\n",$endpoints); + $endpoints = get_option('pubsub_endpoints'); + $hub_urls = explode("\n",$endpoints); - // if no values have been set, revert to the defaults (pubsubhubbub on app engine & superfeedr) - if (!$endpoints) { - $hub_urls[] = "http://pubsubhubbub.appspot.com"; - $hub_urls[] = "http://superfeedr.com/hubbub"; - } - - // 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]); - } + // if no values have been set, revert to the defaults (pubsubhubbub on app engine & superfeedr) + if (!$endpoints) { + $hub_urls[] = "http://pubsubhubbub.appspot.com"; + $hub_urls[] = "http://superfeedr.com/hubbub"; + } + + // 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]); } - - return $hub_urls; + } + + return $hub_urls; } // write the content for our settings page that allows you to define your endpoints function pshb_add_settings_page() { ?> - <div class="wrap"> - <h2>Define custom hubs</h2> - - <form method="post" action="options.php"> - <?php //wp_nonce_field('update-options'); ?> - <!-- starting --> - <?php settings_fields('my_settings_group'); ?> - <?php do_settings_sections('my_settings_section'); ?> - <!-- ending --> - - <?php - - // load the existing pubsub endpoint list from the wordpress options table - $pubsub_endpoints = trim(implode("\n",pshb_get_pubsub_endpoints()),"\n"); - - ?> - - <table class="form-table"> - - <tr valign="top"> - <th scope="row">Hubs (one per line)</th> - <td><textarea name="pubsub_endpoints" style='width:600px;height:100px'><?php echo $pubsub_endpoints; ?></textarea></td> - </tr> - - </table> - - <input type="hidden" name="action" value="update" /> - <input type="hidden" name="page_options" value="pubsub_endpoints" /> - - <p class="submit"> - <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> - </p> - - </form> - - <br /><br /> - <div style='background-color:#FFFEEB;border:1px solid #CCCCCC;padding:12px'> - <strong>Thanks for using PubSubHubbub!</strong><br /> - Visit these links to learn more about PubSubHubbub and the author of this plugin:<br /> - <ul> - <li><a href='http://www.onlineaspect.com'>Subscribe to Online Aspect</a></li> - <li><a href='http://www.twitter.com/joshfraser'>Follow Josh Fraser on twitter</a></li> - <li><a href='http://code.google.com/p/pubsubhubbub/'>Learn more about the PubSubHubbub protocol</a></li> - </ul> - </div> - - </div> + <div class="wrap"> + <h2>Define custom hubs</h2> + + <form method="post" action="options.php"> + <?php //wp_nonce_field('update-options'); ?> + <!-- starting --> + <?php settings_fields('my_settings_group'); ?> + <?php do_settings_sections('my_settings_section'); ?> + <!-- ending --> + + <?php + // load the existing pubsub endpoint list from the wordpress options table + $pubsub_endpoints = trim(implode("\n",pshb_get_pubsub_endpoints()),"\n"); + ?> + + <table class="form-table"> + + <tr valign="top"> + <th scope="row">Hubs (one per line)</th> + <td><textarea name="pubsub_endpoints" style='width:600px;height:100px'><?php echo $pubsub_endpoints; ?></textarea></td> + </tr> + + </table> + + <input type="hidden" name="action" value="update" /> + <input type="hidden" name="page_options" value="pubsub_endpoints" /> + + <p class="submit"> + <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> + </p> + + </form> + + <br /><br /> + <div style='background-color:#FFFEEB;border:1px solid #CCCCCC;padding:12px'> + <strong>Thanks for using PubSubHubbub!</strong><br /> + Visit these links to learn more about PubSubHubbub and the author of this plugin:<br /> + <ul> + <li><a href='http://www.onlineaspect.com'>Subscribe to Online Aspect</a></li> + <li><a href='http://www.twitter.com/joshfraser'>Follow Josh Fraser on twitter</a></li> + <li><a href='http://code.google.com/p/pubsubhubbub/'>Learn more about the PubSubHubbub protocol</a></li> + </ul> + </div> +</div> <?php } // add a settings link next to deactive / edit function pshb_add_settings_link( $links, $file ) { - if( $file == 'pubsubhubbub/pubsubhubbub.php' && function_exists( "admin_url" ) ) { - $settings_link = '<a href="' . admin_url( 'options-general.php?page=pubsubhubbub/pubsubhubbub' ) . '">' . __('Settings') . '</a>'; - array_unshift( $links, $settings_link ); // before other links - } - return $links; + if( $file == 'pubsubhubbub/pubsubhubbub.php' && function_exists( "admin_url" ) ) { + $settings_link = '<a href="' . admin_url( 'options-general.php?page=pubsubhubbub/pubsubhubbub' ) . '">' . __('Settings') . '</a>'; + array_unshift( $links, $settings_link ); // before other links + } + return $links; +} + +// adds some query vars +function pshb_query_var($vars) { + $vars[] = 'hub_mode'; + $vars[] = 'hub_challenge'; + $vars[] = 'hub_topic'; + $vars[] = 'hub_url'; + $vars[] = 'pubsubhubbub'; + return $vars; +} + +// parses the request +function pshb_parse_request() { + global $wp_query, $wp; + $query_vars = $wp->query_vars; + + // handle (un)subscribe requests + if (array_key_exists('hub_mode', $query_vars) + && in_array($query_vars['hub_mode'], array("subscribe", "unsubscribe")) + && isset($query_vars['hub_challenge'])) { + $list = get_option('pubsub_'.$query_vars['hub_mode']); + if (is_array($list) && in_array($query_vars['hub_topic'], $list)) { + // remove urls from option lists when unsubscribing + if ($query_vars['hub_mode'] == "unsubscribe") { + pshb_remove_from_option($query_vars['hub_topic'], "unsubscribe"); + pshb_remove_from_option($query_vars['hub_topic'], "subscribe"); + } + echo $query_vars['hub_challenge']; + exit; + } + // handle pushes + } elseif (array_key_exists('pubsubhubbub', $query_vars) + && $query_vars['pubsubhubbub'] == "endpoint" + && $request_body = @file_get_contents('php://input')) { + do_action('pshb_push', $request_body); + exit; + } +} + +// remove something from the option list +function pshb_remove_from_option($url, $option) { + if (!in_array($option, array("subscribe", "unsubscribe"))) { + return false; + } + + $list = get_option('pubsub_'.$option); + $key = array_search($url, $list); + unset($list[$key]); + update_option('pubsub_'.$option, $list); +} + +// adds link headers as defined in the curren v0.4 draft +// https://github.com/pubsubhubbub/PubSubHubbub/issues/2 +function pshb_template_redirect() { + if ((is_comment_feed() && !is_singular()) + || (is_feed() && !is_comment_feed() && !is_archive())) { + $hub_urls = pshb_get_pubsub_endpoints(); + foreach ($hub_urls as $hub_url) { + header('Link: <'.$hub_url.'>; rel=hub'); + } + header('Link: <'.( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'].'>; rel=self'); + } } // attach the handler that gets called every time you publish a post -add_action('publish_post', 'pshb_publish_to_hub'); +add_action('publish_post', 'pshb_publish_post'); +// attach the handler that gets called every time you get a comment +add_action('comment_post', 'pshb_publish_comment'); // add the link to our settings page in the WP menu structure add_action('admin_menu', 'pshb_add_plugin_menu'); // keep WPMU happy add_action('admin_init', 'pshb_register_my_settings'); function pshb_register_my_settings() { - register_setting('my_settings_group','pubsub_endpoints'); + register_setting('my_settings_group','pubsub_endpoints'); } // add the link tag that points to the hub in the header of our template... // to our atom feed add_action('atom_head', 'pshb_add_atom_link_tag'); +add_action('comments_atom_head', 'pshb_add_atom_link_tag'); // to our RSS 0.92 feed (requires a bit of a hack to include the ATOM namespace definition) add_action('do_feed_rss', 'pshb_start_rss_link_tag', 9); // run before output add_action('do_feed_rss', 'pshb_end_rss_link_tag', 11); // run after output @@ -196,9 +312,19 @@ add_action('rdf_ns', 'pshb_add_rdf_ns_link'); add_action('rdf_header', 'pshb_add_rss_link_tag'); // to our RSS 2 feed add_action('rss2_head', 'pshb_add_rss_link_tag'); +add_action('commentsrss2_head', 'pshb_add_rss_link_tag'); // to our main HTML header -- not sure if we want to include this long-term or not. add_action('wp_head', 'pshb_add_atom_link_tag'); +add_action('template_redirect', 'pshb_template_redirect'); add_filter('plugin_action_links', 'pshb_add_settings_link', 10, 2); +add_filter('query_vars', 'pshb_query_var'); +add_action('parse_request', 'pshb_parse_request'); -?> \ No newline at end of file +/** + * beeing backwards compatible + * @deprecated + */ +function publish_to_hub($deprecated = null, $feed_urls) { + pshb_publish_to_hub($feed_urls); +} \ No newline at end of file diff --git a/wp-content/plugins/pubsubhubbub/readme.txt b/wp-content/plugins/pubsubhubbub/readme.txt index da1cf965d760a55bebc111f4ecf4ba8b7d17b580..930f6cbf8b151f3941d40d853d4877bdf945198b 100644 --- a/wp-content/plugins/pubsubhubbub/readme.txt +++ b/wp-content/plugins/pubsubhubbub/readme.txt @@ -3,18 +3,18 @@ Contributors: joshfraz, pfefferle Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5426516 Tags: pubsubhubbub Requires at least: 2.5 -Tested up to: 3.0.4 -Stable tag: 1.5 +Tested up to: 3.3 +Stable tag: 1.6 A better way to tell the world when your blog is updated. == Description == -This [PubSubHubbub](http://code.google.com/p/pubsubhubbub/ "PubSubHubbub") plugin is a simple way to let people know in real-time when your blog is updated. PubSubHubbub is quickly gaining adoption and is already being used by Google Reader, Google Alerts, FriendFeed and more. +This [PubSubHubbub](http://code.google.com/p/pubsubhubbub/ "PubSubHubbub") plugin is a simple way to let people know in real-time when your blog is updated. PubSubHubbub is quickly gaining adoption and is already being used by Google Reader, Google Alerts, FriendFeed and more. This plugin: - -* Now supports multiple hubs! + +* Now supports multiple hubs! * Supports all of the feed formats used by WordPress, not just ATOM and RSS2 * Announces which hubs you are using by adding `<link rel="hub" ...>` declarations to your template header and ATOM feed * Adds `<atom:link rel="hub" ...>` to your RSS feeds along with the necessary XMLNS declaration for RSS 0.92/1.0 @@ -32,15 +32,13 @@ Please contact me if you operate a hub that you would like to be included as a d 2. Activate the plugin through the 'Plugins' menu in WordPress 3. Select custom hubs under your PubSubHubbub Settings (optional) -Note: PHP 5.0 or better is required. - == Frequently Asked Questions == = Where can I learn more about the PubSubHubbub protocol? = You can visit [PubSubHubbb on Google Code](http://code.google.com/p/pubsubhubbub/ "PubSubHubbb on Google Code") -= Where can I learn more about the author of this plugin? = += Where can I learn more about the authors of this plugin? = You can learn more about [Josh Fraser](http://www.joshfraser.com "Josh Fraser") at [Online Aspect](http://www.onlineaspect.com "Online Aspect") and [Matthias Pfefferle](http://pfefferle.org "Matthias Pfefferle") at [Notizblog](http://notizblog.org/ "Notizblog") @@ -51,6 +49,11 @@ and [Matthias Pfefferle](http://pfefferle.org "Matthias Pfefferle") at [Notizblo == Changelog == += 1.6 = +* Added comment-feed support +* Added simple subscriber functions +* Added link header + = 1.5 = * Added filter to modify $feed_urls * Re-Added Stephen Paul Webers changes diff --git a/wp-content/plugins/pubsubhubbub/subscriber.php b/wp-content/plugins/pubsubhubbub/subscriber.php new file mode 100755 index 0000000000000000000000000000000000000000..edc52294c17ebae5b9f17bf903d268135e4cd9cd --- /dev/null +++ b/wp-content/plugins/pubsubhubbub/subscriber.php @@ -0,0 +1,152 @@ +<?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 subscriber + * + * @author Josh Fraser + * @author Matthias Pfefferle + */ +class PshbSubscriber { + protected $hub_url; + protected $topic_url; + protected $callback_url; + protected $credentials; + // accepted values are "async" and "sync" + protected $verify = "sync"; + protected $verify_token; + protected $lease_seconds; + + // create a new Subscriber (credentials added for SuperFeedr support) + public function __construct($callback_url, $hub_url = null, $credentials = false) { + if ($hub_url && !preg_match("|^https?://|i",$hub_url)) + throw new Exception('The specified hub url does not appear to be valid: '.$hub_url); + + if (!isset($callback_url)) + throw new Exception('Please specify a callback'); + + $this->hub_url = $hub_url; + $this->callback_url = $callback_url; + $this->credentials = $credentials; + } + + public function subscribe($topic_url, $http_function = false) { + if (!$this->hub_url) { + $this->find_hub($topic_url); + } + + return $this->change_subscription("subscribe", $topic_url, $http_function = false); + } + + public function unsubscribe($topic_url, $http_function = false) { + return $this->change_subscription("unsubscribe", $topic_url, $http_function = false); + } + + // helper function since sub/unsub are handled the same way + private function change_subscription($mode, $topic_url, $http_function = false) { + if (!isset($topic_url)) + throw new Exception('Please specify a topic url'); + + // lightweight check that we're actually working w/ a valid url + if (!preg_match("|^https?://|i",$topic_url)) + throw new Exception('The specified topic url does not appear to be valid: '.$topic_url); + + // set the mode subscribe/unsubscribe + $post_string = "hub.mode=".$mode; + $post_string .= "&hub.callback=".urlencode($this->callback_url); + $post_string .= "&hub.verify=".$this->verify; + $post_string .= "&hub.verify_token=".$this->verify_token; + $post_string .= "&hub.lease_seconds=".$this->lease_seconds; + + // append the topic url parameters + $post_string .= "&hub.topic=".urlencode($topic_url); + + // make the http post request and return true/false + // easy to over-write to use your own http function + if ($http_function) + return $http_function($this->hub_url,$post_string); + else + return $this->http($this->hub_url,$post_string); + } + + // default http function that uses curl to post to the hub endpoint + private function http($url, $post_string = null) { + + // add any additional curl options here + $options = array(CURLOPT_URL => $url, + CURLOPT_USERAGENT => "PubSubHubbub-Subscriber-PHP/1.0", + CURLOPT_RETURNTRANSFER => true, + CURLOPT_FOLLOWLOCATION => true); + + if ($post_string) { + $options[CURLOPT_POST] = true; + $options[CURLOPT_POSTFIELDS] = $post_string; + } + + if ($this->credentials) + $options[CURLOPT_USERPWD] = $this->credentials; + + $ch = curl_init(); + curl_setopt_array($ch, $options); + + $response = curl_exec($ch); + $info = curl_getinfo($ch); + + // all good -- anything in the 200 range + if (substr($info['http_code'],0,1) == "2") { + return $response; + } + + return false; + } + + // + public function find_hub($topic_url) { + $self = $topic_url; + $xml = $this->http($topic_url); + if (!$xml) + throw new Exception('Please enter a valid URL'); + + $xml_parser = xml_parser_create(''); + $xml_values = array(); + $xml_tags = array(); + + if(!$xml_parser) + throw new Exception('Your webserver doesn\'t support xml-parsing'); + + xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); + xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0); + xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 1); + xml_parse_into_struct($xml_parser, trim($xml), $xml_values); + xml_parser_free($xml_parser); + + $hubs = array(); + + foreach ($xml_values as $value) { + // get hubs + if ($value['attributes']['rel'] == 'hub') { + $hubs[] = $value['attributes']['href']; + } + // get self url + if ($value['attributes']['rel'] == 'self') { + $self = $value['attributes']['href']; + } + } + + if (count($hubs) >= 1) + $this->hub_url = $hubs[0]; + else + throw new Exception('This feed doesn\'t reference a hub url'); + + $this->topic_url = $self; + } + + public function get_topic_url() { + return $this->topic_url; + } +} +?> \ No newline at end of file