Révision 41cc1b08
Ajouté par Assos Assos il y a presque 9 ans
drupal7/sites/all/modules/feeds/feeds_ui/feeds_ui.admin.inc | ||
---|---|---|
273 | 273 |
/** |
274 | 274 |
* Edit feed configuration. |
275 | 275 |
*/ |
276 |
function feeds_ui_edit_page($importer, $active = 'help', $plugin_key = '') { |
|
277 |
|
|
276 |
function feeds_ui_edit_page(FeedsImporter $importer, $active = 'help', $plugin_key = '') { |
|
278 | 277 |
// Get plugins and configuration. |
279 | 278 |
$plugins = FeedsPlugin::all(); |
279 |
|
|
280 | 280 |
$config = $importer->config; |
281 | 281 |
// Base path for changing the active container. |
282 | 282 |
$path = 'admin/structure/feeds/' . $importer->id; |
... | ... | |
291 | 291 |
$active_container['body'] = '<div class="help feeds-admin-ui">' . feeds_ui_edit_help() . '</div>'; |
292 | 292 |
unset($active_container['actions']); |
293 | 293 |
break; |
294 |
|
|
294 | 295 |
case 'fetcher': |
295 | 296 |
case 'parser': |
296 | 297 |
case 'processor': |
297 | 298 |
$active_container['title'] = t('Select a !plugin_type', array('!plugin_type' => $active)); |
298 | 299 |
$active_container['body'] = drupal_get_form('feeds_ui_plugin_form', $importer, $active); |
299 | 300 |
break; |
301 |
|
|
300 | 302 |
case 'settings': |
301 | 303 |
drupal_add_js(drupal_get_path('module', 'ctools') . '/js/dependent.js'); |
302 | 304 |
ctools_include('dependent'); |
... | ... | |
311 | 313 |
$active_container['body'] = feeds_get_form($plugin, 'configForm'); |
312 | 314 |
} |
313 | 315 |
break; |
316 |
|
|
314 | 317 |
case 'mapping': |
315 |
$active_container['title'] = t('Mapping for !processor', array('!processor' => $plugins[$config['processor']['plugin_key']]['name'])); |
|
318 |
$processor_name = isset($plugins[$config['processor']['plugin_key']]['name']) ? $plugins[$config['processor']['plugin_key']]['name'] : $plugins['FeedsMissingPlugin']['name']; |
|
319 |
$active_container['title'] = t('Mapping for @processor', array('@processor' => $processor_name)); |
|
316 | 320 |
$active_container['body'] = drupal_get_form('feeds_ui_mapping_form', $importer); |
317 | 321 |
break; |
318 | 322 |
} |
... | ... | |
346 | 350 |
$config_info[] = $info; |
347 | 351 |
|
348 | 352 |
// Fetcher. |
349 |
$fetcher = $plugins[$config['fetcher']['plugin_key']];
|
|
353 |
$fetcher = isset($plugins[$config['fetcher']['plugin_key']]) ? $plugins[$config['fetcher']['plugin_key']] : $plugins['FeedsMissingPlugin'];
|
|
350 | 354 |
$actions = array(); |
351 |
if (feeds_get_form($importer->fetcher, 'configForm')) {
|
|
355 |
if ($importer->fetcher->hasConfigForm()) {
|
|
352 | 356 |
$actions = array(l(t('Settings'), $path . '/settings/' . $config['fetcher']['plugin_key'])); |
353 | 357 |
} |
354 | 358 |
$info['title'] = t('Fetcher'); |
... | ... | |
363 | 367 |
$config_info[] = $info; |
364 | 368 |
|
365 | 369 |
// Parser. |
366 |
$parser = $plugins[$config['parser']['plugin_key']];
|
|
370 |
$parser = isset($plugins[$config['parser']['plugin_key']]) ? $plugins[$config['parser']['plugin_key']] : $plugins['FeedsMissingPlugin'];
|
|
367 | 371 |
$actions = array(); |
368 |
if (feeds_get_form($importer->parser, 'configForm')) {
|
|
372 |
if ($importer->parser->hasConfigForm()) {
|
|
369 | 373 |
$actions = array(l(t('Settings'), $path . '/settings/' . $config['parser']['plugin_key'])); |
370 | 374 |
} |
371 | 375 |
$info['title'] = t('Parser'); |
... | ... | |
380 | 384 |
$config_info[] = $info; |
381 | 385 |
|
382 | 386 |
// Processor. |
383 |
$processor = $plugins[$config['processor']['plugin_key']];
|
|
387 |
$processor = isset($plugins[$config['processor']['plugin_key']]) ? $plugins[$config['processor']['plugin_key']] : $plugins['FeedsMissingPlugin'];
|
|
384 | 388 |
$actions = array(); |
385 |
if (feeds_get_form($importer->processor, 'configForm')) {
|
|
389 |
if ($importer->processor->hasConfigForm()) {
|
|
386 | 390 |
$actions[] = l(t('Settings'), $path . '/settings/' . $config['processor']['plugin_key']); |
387 | 391 |
} |
388 | 392 |
$actions[] = l(t('Mapping'), $path . '/mapping'); |
... | ... | |
493 | 497 |
$form['#prefix'] = '<div id="feeds-ui-mapping-form-wrapper">'; |
494 | 498 |
$form['#suffix'] = '</div>'; |
495 | 499 |
|
500 |
// Show message when target configuration gets changed. |
|
501 |
if (!empty($form_state['mapping_settings'])) { |
|
502 |
$form['#mapping_settings'] = $form_state['mapping_settings']; |
|
503 |
$form['changed'] = array( |
|
504 |
'#theme_wrappers' => array('container'), |
|
505 |
'#attributes' => array('class' => array('messages', 'warning')), |
|
506 |
'#markup' => t('* Changes made to target configuration are stored temporarily. Click Save to make your changes permanent.'), |
|
507 |
); |
|
508 |
} |
|
509 |
|
|
496 | 510 |
// Get mapping sources from parsers and targets from processor, format them |
497 | 511 |
// for output. |
498 | 512 |
// Some parsers do not define mapping sources but let them define on the fly. |
... | ... | |
620 | 634 |
} |
621 | 635 |
|
622 | 636 |
if ($form_state['mapping_settings_edit'] === $i) { |
623 |
// Build the form. |
|
624 |
if (isset($target['form_callback'])) { |
|
625 |
$settings_form = call_user_func($target['form_callback'], $mapping, $target, $form, $form_state); |
|
626 |
} |
|
627 |
else { |
|
628 |
$settings_form = array(); |
|
637 |
$settings_form = array(); |
|
638 |
|
|
639 |
foreach ($target['form_callbacks'] as $callback) { |
|
640 |
$settings_form += call_user_func($callback, $mapping, $target, $form, $form_state); |
|
629 | 641 |
} |
630 | 642 |
|
631 | 643 |
// Merge in the optional unique form. |
... | ... | |
650 | 662 |
} |
651 | 663 |
else { |
652 | 664 |
// Build the summary. |
653 |
if (isset($target['summary_callback'])) { |
|
654 |
$summary = call_user_func($target['summary_callback'], $mapping, $target, $form, $form_state); |
|
655 |
} |
|
656 |
else { |
|
657 |
$summary = ''; |
|
665 |
$summary = array(); |
|
666 |
|
|
667 |
foreach ($target['summary_callbacks'] as $callback) { |
|
668 |
$summary[] = call_user_func($callback, $mapping, $target, $form, $form_state); |
|
658 | 669 |
} |
659 | 670 |
|
671 |
// Filter out empty summary values. |
|
672 |
$summary = implode('<br />', array_filter($summary)); |
|
673 |
|
|
660 | 674 |
// Append the optional unique summary. |
661 | 675 |
if ($optional_unique_summary = feeds_ui_mapping_settings_optional_unique_summary($mapping, $target, $form, $form_state)) { |
662 | 676 |
$summary .= ' ' . $optional_unique_summary; |
... | ... | |
679 | 693 |
); |
680 | 694 |
} |
681 | 695 |
} |
696 |
return array(); |
|
682 | 697 |
} |
683 | 698 |
|
684 | 699 |
/** |
... | ... | |
718 | 733 |
* Validation handler for feeds_ui_mapping_form(). |
719 | 734 |
*/ |
720 | 735 |
function feeds_ui_mapping_form_validate($form, &$form_state) { |
721 |
if (empty($form_state['values']['source']) xor empty($form_state['values']['target'])) {
|
|
736 |
if (!strlen($form_state['values']['source']) xor !strlen($form_state['values']['target'])) {
|
|
722 | 737 |
|
723 | 738 |
// Check triggering_element here so we can react differently for ajax |
724 | 739 |
// submissions. |
... | ... | |
726 | 741 |
|
727 | 742 |
// Regular form submission. |
728 | 743 |
case 'op': |
729 |
if (empty($form_state['values']['source'])) {
|
|
744 |
if (!strlen($form_state['values']['source'])) {
|
|
730 | 745 |
form_error($form['source'], t('You must select a mapping source.')); |
731 | 746 |
} |
732 | 747 |
else { |
... | ... | |
790 | 805 |
|
791 | 806 |
$processor->addConfig(array('mappings' => $mappings)); |
792 | 807 |
|
793 |
if (!empty($form_state['values']['source']) && !empty($form_state['values']['target'])) {
|
|
808 |
if (strlen($form_state['values']['source']) && strlen($form_state['values']['target'])) {
|
|
794 | 809 |
try { |
795 | 810 |
$mappings = $processor->getMappings(); |
796 | 811 |
$mappings[] = array( |
... | ... | |
819 | 834 |
$result = array(); |
820 | 835 |
foreach ($options as $k => $v) { |
821 | 836 |
if (is_array($v) && !empty($v['name'])) { |
822 |
$result[$k] = $v['name']; |
|
837 |
$result[$k] = $v['name'] . ' (' . $k . ')';
|
|
823 | 838 |
} |
824 | 839 |
elseif (is_array($v)) { |
825 | 840 |
$result[$k] = $k; |
... | ... | |
1016 | 1031 |
// Some parsers do not define source options. |
1017 | 1032 |
$source = isset($form['source']['#options'][$mapping['source']]) ? $form['source']['#options'][$mapping['source']] : $mapping['source']; |
1018 | 1033 |
$target = isset($form['target']['#options'][$mapping['target']]) ? check_plain($form['target']['#options'][$mapping['target']]) : '<em>' . t('Missing') . '</em>'; |
1034 |
// Add indicator to target if target configuration changed. |
|
1035 |
if (isset($form['#mapping_settings'][$i])) { |
|
1036 |
$target .= '<span class="warning">*</span>'; |
|
1037 |
} |
|
1019 | 1038 |
$rows[] = array( |
1020 | 1039 |
'data' => array( |
1021 | 1040 |
check_plain($source), |
... | ... | |
1043 | 1062 |
drupal_render($form['add']), |
1044 | 1063 |
'', |
1045 | 1064 |
); |
1046 |
$output = '<div class="help feeds-admin-ui">' . drupal_render($form['help']) . '</div>'; |
|
1065 |
$output = ''; |
|
1066 |
if (!empty($form['changed'])) { |
|
1067 |
// This form element is only available if target configuration changed. |
|
1068 |
$output .= drupal_render($form['changed']); |
|
1069 |
} |
|
1070 |
$output .= '<div class="help feeds-admin-ui">' . drupal_render($form['help']) . '</div>'; |
|
1047 | 1071 |
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'feeds-ui-mapping-overview'))); |
1048 | 1072 |
|
1049 | 1073 |
// Build the help table that explains available sources. |
... | ... | |
1064 | 1088 |
$rows = array(); |
1065 | 1089 |
foreach (element_children($form['legendset']['legend']['targets']) as $k) { |
1066 | 1090 |
$rows[] = array( |
1067 |
check_plain(drupal_render($form['legendset']['legend']['targets'][$k]['name'])), |
|
1091 |
check_plain(drupal_render($form['legendset']['legend']['targets'][$k]['name']) . ' (' . $k . ')'),
|
|
1068 | 1092 |
check_plain(drupal_render($form['legendset']['legend']['targets'][$k]['description'])), |
1069 | 1093 |
); |
1070 | 1094 |
} |
... | ... | |
1148 | 1172 |
'%api_version' => feeds_api_version()))); |
1149 | 1173 |
} |
1150 | 1174 |
|
1151 |
$existing = feeds_importer($feeds_importer->id); |
|
1152 |
if ($existing && !$form_state['values']['id_override'] && $existing->export_type != EXPORT_IN_CODE) { |
|
1153 |
return form_error($form['id'], t('Feeds importer already exists with that id.')); |
|
1175 |
// Change to user-supplied id. |
|
1176 |
if ($form_state['values']['id']) { |
|
1177 |
$feeds_importer->id = $form_state['values']['id']; |
|
1178 |
} |
|
1179 |
|
|
1180 |
$exists = feeds_ui_importer_machine_name_exists($feeds_importer->id); |
|
1181 |
|
|
1182 |
if ($exists && !$form_state['values']['id_override']) { |
|
1183 |
if (feeds_importer($feeds_importer->id)->export_type != EXPORT_IN_CODE) { |
|
1184 |
return form_error($form['id'], t('Feeds importer already exists with that id.')); |
|
1185 |
} |
|
1154 | 1186 |
} |
1155 | 1187 |
|
1156 | 1188 |
if (!$form_state['values']['bypass_validation']) { |
... | ... | |
1172 | 1204 |
*/ |
1173 | 1205 |
function feeds_ui_importer_import_submit($form, &$form_state) { |
1174 | 1206 |
$importer = $form_state['importer']; |
1175 |
$importer = feeds_importer($importer->id); |
|
1176 |
$importer->setConfig($importer->config); |
|
1207 |
|
|
1208 |
// Create a copy of the importer to preserve config. |
|
1209 |
$save = feeds_importer($importer->id); |
|
1210 |
$save->setConfig($importer->config); |
|
1177 | 1211 |
foreach (array('fetcher', 'parser', 'processor') as $type) { |
1178 |
$importer->$type->setConfig($importer->config[$type]['config']); |
|
1212 |
$save->setPlugin($importer->config[$type]['plugin_key']); |
|
1213 |
$save->$type->setConfig($importer->config[$type]['config']); |
|
1179 | 1214 |
} |
1180 |
$importer->save();
|
|
1215 |
$save->save();
|
|
1181 | 1216 |
|
1182 | 1217 |
drupal_set_message(t('Successfully imported the %id feeds importer.', array('%id' => $importer->id))); |
1183 | 1218 |
$form_state['redirect'] = 'admin/structure/feeds'; |
Formats disponibles : Unified diff
Update feeds 7.x-2.0-alpha9 -> 7.x-2.0-beta1
Install lib simplepie 1.3.1