49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
// Игнорирование статических файлов
|
|
function ignore_favicon() {
|
|
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
|
|
if (preg_match('/\.(ico|png|jpg|jpeg|gif|css|js|svg|woff|woff2|ttf|eot)$/i', $requestUri)) {
|
|
http_response_code(404);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// Проверка авторизации для API
|
|
function check_ApiAuth($publicActions = []) {
|
|
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
|
|
|
|
if (strpos($requestUri, '/api/') !== false) {
|
|
$input = json_decode(file_get_contents('php://input'), true);
|
|
$action = $input['action'] ?? null;
|
|
|
|
// Публичные действия — без авторизации
|
|
|
|
if (!in_array($action, $publicActions)) {
|
|
$account = new Account();
|
|
$result = $account->check_session($_COOKIE['session'] ?? null);
|
|
if (!$result['success']) {
|
|
RestApi::response($result, 403);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Функция роутинга API
|
|
function handleRouting($routes = []) {
|
|
|
|
$request = $_SERVER['REQUEST_URI'];
|
|
$path = parse_url($request, PHP_URL_PATH);
|
|
|
|
if (isset($routes[$path])) {
|
|
|
|
$file_path = $routes[$path];
|
|
global $_POST, $_FILES, $_SERVER, $_GET;
|
|
include $file_path;
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|