-
Notifications
You must be signed in to change notification settings - Fork 1
/
ddd.php
337 lines (260 loc) · 10.4 KB
/
ddd.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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?php
/**
* @license
* ddd / module-connexion
* Copyright (c) 2022 Abraham Ukachi
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @project module-connexion
* @name DDD (triple d || 3D)
* @file api/ddd.php
* @author: Abraham Ukachi <[email protected]>
* @version: 0.0.1
*
* Usage:
* 1-|> include __DIR__ . 'api/ddd.php';
* -|> $ddd = new DDD();
*
*
* 2-|> $currentView = $ddd->getCurrentView(DDD::SETTINGS_VIEW_DEFAULT);
* -|> echo $currentView;
* |
* o=|> 'language' // <- output will differ based on the current view
*
*
* 3-|> $currentPage = $ddd->getCurrentPage(DDD::PAGE_DEFAULT);
* -|> echo $currentPage;
* |
* o=|> 'home' // <- output will differ based on the current page
*
* ============================
* IMPORTANT: A Web App without an API is like coffee without water :)
* ============================
*/
/*
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* MOTTO: I'll always do more 😜!!!
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
// start a session
session_start();
/*
* The main class of our `module-connexion` Web App named `DDD` (3d)
* NOTE: This class contains all the necessary / major constant variables related to this app.
*/
class DDD {
// Defining some constants ...
// THEMES
const THEME_CLASSIC = 'classic';
const THEME_LIGHT = 'light';
const THEME_DARK = 'dark';
// Define the currently supported themes by this app as `THEMES`
// NOTE: This is a short syntax index array which only contains the name or key of the themes (e.g. 'dark')
const THEMES = [self::THEME_CLASSIC, self::THEME_LIGHT, self::THEME_DARK];
// default theme
const THEME_DEFAULT = self::THEME_DARK;
// PAGES
const PAGE_HOME = 'home';
const PAGE_DDD_STUDIO = 'ddd-studio';
const PAGE_LOGIN = 'connexion';
const PAGE_REGISTER = 'inscription';
const PAGE_PROFILE = 'profil';
const PAGE_SETTINGS = 'settings';
const PAGE_SPLASH_SCREEN = 'splash-screen';
const PAGE_ADMIN = 'admin';
// QUERIES
const QUERY_ROUTE = 'route';
const QUERY_VIEW = 'view';
const QUERY_DIALOG = 'dialog';
const QUERY_STEP = 'step';
// DIALOGS
const DIALOG_DELETE_ACCOUNT = 666;
/* ----< VIEWS >---- */
// settings view
const VIEW_SETTINGS_DEFAULT = 'home';
const VIEW_SETTINGS_ABOUT = 'about';
const VIEW_SETTINGS_LANGUAGE = 'lang';
const VIEW_SETTINGS_THEME = 'theme';
/* ---> End of VIEWS <--- */
/* ----< ROUTES >---- */
// admin routes
const ROUTE_ADMIN_USERS = 'users';
const ROUTE_ADMIN_DASHBOARD = 'dashboard';
/* ---> End of ROUTES <--- */
// the base directory of this app (from the 'api/' folder)
const DIR_BASE = '../';
// defaults
// TODO: Get the default lang with `substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2)` (https://stackoverflow.com/questions/3770513/detect-browser-language-in-php)
const LANGUAGE_DEFAULT = 'en'; // <- english
// Define the current language variable as `LANGUAGE`
// Get the currrent language from SESSION as `lang`
// if it exists, else use 'en' (English) as default
//const APP_LANGUAGE = isset($_SESSION['lang']) ? $_SESSION['lang'] : self::LANGUAGE_DEFAULT;
//const APP_LANGUAGE = ;
//
// public $language = isset($_SESSION['lang']) ? $_SESSION['lang'] : 'en';
// TODO: Create an `APP_THEME` constant for the current theme of the app
/**
* The constructor function that is executed every time this `DDD` class is instantiated.
*/
public function __construct() {
// TODO: do something life-changing here ;)
}
// PUBLIC GETTERS
/**
* Returns the current language of the app.
*
* @return string
*/
public function getCurrentLanguage() {
return isset($_SESSION['lang']) ? $_SESSION['lang'] : self::LANGUAGE_DEFAULT;
}
/**
* Returns the current theme of the app.
*
* @return string
*/
public function getCurrentTheme() {
return isset($_SESSION['theme']) ? $_SESSION['theme'] : self::THEME_DEFAULT;
}
/**
* Returns the current page of this app.
*
* @param string $defaultPage - The default page of the app (i.e. 'home' or PAGE_DEFAULT)
* @param bool $EXT - If TRUE, the extension (eg. 'php') of the current page will be added
*
* @return string - Current page
*/
public function getCurrentPage($defaultPage = self::PAGE_HOME, $EXT = false) {
// Extracting the current page from location's url...
// TIPS:
// $_SERVER['SERVER_NAME']: The name of the server host under which the current script is executing.
// ^^^^^^^^^^^^^^ returns 'localhost'
//
// $_SERVER['REQUEST_URI']: The URI which was given in order to access this page.
// ^^^^^^^^^^^^^^ returns '/module-connexion/settings.php?view=theme'
//
// $_SERVER['SCRIPT_FILENAME']: The absolute pathname of the currently executing script.
// ^^^^^^^^^^^^^^ returns '/Applications/XAMPP/xamppfiles/htdocs/module-connexion/settings.php'
//
// $_SERVER['PHP_SELF']: The filename of the currently executing script.
// ^^^^^^^^^^^^^^ returns '/module-connexion/settings.php'
// Intialize the `currentPage` variable
$currentPage = '';
// TODO: Remove the try/catch blocks below asap. Not Necessary ?
try { // <- let's try to extract the current page (eg. 'settings') from PHP's SERVER
// Get the filename of the current page from PHP's `SERVER` global/reserved variable as `pathname`
$pathname = $_SERVER['PHP_SELF'];
// IDEA: Split the `pathname` with a '/' separator, and use the last item from the list.
$splitPathname = explode('/', $pathname);
// Update the $currentPage with the last item from `splitPathname`
$currentPage = end($splitPathname); // <- returns eg. 'settings.php'
// If `$EXT` is FALSE (a.k.a no extension needed)...
if ($EXT === false) {
// ...split the `$currentPage` with '.' separator (or explode on `.` to an array)
$currentPageParts = explode('.', $currentPage);
// remove the last item or extension from `$currentPageParts` array
array_pop($currentPageParts);
// Join what's left of `$currentPageParts` and update the `$currentPage` accordingly
$currentPage = implode('.', $currentPageParts);
}
}catch (Exception $e) {
// DEBUG [4dbsmaster]: tell me about this error
die($e->getMessage());
}
return (!empty($currentPage)) ? $currentPage : $defaultPage;
}
/**
* Returns the current view of this settings page from the GET parameters.
*
* Example:
*
* $ddd->getCurrentView(DDD::VIEW_SETTINGS_DEFAULT)
*
* @param string $defaultView - The default view of the current page
* @return string : Current view (eg. 'home', 'language', 'about', ..).
*/
public function getCurrentView($defaultView = '') {
// Using our beloved ternary statment, return the value of `view` parameter
// from PHP's global variable GET,only if `view` exists,
// otherwise, just return the given default view
return isset($_GET['view']) ? $_GET['view'] : $defaultView;
}
/**
* Returns the current route of the page.
*
* Example:
*
* $ddd->getCurrentRoute()
*
* @param string $defaultRoute - The default route of the current page
*
* @return string : Current route (eg. 'users', 'dashboard', ..).
*/
public function getCurrentRoute($defaultRoute = '') {
// Using our beloved ternary statment, return the value of `route` parameter
// from PHP's global variable GET,only if `route` exists,
// otherwise, just return the given `defaultRoute`
return isset($_GET[self::QUERY_ROUTE]) ? $_GET[self::QUERY_ROUTE] : $defaultRoute;
}
// PUBLIC SETTERS
// PUBLIC FUNCTIONS
// PRIVATE GETTERS
/**
* Returns an alphabetical color set.
* NOTE: This is a multidimensional array.
*
* @return array
* @private
*/
public function getAlphaColorSet() {
return array(
'a' => ['bgColor' => 'darkorange', 'fgColor' => 'white'],
'b' => ['bgColor' => 'darkred', 'fgColor' => 'white'],
'c' => ['bgColor' => 'darkgreen', 'fgColor' => 'white'],
'd' => ['bgColor' => 'darkyellow', 'fgColor' => 'white'],
'e' => ['bgColor' => 'darkblue', 'fgColor' => 'white'],
'f' => ['bgColor' => '#13005A', 'fgColor' => 'white'],
'g' => ['bgColor' => '#0A2647', 'fgColor' => 'white'],
'h' => ['bgColor' => '#1A120B', 'fgColor' => 'white'],
'i' => ['bgColor' => '#453C67', 'fgColor' => 'white'],
'j' => ['bgColor' => '#2D033B', 'fgColor' => 'white'],
'k' => ['bgColor' => '#00005C', 'fgColor' => 'white'],
'l' => ['bgColor' => '#000000', 'fgColor' => 'white'],
'm' => ['bgColor' => '#404258', 'fgColor' => 'white'],
'n' => ['bgColor' => '#3F3B6C', 'fgColor' => 'white'],
'o' => ['bgColor' => '#4C0033', 'fgColor' => 'white'],
'p' => ['bgColor' => '#182747', 'fgColor' => 'white'],
'q' => ['bgColor' => '#16213E', 'fgColor' => 'white'],
'r' => ['bgColor' => '#472D2D', 'fgColor' => 'white'],
's' => ['bgColor' => '#2C3333', 'fgColor' => 'white'],
't' => ['bgColor' => '#2E0249', 'fgColor' => 'white'],
'u' => ['bgColor' => '#180A0A', 'fgColor' => 'white'],
'v' => ['bgColor' => '#46244C', 'fgColor' => 'white'],
'w' => ['bgColor' => '#191919', 'fgColor' => 'white'],
'x' => ['bgColor' => '#041C32', 'fgColor' => 'white'],
'y' => ['bgColor' => '#1F1D36', 'fgColor' => 'white'],
'z' => ['bgColor' => '#420516', 'fgColor' => 'white']
);
}
// PRIVATE SETTERS
// PRIVATE FUNCTIONS
}
?>