Extending views_rss

mcantelon - December 22, 2006 - 23:51

I am tying to use views_rss to provide an RSS feed of CCK content. Unfortunately, the views_rss module seems to only map standard node fields to the RSS fields so there doesn't seem to be a way to have my CCK fields included in the feed.

Can I develop a module that extends the views module to customize the RSS output (http://drupal.org/node/103475 seems to suggest that). If so, how do I do this (I've created custom modules and customized duplicates of modules, but have never extended an existing module)?

Any wisdom and insight much appreciated.

Mike

Actually, I think this

mcantelon - December 23, 2006 - 00:21

Actually, I think this comment will provide the solution... piping selected CCK fields into standard node fields. Not the most elegant solution, but it will do for now. ;)

Mike

I just did something similar

lyricnz - March 18, 2007 - 02:34

I wanted to provide a RSS feed of certain content-types from a site, with RSS-enclosures (like a podcast). Setting up the fields/filters using Views was no problem - it worked fine in Table mode. However, the URLs that needed to be included in the enclosure weren't real attachments, just CCK fields containing URLs. I ended up just hooking into nodeapi and adding elements to the RSS item:

function YOURMODULE_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op) {
    case 'rss item':
      if ($node->type=="lesson") {
        return array(
          array(
            'key' => 'enclosure',
            'attributes' => array(
              'url' => $node->field_skypecast_url[0]['value'],
              'type' => 'application/x-bittorrent'
            )
          )
      );
    }
  }
}

Not the most elegant solution, I expect, but works for me :)

Why was the code required?

lyricnz - March 18, 2007 - 03:15

The reason I had to do above, was views_rss doesn't really support fields in the same way a normal view does. Only standard fields appear in the RSS feed.

customizing views_rss feeds

zorroposada - March 20, 2007 - 23:47

Hi lyricnz,

where do you insert that piece of code?

do you put it inside views_rss.module?

thanks

Nooooo! You don't want to hack view_rss

lyricnz - March 25, 2007 - 20:07

Hacking other people's modules is almost always the wrong thing to do. You should create your own module, for "all the little hacks" that you need for your site. Add the above bit of code into the yourmodule.module

What File to Put Code?

leoklein - March 23, 2007 - 17:09

Look good and it seems like a terrible omission not to have CCK fields included in RSS Feeds -- using Views -- by default!

In any case, where were you putting this code -- and how might I modify it to include an Image Field?

Thanks for any help.

re: What File to Put Code?

mcantelon - March 23, 2007 - 17:20

I ended up creating a tiny module to use nodeapi to tweak feed content. I'm not using any CCK image fields currently, so the code should be something like the code below (which would theoretically insert the image at the beginning of the teaser):

function rss_full_articles_nodeapi(&$node, $op, $arg = 0) {

  if ($op == 'rss item' && $node->type == 'content_mytype') {
    $node->teaser = $node->field_myimage . $node->teaser;
  }
}

-Mike Cantelon
http://mikecantelon.com

What Calls This Function?

leoklein - March 31, 2007 - 19:58

Sorry for the display of ignorance. I'm not able to connect the dots.

I have no problem creating the module. But I don't understand how it's invoked.

If you create a new module

lyricnz - April 1, 2007 - 13:16

If you create a new module "frob", and name a function "frob_nodeapi()", then it will be called automatically by the Drupal framework whenever something happens that the nodeapi hook needs to know about. This is how Drupal works - by calling particular methods in your module when these sort of things happen.

See http://api.drupal.org/api/5/function/hook_nodeapi

In this case, we're using the fact that hook_nodeapi() is called by views_rss when it's building a RSS item. At this time, we can add arbitrary fields to the item. These are eventually rendered into XML. In my example, for content types "lesson", I am using another field of the object to add a RSS enclosure to the feed:

function YOURMODULE_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op) {
    case 'rss item':                   // hook_nodeapi is called for lots of different things - we only care about generating RSS feds
      if ($node->type=="lesson") {     // and in fact, only care about Content Type "lesson"
        return array(
          array(
            'key' => 'enclosure',
            'attributes' => array(
              'url' => $node->field_skypecast_url[0]['value'],
              'type' => 'application/x-bittorrent'
            )
          )
      );
    }
  }
}

In my case, the code was basically stolen from "upload" module, where it does the same thing - include a RSS enclosure in a feed, based on an attribute of the object. See the rss_item case in http://api.drupal.org/api/5/function/upload_nodeapi

RSS_feed for node_images

faunapolis - July 11, 2007 - 01:52

Hi,

