Skip to content
Snippets Groups Projects
Commit 0ccaed76 authored by Alex Barth's avatar Alex Barth
Browse files

Add file fetcher, add source form handling.

parent fae024b0
No related branches found
No related tags found
No related merge requests found
...@@ -43,6 +43,11 @@ function feeds_feeds_plugin() { ...@@ -43,6 +43,11 @@ function feeds_feeds_plugin() {
'file' => drupal_get_path('module', 'feeds') .'/plugins/FeedsHttpFetcher.inc', 'file' => drupal_get_path('module', 'feeds') .'/plugins/FeedsHttpFetcher.inc',
'parent' => 'FeedsFetcher', 'parent' => 'FeedsFetcher',
), ),
'FeedsFileFetcher' => array(
'name' => t('File fetcher'),
'file' => drupal_get_path('module', 'feeds') .'/plugins/FeedsFileFetcher.inc',
'parent' => 'FeedsFetcher',
),
'FeedsCSVParser' => array( 'FeedsCSVParser' => array(
'name' => t('CSV parser'), 'name' => t('CSV parser'),
'file' => drupal_get_path('module', 'feeds') .'/plugins/FeedsCSVParser.inc', 'file' => drupal_get_path('module', 'feeds') .'/plugins/FeedsCSVParser.inc',
......
...@@ -64,6 +64,7 @@ function feeds_ui_build_create_form(&$form_state) { ...@@ -64,6 +64,7 @@ function feeds_ui_build_create_form(&$form_state) {
); );
} }
else { else {
// @todo: present plugin form first.
feeds_include('feed'); feeds_include('feed');
$feed = feeds_get_feed($form_state['storage']['id']); $feed = feeds_get_feed($form_state['storage']['id']);
$form['settings'] = array( $form['settings'] = array(
......
...@@ -56,25 +56,15 @@ class Feed extends FeedsConfigurable { ...@@ -56,25 +56,15 @@ class Feed extends FeedsConfigurable {
'#options' => array('' => t('None')) + node_get_types('names'), '#options' => array('' => t('None')) + node_get_types('names'),
'#default_value' => $this->config['content_type'], '#default_value' => $this->config['content_type'],
); );
$form['source'] = array( $form['source'] = $this->fetcher->sourceForm($form_state);
'#type' => 'textfield', $period = drupal_map_assoc(array(1, 900, 1800, 3600, 10800, 21600, 43200, 86400, 259200, 604800, 2419200), 'format_interval');
'#title' => t('URL'),
'#description' => t('Enter the URL for this feed @todo: delegate this form to plugin, hide if content type is picked.'),
'#default_value' => $config['source']['id'],
);
$form['update'] = array(
'#type' => 'radios',
'#title' => t('Update existing'),
'#options' => array(1 => t('Yes'), 0 => t('No')),
'#default_value' => $this->config['update'],
);
$period = drupal_map_assoc(array(1, 900, 1800, 3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 3628800, 4838400, 7257600, 15724800, 31536000), 'format_interval');
$period[FEEDAPI_CRON_NEVER_REFRESH] = t('Do not refresh periodically'); $period[FEEDAPI_CRON_NEVER_REFRESH] = t('Do not refresh periodically');
$period[1] = t('As often as possible'); $period[1] = t('As often as possible');
$form['refresh_period'] = array( $form['refresh_period'] = array(
'#type' => 'select', '#type' => 'select',
'#title' => t('Minimum refresh period'), '#title' => t('Minimum refresh period'),
'#options' => $period, '#options' => $period,
'#description' => t('This is the minimum time that must elapse before a feed may be refreshed automatically.'),
'#default_value' => $this->config['refresh_period'], '#default_value' => $this->config['refresh_period'],
); );
return $form; return $form;
...@@ -327,6 +317,29 @@ class FeedsConfigurable { ...@@ -327,6 +317,29 @@ class FeedsConfigurable {
* plugin type. See hook_feeds_plugin(). * plugin type. See hook_feeds_plugin().
*/ */
class FeedsFetcher extends FeedsConfigurable { class FeedsFetcher extends FeedsConfigurable {
/**
* Source form.
*/
public function sourceForm(&$form_state) {
$form = array();
$form['source'] = array(
'#type' => 'textfield',
'#title' => t('URL'),
'#description' => t('Enter the URL for this feed.'),
'#default_value' => $this->config['source'],
);
return $form;
}
/**
* Fetch content from a source and return it.
*
* Stub method. Every class that extends FeedsFetcher must implement this method.
*
* @param $source
* Source value as entered by user through sourceForm().
*/
public function fetch($source) { public function fetch($source) {
return NULL; return NULL;
} }
......
<?php
// $Id$
/**
* @file
* Home of the FeedsFileFetcher.
*/
/**
* Fetches data via HTTP.
*/
class FeedsFileFetcher extends FeedsFetcher {
/**
* Source form.
*/
public function sourceForm(&$form_state) {
$form = array();
$form['source'] = array(
'#type' => 'file',
'#title' => t('File'),
'#description' => t('Upload a file.'),
'#default_value' => $this->config['source'],
);
return $form;
}
/**
* Fetch a local resource.
*/
public function fetch($source) {
// @todo
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment