Hi guys
I'm wandering inside all resources I can find for the Feeds module (code itself, feeds.api.php, docs, Trellon post, other contribs, the issue queue) to find an answer for my problem, but it's a bit much and I don't know how to procede. Here's my problem :
I'm using Managing News to aggregate content from different RSS feeds (default MN configuration). But I have a particular need : the display of all the news should separate the image of the feed item (if any) and display it with specific dimensions. So what it means : I have to parse the content of each feed item (specifically inside the <description> tag), find the <img> tag, retrieve the image locally and put it in the "files" directory, and attach the local path to the Data entry in a new column so I can display through ImageCache in the feed listing (which is jus a view).
Am I correct ? What does it take to do it ? I've looked at the code of the Feeds Image Grabber module, it may be the closest to the first steps (retrieve the image locally) but it only works with a Feed NodeProcessor and imagefields.
Any insight, idea, hint and correction to my understanding really appreciated.
Comments
Comment #1
alex_b commentedYou'd have to add a new DB field using Data and write a views handler that formats the image link into an HTML img tag for you on output. Image grabber could work for the extaction task. Never used it.
Comment #2
DjebbZ commentedThanks for the answer. I see that I can add a field with the Data API with something like
$handler->addField($myfield).Do you know where I should do my "feed parsing and image grabbing" ? hook_nodeapi ? Or a feed hook (which one) ? Or a custom Parser extanding FeedsSyndicationParser ? Or a custom Processor extanding FeedsDataProcessor ? Or a combination ?
Comment #3
DjebbZ commentedOk I found a solution :
I used the
hook_feeds_parser_sources_alterto add a "image" field in the source, and implemented a callback to actually parse the content (using regexp... I tried the QueryPath module but encountered some bugs and limitations), copied the first remote image found (the first was enough in my use case) in the local "files" directory and return the local path if any was found. I also removed the image from the actual content, so the only image showing would only be the local one. And in a template file I used ImageCache to scale the image properly.Not necessarily the cleanest way, but it works... Hope this helps someone in the same case ! The Feeds Image Grabber module has some interesting pieces of code for getting remote images.
Comment #4
drupalicious commentedDjebbZ, I'm working on the exact same problem and have been spinning my wheels for days. I'm trying to implement a simple slideshow on the frontpage of MN. I'm just not a good enough coder to decipher what you mean and was hoping you might let us know what specific files you modified and maybe post the code changes you made. Otherwise I'm going to have to create a new feed importer and start making nodes for images... which is completely self-defeating... Would love to know exactly what you did... thanks :)
Comment #5
DjebbZ commentedSorry I can't post it, the code is commercial. But guidelines are not ! Well these guidelines are based on my memories, I don't have access to the code...
After reading the feeds.api.php of the Feeds module, I implemented in a custom module the hook_feeds_after_parse so I could map my source image into the my targer image field, which is on the Data table. The source image field was created with the hook_feeds_parser_sources_alter, where you create your field for the image source and write your own logic to parse the content and store, for each item, your image into your source image field (I hope you still follow).
Acutally I advise you to read the feeds.api.php file (not hard to understant really) because there is an example to do what you need : parse a source that has an image to store it in a custom source image field, and create a destination image field that will hold you newly parsed image. My advice : at some point you need to download the source file locally in your 'files' directory, and store the local path in your data table. So it will be easy to use this image afterwards. You can even use the imagecache_external module to parse the distant image and store it directly in a preset that interests you (that's what I did, to avoid storing huge image uselessly).
Hope these hints will help you !
Comment #6
iaminawe commentedThis would be an amazing addition to Managing News. I am going to try and make my way through your instructions above and see if I can get this working. Thanks for the outline and will post questions here.
Comment #7
gberm commentedCould you get this working. A tutorial would be great.