I am trying to accomplish the same for images to be fed to the RSS feed from a view. But, it is not doing it, any ideas, thanks

Here is what I tried as a function/module:

function rss_full_articles_nodeapi(&$node, $op, $arg = 0) {

  if ($op == 'rss item' && $node->type == 'bonsai') {
    $node->teaser = $node_images->node_images_display . $node->teaser;
  }
}

rss_feed for node images

drasgardian - October 27, 2007 - 07:28

I think this is the same as what you're looking for. This will add the fully qualified urls for your image thumbnails and full sized images into an rss feed. I've used it to make a flash gallery viewer. (I called my module image_rss_view.module, so you'll need to change the function name).

function image_rss_view_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op) {
    case 'rss item':                   // hook_nodeapi is called for lots of different things - we only care about generating RSS feds
      if ($node->type=="image") {     // and in fact, only care about Content Type "image"
        return array(
          array(
            'key' => 'photo:imgsrc',
            'value' => file_create_url($node->images['_original'])
          ),
          array(
            'key' => 'photo:thumbnail',
            'value' => file_create_url($node->images['thumbnail'])
          )
      );
    }
  }
}

Extending Views RSS Completed

Shane Birley - September 4, 2007 - 00:27

We are just in the final few days of testing, but everything seems to be working decently. Once that is complete, by the end of the week, we will post the modules. These two projects add enclosure tags around media files and add them to the RSS feeds.

http://drupal.org/project/filefield_views_rss (for the filefield cck module)
http://drupal.org/project/link_views_rss (for the link cck module)

---
Shane Birley
Left Right Minds
http://www.leftrightminds.com

rss - image enclosures

agrazi - July 30, 2009 - 00:50

I've noticed that this is still a problem for version 6 of Drupal.

I understand that Drupal requires an image to be attached to a node (thus the image becomes a node?) before it can be used as a teaser thumbnail for the node (this is necessary when the node is displayed internally in Drupal or is seen as an rss feed item).

The external feed I am sourcing into Drupal has an enclosure tag, as below:

[enclosures] => Array
(
[image] => Array
(
[jpeg] => Array
(
[0] => Array
(
[bitrate] =>
[captions] =>
[categories] =>
[channels] =>
[copyright] =>
[credits] =>
[description] =>
[duration] =>
[expression] =>
[framerate] =>
[handler] =>
[hashes] =>
[height] =>
[javascript] => js
[keywords] =>
[lang] =>
[length] => 0
[link] => http://www.peniel.org/blogspot/Instruction-for-life.jpg
[medium] =>
[player] =>
[ratings] =>
[restrictions] =>
[samplingrate] =>
[thumbnails] =>
[title] =>
[type] => image/jpeg
[width] =>
)

)

)

)

The CCK module allows me to map rss feed items to nodes... but not enclosure tags to images.

so, what do I map it to?

How do I map the enclosure tag (image) of an external rss feed to an image node... so that the rss feed has a teaser thumbnail, internally and externally to Drupal?

Will the module described in this thread work for Drupal 6?

agrazi

Coding Help

DavidWhite - August 14, 2009 - 21:00

So I am trying to work on this for a Drupal 6.x system. This is the first actual coding hack that I am attempting (and will hopefully pull off successfully). Here's what I've go so far (and it's not working). This code is inside our custom module.

function um_common_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'rss item':
      if ($node->type == 'volunteer_opportunity') {
return array (
          array (
            'key' => 'item',
            'value' => array (
              'title' => $node->field_volopp_org_name[0]['view'],
  'link' => $node->field_volopp_volunteer_linkl[0]['view'],
  'description' => $node->field_volopp_vols_needed[0]['value']
            )
  )
      );
    }
  }
}

Based on what I can tell so far, the array that contains "key" and "value" are for drupal's benefit, where is the array that contains "Title", "Link" and "Description" are for the benefit of the RSS Parser. Is this right? I'm stepping out of the office for the weekend, so I thought I'd post here in case someone has any ideas or suggestions or helpful hints for me to come back to when I start tackling this again Monday morning.

Thanks,

- David

David White
Owner @ Smooth Stone Services
http://www.smoothstoneservices.com

Web Developer @ TechMission
http://www.techmission.org

I'm very interested in this

tinem - September 21, 2009 - 09:31

I'm very interested in this subject too.

Please vote for a video about this subject

tinem - September 22, 2009 - 06:38

http://buildamodule.com/ - Vote for future videos - How to change RSS view with RSS Item hook_nodeapi.

 
 

Drupal is a registered trademark of Dries Buytaert.