inital commit
[pharext/pharext.org] / app / Controller / Wikipage.php
1 <?php
2
3 namespace app\Controller;
4
5 use app\Controller;
6 use app\Web;
7
8 class Wikipage implements Controller
9 {
10 const WIKI_PATH = "../vendor/m6w6/pharext.wiki/";
11 private $app;
12
13 function __construct(Web $app) {
14 $this->app = $app;
15 $app->getView()->addData([
16 "pages" => $this->wikiPages()
17 ]);
18 }
19
20 function __invoke(array $args = null) {
21 $title = $args["page"];
22 $page = $this->wikiPath($args["page"]);
23 $this->app->display("pages/wiki", compact("title", "page"));
24 }
25
26 function wikiPages() {
27 return array_filter(array_map(function($s) {
28 return strtr(basename($s, ".md"), "-", " ");
29 }, scandir(self::WIKI_PATH)), function($s) {
30 return $s{0} !== ".";
31 });
32 }
33 function wikiPath($page) {
34 $file = basename(strtr($page, " ", "-"), ".md") . ".md";
35 return self::WIKI_PATH . $file;
36 }
37 }