From 0ccaed76097a0382fc4179944d5fefefa9507cf2 Mon Sep 17 00:00:00 2001
From: Alex Barth <alex_b@53995.no-reply.drupal.org>
Date: Wed, 16 Sep 2009 22:33:23 +0000
Subject: [PATCH] Add file fetcher, add source form handling.

---
 feeds.module                 |  5 +++++
 feeds_ui/feeds_ui.admin.inc  |  1 +
 includes/feed.inc            | 39 ++++++++++++++++++++++++------------
 plugins/FeedsFileFetcher.inc | 33 ++++++++++++++++++++++++++++++
 4 files changed, 65 insertions(+), 13 deletions(-)
 create mode 100644 plugins/FeedsFileFetcher.inc

diff --git a/feeds.module b/feeds.module
index ec6f42d6..5870e50c 100644
--- a/feeds.module
+++ b/feeds.module
@@ -43,6 +43,11 @@ function feeds_feeds_plugin() {
       'file' => drupal_get_path('module', 'feeds') .'/plugins/FeedsHttpFetcher.inc',
       'parent' => 'FeedsFetcher',
     ),
+    'FeedsFileFetcher' => array(
+      'name' => t('File fetcher'),
+      'file' =>  drupal_get_path('module', 'feeds') .'/plugins/FeedsFileFetcher.inc',
+      'parent' => 'FeedsFetcher',
+    ),
     'FeedsCSVParser' => array(
       'name' => t('CSV parser'),
       'file' => drupal_get_path('module', 'feeds') .'/plugins/FeedsCSVParser.inc',
diff --git a/feeds_ui/feeds_ui.admin.inc b/feeds_ui/feeds_ui.admin.inc
index b0b576f5..6bf95efa 100644
--- a/feeds_ui/feeds_ui.admin.inc
+++ b/feeds_ui/feeds_ui.admin.inc
@@ -64,6 +64,7 @@ function feeds_ui_build_create_form(&$form_state) {
     );
   }
   else {
+    // @todo: present plugin form first.
     feeds_include('feed');
     $feed = feeds_get_feed($form_state['storage']['id']);
     $form['settings'] = array(
diff --git a/includes/feed.inc b/includes/feed.inc
index bd3c8923..45fdfea2 100644
--- a/includes/feed.inc
+++ b/includes/feed.inc
@@ -56,25 +56,15 @@ class Feed extends FeedsConfigurable {
       '#options' => array('' => t('None')) + node_get_types('names'),
       '#default_value' => $this->config['content_type'],
     );
-    $form['source'] = array(
-      '#type' => 'textfield',
-      '#title' => t('URL'),
-      '#description' => t('Enter the URL for this feed @todo: delegate this form to plugin, hide if content type is picked.'),
-      '#default_value' => $config['source']['id'],
-      );
-    $form['update'] = array(
-      '#type' => 'radios',
-      '#title' => t('Update existing'),
-      '#options' => array(1 => t('Yes'), 0 => t('No')),
-      '#default_value' => $this->config['update'],
-    );
-    $period = drupal_map_assoc(array(1, 900, 1800, 3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 3628800, 4838400, 7257600, 15724800, 31536000), 'format_interval');
+    $form['source'] = $this->fetcher->sourceForm($form_state);
+    $period = drupal_map_assoc(array(1, 900, 1800, 3600, 10800, 21600, 43200, 86400, 259200, 604800, 2419200), 'format_interval');
     $period[FEEDAPI_CRON_NEVER_REFRESH] = t('Do not refresh periodically');
     $period[1] = t('As often as possible');
     $form['refresh_period'] = array(
       '#type' => 'select',
       '#title' => t('Minimum refresh period'),
       '#options' => $period,
+      '#description' => t('This is the minimum time that must elapse before a feed may be refreshed automatically.'),
       '#default_value' => $this->config['refresh_period'],
     );
     return $form;
@@ -327,6 +317,29 @@ class FeedsConfigurable {
  * plugin type. See hook_feeds_plugin().
  */
 class FeedsFetcher extends FeedsConfigurable {
+
+  /**
+   * Source form.
+   */
+  public function sourceForm(&$form_state) {
+    $form = array();
+    $form['source'] = array(
+      '#type' => 'textfield',
+      '#title' => t('URL'),
+      '#description' => t('Enter the URL for this feed.'),
+      '#default_value' => $this->config['source'],
+    );
+    return $form;
+  }
+
+  /**
+   * Fetch content from a source and return it.
+   * 
+   * Stub method. Every class that extends FeedsFetcher must implement this method.
+   *
+   * @param $source 
+   *   Source value as entered by user through sourceForm().
+   */
   public function fetch($source) {
     return NULL;
   }
diff --git a/plugins/FeedsFileFetcher.inc b/plugins/FeedsFileFetcher.inc
new file mode 100644
index 00000000..4d7e0bef
--- /dev/null
+++ b/plugins/FeedsFileFetcher.inc
@@ -0,0 +1,33 @@
+<?php
+// $Id$
+/**
+ * @file
+ * Home of the FeedsFileFetcher.
+ */
+
+/**
+ * Fetches data via HTTP.
+ */
+class FeedsFileFetcher extends FeedsFetcher {
+
+  /**
+   * Source form.
+   */
+  public function sourceForm(&$form_state) {
+    $form = array();
+    $form['source'] = array(
+      '#type' => 'file',
+      '#title' => t('File'),
+      '#description' => t('Upload a file.'),
+      '#default_value' => $this->config['source'],
+    );
+    return $form;
+  }
+
+  /**
+   * Fetch a local resource.
+   */
+  public function fetch($source) {
+    // @todo
+  }
+}
\ No newline at end of file
-- 
GitLab