? 617054-7_pubsub.patch ? libraries/simplepie.inc ? libraries/subscriber.php Index: feeds.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/feeds.module,v retrieving revision 1.18 diff -u -p -r1.18 feeds.module --- feeds.module 11 Nov 2009 03:27:54 -0000 1.18 +++ feeds.module 11 Nov 2009 04:07:33 -0000 @@ -136,6 +136,12 @@ function feeds_menu() { 'file' => 'feeds.pages.inc', ); } + $items['feeds/pubsub/notify/%feeds_importer/%'] = array( + 'page callback' => 'feeds_pubsub_notify', + 'page arguments' => array(3, 4), + 'file' => 'feeds.pages.inc', + 'type' => MENU_CALLBACK, + ); return $items; } Index: feeds.pages.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/feeds.pages.inc,v retrieving revision 1.5 diff -u -p -r1.5 feeds.pages.inc --- feeds.pages.inc 21 Oct 2009 23:18:30 -0000 1.5 +++ feeds.pages.inc 11 Nov 2009 04:07:33 -0000 @@ -40,6 +40,15 @@ function feeds_page() { } /** + * Callback for pubsub notifications. + */ +function feeds_pubsub_notify($feed, $type) { + if ($feed->fetcher instanceof FeedsSubscriberInterface) { + $feed->notify($type); + } +} + +/** * Render a feeds import form on import/[config] pages. */ function feeds_import_form(&$form_state, $feed_id) { Index: feeds.plugins.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/feeds.plugins.inc,v retrieving revision 1.2 diff -u -p -r1.2 feeds.plugins.inc --- feeds.plugins.inc 21 Oct 2009 20:01:18 -0000 1.2 +++ feeds.plugins.inc 11 Nov 2009 04:07:33 -0000 @@ -66,6 +66,17 @@ function _feeds_feeds_plugins() { 'path' => $path, ), ); + $info['FeedsPubSubFetcher'] = array( + 'name' => 'PubSub Fetcher', + 'description' => 'Download content from a URL on notification.', + 'help' => 'Download content from a URL on notification. Currently supports only PubSubHubbub.', + 'handler' => array( + 'parent' => 'FeedsHTTPFetcher', + 'class' => 'FeedsPubSubFetcher', + 'file' => 'FeedsPubSubFetcher.inc', + 'path' => $path, + ), + ); $info['FeedsFileFetcher'] = array( 'name' => 'File upload', 'description' => 'Upload content from a local file.', Index: plugins/FeedsFetcher.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/plugins/FeedsFetcher.inc,v retrieving revision 1.1 diff -u -p -r1.1 FeedsFetcher.inc --- plugins/FeedsFetcher.inc 20 Oct 2009 21:03:08 -0000 1.1 +++ plugins/FeedsFetcher.inc 11 Nov 2009 04:07:33 -0000 @@ -13,6 +13,21 @@ class FeedsFetcherResult extends FeedsRe } /** + * In Publish/Subscribe setups, FeedsFetchers can be notified of new content. + * Fetchers that would like to receive such notifications need to implement + * FeedsSubscriberInterface. For an example, see FeedsPubSubFetcher. + */ +interface FeedsSubscriberInterface { + /** + * Notify the fetcher. + * + * @param $type + * String that identifies the type of notification + */ + public function notify($type); +} + +/** * Abstract class, defines shared functionality between fetchers. * * Implements FeedsSourceInfoInterface to expose source forms to Feeds. Index: plugins/FeedsPubSubFetcher.inc =================================================================== RCS file: plugins/FeedsPubSubFetcher.inc diff -N plugins/FeedsPubSubFetcher.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ plugins/FeedsPubSubFetcher.inc 11 Nov 2009 04:07:33 -0000 @@ -0,0 +1,89 @@ +getConfigFor($this); + $url = $source_config['source']; + + feeds_include_library('http_request.inc', 'http_request'); + if ($this->config['auto_detect_feeds']) { + $result = http_request_get_common_syndication($url); + } + else { + $result = http_request_get($url); + } + if ($result->code != 200) { + throw new Exception(t('Download of @url failed with code !code.', array('@url' => $url, '!code' => $result->code))); + } + return new FeedsFetcherResult($result->data, 'text/xml'); + } + + /** + * Clear caches. + */ + public function clear(FeedsSource $source) { + $source_config = $source->getConfigFor($this); + $url = $source_config['source']; + feeds_include_library('http_request.inc', 'http_request'); + http_request_clear_cache($url); + } + + /** + * Expose source form. + */ + public function sourceForm($source_config) { + $form = array(); + $form['source'] = array( + '#type' => 'textfield', + '#title' => t('URL'), + '#description' => t('Enter a feed URL.'), + '#default_value' => isset($source_config['source']) ? $source_config['source'] : '', + '#required' => TRUE, + ); + return $form; + } + + /** + * Source form validate handler. + */ + public function sourceFormValidate(&$values) { + // @todo: retrieve feed, determine pubsub standard and hub URL. + + // Submit feed to Google PuSH hub. + $hub_url = "http://pubsubhubbub.appspot.com"; + $callback_url = url('feeds/pubsub/notify/'. $this->id .'/push'); + feeds_include_library('subscriber.php'); + $s = new Subscriber($hub_url, $callback_url); + $s->subscribe($values['source']); + unset($s); + } +} +