Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alex_b’s picture

Title: Mapper for CCK Image Field » Create Mapper for CCK Image Field
Component: Miscellaneous » Code
alex_b’s picture

You might want to check out the media field mapper - http://drupal.org/node/221745

smk-ka’s picture

Assigned: Unassigned » smk-ka
Status: Active » Needs review
FileSize
1.55 KB

Here we go: the CCK Imagefield mapper will download the image and save it as local file. You can choose whether to keep the original file name extracted from the URL, or use an MD5 hash of the URL. The latter is ideal for images that are returned by scripts (like getimage.php?foo=), because they would all be saved as "getimage.php" (although not overwriting each other, due to automatic renaming).

An offtopic request for anyone interested in this module:
Since the directory for the automatically downloaded images can grow quite large if you don't delete feed nodes from time to time, I recommend that you vote on e.g. token issue #236596: Add support for date parts YYYY, MM, and DD. This would allow us to store images in subdirectories created from the current date, using Imagefield's token support on paths, of course.

buzink’s picture

Created a very simple image-field mapper. Just remove ".txt" part of the filename and put in /modules/feedapi_mapper/mappers

This will enable you to map a feed element with a cck image field. The image will stay on the original server and will not be downloaded.

apathetic_resistance’s picture

I'm not sure if this is the correct place to post this, but I thought I would mention a problem I had implementing Feed API with Flickr.

I basically set things up the same way that Sean Effel does in his drupal therepy webcast, except that of course he was using Blip.tv movies and I set things up with Flickr photos.

To begin with, I created a Feed, and then mapped the original URL to the emfield in my Flickr content type. When I first created the feed, the emfield was not yet mapped, and so the nodes created by Feed API were text only.

Now, in the webcast, Sean Effel decides to start with a clean slate after mapping the emfield -- he clicks "Remove items" which deletes all of the associated nodes (text only anyway). He then clicks refresh and the Feed is filled with nodes with properly mapped emfields.

The problem is that when I tried this on two of my setups, the Feed refuses to refresh with nodes. It gives the message "There are no new items in the feed." So the feed is useless.

I did find a workaround eventually. I went into the Feed's edit tab and replaced its URL with that of a different flickr photostream. This seems to have tricked the Feed into updating with new items, creating new nodes with properly mapped emfields.

If anyone knows what the problem is, or where this should be addressed, I would love to know about it. Thanks!

smk-ka’s picture

Version: 5.x-1.0-beta4 » 5.x-1.x-dev
FileSize
4.76 KB

Finally found some time to update the CCK Image Field mapper:
- Image handling during FeedAPI update has been fixed.
- Previous version was storing image files twice in target directory.
- Added a blacklist feature.

Aron Novak’s picture

Status: Needs review » Reviewed & tested by the community

I installed the module and I could use with flickr rss feed without any problem.

alex_b’s picture

Can we get a port to 6 for this as well ? :)

alex_b’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed to 5.x - thank you.

http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/feedapi_map...

Needs to be ported to 6.x .

alex_b’s picture

Assigned: smk-ka » Unassigned

Ported... but not necessarily by you, smk-ka :)

mtndan’s picture

Has this actually been ported? Is there a url to download? Thanks in advance.

alex_b’s picture

Assigned: Unassigned » alex_b

I'm going to take a shot at this now.

alex_b’s picture

Assigned: alex_b » Unassigned

port not straightforward, imagefield/filefield API changed (?) - any hints?

Krummrey’s picture

There is a second issue that has some code that needs to be reviewed: #311404: image and audio file mapper

Don't know how that relates to the image and filefield issue though.

alex_b’s picture

I think filefield support is also related: #319538: http://drupal.org/node/319538

911’s picture

Would like to see a image cck field mapper port to drupal 6 too.

spiffyd’s picture

subscribed

flickr compatibility would be great as well

MissyM’s picture

subscribe

yeah, boy, flickr would be handy for dru6

spiffyd’s picture

Suggestion: The image mapper should work with/from the Embedded Media Field module just like how currently their Embedded Video Field has a mapper that works with this module.

MissyM’s picture

It doesn't seem to for me. If you have it working, perhaps you can explain how it works.

spiffyd’s picture

@MissyM: There is no Embedded Image feed mapper right now that's why it doesn't work. However, there is an Embedded Video mapper that works with the the Embedded Video module in emfield module. My suggestion is for someone to to code a similar one based off that.

hydrogen3’s picture

Version: 6.x-1.x-dev » 5.x-1.x-dev
Category: feature » support
Status: Patch (to be ported) » Active

I'm using FeedAPI 5.x-1.x-dev and Mapper 5.x-1.x-dev on D510 and php4 and trying to download Flickr images as new nodes. The nodes are created ok, but there are no images attached. In files/simplepie_cache I can see that the process started when I refresh the feed, but no images.

Am I using the right combination of module versions?

spiffyd’s picture

By Mapper mod you mean feedapi_mapper?

As mentioned on this thread there's no external image mapper available, that's why you're only getting everything else minus the image. Someone else please correct me if I'm wrong on this one.

I guess there's this one thing you can try... see if there's a Link to that image provided. Map it to a CCK Link field then use Contemplate mod to display the picture in teaser or node.

hydrogen3’s picture

Yes, sorry, feedapi_mapper 5.x-1.x-dev. Wait, so what does the mapper in #3 do?

spiffyd’s picture

Sorry hyrodgen3. I thought you had v6.x. The mapper in #3 is for v5 and doesn't work for v6. If there are issues, maybe you should ask the maker of that mapper. I apologize once again~

alex_b’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
Category: support » feature
Status: Active » Patch (to be ported)

#22 Please no hijacking of issues :-)

Please create a new issue for this kind of support requests.

cglusky’s picture

Please see http://drupal.org/node/326083 for an emimage mapper - just tested in D6 and it works with Flickr.

giorgio79’s picture

Thanks alex_b and smk-ka, just what I have been looking for.

Let me know if there is any code that can be tested already for 6.

Dekka’s picture

subscribe

ball.in.th’s picture

Status: Patch (to be ported) » Needs review
FileSize
5.25 KB

Here's a D6 version, slightly modified from http://drupal.org/node/311404#comment-1040107 and feedapi_mapper_emimage.inc. It seems to work with all the latest modules, i.e., Feed Element Mapper 6.x-1.0-beta4, FileField 6.x-3.0-beta1, ImageField 6.x-3.0-beta1.

Note that there's a lot of code I don't understand in this patch, especially those related to filefield. Experts please help!! ^ ^

ball.in.th’s picture

oops! found some typos.

drupalok’s picture

cant confirm this. i tried Drupal 6 version from #31 with Feed Element Mapper 6.x-1.0-beta4, FileField 6.x-3.0-beta1, ImageField 6.x-3.0-beta1.
i copied the
feedapi_mapper_imagefield.inc

to the
sites\all\modules\feedapi_mapper\mappers
folder...

but my imagefield / filefield does not show up as an option
what do i do wrong?
thanks!

ball.in.th’s picture

Hi,

An imagefield must be manually added to the content type of the feed items first. Then, an option to map to the imagefield should show up in the "Map" tab, i.e., node/xxx/map, of a feed node.

pixelantegroup’s picture

Good looking code.

One problem I'm running into though. It doesn't work with imagefield_tokens.

I'll see if I can fix that though.

Quick fix, for my needs (just node type tokens)...sorry no patch for now...just in case anyone else needs this.

insert after line 113:

if( module_exists('filefield_paths') ) {
$widget_image_path = filefield_paths_process_string($widget_image_path, 'node', $node);
}

alex_b’s picture

Title: Create Mapper for CCK Image Field » Mapper for CCK Image Field
virtualdrupal’s picture

