-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
executable file
·125 lines (106 loc) · 4.52 KB
/
index.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
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* i³gel || iiigel
* (c) 2015 - date('Y')
*
* Mario Haim <[email protected]>
*/
error_reporting(E_ALL);
session_start();
$GLOBALS['dInit'] = microtime(TRUE);
$GLOBALS['sDebugOutput'] = '';
define('VERSION', '0.1');
define('PATH_DIR', __DIR__.'/');
require_once(PATH_DIR.'config/main.php');
require_once(PATH_DIR.'vendor/autoload.php');
require_once(PATH_DIR.'src/functions.php');
set_exception_handler('except');
date_default_timezone_set($GLOBALS['aConfig']['sTimeZone']);
define('PATH_URL', ((isset($GLOBALS['aConfig']['sRootPath']) && $GLOBALS['aConfig']['sRootPath'] !== '' && $GLOBALS['aConfig']['sRootPath'] !== '/')? (($GLOBALS['aConfig']['sRootPath']{0} == ':')?($GLOBALS['aConfig']['sRootPath'].'/'):('/'.$GLOBALS['aConfig']['sRootPath'].'/')):'/'));
define('URL', (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https://' : 'http://').$_SERVER['SERVER_NAME'].PATH_URL);
$GLOBALS['bAutoPermission'] = false;
$GLOBALS['aRequest'] = array_merge_recursive($_POST, $_GET);
$GLOBALS['bAjax'] = isset($GLOBALS['aRequest']['c']) ? TRUE : FALSE;
require_once(PATH_DIR.'config/language.php');
$GLOBALS['sLanguage'] = $GLOBALS['aConfig']['aLanguage']['sDefaultCountry'];
$GLOBALS['sDomain'] = $GLOBALS['aConfig']['aLanguage']['sDefaultDomain'];
$GLOBALS['oDb'] = new \Iiigel\Generic\Database();
\Iiigel\Model\User::checkLogin();
//find controller, action, and action params
$aParam = array();
require_once(PATH_DIR.'config/controller-dict.php');
if($GLOBALS['bAjax']) {
$GLOBALS['aRequest']['c'] = '\\Iiigel\\Controller\\'.$GLOBALS['aRequest']['c'];
} else {
$GLOBALS['aRequest']['c'] = isset($GLOBALS['oUserLogin']) ? '\\Iiigel\\Controller\\Dashboard' : '\\Iiigel\\Controller\\StaticPage';
if(isset($GLOBALS['aRequest']['path'])) {
$aTemp = explode('/', $GLOBALS['aRequest']['path']);
for($i = 0; $i < count($aTemp); $i++) {
if(isset($GLOBALS['aConfig']['aController'][$aTemp[$i]])) {
$aTemp[$i] = $GLOBALS['aConfig']['aController'][$aTemp[$i]];
}
}
for($i = count($aTemp) - 1; $i >= 0; $i--) {
$sController = '\\Iiigel\\Controller\\'.implode('\\', array_slice($aTemp, 0, ($i+1)));
if(class_exists($sController)) {
$GLOBALS['aRequest']['c'] = $sController;
$i++;
if(isset($aTemp[$i])) {
if(method_exists($sController, $aTemp[$i])) {
$GLOBALS['aRequest']['a'] = $aTemp[$i];
} else {
$aParam[] = $aTemp[$i];
}
for($j = $i+1; $j < count($aTemp); $j++) {
$aParam[] = $aTemp[$j];
}
}
break;
}
}
}
}
if(class_exists($GLOBALS['aRequest']['c'])) {
$oApp = new $GLOBALS['aRequest']['c']();
//find action
if(!isset($GLOBALS['aRequest']['a']) || !method_exists($oApp, $GLOBALS['aRequest']['a'])) {
$GLOBALS['aRequest']['a'] = $GLOBALS['aRequest']['c']::DEFAULT_ACTION;
}
//find additional action params
$oReflection = new \ReflectionMethod($oApp, $GLOBALS['aRequest']['a']);
$aMethodParam = $oReflection->getParameters();
for($i = 0; $i < count($aMethodParam); $i++) {
$aMethodParam[$i] = $aMethodParam[$i]->name;
if(!isset($aParam[$i]) && isset($GLOBALS['aRequest'][$aMethodParam[$i]])) {
$aParam[$i] = $GLOBALS['aRequest'][$aMethodParam[$i]];
}
}
//log action for currently logged-in user
if(isset($GLOBALS['oUserLogin'])) {
$GLOBALS['oUserLogin']->action();
}
call_user_func_array(array($oApp, $GLOBALS['aRequest']['a']), $aParam);
echo $oApp->output();
}
//debug, depending on call format
if(!$GLOBALS['bAjax'] && $GLOBALS['aConfig']['bDebug']) {
$aParam = $GLOBALS['aRequest'];
unset($aParam['a'], $aParam['c']);
debug(
array(
_('debug.executiontime') => microtime(TRUE) - $GLOBALS['dInit'],
_('debug.version') => VERSION,
_('debug.url') => URL,
_('debug.urlpath') => PATH_URL,
_('debug.basepath') => PATH_DIR,
_('debug.controller') => $GLOBALS['aRequest']['c'],
_('debug.action') => $GLOBALS['aRequest']['a'],
_('debug.params') => $aParam,
_('debug.session') => session_id(),
_('debug.loggedinuser') => isset($GLOBALS['oUserLogin']) ? $GLOBALS['oUserLogin'] : NULL
),
_('debug.pagegenerationstats')
);
}
echo $GLOBALS['sDebugOutput'];
?>