PageRenderTime 64ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/app/vendors/phpThumb/demo/phpThumb.demo.gallery.php

http://github.com/Datawalke/Coordino
PHP | 99 lines | 78 code | 9 blank | 12 comment | 16 complexity | a147512ceb08dc4e757acb0fe98e2557 MD5 | raw file
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>phpThumb :: sample photo gallery demo</title>
  5. </head>
  6. <body>
  7. This is a demo of how you can use <a href="http://phpthumb.sourceforge.net">phpThumb()</a> in an image gallery.<br>
  8. <hr>
  9. <?php
  10. //////////////////////////////////////////////////////////////
  11. /// phpThumb() by James Heinrich <info@silisoftware.com> //
  12. // available at http://phpthumb.sourceforge.net ///
  13. //////////////////////////////////////////////////////////////
  14. /// //
  15. // phpThumb.demo.gallery.php //
  16. // James Heinrich <info@silisoftware.com> //
  17. // //
  18. // Demo showing basic usage of phpThumb in a photo gallery //
  19. // //
  20. //////////////////////////////////////////////////////////////
  21. $docroot = realpath((getenv('DOCUMENT_ROOT') && ereg('^'.preg_quote(realpath(getenv('DOCUMENT_ROOT'))), realpath(__FILE__))) ? getenv('DOCUMENT_ROOT') : str_replace(dirname(@$_SERVER['PHP_SELF']), '', str_replace(DIRECTORY_SEPARATOR, '/', dirname(__FILE__))));
  22. $basedir = '/demo/images/'; // webroot-relative path to main images directory (only this and subdirectories of this will be displayed)
  23. $thumb = '/demo/phpThumb.php'; // webroot-relative path to "phpThumb.php"
  24. $popup = '/demo/demo/phpThumb.demo.showpic.php'; // webroot-relative path to "phpThumb.demo.showpic.php" (only used if $use_popup == true)
  25. $thumbnailsize = 120; // size of thumbnails in pixels when browsing gallery
  26. $displaysize = 480; // size of large image display (popup or plain image) after clicking on thumbnail
  27. $use_popup = true; // if true, open large image in self-resizing popup window; if false, display larger image in main window
  28. //////////////////////////////////////////////////////////////
  29. $dirlimit = realpath($docroot.'/'.$basedir);
  30. $captionfile = $docroot.'/'.$basedir.(@$_REQUEST['dir'] ? $_REQUEST['dir'].'/' : '').'captions.txt';
  31. if (file_exists($captionfile)) {
  32. $filecontents = file($captionfile);
  33. foreach ($filecontents as $key => $value) {
  34. @list($photo, $caption) = explode("\t", $value);
  35. $CAPTIONS[$photo] = $caption;
  36. }
  37. }
  38. if (@$_REQUEST['pic']) {
  39. $alt = @$CAPTIONS[$_REQUEST['pic']] ? $CAPTIONS[$_REQUEST['pic']] : $_REQUEST['pic'];
  40. echo '<img src="'.$thumb.'?src='.htmlentities(urlencode($basedir.@$_REQUEST['dir'].'/'.$_REQUEST['pic']).'&w='.$displaysize.'&h='.$displaysize).'" border="0" alt="'.htmlentities($alt).'"><br>';
  41. echo '<div align="center">'.htmlentities(@$CAPTIONS[$_REQUEST['pic']]).'</div>';
  42. } else {
  43. $currentdir = realpath($docroot.'/'.$basedir.@$_REQUEST['dir']);
  44. if (!ereg('^'.preg_quote($dirlimit), $currentdir)) {
  45. echo 'Cannot browse to "'.htmlentities($currentdir).'"<br>';
  46. } elseif ($dh = @opendir($currentdir)) {
  47. $folders = array();
  48. $pictures = array();
  49. while ($file = readdir($dh)) {
  50. if (is_dir($currentdir.'/'.$file) && ($file{0} != '.')) {
  51. $folders[] = $file;
  52. } elseif (eregi('\.(jpe?g|gif|png|bmp|tiff?)$', $file)) {
  53. $pictures[] = $file;
  54. }
  55. }
  56. closedir($dh);
  57. if (ereg('^'.preg_quote($dirlimit), realpath($currentdir.'/..'))) {
  58. echo '<a href="'.$_SERVER['PHP_SELF'].'?dir='.urlencode($_REQUEST['dir'].'/..').'">Parent directory</a><br>';
  59. }
  60. if (!empty($folders)) {
  61. echo '<ul>';
  62. rsort($folders);
  63. foreach ($folders as $dummy => $folder) {
  64. echo '<li><a href="'.$_SERVER['PHP_SELF'].'?dir='.urlencode(@$_REQUEST['dir'].'/'.$folder).'">'.htmlentities($folder).'</a></li>';
  65. }
  66. echo '</ul>';
  67. }
  68. if (!empty($pictures)) {
  69. foreach ($pictures as $file) {
  70. $alt = (@$CAPTIONS[$file] ? $CAPTIONS[$file] : $file);
  71. echo '<table style="float: left;">'.(@$CAPTIONS[$file] ? '<caption align="bottom">'.htmlentities($CAPTIONS[$file]).'</caption>' : '').'<tbody><tr><td>';
  72. if ($use_popup) {
  73. echo '<a title="'.htmlentities($alt).'" href="#" onClick="window.open(\''.$popup.'?src='.htmlentities($basedir.@$_REQUEST['dir'].'/'.$file.'&w='.$displaysize.'&h='.$displaysize.'&title='.urlencode(@$CAPTIONS[$file] ? $CAPTIONS[$file] : $file)).'\', \'showpic\', \'width='.$displaysize.',height='.$displaysize.',resizable=no,status=no,menubar=no,toolbar=no,scrollbars=no\'); return false;">';
  74. } else {
  75. echo '<a title="'.htmlentities($alt).'" href="'.$_SERVER['PHP_SELF'].'?dir='.htmlentities(urlencode(@$_REQUEST['dir']).'&pic='.urlencode($file)).'">';
  76. }
  77. echo '<img src="'.$thumb.'?src='.htmlentities(urlencode($basedir.@$_REQUEST['dir'].'/'.$file).'&zc=1&w='.$thumbnailsize.'&h='.$thumbnailsize).'" border="1" width="'.$thumbnailsize.'" height="'.$thumbnailsize.'" alt="'.htmlentities($alt).'">';
  78. echo '</a></td></tr></tbody></table>';
  79. }
  80. echo '<br clear="all">';
  81. } else {
  82. echo '<i>No pictures in "'.htmlentities(str_replace(realpath($docroot), '', realpath($docroot.'/'.$basedir.@$_REQUEST['dir']))).'"</i>';
  83. }
  84. } else {
  85. echo 'failed to open "'.htmlentities($basedir).'"';
  86. }
  87. }
  88. ?>
  89. </body>
  90. </html>