diff --git a/_wip_todo/views/home.php b/_wip_todo/views/home.php deleted file mode 100644 index 1aa6520..0000000 --- a/_wip_todo/views/home.php +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - <?=$title?> - Timeline - - - - - - - - - -
- -

- - Twts for - - Timeline for - -

- - - -
- - - - - diff --git a/index.php b/index.php index aaeae64..9311c79 100644 --- a/index.php +++ b/index.php @@ -2,45 +2,46 @@ //require_once("router.php"); //require_once("views/home.php"); -require_once("partials/base.php"); +//require_once("partials/base.php"); -?> +$request = $_SERVER['REQUEST_URI']; +$path = parse_url($request, PHP_URL_PATH); +// $query = parse_url($request, PHP_URL_QUERY); - - - - - - Timeline - - +$viewDir = '/views/'; - +// Define your routes using regular expressions -
- - 'home.php', + '/admin' => 'admin.php', + '/about' => 'about.php', + '/profile/([a-zA-Z0-9_-]+)' => 'profile.php', + '/conv/([a-zA-Z0-9]{7})' => 'conv.php', // matches only twtHash of exactly 7 alphanumeric characters + '/post/([a-zA-Z0-9]{7})' => 'post.php', // matches only twtHash of exactly 7 alphanumeric characters +]; - // TODO: Give a propper error if feed is not valid - if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) { - die('Not a valid URL'); +// Loop through the defined routes and try to match the request URI +foreach ($routes as $pattern => $action) { + if (preg_match('#^' . $pattern . '$#', $path, $matches)) { + + // Extract any matched parameters (e.g., username) + if(!empty($matches[1])) { + //array_shift($matches); + $id = $matches[1]; + } + + // Load the corresponding action (view) + require __DIR__ . $viewDir . $action; + exit; // Stop processing further routes } +} - // $parsedTwtxtFile = getTwtsFromTwtxtString($twtsURL); - if (!is_null($parsedTwtxtFile)) { - $parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile; - include 'partials/profile.php'; - } -} ?> +// If no matching route is found, handle as a 404 +http_response_code(404); +echo "

Oops! Page not found.

"; - - - -
- - - - - +/* Credit: + - PHP FOR BEGINNERS #4 - Create a dynamic Router: https://www.youtube.com/watch?v=eaHBK2XJ5Io + - https://chat.openai.com/c/3082a22a-d70e-4740-891c-9872f5da2180 +*/ \ No newline at end of file diff --git a/index_old.php b/index_old.php new file mode 100644 index 0000000..edf22a5 --- /dev/null +++ b/index_old.php @@ -0,0 +1,38 @@ + + + + + + Timeline + + + + + +
+ +mainURL] = $parsedTwtxtFile; + include 'partials/profile.php'; + } +} ?> + + + + +
+ + + + + \ No newline at end of file diff --git a/libs/Slimdown.php b/libs/Slimdown.php index 971387f..81e26dd 100644 --- a/libs/Slimdown.php +++ b/libs/Slimdown.php @@ -25,7 +25,7 @@ class Slimdown { public static $rules = array ( '/```(.*?)```/s' => self::class .'::code_parse', // code blocks //'/\n(#+)(.*)/' => self::class .'::header', // headers - '/\n(#\s+)(.*)/' => self::class .'::header', // headers - only with a space between # and text, to avoid matching with `#hashtags` + '/\n(#\s+)(.*)/' => self::class .'::header', // headers - only with a space between # and text, to avoid matching with `#hashtags` //'/\!\[([^\[]+)\]\(([^\)]+)\)/' => self::class .'::img', // images '/\!\[(.*?)\]\(([^\)]+)\)/' => self::class .'::img', // images 2 '/\[([^\[]+)\]\(([^\)]+)\)/' => self::class .'::link', // links diff --git a/libs/twtxt.php b/libs/twtxt.php index f9b680e..e857f8e 100644 --- a/libs/twtxt.php +++ b/libs/twtxt.php @@ -139,7 +139,7 @@ function replaceMentionsFromTwt(string $twtString): string { function replaceLinksFromTwt(string $twtString) { // Regular expression pattern to match URLs $pattern = '/(?$1'; $result = preg_replace($pattern, $replacement, $twtString); diff --git a/partials/header.php b/partials/header.php index bab8a96..027e7b2 100644 --- a/partials/header.php +++ b/partials/header.php @@ -1,7 +1,7 @@