somewhat broken...

This commit is contained in:
sorenpeter 2023-11-08 20:58:00 +01:00
parent f6e9e9577b
commit 5bfdac005f
10 changed files with 12 additions and 8 deletions

View file

@ -1,8 +1,10 @@
<?php
//require_once("router.php");
//require_once("views/home.php");
//require_once("partials/base.php");
// Adds support for installation in subfolder
$base = dirname($_SERVER['PHP_SELF']) ;
if ($base === '/' || $base === '\\'){
$base = '';
}
$request = $_SERVER['REQUEST_URI'];
$path = parse_url($request, PHP_URL_PATH);
@ -27,9 +29,10 @@ $routes = [
'/post/([a-zA-Z0-9]{7})' => 'post.php', // matches only twtHash of exactly 7 alphanumeric characters
];
// Loop through the defined routes and try to match the request URI
foreach ($routes as $pattern => $action) {
if (preg_match('#^' . $pattern . '$#', $path, $matches)) {
if (preg_match('#^' . $base.$pattern . '$#', $path, $matches)) {
// Extract any matched parameters (e.g., username)
if(!empty($matches[1])) {
@ -46,6 +49,7 @@ foreach ($routes as $pattern => $action) {
// If no matching route is found, handle as a 404
http_response_code(404);
echo "<h1>Oops! Page not found.</h1>";
echo __DIR__ . $viewDir . $action;
/* Credit:
- PHP FOR BEGINNERS #4 - Create a dynamic Router: https://www.youtube.com/watch?v=eaHBK2XJ5Io

View file

@ -1,7 +1,7 @@
<?php
$profile = getTwtsFromTwtxtString($config['public_txt_url']);
$profile = getTwtsFromTwtxtString("http://darch.dk/twtxt.txt");
// $profile = getTwtsFromTwtxtString("http://darch.dk/twtxt.txt");
?>

View file

@ -33,12 +33,12 @@ if (!empty($_GET['twts'])) { // Show profile for some user
if (isset($_SESSION['password'])) {
include 'views/new_twt.php'; // TODO: Split up new_twt into a view and a partial
}
else {
/*else {
$twtsURL = $config['public_txt_url'];
// $twtsURL = "http://darch.dk/twtxt.txt";
header("Location: /profile?url=".$twtsURL);
header("Location: profile?url=".$twtsURL);
// die();
}
}*/
?>