2022-01-08 16:22:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Classes
|
|
|
|
require_once('lib/helpers.class.php');
|
|
|
|
require_once('lib/thumbs.class.php');
|
|
|
|
require_once('lib/template.class.php');
|
|
|
|
|
|
|
|
// Settings
|
|
|
|
require('conf/config.php');
|
|
|
|
|
|
|
|
// Prepare Some Basic Variables
|
|
|
|
$imagedir = Helpers::end_dir($conf['fs_imagedir']);
|
|
|
|
$thumbdir = Helpers::end_dir($conf['fs_thumbdir']);
|
|
|
|
$imageurl = Helpers::end_dir($conf['web_imagedir']);
|
|
|
|
$thumburl = Helpers::end_dir($conf['web_thumbdir']);
|
|
|
|
|
|
|
|
// Get Parameters or Set Defaults
|
|
|
|
$page = $_GET['p'] ?? $conf['defpage'];
|
|
|
|
$slice = $_GET['s'] ?? $conf['defslice'];
|
|
|
|
$gslice = $_GET['gs'] ?? $conf['defslice'];
|
|
|
|
$dir = $_GET['d'] ?? $conf['defdir'];
|
|
|
|
|
|
|
|
// Create or Load Session
|
|
|
|
session_start();
|
|
|
|
|
|
|
|
// Initialize Thumbnail Handler
|
|
|
|
$t = new Thumb(Helpers::end_dir($imagedir.$dir), $thumbdir, 200, 200);
|
|
|
|
|
|
|
|
// Filelist Cache Handling
|
|
|
|
if (isset($_SESSION['files'])
|
|
|
|
&& $_SESSION['dir'] == $dir
|
|
|
|
&& (time() - $_SESSION['cachetime']) < $conf['flcache']
|
|
|
|
&& !isset($_GET['refcache']))
|
|
|
|
{
|
|
|
|
$files = $_SESSION['files'];
|
|
|
|
} else {
|
|
|
|
$files = array_diff(scandir($imagedir.$dir, SCANDIR_SORT_DESCENDING), array('..', '.'));
|
|
|
|
$_SESSION['files'] = $files;
|
|
|
|
$_SESSION['dir'] = $dir;
|
|
|
|
$_SESSION['cachetime'] = time();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply Filters to Filelist
|
|
|
|
$filter='';
|
|
|
|
if (isset($_GET['f'])) {
|
|
|
|
if ($_GET['f'] != '') {
|
2022-01-10 14:28:39 +00:00
|
|
|
$t = array('(' => '\(', ')' => '\)');
|
2022-01-10 14:23:49 +00:00
|
|
|
$f = strtr($_GET['f'], $t);
|
2022-01-10 14:28:39 +00:00
|
|
|
error_log('----------'.$f.'----------');
|
2022-01-10 14:23:49 +00:00
|
|
|
$files = array_values(preg_grep('/.*'.$f.'.*/i', $files));
|
2022-01-08 16:22:16 +00:00
|
|
|
$filter='&f='.$_GET['f'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort and Reverse Filelist
|
|
|
|
natcasesort($files);
|
|
|
|
$files = array_reverse($files);
|
|
|
|
|
|
|
|
// Get Files for current Page
|
|
|
|
$curfiles = array_slice($files, ($page-1)*$slice ,$slice, true);
|
|
|
|
|
|
|
|
// Prepare Generic Data for Template
|
|
|
|
$data['dir'] = $dir;
|
|
|
|
$data['slice'] = $slice;
|
|
|
|
$data['filter'] = $filter;
|
|
|
|
$data['page'] = $page;
|
|
|
|
$data['prev_page'] = $page - 1;
|
|
|
|
if ($data['prev_page'] < 1)
|
|
|
|
$data['prev_page'] = 1;
|
|
|
|
$data['next_page'] = $page + 1;
|
|
|
|
if ($data['next_page'] > ceil(count($files)/$slice))
|
|
|
|
$data['next_page'] = $page;
|
|
|
|
$data['last_page'] = ceil(count($files)/$slice);
|
|
|
|
|
|
|
|
// Prepare Mode Specific Data and Render Template
|
|
|
|
if ($slice > 1) {
|
|
|
|
foreach ($curfiles as $index => $image) {
|
|
|
|
$tmp['n'] = $image;
|
|
|
|
$tmp['i'] = $index+1;
|
|
|
|
$tmp['t'] = $thumburl.$t->get_thumb($image);
|
|
|
|
$data['images'][] = $tmp;
|
|
|
|
}
|
|
|
|
Template::view('tpl/gallery.html', $data);
|
|
|
|
} else {
|
|
|
|
$data['gallery_page'] = ceil($page/$gslice);
|
|
|
|
$data['gallery_slice'] = $gslice;
|
|
|
|
foreach ($curfiles as $index => $image) {
|
|
|
|
$data['imageurl'] = $imageurl.$dir.'/'.$image;
|
|
|
|
$data['imagename'] = $image;
|
|
|
|
$data['tags'] = explode(" ", pathinfo(trim(strstr(strtolower($image), ' - '), " -"))['filename']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Template::view('tpl/single.html', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|