diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..7d9c8eb --- /dev/null +++ b/.htaccess @@ -0,0 +1 @@ +Options -Indexes \ No newline at end of file diff --git a/config.php b/config.php index c5eb784..8024193 100644 --- a/config.php +++ b/config.php @@ -16,12 +16,12 @@ Please enjoy this free script! */ // EDIT SETTINGS BELOW TO CUSTOMIZE YOUR GALLERY -$thumbs_pr_page = "28"; //Number of thumbnails on a single page -$gallery_width = "900px"; //Gallery width. Eg: "500px" or "70%" +$thumbs_pr_page = "39"; //Number of thumbnails on a single page +$gallery_width = "80%"; //Gallery width. Eg: "500px" or "70%" $backgroundcolor = "white"; //This provides a quick way to change your gallerys background to suit your website. Use either main colors like "black", "white", "yellow" etc. Or HEX colors, eg. "#AAAAAA" -$templatefile = "mano"; //Template filename (must be placed in 'templates' folder) -$title = "MiniGal Nano Testsite"; // Text to be displayed in browser titlebar -$author = "Rybber"; +$templatefile = "darkgold2"; //Template filename (must be placed in 'templates' folder) +$title = "MiniGal Nano test gallery"; // Text to be displayed in browser titlebar +$author = "John Doe"; $folder_color = "black"; // Color of folder icons: blue / black / vista / purple / green / grey $sorting_folders = "name"; // Sort folders by: [name][date] $sorting_files = "name"; // Sort files by: [name][date][size] @@ -30,14 +30,14 @@ $sortdir_files = "ASC"; // Sort direction of files: [ASC][DESC] //LANGUAGE STRINGS $label_home = "Home"; //Name of home link in breadcrumb navigation -$label_new = "New"; //Text to display for new images. Use with $display_new variable +$label_new = "New"; //Text to display for new images. Use with $display_new variable $label_page = "Page"; //Text used for page navigation -$label_all = "All"; //Text used for link to display all images in one page +$label_all = "All"; //Text used for link to display all images in one page $label_noimages = "No images"; //Empty folder text $label_loading = "Loading..."; //Thumbnail loading text //ADVANCED SETTINGS -$thumb_size = 120; //Thumbnail height/width (square thumbs). Changing this will most likely require manual altering of the template file to make it look properly! -$label_max_length = 30; //Maximum chars of a folder name that will be displayed on the folder thumbnail -$display_exif = 1; +$thumb_size = 320; //Thumbnail height/width (square thumbs). Changing this will most likely require manual altering of the template file to make it look properly! +$label_max_length = 40; //Maximum chars of a folder name that will be displayed on the folder thumbnail +$display_exif = 0; ?> \ No newline at end of file diff --git a/config_default.php b/config_default.php index 3a5e016..92bb23d 100644 --- a/config_default.php +++ b/config_default.php @@ -16,10 +16,10 @@ Please enjoy this free script! */ // EDIT SETTINGS BELOW TO CUSTOMIZE YOUR GALLERY -$thumbs_pr_page = "18"; //Number of thumbnails on a single page +$thumbs_pr_page = "21"; //Number of thumbnails on a single page $gallery_width = "900px"; //Gallery width. Eg: "500px" or "70%" $backgroundcolor = "white"; //This provides a quick way to change your gallerys background to suit your website. Use either main colors like "black", "white", "yellow" etc. Or HEX colors, eg. "#AAAAAA" -$templatefile = "mano"; //Template filename (must be placed in 'templates' folder) +$templatefile = "darkgold2"; //Template filename (must be placed in 'templates' folder) $title = "My Gallery"; // Text to be displayed in browser titlebar $author = "Me :)"; $folder_color = "black"; // Color of folder icons: blue / black / vista / purple / green / grey diff --git a/createthumb.php b/createthumb.php index c6b7355..bcf09be 100644 --- a/createthumb.php +++ b/createthumb.php @@ -14,16 +14,62 @@ Community: www.minigal.dk/forum Please enjoy this free script! +Version 0.3.5 modified by Sebastien SAUVAGE (sebsauvage.net): + - Added thumbnail cache (reduces server CPU load, server bandwith and speeds up client page display). + - Thumbnails are now always in JPEG even if the source image is PNG or GIF. USAGE EXAMPLE: File: createthumb.php Example: */ // error_reporting(E_ALL); - + error_reporting(0); +/* if (preg_match("/.jpg$|.jpeg$/i", $_GET['filename'])) header('Content-type: image/jpeg'); if (preg_match("/.gif$/i", $_GET['filename'])) header('Content-type: image/gif'); if (preg_match("/.png$/i", $_GET['filename'])) header('Content-type: image/png'); +*/ + +function str_split_php4( $text, $split = 1 ) { + // place each character of the string into and array + $array = array(); + for ( $i=0; $i < strlen( $text ); ){ + $key = NULL; + for ( $j = 0; $j < $split; $j++, $i++ ) { + $key .= $text[$i]; + } + array_push( $array, $key ); + } + return $array; +} + +function sanitize($name) +{ +// Sanitize image filename (taken from http://iamcam.wordpress.com/2007/03/20/clean-file-names-using-php-preg_replace/ ) +$fname=$name; +$replace="_"; +$pattern="/([[:alnum:]_\.-]*)/"; +$fname=str_replace(str_split_php4(preg_replace($pattern,$replace,$fname)),$replace,$fname); +return $fname; +} + +// Make sure the "thumbs" directory exists. +if (!is_dir('thumbs')) { mkdir('thumbs',0700); } + +// Thumbnail file name and path. +// (We always put thumbnails in jpg for simplification) +$thumbname = 'thumbs/'.sanitize($_GET['filename']).'.jpg'; + +if (file_exists($thumbname)) // If thumbnail exists, serve it. +{ + $fd = fopen($thumbname, "r"); + $cacheContent = fread($fd,filesize ($thumbname)); + fclose($fd); + header('Content-type: image/jpeg'); + echo($cacheContent); +} +else // otherwise, generate thumbnail, send it and save it to file. +{ // Display error image if file isn't found if (!is_file($_GET['filename'])) { @@ -82,11 +128,19 @@ if (preg_match("/.png$/i", $_GET['filename'])) header('Content-type: image/png') imagecopyresampled($target,$source,0,0,$xoord,$yoord,$_GET['size'],$_GET['size'],$width,$height); imagedestroy($source); - if (preg_match("/.jpg$/i", $_GET['filename'])) ImageJPEG($target,null,90); - if (preg_match("/.gif$/i", $_GET['filename'])) ImageGIF($target,null,90); - if (preg_match("/.png$/i", $_GET['filename'])) ImageJPEG($target,null,90); // Using ImageJPEG on purpose + //if (preg_match("/.jpg$/i", $_GET['filename'])) ImageJPEG($target,null,90); + //if (preg_match("/.gif$/i", $_GET['filename'])) ImageGIF($target,null,90); + //if (preg_match("/.png$/i", $_GET['filename'])) ImageJPEG($target,null,90); // Using ImageJPEG on purpose + ob_start(); // Start output buffering. + header('Content-type: image/jpeg'); // We always render the thumbnail in JPEG even if the source is GIF or PNG. + ImageJPEG($target,null,80); imagedestroy($target); + + $cachedImage = ob_get_contents(); // Get the buffer content. + ob_end_flush();// End buffering + $fd = fopen($thumbname, "w"); // Save buffer to disk + if ($fd) { fwrite($fd,$cachedImage); fclose($fd); } - +} ?> \ No newline at end of file diff --git a/index.php b/index.php index fdf4aa5..23e47a5 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,5 @@ - $file, "date" => filemtime($currentdir . "/" . $file . "/folder.jpg"), - "html" => "
  • " . padstring($file, $label_max_length) . "$label_loading
  • "); + "html" => "
  • " . padstring($file, $label_max_length) . "$label_loading
  • "); } else { // Set thumbnail to first image found (if any): @@ -171,19 +184,20 @@ $dirs = array(); $dirs[] = array( "name" => $file, "date" => filemtime($currentdir . "/" . $file), - "html" => "
  • " . padstring($file, $label_max_length) . "$label_loading
  • "); + "html" => "
  • " . padstring($file, $label_max_length) . "$label_loading
  • "); } else { // If no folder.jpg or image is found, then display default icon: $dirs[] = array( "name" => $file, "date" => filemtime($currentdir . "/" . $file), - "html" => "
  • " . padstring($file) . "$label_loading
  • "); + "html" => "
  • " . padstring($file) . "$label_loading
  • "); } } } } // 2. LOAD CAPTIONS +$img_captions['']=''; if (file_exists($currentdir ."/captions.txt")) { $file_handle = fopen($currentdir ."/captions.txt", "rb"); @@ -209,12 +223,20 @@ if (file_exists($currentdir ."/captions.txt")) //Read EXIF if ($display_exif == 1) $img_captions[$file] .= readEXIF($currentdir . "/" . $file); + // Read the optionnal image title and caption in html file (image.jpg --> image.jpg.html) + // Format: title::caption + // Example: My cat::My cat like to roll on the floor. + // If file is not provided, image filename will be used instead. checkpermissions($currentdir . "/" . $file); + + $img_captions[$file] = $file; + if (is_file($currentdir.'/'.$file.'.html')) { $img_captions[$file] = $file.'::'.htmlspecialchars(file_get_contents($currentdir.'/'.$file.'.html'),ENT_QUOTES); } + $files[] = array ( "name" => $file, "date" => filemtime($currentdir . "/" . $file), "size" => filesize($currentdir . "/" . $file), - "html" => "
  • $label_loading
  • "); + "html" => "
  • $label_loading
  • "); } // Other filetypes $extension = ""; @@ -238,7 +260,7 @@ if (file_exists($currentdir ."/captions.txt")) } } closedir($handle); - } else die("ERROR: Could not open $currentdir for reading!"); + } else die("ERROR: Could not open ".htmlspecialchars(stripslashes($currentdir))." for reading!"); //----------------------- // SORT FILES AND FOLDERS @@ -270,6 +292,7 @@ if (sizeof($files) > 0) //----------------------- // OFFSET DETERMINATION //----------------------- + if (!isset($_GET["page"])) $_GET["page"] = 1; $offset_start = ($_GET["page"] * $thumbs_pr_page) - $thumbs_pr_page; if (!isset($_GET["page"])) $offset_start = 0; $offset_end = $offset_start + $thumbs_pr_page; @@ -284,7 +307,6 @@ if (sizeof($files) > 0) //----------------------- // PAGE NAVIGATION //----------------------- -if (!isset($_GET["page"])) $_GET["page"] = 1; if (sizeof($dirs) + sizeof($files) > $thumbs_pr_page) { $page_navigation .= "$label_page "; @@ -293,18 +315,18 @@ if (sizeof($dirs) + sizeof($files) > $thumbs_pr_page) if ($_GET["page"] == $i) $page_navigation .= "$i"; else - $page_navigation .= "" . $i . ""; + $page_navigation .= "" . $i . ""; if ($i != ceil((sizeof($files) + sizeof($dirs)) / $thumbs_pr_page)) $page_navigation .= " | "; } //Insert link to view all images if ($_GET["page"] == "all") $page_navigation .= " | $label_all"; - else $page_navigation .= " | $label_all"; + else $page_navigation .= " | $label_all"; } //----------------------- // BREADCRUMB NAVIGATION //----------------------- -if ($_GET['dir'] != "") +if ($requestedDir != "") { $breadcrumb_navigation .= "" . $label_home . " > "; $navitems = explode("/", $_REQUEST['dir']); @@ -357,6 +379,7 @@ for ($i = $offset_start - sizeof($dirs); $i < $offset_end && $offset_current < $ } //Include hidden links for all images AFTER current page so lightbox is able to browse images on different pages +if ($i<0) $i=1; for ($y = $i; $y < sizeof($files); $y++) { $page_navigation .= ""; @@ -369,12 +392,20 @@ if ($messages != "") { $messages = "
    " . $messages . "
    "; } +// Read folder comment. +$comment_filepath = $currentdir . $file . "/comment.html"; +if (file_exists($comment_filepath)) +{ + $fd = fopen($comment_filepath, "r"); + $comment = utf8_encode(fread($fd,filesize ($comment_filepath))); // utf8_encode to convert from iso-8859 to UTF-8 + fclose($fd); +} //PROCESS TEMPLATE FILE if(GALLERY_ROOT != "") $templatefile = GALLERY_ROOT . "templates/integrate.html"; else $templatefile = "templates/" . $templatefile . ".html"; if(!$fd = fopen($templatefile, "r")) { - echo "Template $templatefile not found!"; + echo "Template ".htmlspecialchars(stripslashes($templatefile))." not found!"; exit(); } else @@ -390,6 +421,7 @@ $messages = "
    " . $messages . " /", "$thumbnails", $template); $template = preg_replace("/<% breadcrumb_navigation %>/", "$breadcrumb_navigation", $template); $template = preg_replace("/<% page_navigation %>/", "$page_navigation", $template); + $template = preg_replace("/<% folder_comment %>/", "$comment", $template); $template = preg_replace("/<% bgcolor %>/", "$backgroundcolor", $template); $template = preg_replace("/<% gallery_width %>/", "$gallery_width", $template); $template = preg_replace("/<% version %>/", "$version", $template); diff --git a/templates/darkgold2.html b/templates/darkgold2.html new file mode 100644 index 0000000..f2dbb73 --- /dev/null +++ b/templates/darkgold2.html @@ -0,0 +1,202 @@ + + + + +<% title %> + + + + + + + +

    <% title %>

    +<% messages %> +

    +<% breadcrumb_navigation %> +

    +
    +
    <% folder_comment %>
    + +
    +
    + +
    + +
    +

    + + diff --git a/templates/exhibition.html b/templates/exhibition.html index f3ddeae..a3e8da5 100644 --- a/templates/exhibition.html +++ b/templates/exhibition.html @@ -98,6 +98,10 @@ a { vertical-align: middle; } +#folder_comment +{ + margin-bottom:10px; +} /* ---------- gallery styles start here ----------------------- */ .gallery { list-style: none; @@ -167,6 +171,7 @@ a { <% breadcrumb_navigation %>

    +
    <% folder_comment %>
    @@ -175,7 +180,7 @@ a {
    - +

    diff --git a/templates/integrate.html b/templates/integrate.html index 85f1433..6e997c9 100644 --- a/templates/integrate.html +++ b/templates/integrate.html @@ -70,6 +70,12 @@ a { display:inline; } +#folder_comment +{ + margin-top:10px; + margin-left:10px; +} + /* ---------- gallery styles start here ----------------------- */ .gallery { list-style: none; @@ -135,6 +141,7 @@ a {

    by: <% author %>

    <% breadcrumb_navigation %>
    +
    <% folder_comment %>
    @@ -143,7 +150,7 @@ a {
    - +

    diff --git a/templates/mano.html b/templates/mano.html index 15a26b5..163797e 100644 --- a/templates/mano.html +++ b/templates/mano.html @@ -96,6 +96,12 @@ a { vertical-align: middle; } +#folder_comment +{ + margin-top:10px; + margin-left:10px; +} + /* ---------- gallery styles start here ----------------------- */ .gallery { list-style: none; @@ -152,6 +158,7 @@ a {

    by: <% author %>

    <% breadcrumb_navigation %>
    +
    <% folder_comment %>
    @@ -161,7 +168,7 @@ a {

    - +