-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Played.php
421 lines (305 loc) · 12.6 KB
/
Played.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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
<?php
# Played
$language = "pt";
if (isset($website["language"]) == True) {
$language = $website["language"];
}
$full_language = $Language -> languages["full"][$language];
if ($language == "general") {
$language = "en";
$full_language = $Language -> languages["full"][$language];
}
# Generate "watched things" tab content
$website["tab_content"]["game_sessions_played"] = [
"string" => "",
"number" => 0
];
# Create additional tabs array
if (array_key_exists("additional_tabs", $website) == False) {
$website["additional_tabs"] = [
"data" => []
];
}
if (isset($website["Data"]["Year"]) == False) {
$website["Data"]["Year"] = Date::Now()["year"];
}
if (in_array($website["Data"]["title"], $website["Years"]) == True) {
$website["Data"]["Year"] = $website["Data"]["title"];
}
if (isset($website["Play History"]) == False) {
$website["Play History"] = [
"Years list" => Date::Create_Years_List($mode = "array", $start = 2021, $plus = 0)
];
}
# Define the data network folder for easier typing
$network_folder = $folders["Mega"]["Notepad"]["Data Networks"]["Games"];
if (isset($gameplayer) == False) {
# Define the "GamePlayer" array
$gameplayer = [
"Files" => [
"Per Game Type" => [
"root" => $network_folder["Play History"][$website["Data"]["Year"]]["Per Game Type"]["root"]
]
],
"Types" => $JSON -> To_PHP($network_folder["Data"]["Types"]),
"Entries" => $JSON -> To_PHP($network_folder["Play History"][$website["Data"]["Year"]]["Entries"]),
"Texts" => $JSON -> To_PHP($folders["Apps"]["Module files"]["GamePlayer"]["Texts"]),
"Language texts" => [],
"Information" => [
"Information" => $JSON -> To_PHP($network_folder["Information"]["Information"])
]
];
$gameplayer["Language texts"] = $Language -> Item($gameplayer["Texts"]);
$types_dictionary = $gameplayer["Types"]["Types"];
$website["Data"]["Numbers"] = [
"By year" => [],
"By type" => []
];
# Iterate through the English media types list
$i = 0;
foreach ($types_dictionary["en"] as $type) {
$website["Data"]["Numbers"]["By type"][$type] = 0;
}
}
if (function_exists("Generate_Game_Type_Headers") == False) {
function Generate_Game_Type_Headers($header_text = "") {
global $website;
global $Language;
global $JSON;
global $gameplayer;
$language = "pt";
if (isset($website["language"]) == True) {
$language = $website["language"];
}
if ($language == "general") {
$language = "en";
}
if ($header_text == "") {
$header_text = $gameplayer["Language texts"]["game_sessions_played_in"]."".$website["Data"]["Year"];
}
$array = [
"links" => "",
"headers" => []
];
$text_color = $website["Style"]["text"]["theme"]["dark"];
$types_dictionary = $gameplayer["Types"]["Types"];
# Define a shortcut for the total number of entries in the year
$total_number = $gameplayer["Entries"]["Numbers"]["Total"];
# Iterate through the English game types list
$i = 0;
foreach ($types_dictionary["en"] as $type) {
$language_type = $types_dictionary[$language][$i];
$number = $gameplayer["Entries"]["Numbers"]["Per Game Type"][$type];
if ($header_text == $gameplayer["Language texts"]["games_being_played"]) {
$number = $gameplayer["Information"]["Information"]["Numbers"][$type];
}
# If the number is not zero (0)
# Or the total number of tasks is zero
if (
$number != 0 or
$total_number == 0
) {
$number_element = HTML::Element("span", $number, "", $text_color);
$span = $language_type.": ".$number_element;
$span = HTML::Element("b", $span);
$href = $header_text.": ".$language_type;
# Anchor element to go to the game type list
if ($number != 0) {
$a = HTML::Element("a", $span, 'href="#'.$href.'"');
}
else {
$a = HTML::Element("a", $span);
}
$array["links"] .= $a."<br />"."\n\t\t";
$gameplayer["Files"]["Per Game Type"][$type] = $JSON -> To_PHP($gameplayer["Files"]["Per Game Type"]["root"].$type."/Sessions.json");
$number_element = HTML::Element("span", $number, "", $text_color);
$span = $language_type.": ".$number_element;
$span = HTML::Element("b", $span);
# Game type header with anchor href to go to the game type sessions part
$a = HTML::Element("a", $span, 'name="'.$href.'"')."<br />";
$array["headers"][$type] = "\t\t".'<!-- "'.$type.'" game type header -->'."\n".
"\t\t".$a."\n";
}
$i++;
}
return $array;
}
}
# Update the "Per Game Type" folder
$gameplayer["Files"]["Per Game Type"] = [
"root" => $network_folder["Play History"][$website["Data"]["Year"]]["Per Game Type"]["root"]
];
# Define the Entries file for easier typing
$entries_file = $network_folder["Play History"][$website["Data"]["Year"]]["Entries"];
if (file_exists($entries_file) == True) {
$gameplayer["Entries"] = $JSON -> To_PHP($entries_file);
# Add to the year entries number
$current_year = $website["Data"]["Year"];
if (isset($website["Data"]["Numbers"]["By year"][$current_year]) == False) {
$website["Data"]["Numbers"]["By year"][$current_year] = $gameplayer["Entries"]["Numbers"]["Total"];
}
# Sort the year keys
ksort($website["Data"]["Numbers"]["By year"]);
$website_title = "Play History";
$tab = "past_registry_".$website["Data"]["Year"];
# If the local year is the current year
# Then, the tab that needs to be used is the "game_sessions_played" tab
if ($website["Data"]["Year"] == $website["current_year"]) {
$tab = "game_sessions_played";
}
if ($website["Data"]["title"] != $website_title) {
$website_dictionary = $website["Dictionary"][$website_title];
$link = $website_dictionary["Links"]["Language"];
if (str_contains($link, "?") == False) {
$link .= "?";
}
else {
$link .= "&";
}
$link .= "tab=".$tab;
# Add the website button to the top of the page
$website["tab_content"]["game_sessions_played"]["string"] .= "<center>"."\n".
$Text -> Format($website_dictionary["Button template"], $link)."\n".
"<p></p>".
# Add the website image to the top of the tab
$website_dictionary["image"]["elements"]["theme"]["dark"]."\n".
"</center>"."\n".
"<br />"."\n";
}
$type_headers = Generate_Game_Type_Headers();
# Update the game sessions number
$website["tab_content"]["game_sessions_played"]["number"] = $gameplayer["Entries"]["Numbers"]["Total"];
if (
$website["Data"]["title"] != $website_title or
$website["tab_content"]["game_sessions_played"]["number"] == 0
) {
# Create the number of game sessions variable with the tab title
$number_of_game_sessions = $gameplayer["Language texts"]["game_sessions_played_in"]." ".$website["Data"]["Year"].":";
# Add the icon of the tab
$number_of_game_sessions .= " ".$website["Icons"]["gamepad"];
# Add the number of game sessions
$number_of_game_sessions .= " ".HTML::Element("span", $website["tab_content"]["game_sessions_played"]["number"], "", $website["Style"]["text"]["theme"]["dark"])."<br /><br />";
# Transform everything into bold style
$number_of_game_sessions = HTML::Element("b", $number_of_game_sessions);
# Add the number of game sessions text to the tab string content
$website["tab_content"]["game_sessions_played"]["string"] .= $number_of_game_sessions;
}
$website["tab_content"]["game_sessions_played"]["string"] .= "<!-- Game type headers -->"."\n"."\t\t".
$type_headers["links"].
"\n"."\t\t"."<br />"."\n\n";
$text_color = $website["Style"]["text"]["theme"]["dark"];
$types_dictionary = $gameplayer["Types"]["Types"];
# Iterate through the English game types list
$i = 0;
foreach ($types_dictionary["en"] as $type) {
$language_type = $types_dictionary[$language][$i];
$modules_language = $types_dictionary[$Language -> modules_language][$i];
$number = $gameplayer["Entries"]["Numbers"]["Per Game Type"][$type];
$website["Data"]["Numbers"]["By type"][$type] += $number;
if ($number != 0) {
$website["tab_content"]["game_sessions_played"]["string"] .= $type_headers["headers"][$type];
$entries = $gameplayer["Files"]["Per Game Type"][$type]["Entries"];
# Iterate through the game type Entries list
foreach ($gameplayer["Files"]["Per Game Type"][$type]["Entries"] as $entry) {
$entry = $gameplayer["Entries"]["Dictionary"][$entry];
# Add the game title
$title = Define_Title($entry["Titles"]);
$item = "";
$entry_title = $title;
# Add the sub-game title if it exists
if (isset($entry["Sub-game"])) {
$sub_game_title = Define_Title($entry["Sub-game"]);
if ($sub_game_title[0].$sub_game_title[1] != ": ") {
$title .= ": ";
}
$title .= $sub_game_title;
}
# Define the date
$format = "Y-m-d\TH:i:s\Z";
if (strlen($entry["Date"]) == 4) {
$format = "Y";
}
$time = $entry["Date"];
if ($time != "") {
$time = Date::Now($time, $format);
}
if (strlen($entry["Date"]) != 4) {
$time = $time["formats"]["HH:MM DD/MM/YYYY"];
}
if (strlen($entry["Date"]) == 4) {
$time = $time["year"];
}
$text = $entry["Number"]." -";
# Add the States
if (array_key_exists("States", $entry) == True) {
if (array_key_exists("Re-played", $entry["States"]) == True) {
$times_text = $gameplayer["Language texts"]["number_of_played_times"].": ".($entry["States"]["Re-played"]["Times"] + 1)."x";
$text .= " ".HTML::Element("span", ($entry["States"]["Re-played"]["Times"] + 1)."x ".$website["Icons"]["gamepad"], 'alt="'.$times_text.'" title="'.$times_text.'"', $website["Style"]["text_highlight"]." underline_on_hover");
}
if (array_key_exists("First game session in year", $entry["States"]) == True) {
$first_text = $gameplayer["Language texts"]["first_game_session_in_year"];
$text .= " ".HTML::Element("span", "1# ".$website["Icons"]["calendar"], 'alt="'.$first_text.'" title="'.$first_text.'"', $website["Style"]["text_highlight"]." underline_on_hover");
}
if (array_key_exists("First game type session in year", $entry["States"]) == True) {
$first_text = Text::Format($gameplayer["Language texts"]["first_game_session_of_the_{}_category_in_year"], $language_type);
$first_text_replaced = str_replace('"', "'", $first_text);
$text .= " ".HTML::Element("span", "1# ".$website["Icons"]["gamepad"]." ".$website["Icons"]["calendar"], 'alt="'.$first_text_replaced.'" title="'.$first_text_replaced.'"', $website["Style"]["text_highlight"]." underline_on_hover");
}
if (
array_key_exists("Re-played", $entry["States"]) == True or
array_key_exists("First entry in year", $entry["States"]) == True or
array_key_exists("First game type session in year", $entry["States"]) == True
) {
$text .= " - ";
}
}
# Add quotes to the game title
$title = '"'.$title.'"';
# Add the platform where the game was played
$platform = $entry["Platform"];
$text_key = str_replace(" ", "_", strtolower($platform));
if (str_contains($text_key, "_") == False) {
$text_key .= ", title()";
}
if (isset($website["Language texts"][$text_key])) {
$platform = $website["Language texts"][$text_key];
}
# If the platform where the game was played is not "PC", add it to the title
if ($platform != "PC") {
$title .= " (".$platform.")";
}
# Add the duration of the session
$duration = $entry["Session duration"];
unset($duration["Text"]);
$duration = Date::Make_Time_Text($duration)[$language];
$title .= ", ".$gameplayer["Language texts"]["session_duration"].": ".$duration;
# Paint the title
$title = HTML::Element("span", $title, "", $text_color." ".$website["Style"]["text_hover"]);
# Update the text
$text .= " ".$title." (".$time.")";
$text = HTML::Element("span", $text, 'style="margin-left: 3%;"', $website["Style"]["text_hover"]);
$website["tab_content"]["game_sessions_played"]["string"] .= $text."<br />"."\n";
}
if ($type != end($types_dictionary[$language])) {
$website["tab_content"]["game_sessions_played"]["string"] .= "\t\t"."<br />"."\n\n";
}
}
$i++;
}
$website["tab_content"]["game_sessions_played"]["string"] .= "<br /><br />";
# Add the tab to the tab templates
if (array_key_exists("game_sessions_played", $website["tabs"]["templates"]) == False) {
$website["tabs"]["templates"]["game_sessions_played"] = [
"name" => $gameplayer["Language texts"]["game_sessions_played_in"]." ".$website["Data"]["Year"],
"add" => " ".HTML::Element("span", $website["tab_content"]["game_sessions_played"]["number"], "", $website["Style"]["text"]["theme"]["dark"]),
"text_style" => "text-align: left;",
"content" => $website["tab_content"]["game_sessions_played"]["string"],
"icon" => "gamepad"
];
}
}
else {
# Define the "Game sessions" tab to be removed if it does not contain game sessions
array_push($website["tabs"]["To remove"], "game_sessions_played");
}
?>