diff --git a/feeds.install b/feeds.install index 731467237586bdb51d2824794cbeada4f321c2af..ba715dfc5a20cb89bca6d6519b4209976e869d3b 100644 --- a/feeds.install +++ b/feeds.install @@ -11,7 +11,7 @@ function feeds_schema() { $schema['feeds_configuration'] = array( 'description' => 'Configuration of feeds objects.', 'export' => array( - 'key' => 'name', + 'key' => 'id', 'identifier' => 'feed_object', 'default hook' => 'feeds', // Function hook name. 'api' => array( diff --git a/feeds.module b/feeds.module index 7804c8b519039c2a7572dea22c8170dc52369552..1e8169eca560eabdae4015297378f98d7ce03062 100644 --- a/feeds.module +++ b/feeds.module @@ -20,6 +20,19 @@ function feeds_perm() { return array('use feeds', 'administer feeds'); } +/** + * Implementation of hook_ctools_plugin_api(). + * + * @todo: switch hook_feeds_plugin() over to hook_ctools_plugin_api(). + */ +function feeds_ctools_plugin_api($owner, $api) { + if ($owner == 'feeds' && $api == 'plugins') { + return array( + 'version' => 1, + ''); + } +} + /** * Implementation of hook_feeds_plugin(). */ diff --git a/feeds_ui/feeds_ui.admin.inc b/feeds_ui/feeds_ui.admin.inc index b2c99e1ec903dcd049bc6480778aea827e0e279b..8c31e85fac27298103dfcb5729668ac477468553 100644 --- a/feeds_ui/feeds_ui.admin.inc +++ b/feeds_ui/feeds_ui.admin.inc @@ -4,6 +4,24 @@ * @file */ +/** + * List available feed configurations. + */ +function feeds_ui_content_overview() { + $rows = array(); + if ($feeds = feeds_load_all()) { + foreach ($feeds as $feed) { + $rows[] = array( + $feed->getId(), + ); + } + } + $header = array( + t('Configurations'), + ); + return theme('table', $header, $rows); +} + /** * Build overview of available configurations. */ @@ -38,7 +56,7 @@ function feeds_ui_build_create_form(&$form_state) { $form['id'] = array( '#type' => 'textfield', '#title' => t('Id'), - '#description' => t('A unique identifier for this preset.'), + '#description' => t('A unique identifier for this configuration.'), ); $form['submit'] = array( '#type' => 'submit', @@ -79,7 +97,7 @@ function feeds_ui_build_create_form_submit($form, &$form_state) { * Edit an existing configuration. */ function feeds_ui_build_edit_form(&$form_state, $feed) { - $form = _feeds_ui_config_form ($feed); + $form = _feeds_ui_config_form($feed); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save'), @@ -88,21 +106,19 @@ function feeds_ui_build_edit_form(&$form_state, $feed) { } /** - * Edit an existing configuration. + * Submit handler for feeds_ui_build_edit_form(). */ -function feeds_ui_build_mapping_form(&$form_state, $feed) { - $form = array(); - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Save'), - ); - return $form; +function feeds_ui_build_edit_form_submit($form, &$form_state) { + $feed = $form['#feed']; + $form['#feed']->addConfig($form_state['values']); + $form['#feed']->save(); + drupal_set_message(t('Saved configuration')); } /** * Edit an existing configuration. */ -function feeds_ui_build_advanced_form(&$form_state, $feed) { +function feeds_ui_build_mapping_form(&$form_state, $feed) { $form = array(); $form['submit'] = array( '#type' => 'submit', @@ -112,9 +128,9 @@ function feeds_ui_build_advanced_form(&$form_state, $feed) { } /** - * Helper, build edit UI for a feed. Used for editing and creating. + * Edit plugin configuration. */ -function _feeds_ui_config_form($feed = NULL) { +function feeds_ui_build_plugin_form(&$form_state, $feed) { $form = array(); $plugins = feeds_get_plugins(); $form['plugins'] = array( @@ -125,14 +141,14 @@ function _feeds_ui_config_form($feed = NULL) { '#type' => 'radios', '#title' => t('Fetcher'), '#options' => $plugins['fetcher'], - '#description' => t('Select a fetcher for this preset'), + '#description' => t('Select a fetcher for this configuration.'), '#default_value' => empty($feed) ? key($plugins['fetcher']) : get_class($feed->fetcher), ); $form['plugins']['parser'] = array( '#type' => 'radios', '#title' => t('Parser'), '#options' => $plugins['parser'], - '#description' => t('Select a parser for this preset'), + '#description' => t('Select a parser for this configuration.'), '#default_value' => empty($feed) ? key($plugins['parser']) : get_class($feed->parser), ); if (empty($feed)) { @@ -147,34 +163,57 @@ function _feeds_ui_config_form($feed = NULL) { '#type' => 'checkboxes', '#title' => t('Processors'), '#options' => $plugins['processor'], - '#description' => t('Select processors for this preset'), + '#description' => t('Select processors for this configuration.'), '#default_value' => $default, ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save'), + ); + return $form; +} + +/** + * Helper, build edit UI for a feed. Used for editing and creating. + * @todo: pull form from feed object. + */ +function _feeds_ui_config_form($feed = NULL) { + $form = array(); + if ($feed) { + $config = $feed->getConfig(); + $form['#feed'] = $feed; + } $form['settings'] = array( '#type' => 'fieldset', - '#title' => t('Basic settings'), + '#title' => t('Basic configuration'), ); $form['settings']['content_type'] = array( '#type' => 'select', '#title' => t('Attach to content type'), - '#description' => t('When you attach a feeds configuration to a node, you can use nodes for creating feeds on your site.'), + '#description' => t('When you attach a configuration to a node, you can use nodes for creating feeds on your site.'), '#options' => array('' => t('None')) + node_get_types('names'), - '#default_value' => '', + '#default_value' => $config['content_type'], ); + $form['settings']['source'] = array( + '#type' => 'textfield', + '#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['settings']['update'] = array( '#type' => 'radios', '#title' => t('Update existing'), '#options' => array(1 => t('Yes'), 0 => t('No')), - '#default_value' => 0, // @todo + '#default_value' => $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('Never refresh'); + $period[FEEDAPI_CRON_NEVER_REFRESH] = t('Do not refresh periodically'); $period[1] = t('As often as possible'); $form['settings']['refresh_period'] = array( '#type' => 'select', '#title' => t('Minimum refresh period'), '#options' => $period, - '#default_value' => 0, // @todo + '#default_value' => $config['refresh_period'], ); return $form; } \ No newline at end of file diff --git a/feeds_ui/feeds_ui.module b/feeds_ui/feeds_ui.module index 2ab236a2f49c794f95360957a410b1f1aa9c9577..e3fee1c86b7e73827cb93e262d363d58255b6ae0 100644 --- a/feeds_ui/feeds_ui.module +++ b/feeds_ui/feeds_ui.module @@ -4,6 +4,20 @@ * @file */ +/** + * Implementation of hook_help(). + */ +function feeds_ui_help($path, $arg) { + switch ($path) { + case 'admin/build/feeds': + $output = '<p>'. t('Configure one or more feeds to import content into Drupal. You can use these feed configurations directly here or - if you attach them to a content type - simply by creating a node from that content type.') .'</p>'; + return $output; + case 'admin/content/feeds': + $output = '<p>'. t('Import content into Drupal.') .'</p>'; + return $output; + } +} + /** * Implementation of hook_menu(). */ @@ -45,25 +59,26 @@ function feeds_ui_menu() { 'type' => MENU_CALLBACK, ); $items['admin/build/feeds/edit/%feeds/edit'] = array( - 'title' => t('Configuration'), + 'title' => t('Basic'), 'type' => MENU_DEFAULT_LOCAL_TASK, ); - $items['admin/build/feeds/edit/%feeds/map'] = array( - 'title' => t('Mapping'), + $items['admin/build/feeds/edit/%feeds/plugins'] = array( + 'title' => t('Plugins'), 'page callback' => 'drupal_get_form', - 'page arguments' => array('feeds_ui_build_mapping_form', 4), + 'page arguments' => array('feeds_ui_build_plugin_form', 4), 'access arguments' => array('administer feeds'), 'file' => 'feeds_ui.admin.inc', 'type' => MENU_LOCAL_TASK, + 'weight' => 1, ); - $items['admin/build/feeds/edit/%feeds/advanced'] = array( - 'title' => t('Advanced'), + $items['admin/build/feeds/edit/%feeds/map'] = array( + 'title' => t('Mapping'), 'page callback' => 'drupal_get_form', - 'page arguments' => array('feeds_ui_build_advanced_form', 4), + 'page arguments' => array('feeds_ui_build_mapping_form', 4), 'access arguments' => array('administer feeds'), 'file' => 'feeds_ui.admin.inc', 'type' => MENU_LOCAL_TASK, - 'weight' => 10, + 'weight' => 2, ); return $items; } diff --git a/includes/feed.inc b/includes/feed.inc index ee2aeac1fc1c6d850b8ea9fdb67ebe39582383f2..7fa42fddd9f15353335b43e4200bca64db6e4a91 100644 --- a/includes/feed.inc +++ b/includes/feed.inc @@ -32,6 +32,21 @@ class Feed extends FeedsConfigurable { } } + /** + * Return defaults for feed configuration. + */ + public function getDefaultConfig() { + return array( + 'fetcher' => 'FeedsHttpFetcher', + 'parser' => 'FeedsSyndicationParser', + 'processors' => array('FeedsNodeProcessor'), + 'content_type' => '', + 'source' => array(), + 'update' => 0, + 'refresh_period' => FEEDAPI_CRON_NEVER_REFRESH, + ); + } + /** * Import feed by using configured fetchers, parsers, processors. */ @@ -146,7 +161,14 @@ class FeedsConfigurable { } public function setConfig($config) { - $this->config = $config; + $default_keys = $this->getDefaultConfig(); + $this->config = array_intersect_key($config, $default_keys); + } + + public function addConfig($config) { + $this->config = array_merge($this->config, $config); + $default_keys = $this->getDefaultConfig(); + $this->config = array_intersect_key($this->config, $default_keys); } public function getDefaultConfig() {