4 use Friendica\Core\System;
6 require_once('library/markdown.php');
8 if (!function_exists('load_doc_file')) {
10 function load_doc_file($s) {
16 if (file_exists("$d/$lang/$b"))
17 return file_get_contents("$d/$lang/$b");
19 return file_get_contents($s);
25 function help_content(App $a) {
27 nav_set_selected('help');
35 // looping through the argv keys bigger than 0 to build
36 // a path relative to /help
37 for($x = 1; $x < argc(); $x ++) {
42 $title = basename($path);
44 $text = load_doc_file('doc/' . $path . '.md');
45 $a->page['title'] = t('Help:') . ' ' . str_replace('-', ' ', notags($title));
47 $home = load_doc_file('doc/Home.md');
51 $a->page['title'] = t('Help');
53 $a->page['aside'] = Markdown($home, false);
57 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
58 $tpl = get_markup_template("404.tpl");
59 return replace_macros($tpl, array(
60 '$message' => t('Page not found.')
64 $html = Markdown($text, false);
66 if ($filename !== "Home") {
67 // create TOC but not for home
68 $lines = explode("\n", $html);
69 $toc="<style>aside ul {padding-left: 1em;}aside h1{font-size:2em}</style><h2>TOC</h2><ul id='toc'>";
71 $idnum = array(0,0,0,0,0,0,0);
72 foreach($lines as &$line){
73 if (substr($line,0,2)=="<h") {
74 $level = substr($line,2,1);
76 $level = intval($level);
77 if ($level<$lastlevel) {
78 for($k=$level;$k<$lastlevel; $k++) $toc.="</ul>";
79 for($k=$level+1;$k<count($idnum);$k++) $idnum[$k]=0;
81 if ($level>$lastlevel) $toc.="<ul>";
83 $id = implode("_", array_slice($idnum,1,$level));
84 $href = System::baseUrl()."/help/{$filename}#{$id}";
85 $toc .= "<li><a href='{$href}'>".strip_tags($line)."</a></li>";
86 $line = "<a name='{$id}'></a>".$line;
91 for($k=0;$k<$lastlevel; $k++) $toc.="</ul>";
92 $html = implode("\n",$lines);
94 $a->page['aside'] = '<section class="help-aside-wrapper">' . $toc . $a->page['aside'] . '</section>';
100 padding: 1em; border: #ff0000 solid 2px;
101 background-color: #f9a3a3; color: #ffffff;