7 use Friendica\Content\Nav;
8 use Friendica\Content\Text\Markdown;
9 use Friendica\Core\Config;
10 use Friendica\Core\L10n;
11 use Friendica\Core\Renderer;
12 use Friendica\Core\System;
13 use Friendica\Util\Strings;
15 function load_doc_file($s)
17 $lang = Config::get('system', 'language');
20 if (file_exists("$d/$lang/$b")) {
21 return file_get_contents("$d/$lang/$b");
24 if (file_exists($s)) {
25 return file_get_contents($s);
31 function help_content(App $a)
33 Nav::setSelected('help');
40 // looping through the argv keys bigger than 0 to build
41 // a path relative to /help
42 for ($x = 1; $x < $a->argc; $x ++) {
47 $path .= $a->getArgumentValue($x);
49 $title = basename($path);
51 $text = load_doc_file('doc/' . $path . '.md');
52 $a->page['title'] = L10n::t('Help:') . ' ' . str_replace('-', ' ', Strings::escapeTags($title));
55 $home = load_doc_file('doc/Home.md');
59 $a->page['title'] = L10n::t('Help');
61 $a->page['aside'] = Markdown::convert($home, false);
65 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . L10n::t('Not Found'));
66 $tpl = Renderer::getMarkupTemplate("404.tpl");
67 return Renderer::replaceMacros($tpl, [
68 '$message' => L10n::t('Page not found.')
72 $html = Markdown::convert($text, false);
74 if ($filename !== "Home") {
75 // create TOC but not for home
76 $lines = explode("\n", $html);
77 $toc = "<h2>TOC</h2><ul id='toc'>";
79 $idnum = [0, 0, 0, 0, 0, 0, 0];
80 foreach ($lines as &$line) {
81 if (substr($line, 0, 2) == "<h") {
82 $level = substr($line, 2, 1);
84 $level = intval($level);
85 if ($level < $lastlevel) {
86 for ($k = $level; $k < $lastlevel; $k++) {
90 for ($k = $level + 1; $k < count($idnum); $k++) {
95 if ($level > $lastlevel) {
100 $id = implode("_", array_slice($idnum, 1, $level));
101 $href = System::baseUrl() . "/help/{$filename}#{$id}";
102 $toc .= "<li><a href='{$href}'>" . strip_tags($line) . "</a></li>";
103 $line = "<a name='{$id}'></a>" . $line;
109 for ($k = 0; $k < $lastlevel; $k++) {
113 $html = implode("\n", $lines);
115 $a->page['aside'] = '<div class="help-aside-wrapper widget"><div id="toc-wrapper">' . $toc . '</div>' . $a->page['aside'] . '</div>';