5 * Menu callbacks, form callbacks and helpers.
9 * Render a page of available importers.
11 function feeds_page() {
13 if ($importers = feeds_importer_load_all()) {
14 foreach ($importers as
$importer) {
15 if ($importer->disabled
) {
18 if (!(user_access('import '.
$importer->id .
' feeds') || user_access('administer feeds'))) {
21 if (empty($importer->config
['content_type'])) {
22 $link = 'import/'.
$importer->id
;
23 $title = $importer->config
['name'];
25 elseif (user_access('create '.
$importer->config
['content_type'] .
' content')) {
26 $link = 'node/add/'.
str_replace('_', '-', $importer->config
['content_type']);
27 $title = node_type_get_name($importer->config
['content_type']);
31 check_plain($importer->config
['description']),
39 return theme('table', array('header' => $header, 'rows' => $rows));
43 * Render a feeds import form on import/[config] pages.
45 function feeds_import_form($form, &$form_state, $importer_id) {
46 $source = feeds_source($importer_id, empty($form['nid']['#value']) ?
0 : $form['nid']['#value']);
49 $form['#importer_id'] = $importer_id;
50 // @todo Move this into fetcher?
51 $form['#attributes']['enctype'] = 'multipart/form-data';
52 $form['feeds'] = array(
53 '#type' => 'fieldset',
56 $form['feeds'] += $source->configForm($form_state);
57 $form['submit'] = array(
59 '#value' => t('Import'),
65 * Validation handler for node forms and feeds_import_form().
67 function feeds_import_form_validate($form, &$form_state) {
68 // @todo This may be a problem here, as we don't have a feed_nid at this point.
69 feeds_source($form['#importer_id'])->configFormValidate($form_state['values']['feeds']);
73 * Submit handler for feeds_import_form().
75 function feeds_import_form_submit($form, &$form_state) {
77 // Save source and import.
78 $source = feeds_source($form['#importer_id']);
79 $source->addConfig($form_state['values']['feeds']);
82 // Refresh feed if import on create is selected.
83 if ($source->importer
->config
['import_on_create']) {
84 feeds_batch_set(t('Importing'), 'import', $form['#importer_id']);
87 // Add to schedule, make sure importer is scheduled, too.
89 $source->importer
->schedule();
93 * Render a feeds import form on node/id/import pages.
95 function feeds_import_tab_form($form, &$form_state, $node) {
96 $importer_id = feeds_get_importer_id($node->type
);
99 $form['#feed_nid'] = $node->nid
;
100 $form['#importer_id'] = $importer_id;
101 $form['#redirect'] = 'node/'.
$node->nid
;
102 return confirm_form($form, t('Import all content from feed?'), 'node/'.
$node->nid
, '', t('Import'), t('Cancel'), 'confirm feeds update');
106 * Submit handler for feeds_import_tab_form().
108 function feeds_import_tab_form_submit($form, &$form_state) {
109 $form_state['redirect'] = $form['#redirect'];
110 feeds_batch_set(t('Importing'), 'import', $form['#importer_id'], $form['#feed_nid']);
114 * Render a feeds delete form.
116 * Used on both node pages and configuration pages.
117 * Therefore $node may be missing.
119 function feeds_delete_tab_form($form, &$form_state, $importer_id, $node = NULL
) {
121 $form['#redirect'] = 'import/'.
$importer_id;
124 $importer_id = feeds_get_importer_id($node->type
);
125 $form['#feed_nid'] = $node->nid
;
126 $form['#redirect'] = 'node/'.
$node->nid
;
128 // Form cannot pass on feed object.
129 $form['#importer_id'] = $importer_id;
130 return confirm_form($form, t('Delete all items from feed?'), $form['#redirect'], '', t('Delete'), t('Cancel'), 'confirm feeds update');
134 * Submit handler for feeds_delete_tab_form().
136 function feeds_delete_tab_form_submit($form, &$form_state) {
137 $form_state['redirect'] = $form['#redirect'];
138 $feed_nid = empty($form['#feed_nid']) ?
0 : $form['#feed_nid'];
139 feeds_batch_set(t('Deleting'), 'clear', $form['#importer_id'], $feed_nid);
143 * Handle a fetcher callback.
145 function feeds_fetcher_callback($importer, $feed_nid = 0) {
146 if ($importer instanceof FeedsImporter
) {
147 return $importer->fetcher
->request($feed_nid);
149 drupal_access_denied();
153 * Theme upload widget.
155 function theme_feeds_upload($variables) {
156 $element = $variables['element'];
157 drupal_add_css(drupal_get_path('module', 'feeds') .
'/feeds.css');
158 _form_set_class($element, array('form-file'));
160 if (!empty($element['#file_info'])) {
161 $file = $element['#file_info'];
162 $wrapper = file_stream_wrapper_get_instance_by_uri($file->uri
);
163 $description .
= '<div class="file-info">';
164 $description .
= '<div class="file-name">';
165 $description .
= l($file->filename
, $wrapper->getExternalUrl());
166 $description .
= '</div>';
167 $description .
= '<div class="file-size">';
168 $description .
= format_size($file->filesize);
169 $description .
= '</div>';
170 $description .
= '<div class="file-mime">';
171 $description .
= check_plain($file->filemime
);
172 $description .
= '</div>';
173 $description .
= '</div>';
175 $description .
= '<div class="file-upload">';
176 $description .
= '<input type="file" name="'.
$element['#name'] .
'"'.
($element['#attributes'] ?
' '.
drupal_attributes($element['#attributes']) : '') .
' id="'.
$element['#id'] .
'" size="'.
$element['#size'] .
"\" />\n";
177 $description .
= '</div>';
178 $element['#description'] = $description;
180 // For some reason not unsetting #title leads to printing the title twice.
181 unset($element['#title']);
182 return theme('form_element', $element);