<?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, 10
);

include("delicious.cred.php");
require_once('php-delicious/php-delicious.inc.php');


#$del_obj = new PhpDelicious(DELICIOUS_USER, DELICIOUS_PASSWORD);
$del_obj = new PhpDelicious('mashupguide', '123xyz');

# get a group of Flickr photos --
# to expand -- you should be able to do any group of Flickr photos -- but for now:
# for now, let's pick your favorites...

# copy over tags?  how so? -- let's do raw tags

# push into delicious with specified tags

# some possible tags
# flickrPhoto to mark that it is a flickrPhoto -- though this can also be computed
# myFlickrPhoto -- also can be computed if you do a comparison
# FlickrFavorite


#
# 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

# do Laura's

$user_id = '43472158@N00';

# I need to loop over pages....

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

// Loop through the photos and output the html

$maxcount = 10;
$count = 0;

foreach ($photos['photo'] as $photo) {

  $count += 1;
  if ($count > $maxcount) {
    break;
  }

  echo $photo['id'], "\n";

  $sUrl = "http://www.flickr.com/photos/$photo[owner]/$photo[id]/";
  $sDescription = $photo['title']. " (on Flickr)";
  $sNotes = '';
  $sDate = '';  # copy over or just post with default time of NOW?
  $bReplace = true;
  echo $sUrl, $sDescription, " ", $sNotes, " ", $sDate, " ", $bReplace;
  $aTags = split(' ', $photo['tags']);
  $aTags[] = 'FlickrFavorite';
  print "\n";
  if ($del_obj->AddPost($sUrl, $sDescription, $sNotes, $aTags, $sDate, $bReplace)) {
    print "added $sUrl successfully\n";
  } else {
    print "problem in adding $sUrl\n";
  }


}


?>
