|
@@ -0,0 +1,53 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+class Page
|
|
|
|
|
+{
|
|
|
|
|
+ public $requestUri;
|
|
|
|
|
+ public $targetPage;
|
|
|
|
|
+ public $title;
|
|
|
|
|
+ // This holds the "main content" of the page that will be wrapped in a simple HTML wrapper
|
|
|
|
|
+ public $content;
|
|
|
|
|
+ public $user;
|
|
|
|
|
+
|
|
|
|
|
+ public function __construct($pageName, $context = array())
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ $this->targetPage = __DIR__ . "/../templates/pages/" . $pageName . ".php";
|
|
|
|
|
+ $this->requestUri = $_SERVER["REQUEST_URI"];
|
|
|
|
|
+
|
|
|
|
|
+ $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
|
|
|
|
|
+ {
|
|
|
|
|
+ print("Target page does not exist: " . $this->targetPage);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 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";
|
|
|
|
|
+ }
|
|
|
|
|
+}
|