diff --git a/mod/help.php b/mod/help.php
deleted file mode 100644
index 19b629271..000000000
--- a/mod/help.php
+++ /dev/null
@@ -1,115 +0,0 @@
-argc > 1) {
- $path = '';
- // looping through the argv keys bigger than 0 to build
- // a path relative to /help
- for ($x = 1; $x < $a->argc; $x ++) {
- if (strlen($path)) {
- $path .= '/';
- }
-
- $path .= $a->getArgumentValue($x);
- }
- $title = basename($path);
- $filename = $path;
- $text = load_doc_file('doc/' . $path . '.md');
- $a->page['title'] = L10n::t('Help:') . ' ' . str_replace('-', ' ', Strings::escapeTags($title));
- }
-
- $home = load_doc_file('doc/Home.md');
- if (!$text) {
- $text = $home;
- $filename = "Home";
- $a->page['title'] = L10n::t('Help');
- } else {
- $a->page['aside'] = Markdown::convert($home, false);
- }
-
- if (!strlen($text)) {
- throw new \Friendica\Network\HTTPException\NotFoundException();
- }
-
- $html = Markdown::convert($text, false);
-
- if ($filename !== "Home") {
- // create TOC but not for home
- $lines = explode("\n", $html);
- $toc = "
TOC
";
- $lastlevel = 1;
- $idnum = [0, 0, 0, 0, 0, 0, 0];
- foreach ($lines as &$line) {
- if (substr($line, 0, 2) == " $lastlevel) {
- $toc .= "";
- }
-
- $idnum[$level] ++;
- $id = implode("_", array_slice($idnum, 1, $level));
- $href = System::baseUrl() . "/help/{$filename}#{$id}";
- $toc .= "- " . strip_tags($line) . "
";
- $line = "" . $line;
- $lastlevel = $level;
- }
- }
- }
-
- for ($k = 0; $k < $lastlevel; $k++) {
- $toc .= "
";
- }
-
- $html = implode("\n", $lines);
-
- $a->page['aside'] = '';
- }
-
- return $html;
-}
diff --git a/src/App/Router.php b/src/App/Router.php
index 088f8dfdd..011840d0f 100644
--- a/src/App/Router.php
+++ b/src/App/Router.php
@@ -125,6 +125,7 @@ class Router
});
$this->routeCollector->addRoute(['GET'], '/hashtag', Module\Hashtag::class);
$this->routeCollector->addRoute(['GET'], '/home', Module\Home::class);
+ $this->routeCollector->addRoute(['GET'], '/help[/{doc:.+}]', Module\Help::class);
$this->routeCollector->addRoute(['GET'], '/inbox[/{nickname}]', Module\Inbox::class);
$this->routeCollector->addRoute(['GET', 'POST'], '/invite', Module\Invite::class);
$this->routeCollector->addGroup('/install', function (RouteCollector $collector) {
diff --git a/src/Module/Help.php b/src/Module/Help.php
new file mode 100644
index 000000000..04c482852
--- /dev/null
+++ b/src/Module/Help.php
@@ -0,0 +1,122 @@
+getConfig();
+ $lang = $config->get('system', 'language');
+
+ // @TODO: Replace with parameter from router
+ if ($app->argc > 1) {
+ $path = '';
+ // looping through the argv keys bigger than 0 to build
+ // a path relative to /help
+ for ($x = 1; $x < $app->argc; $x ++) {
+ if (strlen($path)) {
+ $path .= '/';
+ }
+
+ $path .= $app->getArgumentValue($x);
+ }
+ $title = basename($path);
+ $filename = $path;
+ $text = self::loadDocFile('doc/' . $path . '.md', $lang);
+ $app->page['title'] = L10n::t('Help:') . ' ' . str_replace('-', ' ', Strings::escapeTags($title));
+ }
+
+ $home = self::loadDocFile('doc/Home.md', $lang);
+ if (!$text) {
+ $text = $home;
+ $filename = "Home";
+ $app->page['title'] = L10n::t('Help');
+ } else {
+ $app->page['aside'] = Markdown::convert($home, false);
+ }
+
+ if (!strlen($text)) {
+ throw new HTTPException\NotFoundException();
+ }
+
+ $html = Markdown::convert($text, false);
+
+ if ($filename !== "Home") {
+ // create TOC but not for home
+ $lines = explode("\n", $html);
+ $toc = "TOC
";
+ $lastLevel = 1;
+ $idNum = [0, 0, 0, 0, 0, 0, 0];
+ foreach ($lines as &$line) {
+ if (substr($line, 0, 2) == " $lastLevel) {
+ $toc .= "";
+ }
+
+ $idNum[$level] ++;
+ $id = implode("_", array_slice($idNum, 1, $level));
+ $href = $app->getBaseURL() . "/help/{$filename}#{$id}";
+ $toc .= "- " . strip_tags($line) . "
";
+ $line = "" . $line;
+ $lastLevel = $level;
+ }
+ }
+ }
+
+ for ($k = 0; $k < $lastLevel; $k++) {
+ $toc .= "
";
+ }
+
+ $html = implode("\n", $lines);
+
+ $a->page['aside'] = '';
+ }
+
+ return $html;
+ }
+
+ private static function loadDocFile($fileName, $lang = 'en')
+ {
+ $baseName = basename($fileName);
+ $dirName = dirname($fileName);
+ if (file_exists("$dirName/$lang/$baseName")) {
+ return file_get_contents("$dirName/$lang/$baseName");
+ }
+
+ if (file_exists($fileName)) {
+ return file_get_contents($fileName);
+ }
+
+ return '';
+ }
+}