]> git.mxchange.org Git - friendica.git/blob - mod/help.php
974577876d4c4dc4709ca984f0bcf84934e0b270
[friendica.git] / mod / help.php
1 <?php
2 require_once('library/markdown.php');
3
4 if (!function_exists('load_doc_file')) {
5
6         function load_doc_file($s) {
7                 global $lang;
8                 if (!isset($lang))
9                         $lang = 'en';
10                 $b = basename($s);
11                 $d = dirname($s);
12                 if (file_exists("$d/$lang/$b"))
13                         return file_get_contents("$d/$lang/$b");
14                 if (file_exists($s))
15                         return file_get_contents($s);
16                 return '';
17         }
18
19 }
20
21 function help_content(&$a) {
22
23         nav_set_selected('help');
24
25         global $lang;
26
27         $text = '';
28
29         if ($a->argc > 1) {
30                 $path = '';
31                 // looping through the argv keys bigger than 0 to build
32                 // a path relative to /help
33                 for($x = 1; $x < argc(); $x ++) {
34                         if(strlen($path))
35                                 $path .= '/';
36                         $path .= argv($x);
37                 }
38                 $title = basename($path);
39
40                 $text = load_doc_file('doc/' . $path . '.md');
41                 $a->page['title'] = t('Help:') . ' ' . str_replace('-', ' ', notags($title));
42         }
43         $home = load_doc_file('doc/Home.md');
44         if (!$text) {
45                 $text = $home;
46                 $a->page['title'] = t('Help');
47         } else {
48                 $a->page['aside'] = Markdown($home);
49         }
50
51         if (!strlen($text)) {
52                 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
53                 $tpl = get_markup_template("404.tpl");
54                 return replace_macros($tpl, array(
55                                         '$message' => t('Page not found.')
56                                 ));
57         }
58
59         $html = Markdown($text);
60         $html = "<style>.md_warning { padding: 1em; border: #ff0000 solid 2px; background-color: #f9a3a3; color: #ffffff;</style>".$html;
61         return $html;
62
63 }