Website/index.php

279 lines
8.6 KiB
PHP
Raw Normal View History

2023-09-14 17:33:54 +00:00
<?php
2024-04-01 17:10:19 +00:00
global $twig, $mysql;
2023-09-15 15:10:03 +00:00
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(
2024-03-27 01:34:11 +00:00
'psf' => array(
'name' => 'Panorama Socialist Federation',
2023-11-28 08:35:31 +00:00
'flag' => 'https://raw.theclashfruit.me/CRSS/CRSS/main/Nations/Republic%20of%20Panorama/Flag.svg',
2024-03-27 01:34:11 +00:00
'short' => 'psf',
2024-04-07 06:10:23 +00:00
'short_description' => 'The first nation, prev. known as ROP.',
2024-03-27 01:34:11 +00:00
'description' => 'The first nation on CRSS, previously known as ROP.',
2024-06-03 02:15:16 +00:00
'leader' => 'iforgotaname',
2023-11-28 08:35:31 +00:00
),
2024-01-14 03:14:19 +00:00
'cnk' => array(
'name' => 'Chunkia',
2024-01-14 09:48:14 +00:00
'flag' => 'https://raw.theclashfruit.me/CRSS/CRSS/main/Nations/Chunkia/chunkia512.png',
2024-01-14 03:14:19 +00:00
'short' => 'cnk',
2024-04-07 06:12:34 +00:00
'short_description' => 'Chunkia is based in a chaotic landscape',
2024-01-14 03:23:44 +00:00
'description' => 'In the chaos of Minecraft, chunk errors are inevitable. Chunkia is based in one.',
2024-06-03 02:15:16 +00:00
'leader' => 'WorldWidePixel',
2024-04-25 01:42:34 +00:00
),
2024-04-25 00:22:04 +00:00
'ttk' => array(
'name' => 'The Toaster-Königreich',
'flag' => 'https://raw.theclashfruit.me/CRSS/CRSS/main/Nations/The%20Toaster-K%C3%B6nigreich/The%20Toaster-K%C3%B6nigreich%20Flag.svg',
2024-04-25 00:22:04 +00:00
'short' => 'ttk',
'short_description' => 'The Toaster-Königreich is the Industrialized Nation of CRSS',
'description' => 'In the vast landsacpe of CRSS, The Toaster-Königreich is one of the most industrialized Marxist district of CRSS. With Charge Industries as one of the main government controlled company in the nation.',
2024-06-03 02:15:16 +00:00
'leader' => 'Lupancham',
2024-05-26 08:20:41 +00:00
),
'rob' => array(
'name' => 'Republic of Budapest',
2024-05-26 08:21:30 +00:00
'flag' => 'https://raw.theclashfruit.me/CRSS/CRSS/main/Nations/Republic%20of%20Budapest/Assets/Flag.svg',
'short' => 'rob',
2024-05-26 08:20:41 +00:00
'short_description' => 'Republic of Budapest is a country located to the west of the map.',
'description' => 'Republic of Budapest is a country located to the west of the map.',
2024-06-03 02:15:16 +00:00
'leader' => 'TheClashFruit',
2024-04-25 00:22:04 +00:00
)
2023-09-15 21:04:00 +00:00
);
$companies = array(
'fbk' => array(
'name' => 'FedBank',
'logo' => 'https://raw.theclashfruit.me/CRSS/CRSS/main/Nations/Republic%20of%20Panorama/Flag.svg',
'short' => 'fbk',
'short_description' => 'An International Bank, owned by the PSF government',
'description' => 'FedBank is an International bank owned and controlled by the Panorama Socialist Federation\'s Government. The main building is in PSF, but there is a FedBank in TTK too.'
2024-05-29 02:23:54 +00:00
),
'ntn' => array(
'name' => 'Northern',
'logo' => 'https://raw.theclashfruit.me/CRSS/CRSS/main/Companies/Chunkia/northern.svg',
'short' => 'ntn',
'short_description' => 'The Northern Company.',
'description' => 'Creators of the H1 and the Northern Complex, Northern is dedicated to improving the CRSS experience.'
)
);
2023-09-15 14:47:56 +00:00
2024-04-01 17:10:19 +00:00
if(isset($_SESSION['user'])) {
$dbUser = $mysql->getUserRecordFromId($_SESSION['user']['id']);
$user = $_SESSION['user'];
$user['is_admin'] = $dbUser['is_admin'];
$twig->addGlobal('user', $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);
2024-05-18 20:18:07 +00:00
$twig->addGlobal('companies', $companies);
2024-04-01 17:10:19 +00:00
$twig->addGlobal('dc_uri', 'https://discord.com/api/oauth2/authorize?client_id=1144248396467683338&redirect_uri=' . urlencode($_ENV['DISCORD_REDIRECT']) . '&response_type=code&scope=identify%20guilds&state=' . urlencode($_SERVER['REQUEST_URI']));
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');
});
2024-05-18 20:07:45 +00:00
$router->get('/companies', function() {
global $twig;
$twig->addGlobal('pageUri', '/companies');
echo $twig->render('companies.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
}
});
2024-05-18 20:14:49 +00:00
$router->get('/company/([a-z]+)', function ($company) {
global $twig, $mysql, $companies;
$twig->addGlobal('pageUri', '/company/' . $company);
if(!$companies[$company]) {
http_response_code(404);
echo $twig->render('404.twig');
} else {
echo $twig->render('company.twig', array('company' => $companies[$company]));
2024-05-18 20:14:49 +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) {
2024-04-01 17:10:19 +00:00
http_response_code(401);
2024-01-13 23:58:35 +00:00
2024-04-01 17:10:19 +00:00
echo '<style>body { overflow: hidden; height: 100svh; background: black; display: flex; justify-content: center; align-items: center; }</style><img src="https://http.cat/401" alt="401 Unauthorized" />';
2024-01-13 23:58:35 +00:00
} else {
echo $twig->render('admin/index.twig', array('users' => $users, 'markers' => $markers));
}
} else {
2024-04-01 17:10:19 +00:00
http_response_code(401);
2024-01-13 22:12:46 +00:00
2024-04-01 17:10:19 +00:00
echo '<style>body { overflow: hidden; height: 100svh; background: black; display: flex; justify-content: center; align-items: center; }</style><img src="https://http.cat/401" alt="401 Unauthorized" />';
}
});
$router->get('/admin/__data/page/([a-z]+)', function($page) {
global $twig, $mysql;
if (isset($_SESSION['user'])) {
$user = $mysql->getUserRecordFromId($_SESSION['user']['id']);
$users = $mysql->getUsers();
$markers = $mysql->getMarkers();
if ($user == null && $user['admin'] == 0) {
http_response_code(401);
echo '<style>body { overflow: hidden; height: 100svh; background: black; display: flex; justify-content: center; align-items: center; }</style><img src="https://http.cat/401" alt="401 Unauthorized" />';
} else {
try {
echo $twig->render('admin/pages/' . urlencode($page) . '.twig', array('users' => $users, 'markers' => $markers));
} catch (Exception $e) {
http_response_code(404);
echo $twig->render('admin/pages/404.twig');
}
}
} else {
http_response_code(401);
echo '<style>body { overflow: hidden; height: 100svh; background: black; display: flex; justify-content: center; align-items: center; }</style><img src="https://http.cat/401" alt="401 Unauthorized" />';
2024-01-13 22:12:46 +00:00
}
});
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();