<?php /**/ ?><?php

include("flickr_key.php");
include("mysql_cred.php");

require_once("phpFlickr/phpFlickr.php");

$api = new phpFlickr(API_KEY, API_SECRET);

$db_string = "mysql://" . DB_USER . ":" . DB_PASSWORD. "@" . DB_SERVER . "/". DB_NAME;

$api->enableCache(
    "db", $db_string
);

#
# Get user's ID
#
$username = 'Raymond Yee';
if (isset($_GET['username']))
    $username = $_GET['username'];
$user_id = $api->people_findByUsername($username);
$user_id = $user_id['id'];

#print $user_id;

#print_r($api);
#print_r (get_class_methods($api));

# get a list of the user's favorites (public ones first)
# http://www.flickr.com/services/api/flickr.favorites.getPublicList.html

$photos = $api->favorites_getPublicList($user_id,"owner_name,last_update,tags", 40, NULL);
#print_r($photos);

// Loop through the photos and output the html
foreach ((array)$photos['photo'] as $photo) {
    $photo_url = "http://www.flickr.com/$photo[owner]/$photo[id]";
    echo "<a href='$photo_url'>";
    echo "<img border='0' alt='$photo[title]' ".
        "src=" . $api->buildPhotoURL($photo, "Square") . ">";
    echo "</a>";
    $i++;
    // If it reaches the sixth photo, insert a line break
    if ($i % 6 == 0) {
        echo "<br>\n";
    }
}

?>
