1 | <?php |
||
11 | class FlatFileContentController implements ContainerInjectableInterface |
||
12 | { |
||
13 | use ContainerInjectableTrait; |
||
14 | |||
15 | |||
16 | |||
17 | /** |
||
18 | * Render a page using flat file content. |
||
19 | * |
||
20 | * @return mixed as null when flat file is not found and otherwise a |
||
21 | * complete response object with content to render. |
||
22 | */ |
||
23 | public function catchAll() |
||
24 | { |
||
25 | // Get the current route and see if it matches a content/file |
||
26 | $path = $this->di->get("request")->getRoute(); |
||
27 | $file1 = ANAX_INSTALL_PATH . "/content/${path}.md"; |
||
28 | $file2 = ANAX_INSTALL_PATH . "/content/${path}/index.md"; |
||
29 | |||
30 | $file = is_file($file1) ? $file1 : null; |
||
31 | $file = is_file($file2) ? $file2 : $file; |
||
32 | |||
33 | if (!$file) { |
||
|
|||
34 | return; |
||
35 | } |
||
36 | |||
37 | // Check that file is really in the right place |
||
38 | $real = realpath($file); |
||
39 | $base = realpath(ANAX_INSTALL_PATH . "/content/"); |
||
40 | if (strncmp($base, $real, strlen($base))) { |
||
41 | return; |
||
42 | } |
||
43 | |||
44 | // Get content from markdown file |
||
45 | $content = file_get_contents($file); |
||
46 | $content = $this->di->get("textfilter")->parse( |
||
47 | $content, |
||
48 | ["frontmatter", "variable", "shortcode", "markdown", "titlefromheader"] |
||
49 | ); |
||
50 | |||
51 | // Add content as a view and then render the page |
||
52 | $page = $this->di->get("page"); |
||
53 | $page->add("anax/v2/article/default", [ |
||
54 | "content" => $content->text, |
||
55 | "frontmatter" => $content->frontmatter, |
||
56 | ]); |
||
57 | |||
58 | return $page->render($content->frontmatter); |
||
61 |
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: