Newer
Older
Alex Barth
committed
$output .= '</h4>';
}
if (!empty($container['body'])) {
$output .= '<div class="feeds-container-body">';
if (is_array($container['body'])) {
if (isset($container['body']['#type'])) {
$output .= drupal_render($container['body']);
}
else {
foreach ($container['body'] as $c) {
$output .= theme('feeds_ui_container', array('container' => $c));
}
Alex Barth
committed
}
}
else {
$output .= $container['body'];
}
$output .= '</div>';
}
$output .= '</div>';
return $output;
}
/**
* Theme function for feeds_ui_mapping_form().
*/
function theme_feeds_ui_mapping_form($variables) {
$form = $variables['form'];
Alex Barth
committed
$targets = feeds_importer($form['#importer'])->processor->getMappingTargets();
$targets = _feeds_ui_format_options($targets, TRUE);
$sources = feeds_importer($form['#importer'])->parser->getMappingSources();
// Some parsers do not define source options.
$sources = $sources ? _feeds_ui_format_options($sources, TRUE) : array();
// Build the actual mapping table.
$header = array(
t('Source'),
t('Target'),
niklas
committed
t('Target configuration'),
t('Weight'),
Alex Barth
committed
$rows = array();
if (is_array($form['#mappings'])) {
foreach ($form['#mappings'] as $i => $mapping) {
$source = isset($sources[$mapping['source']]) ? check_plain($sources[$mapping['source']]) : check_plain($mapping['source']);
$target = isset($targets[$mapping['target']]) ? check_plain($targets[$mapping['target']]) : '<em>' . t('Missing') . '</em>';
megachriz
committed
// Add indicator to target if target configuration changed.
if (isset($form['#mapping_settings'][$i])) {
$target .= '<span class="warning">*</span>';
}
'data' => array(
$source,
$target,
drupal_render($form['config'][$i]),
drupal_render($form['remove_flags'][$i]),
drupal_render($form['mapping_weight'][$i]),
),
'class' => array('draggable', 'tabledrag-leaf'),
Alex Barth
committed
}
if (!count($rows)) {
Alex Barth
committed
array(
'colspan' => 5,
Alex Barth
committed
'data' => t('No mappings defined.'),
),
Alex Barth
committed
$rows[] = array(
drupal_render($form['source']),
drupal_render($form['target']),
'',
drupal_render($form['add']),
Alex Barth
committed
);
megachriz
committed
$output = '';
if (!empty($form['changed'])) {
// This form element is only available if target configuration changed.
$output .= drupal_render($form['changed']);
}
$output .= '<div class="help feeds-admin-ui">' . drupal_render($form['help']) . '</div>';
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'feeds-ui-mapping-overview')));
// Build the help table that explains available sources.
$rows = array();
foreach (element_children($form['legendset']['legend']['sources']) as $k) {
$rows[] = array(
check_plain(drupal_render($form['legendset']['legend']['sources'][$k]['name'])),
check_plain(drupal_render($form['legendset']['legend']['sources'][$k]['description'])),
$legend .= '<h4>' . t('Sources') . '</h4>';
$legend .= theme('table', array('header' => array(t('Name'), t('Description')), 'rows' => $rows));
// Build the help table that explains available targets.
$rows = array();
foreach (element_children($form['legendset']['legend']['targets']) as $k) {
$rows[] = array(
check_plain(drupal_render($form['legendset']['legend']['targets'][$k]['name']) . ' (' . $k . ')'),
check_plain(drupal_render($form['legendset']['legend']['targets'][$k]['description'])),
$legend .= '<h4>' . t('Targets') . '</h4>';
$legend .= theme('table', array('header' => array(t('Name'), t('Description')), 'rows' => $rows));
// Stick tables into collapsible fieldset.
$form['legendset']['legend'] = array(
'#markup' => '<div>' . $legend . '</div>',
);
$output .= drupal_render($form['legendset']);
$output .= drupal_render_children($form);
drupal_add_tabledrag('feeds-ui-mapping-overview', 'order', 'sibling', 'feeds-ui-mapping-weight');
worldfallz
committed
/**
* Page callback to import a Feeds importer.
worldfallz
committed
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
*/
function feeds_ui_importer_import($form, &$form_state) {
$form['id'] = array(
'#type' => 'textfield',
'#title' => t('Importer id'),
'#description' => t('Enter the id to use for this importer if it is different from the source importer. Leave blank to use the id of the importer.'),
);
$form['id_override'] = array(
'#type' => 'checkbox',
'#title' => t('Replace an existing importer if one exists with the same id.'),
);
$form['bypass_validation'] = array(
'#type' => 'checkbox',
'#title' => t('Bypass importer validation'),
'#description' => t('Bypass the validation of plugins when importing.'),
);
$form['importer'] = array(
'#type' => 'textarea',
'#rows' => 10,
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Import'),
);
return $form;
}
/**
* Form validation handler for feeds_ui_importer_import().
*
* @see feeds_ui_importer_import_submit()
*/
function feeds_ui_importer_import_validate($form, &$form_state) {
$form_state['values']['importer'] = trim($form_state['values']['importer']);
$form_state['values']['id'] = trim($form_state['values']['id']);
if (!empty($form_state['values']['id']) && preg_match('/[^a-zA-Z0-9_]/', $form_state['values']['id'])) {
form_error($form['id'], t('Feeds importer id must be alphanumeric with underscores only.'));
}
if (substr($form_state['values']['importer'], 0, 5) == '<?php') {
$form_state['values']['importer'] = substr($form_state['values']['importer'], 5);
}
$feeds_importer = NULL;
ob_start();
eval($form_state['values']['importer']);
ob_end_clean();
if (!is_object($feeds_importer)) {
return form_error($form['importer'], t('Unable to interpret Feeds importer code.'));
worldfallz
committed
}
if (empty($feeds_importer->api_version) || $feeds_importer->api_version < 1) {
form_error($form['importer'], t('The importer is not compatible with this version of Feeds.'));
}
elseif (version_compare($feeds_importer->api_version, feeds_api_version(), '>')) {
form_error($form['importer'], t('That importer is created for the version %import_version of Feeds, but you only have version %api_version.', array(
'%import_version' => $feeds_importer->api_version,
'%api_version' => feeds_api_version())));
}
// Change to user-supplied id.
if ($form_state['values']['id']) {
$feeds_importer->id = $form_state['values']['id'];
}
$exists = feeds_ui_importer_machine_name_exists($feeds_importer->id);
if ($exists && !$form_state['values']['id_override']) {
return form_error($form['id'], t('Feeds importer already exists with that id.'));
worldfallz
committed
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
}
if (!$form_state['values']['bypass_validation']) {
foreach (array('fetcher', 'parser', 'processor') as $type) {
$plugin = feeds_plugin($feeds_importer->config[$type]['plugin_key'], $feeds_importer->id);
if (get_class($plugin) == 'FeedsMissingPlugin') {
form_error($form['importer'], t('The plugin %plugin is unavailable.', array('%plugin' => $feeds_importer->config[$type]['plugin_key'])));
}
}
}
$form_state['importer'] = $feeds_importer;
}
/**
* Form submission handler for feeds_ui_importer_import().
*
* @see feeds_ui_importer_import_validate()
*/
function feeds_ui_importer_import_submit($form, &$form_state) {
$importer = $form_state['importer'];
// Create a copy of the importer to preserve config.
$save = feeds_importer($importer->id);
$save->setConfig($importer->config);
worldfallz
committed
foreach (array('fetcher', 'parser', 'processor') as $type) {
Chris Leppanen
committed
$save->setPlugin($importer->config[$type]['plugin_key']);
$save->$type->setConfig($importer->config[$type]['config']);
worldfallz
committed
}
$save->save();
worldfallz
committed
drupal_set_message(t('Successfully imported the %id feeds importer.', array('%id' => $importer->id)));
$form_state['redirect'] = 'admin/structure/feeds';
}