Source Code: flickrphotos
<?php
//phpFlickr
require_once("phpFlickr/phpFlickr.php");
$username = "[USERNAME]";
$apiKey = "[APIKEY]";
$apiSecret ="[APISECRET]";
$authToken = '[AUTHTOKEN]'; //optional
// Create new phpFlickr object
$f = new phpFlickr($apiKey, $apiSecret);
$f->setToken($authToken);
$f->enableCache("db","mysql://USERNAME:PASSWORD@SERVER/DBNAME");
//or
$f->enableCache("fs","cache");
// Find the NSID of the username inputted via the form
$nsid = $f->people_findByUsername($username);
function returnphotosets_getList($f,$user_id){
$photosets = $f->photosets_getList($user_id);
if(!empty($photosets)){
$html .="<ul class='menublock'>";
foreach ($photosets['photoset'] as $set) {
$html .= "<li><a href='photos.php?action=photoset&setid=$set[id]' >$set[title]</a></li>";
}
$html .= "</ul>";
}
echo $html;
}
function returnPhotoThumbs($f,$user_id){
$photosets = $f->photosets_getList($user_id);
$html .= "<h2>Flickr Photos</h2>";
if(!empty($photosets)){
$html .= "<ul style='list-style-type:none;'>";
$i =0;
foreach ($photosets['photoset'] as $set) {
$html .= "<li style='list-style-type:none;'><strong>".$set['title']."</strong><br>";
$html .= "<a href='photos.php?action=photoset&setid=$set[id]' title='$set[title]'>";
$html .= "<img alt='$set[title]' src='http://static.flickr.com/$set[server]/$set[primary]_$set[secret]_s.jpg' />";
$html .= "</a>";
$html .= "</li>";
}
$html .= "</ul>";
}
echo $html;
}
function returnPhotos($f,$setid) {
$photosSetInfo = $f->photosets_getInfo($setid);
$heading = "Photos: ".$photosSetInfo['title'];
$photos = $f->photosets_getPhotos($setid, NULL, NULL);
$html = "<h2>".$heading."</h2><p>";
$html .= "<div id='mainphotodiv' class='splitcontentleftImg'>";
foreach ($photos['photo'] as $photo) {
if($photo['isprimary'] == 1) {
//$html .= "<a href='".$f->buildPhotoURL($photo, "medium")."' rel='lightbox[".$photos['id']."]' title='".$photo['title']."' id='mainphotoHREF'> ";
$html .= "<a href='photos.php?action=slideshow&setid=".$photos['id']."' title='".$photo['title']."' id='mainphotoHREF'> ";
$html .= "<img border='0' alt='$photo[title]' "."src=" . $f->buildPhotoURL($photo, "medium") . " id='mainphoto'>";
$html .= "</a>";
$html .= "<p id='photoTools'><a href='photos.php?action=detailview&setid=".$photos['id']."'>Detail View</a></p>";
$html .= "<p id='mainphotoDesc'>".$photosSetInfo['description']."</p>";
break;
}
}
$html .="</div>";
$html .= "<div id='photos' class='splitcontentrightImg'>";
foreach ($photos['photo'] as $photo) {
$html .= "<a href='".$f->buildPhotoURL($photo, "medium")."' rel='lightbox[".$photos['id']."]' title='".$photo['title']."' >";
$html .= "</a>";
$html .= "<a href='#' title='".$photo['title']."' onclick='SwapImage(".$photo['id'].",".$photos['id'].");return false;' ><img border='0' alt='$photo[description]' src='".$f->buildPhotoURL($photo, "Square")."'id='photo_".$photo['id']."'></a>";
//$html .= "<a href='#'><img border='0' alt='$photo[title]' src='".$f->buildPhotoURL($photo, "Square")."' onclick='SwapImage(\"".$f->buildPhotoURL($photo, "medium")."\",\"".$photo['description']."\",\"photo_".$photo['id']."\");return false;' id='photo_".$photo['id']."'></a>";
}
$html .="</div></p>";
echo $html;
}
function returnPhotosDetailView($f,$setid) {
$photosSetInfo = $f->photosets_getInfo($setid);
$heading = "Photos: ".$photosSetInfo['title'];
$photos = $f->photosets_getPhotos($setid, NULL, NULL);
$i=0;
$html .= "<table border='0' >";
$html .="<tr valign=top>";
foreach ($photos['photo'] as $photo) {
$html .="<td><table>";
$html .="<tr><td><strong>".$photo['title']."</strong></td></tr>";
$html .="<tr><td>";
$html .= "<a href='".$f->buildPhotoURL($photo, "medium")."' rel='lightbox[".$photos['id']."]' title='".$photo['title']."' >";
//$html .= "</a>";
$html .= "<img border='0' alt='$photo[title]' ".
"src='".$f->buildPhotoURL($photo, "small")."' id='photo_".$photo['id']."'></a>";
$html .="</td></tr>";
$html .="<tr><td>".$photo['description']."</td></tr>";
$html .= "</table></td>";
$i++;
if ($i % 3 == 0) {
$html .= "</tr><tr valign=top>";
}
}
$html .="</table>";
echo $html;
}
function returnPhoto($f,$pid,$setid) {
$photo = $f->photos_getInfo($pid,NULL);
$html .="<h2>".$photo['title']."</h2><div class='splitcontentleftImg'> ";
$html .= "<img src='".$f->buildPhotoURL($photo, "medium") ."' id='currentPhoto' class='box' >";
$html .= "</div>";
if($setid != '') {
$photosSetInfo = $f->photosets_getInfo($setid);
$heading = "Photos: ".$photosSetInfo['title'];
$photos = $f->photosets_getPhotos($setid, NULL, NULL);
}
echo $html ;
}
function returnPhotoSetThumbsList($f,$user_id){
$photosets = $f->photosets_getList($user_id);
if(!empty($photosets)){
$html = "<h2>Photo Sets</h2>";
$html .= "<div class='menublock'>";
foreach ($photosets['photoset'] as $set) {
$html .= "<a href='photos.php?action=photoset&setid=$set[id]' title=$set[title]'>";
$html .= "<img alt='$set[title]' src='http://static.flickr.com/$set[server]/$set[primary]_$set[secret]_s.jpg' border='0' align='top'/><br>$set[title]";
$html .= "</a>";
}
$html.= "</div>";
}
echo $html;
}
function returnUserMainTags($f,$user_id){
$tags=$f->tags_getListUserPopular($user_id,10);
$html .= "<h2>Photo Tags</h2>: ";
$html .= "<ul class='menublock'>";
foreach($tags as $tag) {
/*$strStyle = "style=font-size:9px;";
if($tag['count'] <= 10) {
} else if ($tag['count'] <= 10) {
$strStyle = "style=font-size:9px;";
} else if ($tag['count'] <= 20) {
$strStyle = "style=font-size:11px;";
} else if ($tag['count'] <= 30) {
$strStyle = "style=font-size:13px;";
} else if ($tag['count'] <= 40) {
$strStyle = "style=font-size:15px;";
} else if ($tag['count'] <= 50) {
$strStyle = "style=font-size:17px;";
} else {
$strStyle = "style=font-size:9px;";
}
*/
$html.= "<li><a href='photos.php?action=tagview&tag1=".$tag['_content']."' >".$tag['_content']." (".$tag['count'].")</a></li> ";
}
$html .= "</ul>";
echo $html;
}
function returnRelatedTags($f,$user_id,$tag1){
//print_r($tag1);
$tags=$f->tags_getListUserPopular($user_id,10);
$html .= "<span class='small box'>";
$html .= "<strong>Photo Tags:</strong> ";
foreach($tags as $tag) {
$html.= " <a href='photos.php?action=tagview&tag1=".$tag1."&tag2=".$tag['_content']."' >".$tag['_content']." (".$tag['count'].")</a> ";
}
$html .= "</span>";
echo $html;
}
function returnPhotosByTag($f,$tag1,$tag2,$user_id) {
$tags = "\"".$tag1."\"";
$heading = $tag1;
if($tag2 != "") {
$tags = "\"".$tag1.",".$tag2."\"";
$heading .=" and ".$tag2;
}
$args = $args = array("tags"=>$tags, "tag_mode"=>"all","user_id"=>$user_id);
$photos = $f->photos_search($args);
$html .="<h2>Photos by Tag: ".$heading."</h2>";
if( count($photos['photo']) == 0) {
$html .= "<h3 class='error'>Sorry, No Photos match ".$heading."</h3>";
$html .= returnPhotosByTag($f,$tag1,"",$user_id);
} else {
$tags=$f->tags_getListUserPopular($user_id,10);
$html .= "<p class='small box'>";
$html .= "<strong>Photo Tags:</strong> ";
foreach($tags as $tag) {
$html.= " <a href='photos.php?action=tagview&tag1=".$tag1."&tag2=".$tag['_content']."' >".$tag['_content']." (".$tag['count'].")</a> ";
}
$html .= "</p>";
$html .= "<p id='photos' >";
foreach ($photos['photo'] as $photo) {
$html .= "<a href='photos.php?action=photoset&setid=$setid[id]' title='".$photo['title']."' >";
$html .= "<img border='0' alt='$photo[title]' "."src='".$f->buildPhotoURL($photo, "Square")."' id='photo_".$photo['id']."'></a>";
}
$html .="</p>";
}
echo $html;
}
function flickrSlideShow($f,$setid) {
$photosSetInfo = $f->photosets_getInfo($setid);
$heading = "Photos: ".$photosSetInfo['title'];
$photos = $f->photosets_getPhotos($setid, NULL, NULL);
$html .= "<table height=400 width=600 cellpadding=1 bgcolor='#ffffff'>";
$html .= "<tr ><td><strong>".$heading."</strong></td></tr>";
$html .= "<tr valign=middle height=400 >";
$html .= "<td width=400 id='mainphotodivTH'>";
foreach ($photos['photo'] as $photo) {
if($photo['isprimary'] == 1) {
$prenext = $f->photos_getContext ($photo['id']);
$prev = $prenext['prevphoto'];
$next = $prenext['nextphoto'];
$html .= "<table height=400 width=600 cellpadding=1>";
$html .= "<tr valign=top>";
$html .= "<td valign=middle width='15%' id='nextphotoSS'>";
$html .= "</td>";
$html .= "<td align=center width='70%' id='mainphotoSS'>";
$html .= "</td>";
$html .= "<td valign=middle width='15%' id='prevphotoSS'>";
$html .= "</td>";
$html .= "</tr>";
$html .= "</table>";
$html .= "<script>SlideShow(".$photo['id'].");</script>";
break;
}
}
$html .= "</td>";
$html .= "</tr>";
$html .= "<tr>";
$html .= "<td align=center>";
$i = 0;
foreach ($photos['photo'] as $photo) {
$html .= "<a href='#' title='".$photo['title']."' onclick='SlideShow(".$photo['id'].",".$_GET['setid'].");return false;' ><img border='0' alt='$photo[description]' src='".$f->buildPhotoURL($photo, "Square")."' id='photo_".$photo['id']."' width='50' height='50'></a>";
$i++;
if ($i % 7 == 0) {
$html .= "<br>";
}
}
$html .= "</td>";
$html .= "</tr>";
$html .= "</table>";
echo $html;
}
?>
<script>
/* function SwapImage(newImg,newDesc,id) {
//new Effect.Grow('mainphoto');
document.getElementById('mainphoto').src = newImg;
document.getElementById('mainphotoDesc').innerHtml = newDesc;
document.getElementById('mainphotoHREF').href = newImg;
}
*/
var handlerSwapImage = function SwapImage_Callback(str) {
document.getElementById('mainphotodiv').innerHTML = str.responseText;
}
function SwapImage(pid,setid)
{
document.getElementById('mainphoto').src = 'images/loading.gif';
document.getElementById('mainphoto').align = 'absmidddle';
//document.getElementById('mainphotodiv').innerHTML = 'Loading...';
new Ajax.Updater('mainphotodiv','ajaxPhoto.php?pid='+pid+'&setid='+setid+'', { method:'get', asynchronous:true, onSuccess:handlerSwapImage });
}
///
var handlerSlideShow = function SlideShow_Callback(str) {
document.getElementById('mainphotoSS').innerHTML = str.responseText;
}
///
var handlerPrevPhoto = function PrevPhoto_Callback(str) {
document.getElementById('prevphotoSS').innerHTML = str.responseText;
}
///
var handlerNextPhoto = function NextPhoto_Callback(str) {
document.getElementById('nextphotoSS').innerHTML = str.responseText;
}
function SlideShow(pid)
{
document.getElementById('mainphotoSS').innerHTML = '<img src=images/loading.gif>';
document.getElementById('nextphotoSS').innerHTML = '<img src=images/loading.gif>';
document.getElementById('prevphotoSS').innerHTML = '<img src=images/loading.gif>';
new Ajax.Updater('mainphotoSS','ajaxPhoto.php?action=main&pid='+pid+'', { method:'get', asynchronous:true, onSuccess:handlerSlideShow });
new Ajax.Updater('nextphotoSS','ajaxPhoto.php?action=next&pid='+pid+'', { method:'get', asynchronous:true, onSuccess:handlerNextPhoto });
new Ajax.Updater('prevphotoSS','ajaxPhoto.php?action=prev&pid='+pid+'', { method:'get', asynchronous:true, onSuccess:handlerPrevPhoto });
}
function SlideShowPrev(pid)
{
new Ajax.Updater('prevphotoSS','ajaxPhoto.php?action=prev&pid='+pid+'', { method:'get', asynchronous:true, onSuccess:handlerPrevPhoto });
}
function SlideShowNext(pid)
{
new Ajax.Updater('nextphotoSS','ajaxPhoto.php?action=next&pid='+pid+'', { method:'get', asynchronous:true, onSuccess:handlerNextPhoto });
}
</script>
<?php
$action = rawurlencode($_GET['action']);
$setid = rawurlencode($_GET['setid']);
$pid = rawurlencode($_GET['pid']);
$tag1 = rawurlencode($_GET['tag1']);
$tag2 = rawurlencode($_GET['tag2']);
switch($action) {
case 'photoset':
flickrSlideShow($f,$setid);
//returnPhotos($f,$setid);
break;
case 'view':
returnPhoto($f,$pid,$setid);
break;
case 'detailview':
returnPhotosDetailView($f,$setid);
break;
case 'tagview':
returnPhotosByTag($f,$tag1,$tag2,$nsid['id']);
break;
case 'slideshow':
flickrSlideShow($f,$setid);
break;
default:
returnPhotoThumbs($f,$nsid['id']);
break;
}
?>
<?php returnPhotoThumbs($f,$nsid['id']); ?>





