many small updates
[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 $this->app->getView()->addData(["title" => "About: $title"]);
23 if ($title === "Packager hook") {
24 $baseUrl = $this->app->getBaseUrl();
25 $this->app->getView()->addData([
26 "styles" => [$baseUrl->mod("./highlight/styles/dark.css")],
27 "scripts" => [
28 $baseUrl->mod("./highlight/highlight.pack.js"),
29 "hljs.initHighlightingOnLoad();"
30 ]
31 ]);
32 }
33 $page = $this->wikiPath($args["page"]);
34 $this->app->display("pages/wiki", compact("title", "page"));
35 }
36
37 function wikiPages() {
38 return array_filter(array_map(function($s) {
39 return strtr(basename($s, ".md"), "-", " ");
40 }, scandir(self::WIKI_PATH)), function($s) {
41 return $s{0} !== ".";
42 });
43 }
44
45 function wikiPath($page) {
46 $file = basename(strtr($page, " ", "-"), ".md") . ".md";
47 return self::WIKI_PATH . $file;
48 }
49 }