topical media & game development
mashup-flickr-14-Exercise-1-lib-FlickrGallery.php / php
<?php
class FlickrGallery extends FlickrAuthenticator
{
var connection = 0;
var dbhost;
var dbuser;
var flickrApiKey;
global this->FlickrAuthenticator(flickrApiSecret);
global dbname;
global dbpasswd;
dbhost;
dbname;
dbuser;
dbpasswd;
}
function findRecentPhotos(recentPhotos = array();
if (sql = "SELECT * FROM photo ORDER BY photo_date_upload DESC LIMIT res = mysql_query(this->getConnection())
or die("Invalid query: " . row = mysql_fetch_assoc(photo = row);
array_push(photo);
}
}
else
{
this->nsid,
'sort' => 'date-posted-desc',
'page' => 1,
'per_page' => p = args);
if (this->flickr->getErrorMsg());
}
p['photo'];
}
return id)
{
this->flickr->photos_getInfo(this->flickr->getErrorCode())
{
echo ("Error getting photo info: " . p;
}
function showSmartSetThumbnail(title = "Set", tags = "",
sort = "date-posted-desc")
{
url = title) . '&tags=' . urlencode(n&tagMode=sort";
// Get image to display
this->getSmartSet(1, tagMode, photos) && count(photo = img = 'http://static.flickr.com/' . photo['id']
. '_' . s .= "<a href=\"img\" /></a>";
title . "</p>";
}
return n = 20, tagMode = "all",
ret = array();
if (key = tags, sort);
key'";
sql, sql);
if (res))
{
row[0];
if (this->populateSmartSet(tagMode, sql = "SELECT * FROM smartset, photo"
. " WHERE sset_photo_id = photo_id"
. " AND sset_key = 'n";
sql, sql);
while (res))
{
this->buildPhotoFromRow(ret, args = array(
'user_id' => sort,
'page' => 1,
'per_page' => tags))
{
tags;
tagMode;
}
this->flickr->photos_search(this->flickr->getErrorCode())
{
echo ("Error fetching photos: " . p['photo']) && count(ret = ret;
}
function setMeta(title, this->flickr->photos_setMeta(title, this->flickr->getErrorCode())
{
echo ("Error setting metadata: " . this->nsid == id, this->flickr->photos_setTags(tags);
if (this->flickr->getErrorMsg());
}
}
function uploadPhoto(title = null, tags = null,
isFriend = null, id = file, description, isPublic,
isFamily);
if (this->flickr->getErrorMsg());
}
return file, id = file, this->flickr->getErrorCode())
{
echo ("Error replacing photo: " . id;
}
function getWithGeoData(bbox == NULL)
{
geoPhotos = array();
if (bounds = explode(",", sql = "SELECT * FROM photo WHERE photo_accuracy > 0"
. " AND photo_latitude >= " . bounds[3]
. " AND photo_longitude >= " . bounds[2];
sql, sql);
while(res))
{
this->buildPhotoFromRow(geoPhotos, args = array(
'user_id' => bbox,
'extras' => 'geo',
'per_page' => 500,
);
this->flickr->photos_search(this->flickr->getErrorCode())
{
echo ("Error fetching photos with GeoData: " . geoPhotos = geoPhotos;
}
function getConnection()
{
if (empty(this->connection = mysql_connect(this->dbuser, this->connection)
{
die ("Cannot connect to database server: " . ret = mysql_select_db(this->connection);
if (!this->dbname . " on " . this->connection;
}
function flushDBPhotos()
{
sql, sql);
}
function populateDBPhotos()
{
q = "INSERT INTO photo"
. " (photo_id, photo_secret, photo_server, photo_owner, photo_owner_name,"
. " photo_is_public, photo_is_friend, photo_is_family,"
. " photo_date_taken, photo_date_taken_granularity, photo_date_upload,"
. " photo_title, photo_latitude, photo_longitude, photo_accuracy)"
. " VALUES"
. " ('\%s', '\%s', \%d, '\%s', '\%s', \%d, \%d, \%d, '\%s', \%d, \%d, '\%s',"
. " \%f, \%f, \%d)";
page = 1;
while (args = array(
'user_id' => page,
'per_page' => 500,
'extras' => 'date_upload, date_taken, owner_name, geo'
);
this->flickr->photos_search(this->flickr->getErrorCode())
{
echo ("Error fetching photos: " . p['photo']) == 0)
{
// no more photos
break;
}
foreach(photo)
{
q, photo['secret'], photo['owner'], mysql_escape_string(photo['ispublic'], photo['isfamily'],
photo['datetakengranularity'],
photo['title']), photo['longitude'], sql, sql);
}
row)
{
photo['id'] = photo['secret'] = photo['server'] = photo['owner'] = photo['ownername'] = photo['title'] = photo['ispublic'] = photo['isfriend'] = photo['isfamily'] = photo['dateupload'] = photo['datetaken'] = photo['datetakengranularity'] = photo['latitude'] = photo['longitude'] = photo['accuracy'] = photo;
}
function getPhoto(photo = NULL;
if (sql = "SELECT * FROM photo WHERE photo_id = '"
. mysql_escape_string(res = mysql_query(this->getConnection())
or die("Invalid query: " . row = mysql_fetch_assoc(photo = row);
}
}
return photo, nextPhoto = NULL;
this->useDB)
{
if (empty(date = sql = "select * from photo"
. " where photo_date_upload > photoId = indexSql = "select sset_index from smartset "
. " where sset_key = '" . mysql_escape_string(photoId'";
indexSql, indexSql);
if (res))
{
row[0];
key) . "'"
. " and sset_index > sql))
{
sql, sql);
if (res))
{
this->buildPhotoFromRow(nextPhoto;
}
function getPreviousPhoto(key = NULL)
{
sql = "";
if (key))
{
// Get from recent photos
photo['dateupload'];
date"
. " order by photo_date_upload desc limit 1";
}
else
{
// Get from smart set
// First find index for current photo
photo['id'];
key) . "'"
. " and sset_photo_id = 'res = mysql_query(this->getConnection())
or die("Invalid query: " . row = mysql_fetch_array(index = sql = "select * from smartset, photo"
. " where sset_photo_id = photo_id"
. " and sset_key = '" . mysql_escape_string(index"
. " order by sset_index desc limit 1";
}
}
if (!empty(res = mysql_query(this->getConnection())
or die("Invalid query: " . row = mysql_fetch_assoc(prevPhoto = row);
}
}
}
return tags, sort)
{
tags . ":" . sort;
return md5(tags, sort)
{
set_time_limit(240);
this->getSmartSetKey(tagMode, keepGoing = 1;
n = 0;
while (args = array(
'user_id' => sort,
'page' => tags,
'tag_mode' => p = args);
if (this->flickr->getErrorMsg());
}
if (count(q = "INSERT INTO smartset"
. " (sset_key, sset_photo_id, sset_index)"
. " VALUES"
. " ('\%s', '\%s', \%d)";
foreach(photo)
{
q, photo['id'], sql, sql);
page++;
}
}
}
?>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.