stylehub/lib/router.php

39 lines
887 B
PHP
Raw Normal View History

2024-01-18 11:49:38 +01:00
<?php
2024-02-06 16:24:57 +01:00
function initRouter(): array
{
2024-01-18 11:49:38 +01:00
global $routerConfig;
2024-02-06 16:24:57 +01:00
$routerRequest = array();
2024-01-18 11:49:38 +01:00
$routerRequest["requestAddress"] = array_slice(explode('.', $_SERVER['HTTP_HOST']), -3, 3); //get the last 3 elements
2024-02-06 16:24:57 +01:00
$request_uri = explode("/", $_SERVER["QUERY_STRING"]);
2024-01-18 11:49:38 +01:00
2024-02-06 16:24:57 +01:00
$request_uri = array_slice($request_uri, -3, 3);
2024-01-18 11:49:38 +01:00
2024-02-02 15:57:26 +01:00
2024-02-15 10:19:52 +01:00
$routerRequest["site_name"] = $routerConfig["default_site"];
$routerRequest["page_name"] = $routerConfig["default_page"];
if(count($request_uri > 2)){
$routerRequest["page_name"] = basename($request_uri[2]);
2024-02-02 15:55:23 +01:00
}
2024-02-15 10:19:52 +01:00
if(count($request_uri) > 1){
$routerRequest["site_name"] = basename($request_uri[1]);
2024-02-02 15:57:26 +01:00
2024-01-18 11:49:38 +01:00
}
2024-02-06 16:24:57 +01:00
if($_SERVER["REQUEST_METHOD"] == "POST"){
$routerRequest["type"] = "api";
2024-01-18 11:49:38 +01:00
}
2024-02-15 10:17:09 +01:00
2024-02-06 16:24:57 +01:00
if(empty($routerRequest["type"])) {
$routerRequest["type"] = "page";
2024-01-18 11:49:38 +01:00
}
2024-02-06 16:24:57 +01:00
return $routerRequest;
2024-01-18 11:49:38 +01:00
}