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\System;
13 function load_doc_file($s)
15 $lang = Config::get('system', 'language');
18 if (file_exists("$d/$lang/$b")) {
19 return file_get_contents("$d/$lang/$b");
22 if (file_exists($s)) {
23 return file_get_contents($s);
29 function help_content(App $a)
31 Nav::setSelected('help');
37 // looping through the argv keys bigger than 0 to build
38 // a path relative to /help
39 for ($x = 1; $x < argc(); $x ++) {
46 $title = basename($path);
48 $text = load_doc_file('doc/' . $path . '.md');
49 $a->page['title'] = L10n::t('Help:') . ' ' . str_replace('-', ' ', notags($title));
52 $home = load_doc_file('doc/Home.md');
56 $a->page['title'] = L10n::t('Help');
58 $a->page['aside'] = Markdown::convert($home, false);
62 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . L10n::t('Not Found'));
63 $tpl = get_markup_template("404.tpl");
64 return replace_macros($tpl, [
65 '$message' => L10n::t('Page not found.')
69 $html = Markdown::convert($text, false);
71 if ($filename !== "Home") {
72 // create TOC but not for home
73 $lines = explode("\n", $html);
74 $toc = "<h2>TOC</h2><ul id='toc'>";
76 $idnum = [0, 0, 0, 0, 0, 0, 0];
77 foreach ($lines as &$line) {
78 if (substr($line, 0, 2) == "<h") {
79 $level = substr($line, 2, 1);
81 $level = intval($level);
82 if ($level < $lastlevel) {
83 for ($k = $level; $k < $lastlevel; $k++) {
87 for ($k = $level + 1; $k < count($idnum); $k++) {
92 if ($level > $lastlevel) {
97 $id = implode("_", array_slice($idnum, 1, $level));
98 $href = System::baseUrl() . "/help/{$filename}#{$id}";
99 $toc .= "<li><a href='{$href}'>" . strip_tags($line) . "</a></li>";
100 $line = "<a name='{$id}'></a>" . $line;
106 for ($k = 0; $k < $lastlevel; $k++) {
110 $html = implode("\n", $lines);
112 $a->page['aside'] = '<div class="help-aside-wrapper widget"><div id="toc-wrapper">' . $toc . '</div>' . $a->page['aside'] . '</div>';