From 8b5713c0597d652e83e3b5323ae18219588ed8de Mon Sep 17 00:00:00 2001 From: Tom Canac Date: Thu, 30 Jan 2014 12:29:34 +0100 Subject: [PATCH] lazy loading is okay :) --- config.php | 2 +- index.php | 107 +++++++++++++++++++++++-------------------- js/lazy.js | 6 +++ templates/board.html | 7 +++ 4 files changed, 71 insertions(+), 51 deletions(-) create mode 100644 js/lazy.js diff --git a/config.php b/config.php index 6073caa..31cc00a 100644 --- a/config.php +++ b/config.php @@ -27,7 +27,7 @@ $sorting_folders = "name"; // Sort folders by: [name][date] $sorting_files = "name"; // Sort files by: [name][date][size] $sortdir_folders = "ASC"; // Sort direction of folders: [ASC][DESC] $sortdir_files = "ASC"; // Sort direction of files: [ASC][DESC] -$lazyload = 1; // 0 = pagination, 1 = display all pictures on one page. +$lazyload = 0; // 0 = pagination, 1 = display all pictures on one page. //LANGUAGE STRINGS $label_home = "Home"; //Name of home link in breadcrumb navigation diff --git a/index.php b/index.php index 4afcded..e1359a5 100644 --- a/index.php +++ b/index.php @@ -59,7 +59,7 @@ $comment = ""; //----------------------- if (!function_exists('exif_read_data') && $display_exif == 1) { $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"; } //----------------------- @@ -78,7 +78,7 @@ function padstring($name, $length) { global $label_max_length; if (!isset($length)) $length = $label_max_length; if (strlen($name) > $length) { - return substr($name,0,$length) . "..."; + return substr($name,0,$length) . "..."; } else return $name; } function getfirstImage($dirname) { @@ -100,30 +100,30 @@ function getfirstImage($dirname) { function readEXIF($file) { $exif_data = ""; $exif_idf0 = exif_read_data ($file,'IFD0' ,0 ); - $emodel = $exif_idf0['Model']; + $emodel = $exif_idf0['Model']; - $efocal = $exif_idf0['FocalLength']; - list($x,$y) = split('/', $efocal); - $efocal = round($x/$y,0); - - $exif_exif = exif_read_data ($file,'EXIF' ,0 ); - $eexposuretime = $exif_exif['ExposureTime']; - - $efnumber = $exif_exif['FNumber']; - list($x,$y) = split('/', $efnumber); - $efnumber = round($x/$y,0); + $efocal = $exif_idf0['FocalLength']; + list($x,$y) = split('/', $efocal); + $efocal = round($x/$y,0); + + $exif_exif = exif_read_data ($file,'EXIF' ,0 ); + $eexposuretime = $exif_exif['ExposureTime']; + + $efnumber = $exif_exif['FNumber']; + list($x,$y) = split('/', $efnumber); + $efnumber = round($x/$y,0); - $eiso = $exif_exif['ISOSpeedRatings']; - - $exif_date = exif_read_data ($file,'IFD0' ,0 ); - $edate = $exif_date['DateTime']; + $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); + 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; @@ -161,7 +161,7 @@ $dirs = array(); if ($handle = opendir($currentdir)) { while (false !== ($file = readdir($handle))) - { + { // 1. LOAD FOLDERS if (is_directory($currentdir . "/" . $file)) { @@ -215,7 +215,7 @@ if (file_exists($currentdir ."/captions.txt")) } // 3. LOAD FILES - if ($file != "." && $file != ".." && $file != "folder.jpg") + if ($file != "." && $file != ".." && $file != "folder.jpg") { // JPG, GIF and PNG if (preg_match("/.jpg$|.gif$|.png$/i", $file)) @@ -223,41 +223,48 @@ 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. + // 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 ( + $img_captions[$file] = $file; + if (is_file($currentdir.'/'.$file.'.html')) { $img_captions[$file] = $file.'::'.htmlspecialchars(file_get_contents($currentdir.'/'.$file.'.html'),ENT_QUOTES); } + if ($lazyload) { + $files[] = array ( "name" => $file, "date" => filemtime($currentdir . "/" . $file), "size" => filesize($currentdir . "/" . $file), - "html" => "
  • $label_loading
  • "); + "html" => "
  • $label_loading
  • "); + } else { + $files[] = array ( + "name" => $file, + "date" => filemtime($currentdir . "/" . $file), + "size" => filesize($currentdir . "/" . $file), + "html" => "
  • $label_loading
  • "); + } } // Other filetypes $extension = ""; - if (preg_match("/.pdf$/i", $file)) $extension = "PDF"; // PDF - if (preg_match("/.zip$/i", $file)) $extension = "ZIP"; // ZIP archive - if (preg_match("/.rar$|.r[0-9]{2,}/i", $file)) $extension = "RAR"; // RAR Archive - if (preg_match("/.tar$/i", $file)) $extension = "TAR"; // TARball archive - 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 ($extension != "") + if (preg_match("/.pdf$/i", $file)) $extension = "PDF"; // PDF + if (preg_match("/.zip$/i", $file)) $extension = "ZIP"; // ZIP archive + if (preg_match("/.rar$|.r[0-9]{2,}/i", $file)) $extension = "RAR"; // RAR Archive + if (preg_match("/.tar$/i", $file)) $extension = "TAR"; // TARball archive + 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 ($extension != "") { $files[] = array ( "name" => $file, "date" => filemtime($currentdir . "/" . $file), "size" => filesize($currentdir . "/" . $file), "html" => "
  • " . padstring($file, 20) . "$file
  • "); - } - } + } + } } closedir($handle); } else die("ERROR: Could not open ".htmlspecialchars(stripslashes($currentdir))." for reading!"); @@ -292,7 +299,7 @@ if (sizeof($files) > 0) //----------------------- // OFFSET DETERMINATION //----------------------- - if (!isset($_GET["page"])) $_GET["page"] = 1; + 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; @@ -396,9 +403,9 @@ $messages = "
    " . $messages . " =c.screen.width)return q=b.src,!1});y()}function w(){for(var b=0;b=0-a.offset)||t)t||B(d),m.splice(b,1),k--,b--}0===k&&g.prototype.destroy()}function B(b){if(0<% title %> + + +