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

More admin work.

parent 6f18a223
No related branches found
No related tags found
No related merge requests found
;$Id$ ;$Id$
name = Feeds name = Feeds
description = API for importing feeds of data. description = Provides an API for importing feeds of data: Aggregate RSS/Atom/RDF feeds, import CSV files and more.
package = Feeds package = Feeds
dependencies[] = ctools dependencies[] = ctools
core = 6.x core = 6.x
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Implementation of hook_schema(). * Implementation of hook_schema().
*/ */
function feeds_schema() { function feeds_schema() {
$schema['feeds_configuration'] = array( $schema['feeds_config'] = array(
'description' => 'Configuration of feeds objects.', 'description' => 'Configuration of feeds objects.',
'export' => array( 'export' => array(
'key' => 'id', 'key' => 'id',
...@@ -48,6 +48,34 @@ function feeds_schema() { ...@@ -48,6 +48,34 @@ function feeds_schema() {
'class' => array('class'), 'class' => array('class'),
), ),
); );
$schema['feeds_source'] = array(
'description' => 'Source definitions for feeds.',
'fields' => array(
'id' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
'description' => 'Id of the feed configuration.',
),
'nid' => array(
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
'description' => 'Node nid if this particular source is attached to a node.',
),
'source' => array(
'type' => 'text',
'not null' => FALSE,
'description' => 'Definition of the source.',
'serialize' => TRUE,
),
),
'indexes' => array(
'id' => array('id'),
'nid' => array('nid'),
),
);
return $schema; return $schema;
} }
......
...@@ -133,7 +133,7 @@ function feeds_load($id) { ...@@ -133,7 +133,7 @@ function feeds_load($id) {
*/ */
function feeds_load_all() { function feeds_load_all() {
ctools_include('export'); ctools_include('export');
$configs = ctools_export_load_object('feeds_configuration', 'conditions', array('class' => 'Feed')); $configs = ctools_export_load_object('feeds_config', 'conditions', array('class' => 'Feed'));
foreach ($configs as $config) { foreach ($configs as $config) {
$feeds[$config->id] = feeds_get_feed($config->id); $feeds[$config->id] = feeds_get_feed($config->id);
} }
...@@ -156,7 +156,7 @@ function feeds_get_feed($id) { ...@@ -156,7 +156,7 @@ function feeds_get_feed($id) {
* Delete a feed. * Delete a feed.
*/ */
function feeds_delete($id) { function feeds_delete($id) {
db_query('DELETE FROM {feeds_configuration} WHERE id = "%s"', $id); db_query('DELETE FROM {feeds_config} WHERE id = "%s"', $id);
} }
/** /**
......
...@@ -49,56 +49,42 @@ function feeds_ui_build_overview() { ...@@ -49,56 +49,42 @@ function feeds_ui_build_overview() {
/** /**
* Create a new configuration. * Create a new configuration.
*
* @todo: make this a multi-step once all forms are stabilized.
*/ */
function feeds_ui_build_create_form(&$form_state) { function feeds_ui_build_create_form(&$form_state) {
drupal_add_js(drupal_get_path('module', 'feeds_ui') .'/feeds_ui.js');
$form = array(); $form = array();
if (!$form_state['storage']['id']) { $form['#redirect'] = 'admin/build/feeds';
$form['id'] = array( $form['name'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Id'), '#title' => t('Name'),
'#description' => t('A unique identifier for this configuration.'), '#description' => t('A natural name for this configuration. Example: RSS Feed. You can always change this name later.'),
); '#required' => TRUE,
$form['submit'] = array( '#attributes' => array('class' => 'feed-name'),
'#type' => 'submit', );
'#value' => t('Next'), $form['id'] = array(
); '#type' => 'textfield',
} '#title' => t('Machine name'),
else { '#description' => t('A unique identifier for this configuration. Example: rss_feed. Must only contain lower case characters, numbers and underscores.'),
// @todo: present plugin form first. '#required' => TRUE,
feeds_include('feed'); '#attributes' => array('class' => 'feed-id'),
$feed = feeds_get_feed($form_state['storage']['id']); );
$form['settings'] = array( $form['submit'] = array(
'#type' => 'fieldset', '#type' => 'submit',
'#title' => t('Basic configuration'), '#value' => t('Create'),
); );
$form['settings'] += $feed->configForm($form_state);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Create'),
);
}
return $form; return $form;
} }
/** /**
* Validation handler for feeds_build_create_form(). * Validation handler for feeds_build_create_form().
*
* @todo: don't allow attaching more than one configuration to one content type.
*/ */
function feeds_ui_build_create_form_validate($form, &$form_state) { function feeds_ui_build_create_form_validate($form, &$form_state) {
ctools_include('export'); ctools_include('export');
if (isset($form_state['values']['id'])) { $feed = feeds_get_feed($form_state['values']['id']);
$feed = feeds_get_feed($form_state['values']['id']); if (ctools_export_load_object('feeds_config', 'conditions', array('id' => $form_state['values']['id'], 'class' => 'Feed'))) {
if (ctools_export_load_object('feeds_configuration', 'conditions', array('id' => $form_state['values']['id'], 'class' => 'Feed'))) { form_set_error('id', t('Id is taken.'));
form_set_error('id', t('Id is taken.'));
}
}
elseif (isset($form_state['storage']['id'])) {
$feed = feeds_get_feed($form_state['storage']['id']);
if (ctools_export_load_object('feeds_configuration', 'conditions', array('id' => $form_state['storage']['id'], 'class' => 'Feed'))) {
form_set_error('id', t('Id is taken.'));
drupal_goto('admin/build/feeds/create');
}
} }
$feed->configFormValidate($form, &$form_state); $feed->configFormValidate($form, &$form_state);
} }
...@@ -107,19 +93,8 @@ function feeds_ui_build_create_form_validate($form, &$form_state) { ...@@ -107,19 +93,8 @@ function feeds_ui_build_create_form_validate($form, &$form_state) {
* Submit handler for feeds_build_create_form(). * Submit handler for feeds_build_create_form().
*/ */
function feeds_ui_build_create_form_submit($form, &$form_state) { function feeds_ui_build_create_form_submit($form, &$form_state) {
if ($form_state['values']['id']) { $feed = feeds_get_feed($form_state['values']['id']);
$form_state['storage']['id'] = $form_state['values']['id']; $feed->save();
}
else {
// Save feed.
$feed = feeds_get_feed($form_state['storage']['id']);
$feed->configFormSubmit($form, &$form_state);
drupal_set_message(t('Created configuration'));
// Unset storage to enable redirect.
unset($form_state['storage']);
$form_state['redirect'] = 'admin/build/feeds';
}
} }
/** /**
...@@ -154,6 +129,40 @@ function feeds_ui_build_edit_form_submit($form, &$form_state) { ...@@ -154,6 +129,40 @@ function feeds_ui_build_edit_form_submit($form, &$form_state) {
drupal_set_message(t('Saved configuration')); drupal_set_message(t('Saved configuration'));
} }
/**
* Edit plugin configuration.
*/
function feeds_ui_build_plugin_form(&$form_state, $feed) {
$form = array();
$form['#feed'] = $feed;
$form['plugins'] = array(
'#type' => 'fieldset',
'#title' => t('Plugins'),
);
$form['plugins'] += $feed->pluginForm($form_state);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
/**
* Validation handler for feeds_ui_build_edit_form().
*/
function feeds_ui_build_plugin_form_validate($form, &$form_state) {
$form['#feed']->pluginFormValidate($form, &$form_state);
}
/**
* Submit handler for feeds_ui_build_edit_form().
*/
function feeds_ui_build_plugin_form_submit($form, &$form_state) {
$form['#feed']->pluginFormSubmit($form, &$form_state);
drupal_set_message(t('Saved configuration'));
}
/** /**
* Edit mapping. * Edit mapping.
*/ */
...@@ -200,36 +209,16 @@ function feeds_ui_build_mapping_form_submit($form, &$form_state) { ...@@ -200,36 +209,16 @@ function feeds_ui_build_mapping_form_submit($form, &$form_state) {
} }
/** /**
* Edit plugin configuration. * Remove a mapping.
*/ */
function feeds_ui_build_plugin_form(&$form_state, $feed) { function feeds_ui_build_mapping_remove($feed, $processor, $target, $token) {
$form = array(); if (drupal_valid_token($token, $target)) {
$form['#feed'] = $feed; $mapping = $feed->processors[$processor]->removeMapping($target);
$form['plugins'] = array( }
'#type' => 'fieldset', else {
'#title' => t('Plugins'), drupal_set_message(t('Invalid token.'), 'error');
); }
$form['plugins'] += $feed->pluginForm($form_state); drupal_goto('admin/build/feeds/edit/'. $feed->getId() .'/map');
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
/**
* Validation handler for feeds_ui_build_edit_form().
*/
function feeds_ui_build_plugin_form_validate($form, &$form_state) {
$form['#feed']->pluginFormValidate($form, &$form_state);
}
/**
* Submit handler for feeds_ui_build_edit_form().
*/
function feeds_ui_build_plugin_form_submit($form, &$form_state) {
$form['#feed']->pluginFormSubmit($form, &$form_state);
drupal_set_message(t('Saved configuration'));
} }
/** /**
...@@ -273,7 +262,7 @@ function theme_feeds_ui_build_mapping_form($form) { ...@@ -273,7 +262,7 @@ function theme_feeds_ui_build_mapping_form($form) {
$mapping['source'], $mapping['source'],
$target, $target,
$mapping['unique'] ? t('Yes') : t('No'), $mapping['unique'] ? t('Yes') : t('No'),
t('Remove'), l(t('Remove'), 'admin/build/feeds/map-remove/'. $form['#feed']->getId() .'/'. $processor .'/'. $target .'/'. drupal_get_token($target)),
); );
} }
} }
......
...@@ -80,6 +80,13 @@ function feeds_ui_menu() { ...@@ -80,6 +80,13 @@ function feeds_ui_menu() {
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
'weight' => 2, 'weight' => 2,
); );
$items['admin/build/feeds/map-remove/%feeds'] = array(
'page callback' => 'feeds_ui_build_mapping_remove',
'page arguments' => array(4),
'access arguments' => array('administer feeds'),
'file' => 'feeds_ui.admin.inc',
'type' => MENU_CALLBACK,
);
$items['admin/build/feeds/delete/%feeds'] = array( $items['admin/build/feeds/delete/%feeds'] = array(
'title' => t('Create configuration'), 'title' => t('Create configuration'),
'page callback' => 'drupal_get_form', 'page callback' => 'drupal_get_form',
......
...@@ -209,8 +209,8 @@ class FeedsConfigurable { ...@@ -209,8 +209,8 @@ class FeedsConfigurable {
$save->id = $this->id; $save->id = $this->id;
$save->class = get_class($this); $save->class = get_class($this);
$save->config = $this->config; $save->config = $this->config;
db_query('DELETE FROM {feeds_configuration} WHERE id = "%s" AND class = "%s"', $save->id, $save->class); db_query('DELETE FROM {feeds_config} WHERE id = "%s" AND class = "%s"', $save->id, $save->class);
drupal_write_record('feeds_configuration', $save); drupal_write_record('feeds_config', $save);
} }
/** /**
...@@ -218,7 +218,7 @@ class FeedsConfigurable { ...@@ -218,7 +218,7 @@ class FeedsConfigurable {
*/ */
public function load() { public function load() {
ctools_include('export'); ctools_include('export');
if ($config = ctools_export_load_object('feeds_configuration', 'conditions', array('id' => $this->id, 'class' => get_class($this)))) { if ($config = ctools_export_load_object('feeds_config', 'conditions', array('id' => $this->id, 'class' => get_class($this)))) {
$config = array_shift($config); $config = array_shift($config);
$this->config = $config->config; $this->config = $config->config;
return TRUE; return TRUE;
...@@ -400,21 +400,27 @@ class FeedsProcessor extends FeedsConfigurable { ...@@ -400,21 +400,27 @@ class FeedsProcessor extends FeedsConfigurable {
* Declare default configuration. * Declare default configuration.
*/ */
public function getDefaultConfig() { public function getDefaultConfig() {
return array('mappings' => array()); return array('mappings' => FALSE);
} }
/** /**
* Add a mapping to existing mappings. * Add a mapping to existing mappings.
*/ */
public function addMapping($source, $target, $unique = NULL) { public function addMapping($source, $target, $unique = NULL) {
if (!empty($source) && !empty($target)) { if (!empty($source) && !empty($target)) {
$config = $this->getConfig(); $this->config['mappings'][$target] = array(
$config['mappings'][$target] = array(
'source' => $source, 'source' => $source,
'unique' => $unique, 'unique' => $unique,
); );
} }
$this->setConfig($config); $this->save();
}
/**
* Remove a mapping.
*/
public function removeMapping($target) {
unset($this->config['mappings'][$target]);
$this->save(); $this->save();
} }
......
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