-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
137 lines (120 loc) · 3.78 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
126
127
128
129
130
131
132
133
134
135
136
137
<?php
require_once('./core/coreLoader.php');
require_once('./core/ViewUtils.php');
try {
/*******************************************************************************
* Check the TARGET
*/
// DEBUG mode
Console::setDebug(false);
Console::d('Debug status', Console::isDebug() ? 'enable' : 'disable');
// Mandatory vars
$target = CoreUtils::TARGET_T_HOME;
$fullModule = null;
$module = null;
$subModule = null;
$title = 'Home';
$desc = 'Welcome';
$subTitle = null;
$subDesc = null;
$readmeHtml = null;
if (!empty($_GET)) {
if (isset($_GET[CoreUtils::TARGET_T_PLAY])) {
$target = CoreUtils::TARGET_T_PLAY;
}
else if (isset($_GET[CoreUtils::TARGET_T_CONFIG])) {
$target = CoreUtils::TARGET_T_CONFIG;
}
else if (isset($_GET[CoreUtils::TARGET_T_SETUP])) {
$target = CoreUtils::TARGET_T_SETUP;
}
else if (isset($_GET[CoreUtils::TARGET_T_LOG])) {
$target = CoreUtils::TARGET_T_LOG;
}
else {
throw new Exception('Unknow target');
}
$fullModule = $_GET[$target];
$exTargetV = explode('_', $fullModule);
$module = $exTargetV[0];
$subModule = count($exTargetV) > 1 ? $exTargetV[1] : substr($target, 0, 1) . 'Main';
}
/*******************************************************************************
* Check the MODULE + SUB MODULE
*/
switch ($target) {
case CoreUtils::TARGET_T_PLAY:
case CoreUtils::TARGET_T_CONFIG:
if (!Config::getInstance()->isValidModule($target, $module, $subModule))
throw new Exception('Unknow module or submodule');
else {
$manifest = Config::getInstance()->getModuleManifest($module);
$title = $manifest['name'];
$desc = $manifest['desc'];
$subTitle = $manifest[$target][$subModule]['name'];
$subDesc = $manifest[$target][$subModule]['desc'];
$readmeHtml = CoreUtils::getModuleReadme($module);
}
break;
// SETUP
case CoreUtils::TARGET_T_SETUP:
if (!empty($module) and strcasecmp($module, 'run')==0) {
try {
Setup::exec();
} catch (Exception $e) {
Console::e('setup', 'Setup fail Exception', $e);
}
}
$title = 'Setup';
$desc = 'Check and initialize the system';
$readmeHtml = "To load, refresh or update all available <em>Modules</em>.";
break;
// LOG
case CoreUtils::TARGET_T_LOG:
if (!empty($module) and strcasecmp($module, 'run')==0) {
try {
Setup::exec();
} catch (Exception $e) {
Console::e('setup', 'Setup fail Exception', $e);
}
}
$title = 'Log';
$desc = 'See log contents';
$readmeHtml = "To read all generated log. Log are spread into files : one new file each month.";
break;
case CoreUtils::TARGET_T_HOME:
default:
$readmeHtml = CoreUtils::mdParse('README.md');
break;
}
} catch (Exception $e) {
Console::w('index', 'target' , $_GET);
Console::w('index', 'module' , $module);
Console::w('index', 'subModule' , $subModule);
Console::e('index', 'exception', $e);
$target = CoreUtils::TARGET_T_HOME;
}
if (!Setup::isOk()) {
Console::e('index.setup', 'Setup or system update is required.');
}
/*******************************************************************************
* Build Menus
*/
$playMenuHtml = ViewUtils::buildPlayMenu();
$configMenuHtml = ViewUtils::buildConfigMenu();
/*******************************************************************************
* Build API URL
*/
$fullUrl = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$exUrl = explode('?', $fullUrl);
if (count($exUrl) > 1)
$baseUrl = $exUrl[0];
else
$baseUrl = $fullUrl;
$baseUrl = str_replace('index.php', '', $baseUrl);
$baseApiUrl = "{$baseUrl}api.php?$target=$fullModule";
/*******************************************************************************
* DISPLAY
*/
include('./core/view/main.php');
Console::getInstance()->toLogFile();