-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgames.php
86 lines (70 loc) · 2.5 KB
/
games.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
<!DOCTYPE html>
<?php
define('Navbar', TRUE);
include('navbar.php');
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="games.css">
<title>The Games Folder</title>
</head>
<body>
<?php
// Specify the path to the /games folder
$folderPath = 'games';
// Get all subdirectories in the /games folder
$folders = array_filter(glob($folderPath . '/*'), 'is_dir');
// Create a custom sorting function
function compareFolders($folder1, $folder2) {
$folder1Name = strtolower(trim($folder1));
$folder2Name = strtolower(trim($folder2));
return strcmp($folder1Name, $folder2Name);
}
// Sort the folders using the custom sorting function
usort($folders, 'compareFolders');
// Display each folder as a link with an icon and game name
if (!empty($folders)) {
echo '<div class="game-grid">';
foreach ($folders as $folder) {
// Get the folder name
$folderName = basename($folder);
// Read the game name from the "game_name.txt" file
$gameNameFile = $folder . '/game_name.txt';
if (file_exists($gameNameFile)) {
$gameName = trim(file_get_contents($gameNameFile));
} else {
$gameName = $folderName;
}
// Search for favicon and icon files in the folder
$iconFiles = glob($folder . '/*.{ico,png,svg,gif}', GLOB_BRACE);
// Get the first icon file or use a default if none found
$iconSrc = !empty($iconFiles) ? $iconFiles[0] : 'default.png';
// Display the link to the folder's webpage with the /games/ prefix, an icon, and the game name
echo '<div class="game-item">';
echo '<a href="./games/' . $folderName . '">';
echo '<div class="game-icon-wrapper">';
echo '<img src="' . $iconSrc . '" alt="' . $gameName . '">';
echo '</div>';
echo '<div class="game-name">' . $gameName . '</div>';
echo '</a>';
echo '</div>';
// Add a custom script tag to each HTML file in the subdirectory if it doesn't already exist
$htmlFiles = glob($folder . '/*.html');
foreach ($htmlFiles as $htmlFile) {
$content = file_get_contents($htmlFile);
// Check if the script tag already exists in the file
if (strpos($content, '<script async src="https://arc.io/widget.min.js#sMbCtF2L"></script>') === false) {
// Add the script tag only if it doesn't already exist
$content = '<script async src="https://arc.io/widget.min.js#sMbCtF2L"></script>' . $content;
file_put_contents($htmlFile, $content);
}
}
}
echo '</div>';
} else {
echo '<p>No folders found in the /games directory.</p>';
}
?>
</body>
</html>