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$
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
dependencies[] = ctools
core = 6.x
......@@ -8,7 +8,7 @@
* Implementation of hook_schema().
*/
function feeds_schema() {
$schema['feeds_configuration'] = array(
$schema['feeds_config'] = array(
'description' => 'Configuration of feeds objects.',
'export' => array(
'key' => 'id',
......@@ -48,6 +48,34 @@ function feeds_schema() {
'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;
}
......
......@@ -133,7 +133,7 @@ function feeds_load($id) {
*/
function feeds_load_all() {
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) {
$feeds[$config->id] = feeds_get_feed($config->id);
}
......@@ -156,7 +156,7 @@ function feeds_get_feed($id) {
* Delete a feed.
*/
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() {
/**
* Create a new configuration.
*
* @todo: make this a multi-step once all forms are stabilized.
*/
function feeds_ui_build_create_form(&$form_state) {
drupal_add_js(drupal_get_path('module', 'feeds_ui') .'/feeds_ui.js');
$form = array();
if (!$form_state['storage']['id']) {
$form['id'] = array(
'#type' => 'textfield',
'#title' => t('Id'),
'#description' => t('A unique identifier for this configuration.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Next'),
);
}
else {
// @todo: present plugin form first.
feeds_include('feed');
$feed = feeds_get_feed($form_state['storage']['id']);
$form['settings'] = array(
'#type' => 'fieldset',
'#title' => t('Basic configuration'),
);
$form['settings'] += $feed->configForm($form_state);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Create'),
);
}
$form['#redirect'] = 'admin/build/feeds';
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#description' => t('A natural name for this configuration. Example: RSS Feed. You can always change this name later.'),
'#required' => TRUE,
'#attributes' => array('class' => 'feed-name'),
);
$form['id'] = array(
'#type' => 'textfield',
'#title' => t('Machine name'),
'#description' => t('A unique identifier for this configuration. Example: rss_feed. Must only contain lower case characters, numbers and underscores.'),
'#required' => TRUE,
'#attributes' => array('class' => 'feed-id'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Create'),
);
return $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) {
ctools_include('export');
if (isset($form_state['values']['id'])) {
$feed = feeds_get_feed($form_state['values']['id']);
if (ctools_export_load_object('feeds_configuration', 'conditions', array('id' => $form_state['values']['id'], 'class' => 'Feed'))) {
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 = feeds_get_feed($form_state['values']['id']);
if (ctools_export_load_object('feeds_config', 'conditions', array('id' => $form_state['values']['id'], 'class' => 'Feed'))) {
form_set_error('id', t('Id is taken.'));
}
$feed->configFormValidate($form, &$form_state);
}
......@@ -107,19 +93,8 @@ function feeds_ui_build_create_form_validate($form, &$form_state) {
* Submit handler for feeds_build_create_form().
*/
function feeds_ui_build_create_form_submit($form, &$form_state) {
if ($form_state['values']['id']) {
$form_state['storage']['id'] = $form_state['values']['id'];
}
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';
}
$feed = feeds_get_feed($form_state['values']['id']);
$feed->save();
}
/**
......@@ -154,6 +129,40 @@ function feeds_ui_build_edit_form_submit($form, &$form_state) {
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.
*/
......@@ -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) {
$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'));
function feeds_ui_build_mapping_remove($feed, $processor, $target, $token) {
if (drupal_valid_token($token, $target)) {
$mapping = $feed->processors[$processor]->removeMapping($target);
}
else {
drupal_set_message(t('Invalid token.'), 'error');
}
drupal_goto('admin/build/feeds/edit/'. $feed->getId() .'/map');
}
/**
......@@ -273,7 +262,7 @@ function theme_feeds_ui_build_mapping_form($form) {
$mapping['source'],
$target,
$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() {
'type' => MENU_LOCAL_TASK,
'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(
'title' => t('Create configuration'),
'page callback' => 'drupal_get_form',
......
......@@ -209,8 +209,8 @@ class FeedsConfigurable {
$save->id = $this->id;
$save->class = get_class($this);
$save->config = $this->config;
db_query('DELETE FROM {feeds_configuration} WHERE id = "%s" AND class = "%s"', $save->id, $save->class);
drupal_write_record('feeds_configuration', $save);
db_query('DELETE FROM {feeds_config} WHERE id = "%s" AND class = "%s"', $save->id, $save->class);
drupal_write_record('feeds_config', $save);
}
/**
......@@ -218,7 +218,7 @@ class FeedsConfigurable {
*/
public function load() {
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);
$this->config = $config->config;
return TRUE;
......@@ -400,21 +400,27 @@ class FeedsProcessor extends FeedsConfigurable {
* Declare default configuration.
*/
public function getDefaultConfig() {
return array('mappings' => array());
return array('mappings' => FALSE);
}
/**
* Add a mapping to existing mappings.
*/
public function addMapping($source, $target, $unique = NULL) {
if (!empty($source) && !empty($target)) {
$config = $this->getConfig();
$config['mappings'][$target] = array(
$this->config['mappings'][$target] = array(
'source' => $source,
'unique' => $unique,
);
}
$this->setConfig($config);
$this->save();
}
/**
* Remove a mapping.
*/
public function removeMapping($target) {
unset($this->config['mappings'][$target]);
$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