-
Notifications
You must be signed in to change notification settings - Fork 1
/
includes.php
76 lines (58 loc) · 2.38 KB
/
includes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
require 'vendor/autoload.php';
$globalConf = require __DIR__ ."/conf.php";
define("ROOTPATH", $globalConf['webRootPath']);
define("DOMAIN", $globalConf['domain']);
define("MAX_INPUT_LENGTH", 255 - 128); /* you cant make this bigger then 255 with out changing the cap to to the db */
define("MAX_INPUT_LENGTH_PASSWORD", 16 - 8); /* you cant make this bigger then 16 with out changing the cap to to the db */
define("IMAGE_EXTENTIONS", $globalConf['IMAGE_EXTENTIONS']);
define("VIDEO_EXTENTIONS", $globalConf['VIDEO_EXTENTIONS']);
define("AUDIO_EXTENTIONS", $globalConf['AUDIO_EXTENTIONS']);
ini_set('session.cookie_lifetime', $globalConf['sessionLifeTime']);
ini_set("memory_limit", $globalConf['memoryLimit']);
// Autoloader to automatically load class files based on their namespace and class name
spl_autoload_register(function ($class) {
$prefix = 'Modules\\';
$base_dir = __DIR__ . '/modules/';
// Does the class use the namespace prefix?
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
// No, move to the next registered autoloader
return;
}
// Get the relative class name
$relative_class = substr($class, $len);
// Replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
// Handle special case for ModuleBase.php
if ($relative_class === 'Module') {
$file = $base_dir . 'ModuleBase.php';
}
// If the file exists, require it
if (file_exists($file)) {
require $file;
}
});
// Function to load all modules from the /modules directory
function loadModules($modulesDir = __DIR__ . '/modules') {
$modules = [];
foreach (scandir($modulesDir) as $dir) {
if ($dir === '.' || $dir === '..' || is_file($modulesDir . '/' . $dir)) {
continue;
}
$mainFile = $modulesDir . '/' . $dir . '/Main.php';
if (file_exists($mainFile)) {
include_once $mainFile;
$className = 'Modules\\' . $dir . '\\Main';
if (class_exists($className)) {
$modules[] = new $className();
}
}
}
return $modules;
}