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 throw new \Friendica\Network\HTTPException\NotFoundException();
68 $html = Markdown::convert($text, false);
70 if ($filename !== "Home") {
71 // create TOC but not for home
72 $lines = explode("\n", $html);
73 $toc = "<h2>TOC</h2><ul id='toc'>";
75 $idnum = [0, 0, 0, 0, 0, 0, 0];
76 foreach ($lines as &$line) {
77 if (substr($line, 0, 2) == "<h") {
78 $level = substr($line, 2, 1);
80 $level = intval($level);
81 if ($level < $lastlevel) {
82 for ($k = $level; $k < $lastlevel; $k++) {
86 for ($k = $level + 1; $k < count($idnum); $k++) {
91 if ($level > $lastlevel) {
96 $id = implode("_", array_slice($idnum, 1, $level));
97 $href = System::baseUrl() . "/help/{$filename}#{$id}";
98 $toc .= "<li><a href='{$href}'>" . strip_tags($line) . "</a></li>";
99 $line = "<a name='{$id}'></a>" . $line;
105 for ($k = 0; $k < $lastlevel; $k++) {
109 $html = implode("\n", $lines);
111 $a->page['aside'] = '<div class="help-aside-wrapper widget"><div id="toc-wrapper">' . $toc . '</div>' . $a->page['aside'] . '</div>';