clean up spacing

This commit is contained in:
Piotr KUCHARSKI 2014-11-25 13:58:04 +01:00
parent 14cdaf7dd1
commit 5e57817eb5

740
index.php
View file

@ -21,28 +21,17 @@ by Sébastien SAUVAGE.
*/ */
error_reporting(-1);
// Do not edit below this section unless you know what you are doing! // Do not edit below this section unless you know what you are doing!
//-----------------------
// Debug stuff
//-----------------------
// error_reporting(E_ERROR);
// error_reporting(E_ALL);
error_reporting(-1);
/*
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
*/
header('Content-Type: text/html; charset=UTF-8'); // We use UTF-8 for proper international characters handling. header('Content-Type: text/html; charset=UTF-8'); // We use UTF-8 for proper international characters handling.
$version = "0.3.7"; $version = "0.3.7";
ini_set("memory_limit","256M"); ini_set("memory_limit", "256M");
require("config-default.php"); require("config-default.php");
include("config.php"); include("config.php");
//----------------------- //-----------------------
// DEFINE VARIABLES // DEFINE VARIABLES
//----------------------- //-----------------------
@ -59,80 +48,96 @@ $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)) $length = $label_max_length; global $label_max_length;
if (strlen($name) > $length) { if (!isset($length))
return substr($name,0,$length) . "..."; $length = $label_max_length;
} else return $name; if (strlen($name) > $length)
} return substr($name, 0, $length) . "...";
function getfirstImage($dirname) { return $name;
$imageName = false;
$ext = array("jpg", "png", "jpeg", "gif", "JPG", "PNG", "GIF", "JPEG");
if($handle = opendir($dirname))
{
while(false !== ($file = readdir($handle)))
{
$lastdot = strrpos($file, '.');
$extension = substr($file, $lastdot + 1);
if ($file[0] != '.' && in_array($extension, $ext)) break;
}
$imageName = $file;
closedir($handle);
}
return($imageName);
}
function readEXIF($file) {
$exif_data = "";
$exif_idf0 = exif_read_data ($file,'IFD0' ,0 );
$emodel = $exif_idf0['Model'];
$efocal = $exif_idf0['FocalLength'];
//Next is only cosmectic need but give an error due to division by zero
//list($x,$y) = preg_split('/', $efocal);
//$efocal = round($x/$y,0);
$exif_exif = exif_read_data ($file,'EXIF' ,0 );
$eexposuretime = $exif_exif['ExposureTime'];
$efnumber = $exif_exif['FNumber'];
//Next is only cosmectic need but give an error due to division by zero
//list($x,$y) = preg_split('/', $efnumber);
//$efnumber = round($x/$y,0);
$eiso = $exif_exif['ISOSpeedRatings'];
$exif_date = exif_read_data ($file,'IFD0' ,0 );
$edate = $exif_date['DateTime'];
if (strlen($emodel) > 0 OR strlen($efocal) > 0 OR strlen($eexposuretime) > 0 OR strlen($efnumber) > 0 OR strlen($eiso) > 0) $exif_data .= "::";
if (strlen($emodel) > 0) $exif_data .= "$emodel";
if ($efocal > 0) $exif_data .= " | $efocal" . "mm";
if (strlen($eexposuretime) > 0) $exif_data .= " | $eexposuretime" . "s";
if ($efnumber > 0) $exif_data .= " | f$efnumber";
if (strlen($eiso) > 0) $exif_data .= " | ISO $eiso";
return($exif_data);
}
function checkpermissions($file) {
global $messages;
if (substr(decoct(fileperms($file)), -1, strlen(fileperms($file))) < 4 OR substr(decoct(fileperms($file)), -3,1) < 4) $messages = "At least one file or folder has wrong permissions. Learn how to <a href='http://minigal.dk/faq-reader/items/how-do-i-change-file-permissions-chmod.html' target='_blank'>set file permissions</a>";
} }
if (!defined("GALLERY_ROOT")) define("GALLERY_ROOT", ""); function getfirstImage($dirname)
{
$imageName = false;
$ext = array("jpg", "png", "jpeg", "gif", "JPG", "PNG", "GIF", "JPEG");
if ($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))) {
$lastdot = strrpos($file, '.');
$extension = substr($file, $lastdot + 1);
if ($file[0] != '.' && in_array($extension, $ext))
break;
}
$imageName = $file;
closedir($handle);
}
return $imageName;
}
function readEXIF($file)
{
$exif_data = "";
$exif_idf0 = exif_read_data($file, 'IFD0', 0);
$emodel = $exif_idf0['Model'];
$efocal = $exif_idf0['FocalLength'];
//Next is only cosmectic need but give an error due to division by zero
//list($x, $y) = preg_split('/', $efocal);
//$efocal = round($x/$y, 0);
$exif_exif = exif_read_data($file, 'EXIF', 0);
$eexposuretime = $exif_exif['ExposureTime'];
$efnumber = $exif_exif['FNumber'];
//Next is only cosmectic need but give an error due to division by zero
//list($x, $y) = preg_split('/', $efnumber);
//$efnumber = round($x/$y, 0);
$eiso = $exif_exif['ISOSpeedRatings'];
$exif_date = exif_read_data($file, 'IFD0', 0);
$edate = $exif_date['DateTime'];
if (strlen($emodel . $efocal . $eexposuretime . $efnumber . $eiso) > 0)
$exif_data .= "::";
if (strlen($emodel) > 0)
$exif_data .= "$emodel";
if ($efocal > 0)
$exif_data .= " | $efocal" . "mm";
if (strlen($eexposuretime) > 0)
$exif_data .= " | $eexposuretime" . "s";
if ($efnumber > 0)
$exif_data .= " | f$efnumber";
if (strlen($eiso) > 0)
$exif_data .= " | ISO $eiso";
return $exif_data;
}
function checkpermissions($file)
{
global $messages;
if (substr(decoct(fileperms($file)), -1, strlen(fileperms($file))) < 4 OR substr(decoct(fileperms($file)), -3, 1) < 4)
$messages = "At least one file or folder has wrong permissions. Learn how to <a href='http://minigal.dk/faq-reader/items/how-do-i-change-file-permissions-chmod.html' target='_blank'>set file permissions</a>";
}
if (!defined("GALLERY_ROOT"))
define("GALLERY_ROOT", "");
$requestedDir = ''; $requestedDir = '';
if (!empty($_GET['dir'])) $requestedDir = $_GET['dir']; if (!empty($_GET['dir']))
$thumbdir = rtrim('photos/'.$requestedDir,'/'); $requestedDir = $_GET['dir'];
$thumbdir = rtrim('photos/' . $requestedDir, '/');
//$thumbdir = str_replace('/..', '', $thumbdir); // Prevent directory traversal attacks. //$thumbdir = str_replace('/..', '', $thumbdir); // Prevent directory traversal attacks.
if(strstr($thumbdir, '..') !== FALSE) { if (strstr($thumbdir, '..') !== false) {
$requestedDir = ''; $requestedDir = '';
$thumbdir = rtrim('photos/','/'); $thumbdir = rtrim('photos/', '/');
} }
$currentdir = GALLERY_ROOT . $thumbdir; $currentdir = GALLERY_ROOT . $thumbdir;
@ -142,371 +147,332 @@ $currentdir = GALLERY_ROOT . $thumbdir;
//----------------------- //-----------------------
$files = array(); $files = array();
$dirs = array(); $dirs = array();
if (is_dir($currentdir) && $handle = opendir($currentdir)) if (is_dir($currentdir) && $handle = opendir($currentdir)) {
{ while (false !== ($file = readdir($handle)) && !in_array($file, $SkipObjects)) {
while (false !== ($file = readdir($handle)) && !in_array($file, $SkipObjects)) // 1. LOAD FOLDERS
{ if (is_dir($currentdir . "/" . $file)) {
// 1. LOAD FOLDERS if ($file != "." && $file != "..") {
if (is_dir($currentdir . "/" . $file)) checkpermissions($currentdir . "/" . $file); // Check for correct file permission
{ // Set thumbnail to folder.jpg if found:
if ($file != "." && $file != ".." ) if (file_exists($currentdir. '/' . $file . '/folder.jpg')) {
{ $linkParams = http_build_query(
checkpermissions($currentdir . "/" . $file); // Check for correct file permission array('dir' => ltrim("$requestedDir/$file", '/')),
// Set thumbnail to folder.jpg if found: '',
if (file_exists($currentdir. '/' . $file . '/folder.jpg')) '&amp;'
{ );
$linkParams = http_build_query( $linkUrl = "?$linkParams";
array('dir' => ltrim("$requestedDir/$file", '/')),
'',
'&amp;'
);
$linkUrl = "?$linkParams";
$imgParams = http_build_query( $imgParams = http_build_query(
array( array(
'filename' => "$currentdir/$file/folder.jpg", 'filename' => "$currentdir/$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($currentdir . "/" . $file . "/folder.jpg"), "date" => filemtime($currentdir . "/" . $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("$currentdir/" . $file); $firstimage = getfirstImage("$currentdir/" . $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($currentdir . "/" . $file), "date" => filemtime($currentdir . "/" . $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($currentdir . "/" . $file), "date" => filemtime($currentdir . "/" . $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>"
); );
} }
} }
} }
} }
// 2. LOAD CAPTIONS // 2. LOAD CAPTIONS
$img_captions['']=''; $img_captions[''] = '';
if (file_exists($currentdir ."/captions.txt")) if (file_exists($currentdir ."/captions.txt")) {
{ $file_handle = fopen($currentdir ."/captions.txt", "rb");
$file_handle = fopen($currentdir ."/captions.txt", "rb"); while (!feof($file_handle)) {
while (!feof($file_handle) ) $line_of_text = fgets($file_handle);
{ if (empty($line_of_text))
$line_of_text = fgets($file_handle); continue;
if (empty($line_of_text)) { $parts = explode('/n', $line_of_text);
continue; foreach($parts as $img_capts) {
} list($img_filename, $img_caption) = explode('|', $img_capts);
$parts = explode('/n', $line_of_text); $img_captions[$img_filename] = $img_caption;
foreach($parts as $img_capts) }
{ }
list($img_filename, $img_caption) = explode('|', $img_capts); fclose($file_handle);
$img_captions[$img_filename] = $img_caption; }
}
}
fclose($file_handle);
}
// 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
} $filename_caption = "";
else { // JPG, GIF and PNG
$filename_caption=""; if (preg_match("/.jpg$|.gif$|.png$/i", $file)) {
} //Read EXIF
// JPG, GIF and PNG if (!array_key_exists($file, $img_captions)) {
if (preg_match("/.jpg$|.gif$|.png$/i", $file)) if ($display_exif == 1) {
{ $exifReaden = readEXIF($currentdir . "/" . $file);
//Read EXIF //Add to the caption all the EXIF information
if (!array_key_exists($file, $img_captions)) { $img_captions[$file] = $file.$exifReaden;
if ($display_exif == 1) } else {
{ //If no EXIF, just use the filename as caption
$exifReaden= readEXIF($currentdir . "/" . $file); $img_captions[$file] = $file;
//Add to the caption all the EXIF information }
$img_captions[$file] = $file.$exifReaden; }
} // Read the optionnal image title and caption in html file (image.jpg --> image.jpg.html)
else // Format: title::caption
{ // Example: My cat::My cat like to <i>roll</i> on the floor.
//If no EXIF, just use the filename as caption // If file is not provided, image filename will be used instead.
$img_captions[$file] = $file; checkpermissions($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 <i>roll</i> on the floor.
// If file is not provided, image filename will be used instead.
checkpermissions($currentdir . "/" . $file);
if (is_file($currentdir.'/'.$file.'.html')) { if (is_file($currentdir.'/'.$file.'.html'))
$img_captions[$file] = $file.'::'.htmlspecialchars(file_get_contents($currentdir.'/'.$file.'.html'),ENT_QUOTES); $img_captions[$file] = $file.'::'.htmlspecialchars(file_get_contents($currentdir.'/'.$file.'.html'), ENT_QUOTES);
} $linkUrl = str_replace('%2F', '/', rawurlencode("$currentdir/$file"));
$linkUrl = str_replace('%2F', '/', rawurlencode("$currentdir/$file")); $imgParams = http_build_query(
$imgParams = http_build_query( array('filename' => "$thumbdir/$file", 'size' => $thumb_size),
array( '',
'filename' => "$thumbdir/$file", '&amp;');
'size' => $thumb_size $imgUrl = GALLERY_ROOT . "createthumb.php?$imgParams";
), if ($lazyload)
'', $imgopts = "class=\"b-lazy\" src=data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== data-src=\"$imgUrl\"";
'&amp;' else
); $imgopts = "src=\"{$imgUrl}\"";
$imgUrl = GALLERY_ROOT . "createthumb.php?$imgParams"; $files[] = array(
if ($lazyload) { "name" => $file,
$imgopts = "class=\"b-lazy\" src=data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== data-src=\"$imgUrl\""; "date" => filemtime($currentdir . "/" . $file),
} else { "size" => filesize($currentdir . "/" . $file),
$imgopts = "src=\"{$imgUrl}\""; "html" => "<li><a href=\"{$linkUrl}\" rel='lightbox[billeder]' title=\"".htmlentities($img_captions[$file])."\"><img $imgopts alt='$label_loading' /></a>" . $filename_caption . "</li>");
} }
$files[] = array ( // Other filetypes
"name" => $file, $extension = "";
"date" => filemtime($currentdir . "/" . $file), if (preg_match("/.pdf$/i", $file)) $extension = "PDF"; // PDF
"size" => filesize($currentdir . "/" . $file), if (preg_match("/.zip$/i", $file)) $extension = "ZIP"; // ZIP archive
"html" => "<li><a href=\"{$linkUrl}\" rel='lightbox[billeder]' title=\"".htmlentities($img_captions[$file])."\"><img $imgopts alt='$label_loading' /></a>" . $filename_caption . "</li>"); if (preg_match("/.rar$|.r[0-9]{2,}/i", $file)) $extension = "RAR"; // RAR Archive
} if (preg_match("/.tar$/i", $file)) $extension = "TAR"; // TARball archive
// Other filetypes if (preg_match("/.gz$/i", $file)) $extension = "GZ"; // GZip archive
$extension = ""; if (preg_match("/.doc$|.docx$/i", $file)) $extension = "DOCX"; // Word
if (preg_match("/.pdf$/i", $file)) $extension = "PDF"; // PDF if (preg_match("/.ppt$|.pptx$/i", $file)) $extension = "PPTX"; //Powerpoint
if (preg_match("/.zip$/i", $file)) $extension = "ZIP"; // ZIP archive if (preg_match("/.xls$|.xlsx$/i", $file)) $extension = "XLXS"; // Excel
if (preg_match("/.rar$|.r[0-9]{2,}/i", $file)) $extension = "RAR"; // RAR Archive if (preg_match("/.ogv$|.mp4$|.mpg$|.mpeg$|.mov$|.avi$|.wmv$|.flv$|.webm$/i", $file)) $extension = "VIDEO"; // video files
if (preg_match("/.tar$/i", $file)) $extension = "TAR"; // TARball archive if (preg_match("/.aiff$|.aif$|.wma$|.aac$|.flac$|.mp3$|.ogg$|.m4a$/i", $file)) $extension = "AUDIO"; // audio files
if (preg_match("/.gz$/i", $file)) $extension = "GZ"; // GZip archive
if (preg_match("/.doc$|.docx$/i", $file)) $extension = "DOCX"; // Word
if (preg_match("/.ppt$|.pptx$/i", $file)) $extension = "PPTX"; //Powerpoint
if (preg_match("/.xls$|.xlsx$/i", $file)) $extension = "XLXS"; // Excel
if (preg_match("/.ogv$|.mp4$|.mpg$|.mpeg$|.mov$|.avi$|.wmv$|.flv$|.webm$/i", $file)) $extension = "VIDEO"; // video files
if (preg_match("/.aiff$|.aif$|.wma$|.aac$|.flac$|.mp3$|.ogg$|.m4a$/i", $file)) $extension = "AUDIO"; // audio files
if ($extension != "") {
if ($extension != "") $files[] = array(
{ "name" => $file,
$files[] = array ( "date" => filemtime($currentdir . "/" . $file),
"name" => $file, "size" => filesize($currentdir . "/" . $file),
"date" => filemtime($currentdir . "/" . $file), "html" => "<li><a href='$currentdir/$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>");
"size" => filesize($currentdir . "/" . $file), }
"html" => "<li><a href='" . $currentdir . "/" . $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);
} } else {
closedir($handle); die("ERROR: Could not open ".htmlspecialchars(stripslashes($currentdir))." for reading!");
} else die("ERROR: Could not open ".htmlspecialchars(stripslashes($currentdir))." 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"] == "") {
{ unset($dirs[$key]); //Delete empty array entries
if($row["name"] == "") { continue;
unset($dirs[$key]); //Delete empty array entries }
continue; $name[$key] = strtolower($row['name']);
} $date[$key] = strtolower($row['date']);
$name[$key] = strtolower($row['name']); }
$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"])) $_GET["page"] = 1; if (!isset($_GET["page"]))
$offset_start = ($_GET["page"] * $thumbs_pr_page) - $thumbs_pr_page; $_GET["page"] = 1;
if (!isset($_GET["page"])) $offset_start = 0; $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)) $offset_end = sizeof($dirs) + sizeof($files); if ($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)
{ $page_navigation .= "$i";
if ($_GET["page"] == $i) else
$page_navigation .= "$i"; $page_navigation .= "<a href='?dir=" . $requestedDir . "&amp;page=" . ($i) . "'>" . $i . "</a>";
else if ($i != ceil((sizeof($files) + sizeof($dirs)) / $thumbs_pr_page))
$page_navigation .= "<a href='?dir=" . $requestedDir . "&amp;page=" . ($i) . "'>" . $i . "</a>"; $page_navigation .= " | ";
if ($i != ceil((sizeof($files) + sizeof($dirs)) / $thumbs_pr_page)) $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 $page_navigation .= " | <a href='?dir=" . $requestedDir . "&amp;page=all'>$label_all</a>"; else
$page_navigation .= " | <a href='?dir=" . $requestedDir . "&amp;page=all'>$label_all</a>";
} }
//----------------------- //-----------------------
// BREADCRUMB NAVIGATION // BREADCRUMB NAVIGATION
//----------------------- //-----------------------
if ($requestedDir != "") if ($requestedDir != "") {
{ $breadcrumb_navigation .= "<a href='?dir='>" . $label_home . "</a> $breadcrumb_separator ";
$breadcrumb_navigation .= "<a href='?dir='>" . $label_home . "</a> $breadcrumb_separator "; $navitems = explode("/", $_REQUEST['dir']);
$navitems = explode("/", $_REQUEST['dir']); for ($i = 0; $i < sizeof($navitems); $i++) {
for($i = 0; $i < sizeof($navitems); $i++) if ($i == sizeof($navitems)-1) {
{ $breadcrumb_navigation .= $navitems[$i];
if ($i == sizeof($navitems)-1) $breadcrumb_navigation .= $navitems[$i]; } else {
else $breadcrumb_navigation .= "<a href='?dir=";
{ for ($x = 0; $x <= $i; $x++) {
$breadcrumb_navigation .= "<a href='?dir="; $breadcrumb_navigation .= $navitems[$x];
for ($x = 0; $x <= $i; $x++) if ($x < $i)
{ $breadcrumb_navigation .= "/";
$breadcrumb_navigation .= $navitems[$x]; }
if ($x < $i) $breadcrumb_navigation .= "/"; $breadcrumb_navigation .= "'>" . $navitems[$i] . "</a> $breadcrumb_separator ";
} }
$breadcrumb_navigation .= "'>" . $navitems[$i] . "</a> $breadcrumb_separator "; }
} } else {
} $breadcrumb_navigation .= $label_home;
} else $breadcrumb_navigation .= $label_home; }
//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='" . $currentdir . "/" . $files[$y]["name"] . "' class='hidden' title='" . $img_captions[$files[$y]["name"]] . "'></a>";
$breadcrumb_navigation .= "<a href='" . $currentdir . "/" . $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 .= "<li>$label_noimages</li>"; //Display 'no images' text $thumbnails .= "<li>$label_noimages</li>"; //Display 'no images' text
if($currentdir == "photos") $messages = "It looks like you have just installed MiniGal Nano. Please run the <a href='system_check.php'>system check tool</a>"; if ($currentdir == "photos")
$messages = "It looks like you have just installed MiniGal Nano. Please run the <a href='system_check.php'>system check tool</a>";
} }
$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++;
{ $thumbnails .= $files[$i]["html"];
$offset_current++; }
$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) $i=1; if ($i < 0)
for ($y = $i; $y < sizeof($files); $y++) $i = 1;
{ for ($y = $i; $y < sizeof($files); $y++) {
$page_navigation .= "<a href='" . $currentdir . "/" . $files[$y]["name"] . "' class='hidden' title='" . $img_captions[$files[$y]["name"]] . "'></a>"; $page_navigation .= "<a href='" . $currentdir . "/" . $files[$y]["name"] . "' class='hidden' title='" . $img_captions[$files[$y]["name"]] . "'></a>";
} }
//----------------------- //-----------------------
// OUTPUT MESSAGES // OUTPUT MESSAGES
//----------------------- //-----------------------
if ($messages != "") { if ($messages != "") {
$messages = "<div id=\"topbar\">" . $messages . " <a href=\"#\" onclick=\"document.getElementById('topbar').style.display = 'none';\";><img src=\"images/close.png\" /></a></div>"; $messages = "<div id=\"topbar\">" . $messages . " <a href=\"#\" onclick=\"document.getElementById('topbar').style.display = 'none';\";><img src=\"images/close.png\" /></a></div>";
} }
// Read folder comment. // Read folder comment.
$comment_filepath = $currentdir . $file . "/comment.html"; $comment_filepath = $currentdir . $file . "/comment.html";
if (file_exists($comment_filepath)) if (file_exists($comment_filepath)) {
{ $fd = fopen($comment_filepath, "r");
$fd = fopen($comment_filepath, "r"); $comment = fread($fd, filesize($comment_filepath));
$comment = fread($fd,filesize ($comment_filepath)); fclose($fd);
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 ".htmlspecialchars(stripslashes($templatefile))." not found!";
exit();
}
else
{
$template = fread ($fd, filesize ($templatefile));
fclose ($fd);
$template = stripslashes($template);
$template = preg_replace("/<% title %>/", $title, $template);
$template = preg_replace("/<% messages %>/", $messages, $template);
$template = preg_replace("/<% author %>/", $author, $template);
$template = preg_replace("/<% gallery_root %>/", GALLERY_ROOT, $template);
$template = preg_replace("/<% images %>/", "$images", $template);
$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);
echo "$template";
}
//----------------------- //PROCESS TEMPLATE FILE
//Debug stuff if (GALLERY_ROOT != "")
//----------------------- $templatefile = GALLERY_ROOT . "templates/integrate.html";
/* $mtime = microtime(); else
$mtime = explode(" ",$mtime); $templatefile = "templates/" . $templatefile . ".html";
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime; if (!$fd = fopen($templatefile, "r")) {
$totaltime = ($endtime - $starttime); echo "Template ".htmlspecialchars(stripslashes($templatefile))." not found!";
echo "This page was created in ".$totaltime." seconds"; exit();
*/ } else {
?> $template = fread($fd, filesize ($templatefile));
fclose($fd);
$template = stripslashes($template);
$template = preg_replace("/<% title %>/", $title, $template);
$template = preg_replace("/<% messages %>/", $messages, $template);
$template = preg_replace("/<% author %>/", $author, $template);
$template = preg_replace("/<% gallery_root %>/", GALLERY_ROOT, $template);
$template = preg_replace("/<% images %>/", "$images", $template);
$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);
echo "$template";
}