aboutsummaryrefslogtreecommitdiff
path: root/src/View/class-template.php
blob: f0bfdcd55d2a225064f09fd00285f9ce42e368e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?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() {
		// Get the template file
		$template_file = 'templates/template.html';
		$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