The fix in #31 doesn't work with Feed Element Mapper 6.x-1.0-beta9, I get a warning invalid argument on line 3, and the option doesn't appear in the pulldowns. Downgrading to beta5 got it up and running for me.

Krummrey’s picture

#31 doesn't work for me either. Getting the same error:

warning: Missing argument 3 for imagefield_feedapi_mapper() in drupal-6/sites/all/modules/feedapi_mapper/mappers/feedapi_mapper_imagefield.inc on line 13.

Line 13 is:

function imagefield_feedapi_mapper($op, $node, $field_name, $feed_element = array(), $sub_field = '') {

changing it to:

function imagefield_feedapi_mapper($op, $node, $feed_element = array(), $field_name = '', $sub_field = '') {

gets rid of the errors, but doesn't invoke the mapper. Probably because the $field_name is empty? So I removed the following check. That way I don't get any errors and the mapper shows up in the mapper list. But it still doesn't work.

I was wondering if FileField Sources would be of any help here? It does the same thing on a GUI level. Instead of uploading the image/file directly you can specify a URL. That file then gets downloaded and insterted into the FileField.

Krummrey’s picture

For those of you that want to try it out, here's the mapper the way I described it above.

Problems I found and couldn't solve:

$filename:
The $filename doesn't get built. I think the switch for $filename_option doesn't work. Is $filename_option ever set?

$widget_image_path:
That doesn't get built either.

benkewell’s picture

modified from the file on #38
this one changed the way how the fields are returned when called with $op = 'list'
following the way that feedapi_mapper_content.inc and feedapi_mapper_date.inc are written
in this way the $field_name and $sub_field are passed correctly when mapping
while #38 version gives 2 blank strings resulting in no imagefield data created

it is working well on my development website

virtualdrupal’s picture

Re: #39

This works for me with beta9, thank you

alex_b’s picture

Status: Needs review » Needs work

Setting back to needs work because:

- The commented-out code needs do go.
- Jan, I take it that the problems you describe in #38 are not addressed yet.

#39: yes, there was an API change with #397682: Let mappers declare mapping targets - fortunately, there is good API documentation in api.php now.

Krummrey’s picture

Well, I got errors even with #39.

"warning: mkdir() [function.mkdir]: No such file or directory in /drupal-6/sites/all/modules/feedapi_mapper/mappers/feedapi_mapper_imagefield.inc on line 128."

might be something with my setup if noone else has these.

virtualdrupal’s picture

While this works for the most part, I have several feeds with images that don't seem to work, you can see the image link when you expand "Feed Item Example", but mapping it doesn't appear to work.. again other feeds work fine, are they buried to far in the array?

Example
http://rss.news.yahoo.com/rss/us

stephencarr’s picture

//subscribe

ball.in.th’s picture

Status: Needs work » Needs review
FileSize
6.54 KB

Hi,

Here's a new version modified from #39:
- uses Drupal File interface
- uses filefield_widget to detoken & transliteration filenames (copied parts from http://drupal.org/project/filefield_sources)
- other bug fixes
- works with feed in #43

Known problem:
Description doesn't show up in "Description of available mappers".

Note:
I still dont really understand how FileField works. Experts please help. ^ ^

Krummrey’s picture

My current test-site gives me an error and saves empty nodes:

warning: call_user_func(imagefield_feedapi_mapper) [function.call-user-func]: First argument is expected to be a valid callback in /drupal-6/sites/all/modules/feedapi_mapper/feedapi_mapper.module on line 138.

I'll try it with a completely new and clean install over the weekend.

ball.in.th’s picture

That's odd. Have you tried emptying all cache in admin/settings/performance ?

Krummrey’s picture

Forget that last one...
I've reinstalled everything just now. The error does not appear, but neither does the image mapper.
Therefore I can't map anything to the imagefield.

Tried the link mapper - that works.

ball.in.th’s picture

Do you have an imagefield added to your content type? ^ ^

ball.in.th’s picture

Updated version with a bug fix:
- file path with nested directory wasn't properly created

Another know problem:
- doesn't work with http://drupal.org/project/filefield_paths ; a bug in filefield_widget_file_path()?

ball.in.th’s picture

Another updated version with support for feedapi_inherit module. It will use feedapi_node's user instead of the current user to replace tokens if enabled. For example, if you want attachments from a feed to be saved under sites/default/files/host.com/, then simply:

  1. create a new user named 'host.com'
  2. create a feed by that user
  3. enable FeedAPI Inherit module
  4. set "Feed nodes inherit taxonomy settings from parent feed." in feed node
  5. set "[user]" in feed items' content type Path settings

This version does pretty much everything I need now. ^ ^

Krummrey’s picture

Yes I have an Imagefield.

Whatever you have changed, it now works! The images get downloaded.

GREAT

Jan

fumbling’s picture

Thanks for introducing this mapper. Installed the mapper, and the pieces are all in place (the imagefield shows in the options drop down for each mapping element, etc.) However, I can't seem to get it to work to pull in profile images from a Twitter atom feed, such as http://search.twitter.com/search.atom?q=drupal FeedAPI pulls in everything but the image.

The element for the profile image is definitely there in the source code for the feed page, but it's not tagged as an element in a standard form, so maybe that's why FeedAPI + mapper isn't picking it up? Any thoughts on how I can get it parsed so that feed element mapper will recognize it as one of the options to map over?

Here's an example of the source code for a Twitter feed:

 <entry>
    <id>tag:search.twitter.com,2005:2676951619</id>
    <published>2009-07-16T21:55:57Z</published>
    <link type="text/html" rel="alternate" href="http://twitter.com/einsteinsboi/statuses/2676951619"/>
    <title>RT @lauras: RT @ericg "There's no elevator to Drupal. You've got to take the stairs." -@kentbye (via @jjeff)</title>
    <content type="html">RT &lt;a href="http://twitter.com/lauras"&gt;@lauras&lt;/a&gt;: RT &lt;a href="http://twitter.com/ericg"&gt;@ericg&lt;/a&gt; &amp;quot;There's no elevator to &lt;b&gt;Drupal&lt;/b&gt;. You've got to take the stairs.&amp;quot; -@kentbye (via &lt;a href="http://twitter.com/jjeff"&gt;@jjeff&lt;/a&gt;)</content>
    <updated>2009-07-16T21:55:57Z</updated>
    <link type="image/png" rel="image" href="http://s3.amazonaws.com/twitter_production/profile_images/75120935/P1000984_normal.jpg"/>
    <twitter:source>&lt;a href="http://www.tweetdeck.com/"&gt;TweetDeck&lt;/a&gt;</twitter:source>
    <twitter:lang>en</twitter:lang>
    <author>
      <name>einsteinsboi (mary)</name>
      <uri>http://twitter.com/einsteinsboi</uri>
    </author>
  </entry>

And the element from the above that I want to parse, the one with the profile image in it that's not reaching drupal, reads (in this example):

<link type="image/png" rel="image" href="http://s3.amazonaws.com/twitter_production/profile_images/75120935/P1000984_normal.jpg"/>

I'm using common syndication parser. Should I try simple pie? Any other thoughts on how I could make it work?

ball.in.th’s picture

Hi,

I've tested http://search.twitter.com/search.atom?q=drupal with the simple pie parser and it doesn't seem to help. "Feed item example" on the Map tab looks like the following quote. The picture links are empty even though they are not when viewed as sourcecode by firefox. So it seems they're filtered out somewhere before reaching the imagefield mapper. Perhaps filing a bug report for Feed Element Mapper module might be a good idea.

Array
(
    [title] => Sweeet. Just set up drupal 6.13 on my server. Gonna play around with it!
    [description] => Sweeet. Just set up drupal 6.13 on my server. Gonna play around with it!
    [options] => Array
        (
            [original_url] => http://twitter.com/f1vlad/statuses/2734459681
            [timestamp] => 1248069921
            [guid] => tag:search.twitter.com,2005:2734459681
            [original_author] => Array
                (
                    [name] => LesleyChang (Lesley  C)
                    [link] => http://twitter.com/LesleyChang
                    [email] => 
                )

            [domains] => 
            [tags] => 
            [raw] => Array
                (
                    [id] => tag:search.twitter.com,2005:2734724834
                    [published] => 2009-07-20T06:32:02Z
                    [link] => Array
                        (
                            [0] => 
                            [1] => 
                        )

                    [title] => Sweeet. Just set up drupal 6.13 on my server. Gonna play around with it!
                    [content] => Sweeet. Just set up drupal 6.13 on my server. Gonna play around with it!
                    [updated] => 2009-07-20T06:32:02Z
                    [author] => 
      
      
    
                )

        )

)
fumbling’s picture

Thanks for trying it out. I'll poke around some more and then most likely file a bug report as you suggest. Appreciate your help.

alex_b’s picture

ball.in.th’s picture

This one seems to have more features, i.e.,
- support images that are returned by scripts (like getimage.php?foo=)
- can save images in sub-directories
- support token & transliterate in pathname and transliterate in filename
- support feedapi_inherit module

^ ^

alex_b’s picture

#54: "The picture links are empty even though they are not when viewed as sourcecode by firefox. So it seems they're filtered out somewhere before reaching the imagefield mapper. Perhaps filing a bug report for Feed Element Mapper module might be a good idea."

- it's the parser's responsibility to retrieve specific elements from a feed. So you're talking about a feature request to a parser rather than a bug report to Feed Element Mapper.

alex_b’s picture

Status: Needs review » Closed (duplicate)

#57: I'll have to give #319538: Mapper for FileField / ImageField the preference because it addresses filefield and imagefield mapping in one - which is the way to go as imagefield is essentially filefield with a different widget setting.

However, I think the option to generate filenames in order to avoid overwriting is very valuable, I'm hoping you are ready to add this as a follow up patch to #319538: Mapper for FileField / ImageField. Shouldn't be hard to do.

Further, querying the filepath with filefield_widget_file_path() is actually mandatory. Accordingly, I've added a comment to the other issue: #319538-23: Mapper for FileField / ImageField.

ball.in.th’s picture

In case anyone is using the mapper in #51, it seems the ability to use feed node's user to replace tokens instead of currently logged in user has nothing to do with feedapi_inherit module, so here's an updated version. This can be used until the FileField mapper has similar features.

philpro’s picture

Your work here is excellent, I really appreciate it.

I am using the csv parser module to import vehicle data, which is working excellently, except in the case where we are provided a list of multiple image urls. Is it possible (or does this module already) support importing multiple images into an image field that allows an unlimited number of photos?

Below is an example of one line taken from the CSV, the volume of data is probably a bit excessive, but I thought it might be helpful to understand what I am meaning. It's probably worth noting that the number of images for each vehicle in the csv feed is never the same.

Thanks,

"USED","T7777","JTD55555555555555555","2008","Toyota","Prius","1224","4dr Car","Touring","4","Super White","Gray","4","1.5L","Automatic","32869","0","0","0","0","True","6/3/2009","","FABRIC SEAT TRIM,Keyless Entry,Power Door Locks,Heated Mirrors,Power Driver Mirror,Pass-Through Rear Seat,Cloth Seats,Bucket Seats,Power Steering,Adjustable Steering Wheel,Tires - Front All-Season,Tires - Rear All-Season,Compact Spare Tire,Traction Control,Aluminum Wheels,Power Windows,Intermittent Wipers,Power Passenger Mirror,Heated Exterior Driver Mirror,Heated Exterior Passenger Mirror,Variable Speed Intermittent Wipers,Steering Wheel Controls,Auxiliary Pwr Outlet,Vehicle Anti-Theft System,Auto-Off Headlights,Driver Vanity Mirror,Passenger Vanity Mirror,Driver Air Bag,Passenger Air Bag,Side Air Bag,Side Head Air Bag,Climate Control,A/C,AM/FM Stereo,CD Player,4-Wheel ABS,Front Disc/Rear Drum Brakes,Cruise Control,Rear Defrost,Child Safety Locks,Front Wheel Drive,Driver Illuminated Vanity Mirror,Passenger Illuminated Visor Mirror,Front Reading Lamps,Rear Spoiler,Tire Pressure Monitoring System,Keyless Start","5dr HB (Natl)","White","040","Gray","","","I","EFI","I4 1.5L","1","1-Speed Automatic","FWD","Hybrid Fuel","48","45","Mid-size","106.3","0","0","0","0","FE__","4-door Mid-Size Passenger Car","5","FAFAFA","","91","http://mywebsite.com/dealers/843/1292/T3221.jpg,http://mywebsite.com/dea...(2).jpg,http://mywebsite.com/dealers/843/1292/T3221(3).jpg,http://mywebsite.com/dealers/843/1292/T3221(4).jpg,http://mywebsite.com/dealers/843/1292/T3221(5).jpg,http://mywebsite.com/dealers/843/1292/T3221(6).jpg,http://mywebsite.com/dealers/843/1292/T3221(7).jpg,http://mywebsite.com/dealers/843/1292/T3221(8).jpg,http://mywebsite.com/dealers/843/1292/T3221(9).jpg,http://mywebsite.com/dealers/843/1292/T3221(10).jpg,http://mywebsite.com/dealers/843/1292/T3221(11).jpg,http://mywebsite.com/dealers/843/1292/T3221(12).jpg,http://mywebsite.com/dealers/843/1292/T3221(13).jpg,http://mywebsite.com/dealers/843/1292/T3221(14).jpg,http://mywebsite.com/dealers/843/1292/T3221(15).jpg,http://mywebsite.com/dealers/843/1292/T3221(16).jpg,http://mywebsite.com/dealers/843/1292/T3221(17).jpg,http://mywebsite.com/dealers/843/1292/T3221(18).jpg,http://mywebsite.com/dealers/843/1292/T3221(19).jpg,http://mywebsite.com/dealers/843/1292/T3221(20).jpg,http://mywebsite.com/dealers/843/1292/T3221(21).jpg,http://mywebsite.com/dealers/843/1292/T3221(22).jpg,http://mywebsite.com/dealers/843/1292/T3221(23).jpg"

philpro’s picture

Not sure if this is the correct way to do it, but for my purposes this worked!

I added this when i realized that the code was setup for multiple images already, and what the csv was feeding it was a single line of comma separated urls instead of an array:

  $feed_element_exploded = explode(',', $feed_element); 
  

Thanks.

philpro’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev

This patch does not function with the latest release of feed mapper. The cck filefield and imagefield types do not appear in the mapping section.

isani’s picture

I'm having trouble with the mapper from #60.

I have a Feed Scraper set up which scrapes image URLs from a feed. I can map the URL to a text field, and it shows up fine. I can also map it to an ImageField and save the mapping. The ImageFields remain empty, however. Refreshing the feed doesn't help. There are no error messages in the log.

I'm using FileField 6.x-3.2, ImageField 6.x-3.2, FeedAPI 6.x-1.9-beta2 and Feed Scraper 6.x-1.x-dev.

ball.in.th’s picture

Regarding #63 and #64, have you guys tried http://drupal.org/node/319538 ?

greg_meszaros’s picture

Hi,

Can I ask you? Do you solved problem with support importing multiple images into an image field that allows an unlimited number of photos? I installed feeds modules, import is OK, but I can import only one image. When I trying to import for example www.1jpg. www.2.jpg it is not working. But when I import only www.1.jpg, then it is working.

Do you know, what can be tje problem? Im using the 6.x-1.0-beta10 feeds module (last release)

Thx for your answer.