The Blog / Development / Getting Flickr Photos into MODx Revolution

Getting Flickr Photos into MODx Revolution

29 Aug 2010

I have now moved this website over to MODx Revolution 2.0.0. I must say the migration wasn't too difficult although I was waiting on a one click upgrade path but after looking at the way how MODx is built in general, it wouldn't have been possible as different developers use different plugins, snippets and addons. I was reading Muddy Dog Paws and realized he was having problems getting Flickr to work in MODx Revolution.

In Evolution I was using FeedX to pull my Flickr Photos, but now that I upgraded to Revolution and FeedX haven't been upgraded as yet I decided to use getFeed instead. While I integrated this I soon after noticed one little problem, this problem was that the Magpie RSS Class that getFeed uses doesn't allow you to get xml node attributes.

In order to get a Photo from a Flickr feed you would need to get it from a xml node's attribute. I decided to change the format I get back from Flickr and got the image information inside the tags instead, only issue was that it also included some text content.

At this point I decided to use some regular expression and modify the image string in order to get the image and the size I wanted. Below you will find each piece of code that was used.

[[getFeed? &url=`` &tpl=`flickr` &limit=`3`]]

The flickr chunk look like this

<a title="[[+title]]" href="[[+link]]">
    <img src="[[+description:getImgSrc]]" alt="[[+title]]" />

And here is the code for getImgSrc snippet

// Match The IMG Tag
preg_match('/]+>/i',$input, $result);

preg_match('/(src)=("[^"]*")/i',$result[0], $img);

preg_match('/("[^"]*")/i',$img[0], $output);

return substr($output[0], 1, -6) . 's.jpg';

I know the code is a bit dirty, but as I just needed to get this up and running on MODx Revolution as quick as possible. You can change the size of the image returned by changing the s.jpg to whatever you want or you could even pass it in as property of getImgSrc.

Social Media

London Midland Train Square Bob Sponge Pants at o2 Arena The Reliable