From 22622d6b3cef9b20137c6c374cd1f8eac563ce70 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 19 Jun 2013 02:03:56 +0200 Subject: [PATCH] Initial routing --- public_html/includes/base.php | 3 +++ public_html/modules/homepage.php | 18 ++++++++++++++++++ public_html/modules/page.php | 25 +++++++++++++++++++++++++ public_html/rewrite.php | 26 ++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 public_html/modules/homepage.php create mode 100644 public_html/modules/page.php diff --git a/public_html/includes/base.php b/public_html/includes/base.php index ec8acc1..fa9bec3 100644 --- a/public_html/includes/base.php +++ b/public_html/includes/base.php @@ -16,3 +16,6 @@ if(!isset($_APP)) { die("Unauthorized."); } $_CPHP = true; $_CPHP_CONFIG = "../config.json"; require("cphp/base.php"); + +require("lib/Markdown.php"); +require("lib/MarkdownExtra.php"); diff --git a/public_html/modules/homepage.php b/public_html/modules/homepage.php new file mode 100644 index 0000000..e8ac85f --- /dev/null +++ b/public_html/modules/homepage.php @@ -0,0 +1,18 @@ +strings, array()); diff --git a/public_html/modules/page.php b/public_html/modules/page.php new file mode 100644 index 0000000..5f1e73f --- /dev/null +++ b/public_html/modules/page.php @@ -0,0 +1,25 @@ + $router->uParameters[1]), 60, true); +} +catch (NotFoundException $e) +{ + throw new RouterException("Page does not exist."); +} + +$sPageContents = Michelf\MarkdownExtra::defaultTransform($sPage->uBody); diff --git a/public_html/rewrite.php b/public_html/rewrite.php index 3cdc267..0139b79 100644 --- a/public_html/rewrite.php +++ b/public_html/rewrite.php @@ -14,3 +14,29 @@ $_APP = true; require("includes/base.php"); +$sPageTitle = ""; +$sPageContents = ""; + +$router = new CPHPRouter(); + +$router->allow_slash = true; +$router->ignore_query = true; + +$router->routes = array( + 0 => array( + "^/$" => "modules/homepage.php", + "^/(.*)$" => "modules/page.php" + ) +); + +try +{ + $router->RouteRequest(); +} +catch (RouterException $e) +{ + http_status_code(404); + die("404 Not Found"); +} + +echo($sPageContents);