<?php

/*
 * Written by Justin Henry, http://greengaloshes.cc
 * Released under GNU Lesser General Public License (http://www.gnu.org/copyleft/lgpl.html)    
*/

require_once("phpFlickr/phpFlickr.php");

/**
* FlickrGallery
*/
class flickrGallery
{
    function 
FlickrGallery()
    {
        
$this->user_id '1234567@N00'// replace w/ a real user id
        
$this->api_key '4dsds09fgsfg34jh0e76g'//replace w/ a real api key 
        
$this->fs_cache_path '/full/system/path/to/cache/dir/'// where to store downloaded images
        
        
$this->cache_url 'http://full.url.to/above/cache/dir/'// so we can access the downloaded images
        
$this->zoomify_path '/full/system/path/to/zoomify/dir/'// tell the system where to put zoomed images
        
        // init api class
        
$this->=& new phpFlickr($this->api_key);

        
// turn on cache
        
$this->f->enableCache("db"'mysql://user:password@server/database'); // reccommended. 
        //$this->f->enableCache("fs", $this->fs_cache_path); // if you don't have a database
        
        // this tells phpFlickr::imageCache where to cache images
        
$this->f->cache_dir $this->fs_cache_path
    }


    
/**
     * display_gallery
     * 
     * @return void 
     * @author Justin Henry
     **/
    
function display_gallery($tags$result_size$refresh_image_cache false)
    {

        
// perform search
        
$search_results $this->f->photos_search
                                                    array(
                                                        
"user_id"=>$this->user_id
                                                        
"tags"=>$tags
                                                        
"per_page"=>$result_size
                                                        
"tag_mode"=>"all"
                                                        

                                                );
    
        
// loop through results and display
        
foreach ($search_results['photo'] as $photo) : 
        
            
$photo_id $photo['id'];
            
$url $this->f->buildPhotoURL($photo"Small");
            
$cached_image "cache/" $this->f->cacheImage($url$refresh_image_cache);
    
?>    

        <span class="thumb"><p class="title"><?php echo $photo["title"]; ?></p>
        <a class="new_screen" href="zoom.php?photo_id=<?php echo $photo_id?>"><img class="tn" src="<?php echo $cached_image?>" alt="<?php echo $photo["title"]; ?>" /></a>
        <p class="subtitle"><a class="new_screen" href="zoom.php?photo_id=<?php echo $photo_id?>">Zoom in on this photo</a>, or view the <a class="new_screen" href="http://flickr.com/photos/<?php echo $this->user_id?>/<?php echo $photo_id?>">photo page</a>.</p>
        </span>

        <?php 
    
        
endforeach; 
    
    }

    function 
display_large_image($photo_id$refresh_image_cache false)
    {
    
        
// perform query
        
$photo $this->f->photos_getInfo($photo_id);
    
        
// set up cache
        
$url $this->f->buildPhotoURL($photo"large");
        
$cached_image "cache/" $this->f->cacheImage($url$refresh_image_cache);
        
?>
    
        <span class="large_size"><p class="title"><?php echo $photo["title"]; ?></p>
        <img class="large" src="<?php echo $cached_image?>" alt="<?php echo $photo["title"]; ?>" />
        <p class="description"><?php echo $photo["description"]; ?></p>
        <p class="flickr_credit">You can also view the <a class="new_screen" href="http://flickr.com/photos/<?php echo $this->user_id?>/<?php echo $photo_id?>">photo page</a>.</p>
        </span>
    
        <?php
    
}
    
    function 
zoomify_collection($tags$result_size$refresh_image_cache false)
    {
        
$cache_url null;
        
$zoomify_path null;

        
// perform search
        
$search_results $this->f->photos_search( array("user_id"=>$this->user_id"tags"=>$tags"per_page"=>$result_size) );
    
        foreach (
$search_results['photo'] as $photo) { 
        
            
$photo_id $photo['id'];
            
$url $this->f->buildPhotoURL($photo"Original");
            
//$sizes = $this->f->photos_getSizes($photo["id"]);
            //print_r($sizes);
            
$this->f->cache_dir $this->zoomify_path;
            
$cached_image $this->zoomify_path $this->f->cacheImage($url$refresh_image_cache);
            
            
$filename explode("."basename($url));
            
$base $filename[0] . "_zdata";
            
            
// if it hasn't been converted, process it.
            
if(!is_dir($this->zoomify_path.$base)) {
                echo 
"<h2>processing image $cached_image ...</h2>";
                
$zoomify = new ZoomifyFileProcessor();
                
$zoomify->debug 1;
                
$zoomify->ZoomifyProcess($cached_image);
            }
        } 
    
    }
    
}
?>