6 * Menu callbacks, form callbacks and helpers.
10 * Render a page of available importers.
12 function feeds_page() {
14 if ($importers = feeds_importer_load_all()) {
15 foreach ($importers as
$importer) {
16 if ($importer->disabled
) {
19 if (!(user_access('import '.
$importer->id .
' feeds') || user_access('administer feeds'))) {
22 if (empty($importer->config
['content_type'])) {
23 $link = 'import/'.
$importer->id
;
24 $title = $importer->config
['name'];
26 elseif (user_access('create '.
$importer->config
['content_type'] .
' content')) {
27 $link = 'node/add/'.
str_replace('_', '-', $importer->config
['content_type']);
28 $title = node_type_get_name($importer->config
['content_type']);
32 check_plain($importer->config
['description']),
40 return theme('table', array('header' => $header, 'rows' => $rows));
44 * Render a feeds import form on import/[config] pages.
46 function feeds_import_form($form, &$form_state, $importer_id) {
47 $source = feeds_source($importer_id, empty($form['nid']['#value']) ?
0 : $form['nid']['#value']);
50 $form['#importer_id'] = $importer_id;
51 // @todo Move this into fetcher?
52 $form['#attributes']['enctype'] = 'multipart/form-data';
53 $form['feeds'] = array(
54 '#type' => 'fieldset',
57 $form['feeds'] += $source->configForm($form_state);
58 $form['submit'] = array(
60 '#value' => t('Import'),
66 * Validation handler for node forms and feeds_import_form().
68 function feeds_import_form_validate($form, &$form_state) {
69 // @todo This may be a problem here, as we don't have a feed_nid at this point.
70 feeds_source($form['#importer_id'])->configFormValidate($form_state['values']['feeds']);
74 * Submit handler for feeds_import_form().
76 function feeds_import_form_submit($form, &$form_state) {
78 // Save source and import.
79 $source = feeds_source($form['#importer_id']);
80 $source->addConfig($form_state['values']['feeds']);
83 // Refresh feed if import on create is selected.
84 if ($source->importer
->config
['import_on_create']) {
85 feeds_batch_set(t('Importing'), 'import', $form['#importer_id']);
88 // Add to schedule, make sure importer is scheduled, too.
90 $source->importer
->schedule();
94 * Render a feeds import form on node/id/import pages.
96 function feeds_import_tab_form($form, &$form_state, $node) {
97 $importer_id = feeds_get_importer_id($node->type
);
100 $form['#feed_nid'] = $node->nid
;
101 $form['#importer_id'] = $importer_id;
102 $form['#redirect'] = 'node/'.
$node->nid
;
103 return confirm_form($form, t('Import all content from feed?'), 'node/'.
$node->nid
, '', t('Import'), t('Cancel'), 'confirm feeds update');
107 * Submit handler for feeds_import_tab_form().
109 function feeds_import_tab_form_submit($form, &$form_state) {
110 $form_state['redirect'] = $form['#redirect'];
111 feeds_batch_set(t('Importing'), 'import', $form['#importer_id'], $form['#feed_nid']);
115 * Render a feeds delete form.
117 * Used on both node pages and configuration pages.
118 * Therefore $node may be missing.
120 function feeds_delete_tab_form($form, &$form_state, $importer_id, $node = NULL
) {
122 $form['#redirect'] = 'import/'.
$importer_id;
125 $importer_id = feeds_get_importer_id($node->type
);
126 $form['#feed_nid'] = $node->nid
;
127 $form['#redirect'] = 'node/'.
$node->nid
;
129 // Form cannot pass on feed object.
130 $form['#importer_id'] = $importer_id;
131 return confirm_form($form, t('Delete all items from feed?'), $form['#redirect'], '', t('Delete'), t('Cancel'), 'confirm feeds update');
135 * Submit handler for feeds_delete_tab_form().
137 function feeds_delete_tab_form_submit($form, &$form_state) {
138 $form_state['redirect'] = $form['#redirect'];
139 $feed_nid = empty($form['#feed_nid']) ?
0 : $form['#feed_nid'];
140 feeds_batch_set(t('Deleting'), 'clear', $form['#importer_id'], $feed_nid);
144 * Handle a fetcher callback.
146 function feeds_fetcher_callback($importer, $feed_nid = 0) {
147 if ($importer instanceof FeedsImporter
) {
148 return $importer->fetcher
->request($feed_nid);
150 drupal_access_denied();
154 * Theme upload widget.
156 function theme_feeds_upload($variables) {
157 $element = $variables['element'];
158 drupal_add_css(drupal_get_path('module', 'feeds') .
'/feeds.css');
159 _form_set_class($element, array('form-file'));
161 if (!empty($element['#file_info'])) {
162 $info = $element['#file_info'];
163 $description .
= '<div class="file-info">';
164 $description .
= '<div class="file-name">';
165 $description .
= l(basename($info['path']), $info['path']);
166 $description .
= '</div>';
167 $description .
= '<div class="file-size">';
168 $description .
= format_size($info['size']);
169 $description .
= '</div>';
170 if (isset($info['mime'])) {
171 $description .
= '<div class="file-mime">';
172 $description .
= check_plain($info['mime']);
173 $description .
= '</div>';
175 $description .
= '</div>';
177 $description .
= '<div class="file-upload">';
178 $description .
= '<input type="file" name="'.
$element['#name'] .
'"'.
($element['#attributes'] ?
' '.
drupal_attributes($element['#attributes']) : '') .
' id="'.
$element['#id'] .
'" size="'.
$element['#size'] .
"\" />\n";
179 $description .
= '</div>';
180 $element['#description'] = $description;
181 return theme('form_element', $element);