|
@@ -0,0 +1,72 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+class PageContext
|
|
|
|
|
+{
|
|
|
|
|
+ // Initial request path
|
|
|
|
|
+ public $requestPath;
|
|
|
|
|
+ // Path to the actual target page PHP file
|
|
|
|
|
+ public $targetPage;
|
|
|
|
|
+ // Title of the page - this is usually set in the page PHP file
|
|
|
|
|
+ public $title;
|
|
|
|
|
+ // This holds the "main content" of the page that will be wrapped in a simple HTML wrapper
|
|
|
|
|
+ public $content;
|
|
|
|
|
+ // The currently logged in user - if the user is actually logged in
|
|
|
|
|
+ public $user;
|
|
|
|
|
+
|
|
|
|
|
+ public function __construct($requestPath)
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->requestPath = $requestPath;
|
|
|
|
|
+
|
|
|
|
|
+ $targetPage = $this->requestPath;
|
|
|
|
|
+ if ($targetPage == "/")
|
|
|
|
|
+ {
|
|
|
|
|
+ $targetPage = "/home";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $targetPage = __DIR__ . "/../pages" . $targetPage . ".php";
|
|
|
|
|
+
|
|
|
|
|
+ $this->targetPage = $targetPage;
|
|
|
|
|
+ $context = array(
|
|
|
|
|
+ "requestUri" => $_SERVER["REQUEST_URI"],
|
|
|
|
|
+ "targetPage" => $targetPage,
|
|
|
|
|
+ "template" => function ($path) {
|
|
|
|
|
+ echo "TEMPLATE: " . $path;
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ $this->user = User::loadFromContext();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function render()
|
|
|
|
|
+ {
|
|
|
|
|
+ $context = $this;
|
|
|
|
|
+
|
|
|
|
|
+ // Start output buffering - everything that is "printed" while we are buffering
|
|
|
|
|
+ // is captured for later use which allows us to insert the content into a larger
|
|
|
|
|
+ // construct like the overall page template.
|
|
|
|
|
+ ob_start();
|
|
|
|
|
+
|
|
|
|
|
+ if (is_file($this->targetPage))
|
|
|
|
|
+ {
|
|
|
|
|
+ include $this->targetPage;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ include __DIR__ . "/../pages/404.php";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // End buffering and return its contents
|
|
|
|
|
+ $this->content = ob_get_clean();
|
|
|
|
|
+
|
|
|
|
|
+ // Now we take that "content" and wrap it inside of a page template so that the result
|
|
|
|
|
+ // will be a fully functional HTML page.
|
|
|
|
|
+ $this->template("html");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function template($path, $variables = array())
|
|
|
|
|
+ {
|
|
|
|
|
+ $context = $this;
|
|
|
|
|
+ extract($variables);
|
|
|
|
|
+ include __DIR__ . "/../templates/" . $path . ".php";
|
|
|
|
|
+ }
|
|
|
|
|
+}
|