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 ++) {
39 $title = basename($path);
41 $text = load_doc_file('doc/' . $path . '.md');
42 $a->page['title'] = t('Help:') . ' ' . str_replace('-', ' ', notags($title));
44 $home = load_doc_file('doc/Home.md');
48 $a->page['title'] = t('Help');
50 $a->page['aside'] = Markdown($home);
54 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
55 $tpl = get_markup_template("404.tpl");
56 return replace_macros($tpl, array(
57 '$message' => t('Page not found.')
61 $html = Markdown($text);
63 if ($filename !== "Home") {
64 // create TOC but not for home
65 $lines = explode("\n", $html);
66 $toc="<style>aside ul {padding-left: 1em;}aside h1{font-size:2em}</style><h2>TOC</h2><ul id='toc'>";
68 $idnum = array(0,0,0,0,0,0,0);
69 foreach ($lines as &$line){
70 if (substr($line,0,2)=="<h") {
71 $level = substr($line,2,1);
73 $level = intval($level);
74 if ($level<$lastlevel) {
75 for ($k=$level;$k<$lastlevel; $k++) {
78 for ($k=$level+1;$k<count($idnum);$k++) {
82 if ($level>$lastlevel) {
86 $id = implode("_", array_slice($idnum,1,$level));
87 $href = App::get_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'] = $toc.$a->page['aside'];
103 padding: 1em; border: #ff0000 solid 2px;
104 background-color: #f9a3a3; color: #ffffff;