5 require_once('library/markdown.php');
7 if (!function_exists('load_doc_file')) {
9 function load_doc_file($s) {
15 if (file_exists("$d/$lang/$b"))
16 return file_get_contents("$d/$lang/$b");
18 return file_get_contents($s);
24 function help_content(App $a) {
26 nav_set_selected('help');
34 // looping through the argv keys bigger than 0 to build
35 // a path relative to /help
36 for($x = 1; $x < argc(); $x ++) {
41 $title = basename($path);
43 $text = load_doc_file('doc/' . $path . '.md');
44 $a->page['title'] = t('Help:') . ' ' . str_replace('-', ' ', notags($title));
46 $home = load_doc_file('doc/Home.md');
50 $a->page['title'] = t('Help');
52 $a->page['aside'] = Markdown($home);
56 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
57 $tpl = get_markup_template("404.tpl");
58 return replace_macros($tpl, array(
59 '$message' => t('Page not found.')
63 $html = Markdown($text);
65 if ($filename !== "Home") {
66 // create TOC but not for home
67 $lines = explode("\n", $html);
68 $toc="<style>aside ul {padding-left: 1em;}aside h1{font-size:2em}</style><h2>TOC</h2><ul id='toc'>";
70 $idnum = array(0,0,0,0,0,0,0);
71 foreach($lines as &$line){
72 if (substr($line,0,2)=="<h") {
73 $level = substr($line,2,1);
75 $level = intval($level);
76 if ($level<$lastlevel) {
77 for($k=$level;$k<$lastlevel; $k++) $toc.="</ul>";
78 for($k=$level+1;$k<count($idnum);$k++) $idnum[$k]=0;
80 if ($level>$lastlevel) $toc.="<ul>";
82 $id = implode("_", array_slice($idnum,1,$level));
83 $href = App::get_baseurl()."/help/{$filename}#{$id}";
84 $toc .= "<li><a href='{$href}'>".strip_tags($line)."</a></li>";
85 $line = "<a name='{$id}'></a>".$line;
90 for($k=0;$k<$lastlevel; $k++) $toc.="</ul>";
91 $html = implode("\n",$lines);
93 $a->page['aside'] = '<section class="help-aside-wrapper">' . $toc . $a->page['aside'] . '</section>';
99 padding: 1em; border: #ff0000 solid 2px;
100 background-color: #f9a3a3; color: #ffffff;