class FeedsHTTPFetcher in Feeds 6
Same name and namespace in other branches
- 7.2 plugins/FeedsHTTPFetcher.inc \FeedsHTTPFetcher
- 7 plugins/FeedsHTTPFetcher.inc \FeedsHTTPFetcher
Fetches data via HTTP.
Hierarchy
- class \FeedsConfigurable
- class \FeedsPlugin implements FeedsSourceInterface
- class \FeedsFetcher
- class \FeedsHTTPFetcher
- class \FeedsFetcher
- class \FeedsPlugin implements FeedsSourceInterface
Expanded class hierarchy of FeedsHTTPFetcher
7 string references to 'FeedsHTTPFetcher'
- FeedsImporter::configDefaults in includes/
FeedsImporter.inc - Return defaults for feed configuration.
- FeedsRSStoDataTest::test in tests/
feeds_processor_data.test - Test node creation, refreshing/deleting feeds and feed items.
- FeedsWebTestCase::createImporterConfiguration in tests/
feeds.test - Create an importer configuration.
- feeds_fast_news_feeds_importer_default in feeds_fast_news/
feeds_fast_news.feeds_importer_default.inc - Implementation of hook_feeds_importer_default().
- feeds_news_feeds_importer_default in feeds_news/
feeds_news.feeds_importer_default.inc - Implementation of hook_feeds_importer_default().
File
- plugins/
FeedsHTTPFetcher.inc, line 42
View source
class FeedsHTTPFetcher extends FeedsFetcher {
/**
* Implements FeedsFetcher::fetch().
*/
public function fetch(FeedsSource $source) {
$source_config = $source
->getConfigFor($this);
if ($this->config['use_pubsubhubbub'] && ($raw = $this
->subscriber($source->feed_nid)
->receive())) {
return new FeedsImportBatch($raw, $source->feed_nid);
}
return new FeedsHTTPBatch($source_config['source'], $source->feed_nid);
}
/**
* 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);
}
/**
* Implements FeedsFetcher::request().
*/
public function request($feed_nid = 0) {
feeds_dbg($_GET);
@feeds_dbg(file_get_contents('php://input'));
// A subscription verification has been sent, verify.
if (isset($_GET['hub_challenge'])) {
$this
->subscriber($feed_nid)
->verifyRequest();
}
else {
try {
feeds_source($this->id, $feed_nid)
->existing()
->import();
} catch (Exception $e) {
// In case of an error, respond with a 503 Service (temporary) unavailable.
header('HTTP/1.1 503 "Not Found"', NULL, 503);
exit;
}
}
// Will generate the default 200 response.
header('HTTP/1.1 200 "OK"', NULL, 200);
exit;
}
/**
* Override parent::configDefaults().
*/
public function configDefaults() {
return array(
'auto_detect_feeds' => FALSE,
'use_pubsubhubbub' => FALSE,
'designated_hub' => '',
);
}
/**
* Override parent::configForm().
*/
public function configForm(&$form_state) {
$form = array();
$form['auto_detect_feeds'] = array(
'#type' => 'checkbox',
'#title' => t('Auto detect feeds'),
'#description' => t('If the supplied URL does not point to a feed but an HTML document, attempt to extract a feed URL from the document.'),
'#default_value' => $this->config['auto_detect_feeds'],
);
$form['use_pubsubhubbub'] = array(
'#type' => 'checkbox',
'#title' => t('Use PubSubHubbub'),
'#description' => t('Attempt to use a <a href="http://en.wikipedia.org/wiki/PubSubHubbub">PubSubHubbub</a> subscription if available.'),
'#default_value' => $this->config['use_pubsubhubbub'],
);
$form['designated_hub'] = array(
'#type' => 'textfield',
'#title' => t('Designated hub'),
'#description' => t('Enter the URL of a designated PubSubHubbub hub (e. g. superfeedr.com). If given, this hub will be used instead of the hub specified in the actual feed.'),
'#default_value' => $this->config['designated_hub'],
'#process' => array(
'ctools_dependent_process',
),
'#dependency' => array(
'edit-use-pubsubhubbub' => array(
1,
),
),
);
return $form;
}
/**
* 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'] : '',
'#maxlength' => NULL,
'#required' => TRUE,
);
return $form;
}
/**
* Override parent::sourceFormValidate().
*/
public function sourceFormValidate(&$values) {
$values['source'] = trim($values['source']);
if (!feeds_valid_url($values['source'], TRUE)) {
$form_key = 'feeds][' . get_class($this) . '][source';
form_set_error($form_key, t('The URL %source is invalid.', array(
'%source' => $values['source'],
)));
}
elseif ($this->config['auto_detect_feeds']) {
feeds_include_library('http_request.inc', 'http_request');
if ($url = http_request_get_common_syndication($values['source'])) {
$values['source'] = $url;
}
}
}
/**
* Override sourceSave() - subscribe to hub.
*/
public function sourceSave(FeedsSource $source) {
if ($this->config['use_pubsubhubbub']) {
$this
->subscribe($source);
}
}
/**
* Override sourceDelete() - unsubscribe from hub.
*/
public function sourceDelete(FeedsSource $source) {
if ($this->config['use_pubsubhubbub']) {
$this
->unsubscribe($source);
}
}
/**
* Implement FeedsFetcher::subscribe() - subscribe to hub.
*/
public function subscribe(FeedsSource $source) {
$source_config = $source
->getConfigFor($this);
$this
->subscriber($source->feed_nid)
->subscribe($source_config['source'], url($this
->path($source->feed_nid), array(
'absolute' => TRUE,
)), valid_url($this->config['designated_hub']) ? $this->config['designated_hub'] : '');
}
/**
* Implement FeedsFetcher::unsubscribe() - unsubscribe from hub.
*/
public function unsubscribe(FeedsSource $source) {
$source_config = $source
->getConfigFor($this);
$this
->subscriber($source->feed_nid)
->unsubscribe($source_config['source'], url($this
->path($source->feed_nid), array(
'absolute' => TRUE,
)));
}
/**
* Implement FeedsFetcher::importPeriod().
*/
public function importPeriod(FeedsSource $source) {
if ($this
->subscriber($source->feed_nid)
->subscribed()) {
return 259200;
// Delay for three days if there is a successful subscription.
}
}
/**
* Convenience method for instantiating a subscriber object.
*/
protected function subscriber($subscriber_id) {
return PushSubscriber::instance($this->id, $subscriber_id, 'PuSHSubscription', PuSHEnvironment::instance());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
protected | property | CTools export enabled status of this object. | |
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
public | function | Similar to setConfig but adds to existing configuration. | 1 |
FeedsConfigurable:: |
public | function | Submission handler for configForm(). | 3 |
FeedsConfigurable:: |
public | function | Validation handler for configForm(). | 3 |
FeedsConfigurable:: |
public | function | Copy a configuration. | 1 |
FeedsConfigurable:: |
public | function | Determine whether this object is persistent and enabled. I. e. it is defined either in code or in the database and it is enabled. | 1 |
FeedsConfigurable:: |
public | function | Implementation of getConfig(). | 1 |
FeedsConfigurable:: |
public static | function | Instantiate a FeedsConfigurable object. | 1 |
FeedsConfigurable:: |
public | function | Set configuration. | 1 |
FeedsConfigurable:: |
public | function | Override magic method __get(). Make sure that $this->config goes through getConfig() | |
FeedsConfigurable:: |
public | function | Override magic method __isset(). This is needed due to overriding __get(). | |
FeedsFetcher:: |
public | function | Menu item definition for fetchers of this class. Note how the path component in the item definition matches the return value of FeedsFetcher::path(); | |
FeedsFetcher:: |
public | function | Construct a path for a concrete fetcher/source combination. The result of this method matches up with the general path definition in FeedsFetcher::menuItem(). For example usage look at FeedsHTTPFetcher. | |
FeedsHTTPFetcher:: |
public | function |
Clear caches. Overrides FeedsFetcher:: |
|
FeedsHTTPFetcher:: |
public | function |
Override parent::configDefaults(). Overrides FeedsConfigurable:: |
|
FeedsHTTPFetcher:: |
public | function |
Override parent::configForm(). Overrides FeedsConfigurable:: |
|
FeedsHTTPFetcher:: |
public | function |
Implements FeedsFetcher::fetch(). Overrides FeedsFetcher:: |
|
FeedsHTTPFetcher:: |
public | function |
Implement FeedsFetcher::importPeriod(). Overrides FeedsFetcher:: |
|
FeedsHTTPFetcher:: |
public | function |
Implements FeedsFetcher::request(). Overrides FeedsFetcher:: |
|
FeedsHTTPFetcher:: |
public | function |
Override sourceDelete() - unsubscribe from hub. Overrides FeedsPlugin:: |
|
FeedsHTTPFetcher:: |
public | function |
Expose source form. Overrides FeedsPlugin:: |
|
FeedsHTTPFetcher:: |
public | function |
Override parent::sourceFormValidate(). Overrides FeedsPlugin:: |
|
FeedsHTTPFetcher:: |
public | function |
Override sourceSave() - subscribe to hub. Overrides FeedsPlugin:: |
|
FeedsHTTPFetcher:: |
public | function |
Implement FeedsFetcher::subscribe() - subscribe to hub. Overrides FeedsFetcher:: |
|
FeedsHTTPFetcher:: |
protected | function | Convenience method for instantiating a subscriber object. | |
FeedsHTTPFetcher:: |
public | function |
Implement FeedsFetcher::unsubscribe() - unsubscribe from hub. Overrides FeedsFetcher:: |
|
FeedsPlugin:: |
public | function |
Returns TRUE if $this->sourceForm() returns a form. Overrides FeedsSourceInterface:: |
|
FeedsPlugin:: |
protected static | function | Loads on-behalf implementations from mappers/ directory. | |
FeedsPlugin:: |
public | function |
Save changes to the configuration of this object.
Delegate saving to parent (= Feed) which will collect
information from this object by way of getConfig() and store it. Overrides FeedsConfigurable:: |
|
FeedsPlugin:: |
public | function |
Implementation of FeedsSourceInterface::sourceDefaults(). Overrides FeedsSourceInterface:: |
1 |
FeedsPlugin:: |
protected | function |
Constructor. Overrides FeedsConfigurable:: |