Newer
Older
<?php
// $Id$
/**
* @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);
}
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Build overview of available configurations.
*/
function feeds_ui_build_overview() {
$rows = array();
if ($feeds = feeds_load_all()) {
foreach ($feeds as $feed) {
$rows[] = array(
$feed->getId(),
l(t('Edit'), 'admin/build/feeds/edit/'. $feed->getId()) .' | '.
l(t('Delete'), 'admin/build/feeds/delete/'. $feed->getId()),
);
}
}
$rows[] = array(
l(t('New configuration'), 'admin/build/feeds/create'),
' ',
);
$header = array(
t('Configurations'),
t('Operations'),
);
return theme('table', $header, $rows);
}
/**
* Create a new configuration.
*/
function feeds_ui_build_create_form(&$form_state) {
$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.
Alex Barth
committed
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'),
);
}
return $form;
}
Alex Barth
committed
/**
* Validation handler for feeds_build_create_form().
*
* @todo: don't allow attaching more than one configuration to one content type.
Alex Barth
committed
*/
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']);
Alex Barth
committed
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']);
Alex Barth
committed
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);
Alex Barth
committed
}
/**
* 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 {
Alex Barth
committed
// 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';
}
}
/**
* Edit an existing configuration.
*/
function feeds_ui_build_edit_form(&$form_state, $feed) {
Alex Barth
committed
$form['#feed'] = $feed;
$form['settings'] = array(
'#type' => 'fieldset',
'#title' => t('Basic configuration'),
);
$form['settings'] += $feed->configForm($form_state);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
Alex Barth
committed
/**
* Validation handler for feeds_ui_build_edit_form().
*/
function feeds_ui_build_edit_form_validate($form, &$form_state) {
$form['#feed']->configFormValidate($form, &$form_state);
}
* Submit handler for feeds_ui_build_edit_form().
function feeds_ui_build_edit_form_submit($form, &$form_state) {
Alex Barth
committed
$form['#feed']->configFormSubmit($form, &$form_state);
drupal_set_message(t('Saved configuration'));
* Edit mapping.
function feeds_ui_build_mapping_form(&$form_state, $feed) {
// Build a mapping form for each processor configured.
$sources = $feed->parser->getMappingSources();
foreach ($feed->processors as $class => $processor) {
$mappings = $processor->getMappings();
$targets = $processor->getMappingTargets();
$form['processors'][$class] = array(
'#type' => 'fieldset',
'#title' => $class, // @todo: human readable title.
);
$form['processors'][$class]['#mappings'] = $mappings;
$form['processors'][$class]['#targets'] = $targets;
$form['processors'][$class]['sources'] = array(
'#type' => 'select',
'#options' => array('' => t('Select a source')) + drupal_map_assoc($sources),
);
$form['processors'][$class]['targets'] = array(
'#type' => 'select',
'#options' => array('' => t('Select a target')) + drupal_map_assoc(array_keys($targets)),
);
$form['processors'][$class]['add'] = array(
'#type' => 'submit',
'#value' => t('Add'),
);
}
return $form;
}
/**
* Edit plugin configuration.
function feeds_ui_build_plugin_form(&$form_state, $feed) {
$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'));
}
/**
* Delete form.
*/
function feeds_ui_build_delete_form(&$form_state, $feed) {
$form['#redirect'] = 'admin/build/feeds';
$form['#feed'] = $feed;
return confirm_form($form,
t('Would you really like to delete the configuration !id?', array('!id' => $feed->getId())),
$form['#redirect'],
t('This action cannot be undone.'),
t('Delete')
);
}
/**
* Submit handler for feeds_ui_build_delete_form().
*/
function feeds_ui_build_delete_form_submit($form, &$form_state) {
feeds_delete($form['#feed']->getId());
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
}
/**
* Theme function for feeds_ui_build_mapping_form().
*/
function theme_feeds_ui_build_mapping_form($form) {
$output = '';
$header = array(
t('Source'),
t('Target'),
t('Unique'),
t('Remove'),
);
foreach (element_children($form['processors']) as $processor) {
$rows = array();
if (is_array($form['processors'][$processor]['#mappings'])) {
foreach ($form['processors'][$processor]['#mappings'] as $mapping) {
$rows[] = array(
// @todo.
);
}
}
if (!count($rows)) {
$rows[] = array(
array(
'colspan' => 4,
'data' => t('No mappings defined.'),
),
);
}
$rows[] = array(
drupal_render($form['processors'][$processor]['sources']),
drupal_render($form['processors'][$processor]['targets']),
'',
drupal_render($form['processors'][$processor]['add']),
);
$form['processors'][$processor]['#value'] = theme('table', $header, $rows);
}
$output .= drupal_render($form);
return $output;