NanoGal/public/index.php
2024-10-29 11:36:24 +01:00

112 lines
3.4 KiB
PHP

<?php
date_default_timezone_set('Europe/Paris');
$time_start = microtime(true);
require '../vendor/autoload.php';
use App\FileAndDir;
use App\Cache;
use Utils\Utils;
error_reporting(-1);
$version = "0.1.0";
ini_set("memory_limit", "256M");
/*
Not edit this param directly
See README.md
*/
$config = [
'templateFile' => 'default', // Template filename (must be placed in 'public/templates' folder)
'title' => 'NanoGal', // Text to be displayed in browser titlebar
'description' => 'My gallery', // Use in meta tag "description"
'author' => 'NanoGal', // Your name
'skipObjects' => ['comment.html', '.gitkeep', 'aFolder', 'aFile.ext'], //Those files and folders will not be displayed (affects the page and the RSS feed)
'imageCaptionPosition' => 'right', // Position of caption in lightbox
'sortBy' => 'name', // Sort by name or date
'orderBy' => 'desc', // Order by asc or desc
'thumbSize' => 250, // Thumbnail height/width (square thumbs)
'displayExifInfo' => false, // Display Exif info in caption
'disableCache' => false, // Enable or disable cache
'showShareLink' => false, // Show link for thumb, full, markdown link (thumb + link to full)
'nbItemsAtom' => 25 // Number of item in atom feed
];
if (file_exists('../datas/config.php')) {
include '../datas/config.php';
$config = array_merge($config, $userConfig);
}
$messages = '';
if (!function_exists('exif_read_data') && $config['displayExifInfo'] === true) {
$display_exif = 0;
$messages = "Error: PHP EXIF is not available. Set &#36;display_exif = 0; in config.php to remove this message";
}
$requestedDir = '';
if (!empty($_GET['dir'])) {
$requestedDir = $_GET['dir'];
}
$thumbdir = rtrim('photos' . $requestedDir, '/');
$current_dir = $thumbdir;
$cache = new Cache($current_dir, $config);
if ($config['disableCache'] === false) {
$cacheHash = '../cache/html/' . md5($current_dir);
$cache->countDirsAndFiles();
}
$fileChange = $cache->changeFile();
$configChange = $cache->changeConf();
if ($fileChange || $configChange || !file_exists($cacheHash . '.html') || $config['disableCache'] === true) {
if ($cache->changeConf()) {
$cache->clearCache();
}
if ($fileChange || $configChange) {
Cache::clearAtomFeed();
}
if ($config['disableCache'] === false) {
$cache->save();
}
$list = new FileAndDir($current_dir, $requestedDir, $config);
$listDir = $list->listDirs();
$folderNote = $list->getFolderNote();
$breadcrumb_navigation = $list->makeBreadcrumb();
ob_start();
$userCss = '';
if (file_exists('../datas/user.css')) {
$userCss = '<style>' . file_get_contents('../datas/user.css') . '</style>';
}
if (file_exists('templates/' . $config['templateFile'] . '/' . $config['templateFile'] . '.php')) {
require 'templates/' . $config['templateFile'] . '/' . $config['templateFile'] . '.php';
} else {
require 'templates/board/board.php';
}
$content = ob_get_contents();
$gen = 'Build in : ';
if ($config['disableCache'] === false) {
file_put_contents($cacheHash . '.html', $content);
}
ob_end_clean();
} else {
$gen = 'Serve from cache in : ';
$content = file_get_contents($cacheHash . '.html');
}
$time_end = microtime(true);
$executionTime = round(($time_end - $time_start), 5);
$content = preg_replace("/<% buildTime %>/", $gen . $executionTime . 's', $content);
echo $content;