image-heberg/config/image-heberg.php
2023-08-25 23:45:43 +02:00

141 lines
4.8 KiB
PHP

<?php
/*
* Copyright 2008-2023 Anael MOBILIA
*
* This file is part of image-heberg.fr.
*
* image-heberg.fr is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* image-heberg.fr is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with image-heberg.fr. If not, see <http://www.gnu.org/licenses/>
*/
namespace ImageHeberg;
use Throwable;
if (_DEBUG_) {
error_reporting(E_ALL | E_STRICT);
}
if (!_PHPUNIT_) {
/**
* Gestion des exceptions de l'application
* @param Throwable $exception
*/
function exception_handler(Throwable $exception): void
{
if (_DEBUG_) {
// Afficher l'erreur en masquant les informations sensibles
echo '<pre>';
print_r(str_replace([_BDD_HOST_, _BDD_NAME_, _BDD_USER_, _BDD_PASS_, _PATH_], 'xxx', $exception->getMessage()));
echo '<br /><br /><hr /><br />';
print_r(str_replace([_BDD_HOST_, _BDD_NAME_, _BDD_USER_, _BDD_PASS_, _PATH_], 'xxx', $exception->getTraceAsString()));
echo '</pre>';
} else {
echo 'Une erreur a été rencontrée';
}
/**
* Envoi d'un mail avec le détail de l'erreur à l'administrateur
*/
// Adresse expediteur
$headers = 'From: ' . _ADMINISTRATEUR_EMAIL_;
// Adresse de retour
$headers .= PHP_EOL . 'Reply-To: ' . _ADMINISTRATEUR_EMAIL_;
// Agent mail
$headers .= PHP_EOL . 'X-Mailer: ' . _SITE_NAME_ . ' script at ' . _URL_;
// Date
$headers .= PHP_EOL . 'Date: ' . date('D, j M Y H:i:s +0200');
$message = PHP_EOL . $exception->getMessage() . PHP_EOL . $exception->getTraceAsString();
$message .= PHP_EOL . 'URL : ' . $_SERVER['REQUEST_URI'];
if (isset($_SERVER['HTTP_REFERER'])) {
$message .= PHP_EOL . 'HTTP REFERER : ' . $_SERVER['HTTP_REFERER'];
}
$message .= PHP_EOL . 'HTTP USER AGENT : ' . $_SERVER['HTTP_USER_AGENT'];
$message .= PHP_EOL . 'REMOTE ADDR : ' . $_SERVER['REMOTE_ADDR'];
mail(_ADMINISTRATEUR_EMAIL_, '[' . _SITE_NAME_ . '] - Erreur rencontrée', $message, $headers);
}
set_exception_handler('ImageHeberg\exception_handler');
}
/**
* Répertoires
*/
define('_REPERTOIRE_IMAGE_', 'files/');
define('_REPERTOIRE_MINIATURE_', _REPERTOIRE_IMAGE_ . 'thumbs/');
define('_REPERTOIRE_ADMIN_', 'admin/');
define('_REPERTOIRE_MEMBRE_', 'membre/');
define('_REPERTOIRE_CONFIG_', 'config/');
/**
* URL
*/
define('_URL_', 'http://' . _BASE_URL_);
define('_URL_HTTPS_', 'https://' . _BASE_URL_);
define('_URL_SANS_SCHEME_', '//' . _BASE_URL_);
define('_URL_ADMIN_', _URL_HTTPS_ . _REPERTOIRE_ADMIN_);
define('_URL_MEMBRE_', _URL_HTTPS_ . _REPERTOIRE_MEMBRE_);
define('_URL_IMAGES_', _URL_ . _REPERTOIRE_IMAGE_);
define('_URL_MINIATURES_', _URL_ . _REPERTOIRE_MINIATURE_);
define('_URL_CONFIG_', _URL_HTTPS_ . _REPERTOIRE_CONFIG_);
/**
* Système de fichiers
*/
define('_PATH_IMAGES_', _PATH_ . _REPERTOIRE_IMAGE_);
define('_PATH_MINIATURES_', _PATH_ . _REPERTOIRE_MINIATURE_);
define('_PATH_TESTS_IMAGES_', _PATH_ . '__tests/images/');
define('_PATH_TESTS_OUTPUT_', _PATH_ . '__tests/output/');
define('_TPL_TOP_', _PATH_ . 'template/templateV2Top.php');
define('_TPL_BOTTOM_', _PATH_ . 'template/templateV2Bottom.php');
// Fonction de chargement des classes en cas de besoin
spl_autoload_register(function ($class) {
// Suppression du namespace
$class = str_replace('ImageHeberg\\', '', $class);
if (str_contains($class, 'Helper')) {
// Helper par exemple
$file = _PATH_ . 'classes/' . $class . '.php';
} else {
// Classe instantiable
$file = _PATH_ . 'classes/' . $class . '.class.php';
}
// Si le fichier existe...
if (file_exists($file)) {
require $file;
}
});
/**
* Paramètres divers pour les images
*/
// Gestion de la mémoire
define('_FUDGE_FACTOR_', 1.8);
define('_IMAGE_DIMENSION_MAX_', HelperImage::getMaxDimension());
// Images spécifiques
define('_IMAGE_404_', '_image_404.png');
define('_IMAGE_BAN_', '_image_banned.png');
// Dimensions des apeçus dans l'espace membre
define('_SIZE_PREVIEW_', 256);
/**
* Tor
*/
// URL de l'API Tor
define('_TOR_EXIT_NODE_LIST_URL_', 'https://onionoo.torproject.org/details?flag=exit');
define('_TOR_LISTE_IPV4_', _PATH_ . _REPERTOIRE_IMAGE_ . 'z_cache/ipv4.txt');
define('_TOR_LISTE_IPV6_', _PATH_ . _REPERTOIRE_IMAGE_ . 'z_cache/ipv6.txt');