-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.php
104 lines (97 loc) · 3.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
<?php
/**
* Mr. Password
* Copyright Dalegroup Pty Ltd 2012
*
*
* @package mrpassword
* @author Michael Dale <[email protected]>
*/
namespace mrpassword;
//it would be nice to have this above the namespace as currently it isn't too useful.
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
die('This program requires PHP 5.3.0 or higher to run.');
}
//get the directory root info
define(__NAMESPACE__ . '\ROOT', __DIR__);
define(__NAMESPACE__ . '\SYSTEM', ROOT . '/system');
/**
* Loader does all the important startup stuff.
*/
include(SYSTEM . '/loader.php');
$dont_redirect_to = array(
$config->get('script_path') . '/login/',
$config->get('script_path') . '/captcha/'
);
//store requested page in session, used to redirect user to correct page after login
if (!in_array($_SERVER['REQUEST_URI'], $dont_redirect_to)) {
$_SESSION['page'] = $_SERVER['REQUEST_URI'];
}
//check if user is browsing to the login or registration page
if ($url->get_action() == 'api' || $url->get_action() == 'login' || $url->get_action() == 'register' || $url->get_action() == 'forgot' || $url->get_action() == 'cron' || $url->get_action() == 'reset') {
//if already logged in redirect to the dashboard
if ($auth->logged_in()) {
header('Location: ' . $config->get('address') . '/');
}
else {
include(THEMES . '/'.CURRENT_THEME.'/pages/'.$url->get_action().'/index.php');
}
}
//public plugin
else if ($url->get_action() == 'public' || $url->get_action() == 'simple' || $url->get_action() == 'captcha') {
try {
if (!file_exists(THEMES . '/' . CURRENT_THEME . '/pages/' . $url->get_action() . '/index.php')) {
throw new \Exception('The theme action file "' . THEMES . '/' . CURRENT_THEME . '/pages/' . $url->get_action() . '/index.php' . '" could not be found.');
}
else {
include(THEMES . '/' . CURRENT_THEME . '/pages/' . $url->get_action() . '/index.php');
}
}
catch (\Exception $e) {
//send error if unable to find a theme file for the URL
$error->create(array('type' => '404', 'message' => $e->getMessage()));
}
}
//all other pages require authentication
else if ($auth->logged_in()) {
try {
//plugins
if ($url->get_action() == 'p') {
if (!file_exists(THEMES . '/' . CURRENT_THEME . '/pages/' . $url->get_action() . '/index.php')) {
throw new \Exception('The theme action file "' . THEMES . '/' . CURRENT_THEME . '/pages/' . $url->get_action() . '/index.php' . '" could not be found.');
}
else {
include(THEMES . '/' . CURRENT_THEME . '/pages/' . $url->get_action() . '/index.php');
}
}
//this is a first level url i.e /users/
else if ($url->get_module() == '' || $url->get_module() == 'category') {
if (!file_exists(THEMES . '/' . CURRENT_THEME . '/pages/' . $url->get_action() . '/index.php')) {
throw new \Exception('The theme action file "' . THEMES . '/' . CURRENT_THEME . '/pages/' . $url->get_action() . '/index.php' . '" could not be found.');
}
else {
include(THEMES . '/' . CURRENT_THEME . '/pages/' . $url->get_action() . '/index.php');
}
}
//this is a second level url i.e /users/view/
else {
if (!file_exists(THEMES . '/' . CURRENT_THEME . '/pages/' . $url->get_action() . '/' . $url->get_module(). '.php')) {
throw new \Exception('The theme action file "' . THEMES . '/' . CURRENT_THEME . '/pages/' . $url->get_action() . '/' . $url->get_module() . '.php' . '" could not be found.');
}
else {
include(THEMES . '/' . CURRENT_THEME . '/pages/' . $url->get_action() . '/' . $url->get_module() . '.php');
}
}
}
catch (\Exception $e) {
//send error if unable to find a theme file for the URL
$error->create(array('type' => '404', 'message' => $e->getMessage()));
}
}
else {
//if all else fails go to the login page
header('Location: ' . $config->get('address') . '/login/');
}
exit;
?>