php code for flickr
hi all,
here is some code i hacked together to make it possible to show flickr images on http://www.varnelis.net
flickr's javascript badge left me wanting and i could never figure out the flickr modules... but i found a site ( http://prwdot.org/archives/002468.html ) that had a php routine using the magpierss routines (see below...these could be interesting!) ready to go, even if it wasn't for drupal.
i made some changes since I wanted my images to be of a specific size. you can go in and play with either the given flickr sizes (see http://digitalphotography.weblogsinc.com/entry/1234000650052735/) for the proper codes. i've set the image width to 300 in the line that contains the preg_replace code and eliminated any height constraint.
no warranties on this, i'm a php hack, not a coder. and if anybody has any better ideas for cleaning up the img
the code works equally well in a block and in a page (e. g. http://www.varnelis.net/flickr)
here is the code for multiple images, right now it's set to 9.
<?php
// USER CONFIGURATION SECTION
// MagpieRSS Configuration
// This is an example based on my system;
// you will need to customize it for your system
// and your preferences. You can remove it entirely
// if you have done it elsewhere
// refer to <a href="http://magpierss.sourceforge.net/
" title="http://magpierss.sourceforge.net/
" rel="nofollow">http://magpierss.sourceforge.net/
</a> require_once('/home/kazys/public_html/varnelis/magpierss/rss_fetch.inc');
error_reporting(E_ERROR);
define(MAGPIE_DETECT_ENCODING, true);
define(MAGPIE_DEBUG, 0);
define(MAGPIE_FETCH_TIME_OUT, 15);
define(MAGPIE_USE_GZIP, true);
// flickr configuration
// How many photos you want to display
$num_photos = 9;
// URL for the flickr feed you want to use
$flickr_feed_url = 'http://flickr.com/services/feeds/photos_public.gne?id=43364113@N00&format=rss_200';
?>
<?php
// Fetch the feed
$flickr = fetch_rss( $flickr_feed_url );
if ($flickr) {
$flickr_title = $flickr->channel["title"];
$flickr_link = $flickr->channel["link"];
?>
<!-- Display the title and link to the feed -->
<?php
// Pick some random photos
$random_photos = array_rand($flickr->items,$num_photos);
foreach ( $random_photos as $random_photo ) {
$description = explode("\n\n",$flickr->items[$random_photo]["description"]);
$description = str_replace("_m.jpg", ".jpg", $description);
$description = preg_replace("/width=\"\d+\"/", 'width=\"300\"', $description);
$description = preg_replace("/height=\"\d+\"/", '', $description);
$description = str_replace("style=\"border: 1px solid #000000;\"", " ", $description);
?>
<!-- Display the given photo -->
<?php echo $description[1]; ?>
<?php
}
} else {
?><!-- Display an error message if things didn't work -->
<p>An error occurred in the MagpieRSS parser:</p>
<p><?php echo magpie_error(); ?></p>
<?php
}
?>in case you only want one image, you'll need the following:
<?php
// USER CONFIGURATION SECTION
// MagpieRSS Configuration
// This is an example based on my system;
// you will need to customize it for your system
// and your preferences. You can remove it entirely
// if you have done it elsewhere
// refer to <a href="http://magpierss.sourceforge.net/
" title="http://magpierss.sourceforge.net/
" rel="nofollow">http://magpierss.sourceforge.net/
</a> require_once('/home/kazys/public_html/varnelis/magpierss/rss_fetch.inc');
error_reporting(E_ERROR);
define(MAGPIE_DETECT_ENCODING, true);
define(MAGPIE_DEBUG, 0);
define(MAGPIE_FETCH_TIME_OUT, 15);
define(MAGPIE_USE_GZIP, true);
// flickr configuration
// How many photos you want to display
$num_photos = 2;
// URL for the flickr feed you want to use
$flickr_feed_url = 'http://flickr.com/services/feeds/photos_public.gne?id=43364113@N00&format=rss_200';
?>
<?php
// Fetch the feed
$flickr = fetch_rss( $flickr_feed_url );
if ($flickr) {
$flickr_title = $flickr->channel["title"];
$flickr_link = $flickr->channel["link"];
?>
<!-- Display the title and link to the feed -->
<?php
// Pick some random photos
$random_photos = array_rand($flickr->items,$num_photos);
$random_photo = $random_photos [1];
$description = explode("\n\n",$flickr->items[$random_photo]["description"]);
$description = str_replace("_m.jpg", ".jpg", $description);
$description = preg_replace("/width=\"\d+\"/", 'width=\"300\"', $description);
$description = preg_replace("/height=\"\d+\"/", '', $description);
$description = str_replace("style=\"border: 1px solid #000000;\"", " ", $description);
echo $description[1];
} else {
?><!-- Display an error message if things didn't work -->
<p>An error occurred in the MagpieRSS parser:</p>
<p><?php echo magpie_error(); ?></p>
<?php
}
?>
good
well done~
thanks!
was wondering if anybody would notice...
it's in use on varnelis.net and works really well for me...
I just see this
I just see this error:
warning: Invalid argument supplied for foreach() in /home/kazys/public_html/varnelis/modules/flickr.module on line 92.when I visit www.varnelis.net/flickr...
I assume this is not the same thing as the Flickr Module?: http://drupal.org/node/14912
http://www.spaz.org - Semi-Permanent Autonomous Zone
thanks for pointing that out.
i'd tried the flickr module and didn't find it did what I wanted (which is create a random block with a flickr image that links back to flickr).
i had left it enabled and somehow had the /flickr page set to it. i've disabled the module and rebuilt the page with the php code for multiple images above.
Flickr modules
There is a Flickr module available, but it doesn't have blocks, so I started working on a complete rewrite which you can see on the Bryght public Subversion repository. Using that module, if you have the phpFlickr library and a Flickr API key, you can get blocks of tagged photos.
Group feeds?
Hey! That code is awesome! So easyt and works perfect with my Flickr feeds. Thanks a lot!
Now... I'm trying to use it with a group pool feed, which is public and should work the same, but it doesn't. Any ideas? It just reurns no pictures.
Group rss:
http://flickr.com/groups/spaniards/pool/feed/?format=rss_200
Thanks in advanced!
Well, finally I got it
Well, finally I got it working. I have changed the code a litle, because I prefer to show the picture description and user name (because its a group feed). I didn't want the random feature either, so I removed it.
You can see it working at http://spaniards.es/fotos
And this is the code:
<?php
require_once('misc/magpierss/rss_fetch.inc');
error_reporting(E_ERROR);
define(MAGPIE_DETECT_ENCODING, true);
define(MAGPIE_DEBUG, 0);
define(MAGPIE_FETCH_TIME_OUT, 15);
define(MAGPIE_USE_GZIP, true);
// URL for the flickr feed you want to use
$flickr_feed_url = 'http://flickr.com/groups/spaniards/pool/feed/?format=rss_200';
// Fetch the feed
$flickr = fetch_rss( $flickr_feed_url );
if ($flickr) {
$flickr_title = $flickr->channel["title"];
$flickr_link = $flickr->channel["link"];
echo "<h2>$flickr_title</h2> <a href='$flickr_link'>$flickr_link</a><br/>\n";
echo "<p>Num. imágenes: " . count($flickr->items) . "</p>\n";
foreach ($flickr->items as $photo => $val) {
$description = $val["description"];
$datetxt = ($val["pubDate"] != '')? " - Foto tomada el día " . $val["pubDate"] : '';
$description = str_replace("has added a photo to the pool:", $datetxt, $description);
echo $description . "\n";
}
} else {
?>
<!-- Display an error message if things didn't work -->
<p>An error occurred in the MagpieRSS parser:</p>
<p> <?php echo magpie_error(); ?> </p>
<?php
}
?>
*** The "pubDate" field doesn't work, so it doesn't show anything. Any clues about how to get this value?
glad you like!
glad you like!
amazing that i could actually give something back to the community...
no idea about pubDate unfortunately
Tiny, Tiny, Tiny photos from flickr
This looks like it is exactly the php code I need for some flickr integration....but....
When I put it on a static page (4.7) I just get tiny, tiny, tiny photos....then I clicked on the page example above and the author has the same problem on his site (http://www.varnelis.net/flickr) ....as this code is a bit old, I'm guessing something in the api has changed, but I'm not technical enough to figure it out...
any ideas out there?
looks like it's your browser
maybe it's your browser and it's time for an upgrade?
it works fine in firefox. nothing has changed, all is as it was.
http://www.varnelis.net
I've been working with
I've been working with MagpieRSS and the flexinode module to feed random images from flickr. The php file that uses MagpieRSS works fine by itself. However, when i incorporate it into drupal, i get this warning message (along with my photos):
warning: mkdir() [function.mkdir]: Permission denied in /.../themes/bluemarine/magpierss/rss_cache.inc on line 34.
warning: fopen(magpie_cache/c25fb6c1d04909b44915bd950e3d5239) [function.fopen]: failed to open stream: No such file or directory in /.../themes/bluemarine/magpierss/rss_cache.inc on line 54.
I've screwed around with permissions and i've made sure that the current folder and parent folder and even the cache folder all have their permissions properly set and to no avail. Please help.
Hmm, maybe there is some
Hmm, maybe there is some code somewhere thats changing the permissions along the operation? Overriding your nifty permissions.
Hi
Free source code PHP for search images from Flickr.com
http://www.myfineday.com/2008/10/08/php-flickr-search/