Random or Latest Flickr Photos Mod ?

Started by Minare, November 15, 2008, 09:45:00 AM

Previous topic - Next topic

Minare

Hi

Above the news section, there can be a place to show five latest  or random flickr photos of a specific flickr user.

It would be really a nice and popular mod, just an idea, if anyone is capable of doing this and have time to do, it would be great  :)


PJLawrence

#1
This can be achieved by using one of SMF many portal systems i.e Tinyportal or Simpleportal, via a php block.

What you'll need to do first is to download phpFlickr-2.2.0.zip from http://sourceforge.net/project/showfiles.php?group_id=139987&package_id=153541&release_id=569504.
Then copy the folder phpFlickr-2.2.0, contained in this zip file, into your smf source folder. i.e. the folder phpFlickr-2.2.0 should be a subdirectory of your SMF source directory.

You will then need to obtain your own Flickr API key from http://www.flickr.com/services/api/key.gne.

Once you have obtained an API key you should create a PHP block in your chosen portal system which contains the code below.
Edit the script to include your Flickr user ID and API key. (note the example api_key in the code is a made up key for demonstration purposes only.)

Set your block display options and your recently uploaded Flickr images should be displayed in that block.


// Code to display a flickr user's most recently uploaded photos
//
// First download the phpflickr source code from http://phpflickr.com/
// and copy the folder phpFlickr-2.2.0 into your smf source folder
//
// You need to assign the following variables...
// $api_key - This is the API key given to you by flickr.com.
// Replace [API Key] with you API key.
// You can get an API Key at: http://www.flickr.com/services/api/key.gne
// e.g. $api_key = "z28afz1861e2byb888325695c7fx4df6"; 
$api_key = "[API Key]"; 
// replace [Flickr ID] with your Flickr User ID
// e.g. $UserID = "Fred 08";
$UserID = "[Flickr ID]";
// The number of images to display
$NumberOfPhotos=5;       

require_once("phpFlickr-2.2.0/phpFlickr.php");
// Create new phpFlickr object
$f = new phpFlickr($api_key);

if (!empty($UserID)) {
    // Find the NSID of the username
    $person = $f->people_findByUsername($UserID);

    // Get the friendly URL of the user's photos
    $photos_url = $f->urls_getUserPhotos($person['id']);

    // Get the user's first $NumberOfPhotos public photos
    $photos = $f->people_getPublicPhotos($person['id'], NULL, $NumberOfPhotos);

    // Loop through the photos and output the html
$i = 0;
    foreach ((array)$photos['photo'] as $photo) {
        echo "<a href=$photos_url$photo[id]>";
        echo "<img border='0' alt='$photo[title]' ".
            "src=" . $f->buildPhotoURL($photo, "Square") . ">";
        echo "</a>";
        $i++;
        // If it reaches the 8th photo, insert a line break
        if ($i % 8 == 0) {
            echo "<br />\n";
        }
    }
}

Jojie

HI, Lawrence.

I actually have your mod installed in my site. which works..

the only thing is.. I'm interested in the search function. As I am i don't have the abiltiy to do PHP I'm hoping any of you guys could provide some code snips for this..

Bascially all i want to do is... modify this mode:  http://custom.simplemachines.org/mods/index.php?mod=1564 
where the userID   becomes a tag. Ofcourse if you gys want to update the mod to include it would be really great..


Arantor

Normally I'd say that you'd be best asking on the mod's support topic, though to be honest I doubt it's being supported now.

Just isn't much call for Flickr mods for SMF :(
Holder of controversial views, all of which my own.


PJLawrence

jojie, searching flicker for a given tag is possible using phpFlickr and shouldn't require many changes  to the code above.
see http://you.gotfoo.org/flickr-photo-search-using-phpflickr/

Advertisement: