From 3e1ec6fb50b7c8e780318d56deead0c027296c3f Mon Sep 17 00:00:00 2001
From: Michael Strelan <mstrelan@gmail.com>
Date: Thu, 3 Mar 2011 11:38:26 +1000
Subject: [PATCH] Expose feed title, description and link

---
 plugins/FeedsParser.inc |   37 ++++++++++++++++++++++++++++++++++---
 1 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/plugins/FeedsParser.inc b/plugins/FeedsParser.inc
index e3bfd6d..8441f97 100644
--- a/plugins/FeedsParser.inc
+++ b/plugins/FeedsParser.inc
@@ -51,7 +51,23 @@ abstract class FeedsParser extends FeedsPlugin {
     drupal_alter('feeds_parser_sources', $sources, feeds_importer($this->id)->config['content_type']);
     if (!feeds_importer($this->id)->config['content_type']) {
       return $sources;
-    }
+    }
+    $sources['feed:title'] = array(
+      'name' => t('Feed: Title'),
+      'description' => t('The title of the feed.'),
+    );
+    $sources['feed:description'] = array(
+      'name' => t('Feed: Description'),
+      'description' => t('The description of the feed.'),
+    );
+    $sources['feed:link'] = array(
+      'name' => t('Feed: Link'),
+      'description' => t('The link of the feed.'),
+    );
+    $sources['parent:title'] = array(
+      'name' => t('Feed node: Title'),
+      'description' => t('The feed node title.'),
+    );
     $sources['parent:uid'] = array(
       'name' => t('Feed node: User ID'),
       'description' => t('The feed node author uid.'),
@@ -81,8 +97,23 @@ abstract class FeedsParser extends FeedsPlugin {
    * @see FeedsCSVParser::getSourceElement().
    */
   public function getSourceElement(FeedsImportBatch $batch, $element_key) {
-    if (($node = node_load($batch->feed_nid)) && $element_key == 'parent:uid') {
-      return $node->uid;
+    if (($node = node_load($batch->feed_nid)) && (strpos($element_key, 'parent:') === 0)) {
+      switch ($element_key) {
+        case 'parent:title':
+          return $node->title;
+        case 'parent:uid':
+          return $node->uid;
+      }
+    }
+    elseif (strpos($element_key, 'feed:') === 0) {
+      switch ($element_key) {
+        case 'feed:title':
+          return $batch->title;
+        case 'feed:description':
+          return $batch->description;
+        case 'feed:link':
+          return $batch->link;
+      }
     }
     $item = $batch->currentItem();
     return isset($item[$element_key]) ? $item[$element_key] : '';
-- 
1.7.4

