forked from gizmore/gdo6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
112 lines (101 loc) · 2.77 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
<?php
use GDO\Core\Application;
use GDO\Core\Debug;
use GDO\Core\Logger;
use GDO\Language\Trans;
use GDO\UI\GDT_Page;
use GDO\User\GDO_User;
use GDO\Session\GDO_Session;
use GDO\DB\Database;
use GDO\Core\ModuleLoader;
use GDO\Core\Website;
use GDO\UI\GDT_Container;
use GDO\UI\GDT_HTML;
use GDO\Core\GDT_Error;
set_include_path('.');
include 'GDO6.php';
@include 'protected/config.php';
if (!defined('GWF_CONFIGURED'))
{
echo "<!DOCTYPE html><html><body><h1>GDO6</h1><p>Please create a config.php, preferrably with <a href=\"install/wizard.php\">the install wizard.</a></p></body></html>\n";
die();
}
$page = GDT_Page::make('page');
Database::init();
new ModuleLoader(GDO_PATH . 'GDO/');
GDO_Session::init(GWF_SESS_NAME, GWF_SESS_DOMAIN, GWF_SESS_TIME, !GWF_SESS_JS, GWF_SESS_HTTPS);
$app = new Application();
# Bootstrap
Trans::$ISO = GWF_LANGUAGE;
Logger::init(null, GWF_ERROR_LEVEL); # 1st init as guest
Debug::init();
Debug::enableErrorHandler();
Debug::enableExceptionHandler();
Debug::setDieOnError(GWF_ERROR_DIE);
Debug::setMailOnError(GWF_ERROR_MAIL);
ModuleLoader::instance()->loadModulesCache();
GDO_Session::instance();
if (GDO_User::current()->isAuthenticated())
{
# @TODO: username can be ambigious? check if guests and members can have the same name. if so make sure the guest prefix is a valid filename on all filesystems.
Logger::init(GDO_User::current()->getUserName(), GWF_ERROR_LEVEL); # 2nd init with username
}
# All fine!
define('GWF_CORE_STABLE', 1);
try
{
$rqmethod = $_SERVER['REQUEST_METHOD'];
if (!in_array($rqmethod, ['GET', 'POST'], true))
{
die('METHOD not processed: ' . $rqmethod);
}
# Exec
ob_start();
$method = $app->getMethod();
$response = $method->exec();
}
catch (Throwable $e)
{
Logger::logException($e);
Debug::debugException($e, false); # send exception mail
$response = GDT_Error::responseException($e);
}
finally
{
$content = ob_get_contents();
ob_end_clean();
}
# Render Page
switch ($app->getFormat())
{
case 'json':
if ($session = GDO_Session::instance())
{
$session->commit();
}
if ($content)
{
echo $content;
}
if ($response)
{
Website::renderJSON($response->renderJSON());
}
die(0);
break;
case 'html':
if ($app->isAjax())
{
$out = $response->renderHTML();
}
else
{
$container = GDT_Container::make('c1')->addFields([GDT_HTML::withHTML($content), $response]);
$out = $page->html($container->renderCell())->renderCell();
}
}
if ($session = GDO_Session::instance())
{
$session->commit();
}
echo $out;