? feeds_imagegrabber-direct_file_grabbing.20100719.patch
? feeds_imagegrabber-direct_url_grabber.png
? feeds_imagegrabber-use_library_directory.20100718.patch
Index: README.TXT
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/feeds_imagegrabber/Attic/README.TXT,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 README.TXT
--- README.TXT	12 Mar 2010 14:46:55 -0000	1.1.2.2
+++ README.TXT	19 Jul 2010 14:58:09 -0000
@@ -18,6 +18,7 @@ Installation
 
 1) Place this module directory in your modules folder (this will usually be "sites/all/modules/").
 2) Download the UrlToAbsolute package (http://sourceforge.net/projects/absoluteurl) and copy the "url_to_absolute.php" file to the feeds_imagegrabber directory.
+2.a) Alternatively, you can place the downloaded library into "sites/all/libraries" such that the php script can be found at "sites/all/libraries/AbsoluteUrl/url_to_absolute.php"
 3) Enable the module.
 
 Usage
Index: feeds_imagegrabber.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/feeds_imagegrabber/Attic/feeds_imagegrabber.install,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 feeds_imagegrabber.install
--- feeds_imagegrabber.install	12 Mar 2010 14:46:55 -0000	1.1.2.2
+++ feeds_imagegrabber.install	19 Jul 2010 14:58:09 -0000
@@ -94,11 +94,11 @@ function feeds_imagegrabber_requirements
   switch ($phase) {
     case 'install':
     case 'runtime':
-      $path = drupal_get_path('module', 'feeds_imagegrabber') .'/url_to_absolute.php';
-      if (!file_exists($path)) {
+      module_load_include('module', 'feeds_imagegrabber', 'feeds_imagegrabber');
+      if (! feeds_imagegrabber_load_url_to_absolute()) {
         $requirements['feeds_imagegrabber_absoluteurl'] = array(
           'title' => $t("Feeds Image Grabber"),
-          'description' => $t("Obtain the !conversion package and copy <b>url_to_absolute.php</b> to the feeds_imagegrabber directory.",
+          'description' => $t("Obtain the !conversion package and copy <b>url_to_absolute.php</b> to either the feeds_imagegrabber directory, or to <code>sites/all/libraries</code> so that the php script can be found at <code>sites/all/libraries/AbsoluteUrl/url_to_absolute.php</code>.",
             array('!conversion' => l('UrlToAbsolute', 'http://sourceforge.net/projects/absoluteurl', array('absolute' => TRUE)))
           ),
           'severity' => $phase == 'install' ? REQUIREMENT_WARNING : REQUIREMENT_ERROR,
Index: feeds_imagegrabber.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/feeds_imagegrabber/feeds_imagegrabber.module,v
retrieving revision 1.1.4.7
diff -u -p -r1.1.4.7 feeds_imagegrabber.module
--- feeds_imagegrabber.module	28 Mar 2010 03:31:13 -0000	1.1.4.7
+++ feeds_imagegrabber.module	19 Jul 2010 14:58:10 -0000
@@ -15,6 +15,14 @@
  */
 define('FIG_HTTP_REQUEST_TIMEOUT', 1);
 
+/**
+ * Options used as parameters to feeds_imagegrabber_webpage_scraper
+ */
+define('FIG_SCRAPER_METHOD_NONE', 0);
+define('FIG_SCRAPER_METHOD_ID', 1);
+define('FIG_SCRAPER_METHOD_CLASS', 2);
+define('FIG_SCRAPER_METHOD_URL', 3);
+
 //=============
 //DRUPAL HOOKS.
 //=============
@@ -55,9 +63,10 @@ function feeds_imagegrabber_form_alter(&
         '#type' => 'radios',
         '#title' => t('Search for an image between the tag which is identified by'),
         '#options' => array(
-          t('None, search the whole web-page for the image.'),
-          t('an Id'),
-          t('a Class'),
+          FIG_SCRAPER_METHOD_NONE => t('None, search the whole web-page for the image.'),
+          FIG_SCRAPER_METHOD_ID => t('an Id'),
+          FIG_SCRAPER_METHOD_CLASS => t('a Class'),
+          FIG_SCRAPER_METHOD_URL => t('No scraping, the link is a direct path to an image.'),
         ),
         '#default_value' => $settings['id_class'],
       );
@@ -95,7 +104,7 @@ function feeds_imagegrabber_form_node_va
   if ($form_state['values']['feeds_imagegrabber']['enabled'] == 1) {
     $id_class = $form_state['values']['feeds_imagegrabber']['id_class'];
     $id_class_desc = $form_state['values']['feeds_imagegrabber']['id_class_desc'];
-    if ($id_class) {
+    if ($id_class == FIG_SCRAPER_METHOD_ID || $id_class == FIG_SCRAPER_METHOD_ID) {
       if (!isset($id_class_desc) || empty($id_class_desc) || $id_class_desc == '') {
         form_set_error('feeds_imagegrabber][id_class_desc', "Specify the id/class of the desired tag.");
       }
@@ -187,16 +196,15 @@ function feeds_imagegrabber_feeds_node_p
 function feeds_imagegrabber_feeds_set_target($node, $target, $page_url) {
   $feed_nid     = $node->feeds_node_item->feed_nid;
   $settings     = feeds_imagegrabber_get_settings($feed_nid);
+
   if(!$settings || !$settings['enabled']) {
     return;
   }
   
-  $path = drupal_get_path('module', 'feeds_imagegrabber') .'/url_to_absolute.php';
-  if (!file_exists($path)) {
+  if (! feeds_imagegrabber_load_url_to_absolute()) {
     drupal_set_message(t('Feeds Image Grabber: The URL conversion script is missing. Go to <a href="!admin-reports-status">Status Report page</a>', array('!admin-reports-status' => url('admin/reports/status'))), 'error');
-    return;
+    return FALSE;
   }
-  require_once($path);
 
   list($field_name) = split(':', $target);
   $field        = content_fields($field_name, $node->type);
@@ -212,20 +220,28 @@ function feeds_imagegrabber_feeds_set_ta
   }
   
   if (valid_url($page_url)) {
-    $xml = feeds_imagegrabber_webpage_scraper($page_url, $settings['id_class'], $settings['id_class_desc'], $timeout);
-    if ($xml == FALSE) {
-      return;
+    if ($settings['id_class'] == FIG_SCRAPER_METHOD_URL) {
+      // No scraping, just get the image directly.
+      $images = array($page_url => 0);
     }
-  $timeout = $timeout - timer_read('page')/1000 + $page_time;
-  
-    $options = array(
-      'max_imagesize' => $max_filesize,
-      'timeout' => $timeout,
-      'feeling_lucky' => $settings['feeling_lucky'],
-    );
-
-    $images = feeds_imagegrabber_scrape_images($xml, $page_url, $options);
-    if ($images == FALSE || count($images) <= 0) {
+    else {
+      $xml = feeds_imagegrabber_webpage_scraper($page_url, $settings['id_class'], $settings['id_class_desc'], $timeout);
+      if ($xml == FALSE) {
+        return;
+      }
+    $timeout = $timeout - timer_read('page')/1000 + $page_time;
+    
+      $options = array(
+        'max_imagesize' => $max_filesize,
+        'timeout' => $timeout,
+        'feeling_lucky' => $settings['feeling_lucky'],
+      );
+      $images = feeds_imagegrabber_scrape_images($xml, $page_url, $options);
+      // Done scraping.
+    }
+    
+    if (empty($images)) {
+      watchdog('feeds_imagegrabber', 'No images to import from @url', array('@url' => $page_url), WATCHDOG_NOTICE);
       return;
     }
 
@@ -253,9 +269,15 @@ function feeds_imagegrabber_feeds_set_ta
           break;
         }
       }
+      else {
+        watchdog('feeds_imagegrabber', 'Failed to retrieve image file from @url', array('@url' => $url), WATCHDOG_WARNING);
+      }
     }
     $node->$field_name = $items;
   }
+  else {
+    watchdog('feeds_imagegrabber', 'Input to field was not a valid URL. @url', array('@url' => $page_url), WATCHDOG_WARNING);
+  }
 }
 
 //==================
@@ -448,17 +470,17 @@ function feeds_imagegrabber_webpage_scra
     return FALSE;
   }
 
-  if ($itype == 0) {
+  if ($itype == FIG_SCRAPER_METHOD_NONE) {
     $items = @$doc->getElementsByTagName("body");
     if ($items != NULL && $items->length > 0) {
       $dist = $items->item(0);
     }
     else $dist = NULL;
   }
-  elseif ($itype == 1) {
+  elseif ($itype == FIG_SCRAPER_METHOD_ID) {
     $dist = @$doc->getElementById($ivalue);
   }
-  elseif ($itype == 2) {
+  elseif ($itype == FIG_SCRAPER_METHOD_CLASS) {
     $xpath = new DOMXPath($doc);
     $items = @$xpath->query("//*[@class and contains(concat(' ',normalize-space(@class),' '),' $ivalue ')]");
     if ($items != NULL && $items->length > 0) {
@@ -837,3 +859,27 @@ function feeds_imagegrabber_http_request
   return $result;
 }
 
+/**
+ * Initializes the required AbsoluteUrl library.
+ * 
+ * Package from http://sourceforge.net/projects/absoluteurl
+ * is expected to be in the module directory or sites/all/libraries
+ * 
+ * @return bool success
+ */
+function feeds_imagegrabber_load_url_to_absolute() {
+  $paths = array(
+    drupal_get_path('module', 'feeds_imagegrabber'),
+    'sites/all/libraries/absoluteurl',
+    'sites/all/libraries/AbsoluteUrl',
+  );
+  foreach ($paths as $library_path) {
+    $path = $library_path . '/url_to_absolute.php';
+    if (file_exists($path)) {
+      require_once($path);
+      return TRUE;
+    }
+  }
+  // Failed.
+  return FALSE;
+}
\ No newline at end of file
