From b55589eea32d360f00c93414ef0369f4edf78b56 Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Mon, 28 Apr 2014 11:34:36 +0200 Subject: [PATCH] Autoloader improvements --- php/api.php | 1 - php/autoload.php | 19 ++++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/php/api.php b/php/api.php index 80e5352..b6d9b1e 100755 --- a/php/api.php +++ b/php/api.php @@ -73,7 +73,6 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) { ### define('LYCHEE_ACCESS_ADMIN', true); - require(__DIR__ . '/access/Admin.php'); $admin = new Admin($database, $plugins, $settings); $admin->check($_POST['function']); diff --git a/php/autoload.php b/php/autoload.php index 09d7a6d..b2dae0c 100644 --- a/php/autoload.php +++ b/php/autoload.php @@ -6,10 +6,23 @@ # @copyright 2014 by Tobias Reich ### -function lycheeAutoloader($class_name) { - require __DIR__ . '/modules/' . $class_name . '.php'; +if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!'); + +function lycheeAutoloaderModules($class_name) { + + $file = LYCHEE . 'php/modules/' . $class_name . '.php'; + if (file_exists($file)!==false) require $file; + } -spl_autoload_register('lycheeAutoloader'); +function lycheeAutoloaderAccess($class_name) { + + $file = LYCHEE . 'php/access/' . $class_name . '.php'; + if (file_exists($file)!==false) require $file; + +} + +spl_autoload_register('lycheeAutoloaderModules'); +spl_autoload_register('lycheeAutoloaderAccess'); ?> \ No newline at end of file