Website/index.php

105 lines
2.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',
'flag' => 'https://git.theclashfruit.me/CRSS/CRSS/raw/branch/main/Nations/Republic%20of%20Panorama/Flag.svg',
'short' => 'rop',
)
);
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);
$twig->addGlobal('playerCount', count($json));
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');
});
$router->get('/rules', function() {
global $twig;
2023-09-18 16:37:58 +00:00
$twig->addGlobal('pageUri', '/rules');
2023-09-15 15:48:05 +00:00
echo $twig->render('rules.twig');
});
$router->get('/map', function() {
2023-09-15 15:48:05 +00:00
global $twig;
2023-09-18 16:37:58 +00:00
$twig->addGlobal('pageUri', '/map');
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
$user = $mysql->getUserRecordFromId($_SESSION['user']['id']);
if($user == null) {
http_response_code(404);
echo $twig->render('404.twig');
} else {
echo $twig->render('profile.twig', array('db_data' => $user));
}
});
$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);
2023-09-15 21:04:00 +00:00
$user = $mysql->getUserRecordFromUsername($name);
if($user == null) {
http_response_code(404);
echo $twig->render('404.twig');
} else {
echo $twig->render('user.twig', array('db_user' => $user));
}
});
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');
});
$router->run();