-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
107 lines (89 loc) · 2.95 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
<?php
define ( 'FLUIDFRAME', true );
define ( 'INSTALLDIR', dirname ( __FILE__ ) );
require_once (INSTALLDIR . '/version.php');
require_once (INSTALLDIR . '/lib/core.php');
try {
Fluidframe::init ();
$_lang = common_language ();
} catch ( Exception $e ) {
common_error ( $e->getTraceAsString () );
$error = new ErrorAction ( 'en' );
$error->setErrorMessage ( 500, $e->getMessage () );
$error->handle ();
}
function getPath($req) {
if ((common_config('site', 'fancy') || !array_key_exists('PATH_INFO', $_SERVER))
&& array_key_exists('p', $req)
) {
$path = $req['p'];
if(substr($path,0,1) == '/') {
$path = substr($path,1);
}
return $path;
} else if (array_key_exists('PATH_INFO', $_SERVER)) {
$path = $_SERVER['PATH_INFO'];
$script = $_SERVER['SCRIPT_NAME'];
if (substr($path, 0, mb_strlen($script)) == $script) {
return substr($path, mb_strlen($script));
} else {
return $path;
}
} else {
return null;
}
}
$path = getPath($_REQUEST);
$r = Router::get();
$args = $r->map($path);
if (!$args) {
$error = new ErrorAction ( $_lang );
$error->setErrorMessage ( 404, 'Unkown page' );
$error->handle ();
return;
}
// do I have a lang in URL?
if(isset($args['lang'])) {
$__lang = $args['lang'];
$__all_lang = common_config('site','langs');
if(isset($__all_lang[$__lang])) {
$_lang = $__lang;
}
}
// does the route indicate an action?
if (isset ( $args['action'] )) {
// take the action class directly from the route
$action = $args['action'];
} else {
// use a default action class
$action = 'index';
}
$action_class = ucfirst ( $action ) . 'Action';
if (! class_exists ( $action_class )) {
$error = new ErrorAction ( $_lang );
$error->setErrorMessage ( 400, 'Unkown action <' . $action_class . '>' );
$error->handle ();
}
$actionClass = new $action_class ( $_lang );
try {
$args = array_merge($args, $_REQUEST);
if ($actionClass->prepare ( $args )) {
$actionClass->handle ();
}
} catch ( ClientException $e ) {
$error = new ErrorAction ( $_lang );
$error->setErrorMessage ( $e->getCode (), 'ClientException:' . $e->getMessage () );
$error->handle ();
} catch ( ServerException $e ) {
$error = new ErrorAction ( $_lang );
$error->setErrorMessage ( $e->getCode (), 'ServerException: ' . $e->getMessage () );
$error->handle ();
} catch ( FluidframeException $e ) {
$error = new ErrorAction ( $_lang );
$error->setErrorMessage ( 500, 'FluidframeException: ' . $e->getMessage () );
$error->handle ();
} catch ( Exception $e ) {
$error = new ErrorAction ( $_lang );
$error->setErrorMessage ( 500, 'Exception: ' . $e->getMessage () );
$error->handle ();
}