-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprivate_function.php
More file actions
182 lines (153 loc) · 7.13 KB
/
private_function.php
File metadata and controls
182 lines (153 loc) · 7.13 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
<?php
/*
Name: Function private
Purpose: Framework specific private function library
Author: Broken Arrow (SKJoy2001@GMail.Com);
Created: May 30, 2018 05:30 PM
Modified: June 17, 2018 03:36 AM
*/
namespace sPHP;
function ___LoadConfiguration($APP){
// Create useful shortcut variables to use within configuration script
$ENV = $APP->Terminal()->Environment();
if(!isset($CFG["LegacySupport_sPHP_LongLocalVariable"]) || $CFG["LegacySupport_sPHP_LongLocalVariable"]){
$Environment = $ENV;
}
// Load central configuration
require "{$APP->Terminal()->Environment()->Path()}system/configuration.php";
$Result = $Configuration;
// Load domain specific configuration
if(file_exists($ConfigurationScript = "{$APP->Terminal()->Environment()->DomainPath()}/system/configuration.php")){
require $ConfigurationScript;
$Result = array_merge($Result, $Configuration);
}
return $Result;
}
function ___ExecuteApplicationScript($APP, $TPL, $CFG){
// Make useful objects accessible through shortcut local variables
#region Update globalized resources
global $sPHP;
\sPHP::$Application = \sPHP::$APP = $sPHP["Application"] = $sPHP["APP"] = $APP;
\sPHP::$Configuration = \sPHP::$CFG = $sPHP["Configuration"] = $sPHP["CFG"] = $CFG;
$ENV = \sPHP::$Environment = \sPHP::$ENV = $sPHP["Environment"] = $sPHP["ENV"] = $APP->Terminal()->Environment();
$TRM = \sPHP::$Terminal = \sPHP::$TRM = $sPHP["Terminal"] = $sPHP["TRM"] = $APP->Terminal();
$SSN = \sPHP::$Session = \sPHP::$SSN = $sPHP["Session"] = $sPHP["SSN"] = $APP->Session();
$USR = \sPHP::$User = \sPHP::$USR = $sPHP["User"] = $sPHP["USR"] = $SSN->User();
$UTL = \sPHP::$Utility = \sPHP::$UTL = $sPHP["Utility"] = $sPHP["UTL"] = $ENV->Utility();
$DBG = \sPHP::$Debug = \sPHP::$DBG = $sPHP["Debug"] = $sPHP["DBG"] = $UTL->Debug();
\sPHP::$Template = \sPHP::$TPL = $sPHP["Template"] = $sPHP["TPL"] = $TPL;
$DTB = \sPHP::$Database = \sPHP::$DTB = $sPHP["Database"] = $sPHP["DTB"] = $APP->Database();
$TBL = \sPHP::$Table = \sPHP::$TBL = $sPHP["Table"] = $sPHP["TBL"] = $CFG["DatabaseTable"];
$LOG = \sPHP::$Log = \sPHP::$LOG = $sPHP["Log"] = $sPHP["LOG"] = $APP->Log();
if(!isset($CFG["LegacySupport_sPHP_LongLocalVariable"]) || $CFG["LegacySupport_sPHP_LongLocalVariable"]){ // Legacy support
$Application = $APP;
$Configuration = $CFG;
$Environment = $ENV;
$Terminal = $TRM;
$Session = $SSN;
$User = $USR;
$Utility = $UTL;
$Debug = $DBG;
$Template = $TPL;
$Database = $DTB;
$Table = $TBL;
}
#endregion Update globalized resources
#region Execute script
require "{$ENV->Path()}system/pre.php";
$_POST["_Script"] = strtolower($_POST["_Script"]);
$DebugCheckpointID = $DBG->StartCheckpoint("script/{$_POST["_Script"]}");
if(file_exists($ScriptToExecute = "{$ENV->ScriptPath()}{$_POST["_Script"]}.php")){
require $ScriptToExecute; // Execute script from application
if(file_exists($ScriptToExecute = "{$ENV->DomainPath()}script/{$_POST["_Script"]}.php"))require $ScriptToExecute; // Execute domain script only when Application script exists
}
else{ // Application script not found
if(($APP->UseSystemScript() || in_array($_POST["_Script"], [
// Below system scripts are always allowed to be executed
"user/signin",
"user/signinaction",
"user/password/reset",
"user/signout",
//"utility/settings/input",
//"utility/settings/action"
])) && file_exists($ScriptToExecute = "{$ENV->SystemPath()}script/{$_POST["_Script"]}.php")){
require $ScriptToExecute; // Execute script from framework
}
else{ // Framwork script not found
if(file_exists($ScriptToExecute = "{$ENV->ScriptPath()}error/http/404.php")){
require $ScriptToExecute; // Execute error script from application
}
else{ // Application error script not found
if($APP->UseSystemScript() && file_exists($ScriptToExecute = "{$ENV->SystemPath()}script/error/http/404.php")){
require $ScriptToExecute; // Execute error script from framework
}
else{ // Framework error script not found
trigger_error("Requested script '{$_POST["_Script"]}' not found!", E_USER_ERROR); // Trigger generic error
}
}
}
}
$DBG->StopCheckpoint($DebugCheckpointID);
require "{$ENV->Path()}system/post.php";
#endregion Execute script
//$APP->Terminal()->Flush(); // Required to set the contents in order of header and main
$APP->Terminal()->Suspended(false); // Automatically calls the Flush method of Terminal
if($APP->Terminal()->DocumentType() == DOCUMENT_TYPE_HTML && !isset($_POST["_MainContentOnly"])){ // Execute header & footer if not instructed to suppress
if(!isset($_POST["_NoHeader"])){ // Header
$APP->Terminal()->Mode(OUTPUT_BUFFER_MODE_HEADER); // Change buffer to header mode
$DebugCheckpointID = $DBG->StartCheckpoint("template/header.php");
// This is put here to exclusively use for Terminals that are real browsing devices
// Do not waste system resource if User device notificatin is not required
if($APP->UserDeviceNotification())require __DIR__ . "/include/useruserdevice_add.php"; // Register user device
require "{$ENV->Path()}template/header.php"; // Execute header script
if(file_exists($HeaderScript = "{$ENV->DomainPath()}template/header.php"))require $HeaderScript; // Execute domain header script
$DBG->StopCheckpoint($DebugCheckpointID);
$APP->Terminal()->Flush(); // Required to set the contents in order of header and main
}
if(!isset($_POST["_NoFooter"])){ // Footer
$APP->Terminal()->Mode(OUTPUT_BUFFER_MODE_MAIN); // Change back buffer to main mode
$DebugCheckpointID = $DBG->StartCheckpoint("template/footer.php");
require "{$ENV->Path()}template/footer.php"; // Execute footer script
if(file_exists($FooterScript = "{$ENV->DomainPath()}template/footer.php"))require $FooterScript; // Execute domain footer script
// This is put here to exclusively use for Terminals that are real browsing devices
// Do not waste system resource if User device notificatin is not required
if($APP->UserDeviceNotification())require __DIR__ . "/include/useruserdevicenotification_fetch.php"; // Fetch UserUserDeviceNotification
$DBG->StopCheckpoint($DebugCheckpointID);
}
}
return true;
}
function ___ExecuteTemplateView($Script, $VAR, $APP, $CFG){
// Make useful objects accessible through shortcut local variables
#region Update globalized resources
global $sPHP;
\sPHP::$Variable = \sPHP::$VAR = $sPHP["Variable"] = $sPHP["VAR"] = $VAR;
$ENV = \sPHP::$Environment;
$TRM = \sPHP::$Terminal;
$SSN = \sPHP::$Session;
$USR = \sPHP::$User;
$UTL = \sPHP::$Utility;
$DBG = \sPHP::$Debug;
$DTB = \sPHP::$Database;
$TBL = \sPHP::$Table;
$LOG = \sPHP::$Log;
if(!isset($CFG["LegacySupport_sPHP_LongLocalVariable"]) || $CFG["LegacySupport_sPHP_LongLocalVariable"]){ // Legacy support
$Variable = $VAR;
$Application = $APP;
$Configuration = $CFG;
$Environment = $ENV;
$Terminal = $TRM;
$Session = $SSN;
$User = $USR;
$Utility = $UTL;
$Debug = $DBG;
$Database = $DTB;
$Table = $TBL;
}
#endregion Update globalized resources
$DebugCheckpointID = $DBG->StartCheckpoint("template/view/{$Script}");
require $Script; // Execute script
$DBG->StopCheckpoint($DebugCheckpointID);
return true;
}
?>