From 6aa5e0129e3247a93b7d353ec6fd651f2876b956 Mon Sep 17 00:00:00 2001 From: Tom Canac Date: Fri, 24 Jun 2016 17:07:13 +0200 Subject: [PATCH] Some refactoring --- AUTHORS | 3 +-- index.php | 71 ++++++++++++++++++++++++--------------------------- integrate.php | 4 +-- 3 files changed, 37 insertions(+), 41 deletions(-) diff --git a/AUTHORS b/AUTHORS index 1cb194f..b0085f3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -5,7 +5,7 @@ Copyright (c) Thomas Rybak (2014) Copyright (c) Sébastien Sauvage (2014) Copyright (c) Aldarone (2014) Copyright (c) Sylvhem (2014) -Copyright (c) Tom Canac (2014, 2015) +Copyright (c) Tom Canac (2014, 2015, 2016) Copyright (c) Alda Marteau-Hardi (2014) Copyright (c) bitbybit (2014) Copyright (c) cyberic99 (2014) @@ -15,4 +15,3 @@ Copyright (c) Lucas Cimon (2014) Copyright (c) nodiscc (2014, 2015) Copyright (c) Orangina Rouge (2014) Copyright (c) Nitrux Project (2014) - diff --git a/index.php b/index.php index 5c97b6e..9af1dea 100755 --- a/index.php +++ b/index.php @@ -122,6 +122,8 @@ function readEXIF($file) { if (count($exif_arr) > 0) { return "::" . implode(" | ", $exif_arr); } + + return $exif_arr; } function checkpermissions($file) { @@ -136,16 +138,11 @@ function checkpermissions($file) { } function guardAgainstDirectoryTraversal($path) { - /* - * I don't like regexes but this matches - * any attemp of directory traversal I could think of - * without forbidding « .. » in directory names. - */ $pattern = "/^(.*\/)?(\.\.)(\/.*)?$/"; - $directoryTraversal = preg_match($pattern, $path); + $directory_traversal = preg_match($pattern, $path); - if ($directoryTraversal === 1) { - die("ERROR: Could not open " . htmlspecialchars(stripslashes($currentdir)) . " for reading!"); + if ($directory_traversal === 1) { + die("ERROR: Could not open " . htmlspecialchars(stripslashes($current_dir)) . " for reading!"); } } @@ -158,11 +155,11 @@ if (!empty($_GET['dir'])) { $requestedDir = $_GET['dir']; } -$photoRoot = GALLERY_ROOT . 'photos/'; +$photo_root = GALLERY_ROOT . 'photos/'; $thumbdir = rtrim('photos/' . $requestedDir, '/'); -$currentdir = GALLERY_ROOT . $thumbdir; +$current_dir = GALLERY_ROOT . $thumbdir; -guardAgainstDirectoryTraversal($currentdir); +guardAgainstDirectoryTraversal($current_dir); //----------------------- // READ FILES AND FOLDERS @@ -170,9 +167,9 @@ guardAgainstDirectoryTraversal($currentdir); $files = array(); $dirs = array(); $img_captions = array(); -if (is_dir($currentdir) && $handle = opendir($currentdir)) { +if (is_dir($current_dir) && $handle = opendir($current_dir)) { // 1. LOAD CAPTIONS - $caption_filename = "$currentdir/captions.txt"; + $caption_filename = "$current_dir/captions.txt"; if (is_readable($caption_filename)) { $caption_handle = fopen($caption_filename, "rb"); while (!feof($caption_handle)) { @@ -186,13 +183,13 @@ if (is_dir($currentdir) && $handle = opendir($currentdir)) { fclose($caption_handle); } - while (false !== ($file = readdir($handle)) && !in_array($file, $SkipObjects)) { + while (false !== ($file = readdir($handle)) && !in_array($file, $skip_objects)) { // 2. LOAD FOLDERS - if (is_dir($currentdir . "/" . $file)) { + if (is_dir($current_dir . "/" . $file)) { if ($file != "." && $file != "..") { - checkpermissions($currentdir . "/" . $file); // Check for correct file permission + checkpermissions($current_dir . "/" . $file); // Check for correct file permission // Set thumbnail to folder.jpg if found: - if (file_exists($currentdir . '/' . $file . '/folder.jpg')) { + if (file_exists($current_dir . '/' . $file . '/folder.jpg')) { $linkParams = http_build_query( array('dir' => ltrim("$requestedDir/$file", '/')), '', @@ -202,7 +199,7 @@ if (is_dir($currentdir) && $handle = opendir($currentdir)) { $imgParams = http_build_query( array( - 'filename' => "$currentdir/$file/folder.jpg", + 'filename' => "$current_dir/$file/folder.jpg", 'size' => $thumb_size, ), '', @@ -212,13 +209,13 @@ if (is_dir($currentdir) && $handle = opendir($currentdir)) { $dirs[] = array( "name" => $file, - "date" => filemtime($currentdir . "/" . $file . "/folder.jpg"), + "date" => filemtime($current_dir . "/" . $file . "/folder.jpg"), "html" => "
  • " . padstring($file, $label_max_length) . "\"$label_loading\"
  • ", ); } else { // Set thumbnail to first image found (if any): unset($firstimage); - $firstimage = getfirstImage("$currentdir/" . $file); + $firstimage = getfirstImage("$current_dir/" . $file); if ($firstimage != "") { $linkParams = http_build_query( @@ -240,7 +237,7 @@ if (is_dir($currentdir) && $handle = opendir($currentdir)) { $dirs[] = array( "name" => $file, - "date" => filemtime($currentdir . "/" . $file), + "date" => filemtime($current_dir . "/" . $file), "html" => "
  • " . padstring($file, $label_max_length) . "$label_loading
  • ", ); } else { @@ -255,7 +252,7 @@ if (is_dir($currentdir) && $handle = opendir($currentdir)) { $dirs[] = array( "name" => $file, - "date" => filemtime($currentdir . "/" . $file), + "date" => filemtime($current_dir . "/" . $file), "html" => "
  • " . padstring($file, $label_max_length) . "$label_loading
  • ", ); } @@ -276,7 +273,7 @@ if (is_dir($currentdir) && $handle = opendir($currentdir)) { //Read EXIF if (!array_key_exists($file, $img_captions)) { if ($display_exif == 1) { - $exifReaden = readEXIF($currentdir . "/" . $file); + $exifReaden = readEXIF($current_dir . "/" . $file); //Add to the caption all the EXIF information $img_captions[$file] = $file . $exifReaden; } else { @@ -288,13 +285,13 @@ if (is_dir($currentdir) && $handle = opendir($currentdir)) { // 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); + checkpermissions($current_dir . "/" . $file); - if (is_file($currentdir . '/' . $file . '.html')) { - $img_captions[$file] = $file . '::' . htmlspecialchars(file_get_contents($currentdir . '/' . $file . '.html'), ENT_QUOTES); + if (is_file($current_dir . '/' . $file . '.html')) { + $img_captions[$file] = $file . '::' . htmlspecialchars(file_get_contents($current_dir . '/' . $file . '.html'), ENT_QUOTES); } - $linkUrl = str_replace('%2F', '/', rawurlencode("$currentdir/$file")); + $linkUrl = str_replace('%2F', '/', rawurlencode("$current_dir/$file")); $imgParams = http_build_query( array('filename' => "$thumbdir/$file", 'size' => $thumb_size), '', @@ -308,8 +305,8 @@ if (is_dir($currentdir) && $handle = opendir($currentdir)) { $files[] = array( "name" => $file, - "date" => filemtime($currentdir . "/" . $file), - "size" => filesize($currentdir . "/" . $file), + "date" => filemtime($current_dir . "/" . $file), + "size" => filesize($current_dir . "/" . $file), "html" => "
  • $label_loading" . $filename_caption . "
  • "); } // Other filetypes @@ -358,15 +355,15 @@ if (is_dir($currentdir) && $handle = opendir($currentdir)) { if ($extension != "") { $files[] = array( "name" => $file, - "date" => filemtime($currentdir . "/" . $file), - "size" => filesize($currentdir . "/" . $file), - "html" => "
  • " . padstring($file, 20) . "$file$filename_caption
  • "); + "date" => filemtime($current_dir . "/" . $file), + "size" => filesize($current_dir . "/" . $file), + "html" => "
  • " . padstring($file, 20) . "$file$filename_caption
  • "); } } } closedir($handle); } else { - die("ERROR: Could not open " . htmlspecialchars(stripslashes($currentdir)) . " for reading!"); + die("ERROR: Could not open " . htmlspecialchars(stripslashes($current_dir)) . " for reading!"); } //----------------------- @@ -468,7 +465,7 @@ if ($requestedDir != "" && $requestedDir != "photos") { //Include hidden links for all images BEFORE current page so lightbox is able to browse images on different pages for ($y = 0; $y < $offset_start - sizeof($dirs); $y++) { - $breadcrumb_navigation .= ""; + $breadcrumb_navigation .= ""; } //----------------------- @@ -476,7 +473,7 @@ for ($y = 0; $y < $offset_start - sizeof($dirs); $y++) { //----------------------- if (count($dirs) + count($files) == 0) { $thumbnails .= "
    $label_noimages
    $label_noimages_advice
    "; //Display 'no images' text - if ($currentdir == "photos") { + if ($current_dir == "photos") { $messages = "It looks like you have just installed MiniGal Nano. Please run the system check tool.
    @@ -505,7 +502,7 @@ if ($i < 0) { } for ($y = $i; $y < sizeof($files); $y++) { - $page_navigation .= ""; + $page_navigation .= ""; } //----------------------- @@ -516,7 +513,7 @@ if ($messages != "") { } // Read folder comment. -$comment_filepath = $currentdir . $file . "/comment.html"; +$comment_filepath = $current_dir . $file . "/comment.html"; if (file_exists($comment_filepath)) { $fd = fopen($comment_filepath, "r"); $comment = "
    " . fread($fd, filesize($comment_filepath)) . "
    "; diff --git a/integrate.php b/integrate.php index 953d3ee..459dcab 100644 --- a/integrate.php +++ b/integrate.php @@ -7,9 +7,9 @@ * MinigalNano is licensed under the AGPL v3 (https://gnu.org/licenses/agpl-3.0.txt). */ -$path_to_minigalnano = "minigalnano/"; // <- Enter RELATIVE path to MiniGal Nano here (eg. "subfolder/minigalnano") - DO NOT END WITH / +// Enter relativepath to MiniGal Nano here (eg. "subfolder/minigalnano") - No trailing / +$path_to_minigalnano = "minigalnano/"; -// DO NOT EDIT BELOW THIS LINE! define("GALLERY_ROOT", $path_to_minigalnano); require GALLERY_ROOT . "index.php"; ?>