Skip to content

Commit 6615539

Browse files
committed
I have made several improvements to various PHP files, functions, and classes.
And I also made several changes regarding Python programs that generate data that is read by PHP websites. For example, the programs "Watch_History", "GamePlayer", "Tasks", and "Stories".
1 parent e3319fb commit 6615539

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+728
-416
lines changed

Classes/File.php

+19-18
Original file line numberDiff line numberDiff line change
@@ -92,32 +92,33 @@ public function Contents($file, $add_br = True, $add_n = True) {
9292
array_push($contents["lines"], $this -> Replace_Text($line));
9393
}
9494

95-
if ($contents["lines"][0] == "") {
96-
$contents["lines"] = [];
97-
}
95+
$i = 0;
96+
foreach ($contents["lines"] as $line) {
97+
$contents["string"] .= $line;
98+
99+
if ($i != $contents["length"] - 1) {
100+
if ($add_br == True) {
101+
$contents["string"] .= "<br />";
102+
}
98103

99-
else {
100-
$i = 0;
101-
foreach ($contents["lines"] as $line) {
102-
$contents["string"] .= $line;
103-
104-
if ($i != $contents["length"] - 1) {
105-
if ($add_br == True) {
106-
$contents["string"] .= "<br />";
107-
}
108-
109-
if ($add_n == True) {
110-
$contents["string"] .= "\n";
111-
}
104+
if ($add_n == True) {
105+
$contents["string"] .= "\n";
112106
}
113-
114-
$i++;
115107
}
108+
109+
$i++;
116110
}
117111

118112
fclose($read);
119113
}
120114

115+
if (
116+
array_keys($contents["lines"]) == [0] and
117+
array_values($contents["lines"]) == [""]
118+
) {
119+
$contents["lines"] = [];
120+
}
121+
121122
return $contents;
122123
}
123124

Classes/Folder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function Contents($folder, $replace_with = "") {
154154
$key = (string)explode(".", $key)[0];
155155

156156
$contents[$item]["Dictionary"][$key] = [
157-
"Name" => $contents[$item]["Names"][$i],
157+
"Name" => $key,
158158
"Title" => $contents[$item]["Names"][$i],
159159
"Extension" => $contents[$item]["Extensions"][$key],
160160
"Path" => $contents[$item]["List"][$i],

Classes/HTML.php

+49-10
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,27 @@ public static function Generate_Buttons() {
181181

182182
$border_color = $website["Style"]["border_color"];
183183

184+
$open_hamburger_menu_button = "<!-- Open hamburger menu button -->"."\n".
185+
HTML::Button("\n\t".$show_text, 'id="hamburger_menu_button" onclick="Show_Hamburger_Menu();" style="position: fixed; left: 0%;"', "w3-btn ".$website["Style"]["button"]["theme"]["light"]." w3-animate-zoom");
186+
187+
$close_hamburger_menu_button = "\t".'<!-- Close hamburger menu button -->'."\n".
188+
"\t".HTML::Button("\n\t\t".$hide_text."\t", ' onclick="Hide_Hamburger_Menu();" style="float: right; padding: 2px 14px 3px 14px !important;"', "w3-btn ".$website["Style"]["button"]["theme"]["light"]);
189+
184190
$buttons = [
185191
"list" => [],
186192

187-
"hamburger_menu" => "\n"."<!-- Open hamburger menu button -->"."\n".
188-
HTML::Element("button", "\n\t".$show_text, 'id="hamburger_menu_button" onclick="Show_Hamburger_Menu();" style="position: fixed; left: 0%;"', "w3-btn ".$website["Style"]["button"]["theme"]["light"]." w3-animate-zoom")."\n".
193+
"hamburger_menu" => "\n".$open_hamburger_menu_button.
194+
"\n\n".
189195
"\n"."<!--- Hamburger menu -->"."\n".
190-
'<div id="hamburger_menu" class="w3-container w3-animate-left '.$website["Style"]["background"]["theme"]["normal"]." ".$website["Style"]["border_4px"]["theme"][$border_color]." ".$website["Style"]["border_radius"].'" style="padding: 1%; position: fixed; display: none;">'."\n\n".
191-
"\t".'<!-- Hide hamburger menu button -->'."\n".
192-
"\t".HTML::Element("button", "\n\t\t".$hide_text."\t", ' onclick="Hide_Hamburger_Menu();" style="float: right; padding: 2px 14px 3px 14px !important;"', "w3-btn ".$website["Style"]["button"]["theme"]["light"])."\n\n".
196+
'<div id="hamburger_menu" class="w3-container w3-animate-left '.$website["Style"]["background"]["theme"]["normal"]." ".$website["Style"]["border_4px"]["theme"][$border_color]." ".$website["Style"]["border_radius"].'" style="padding: 1%; position: fixed; display: none;">'.
197+
"\n\n".
198+
$close_hamburger_menu_button."\n\n".
193199
"\t".HTML::Element("h2", $website["Language texts"]["tab_menu"].": ", 'style="font-weight: bold;"', "text_size ".$website["Style"]["text_highlight"])."\n\n".
194-
"\t"."<br />"."\n\n".
200+
"\t"."<br />".
195201
'<div style="overflow-y: auto; overflow-x: hidden; max-height: 80vh;">'."\n"
196202
];
197203

198-
# Generate buttons
204+
# Generate the buttons
199205
$i = 0;
200206
foreach (array_keys($website["tabs"]["data"]) as $id) {
201207
$tab = $website["tabs"]["data"][$id];
@@ -236,6 +242,11 @@ public static function Generate_Buttons_List($tab = [], $remove = "", $center =
236242
if ($tab == []) {
237243
$tab["all_buttons"] = False;
238244
$tab["only_button"] = Null;
245+
$tab["Buttons list"] = [];
246+
}
247+
248+
if (isset($tab["Buttons list"]) == False) {
249+
$tab["Buttons list"] = [];
239250
}
240251

241252
$string = "";
@@ -246,6 +257,14 @@ public static function Generate_Buttons_List($tab = [], $remove = "", $center =
246257

247258
$buttons_list = $website["buttons_list"];
248259

260+
if (isset($website["Additional buttons"]) == True) {
261+
$buttons_list = $buttons_list + $website["Additional buttons"];
262+
}
263+
264+
if ($tab["Buttons list"] != []) {
265+
$buttons_list = $tab["Buttons list"];
266+
}
267+
249268
if ($tab["only_button"] == Null) {
250269
if ($tab["all_buttons"] == False) {
251270
$i = 0;
@@ -261,12 +280,14 @@ public static function Generate_Buttons_List($tab = [], $remove = "", $center =
261280
# Previous button
262281
if ($number -1 != -1) {
263282
$buttons_list[$number - 1] = self::Element("span", $buttons_list[$number - 1], 'style="float: left;"', "margin_sides_5_cent");
283+
264284
$string .= $buttons_list[$number - 1];
265285
}
266286

267287
# Next button
268288
if ($number + 1 != count($buttons_list)) {
269289
$buttons_list[$number + 1] = self::Element("span", $buttons_list[$number + 1], 'style="float: right;"', "margin_sides_5_cent");
290+
270291
$string .= $buttons_list[$number + 1];
271292
}
272293

@@ -323,21 +344,39 @@ public static function Tab_Info($tab, $i) {
323344
}
324345
}
325346

347+
# Define the tab display key
348+
349+
# Define the "Display" key to hide the tab by default
350+
$tab["Display"] = " display: none;";
351+
352+
# If the "Display tab by default" key is present
353+
# And it is True
354+
if (
355+
isset($tab["Display tab by default"]) == True and
356+
$tab["Display tab by default"] == True
357+
) {
358+
# Define the "Display" key to show the tab by default
359+
$tab["Display"] = " display: block;";
360+
}
361+
326362
# Read the tab file if the file index exists
327363
if (isset($tab["file"]) == True) {
328364
$contents = $File -> Contents($tab["file"]);
329365

330-
if ($contents["lines"] != [] and array_key_exists("content", $tab) == False) {
366+
if (
367+
$contents["lines"] != [] and
368+
isset($tab["content"]) == False
369+
) {
331370
$tab["content"] = Linkfy($contents["string"]);
332371
}
333372

334-
# If file is empty, use empty message text
373+
# If the file is empty, use the empty message text
335374
if ($contents["lines"] == []) {
336375
if (isset($tab["empty_message"]) == False) {
337376
$tab["empty_message"] = $website["Language texts"]["this_file_does_not_exist_{}"];
338377
}
339378

340-
$tab["content"] = $tab["empty_message"];
379+
$tab["content"] = "test".$tab["empty_message"];
341380
}
342381
}
343382

Classes/Language.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,19 @@ public function Define_User_Language() {
100100
$this -> language_texts = $website["Language texts"];
101101

102102
$website["language_icon"] = $website["Language texts"]["language_icon"];
103+
104+
# Define the website "Languages" dictionary
105+
$website["Languages"] = [
106+
"Small" => $website["language"],
107+
"Full" => $website["full_language"],
108+
"Module" => $this -> settings["Language"]
109+
];
110+
111+
# Define the language texts but with the module language
112+
$website["Language texts (Module language)"] = self::Item($website["Texts"], $website["Languages"]["Module"]);
103113
}
104114

105-
public static function Item($item) {
115+
public static function Item($item, $parameter_language = "") {
106116
global $website;
107117

108118
$language = $website["language"];
@@ -111,6 +121,10 @@ public static function Item($item) {
111121
$language = "en";
112122
}
113123

124+
if ($parameter_language != "") {
125+
$language = $parameter_language;
126+
}
127+
114128
if (
115129
is_array($item) == True and
116130
isset($item[$language]) == True

Classes/Story.php

+46-13
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function Chapter_Text() {
7373
global $chapter_tab;
7474

7575
if (isset($website["Data"]["JSON"]["story"]) == False) {
76-
$root_variables_folder = $story["Folders"]["Chapters"]["root"].$website["Texts"]["variables, title()"]["en"]."/";
76+
$root_variables_folder = $story["Folders"]["Chapters"]["root"].$website["Language texts"]["variables, title()"]."/";
7777
$Folder -> Create($root_variables_folder);
7878

7979
$root_variables_file = $root_variables_folder.$chapter_tab["number_leading_zeroes"].".txt";
@@ -84,7 +84,7 @@ public function Chapter_Text() {
8484
$language_variables_file = $language_variables_folder.$chapter_tab["number_leading_zeroes"].".txt";
8585
}
8686

87-
# Define chapter file
87+
# Define the chapter file
8888
$chapter_file = $story["Folders"]["Chapters"][$full_language]["root"].$chapter_tab["chapter_title_file"].".txt";
8989

9090
$chapter_contents = $File -> Contents($chapter_file, $add_br = False);
@@ -160,26 +160,48 @@ public function Chapter_Cover() {
160160
global $chapter_tab;
161161
global $i;
162162
global $parse;
163+
global $folders;
163164

164165
$local_chapter_cover = "";
165166

166167
if (
167-
isset($website["Data"]["Folders"]["Local website"]["Images"]["Story covers"]) and
168-
$parse == "/generate"
168+
$website["States"]["Website"]["Generate"] == False or
169+
isset($_GET["show_chapter_covers"]) == True
169170
) {
170-
$chapter_cover_file_name = $full_language."/".Text::Chapter_Cover_Folder($i)."/".Text::Add_Leading_Zeroes($i);
171+
$chapter_cover_file_name = $full_language;
171172

172173
$image_format = "";
173174

175+
# Define the local and remote folderes
176+
$local_chapter_folder = $website["Data"]["Folders"]["Website"]["Images"]["Local"]["Chapters"]["root"];
177+
$remote_chapter_folder = $website["Data"]["Folders"]["Website"]["Images"]["Remote"]["Chapters"]["root"];
178+
179+
# Define the chapter folder
180+
$chapter_folder = Text::Add_Leading_Zeroes($i)."/";
181+
182+
# Add the chapter folder to the local and remote cover image Folders
183+
$local_chapter_folder .= $chapter_folder;
184+
$remote_chapter_folder .= $chapter_folder;
185+
174186
foreach ($website["Image formats"] as $format) {
175-
$local_chapter_cover = $website["Data"]["Folders"]["Local website"]["Images"]["Story covers"]["root"].$chapter_cover_file_name.".".$format;
187+
$local_chapter_cover = $local_chapter_folder.$chapter_cover_file_name.".".$format;
176188

177189
if (file_exists($local_chapter_cover) == True) {
178190
$image_format = $format;
179191
}
180192
}
181193

182-
$remote_chapter_cover = $website["Data"]["Folders"]["Website"]["Website images"]["Story covers"]["root"].$chapter_cover_file_name.".".$image_format;
194+
# Replace remote folder with the local PHP images folder
195+
# To test if the images appear correctly
196+
if ($website["States"]["Website"]["Generate"] == False) {
197+
$php_folder = "Images/".$website["Data"]["title"]."/";
198+
199+
$remote_folder = "/".$php_folder;
200+
201+
$remote_chapter_folder = str_replace($website["Data"]["Folders"]["Website"]["Images"]["Remote"]["root"], $remote_folder, $remote_chapter_folder);
202+
}
203+
204+
$remote_chapter_cover = $remote_chapter_folder.$chapter_cover_file_name.".".$image_format;
183205
}
184206

185207
else {
@@ -311,7 +333,7 @@ public function Get_Chapter_Reads($reads_folder) {
311333
$readers = $File -> Contents($reader_file)["lines"];
312334

313335
# Define read date file
314-
$read_date_file = $reads_folder."Read date.txt";
336+
$read_date_file = $reads_folder."Date.txt";
315337
$read_dates = $File -> Contents($read_date_file)["lines"];
316338

317339
$text = HTML::Element("b", $website["Language texts"]["read, title()"].": ", "", "margin_top_bottom_2_cent");
@@ -481,6 +503,7 @@ public function Chapter_Tab() {
481503
"id" => "chapter_".$i,
482504
"chapter_title" => $i." - ".$chapter_title,
483505
"chapter_title_file" => Text::Add_Leading_Zeroes($i)." - ".$Folder -> Sanitize($chapter_title),
506+
"painted_chapter_title" => $painted_chapter_title,
484507
"you_are_reading" => Text::Format($website["Language texts"]["you_are_reading_{}_chapter_{}"], [$painted_story_title, $painted_chapter_title]),
485508
"you_read" => Text::Format($website["Language texts"]["you_just_read_{}_chapter_{}"], [$painted_story_title, $painted_chapter_title]),
486509
"class" => $website["Style"]["tab"]["theme_dark"],
@@ -590,7 +613,10 @@ public function Chapter_Tab() {
590613

591614
$style = "width: 100%; height: 800px; border: none; overflow-y: hidden; resize: none;";
592615

593-
$h2 = HTML::Element("h2", "<p><br /><b>".$website["Language texts"]["write, title()"].":"."</b><br /><br /><p>", "", $chapter_tab["chapter_text_color"])."\n";
616+
$write_text = "<p><br /><b>".$website["Language texts"]["write, title()"].": ".$website["Icons"]["pen"]."<br />".
617+
$chapter_tab["chapter_title"]."</b><br /><br /><p>";
618+
619+
$h2 = HTML::Element("h2", $write_text, "", $chapter_tab["chapter_text_color"])."\n";
594620

595621
$title = "<center>".$h2."</center>";
596622

@@ -639,11 +665,15 @@ public function Chapter_Tab() {
639665
$chapter_tab["comment"] = str_replace("button", "buttons", $chapter_tab["comment"]);
640666
}
641667

642-
$comments_folder = $story["Folders"]["Comments"]["Chapter"].$chapter_tab["number_leading_zeroes"]."/";
643-
$reads_folder = $story["Folders"]["Readers and Reads"]["Reads"].$chapter_tab["number_leading_zeroes"]."/";
668+
$comments_folder = $story["Folders"]["Comments"]["root"].$chapter_tab["number_leading_zeroes"]."/";
669+
$reads_folder = $story["Folders"]["Readers"]["Reads"]["root"].$chapter_tab["number_leading_zeroes"]."/";
644670

645-
if (file_exists($comments_folder) == True or file_exists($reads_folder) == True) {
671+
if (
672+
file_exists($comments_folder) == True or
673+
file_exists($reads_folder) == True
674+
) {
646675
$chapter_tab["additional_elements"] = $website["elements"]["hr_1px"]["theme"]["dark"];
676+
647677
$width = "37";
648678
$margin = "10";
649679
}
@@ -668,7 +698,10 @@ public function Chapter_Tab() {
668698
$chapter_tab["additional_elements"] .= $reads;
669699
}
670700

671-
if (file_exists($comments_folder) == True and file_exists($reads_folder) == True) {
701+
if (
702+
file_exists($comments_folder) == True and
703+
file_exists($reads_folder) == True
704+
) {
672705
if (count($commentators) <= 1) {
673706
$chapter_tab["padding"] = "50vh";
674707
}

Classes/Text files/Texts.json

-17
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,6 @@
171171
"en": "Chapters in English",
172172
"pt": "Capítulos em Português"
173173
},
174-
"reader, title()": {
175-
"en": "Reader",
176-
"pt": "Leitor"
177-
},
178-
"readers, title()": {
179-
"en": "Readers",
180-
"pt": "Leitores"
181-
},
182174
"other_stories": {
183175
"en": "Other stories",
184176
"pt": "Outras histórias"
@@ -191,19 +183,10 @@
191183
"en": "Words",
192184
"pt": "Palavras"
193185
},
194-
"no_readers, en - pt": "No Readers - Sem Leitores",
195186
"story_creation_date": {
196187
"en": "Story creation date",
197188
"pt": "Data de criação da história"
198189
},
199-
"read, title()": {
200-
"en": "Read",
201-
"pt": "Leitura"
202-
},
203-
"reads, title()": {
204-
"en": "Reads",
205-
"pt": "Leituras"
206-
},
207190
"i_read": {
208191
"en": "I read",
209192
"pt": "Eu li"

Classes/Text.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public static function Add_Leading_Zeroes($number) {
198198
}
199199

200200
if ($number > 9) {
201-
return $number;
201+
return (string)$number;
202202
}
203203
}
204204

0 commit comments

Comments
 (0)