Aquarionics

/home/a/aquarion/sites/www.aquarionics.com/epistula/chapters/gallery.inc.php

All my code (That is, anything not in the "Others" list on the right) is BSD licenced.

You can also view this page as text/plain or colour-coded source


<?PHP
/*******************************************************************************
    Chapter - Gallery
********************************************************************************

    Gallery. Display a gallery of images

    TODO: Fix the fugly URLS
    TODO: Fix the fugly code
    TODO: Rewrite gallery from scratch, it's ugly beyond dreams

    $Id: gallery.inc.php,v 1.2 2004/06/04 09:49:41 aquarion Exp $

    $log$

*******************************************************************************/

$file = implode("/",$wanted);

$page->title = "Gallery";


/*******************************************************************

        Functions

********************************************************************/

if ($wanted[1] == "") {
    $page->content .= $page->item(byCat("gallery", "", "", "title"));    
} elseif ($wanted[1] == "id" && is_numeric($wanted[2])) {
    if (checkexists("gallery", $wanted[2])) {
        $query = "select * from gallery where gallery.id = ".$wanted[2];
        $results = safequery($query);
        if (mysql_num_rows($results) == 0) {
            $page->content = "No gallery by that name.";
        } else {
            $gallery = mysql_fetch_assoc($results);
            $page->forwardto("/gallery/".ep_encode($gallery['title']));
        }
    } else {
        $page->debug[] = "No gallery by that ID.";
        $page->status = 404;
    }
} else {

$query = "select * from gallery where title = \"".urldecode(ep_decode(stripslashes($wanted[1])))."\"";
$results = safequery($query);



if (mysql_num_rows($results) == 0) {
        $page->content = "Gallery in existance failure error. The universe will self-destruct shortly.<br>".$query;
        $found = 0;

} else {
    $page->debug[] = "Found Gallery";

    $gallery = mysql_fetch_assoc($results);
    $page->title = $gallery['title'];
    $dir = $_EP['galleryRoot']."/".$gallery['directory'];

    $fdir = $_EP['webdir']."/".$dir;

    $page->localnav = pageShowAds($page->date,"", "gallery-".$gallery['id']);


    $menu = array();
    $readdir = opendir($fdir) or die('Could not open dir.');
    while($file = readdir($readdir)){
        if(preg_match("/.(jpg|gif|png|avi|mpg|mov)$/i", $file) && !preg_match("/.thumb.(jpg|gif|png|avi|mpg|mov)$/i", $file) && !preg_match("/^title.gif$/i", $file)){
            $fn_length = strlen($file);
            $fn_dot = strpos($file, ".");
            $fn_name = substr ($file, 0, $fn_dot);
            $fn_size = filesize($fdir."/".$file)/102.4;
            $fn_size = (int) $fn_size;
            $fn_ext = substr ($file, ($fn_dot+1), $fn_length);
            if (preg_match("/.(jpg|gif|png)$/i", $file)){
                $bigimage = getimagesize($fdir."/".$file);
                $alt = $file.", ".$bigimage[0]."*". $bigimage[1] ." <".$fn_size."k>";
            } else {
                $alt = $file.", <".$fn_size."k>";
            }
            $link = "/gallery/".ep_encode($gallery['title'])."/".htmlentities($file);
            if (file_exists($fdir."/".$fn_name .".caption")){
                $caption = break_string(strip_tags(implode("", file($fdir."/".$fn_name .".caption"))), 70, "");
            }elseif (file_exists($fdir."/".$file .".caption")){
                $caption = break_string(strip_tags(implode("", file($fdir."/".$file .".caption"))), 70, "");
            } else {
                $caption = "";
            }
            $files[] = $file;
            $menu[] = array('name' => ucwords($fn_name), 'link' => $link, 'title' => $alt ."-".$caption);
        }

     } // end while
    closedir($readdir);
    #$page->pagenav = $page->subheading("Photos");
    #$page->pagenav.=$page->menu($menu);
    #$page->localnav = $page->subheading("Galleries");
    #$page->localnav .= byCat("gallery", "nodesc", "", "title");

    

    if ($wanted[2] == "") {

        $out = $page->gallery($gallery);
        #$out = $page->subheading($gallery['title']);
        #$out .= "<p>".$gallery['description']."</p>";
        #$out .= gallery($dir, $wanted[1], "/gallery/", 4);
        #$out = $page->item("
        #$out .= $page->gallery($id);
    } else {
        $photo = urldecode($wanted[2]);
        if (file_exists($fdir."/".$photo) && is_dir($fdir)){

            $output = $page->subheading($gallery['title']);

            $key = array_search($photo, $files);

            if ($key != (count($files)-1)){
                $next = array('name'=>'Next', 'link'=> $files[$key+1]);
                $page->links[] = array (
                    'rel' => "next",
                    'title' => "Next Image",
                    'href' =>  $files[$key-1]
                );
                $page->links[] = array (
                    'rel' => "last",
                    'title' => "Final Image",
                    'href' =>  $files[(count($files)-1)]
                );

            } else {
                $next = array('name'=>'Next');
            }

            if ($key != 0){
                $back = array('name'=>'Previous', 'link'=>$files[$key-1]);
                #$back = "<A HREF=\"".$files[$key-1]."\">Previous</A>";
                $page->links[] = array (
                    'rel' => "prev",
                    'title' => "Previous Image",
                    'href' =>  $files[$key-1]
                );
                $page->links[] = array (
                    'rel' => "first",
                    'title' => "First Image",
                    'href' =>  $files[0]
                );
            } else {
                $back = array('name'=>'Back');
            }


            $output .= $page->menu(
                array(
                    array('name'=>'First', 'link'=>$files[0]),
                    $back,
                    array('name'=>($key + 1) ."/".count($files)),
                    $next,
                    array('name'=>'Final', 'link'=>(count($files)-1))
                ), "pipe");

            #$output .=  "<p><A HREF=\"".$files[0]."\">First</A> | ". $back." | ". ($key + 1) ."/".count($files)." | ".$next." | <A HREF=\"".(count($files)-1)."\">Final</A></p>\n";

            #$ffile = $fdir."/".$photo;
            $file = $dir."/".$photo;

            if (file_exists($fn_name .".caption")) {
                $caption = implode("\n",file($fn_name .".caption"));
            }elseif (file_exists($file.".caption")) {
                $caption = implode("\n",file($file .".caption"));
            }

            if (preg_match("/.(mov|avi|mpg)$/i", $photo)) {
                $output .= "<embed src=\"/".$file."\" style=\"max-width: 100%\">";
            } else {
                $output .= "<img src=\"/".$file."\" style=\"max-width: 100%\" alt=\"$caption\">";
            }
        
            $fn_length = strlen($file);
            $fn_dot = strpos($file, ".");
            $fn_name = substr ($file, 0, $fn_dot);
            $fn_ext = substr ($file, ($fn_dot+1), $fn_length);
    

            if($caption){
                $output .= "<br>(<i>$caption</i>)";
            }


            $output .= $page->menu(
                array(
                    array(
                        'name'=>'Download This', 
                        'link'=>"/".$file
                    )
                ), "pipe");


            $output .= $page->menu(
                array(
                    array(
                        'name'=>'Aquarionics', 
                        'link'=>"/"
                    ),
                    array(
                        'name'=>'Index of Galleries', 
                        'link'=> "/gallery"
                    ),
                    array(
                        'name'=> "Index of \"".$gallery['title']."\"", 
                        'link'=> "/gallery/".ep_encode($gallery['title'])
                    ),
                ), "pipe");

        } else {
            $output .= "No Photo of that name ($photo)";
        }
        $out .= $page->item($output, false, "gallery photo");
    }

    $page->content .=  $out;
    #$page->content .= getQV($page,$gallery['id'],$type);
    #$page->content .= getComments($page, $type."-".$gallery['id']);
    }
} // end Wanted Empty



?>



Using a heavily customised version of Tom's PHPCode2ValidXHTML Thing

Nicholas 'Aquarion' Avenell is a web developer in London, you can find out more about him or how to get in touch.

There are more Articles, Projects, Journal Entries, Photographs and things that defy description here, too.

If you're looking for something specific, there are Calendar & Category -based lists of everything.

And if you want to follow stuff that appears here, try a Syndication Feed, or the generic Feed of everything.

Aquarionics on Livejournal


Aquarion [updating]
Twitter last updated


© 2000 to 2008 inclusive Nicholas Avenell
All comments are the property of their creators, published with permission
(Unless otherwise indicated, the opinions and sentiments expressed on this site are those of the author and not of any organisation of which he is an affiliate, including his employer. Caveat Lector, E&OE. sigh)
0.181 seconds, 1 queries, 2.74Mb on Thu, 20 Nov 2008 15:02:26 +0000, Not cached
Generated by Epistula Version 2.0.3