1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
// namespace Anax\Page; |
4
|
|
|
namespace Marcusgsta\Page; |
5
|
|
|
|
6
|
|
|
use \Anax\DI\InjectionAwareInterface; |
7
|
|
|
use \Anax\DI\InjectionAwareTrait; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* A default page rendering class. |
11
|
|
|
*/ |
12
|
|
|
class FlatFileContentController implements InjectionAwareInterface |
13
|
|
|
{ |
14
|
|
|
use InjectionAwareTrait; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Render a page using flat file content. |
20
|
|
|
* @SuppressWarnings(PHPMD.UnusedLocalVariable) |
21
|
|
|
* |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
|
|
public function render() |
25
|
|
|
{ |
26
|
|
|
// Get the current route and see if it matches a content/file |
27
|
|
|
$path = $this->di->get("request")->getRoute(); |
28
|
|
|
$file1 = ANAX_INSTALL_PATH . "/content/${path}.md"; |
29
|
|
|
$file2 = ANAX_INSTALL_PATH . "/content/${path}/index.md"; |
30
|
|
|
|
31
|
|
|
$file = is_file($file1) ? $file1 : null; |
32
|
|
|
$file = is_file($file2) ? $file2 : $file; |
33
|
|
|
|
34
|
|
|
if (!$file) { |
|
|
|
|
35
|
|
|
return; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
// Check that file is really in the right place |
39
|
|
|
$real = realpath($file); |
40
|
|
|
$base = realpath(ANAX_INSTALL_PATH . "/content/"); |
41
|
|
|
if (strncmp($base, $real, strlen($base))) { |
42
|
|
|
return; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
// Get content from markdown file |
46
|
|
|
$content = file_get_contents($file); |
47
|
|
|
$content = $this->di->get("textfilter")->parse( |
48
|
|
|
$content, |
49
|
|
|
["yamlfrontmatter", "shortcode", "markdown", "titlefromheader"] |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
// Render a standard page using layout |
53
|
|
|
$this->di->get("view")->add("default1/article", [ |
54
|
|
|
"content" => $content->text, |
55
|
|
|
"frontmatter" => $content->frontmatter, |
56
|
|
|
]); |
57
|
|
|
$this->di->get("pageRender")->renderPage($content->frontmatter); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: