|
Posted by Dave B on 08/26/05 02:23
Hi,
I have a gallery that I'm trying to set up for a client (it's got some
pornographic pics on it - so if your sensibilities are offended by that, you
might want to skip it :) ).
The page is at
http://www.eroticaboxing.com/08gallery/index.php?gallery=gallery1
The php code I'm using sets everything up nicely with thumbnails, etc.,
but the thumbnails themselves don't link to a larger pic - instead, there's
a text link below each thumbnail that says "enlarge". I've pasted the code
below, and I was hoping one of y'all could tell me how to change it so the
the thumbnail was the link?
Thanks...!
<?php
/************************************************************************
Dynamic Gallery Class ver 1.0
This is a simple class that creates a gallery for displaying images complete
with thumbnails, large images pop up, and descriptions for the pop up. It is
easy to use and prepare even for a non PHP coder.
class dynamic_gallery {
//Just make a couple of small changes to this file.
//Insert the absolute path to the directory which will hold the galleries
//You can change "text", "small" and "large" to any directory name you
want.
var $thumbs_dir; // Directroy where created thumbnails can be stored
permanently
var $image_dir = 'large'; //Directory where you download images are stored.
May be higher resolution images.
var $txt_dir = 'text'; //Directory where you text files are stored in. Best
to just leave it text.
//Don't change any of the variables below
var $gallery_root;
var $gallery_name;
var $file;
var $columns = '';
var $num_cols;
var $file_array = array();
var $page;
var $num_pages;
var $length;
var $start_num;
var $save_thumbs;
function dynamic_gallery( $name, $pager=0, $cols = 3){
$this->gallery_name = $name;
$this->num_cols = $cols;
$this->page = $pager;
$cwd = getcwd();
$this->gallery_root = $cwd."/";
}
function display_galleries(){
$num_galleries = 0;
if(is_dir($this->gallery_root)){
$dh =opendir($this->gallery_root);
while( false !== ($dir = readdir($dh))) {
if( is_dir($this->gallery_root.$dir) && $dir != "." && $dir != "..") {
$format_dir = str_replace("_", " ", $dir);
print "<p><a
href=\"{$_SERVER['PHP_SELF']}?gallery=$dir\">$format_dir</a></p>";
$num_galleries++;
}
}
} else {
$this->message("This gallery directory doesn't exist.");
}
if ($num_galleries == 0)
{
$this->message("There are no galleries to display.");
}
closedir($dh);
}
function create_file_array ( ){
if(is_dir($this->gallery_root.$this->gallery_name."/") ) {
$dh = opendir ( $this->gallery_root.$this->gallery_name."/" );
while (false !== ($this->file = readdir($dh))){
if ( $this->file != "." && $this->file != ".." ){
//This script recognizes .jpg and .gif files only.
if ( substr($this->file, -4) == ".jpg" || substr($this->file, -4) ==
".JPG" || substr($this->file, -4) == ".gif"){
$this->file_array[] = $this->file;
}
}
}
if ( count($this->file_array) >= 1 ){
return true;
} else {
$this->message('This gallery contains no images');
return false;
}
} else {
$this->message('This gallery does not exist');
return false;
}
closedir($dh);
}
function message ($message){
print $message;
}
function print_file_array () {
sort($this->file_array);
$this->length = count($this->file_array);
$this->num_pages = ceil($this->length/30);//needs to dump into array
$this->start_num = (!isset($this->page)) ? 0 : ($this->page*30);
$end_num = ($end_num < $this->length) ? 30: $this->start_num -
$this->length ;
$output = array_slice($this->file_array, $this->start_num, $end_num);
$this->print_navigation($this->num_pages, $this->length,
$this->start_num);
for ($x=0; $x<=$this->length; $x++) {
$y = $x/$this->num_cols;
//make the thumbs as necessary
//determine if the file already exitst in a folder
if( $this->save_thumbs === true &&
file_exists($this->gallery_name."/".$this->thumbs_dir."/".$output[$x])) {
$img_src = $this->gallery_name."/".$this->thumbs_dir."/".$output[$x];
} elseif($this->save_thumbs === true) {
//We need to make the image and send a path
gallery_controller::make_images($this->gallery_name."/".$output[$x]);
$img_src = $this->gallery_name."/".$this->thumbs_dir."/".$output[$x];
} else {
$img_src = "create_thumbs.php?p=".$this->gallery_name."/".$output[$x];
}
$this->column .= "<td><img src=\"$img_src\">\n";
//in the line below, change "self" to "blank" for a new page
$this->column .= "<br><a
href=\"display_large.php?image=".$output[$x]."&gallery=$this->gallery_name\"
target=\"_self\">enlarge</a>\n";
//line below adds the word "download" below thumbnails
/*$this->column .= "<a
href=\"".$this->gallery_name."/".$this->image_dir."/".$output[$x]."\">download</a></td>\n";
*/
if ($x == 0){
print "<table width=\"80%\" border=\"0\" cellpadding=\"5\"
align=\"center\"><tr>\n";
print $this->column;
}
if ( is_int($y) && $x != 0 && isset($output[$x])){
print '</tr><tr>'.$this->column;
}
if ( !is_int($y) && isset($output[$x])){
print $this->column;
}
unset($this->column);
}
print "</tr></table>\n";
$this->print_navigation($this->num_pages, $this->length,
$this->start_num);
}
function print_navigation ( $num_pages, $length, $start_num ){
$num = $this->num_pages;
$pages_list = array();
for ($x = 0; $x < $num; $x++)
/*This part removed by me to eliminate page numbers {
// print navigation
$pr_page= $x +1;
$pages_list[$x] = $pr_page;
}
Down to here - remove slash and asterisks to reacitvate */
$page_length = count($pages_list);
if ($num <= 5){
//Exception for fewer than 5 pages of pics
$page_start = 0;
}
else if ($num >5 && $this->page != 0 && $this->page+1 != $num ){
//Exception for more than 5 pages
if($this->page == ($num-2)){
//Exception for 2nd to last page
$page_start = $this->page -3;
}
else if ($this->page == 1){
//Exception for 2nd page
$page_start = 0;
}
else {
$page_start = $this->page -2; //All other pages increment by 2
}
}
else if ($this->page +1 == $num){
//Exception for last page
$page_start = $this->page - 4;
}
else if ($num >5 && $this->page == 0)
{ //Exception for first page
$page_start =0;
}
else{
}
$page_output = array_slice($pages_list, $page_start, 5);
foreach ($page_output as $val){
$urlPage = $val -1;
print "<a href=\"index.php?page=$urlPage&gallery=$this->gallery_name\"
class=\"boldblack\">page $val</a> | ";
}
$end_image = $this->start_num+30;
$end_image =( $end_image > $this->length)? $this->length :
$this->start_num+30;
$display_start = ($this->start_num == 0 )? 1 : $this->start_num;
($num >5)? print " of $num pages $this->length total images": print
"$display_start through $end_image of $this->length total images";
}
function display_large($image){
$descrip_file = str_replace(substr($image, -4), '.txt', $image );
if(file_exists($this->gallery_root.$this->gallery_name."/".$this->txt_dir."/".$descrip_file)){
$description =
file_get_contents($this->gallery_name."/".$this->txt_dir."/".$descrip_file);
} else {
$description = false;
}
if ( file_exists($this->gallery_root.$this->gallery_name."/".$image) ){
$previous_image = $this->previous_image($image);
$next_image = $this->next_image($image);
if ($previous_image){
print "<a
href=\"display_large.php?image=".$previous_image."&gallery=".$this->gallery_name."\">previous</a>
| ";
}
if ($next_image){
print "<a
href=\"display_large.php?image=".$next_image."&gallery=".$this->gallery_name."\">next</a><br>";
}
print "<img src=\"".$this->gallery_name."/".$image."\">";
if ($description) print $description;
} else {
$this->message( "There is no larger image for this thumbnail.");
}
}
function next_image($image){
$this->create_file_array();
$cur_image = array_search($image, $this->file_array);
if ($cur_image+1 >= count($this->file_array)){
return false;
}
$next_image = $this->file_array[$cur_image+1];
return $next_image;
}
function previous_image($image){
$this->create_file_array();
$cur_image = array_search($image, $this->file_array);
if ($cur_image-1 <= 0 && $cur_image != 1){
return false;
}
$previous_image = $this->file_array[$cur_image-1];
return $previous_image;
}
}//end Class
?>
Navigation:
[Reply to this message]
|