====== Modifications apportées à MiniGal Nano ======
Voici le diff (-u) des fichiers avec le détail de ce que j'ai modifié entre la version officielle de MiniGal Nano 0.3.5 et la mienne (0.3.5 SSE2).
===== .htaccess =====
Fichier ajouté.
Options -Indexes
===== config.php =====
--- config.php.original Mon Dec 06 10:43:00 2010
+++ config.php Wed Dec 01 12:08:06 2010
@@ -16,12 +16,12 @@
*/
// EDIT SETTINGS BELOW TO CUSTOMIZE YOUR GALLERY
-$thumbs_pr_page = "28"; //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)
-$title = "MiniGal Nano Testsite"; // Text to be displayed in browser titlebar
-$author = "Rybber";
+$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
$sorting_folders = "name"; // Sort folders by: [name][date]
$sorting_files = "name"; // Sort files by: [name][date][size]
@@ -39,5 +39,5 @@
//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;
+$display_exif = 0;
?>
===== config_default.php =====
--- config_default.php.original Sun Nov 28 23:36:00 2010
+++ config_default.php Wed Dec 01 12:08:06 2010
@@ -16,10 +16,10 @@
*/
// 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
===== createthumb.php =====
--- createthumb.php.original Mon Dec 06 10:45:00 2010
+++ createthumb.php Wed Dec 08 19:54:34 2010
@@ -14,16 +14,62 @@
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 @@
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,90);
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); }
-
+}
?>
===== index.php =====
--- index.php.original Mon Dec 06 10:22:00 2010
+++ index.php Wed Dec 15 09:35:44 2010
@@ -13,17 +13,24 @@
Community: www.minigal.dk/forum
Please enjoy this free script!
-*/
+
+Version 0.3.5 modified by Sebastien SAUVAGE (sebsauvage.net):
+ - Disabled new version check (problems on some servers)
+ - Disabled error reporting
+ - Added gallery comment (create comment.html in each directory)
+ - security update against XSS
+
+*/
// Do not edit below this section unless you know what you are doing!
//-----------------------
// Debug stuff
//-----------------------
- error_reporting(E_ERROR);
+// error_reporting(E_ERROR);
// error_reporting(E_ALL);
-// error_reporting(0);
+ error_reporting(0);
/*
$mtime = microtime();
$mtime = explode(" ",$mtime);
@@ -46,6 +53,8 @@
$images = "";
$exif_data = "";
$messages = "";
+$comment = "";
+
//-----------------------
// PHP ENVIRONMENT CHECK
@@ -126,14 +135,14 @@
//-----------------------
// CHECK FOR NEW VERSION
//-----------------------
-if (ini_get('allow_url_fopen') == "1") {
- $file = @fopen ("http://www.minigal.dk/minigalnano_version.php", "r");
- $server_version = fgets ($file, 1024);
- if (strlen($server_version) == 5 ) { //If string retrieved is exactly 5 chars then continue
- if (version_compare($server_version, $version, '>')) $messages = "MiniGal Nano $server_version is available! Get it now";
- }
- fclose($file);
-}
+//if (ini_get('allow_url_fopen') == "1") {
+// $file = @fopen ("http://www.minigal.dk/minigalnano_version.php", "r");
+// $server_version = fgets ($file, 1024);
+// if (strlen($server_version) == 5 ) { //If string retrieved is exactly 5 chars then continue
+// if (version_compare($server_version, $version, '>')) $messages = "MiniGal Nano $server_version is available! Get it now";
+// }
+// fclose($file);
+//}
if (!defined("GALLERY_ROOT")) define("GALLERY_ROOT", "");
$thumbdir = rtrim('photos' . "/" .$_REQUEST["dir"],"/");
@@ -238,7 +247,7 @@
}
}
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
@@ -369,12 +378,22 @@
$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 +409,7 @@
$template = preg_replace("/<% thumbnails %>/", "$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);
===== templates/mano.html =====
--- mano.html.original Sun Dec 05 23:36:00 2010
+++ mano.html Wed Dec 08 20:03:10 2010
@@ -96,6 +96,12 @@
vertical-align: middle;
}
+#folder_comment
+{
+ margin-top:10px;
+ margin-left:10px;
+}
+
/* ---------- gallery styles start here ----------------------- */
.gallery {
list-style: none;
@@ -152,6 +158,7 @@
by: <% author %>
<% breadcrumb_navigation %>
+
@@ -161,7 +168,7 @@
-
+