? aggregator-fix-relative-links-rev-4.patch
? aggregator-fix-relative-links-rev-5.patch
? comment_form_submit_redirect_fix-D7-rev2.patch
? comment_form_submit_redirect_fix-D7.patch
? remove_.patch
? remove_page_from_remaining_hook_node_view.patch
? rename_drupal_execute_rev2.patch
? modules/aggregator/.directory
Index: modules/aggregator/aggregator.parser.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/aggregator/aggregator.parser.inc,v
retrieving revision 1.1
diff -u -p -r1.1 aggregator.parser.inc
--- modules/aggregator/aggregator.parser.inc	22 Dec 2008 19:38:31 -0000	1.1
+++ modules/aggregator/aggregator.parser.inc	24 Mar 2009 06:34:05 -0000
@@ -149,6 +149,11 @@ function aggregator_parse_feed(&$data, $
       $item['DESCRIPTION'] = $item['CONTENT'];
     }
 
+    // Try to replace all relative links with absolute links.
+    if (!empty($item['DESCRIPTION'])) {
+      $item['DESCRIPTION'] = aggregator_convert_relative_links($item['LINK'], $item['DESCRIPTION']);
+    }
+
     // Try to resolve and parse the item's publication date.
     $date = '';
     foreach (array('PUBDATE', 'DC:DATE', 'DCTERMS:ISSUED', 'DCTERMS:CREATED', 'DCTERMS:MODIFIED', 'ISSUED', 'CREATED', 'MODIFIED', 'PUBLISHED', 'UPDATED') as $key) {
@@ -325,3 +330,40 @@ function aggregator_parse_w3cdtf($date_s
     return FALSE;
   }
 }
+
+/**
+ * Convert all relative links contained in the src and href elements within 
+ * a feed item's description to absolute links.
+ *
+ * @param $link
+ *   This is the link to the item, taken from $item['LINK'].
+ * @param $description
+ *   The description, taken from $item['DESCRIPTION'].
+ * @return
+ *   The string passed in $description with all relative links changed.
+ */
+function aggregator_convert_relative_links($link, $description) {
+
+  // Create parts to use in the replacement patterns.
+  $item_url_parts = parse_url($link);
+  $item_base_url  = $item_url_parts['scheme'] . '://' . $item_url_parts['host'];
+    
+  if (array_key_exists('path', $item_url_parts)) {
+    $item_path_parts = pathinfo($item_url_parts['path']);
+    $item_path_dirname = $item_path_parts['dirname'] . '/';
+  } 
+  else {
+    $item_path_dirname = $item_base_url;
+  }
+
+  // Replace all links starting with '/'.
+  $regexp      = "/\b(href|src)(\s*=\s*['\"])([\/][A-Za-z0-9\/]*)(['\"])/";
+  $description = preg_replace($regexp, '$1$2' . $item_base_url . '$3$4', $description);
+
+  // Replace all relative links not starting with '/'. Absolute links are not matched, 
+  // since ':' is not in the capture pattern.
+  $regexp      = "/\b(href|src)(\s*=\s*['\"])([^\/][A-Za-z0-9\/]*)(['\"])/";
+  $description = preg_replace($regexp, '$1$2' . $item_path_dirname . '$3$4', $description);
+
+  return $description;
+}
