| [ PHPXref.com ] | [ Generated: Sun Jul 20 19:55:57 2008 ] | [ PHP Slideshow 0.9.9 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 PHPSlideShow v0.9 written by Greg Lawler 4 from http://www.zinkwazi.com/scripts 5 6 v0.9.9 June 2006 - added auto thumbnail creation 7 v0.9.8 June 2006 - fixed the pics.txt special characters bug :) 8 v0.9.7 May 2006 - fixed some Notify errors... 9 v0.9.6 Feb 2006 - Added the <NEXT_IMAGE> tag and javascrip preloading. 10 v0.9.5 Christmas 2005 - added sort by name and filmstrip thumbnail view 11 v0.9.2 Aug 2005 - depricated $GLOBALS[] replaced with _GET 12 v0.9.1 Aug 2005 - bug fixed to allow use on PHP < 4.3 13 v0.9 June 2005 - major re-write, now template based 14 v0.6.2 august 2002 - minor upgrade, added javascript notes 15 v0.6.1 july 2002 - fixed special character bug. 16 v0.6 july 2002 - added lots of formatting options and a security patch 17 v0.5.1 march 2002 - minor bug fixes, reg exp fix... 18 v0.5 march 2002 - osx path fix, page headings for multi dir, cleaner... 19 v0.4 july 10 2001 20 v0.3.5 july 5 2001 21 v0.3.4 april 19 2001 22 v0.3.3 january 9 2001 23 v0.3.1 september 29 2000 - added support for navigation image buttons 24 v0.3 september 12 2000 - added support for image descriptions 25 v0.2 august 28 2000 26 27 PHPSlideshow is relesed under the GPL 28 See the license at http://www.gnu.org/licenses/gpl.txt 29 Feel free to use/modify this little script 30 31 IMPORTANT NOTE.... ;) 32 if you want to send me a token of appreciation, i like coffee so 33 anything from http://www.starbucks.com/card will be gladly accepted ;) 34 my address is: 35 attention: greg lawler 36 801 alston road, santa barbara, ca 93108 usa 37 38 INSTALLATION: See README.txt 39 40 enjoy :) 41 greg 42 */ 43 44 // NOTE: your phpslideshow.php script will work "out of the box" and 45 // all layout and visual effects are controlled by the template.html file. 46 // you can fine tune your slideshow by editing some of these settings. 47 48 // ------------- BEGIN CONFIG SECTION -- 49 // error reporting 50 // error_reporting(E_ALL); 51 52 // number of thumbnails to display f a thumbnail directory exists 53 // (note that this will be rounded down to an odd 54 // number if you use $thumbnail_view = "circular";.) 55 $thumb_row = 20; 56 57 // thumbnail directory name (no slashes needed) 58 $thumbnail_dir = "thumbnails"; 59 60 // do you want to automatically generate thumbnails? 61 // if this is set to true, you will need to provide your web site 62 // ftp login info and web root directory below. 63 // $create_thumbnails = "true"; 64 $create_thumbnails = "false"; 65 66 // ftp user information for automatic thumbnails 67 $ftp_username = "your_username_here"; 68 $ftp_password = "your_password_here"; 69 70 // ftp web root directory (httpdocs, wwwroot, webroot etc.) 71 // this is the directory that your website is located in on your FTP login. 72 // (no slashes needed) 73 $ftp_web_root = "httpdocs"; 74 75 // thumbnail size 76 $thumbnail_max_width = 30; 77 $thumbnail_max_height = 30; 78 79 // $thumbnail_style: "scale" will resize and maintain proportions to the original image 80 // "crop" will resize to exactly the thumbnail size you specify 81 $thumbnail_style = "crop"; 82 83 // output quality: 60 = poor quality tiny file, 100 = best quality larger file... 84 $thumbnail_quality = 80; 85 86 // this should work as localhost but if not, insert your ftp server's name 87 $ftp_hostname = "localhost"; 88 89 // sort/display images with newest or oldest on top or alphabetically by name. 90 // this has no effect when pics.txt is used. 91 // $sort_images = "oldest"; 92 //$sort_images = "newest"; 93 $sort_images = "name"; 94 95 // thumbnail view: can be "filmstrip" or "circular" 96 //$thumbnail_view = "circular"; 97 $thumbnail_view = "filmstrip"; 98 99 // name of file containing optional page headings 100 $heading_info_file = "heading.txt"; 101 102 // file containing optional image descriptions 103 $pic_info_file="pics.txt"; 104 105 // language text for various areas... 106 $lang_back = "back"; 107 $lang_next = "next"; 108 $lang_of = "of"; 109 $lang_stop_slideshow = "stop slideshow"; 110 $lang_start_slideshow = "start slideshow"; 111 $lang_img_hover = "click for next image..."; 112 $lang_img_alt = "slideshow image"; 113 114 // automated slideshow options 115 // remember that you need <META_REFRESH> in the <head> section of your html 116 // AND the <AUTO_SLIDESHOW_LINK> tag in your page. 117 // $delay is the number of seconds to pause between slides... 118 $delay = 2; 119 // set to true to display navigation icons instead of text... 120 $show_navigation_buttons = "false"; 121 $back_button = "/back.gif"; 122 $next_button = "/next.gif"; 123 124 // ------------- END CONFIG SECTION -- 125 126 ################################################################################ 127 // begin code :: don't make changes below this line... 128 129 // initialize some stuff: 130 $auto_url = ""; 131 $thumbnail_actual_width = ""; 132 $thumbnail_actual_height = ""; 133 134 // grab the variables we want set for newer php version compatability 135 $phpslideshow = isset($_GET['phpslideshow']) ? $_GET['phpslideshow'] : ''; 136 $path_to_images = isset($_GET['directory']) ? $_GET['directory'] : ''; 137 $currentPic = isset($_GET['currentPic']) ? $_GET['currentPic'] : ''; 138 $browse = isset($_GET['browse']) ? $_GET['browse'] : ''; 139 $auto = isset($_GET['auto']) ? $_GET['auto'] : ''; 140 141 // check for platform dependent path info... (for windows and mac OSX) 142 $path = empty($HTTP_SERVER_VARS['PATH_INFO'])? 143 $HTTP_SERVER_VARS['PHP_SELF']:$HTTP_SERVER_VARS['PATH_INFO']; 144 145 // this only works on php > 4.3, replacing with file() 146 //if( file_exists( "template.html" ) ) $template = file_get_contents("template.html"); 147 if( file_exists( "template.html" ) ) $template = implode("", file('template.html')); 148 else { 149 echo "<b>ERROR:</b> Can't find the template.html file!"; 150 exit; 151 } 152 153 // check that the user did not change the path... 154 if (preg_match(':(\.\.|^/|\:):', $path_to_images) || strpos($path_to_images, $thumbnail_dir) !== false) { 155 echo "<strong>ERROR:</strong> Your request contains an invalid path.<br /> 156 Can not locate <strong>$path_to_images</strong> in this directory.<br />"; 157 exit; 158 } 159 160 if (empty($path_to_images)) $path_to_images = "."; 161 // if there is no $heading_info_file (see format above) set page heading here 162 if ( !file_exists("$path_to_images/$heading_info_file")) { 163 $header = "PHPSlideshow by greg lawler at zinkwazi.com"; 164 $title = "<a href=\"http://www.zinkwazi.com/\">PHPSlideshow by greg lawler at zinkwazi.com</a>"; 165 } 166 else { 167 $heading_info = file("$path_to_images/$heading_info_file"); 168 $header = "$heading_info[0]"; 169 $title = $header; 170 } 171 $template = str_replace("<SHOW_TITLE>",$title,$template); 172 $template = str_replace("<WINDOW_TITLE>",$header,$template); 173 174 // image / text buttons 175 if ($show_navigation_buttons == "true") { 176 $back_src = "<img src='$back_button' alt='back' class='nav_buttons' class='nav_buttons'>"; 177 $next_src = "<img src='$next_button' alt='next' class='nav_buttons' class='nav_buttons'>"; 178 } 179 else { 180 $back_src = "$lang_back"; 181 $next_src = "$lang_next"; 182 } 183 184 if ( !file_exists("$path_to_images/$pic_info_file")) { 185 $dh = opendir( "$path_to_images" ); 186 $pic_info = array(); 187 $time_info = array(); 188 while( $file = readdir( $dh ) ) { 189 // look for these file types.... 190 if (preg_match('/(jpg|jpeg|gif|png)$/i',$file)) { 191 $time_info[] = filemtime("$path_to_images/$file"); 192 $pic_info[] = $file; 193 } 194 } 195 if ($sort_images == 'name') { 196 natcasesort($pic_info); 197 $pic_info = array_reverse(array_reverse($pic_info)); //resetting array keys 198 } 199 else { 200 $sortorder = $sort_images == "oldest" ? SORT_ASC : SORT_DESC; 201 array_multisort($time_info, $sortorder, $pic_info, SORT_ASC, $time_info); 202 } 203 } 204 else { 205 $pic_info=file("$path_to_images/$pic_info_file"); 206 } 207 208 // begin messing with the array 209 $number_pics = count ($pic_info); 210 if (($currentPic > $number_pics)||($currentPic == $number_pics)||!$currentPic) 211 $currentPic = '0'; 212 $item = preg_split('/;/', rtrim($pic_info[$currentPic]), 2); 213 $last = $number_pics - 1; 214 $next = $currentPic + 1; 215 $next_item = @preg_split('/;/', rtrim($pic_info[$next]), 2); 216 if ($currentPic > 0 ) $back = $currentPic - 1; 217 else $currentPic = "0"; 218 219 220 $blank = empty($item[1])?' ':$item[1]; 221 222 if ($currentPic > 0 ) $nav=$back; 223 else $nav=$last; 224 $nav = "<a href='$path?directory=$path_to_images¤tPic=$nav'>$back_src</a>"; 225 $current_show = "$path?directory=$path_to_images"; 226 $next_link = "<a href='$path?directory=$path_to_images¤tPic=$next'>$next_src</a>"; 227 $template = str_replace("<CURRENT_SHOW>",$current_show,$template); 228 $template = str_replace("<BACK>",$nav,$template); 229 $template = str_replace("<NEXT>",$next_link,$template); 230 $template = str_replace("<POSITION>","$next $lang_of $number_pics",$template); 231 232 233 // {{{ ------- EXIF stuff 234 235 //get comments from the EXIF data if available... 236 if(extension_loaded('exif')) { 237 $curr_image = "$path_to_images/$item[0]"; 238 $all_exif = @exif_read_data($curr_image,0,true); 239 $exifhtml = @$all_exif['COMPUTED']; 240 $comment = @$all_exif['COMMENT'][0]; 241 if (!empty($comment)) { 242 $template = str_replace("<EXIF_COMMENT>",$comment,$template); 243 } 244 } 245 // }}} 246 247 $image_title = isset($item[1]) ? $item[1] : ''; 248 $template = str_replace("<IMAGE_TITLE>",$image_title,$template); 249 250 // {{{ ------- my_circular($a_images, $currentPic, $thumb_row); 251 252 function my_circular($thumbnail_dir, &$template, $a_images, $currentPic, $thumb_row, $path_to_images) { 253 global $path; 254 global $auto_url; 255 256 // get size of $a_images array... 257 $number_pics = count($a_images); 258 // do a little error checking... 259 if ($currentPic > $number_pics) $currentPic = 0; 260 if ($currentPic < 0) $currentPic = 0; 261 if ($thumb_row < 0) $thumb_row = 1; 262 263 // check if thumbnail row is greater than number of images... 264 if ($thumb_row > $number_pics) $thumb_row = $number_pics; 265 266 // split the thumbnail number and make it symmetrical... 267 $half = floor($thumb_row/2); 268 269 // show thumbnails 270 // left hand thumbs 271 if (($currentPic - $half) < 0) { // near the start... 272 $underage = ($currentPic-1) - $half; 273 for ( $x=($number_pics-abs($underage+1)); $x<$number_pics; $x++) { 274 $next=$x; 275 $item = preg_split('/;/', rtrim($a_images[$x]), 2); 276 $out .= "\n<a href='$path?directory=$path_to_images$auto_url¤tPic=$next' class='thumbnail'><img src='$path_to_images/$thumbnail_dir/".$item[0]."' class='thumbnail'></a>"; 277 } 278 for ( $x=0; $x<$currentPic ; $x++ ) { 279 $next=$x; 280 $item = preg_split('/;/', rtrim($a_images[$x]), 2); 281 $out .= "\n<a href='$path?directory=$path_to_images$auto_url¤tPic=$next' class='thumbnail'><img src='$path_to_images/$thumbnail_dir/".$item[0]."' class='thumbnail'></a>"; 282 } 283 } 284 else { 285 for ( $x=$currentPic-$half; $x < $currentPic; $x++ ) { 286 $next=$x; 287 $item = preg_split('/;/', rtrim($a_images[$x]), 2); 288 $out .= "\n<a href='$path?directory=$path_to_images$auto_url¤tPic=$next' class='thumbnail'><img src='$path_to_images/$thumbnail_dir/".$item[0]."' class='thumbnail'></a>"; 289 } 290 } 291 292 // show current (center) image thumbnail... 293 $item = preg_split('/;/', rtrim($a_images[$currentPic]), 2); 294 $out .= "\n<img src='$path_to_images/$thumbnail_dir/".rtrim($item[0])."' class='thumbnail_center'>"; 295 296 // array for right side... 297 if (($currentPic + $half) >= $number_pics) { // near the end 298 $overage = (($currentPic + $half) - $number_pics); 299 for ( $x=$currentPic+1; $x < $number_pics; $x++) { 300 $next=$x; 301 $item = preg_split('/;/', rtrim($a_images[$x]), 2); 302 $out .= "\n<a href='$path?directory=$path_to_images$auto_url¤tPic=$next' class='thumbnail'><img src='$path_to_images/$thumbnail_dir/".$item[0]."' class='thumbnail'></a>"; 303 } 304 for ( $x=0; $x<=abs($overage); $x++) { 305 $next=$x; 306 $item = preg_split('/;/', rtrim($a_images[$x]), 2); 307 $out .= "\n<a href='$path?directory=$path_to_images$auto_url¤tPic=$next' class='thumbnail'><img src='$path_to_images/$thumbnail_dir/".$item[0]."' class='thumbnail'></a>"; 308 } 309 } 310 else { 311 for ( $x=$currentPic+1; $x<=$currentPic+$half; $x++ ) { // right hand thumbs 312 $next=$x; 313 $item = preg_split('/;/', rtrim($a_images[$x]), 2); 314 $out .= "\n<a href='$path?directory=$path_to_images$auto_url¤tPic=$next' class='thumbnail'><img src='$path_to_images/$thumbnail_dir/".$item[0]."' class='thumbnail'></a>"; 315 } 316 } 317 $template = str_replace("<THUMBNAIL_ROW>",$out,$template); 318 } 319 // }}} 320 // {{{ ------- my_filmstrip($a_images, $currentPic, $thumb_row); 321 322 function my_filmstrip($thumbnail_dir, &$template, $a_images, $currentPic, $thumb_row, $path_to_images) { 323 global $path; 324 global $auto_url; 325 326 // get size of $a_images array... 327 $number_pics = count($a_images); 328 // do a little error checking... 329 if ($currentPic > $number_pics) $currentPic = 0; 330 if ($currentPic < 0) $currentPic = 0; 331 if ($thumb_row < 0) $thumb_row = 1; 332 if ($thumb_row > $number_pics) $thumb_row = $number_pics; 333 334 if ($currentPic >= $thumb_row) { 335 $start = $currentPic - $thumb_row + 1; 336 } 337 else { 338 $start = 0; 339 } 340 341 $out = ''; 342 for ($x = $start; $x < ($start + $thumb_row); $x++ ) { 343 $item = preg_split('/;/', rtrim($a_images[$x]), 2); 344 $class = $x == $currentPic ? 'thumbnail_center' : 'thumbnail'; 345 $out .= "\n<a href='$path?directory=$path_to_images$auto_url¤tPic=$x' class='thumbnail'><img src='$path_to_images/$thumbnail_dir/".$item[0]."' class='$class'></a>"; 346 } 347 348 $template = str_replace("<THUMBNAIL_ROW>",$out,$template); 349 } 350 // }}} 351 // {{{ meta refresh stuff for auto slideshow... 352 if ($auto == "1") { 353 $auto_url = "&auto=1"; 354 $meta_refresh = "<meta http-equiv='refresh' content='".$delay; 355 $meta_refresh .= ";url=".$path."?directory=".$path_to_images.$auto_url."¤tPic=".$next."'>"; 356 $template = str_replace("<META_REFRESH>",$meta_refresh,$template); 357 $auto_slideshow = "<a href='$path?directory=$path_to_images¤tPic=$currentPic'>$lang_stop_slideshow</a>\n"; 358 $template = str_replace("<AUTO_SLIDESHOW_LINK>",$auto_slideshow,$template); 359 } 360 else { 361 $template = str_replace("<META_REFRESH>","",$template); 362 $auto_slideshow = "<a href='$path?directory=$path_to_images&auto=1¤tPic=$next'>$lang_start_slideshow</a>\n"; 363 $template = str_replace("<AUTO_SLIDESHOW_LINK>",$auto_slideshow,$template); 364 } 365 // }}} 366 367 $images = "<a href='$path?directory=$path_to_images$auto_url¤tPic=$next'>"; 368 $images .= "<img src='$path_to_images/$item[0]' class='image' alt='$lang_img_alt' title='$lang_img_hover'></a>"; 369 $template = str_replace("<IMAGE>",$images,$template); 370 $next_image = "$path_to_images/$next_item[0]"; 371 $template = str_replace("<NEXT_IMAGE>",$next_image,$template); // useful for prefetching 372 373 if( file_exists( "$path_to_images/$thumbnail_dir" ) ) { 374 if( $thumbnail_view == "circular" ) { 375 my_circular($thumbnail_dir, $template, $pic_info, $currentPic, $thumb_row, $path_to_images); 376 } 377 else { 378 my_filmstrip($thumbnail_dir, $template, $pic_info, $currentPic, $thumb_row, $path_to_images); 379 } 380 } 381 382 $image_filename = "$item[0]"; 383 $template = str_replace("<IMAGE_FILENAME>",$image_filename,$template); 384 385 // {{{ ----- create the thumbnails and set the permissions... 386 // the credit for this litte bit of genius goes to Jon from spiicytuna.org who suggested writing the directory 387 // and permissions via ftp and sent me some code to prove his point :). 388 if ($create_thumbnails == "true") { 389 $full_www_path = dirname ($path); 390 $full_ftp_path = $ftp_web_root."/".$full_www_path; 391 $thumbnail = $path_to_images."/".$thumbnail_dir."/".$item[0]; 392 if (file_exists($thumbnail)) { 393 // echo "The thumbnail $thumbnail exists"; 394 } else { 395 // create the thumbnail directory for writing 396 create_directory($full_ftp_path, $thumbnail_dir, $path_to_images, $ftp_hostname, $ftp_username, $ftp_password); 397 // location of the original image 398 $sourcefile = "$path_to_images/$item[0]"; 399 // output file 400 $targetfile = $thumbnail; 401 /* Create a new image object (not neccessarily true colour) */ 402 $source_id = null; 403 // prep according to image type 404 if (preg_match('/(jpg|jpeg)$/i',$sourcefile)) $source_id = imageCreatefromjpeg("$sourcefile"); 405 elseif (preg_match('/(png)$/i',$sourcefile)) $source_id = imageCreatefrompng("$sourcefile"); 406 elseif (preg_match('/(gif)$/i',$sourcefile)) $source_id = imageCreatefromgif("$sourcefile"); 407 else die("Unknown image file type"); 408 /* Get the dimensions of the source picture */ 409 $source_width = imagesx($source_id); 410 $source_height = imagesy($source_id); 411 // scale or crop during thumbnail resize 412 $scale = max($thumbnail_max_width/$source_width, $thumbnail_max_height/$source_height); 413 if($scale < 1) { 414 $thumbnail_actual_width = floor($scale * $source_width); 415 $thumbnail_actual_height = floor($scale * $source_height); 416 $target_id=imagecreatetruecolor($thumbnail_actual_width, $thumbnail_actual_height); 417 if(function_exists('imagecopyresampled')) { 418 $target_pic=imagecopyresampled($target_id,$source_id,0,0,0,0,$thumbnail_actual_width,$thumbnail_actual_height,$source_width,$source_height); 419 } 420 else { 421 $target_pic=imagecopyresized($target_id,$source_id,0,0,0,0,$thumbnail_actual_width,$thumbnail_actual_height,$source_width,$source_height); 422 } 423 imagedestroy($source_id); 424 $source_id = $target_id; 425 } 426 if($thumbnail_style == "crop") { 427 $target_id=imagecreatetruecolor($thumbnail_max_width, $thumbnail_max_height); 428 if(function_exists('imagecopyresampled')) { 429 $target_pic=imagecopyresampled($target_id,$source_id,0,0,0,0,$thumbnail_max_width,$thumbnail_max_height,$thumbnail_max_width,$thumbnail_max_height); 430 } 431 else { 432 $target_pic=imagecopyresized($target_id,$source_id,0,0,0,0,$thumbnail_max_width,$thumbnail_max_height,$thumbnail_max_width,$thumbnail_max_height); 433 } 434 imagedestroy($source_id); 435 $source_id = $target_id; 436 } 437 imagejpeg ($target_id,"$targetfile",$thumbnail_quality); 438 } 439 } 440 // {{{ ----- create_directory($full_ftp_path, $thumbnail_dir, $path_to_images, $ftp_hostname, $ftp_username, $ftp_password) 441 function create_directory($full_ftp_path, $thumbnail_dir, $path_to_images, $ftp_hostname, $ftp_username, $ftp_password) { 442 $new_thumbnail_dir = $path_to_images."/".$thumbnail_dir; 443 //check to see if the directory is already there.... 444 if(file_exists($new_thumbnail_dir)){ 445 // check permissions for writing 446 if (!is_writable($new_thumbnail_dir)) { 447 chmod_ftp_directory($full_ftp_path, $thumbnail_dir, $path_to_images, $ftp_hostname, $ftp_username, $ftp_password); 448 } 449 } 450 else{ 451 $conn_id = ftp_connect($ftp_hostname); 452 // login with username and password 453 $login_result = ftp_login($conn_id, $ftp_username, $ftp_password); 454 // try to chmod $path directory 455 if (!ftp_chdir($conn_id, $full_ftp_path)) die("FTP ERROR: ftp_web_root directory not found."); 456 if(ftp_mkdir($conn_id, $new_thumbnail_dir)) { 457 ftp_site($conn_id, "CHMOD 777 $new_thumbnail_dir") or die("FTP ERROR: unable to write to server."); 458 return true; 459 } else { 460 return false; 461 } 462 // close the FTP connection 463 ftp_close($conn_id); 464 return true; 465 } 466 } 467 // }}} 468 // {{{ ----- function chmod_ftp_directory($full_ftp_path, $thumbnail_dir, $path_to_images, $ftp_hostname, $ftp_username, $ftp_password) 469 function chmod_ftp_directory($full_ftp_path, $thumbnail_dir, $path_to_images, $ftp_hostname, $ftp_username, $ftp_password) { 470 $new_thumbnail_dir = $path_to_images."/".$thumbnail_dir; 471 $conn_id = ftp_connect($ftp_hostname); 472 // login with username and password 473 $login_result = ftp_login($conn_id, $ftp_username, $ftp_password); 474 // try to chmod $path directory 475 if (!ftp_chdir($conn_id, $full_ftp_path)) die("FTP ERROR: ftp_web_root directory not found."); 476 if (!ftp_site($conn_id, "CHMOD 777 $new_thumbnail_dir")) die("FTP ERROR: unable to write to server."); 477 // close the FTP connection 478 ftp_close($conn_id); 479 return true; 480 } 481 // }}} 482 // }}} 483 echo $template; 484 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |