-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Index.php
239 lines (179 loc) · 6.13 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
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
<?php
# Index.php
session_start();
# Load the "Folders.php" file to define the folders
require "Folders.php";
if (function_exists("str_contains") == False) {
function str_contains($haystack, $needle) {
return $needle !== "" && mb_strpos($haystack, $needle) !== False;
}
}
if (function_exists("array_insert") == False) {
function array_insert(&$array, $position, $insert) {
if (is_int($position)) {
array_splice($array, $position, 0, $insert);
}
else {
$position = array_search($position, array_keys($array));
$array = array_merge(
array_slice($array, 0, $position),
$insert,
array_slice($array, $position)
);
}
return $array;
}
}
# Load the auto linker
require $folders["Mega"]["PHP"]["Modules"]["root"]."lib_autolink.php";
# Loads the classes, including the module ones (Slim, RainTPL)
require $folders["Mega"]["PHP"]["Classes"]["Loader"];
if (isset($parse) == False) {
$parse = parse_url($_SERVER["REQUEST_URI"])["path"];
}
# Define the local switches
$switches = $Global_Switches -> global_switches;
$has_switches = False;
# Check if the "_GET" variable contains switches
foreach (array_keys($Global_Switches -> global_switches) as $switch) {
if (
isset($_GET[$switch]) == True or
isset($_POST[$switch]) == True
) {
if (isset($_GET[$switch]) == True) {
$method = $_GET;
}
if (isset($_POST[$switch]) == True) {
$method = $_POST;
}
$switches[$switch] = (string)$method[$switch];
$switches[$switch] = filter_var($method[$switch], FILTER_VALIDATE_BOOLEAN);
$has_switches = True;
}
}
# Switch to either the default switches or the modified ones
$Global_Switches -> Switch($switches);
# If the local switches and global switches were not equal, reload classes
if ($switches != $Global_Switches -> switches) {
# Loads the classes, including the module ones (Slim, RainTPL)
require $folders["Mega"]["PHP"]["Classes"]["Loader"];
}
# Creates the "website" array and fills it
require $folders["PHP"]["Website"];
# Runs the "SQL.php" file to update the database with the website information
require $folders["PHP"]["SQL"];
# Assign the website array and the Language class instance variables to RainTPL
$tpl -> assign("website", $website);
$tpl -> assign("Language", $Language);
$tpl -> assign("parse", $parse);
$tpl -> assign("website", $website);
function Generate_Website() {
global $tpl;
global $website;
global $folders;
global $parse;
global $File;
# Create website HTML for generate route
$website["html"] = "";
$website["html"] .= $tpl -> draw("Head", $toString = True);
if ($website["language"] != "general") {
$website["html"] .= $tpl -> draw("Body", $toString = True);
}
$website["html"] .= $tpl -> draw("Footer", $toString = True);
# Define HTML file for website
$html_file = $website["Data"]["Folders"]["Local website"]["Language"]."Index.html";
# Define website state
if (file_exists($html_file) == False) {
$website["state"] = $website["Language texts"]["the_website_file_did_not_exist_the_new_content_was_written_into_it"];
}
# Create the file
$File -> Create($html_file);
$old_contents = $File -> Contents($html_file, $add_br = False, $add_n = False);
# Update the HTML file with the website contents
$File -> Edit($html_file, $website["html"], "w");
$new_contents = $File -> Contents($html_file, $add_br = False, $add_n = False);
if (file_exists($html_file) == True) {
$website["state"] = $website["Language texts"]["the_website_file_was_not_updated"];
if ($old_contents["string"] != $new_contents["string"]) {
$website["state"] = $website["Language texts"]["the_website_file_was_updated_with_the_new_content"];
}
}
# Show information about generated website
$website["Data"]["description"]["html"] = Text::Format($website["Language texts"]["website_to_generate_the_website_{}"], $website["Data"]["titles"]["language"]);
# Make backup of website title and define website title for Generate route
$website["Data"]["titles"]["backup"] = $website["Data"]["titles"]["language"];
$website["Data"]["titles"]["language"] = $website["Language texts"]["generate_website"].': "'.$website["Data"]["titles"]["backup"].'"';
$website["Data"]["titles"]["sanitized"] = str_replace('"', "'", $website["Data"]["titles"]["language"]);
# Define the website meta title
$website["Meta title"] = str_replace('"', "'", $website["Data"]["titles"]["language"]);
# Define website link
$website["Data"]["Links"]["Language"] = $website["Local URL"]["Index"];
# Remove JavaScript stuff
$website["javascript"]["links"] = "";
$website["javascript"]["links"] = "";
$website["javascript"]["class_attributes"]["body"] = "";
$parse = "/";
Generate_Form();
$website["content"] = "<br />"."<br />"."<br />"."<br />"."<br />"."\n\n".
$website["form"];
$tpl -> assign("website", $website);
$tpl -> assign("parse", $parse);
$tpl -> draw("Generate/Body", False);
}
# Define route for the Index ("Code" programming mode)
$slim -> get("/", function() {
global $tpl;
global $parse;
global $website;
if (
isset($website["mode"]) and
$website["mode"] == "Generate"
) {
header("Location: /generate");
exit;
}
$tpl -> draw("Body");
});
$slim -> post("/", function() {
global $tpl;
global $website;
if (
isset($website["mode"]) and
$website["mode"] == "Generate"
) {
header("Location: /generate");
exit;
}
$tpl -> draw("Body");
});
# Define route for the Select website page
$slim -> get("/select", function() {
global $tpl;
global $website;
$website["Data"]["titles"] = [
"language" => $website["Language texts"]["select_website"]
];
$website["Data"]["titles"]["sanitized"] = str_replace('"', "'", $website["Data"]["titles"]["language"]);
$website["content"] = "<br />"."<br />"."<br />"."<br />"."<br />"."\n\n".
$website["form"];
$tpl -> assign("website", $website);
$tpl -> draw("Select/Body");
});
# Define route for the Generate programming mode
$slim -> get("/generate", function() {
Generate_Website();
});
$slim -> post("/generate", function() {
Generate_Website();
});
# Run the Slim app to check routes
$slim -> run();
if ($website["verbose"] == True) {
if ($_POST != []) {
Text::Show_Variable($_POST);
}
if ($_GET != []) {
Text::Show_Variable($_GET);
}
}
?>