forked from sumocoders/Simple-Application-Framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.php
executable file
·113 lines (95 loc) · 2.46 KB
/
init.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* Init
* @package site
* @author Tijs Verkoyen <[email protected]>
* @since 1.0
*/
class Init
{
/**
* Default constructor
*/
public function __construct()
{
// set a default timezone if no one was set by PHP.ini
if(ini_get('date.timezone') == '') date_default_timezone_set('Europe/Brussels');
// require globals
require_once './library/globals.php';
// define constants
define('CACHE_PATH', PATH_WWW . '/cache');
define('CORE_PATH', PATH_WWW . '/core');
// set include path
set_include_path(realpath(PATH_WWW . '/vendor/spoon/library') . PATH_SEPARATOR . PATH_WWW . PATH_SEPARATOR . get_include_path());
// set debugging
if(SPOON_DEBUG)
{
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'On');
define('LAST_MODIFIED', microtime(true));
}
else
{
error_reporting(0);
ini_set('display_errors', 'Off');
define('LAST_MODIFIED', filemtime(__DIR__ . '/library/globals.php'));
}
// require Spoon
require_once 'spoon/spoon.php';
Spoon::setDebug(SPOON_DEBUG);
/**
* @remark only for SumoCoders
*
* Here we initialize our Sumo class, which will add some Sumo specific stuff
* into this Fork instance.
*/
$sumo = new SumoCoders\SumoForkClass\SumoForkClass();
$sumo->setErrbitApiKey(ERRBIT_API_KEY);
$sumo->setDebug(SPOON_DEBUG);
$sumo->init();
// require frontend-classes
spl_autoload_register(array('Init', 'autoLoader'));
// disable magic quotes
SpoonFilter::disableMagicQuotes();
}
/**
* AutoLoader
*
* @param string $class The class that should be loaded.
*/
public static function autoLoader($class)
{
$exceptions = array(
'ajaxaction' => 'ajax_action',
'defaultentity' => 'default_entity'
);
// ignore case
$class = strtolower($class);
// an exception?
if(in_array($class, array_keys($exceptions))) $class = $exceptions[$class];
// remove prefix
if($class != 'site' && substr($class, 0, 4) == 'site') $class = substr($class, 4);
// data grid
if(substr($class, 0, 8) == 'datagrid') $class = 'datagrid';
// rebuild filename
$filename = $class . '.php';
$path = PATH_WWW . '/core/classes/' . $filename;
if(file_exists($path))
{
require_once $path;
return;
}
$path = PATH_WWW . '/modules/' . $class . 's/model/model.php';
if(file_exists($path))
{
require_once $path;
return;
}
$path = PATH_LIBRARY . '/external/' . $filename;
if(file_exists($path))
{
require_once $path;
return;
}
}
}