6 use Friendica\Content\Nav;
7 use Friendica\Content\Text\Markdown;
8 use Friendica\Core\L10n;
9 use Friendica\Core\System;
11 if (!function_exists('load_doc_file')) {
13 function load_doc_file($s) {
19 if (file_exists("$d/$lang/$b"))
20 return file_get_contents("$d/$lang/$b");
22 return file_get_contents($s);
28 function help_content(App $a) {
30 Nav::setSelected('help');
38 // looping through the argv keys bigger than 0 to build
39 // a path relative to /help
40 for($x = 1; $x < argc(); $x ++) {
45 $title = basename($path);
47 $text = load_doc_file('doc/' . $path . '.md');
48 $a->page['title'] = L10n::t('Help:') . ' ' . str_replace('-', ' ', notags($title));
50 $home = load_doc_file('doc/Home.md');
54 $a->page['title'] = L10n::t('Help');
56 $a->page['aside'] = Markdown::convert($home, false);
60 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . L10n::t('Not Found'));
61 $tpl = get_markup_template("404.tpl");
62 return replace_macros($tpl, [
63 '$message' => L10n::t('Page not found.')
67 $html = Markdown::convert($text, false);
69 if ($filename !== "Home") {
70 // create TOC but not for home
71 $lines = explode("\n", $html);
72 $toc="<style>aside ul {padding-left: 1em;}aside h1{font-size:2em}</style><h2>TOC</h2><ul id='toc'>";
74 $idnum = [0,0,0,0,0,0,0];
75 foreach($lines as &$line){
76 if (substr($line,0,2)=="<h") {
77 $level = substr($line,2,1);
79 $level = intval($level);
80 if ($level<$lastlevel) {
81 for($k=$level;$k<$lastlevel; $k++) $toc.="</ul>";
82 for($k=$level+1;$k<count($idnum);$k++) $idnum[$k]=0;
84 if ($level>$lastlevel) $toc.="<ul>";
86 $id = implode("_", array_slice($idnum,1,$level));
87 $href = System::baseUrl()."/help/{$filename}#{$id}";
88 $toc .= "<li><a href='{$href}'>".strip_tags($line)."</a></li>";
89 $line = "<a name='{$id}'></a>".$line;
94 for($k=0;$k<$lastlevel; $k++) $toc.="</ul>";
95 $html = implode("\n",$lines);
97 $a->page['aside'] = '<section class="help-aside-wrapper">' . $toc . $a->page['aside'] . '</section>';
103 padding: 1em; border: #ff0000 solid 2px;
104 background-color: #f9a3a3; color: #ffffff;