2 require_once('library/markdown.php');
4 if (!function_exists('load_doc_file')) {
6 function load_doc_file($s) {
12 if (file_exists("$d/$lang/$b"))
13 return file_get_contents("$d/$lang/$b");
15 return file_get_contents($s);
21 function help_content(App $a) {
23 nav_set_selected('help');
31 // looping through the argv keys bigger than 0 to build
32 // a path relative to /help
33 for($x = 1; $x < argc(); $x ++) {
38 $title = basename($path);
40 $text = load_doc_file('doc/' . $path . '.md');
41 $a->page['title'] = t('Help:') . ' ' . str_replace('-', ' ', notags($title));
43 $home = load_doc_file('doc/Home.md');
47 $a->page['title'] = t('Help');
49 $a->page['aside'] = Markdown($home);
53 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
54 $tpl = get_markup_template("404.tpl");
55 return replace_macros($tpl, array(
56 '$message' => t('Page not found.')
60 $html = Markdown($text);
62 if ($filename !== "Home") {
63 // create TOC but not for home
64 $lines = explode("\n", $html);
65 $toc="<style>aside ul {padding-left: 1em;}aside h1{font-size:2em}</style><h2>TOC</h2><ul id='toc'>";
67 $idnum = array(0,0,0,0,0,0,0);
68 foreach($lines as &$line){
69 if (substr($line,0,2)=="<h") {
70 $level = substr($line,2,1);
72 $level = intval($level);
73 if ($level<$lastlevel) {
74 for($k=$level;$k<$lastlevel; $k++) $toc.="</ul>";
75 for($k=$level+1;$k<count($idnum);$k++) $idnum[$k]=0;
77 if ($level>$lastlevel) $toc.="<ul>";
79 $id = implode("_", array_slice($idnum,1,$level));
80 $href = App::get_baseurl()."/help/{$filename}#{$id}";
81 $toc .= "<li><a href='{$href}'>".strip_tags($line)."</a></li>";
82 $line = "<a name='{$id}'></a>".$line;
87 for($k=0;$k<$lastlevel; $k++) $toc.="</ul>";
88 $html = implode("\n",$lines);
90 $a->page['aside'] = $toc.$a->page['aside'];
96 padding: 1em; border: #ff0000 solid 2px;
97 background-color: #f9a3a3; color: #ffffff;