Fix missing folder

This commit is contained in:
Knah Tsaeb 2019-11-13 12:08:51 +01:00
parent 697d5fea2d
commit 44703f20a4
2 changed files with 384 additions and 375 deletions

755
index.php
View File

@ -22,123 +22,129 @@ include "config.php";
//----------------------- //-----------------------
// DEFINE VARIABLES // DEFINE VARIABLES
//----------------------- //-----------------------
$page_navigation = ""; $page_navigation = "";
$breadcrumb_navigation = ""; $breadcrumb_navigation = "";
$thumbnails = ""; $thumbnails = "";
$new = ""; $new = "";
$images = ""; $images = "";
$exif_data = ""; $exif_data = "";
$messages = ""; $messages = "";
$comment = ""; $comment = "";
//----------------------- //-----------------------
// PHP ENVIRONMENT CHECK // PHP ENVIRONMENT CHECK
//----------------------- //-----------------------
if (!function_exists('exif_read_data') && $display_exif == 1) { if (!function_exists('exif_read_data') && $display_exif == 1) {
$display_exif = 0; $display_exif = 0;
$messages = "Error: PHP EXIF is not available. Set $display_exif = 0; in config.php to remove this message"; $messages = "Error: PHP EXIF is not available. Set $display_exif = 0; in config.php to remove this message";
} }
//----------------------- //-----------------------
// FUNCTIONS // FUNCTIONS
//----------------------- //-----------------------
function padstring($name, $length) { function padstring($name, $length)
global $label_max_length; {
if (!isset($length)) { global $label_max_length;
$length = $label_max_length; if (!isset($length)) {
} $length = $label_max_length;
if (strlen($name) > $length) { }
return substr($name, 0, $length) . "..."; if (strlen($name) > $length) {
} return substr($name, 0, $length) . "...";
return $name; }
return $name;
} }
function getfirstImage($dirname) { function getfirstImage($dirname)
$imageName = false; {
$extensions = array("jpg", "png", "jpeg", "gif"); $imageName = false;
if ($handle = opendir($dirname)) { $extensions = array("jpg", "png", "jpeg", "gif");
while (false !== ($file = readdir($handle))) { if ($handle = opendir($dirname)) {
if ($file[0] == '.') { while (false !== ($file = readdir($handle))) {
continue; if ($file[0] == '.') {
} continue;
$pathinfo = pathinfo($file); }
if (empty($pathinfo['extension'])) { $pathinfo = pathinfo($file);
continue; if (empty($pathinfo['extension'])) {
} continue;
$ext = strtolower($pathinfo['extension']); }
if (in_array($ext, $extensions)) { $ext = strtolower($pathinfo['extension']);
$imageName = $file; if (in_array($ext, $extensions)) {
break; $imageName = $file;
} break;
} }
closedir($handle); }
} closedir($handle);
return $imageName; }
return $imageName;
} }
function parse_fraction($v, $round = 0) { function parse_fraction($v, $round = 0)
list($x, $y) = array_map('intval', explode('/', $v)); {
if (empty($x) || empty($y)) { list($x, $y) = array_map('intval', explode('/', $v));
return $v; if (empty($x) || empty($y)) {
} return $v;
if ($x % $y == 0) { }
return $x / $y; if ($x % $y == 0) {
} return $x / $y;
if ($y % $x == 0) { }
return "1/" . $y / $x; if ($y % $x == 0) {
} return "1/" . $y / $x;
return round($x / $y, $round); }
return round($x / $y, $round);
} }
function readEXIF($file) { function readEXIF($file)
$exif_arr = array(); {
$exif_data = exif_read_data($file); $exif_arr = array();
$exif_data = exif_read_data($file);
$exif_val = @$exif_data['Model']; $exif_val = @$exif_data['Model'];
if (!empty($exif_val)) { if (!empty($exif_val)) {
$exif_arr[] = $exif_val; $exif_arr[] = $exif_val;
} }
$exif_val = @$exif_data['FocalLength']; $exif_val = @$exif_data['FocalLength'];
if (!empty($exif_val)) { if (!empty($exif_val)) {
$exif_arr[] = parse_fraction($exif_val) . "mm"; $exif_arr[] = parse_fraction($exif_val) . "mm";
} }
$exif_val = @$exif_data['ExposureTime']; $exif_val = @$exif_data['ExposureTime'];
if (!empty($exif_val)) { if (!empty($exif_val)) {
$exif_arr[] = parse_fraction($exif_val, 2) . "s"; $exif_arr[] = parse_fraction($exif_val, 2) . "s";
} }
$exif_val = @$exif_data['FNumber']; $exif_val = @$exif_data['FNumber'];
if (!empty($exif_val)) { if (!empty($exif_val)) {
$exif_arr[] = "f" . parse_fraction($exif_val); $exif_arr[] = "f" . parse_fraction($exif_val);
} }
$exif_val = @$exif_data['ISOSpeedRatings']; $exif_val = @$exif_data['ISOSpeedRatings'];
if (!empty($exif_val)) { if (!empty($exif_val)) {
$exif_arr[] = "ISO " . $exif_val; $exif_arr[] = "ISO " . $exif_val;
} }
if (count($exif_arr) > 0) { if (count($exif_arr) > 0) {
return "::" . implode(" | ", $exif_arr); return "::" . implode(" | ", $exif_arr);
} }
return $exif_arr; return $exif_arr;
} }
function checkpermissions($file) { function checkpermissions($file)
global $messages; {
global $messages;
if (!is_readable($file)) { if (!is_readable($file)) {
$messages = "At least one file or folder has wrong permissions. " $messages = "At least one file or folder has wrong permissions. "
. "Learn how to <a href='http://minigal.dk/faq-reader/items/" . "Learn how to <a href='http://minigal.dk/faq-reader/items/"
. "how-do-i-change-file-permissions-chmod.html' target='_blank'>" . "how-do-i-change-file-permissions-chmod.html' target='_blank'>"
. "set file permissions</a>"; . "set file permissions</a>";
} }
} }
function guardAgainstDirectoryTraversal($path) { function guardAgainstDirectoryTraversal($path)
$pattern = "/^(.*\/)?(\.\.)(\/.*)?$/"; {
$pattern = "/^(.*\/)?(\.\.)(\/.*)?$/";
$directory_traversal = preg_match($pattern, $path); $directory_traversal = preg_match($pattern, $path);
if ($directory_traversal === 1) { if ($directory_traversal === 1) {
@ -147,16 +153,16 @@ function guardAgainstDirectoryTraversal($path) {
} }
if (!defined("GALLERY_ROOT")) { if (!defined("GALLERY_ROOT")) {
define("GALLERY_ROOT", ""); define("GALLERY_ROOT", "");
} }
$requestedDir = ''; $requestedDir = '';
if (!empty($_GET['dir'])) { if (!empty($_GET['dir'])) {
$requestedDir = $_GET['dir']; $requestedDir = $_GET['dir'];
} }
$photo_root = GALLERY_ROOT . 'photos/'; $photo_root = GALLERY_ROOT . 'photos/';
$thumbdir = rtrim('photos/' . $requestedDir, '/'); $thumbdir = rtrim('photos/' . $requestedDir, '/');
$current_dir = GALLERY_ROOT . $thumbdir; $current_dir = GALLERY_ROOT . $thumbdir;
guardAgainstDirectoryTraversal($current_dir); guardAgainstDirectoryTraversal($current_dir);
@ -164,277 +170,280 @@ guardAgainstDirectoryTraversal($current_dir);
//----------------------- //-----------------------
// READ FILES AND FOLDERS // READ FILES AND FOLDERS
//----------------------- //-----------------------
$files = array(); $files = array();
$dirs = array(); $dirs = array();
$img_captions = array(); $img_captions = array();
if (is_dir($current_dir) && $handle = opendir($current_dir)) { if (is_dir($current_dir) && $handle = opendir($current_dir)) {
// 1. LOAD CAPTIONS // 1. LOAD CAPTIONS
$caption_filename = "$current_dir/captions.txt"; $caption_filename = "$current_dir/captions.txt";
if (is_readable($caption_filename)) { if (is_readable($caption_filename)) {
$caption_handle = fopen($caption_filename, "rb"); $caption_handle = fopen($caption_filename, "rb");
while (!feof($caption_handle)) { while (!feof($caption_handle)) {
$caption_line = fgetss($caption_handle); $caption_line = fgetss($caption_handle);
if (empty($caption_line)) { if (empty($caption_line)) {
continue; continue;
} }
list($img_file, $img_text) = explode('|', $caption_line); list($img_file, $img_text) = explode('|', $caption_line);
$img_captions[$img_file] = trim($img_text); $img_captions[$img_file] = trim($img_text);
} }
fclose($caption_handle); fclose($caption_handle);
} }
while (false !== ($file = readdir($handle)) && !in_array($file, $skip_objects)) { while (false !== ($file = readdir($handle))) {
// 2. LOAD FOLDERS if (in_array($file, $skip_objects)) {
if (is_dir($current_dir . "/" . $file)) { continue;
if ($file != "." && $file != "..") { }
checkpermissions($current_dir . "/" . $file); // Check for correct file permission // 2. LOAD FOLDERS
// Set thumbnail to folder.jpg if found: if (is_dir($current_dir . "/" . $file)) {
if (file_exists($current_dir . '/' . $file . '/folder.jpg')) { if ($file != "." && $file != "..") {
$linkParams = http_build_query( checkpermissions($current_dir . "/" . $file); // Check for correct file permission
array('dir' => ltrim("$requestedDir/$file", '/')), // Set thumbnail to folder.jpg if found:
'', if (file_exists($current_dir . '/' . $file . '/folder.jpg')) {
'&amp;' $linkParams = http_build_query(
); array('dir' => ltrim("$requestedDir/$file", '/')),
$linkUrl = "?$linkParams"; '',
'&amp;'
);
$linkUrl = "?$linkParams";
$imgParams = http_build_query( $imgParams = http_build_query(
array( array(
'filename' => "$current_dir/$file/folder.jpg", 'filename' => "$current_dir/$file/folder.jpg",
'size' => $thumb_size, 'size' => $thumb_size,
), ),
'', '',
'&amp;' '&amp;'
); );
$imgUrl = GALLERY_ROOT . "createthumb.php?$imgParams"; $imgUrl = GALLERY_ROOT . "createthumb.php?$imgParams";
$dirs[] = array( $dirs[] = array(
"name" => $file, "name" => $file,
"date" => filemtime($current_dir . "/" . $file . "/folder.jpg"), "date" => filemtime($current_dir . "/" . $file . "/folder.jpg"),
"html" => "<li><a href=\"{$linkUrl}\"><em>" . padstring($file, $label_max_length) . "</em><span></span><img src=\"{$imgUrl}\" alt=\"$label_loading\" /></a></li>", "html" => "<li><a href=\"{$linkUrl}\"><em>" . padstring($file, $label_max_length) . "</em><span></span><img src=\"{$imgUrl}\" alt=\"$label_loading\" /></a></li>",
); );
} else { } else {
// Set thumbnail to first image found (if any): // Set thumbnail to first image found (if any):
unset($firstimage); unset($firstimage);
$firstimage = getfirstImage("$current_dir/" . $file); $firstimage = getfirstImage("$current_dir/" . $file);
if ($firstimage != "") { if ($firstimage != "") {
$linkParams = http_build_query( $linkParams = http_build_query(
array('dir' => ltrim("$requestedDir/$file", '/')), array('dir' => ltrim("$requestedDir/$file", '/')),
'', '',
'&amp;' '&amp;'
); );
$linkUrl = "?$linkParams"; $linkUrl = "?$linkParams";
$imgParams = http_build_query( $imgParams = http_build_query(
array( array(
'filename' => "$thumbdir/$file/$firstimage", 'filename' => "$thumbdir/$file/$firstimage",
'size' => $thumb_size, 'size' => $thumb_size,
), ),
'', '',
'&amp;' '&amp;'
); );
$imgUrl = GALLERY_ROOT . "createthumb.php?$imgParams"; $imgUrl = GALLERY_ROOT . "createthumb.php?$imgParams";
$dirs[] = array( $dirs[] = array(
"name" => $file, "name" => $file,
"date" => filemtime($current_dir . "/" . $file), "date" => filemtime($current_dir . "/" . $file),
"html" => "<li><a href=\"{$linkUrl}\"><em>" . padstring($file, $label_max_length) . "</em><span></span><img src=\"{$imgUrl}\" alt='$label_loading' /></a></li>", "html" => "<li><a href=\"{$linkUrl}\"><em>" . padstring($file, $label_max_length) . "</em><span></span><img src=\"{$imgUrl}\" alt='$label_loading' /></a></li>",
); );
} else { } else {
// If no folder.jpg or image is found, then display default icon: // If no folder.jpg or image is found, then display default icon:
$linkParams = http_build_query( $linkParams = http_build_query(
array('dir' => ltrim("$requestedDir/$file", '/')), array('dir' => ltrim("$requestedDir/$file", '/')),
'', '',
'&amp;' '&amp;'
); );
$linkUrl = "?$linkParams"; $linkUrl = "?$linkParams";
$imgUrl = GALLERY_ROOT . 'images/folder_' . strtolower($folder_color) . '.png'; $imgUrl = GALLERY_ROOT . 'images/folder_' . strtolower($folder_color) . '.png';
$dirs[] = array( $dirs[] = array(
"name" => $file, "name" => $file,
"date" => filemtime($current_dir . "/" . $file), "date" => filemtime($current_dir . "/" . $file),
"html" => "<li><a href=\"{$linkUrl}\"><em>" . padstring($file, $label_max_length) . "</em><span></span><img src=\"{$imgUrl}\" width='$thumb_size' height='$thumb_size' alt='$label_loading' /></a></li>", "html" => "<li><a href=\"{$linkUrl}\"><em>" . padstring($file, $label_max_length) . "</em><span></span><img src=\"{$imgUrl}\" width='$thumb_size' height='$thumb_size' alt='$label_loading' /></a></li>",
); );
} }
} }
} }
} }
// 3. LOAD FILES // 3. LOAD FILES
if ($file != "." && $file != ".." && $file != "folder.jpg") { if ($file != "." && $file != ".." && $file != "folder.jpg") {
if ($display_filename) { if ($display_filename) {
$filename_caption = "<em>" . padstring($file, $label_max_length) . "</em>"; $filename_caption = "<em>" . padstring($file, $label_max_length) . "</em>";
} else { } else {
$filename_caption = ""; $filename_caption = "";
} }
// JPG, GIF and PNG // JPG, GIF and PNG
if (preg_match("/.jpg$|.gif$|.png$/i", $file)) { if (preg_match("/.jpg$|.gif$|.png$/i", $file)) {
//Read EXIF //Read EXIF
if (!array_key_exists($file, $img_captions)) { if (!array_key_exists($file, $img_captions)) {
if ($display_exif == 1) { if ($display_exif == 1) {
$exifReaden = readEXIF($current_dir . "/" . $file); $exifReaden = readEXIF($current_dir . "/" . $file);
//Add to the caption all the EXIF information //Add to the caption all the EXIF information
$img_captions[$file] = $file . $exifReaden; $img_captions[$file] = $file . $exifReaden;
} else { } else {
//If no EXIF, just use the filename as caption //If no EXIF, just use the filename as caption
$img_captions[$file] = $file; $img_captions[$file] = $file;
} }
} }
// Read the optionnal image title and caption in html file (image.jpg --> image.jpg.html) // Read the optionnal image title and caption in html file (image.jpg --> image.jpg.html)
// Format: title::caption // Format: title::caption
// Example: My cat::My cat like to <i>roll</i> on the floor. // Example: My cat::My cat like to <i>roll</i> on the floor.
// If file is not provided, image filename will be used instead. // If file is not provided, image filename will be used instead.
checkpermissions($current_dir . "/" . $file); checkpermissions($current_dir . "/" . $file);
if (is_file($current_dir . '/' . $file . '.html')) { if (is_file($current_dir . '/' . $file . '.html')) {
$img_captions[$file] = $file . '::' . htmlspecialchars(file_get_contents($current_dir . '/' . $file . '.html'), ENT_QUOTES); $img_captions[$file] = $file . '::' . htmlspecialchars(file_get_contents($current_dir . '/' . $file . '.html'), ENT_QUOTES);
} }
$linkUrl = str_replace('%2F', '/', rawurlencode("$current_dir/$file")); $linkUrl = str_replace('%2F', '/', rawurlencode("$current_dir/$file"));
$imgParams = http_build_query( $imgParams = http_build_query(
array('filename' => "$thumbdir/$file", 'size' => $thumb_size), array('filename' => "$thumbdir/$file", 'size' => $thumb_size),
'', '',
'&amp;'); '&amp;');
$imgUrl = GALLERY_ROOT . "createthumb.php?$imgParams"; $imgUrl = GALLERY_ROOT . "createthumb.php?$imgParams";
if ($lazyload) { if ($lazyload) {
$imgopts = "class=\"b-lazy\" src=data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== data-src=\"$imgUrl\""; $imgopts = "class=\"b-lazy\" src=data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== data-src=\"$imgUrl\"";
} else { } else {
$imgopts = "src=\"{$imgUrl}\""; $imgopts = "src=\"{$imgUrl}\"";
} }
$files[] = array( $files[] = array(
"name" => $file, "name" => $file,
"date" => filemtime($current_dir . "/" . $file), "date" => filemtime($current_dir . "/" . $file),
"size" => filesize($current_dir . "/" . $file), "size" => filesize($current_dir . "/" . $file),
"html" => "<li><a href=\"{$linkUrl}\" rel='lightbox[billeder]' title=\"" . htmlentities($img_captions[$file]) . "\"><img $imgopts alt='$label_loading' /></a>" . $filename_caption . "</li>"); "html" => "<li><a href=\"{$linkUrl}\" rel='lightbox[billeder]' title=\"" . htmlentities($img_captions[$file]) . "\"><img $imgopts alt='$label_loading' /></a>" . $filename_caption . "</li>");
} }
// Other filetypes // Other filetypes
$extension = ""; $extension = "";
if (preg_match("/\.pdf$/i", $file)) { if (preg_match("/\.pdf$/i", $file)) {
$extension = "PDF"; $extension = "PDF";
} }
// PDF // PDF
if (preg_match("/\.zip$/i", $file)) { if (preg_match("/\.zip$/i", $file)) {
$extension = "ZIP"; $extension = "ZIP";
} }
// ZIP archive // ZIP archive
if (preg_match("/\.rar$|\.r[0-9]{2,}/i", $file)) { if (preg_match("/\.rar$|\.r[0-9]{2,}/i", $file)) {
$extension = "RAR"; $extension = "RAR";
} }
// RAR Archive // RAR Archive
if (preg_match("/\.tar$/i", $file)) { if (preg_match("/\.tar$/i", $file)) {
$extension = "TAR"; $extension = "TAR";
} }
// TARball archive // TARball archive
if (preg_match("/\.gz$/i", $file)) { if (preg_match("/\.gz$/i", $file)) {
$extension = "GZ"; $extension = "GZ";
} }
// GZip archive // GZip archive
if (preg_match("/\.doc$|\.docx$/i", $file)) { if (preg_match("/\.doc$|\.docx$/i", $file)) {
$extension = "DOCX"; $extension = "DOCX";
} }
// Word // Word
if (preg_match("/\.ppt$|\.pptx$/i", $file)) { if (preg_match("/\.ppt$|\.pptx$/i", $file)) {
$extension = "PPTX"; $extension = "PPTX";
} }
//Powerpoint //Powerpoint
if (preg_match("/\.xls$|\.xlsx$/i", $file)) { if (preg_match("/\.xls$|\.xlsx$/i", $file)) {
$extension = "XLXS"; $extension = "XLXS";
} }
// Excel // Excel
if (preg_match("/\.ogv$|\.mp4$|\.mpg$|\.mpeg$|\.mov$|\.avi$|\.wmv$|\.flv$|\.webm$/i", $file)) { if (preg_match("/\.ogv$|\.mp4$|\.mpg$|\.mpeg$|\.mov$|\.avi$|\.wmv$|\.flv$|\.webm$/i", $file)) {
$extension = "VIDEO"; $extension = "VIDEO";
} }
// video files // video files
if (preg_match("/\.aiff$|\.aif$|\.wma$|\.aac$|\.flac$|\.mp3$|\.ogg$|\.m4a$/i", $file)) { if (preg_match("/\.aiff$|\.aif$|\.wma$|\.aac$|\.flac$|\.mp3$|\.ogg$|\.m4a$/i", $file)) {
$extension = "AUDIO"; $extension = "AUDIO";
} }
// audio files // audio files
if ($extension != "") { if ($extension != "") {
$files[] = array( $files[] = array(
"name" => $file, "name" => $file,
"date" => filemtime($current_dir . "/" . $file), "date" => filemtime($current_dir . "/" . $file),
"size" => filesize($current_dir . "/" . $file), "size" => filesize($current_dir . "/" . $file),
"html" => "<li><a href='$current_dir/$file' title='$file'><em-pdf>" . padstring($file, 20) . "</em-pdf><span></span><img src='" . GALLERY_ROOT . "images/filetype_" . $extension . ".png' width='$thumb_size' height='$thumb_size' alt='$file' /></a>$filename_caption</li>"); "html" => "<li><a href='$current_dir/$file' title='$file'><em-pdf>" . padstring($file, 20) . "</em-pdf><span></span><img src='" . GALLERY_ROOT . "images/filetype_" . $extension . ".png' width='$thumb_size' height='$thumb_size' alt='$file' /></a>$filename_caption</li>");
} }
} }
} }
closedir($handle); closedir($handle);
} else { } else {
die("ERROR: Could not open " . htmlspecialchars(stripslashes($current_dir)) . " for reading!"); die("ERROR: Could not open " . htmlspecialchars(stripslashes($current_dir)) . " for reading!");
} }
//----------------------- //-----------------------
// SORT FILES AND FOLDERS // SORT FILES AND FOLDERS
//----------------------- //-----------------------
if (sizeof($dirs) > 0) { if (sizeof($dirs) > 0) {
foreach ($dirs as $key => $row) { foreach ($dirs as $key => $row) {
if ($row["name"] == "") { if ($row["name"] == "") {
unset($dirs[$key]); //Delete empty array entries unset($dirs[$key]); //Delete empty array entries
continue; continue;
} }
$name[$key] = strtolower($row['name']); $name[$key] = strtolower($row['name']);
$date[$key] = strtolower($row['date']); $date[$key] = strtolower($row['date']);
} }
@array_multisort($$sorting_folders, $sortdir_folders, $name, $sortdir_folders, $dirs); @array_multisort($$sorting_folders, $sortdir_folders, $name, $sortdir_folders, $dirs);
} }
if (sizeof($files) > 0) { if (sizeof($files) > 0) {
foreach ($files as $key => $row) { foreach ($files as $key => $row) {
if ($row["name"] == "") { if ($row["name"] == "") {
unset($files[$key]); //Delete empty array entries unset($files[$key]); //Delete empty array entries
continue; continue;
} }
$name[$key] = strtolower($row['name']); $name[$key] = strtolower($row['name']);
$date[$key] = strtolower($row['date']); $date[$key] = strtolower($row['date']);
$size[$key] = strtolower($row['size']); $size[$key] = strtolower($row['size']);
} }
@array_multisort($$sorting_files, $sortdir_files, $name, SORT_ASC, $files); @array_multisort($$sorting_files, $sortdir_files, $name, SORT_ASC, $files);
} }
//----------------------- //-----------------------
// OFFSET DETERMINATION // OFFSET DETERMINATION
//----------------------- //-----------------------
if (!isset($_GET["page"])) { if (!isset($_GET["page"])) {
$_GET["page"] = 1; $_GET["page"] = 1;
} }
$offset_start = ($_GET["page"] * $thumbs_pr_page) - $thumbs_pr_page; $offset_start = ($_GET["page"] * $thumbs_pr_page) - $thumbs_pr_page;
$offset_end = $offset_start + $thumbs_pr_page; $offset_end = $offset_start + $thumbs_pr_page;
if ($offset_end > sizeof($dirs) + sizeof($files)) { if ($offset_end > sizeof($dirs) + sizeof($files)) {
$offset_end = sizeof($dirs) + sizeof($files); $offset_end = sizeof($dirs) + sizeof($files);
} }
if ($_GET["page"] == "all" || $lazyload) { if ($_GET["page"] == "all" || $lazyload) {
$offset_start = 0; $offset_start = 0;
$offset_end = sizeof($dirs) + sizeof($files); $offset_end = sizeof($dirs) + sizeof($files);
} }
//----------------------- //-----------------------
// PAGE NAVIGATION // PAGE NAVIGATION
//----------------------- //-----------------------
if (!$lazyload && sizeof($dirs) + sizeof($files) > $thumbs_pr_page) { if (!$lazyload && sizeof($dirs) + sizeof($files) > $thumbs_pr_page) {
$page_navigation .= "$label_page "; $page_navigation .= "$label_page ";
for ($i = 1; $i <= ceil((sizeof($files) + sizeof($dirs)) / $thumbs_pr_page); $i++) { for ($i = 1; $i <= ceil((sizeof($files) + sizeof($dirs)) / $thumbs_pr_page); $i++) {
if ($_GET["page"] == $i) { if ($_GET["page"] == $i) {
$page_navigation .= "$i"; $page_navigation .= "$i";
} else { } else {
$page_navigation .= "<a href='?dir=" . $requestedDir . "&amp;page=" . ($i) . "'>" . $i . "</a>"; $page_navigation .= "<a href='?dir=" . $requestedDir . "&amp;page=" . ($i) . "'>" . $i . "</a>";
} }
if ($i != ceil((sizeof($files) + sizeof($dirs)) / $thumbs_pr_page)) { if ($i != ceil((sizeof($files) + sizeof($dirs)) / $thumbs_pr_page)) {
$page_navigation .= " | "; $page_navigation .= " | ";
} }
} }
//Insert link to view all images //Insert link to view all images
if ($_GET["page"] == "all") { if ($_GET["page"] == "all") {
$page_navigation .= " | $label_all"; $page_navigation .= " | $label_all";
} else { } else {
$page_navigation .= " | <a href='?dir=" . $requestedDir . "&amp;page=all'>$label_all</a>"; $page_navigation .= " | <a href='?dir=" . $requestedDir . "&amp;page=all'>$label_all</a>";
} }
} }
@ -442,109 +451,109 @@ if (!$lazyload && sizeof($dirs) + sizeof($files) > $thumbs_pr_page) {
// BREADCRUMB NAVIGATION // BREADCRUMB NAVIGATION
//----------------------- //-----------------------
if ($requestedDir != "" && $requestedDir != "photos") { if ($requestedDir != "" && $requestedDir != "photos") {
$breadcrumb_navigation = "<div class=\"NavWrapper\">"; $breadcrumb_navigation = "<div class=\"NavWrapper\">";
$breadcrumb_navigation .= "<a href='?dir='>" . $label_home . "</a> $breadcrumb_separator "; $breadcrumb_navigation .= "<a href='?dir='>" . $label_home . "</a> $breadcrumb_separator ";
$navitems = explode("/", htmlspecialchars($_REQUEST['dir'])); $navitems = explode("/", htmlspecialchars($_REQUEST['dir']));
for ($i = 0; $i < sizeof($navitems); $i++) { for ($i = 0; $i < sizeof($navitems); $i++) {
if ($i == sizeof($navitems) - 1) { if ($i == sizeof($navitems) - 1) {
$breadcrumb_navigation .= $navitems[$i]; $breadcrumb_navigation .= $navitems[$i];
} else { } else {
$breadcrumb_navigation .= "<a href='?dir="; $breadcrumb_navigation .= "<a href='?dir=";
for ($x = 0; $x <= $i; $x++) { for ($x = 0; $x <= $i; $x++) {
$breadcrumb_navigation .= $navitems[$x]; $breadcrumb_navigation .= $navitems[$x];
if ($x < $i) { if ($x < $i) {
$breadcrumb_navigation .= "/"; $breadcrumb_navigation .= "/";
} }
} }
$breadcrumb_navigation .= "'>" . $navitems[$i] . "</a> $breadcrumb_separator "; $breadcrumb_navigation .= "'>" . $navitems[$i] . "</a> $breadcrumb_separator ";
} }
} }
$breadcrumb_navigation .= "</div>"; $breadcrumb_navigation .= "</div>";
} }
//Include hidden links for all images BEFORE current page so lightbox is able to browse images on different pages //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++) { for ($y = 0; $y < $offset_start - sizeof($dirs); $y++) {
$breadcrumb_navigation .= "<a href='" . $current_dir . "/" . $files[$y]["name"] . "' class='hidden' title='" . $img_captions[$files[$y]["name"]] . "'></a>"; $breadcrumb_navigation .= "<a href='" . $current_dir . "/" . $files[$y]["name"] . "' class='hidden' title='" . $img_captions[$files[$y]["name"]] . "'></a>";
} }
//----------------------- //-----------------------
// DISPLAY FOLDERS // DISPLAY FOLDERS
//----------------------- //-----------------------
if (count($dirs) + count($files) == 0) { if (count($dirs) + count($files) == 0) {
$thumbnails .= "<div class=\"Empty\">$label_noimages</div> <div class=\"EmptyAdvice\">$label_noimages_advice</div>"; //Display 'no images' text $thumbnails .= "<div class=\"Empty\">$label_noimages</div> <div class=\"EmptyAdvice\">$label_noimages_advice</div>"; //Display 'no images' text
if ($current_dir == "photos") { if ($current_dir == "photos") {
$messages = $messages =
"It looks like you have just installed MiniGal Nano. "It looks like you have just installed MiniGal Nano.
Please run the <a href='system_check.php'>system check tool</a>. <br> Please run the <a href='system_check.php'>system check tool</a>. <br>
And why not have a look to config.php and customize some values ?"; And why not have a look to config.php and customize some values ?";
} }
} }
$offset_current = $offset_start; $offset_current = $offset_start;
for ($x = $offset_start; $x < sizeof($dirs) && $x < $offset_end; $x++) { for ($x = $offset_start; $x < sizeof($dirs) && $x < $offset_end; $x++) {
$offset_current++; $offset_current++;
$thumbnails .= $dirs[$x]["html"]; $thumbnails .= $dirs[$x]["html"];
} }
//----------------------- //-----------------------
// DISPLAY FILES // DISPLAY FILES
//----------------------- //-----------------------
for ($i = $offset_start - sizeof($dirs); $i < $offset_end && $offset_current < $offset_end; $i++) { for ($i = $offset_start - sizeof($dirs); $i < $offset_end && $offset_current < $offset_end; $i++) {
if ($i >= 0) { if ($i >= 0) {
$offset_current++; $offset_current++;
$thumbnails .= $files[$i]["html"]; $thumbnails .= $files[$i]["html"];
} }
} }
//Include hidden links for all images AFTER current page so lightbox is able to browse images on different pages //Include hidden links for all images AFTER current page so lightbox is able to browse images on different pages
if ($i < 0) { if ($i < 0) {
$i = 1; $i = 1;
} }
for ($y = $i; $y < sizeof($files); $y++) { for ($y = $i; $y < sizeof($files); $y++) {
$page_navigation .= "<a href='" . $current_dir . "/" . $files[$y]["name"] . "' class='hidden' title='" . $img_captions[$files[$y]["name"]] . "'></a>"; $page_navigation .= "<a href='" . $current_dir . "/" . $files[$y]["name"] . "' class='hidden' title='" . $img_captions[$files[$y]["name"]] . "'></a>";
} }
//----------------------- //-----------------------
// OUTPUT MESSAGES // OUTPUT MESSAGES
//----------------------- //-----------------------
if ($messages != "") { if ($messages != "") {
$messages = $messages . "<div><a id=\"closeMessage\" class=\"closeMessage\" href=\"#\"><img src=\"images/close.png\" /></a><div>"; $messages = $messages . "<div><a id=\"closeMessage\" class=\"closeMessage\" href=\"#\"><img src=\"images/close.png\" /></a><div>";
} }
// Read folder comment. // Read folder comment.
$comment_filepath = $current_dir . $file . "/comment.html"; $comment_filepath = $current_dir . $file . "/comment.html";
if (file_exists($comment_filepath)) { if (file_exists($comment_filepath)) {
$fd = fopen($comment_filepath, "r"); $fd = fopen($comment_filepath, "r");
$comment = "<div class=\"Comment\">" . fread($fd, filesize($comment_filepath)) . "</div>"; $comment = "<div class=\"Comment\">" . fread($fd, filesize($comment_filepath)) . "</div>";
fclose($fd); fclose($fd);
} }
//PROCESS TEMPLATE FILE //PROCESS TEMPLATE FILE
if (GALLERY_ROOT != "") { if (GALLERY_ROOT != "") {
$templatefile = GALLERY_ROOT . "templates/integrate.html"; $templatefile = GALLERY_ROOT . "templates/integrate.html";
} else { } else {
$templatefile = "templates/" . $templatefile . ".html"; $templatefile = "templates/" . $templatefile . ".html";
} }
if (!$fd = fopen($templatefile, "r")) { if (!$fd = fopen($templatefile, "r")) {
echo "Template " . htmlspecialchars(stripslashes($templatefile)) . " not found!"; echo "Template " . htmlspecialchars(stripslashes($templatefile)) . " not found!";
exit(); exit();
} else { } else {
$template = fread($fd, filesize($templatefile)); $template = fread($fd, filesize($templatefile));
fclose($fd); fclose($fd);
$template = stripslashes($template); $template = stripslashes($template);
$template = preg_replace("/<% title %>/", $title, $template); $template = preg_replace("/<% title %>/", $title, $template);
$template = preg_replace("/<% messages %>/", $messages, $template); $template = preg_replace("/<% messages %>/", $messages, $template);
$template = preg_replace("/<% author %>/", $author, $template); $template = preg_replace("/<% author %>/", $author, $template);
$template = preg_replace("/<% gallery_root %>/", GALLERY_ROOT, $template); $template = preg_replace("/<% gallery_root %>/", GALLERY_ROOT, $template);
$template = preg_replace("/<% images %>/", "$images", $template); $template = preg_replace("/<% images %>/", "$images", $template);
$template = preg_replace("/<% thumbnails %>/", "$thumbnails", $template); $template = preg_replace("/<% thumbnails %>/", "$thumbnails", $template);
$template = preg_replace("/<% breadcrumb_navigation %>/", "$breadcrumb_navigation", $template); $template = preg_replace("/<% breadcrumb_navigation %>/", "$breadcrumb_navigation", $template);
$template = preg_replace("/<% page_navigation %>/", "$page_navigation", $template); $template = preg_replace("/<% page_navigation %>/", "$page_navigation", $template);
$template = preg_replace("/<% folder_comment %>/", "$comment", $template); $template = preg_replace("/<% folder_comment %>/", "$comment", $template);
$template = preg_replace("/<% bgcolor %>/", "$backgroundcolor", $template); $template = preg_replace("/<% bgcolor %>/", "$backgroundcolor", $template);
$template = preg_replace("/<% gallery_width %>/", "$gallery_width", $template); $template = preg_replace("/<% gallery_width %>/", "$gallery_width", $template);
$template = preg_replace("/<% version %>/", "$version", $template); $template = preg_replace("/<% version %>/", "$version", $template);
echo "$template"; echo "$template";
} }

View File

@ -140,8 +140,8 @@
<script src="<% gallery_root %>js/lazy.js"></script> <script src="<% gallery_root %>js/lazy.js"></script>
<script src="<% gallery_root %>js/script.js"></script> <script src="<% gallery_root %>js/script.js"></script>
<script src="<% gallery_root %>js/mootools.js"></script> <script src="<% gallery_root %>js/mootools1.5.0.js"></script>
<script src="<% gallery_root %>js/mediabox1.3.4.js"></script> <script src="<% gallery_root %>js/mediabox1.5.4.js"></script>
</head> </head>
<body> <body>
<header id="top" role="banner"> <header id="top" role="banner">