in the
section of your html
// AND the tag in your page.
// $delay is the number of seconds to pause between slides...
$delay = 4;
// set to true to display navigation icons instead of text...
$show_navigation_buttons = "false";
$back_button = "/back.gif";
$next_button = "/next.gif";
// ------------- END CONFIG SECTION --
################################################################################
// begin code :: don't make changes below this line...
// initialize some stuff:
$auto_url = "";
$thumbnail_actual_width = "";
$thumbnail_actual_height = "";
// grab the variables we want set for newer php version compatability
$phpslideshow = isset($_GET['phpslideshow']) ? $_GET['phpslideshow'] : '';
$path_to_images = isset($_GET['directory']) ? $_GET['directory'] : '';
$currentPic = isset($_GET['currentPic']) ? $_GET['currentPic'] : '';
$browse = isset($_GET['browse']) ? $_GET['browse'] : '';
$auto = isset($_GET['auto']) ? $_GET['auto'] : '';
// check for platform dependent path info... (for windows and mac OSX)
$path = empty($HTTP_SERVER_VARS['PATH_INFO'])?
$HTTP_SERVER_VARS['PHP_SELF']:$HTTP_SERVER_VARS['PATH_INFO'];
// this only works on php > 4.3, replacing with file()
//if( file_exists( "template.html" ) ) $template = file_get_contents("template.html");
if( file_exists( "template.html" ) ) $template = implode("", file('template.html'));
else {
echo "ERROR: Can't find the template.html file!";
exit;
}
// check that the user did not change the path...
if (preg_match(':(\.\.|^/|\:):', $path_to_images) || strpos($path_to_images, $thumbnail_dir) !== false) {
echo "ERROR: Your request contains an invalid path.
Can not locate $path_to_images in this directory.
";
exit;
}
if (empty($path_to_images)) $path_to_images = ".";
// if there is no $heading_info_file (see format above) set page heading here
if ( !file_exists("$path_to_images/$heading_info_file")) {
$header = "PHPSlideshow by greg lawler at zinkwazi.com";
$title = "PHPSlideshow by greg lawler at zinkwazi.com";
}
else {
$heading_info = file("$path_to_images/$heading_info_file");
$header = "$heading_info[0]";
$title = $header;
}
$template = str_replace("",$title,$template);
$template = str_replace("",$header,$template);
// image / text buttons
if ($show_navigation_buttons == "true") {
$back_src = "
";
$next_src = "
";
}
else {
$back_src = "$lang_back";
$next_src = "$lang_next";
}
if ( !file_exists("$path_to_images/$pic_info_file")) {
$dh = opendir( "$path_to_images" );
$pic_info = array();
$time_info = array();
while( $file = readdir( $dh ) ) {
// look for these file types....
if (preg_match('/(jpg|jpeg|gif|png)$/i',$file)) {
$time_info[] = filemtime("$path_to_images/$file");
$pic_info[] = $file;
}
}
if ($sort_images == 'name') {
natcasesort($pic_info);
$pic_info = array_reverse(array_reverse($pic_info)); //resetting array keys
}
else {
$sortorder = $sort_images == "oldest" ? SORT_ASC : SORT_DESC;
array_multisort($time_info, $sortorder, $pic_info, SORT_ASC, $time_info);
}
}
else {
$pic_info=file("$path_to_images/$pic_info_file");
}
// begin messing with the array
$number_pics = count ($pic_info);
if (($currentPic > $number_pics)||($currentPic == $number_pics)||!$currentPic)
$currentPic = '0';
$item = preg_split('/;/', rtrim($pic_info[$currentPic]), 2);
$last = $number_pics - 1;
$next = $currentPic + 1;
$next_item = @preg_split('/;/', rtrim($pic_info[$next]), 2);
if ($currentPic > 0 ) $back = $currentPic - 1;
else $currentPic = "0";
$blank = empty($item[1])?' ':$item[1];
if ($currentPic > 0 ) $nav=$back;
else $nav=$last;
$nav = "$back_src";
$current_show = "$path?directory=$path_to_images";
$next_link = "$next_src";
$template = str_replace("",$current_show,$template);
$template = str_replace("",$nav,$template);
$template = str_replace("",$next_link,$template);
$template = str_replace("","$next $lang_of $number_pics",$template);
// {{{ ------- EXIF stuff
//get comments from the EXIF data if available...
if(extension_loaded('exif')) {
$curr_image = "$path_to_images/$item[0]";
$all_exif = @exif_read_data($curr_image,0,true);
$exifhtml = @$all_exif['COMPUTED'];
$comment = @$all_exif['COMMENT'][0];
if (!empty($comment)) {
$template = str_replace("",$comment,$template);
}
}
// }}}
$image_title = isset($item[1]) ? $item[1] : '';
$template = str_replace("",$image_title,$template);
// {{{ ------- my_circular($a_images, $currentPic, $thumb_row);
function my_circular($thumbnail_dir, &$template, $a_images, $currentPic, $thumb_row, $path_to_images) {
global $path;
global $auto_url;
// get size of $a_images array...
$number_pics = count($a_images);
// do a little error checking...
if ($currentPic > $number_pics) $currentPic = 0;
if ($currentPic < 0) $currentPic = 0;
if ($thumb_row < 0) $thumb_row = 1;
// check if thumbnail row is greater than number of images...
if ($thumb_row > $number_pics) $thumb_row = $number_pics;
// split the thumbnail number and make it symmetrical...
$half = floor($thumb_row/2);
// show thumbnails
// left hand thumbs
if (($currentPic - $half) < 0) { // near the start...
$underage = ($currentPic-1) - $half;
for ( $x=($number_pics-abs($underage+1)); $x<$number_pics; $x++) {
$next=$x;
$item = preg_split('/;/', rtrim($a_images[$x]), 2);
$out .= "\n
";
}
for ( $x=0; $x<$currentPic ; $x++ ) {
$next=$x;
$item = preg_split('/;/', rtrim($a_images[$x]), 2);
$out .= "\n
";
}
}
else {
for ( $x=$currentPic-$half; $x < $currentPic; $x++ ) {
$next=$x;
$item = preg_split('/;/', rtrim($a_images[$x]), 2);
$out .= "\n
";
}
}
// show current (center) image thumbnail...
$item = preg_split('/;/', rtrim($a_images[$currentPic]), 2);
$out .= "\n
";
// array for right side...
if (($currentPic + $half) >= $number_pics) { // near the end
$overage = (($currentPic + $half) - $number_pics);
for ( $x=$currentPic+1; $x < $number_pics; $x++) {
$next=$x;
$item = preg_split('/;/', rtrim($a_images[$x]), 2);
$out .= "\n
";
}
for ( $x=0; $x<=abs($overage); $x++) {
$next=$x;
$item = preg_split('/;/', rtrim($a_images[$x]), 2);
$out .= "\n
";
}
}
else {
for ( $x=$currentPic+1; $x<=$currentPic+$half; $x++ ) { // right hand thumbs
$next=$x;
$item = preg_split('/;/', rtrim($a_images[$x]), 2);
$out .= "\n
";
}
}
$template = str_replace("",$out,$template);
}
// }}}
// {{{ ------- my_filmstrip($a_images, $currentPic, $thumb_row);
function my_filmstrip($thumbnail_dir, &$template, $a_images, $currentPic, $thumb_row, $path_to_images) {
global $path;
global $auto_url;
// get size of $a_images array...
$number_pics = count($a_images);
// do a little error checking...
if ($currentPic > $number_pics) $currentPic = 0;
if ($currentPic < 0) $currentPic = 0;
if ($thumb_row < 0) $thumb_row = 1;
if ($thumb_row > $number_pics) $thumb_row = $number_pics;
if ($currentPic >= $thumb_row) {
$start = $currentPic - $thumb_row + 1;
}
else {
$start = 0;
}
$out = '';
for ($x = $start; $x < ($start + $thumb_row); $x++ ) {
$item = preg_split('/;/', rtrim($a_images[$x]), 2);
$class = $x == $currentPic ? 'thumbnail_center' : 'thumbnail';
$out .= "\n
";
}
$template = str_replace("",$out,$template);
}
// }}}
// {{{ meta refresh stuff for auto slideshow...
if ($auto == "1") {
$auto_url = "&auto=1";
$meta_refresh = "";
$template = str_replace("",$meta_refresh,$template);
$auto_slideshow = "$lang_stop_slideshow\n";
$template = str_replace("",$auto_slideshow,$template);
}
else {
$template = str_replace("","",$template);
$auto_slideshow = "$lang_start_slideshow\n";
$template = str_replace("",$auto_slideshow,$template);
}
// }}}
$images = "";
$images .= "
";
$template = str_replace("",$images,$template);
$next_image = "$path_to_images/$next_item[0]";
$template = str_replace("",$next_image,$template); // useful for prefetching
if( file_exists( "$path_to_images/$thumbnail_dir" ) ) {
if( $thumbnail_view == "circular" ) {
my_circular($thumbnail_dir, $template, $pic_info, $currentPic, $thumb_row, $path_to_images);
}
else {
my_filmstrip($thumbnail_dir, $template, $pic_info, $currentPic, $thumb_row, $path_to_images);
}
}
$image_filename = "$item[0]";
$template = str_replace("",$image_filename,$template);
// Bob Alberti (albatross@albatross.org) experimental code to link in .mov files
// 2006-07-12
// Strip off the extension
$image_movie=substr($image_filename,0,strpos($image_filename,"."));
// Look for .mov extension of same filename
if( file_exists( "$path_to_images/$image_movie.mov" ) ) {
// Build size-of-movie string, first see if it's "X-many K" in size
$movie_size=sprintf("%.2f", filesize("$path_to_images/$image_movie.mov")/1024);
$movie_unit="K";
// then see if it's "X-many M" in size
if ( $movie_size > 1024 ) {
$movie_size = sprintf("%.2f",$movie_size/1024);
$movie_unit="M";
}
// Link to open new window to show movie (would like to size to fit)
$template = str_replace("",
"View Movie:
$image_movie.mov (size: $movie_size $movie_unit)",$template);
// Add movie size after link
}
else {
// Default for debugging purposes is to show the filename
$template = str_replace("","$image_filename",$template);
}
// End of Bob Alberti experimental section.
// {{{ ----- create the thumbnails and set the permissions...
// the credit for this litte bit of genius goes to Jon from spiicytuna.org who suggested writing the directory
// and permissions via ftp and sent me some code to prove his point :).
if ($create_thumbnails == "true") {
$full_www_path = dirname ($path);
$full_ftp_path = $ftp_web_root."/".$full_www_path;
$thumbnail = $path_to_images."/".$thumbnail_dir."/".$item[0];
if (file_exists($thumbnail)) {
// echo "The thumbnail $thumbnail exists";
} else {
// create the thumbnail directory for writing
create_directory($full_ftp_path, $thumbnail_dir, $path_to_images, $ftp_hostname, $ftp_username, $ftp_password);
// location of the original image
$sourcefile = "$path_to_images/$item[0]";
// output file
$targetfile = $thumbnail;
/* Create a new image object (not neccessarily true colour) */
$source_id = null;
// prep according to image type
if (preg_match('/(jpg|jpeg)$/i',$sourcefile)) $source_id = imageCreatefromjpeg("$sourcefile");
elseif (preg_match('/(png)$/i',$sourcefile)) $source_id = imageCreatefrompng("$sourcefile");
elseif (preg_match('/(gif)$/i',$sourcefile)) $source_id = imageCreatefromgif("$sourcefile");
else die("Unknown image file type");
/* Get the dimensions of the source picture */
$source_width = imagesx($source_id);
$source_height = imagesy($source_id);
// scale or crop during thumbnail resize
$scale = max($thumbnail_max_width/$source_width, $thumbnail_max_height/$source_height);
if($scale < 1) {
$thumbnail_actual_width = floor($scale * $source_width);
$thumbnail_actual_height = floor($scale * $source_height);
$target_id=imagecreatetruecolor($thumbnail_actual_width, $thumbnail_actual_height);
if(function_exists('imagecopyresampled')) {
$target_pic=imagecopyresampled($target_id,$source_id,0,0,0,0,$thumbnail_actual_width,$thumbnail_actual_height,$source_width,$source_height);
}
else {
$target_pic=imagecopyresized($target_id,$source_id,0,0,0,0,$thumbnail_actual_width,$thumbnail_actual_height,$source_width,$source_height);
}
imagedestroy($source_id);
$source_id = $target_id;
}
if($thumbnail_style == "crop") {
$target_id=imagecreatetruecolor($thumbnail_max_width, $thumbnail_max_height);
if(function_exists('imagecopyresampled')) {
$target_pic=imagecopyresampled($target_id,$source_id,0,0,0,0,$thumbnail_max_width,$thumbnail_max_height,$thumbnail_max_width,$thumbnail_max_height);
}
else {
$target_pic=imagecopyresized($target_id,$source_id,0,0,0,0,$thumbnail_max_width,$thumbnail_max_height,$thumbnail_max_width,$thumbnail_max_height);
}
imagedestroy($source_id);
$source_id = $target_id;
}
imagejpeg ($target_id,"$targetfile",$thumbnail_quality);
}
}
// {{{ ----- create_directory($full_ftp_path, $thumbnail_dir, $path_to_images, $ftp_hostname, $ftp_username, $ftp_password)
function create_directory($full_ftp_path, $thumbnail_dir, $path_to_images, $ftp_hostname, $ftp_username, $ftp_password) {
$new_thumbnail_dir = $path_to_images."/".$thumbnail_dir;
//check to see if the directory is already there....
if(file_exists($new_thumbnail_dir)){
// check permissions for writing
if (!is_writable($new_thumbnail_dir)) {
chmod_ftp_directory($full_ftp_path, $thumbnail_dir, $path_to_images, $ftp_hostname, $ftp_username, $ftp_password);
}
}
else{
$conn_id = ftp_connect($ftp_hostname);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_username, $ftp_password);
// try to chmod $path directory
if (!ftp_chdir($conn_id, $full_ftp_path)) die("FTP ERROR: ftp_web_root directory not found.");
if(ftp_mkdir($conn_id, $new_thumbnail_dir)) {
ftp_site($conn_id, "CHMOD 777 $new_thumbnail_dir") or die("FTP ERROR: unable to write to server.");
return true;
} else {
return false;
}
// close the FTP connection
ftp_close($conn_id);
return true;
}
}
// }}}
// {{{ ----- function chmod_ftp_directory($full_ftp_path, $thumbnail_dir, $path_to_images, $ftp_hostname, $ftp_username, $ftp_password)
function chmod_ftp_directory($full_ftp_path, $thumbnail_dir, $path_to_images, $ftp_hostname, $ftp_username, $ftp_password) {
$new_thumbnail_dir = $path_to_images."/".$thumbnail_dir;
$conn_id = ftp_connect($ftp_hostname);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_username, $ftp_password);
// try to chmod $path directory
if (!ftp_chdir($conn_id, $full_ftp_path)) die("FTP ERROR: ftp_web_root directory not found.");
if (!ftp_site($conn_id, "CHMOD 777 $new_thumbnail_dir")) die("FTP ERROR: unable to write to server.");
// close the FTP connection
ftp_close($conn_id);
return true;
}
// }}}
// }}}
echo $template;
?>