Website/index.php

181 lines
4.1 KiB
PHP
Raw Normal View History

2023-09-14 17:33:54 +00:00
<?php
2023-09-15 15:10:03 +00:00
global $twig;
2023-09-14 17:33:54 +00:00
require_once '_config.php';
2023-09-15 15:10:03 +00:00
2023-09-15 15:42:27 +00:00
use Bramus\Router\Router;
2023-11-18 12:23:34 +00:00
$curl = new anlutro\cURL\cURL;
2023-09-15 15:42:27 +00:00
$router = new Router();
2023-09-15 15:10:03 +00:00
session_start();
2023-09-15 21:04:00 +00:00
$nations = array(
'rop' => array(
'name' => 'Republic of Panorama',
2023-11-28 08:35:31 +00:00
'flag' => 'https://raw.theclashfruit.me/CRSS/CRSS/main/Nations/Republic%20of%20Panorama/Flag.svg',
2023-09-15 21:04:00 +00:00
'short' => 'rop',
'description' => 'Short description of R.O.P.',
2023-11-28 08:35:31 +00:00
),
'drr' => array(
'name' => 'Democratic Republic of Rayland',
'flag' => 'https://raw.theclashfruit.me/CRSS/CRSS/main/Nations/Democratic%20Republic%20of%20Rayland/bannre.png',
'short' => 'drr',
'description' => 'Short description of D.R.R.',
2023-09-15 21:04:00 +00:00
)
);
2023-09-15 14:47:56 +00:00
2023-09-15 15:28:11 +00:00
if(isset($_SESSION['user']))
$twig->addGlobal('user', $_SESSION['user']);
2023-09-15 15:42:27 +00:00
2023-11-18 12:23:34 +00:00
$res = $curl->get('https://crss.blurryface.xyz/api/v1/players');
$json = json_decode($res->body, true);
2024-01-13 22:12:46 +00:00
if($json != null)
2023-12-13 17:24:39 +00:00
$twig->addGlobal('playerCount', count($json));
2024-01-13 22:12:46 +00:00
else
$twig->addGlobal('playerCount', $json);
2023-12-13 17:24:39 +00:00
$twig->addGlobal('nations', $nations);
2023-11-18 12:23:34 +00:00
$twig->addGlobal('reduced', isset($_GET['reduced']));
2023-09-15 15:42:27 +00:00
$router->get('/', function() {
2023-09-15 15:44:03 +00:00
global $twig;
2023-09-18 16:37:58 +00:00
$twig->addGlobal('pageUri', '/');
2023-09-15 15:44:03 +00:00
2023-09-15 15:42:27 +00:00
echo $twig->render('index.twig');
});
$router->get('/nations', function() {
2023-09-15 15:44:03 +00:00
global $twig;
2023-09-18 16:37:58 +00:00
$twig->addGlobal('pageUri', '/nations');
2023-09-15 15:44:03 +00:00
2023-09-15 15:48:05 +00:00
echo $twig->render('nations.twig');
});
2023-11-26 21:40:10 +00:00
$router->get('/gallery', function() {
2023-09-15 15:48:05 +00:00
global $twig;
2023-09-18 16:37:58 +00:00
2023-11-26 21:40:10 +00:00
$twig->addGlobal('pageUri', '/gallery');
2023-09-15 15:48:05 +00:00
2023-11-26 21:40:10 +00:00
echo $twig->render('gallery.twig');
2023-09-15 15:48:05 +00:00
});
$router->get('/map', function() {
2024-01-13 22:12:46 +00:00
global $twig, $mysql;
2023-09-18 16:37:58 +00:00
$twig->addGlobal('pageUri', '/map');
2024-01-13 22:12:46 +00:00
$twig->addGlobal('markers', json_encode($mysql->getMarkers()));
2023-11-28 10:18:21 +00:00
if(isset($_GET['center']))
$twig->addGlobal('center', $_GET['center']);
else
$twig->addGlobal('center', '0;0');
2023-09-15 15:48:05 +00:00
echo $twig->render('map.twig');
2023-09-15 15:42:27 +00:00
});
2023-09-15 21:04:00 +00:00
$router->get('/profile', function() {
global $twig, $mysql;
2023-09-18 16:37:58 +00:00
$twig->addGlobal('pageUri', '/profile');
2023-09-15 21:04:00 +00:00
2024-01-13 23:58:35 +00:00
if (isset($_SESSION['user'])) {
$user = $mysql->getUserRecordFromId($_SESSION['user']['id']);
if ($user == null && $user['admin'] == 0) {
http_response_code(404);
echo $twig->render('404.twig');
} else {
echo $twig->render('profile.twig', array('db_data' => $user));
}
} else {
2023-09-15 21:04:00 +00:00
http_response_code(404);
echo $twig->render('404.twig');
}
});
2023-11-28 08:35:31 +00:00
$router->get('/nation/([a-z]+)', function ($nation) {
global $twig, $mysql, $nations;
$twig->addGlobal('pageUri', '/nation/' . $nation);
if(!$nations[$nation]) {
http_response_code(404);
echo $twig->render('404.twig');
} else {
echo $twig->render('nation.twig', array('nation' => $nations[$nation]));
2023-11-28 08:35:31 +00:00
}
});
2023-09-15 21:04:00 +00:00
$router->get('/u/([a-z0-9_\.]+)', function($name) {
global $twig, $mysql, $discord;
2023-09-18 16:37:58 +00:00
$twig->addGlobal('pageUri', '/u/' . $name);
2024-01-13 23:58:35 +00:00
2023-09-15 21:04:00 +00:00
$user = $mysql->getUserRecordFromUsername($name);
2024-01-13 23:58:35 +00:00
2023-09-15 21:04:00 +00:00
if($user == null) {
http_response_code(404);
2024-01-13 23:58:35 +00:00
2023-09-15 21:04:00 +00:00
echo $twig->render('404.twig');
} else {
echo $twig->render('user.twig', array('db_user' => $user));
}
});
2024-01-13 22:12:46 +00:00
// ---------------- Admin ---------------- //
$router->get('/admin', function() {
global $twig, $mysql;
$twig->addGlobal('pageUri', '/admin');
2024-01-13 23:58:35 +00:00
if (isset($_SESSION['user'])) {
$user = $mysql->getUserRecordFromId($_SESSION['user']['id']);
$users = $mysql->getUsers();
$markers = $mysql->getMarkers();
2024-01-13 22:12:46 +00:00
2024-01-13 23:58:35 +00:00
if ($user == null && $user['admin'] == 0) {
http_response_code(404);
echo $twig->render('404.twig');
} else {
echo $twig->render('admin/index.twig', array('users' => $users, 'markers' => $markers));
}
} else {
2024-01-13 22:12:46 +00:00
http_response_code(404);
echo $twig->render('404.twig');
}
});
2024-01-13 23:58:35 +00:00
// ---------------- Admin API ---------------- //
$adminApi = new Admin($router);
$adminApi->registerApiRoutes();
2024-01-13 22:12:46 +00:00
// ----------------- 404 ----------------- //
2023-09-15 15:42:27 +00:00
$router->set404(function() {
2023-09-15 15:44:03 +00:00
global $twig;
2023-09-18 16:37:58 +00:00
$twig->addGlobal('pageUri', '404');
2023-09-15 15:44:03 +00:00
2023-09-15 15:42:27 +00:00
http_response_code(404);
echo $twig->render('404.twig');
});
2023-11-26 21:40:10 +00:00
$router->run();