6 use Friendica\Content\Nav;
7 use Friendica\Content\Text\Markdown;
8 use Friendica\Core\System;
10 if (!function_exists('load_doc_file')) {
12 function load_doc_file($s) {
18 if (file_exists("$d/$lang/$b"))
19 return file_get_contents("$d/$lang/$b");
21 return file_get_contents($s);
27 function help_content(App $a) {
29 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 ++) {
44 $title = basename($path);
46 $text = load_doc_file('doc/' . $path . '.md');
47 $a->page['title'] = t('Help:') . ' ' . str_replace('-', ' ', notags($title));
49 $home = load_doc_file('doc/Home.md');
53 $a->page['title'] = t('Help');
55 $a->page['aside'] = Markdown::convert($home, false);
59 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
60 $tpl = get_markup_template("404.tpl");
61 return replace_macros($tpl, [
62 '$message' => t('Page not found.')
66 $html = Markdown::convert($text, false);
68 if ($filename !== "Home") {
69 // create TOC but not for home
70 $lines = explode("\n", $html);
71 $toc="<style>aside ul {padding-left: 1em;}aside h1{font-size:2em}</style><h2>TOC</h2><ul id='toc'>";
73 $idnum = [0,0,0,0,0,0,0];
74 foreach($lines as &$line){
75 if (substr($line,0,2)=="<h") {
76 $level = substr($line,2,1);
78 $level = intval($level);
79 if ($level<$lastlevel) {
80 for($k=$level;$k<$lastlevel; $k++) $toc.="</ul>";
81 for($k=$level+1;$k<count($idnum);$k++) $idnum[$k]=0;
83 if ($level>$lastlevel) $toc.="<ul>";
85 $id = implode("_", array_slice($idnum,1,$level));
86 $href = System::baseUrl()."/help/{$filename}#{$id}";
87 $toc .= "<li><a href='{$href}'>".strip_tags($line)."</a></li>";
88 $line = "<a name='{$id}'></a>".$line;
93 for($k=0;$k<$lastlevel; $k++) $toc.="</ul>";
94 $html = implode("\n",$lines);
96 $a->page['aside'] = '<section class="help-aside-wrapper">' . $toc . $a->page['aside'] . '</section>';
102 padding: 1em; border: #ff0000 solid 2px;
103 background-color: #f9a3a3; color: #ffffff;