-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
209 lines (150 loc) · 4.83 KB
/
bootstrap.php
File metadata and controls
209 lines (150 loc) · 4.83 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<? /* Bolt it on
------------------------------
** Webninja bootstrap file
** July 2013
------------------------------
** Here we go */
// Initiate session
session_start();
// Define stucture APP path
define( 'APP', 'app' );
// Define stucture LIBRARY path
define( 'SYSTEM', 'system' );
// Define stucture LIBRARY path
define( 'LIBRARY', SYSTEM.'/library' );
// Define stucture ADMIN path
define( 'ADMIN', APP.'/admin/' );
// Define the config file
if (file_exists(dirname(PATH).'/config/config.php')) {
/** The config file resides one level above the main directory */
require_once(dirname(PATH).'/config/config.php');
};
// URL - Edit root URL
$site_url = 'http://'.$_SERVER['HTTP_HOST'].'/';
// Sitename
if(isset($_GET['site'])){
$siteslug = $_GET['site'];
}
// Define parent URL
define( 'URL', $site_url);
/* Check to see if the site is being previewed or if looking
through the domain */
if(isset($siteslug)){
// When looking through preview
$site = $db->get_row("SELECT * FROM app_sites WHERE site_slug = '$siteslug'");
$preview = true;
// Define parent preview nav path
define( 'NAV', URL.'preview/'.$siteslug.'/');
} else {
// When loading site domain
$site = $db->get_row("SELECT * FROM app_sites WHERE site_url = '$site_url'");
$preview = false;
// Define parent nav path
define( 'NAV', URL);
}
if(isset($site)){
// Define SITE ID
define('SITE_ID', $site->id);
// Define the Site folder
define('SITE', APP.'/sites/'.SITE_ID);
// Set site theme
$theme = $site->site_theme;
if($theme != ''){
// If theme is set...
define( 'THEME', APP.'/themes/'.$theme);
} else {
// Use setup them
define( 'THEME', APP.'/themes/setup' );
}
//echo SITE;
} else {
echo 'No site';
}
// Load in the classes
require_once(SYSTEM . '/system_classes.php' );
// Setup the page class
$page = new Page($db);
// Load the appropriate pages to run the Webninja platform
// a) Check to see if there is a page asssociated to the URL...
if(isset($_GET['pagename'])){
// b) Check for admin url and get us outta here as long as it's not a preview and its the Webninja platform
if($preview == false || SITE_ID == '1'){
// Variables in place of /admin/ - admin, dashboard, manager
if($_GET['pagename'] == 'admin' || $_GET['pagename'] == 'dashboard' || $_GET['pagename'] == 'manager' ){
header('location: /admin/');
exit;
};
};
$pagemap = $page->page_map($_GET['pagename']);
} else {
// a) Else define the homepage
$pagemap = $page->page_map('home-page');
}
// Setup the user class
$user = new User($db);
$user->login_submit();
// Load in the functions
require_once(SYSTEM . '/system_functions.php' );
// Kickstart the views/theme delivery
// Check to see if there is a page asssociated to the URL
if(isset($_GET['pagename'])){
$pagemap = $page->page_map($_GET['pagename']);
if($pagemap == '404'){
if (file_exists(SITE.'/404.php')){
require_once(SITE . '/404.php');
} else {
require_once(THEME . '/404.php');
}
} else if ($pagemap->pagename == 'home-page') {
header('location:'.URL);
} else {
// If page exists, determine what template to load
if($pagemap->pagetemplate == ''){
// Load the default page template if no template is listed in the database
if (file_exists(SITE.'/page.php')){
require_once(SITE . '/page.php');
} else {
require_once(THEME . '/page.php');
}
} elseif($pagemap->pagetemplate == 'user'){
// Check to see if the page is a user page
$username = $page->get_profile();
// If the username exists in the database
if(isset($username->username)){
// Load the global user template
require_once(SITE . '/user-profile.php');
} elseif ($username == 'undefined'){
// If no username is defined, load user landing page
if (file_exists(SITE.'/page-'.$pagemap->pagetemplate.'.php')){
require_once(SITE . '/page-'.$pagemap->pagetemplate.'.php');
} else {
require_once(THEME . '/page-'.$pagemap->pagetemplate.'.php');
}
} else {
// If username doesn't exist, load 404 page
if (file_exists(SITE.'/404.php')){
require_once(SITE . '/404.php');
} else {
require_once(THEME . '/404.php');
} }
} elseif($pagemap->pagetemplate == 'login'){
// Load the default page template if no template is listed in the database
require_once(SITE . '/login.php');
} else {
// If there is a unique template, load the custom template
// Custom templates are saved in the theme folder as page-templatename.php
if (file_exists(SITE.'/page-'.$pagemap->pagetemplate.'.php')){
require_once(SITE . '/page-'.$pagemap->pagetemplate.'.php');
} else {
require_once(THEME . '/page-'.$pagemap->pagetemplate.'.php');
}
}
}
} else {
// Is homepage
if (file_exists(SITE.'/index.php')){
require_once(SITE . '/index.php');
} else {
require_once(THEME . '/index.php');
}
}