aboutsummaryrefslogtreecommitdiff
path: root/src/View
diff options
context:
space:
mode:
authorChristian Cleberg <hello@cleberg.net>2023-06-14 22:08:34 -0500
committerChristian Cleberg <hello@cleberg.net>2023-06-14 22:08:34 -0500
commit49efb238b879bce764d04dad99c7a169e80f93dd (patch)
tree7b1d26dbe86710ee7830b3fe6ff82afff3712e2d /src/View
parent53488151f29e3afbd1b1348597ff2123b97ad2d7 (diff)
downloadhn-49efb238b879bce764d04dad99c7a169e80f93dd.tar.gz
hn-49efb238b879bce764d04dad99c7a169e80f93dd.tar.bz2
hn-49efb238b879bce764d04dad99c7a169e80f93dd.zip
massive overhaul to implement proper MVC
Diffstat (limited to 'src/View')
-rw-r--r--src/View/BaseTemplate.php35
-rw-r--r--src/View/class-template.php58
2 files changed, 35 insertions, 58 deletions
diff --git a/src/View/BaseTemplate.php b/src/View/BaseTemplate.php
new file mode 100644
index 0000000..17bc39e
--- /dev/null
+++ b/src/View/BaseTemplate.php
@@ -0,0 +1,35 @@
+<!doctype html>
+<html lang="en">
+
+<head>
+ <title><?php echo $this->title; ?></title>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
+ <meta http-equiv="x-ua-compatible" content="ie=edge">
+ <meta name="author" content="<?php echo $GLOBALS['author_name']; ?>">
+ <meta name="description" content="<?php echo $this->description; ?>">
+ <link rel="canonical" href="<?php echo $this->canonical_url; ?>">
+ <link rel="stylesheet" href="/static/styles.min.css">
+</head>
+
+<body>
+<main id="main">
+ <nav class="links">
+ <span><a href="/">Top</a> &middot; </span>
+ <span><a href="/best/">Best</a> &middot;</span>
+ <span><a href="/new/">New</a> &middot;</span>
+ <span><a href="/ask/">Ask</a> &middot;</span>
+ <span><a href="/show/">Show</a> &middot;</span>
+ <span><a href="/job/">Job</a></span>
+ </nav>
+ <?php echo $this->content; ?>
+</main>
+
+<footer>
+ <p><a href="https://sr.ht/~cmc/hn/">Source Code</a></p>
+ <p>Copyright &copy; 2023 - <?php echo $this->current_year; ?></p>
+</footer>
+
+</body>
+
+</html>
diff --git a/src/View/class-template.php b/src/View/class-template.php
deleted file mode 100644
index 9a3c598..0000000
--- a/src/View/class-template.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-
-namespace HN\View;
-
-/**
-* Template View
-*
-* @author cmc <hello@cleberg.net>
-*/
-class Template
-{
- /**
- * @var string
- */
- private $canonical_url;
- /**
- * @var string
- */
- private $description;
- /**
- * @var string
- */
- private $title;
- /**
- * @var string
- */
- private $content;
- /**
- * @var false|string
- */
- private $current_year;
-
- public function __construct(string $canonical_url, string $page_description, string $page_title, string $content_col) {
- $this->canonical_url = $canonical_url;
- $this->description = $page_description;
- $this->title = $page_title;
- $this->content = $content_col;
- $this->current_year = date("Y");
- }
-
- public function echo_template(string $template_file) {
- // Get the template file
- $page = file_get_contents($template_file);
-
- // Replace the template variables
- $page = str_replace('{page_title}', $this->title, $page);
- $page = str_replace('{page_description}', $this->description, $page);
- $page = str_replace('{canonical_url}', $this->canonical_url, $page);
- $page = str_replace('{content}', $this->content, $page);
- $page = str_replace('{current_year}', $this->current_year, $page);
-
- // Echo the filled-out template
- echo $page;
- }
-}
-
-// EOF
-