]> git.mxchange.org Git - friendica.git/blob - mod/help.php
Remove unused global cache constants
[friendica.git] / mod / help.php
1 <?php
2 /**
3  * @file mod/help.php
4  */
5 use Friendica\App;
6 use Friendica\Content\Nav;
7 use Friendica\Content\Text\Markdown;
8 use Friendica\Core\L10n;
9 use Friendica\Core\System;
10
11 if (!function_exists('load_doc_file')) {
12
13         function load_doc_file($s) {
14                 global $lang;
15                 if (!isset($lang))
16                         $lang = 'en';
17                 $b = basename($s);
18                 $d = dirname($s);
19                 if (file_exists("$d/$lang/$b"))
20                         return file_get_contents("$d/$lang/$b");
21                 if (file_exists($s))
22                         return file_get_contents($s);
23                 return '';
24         }
25
26 }
27
28 function help_content(App $a) {
29
30         Nav::setSelected('help');
31
32         global $lang;
33
34         $text = '';
35
36         if ($a->argc > 1) {
37                 $path = '';
38                 // looping through the argv keys bigger than 0 to build
39                 // a path relative to /help
40                 for($x = 1; $x < argc(); $x ++) {
41                         if(strlen($path))
42                                 $path .= '/';
43                         $path .= argv($x);
44                 }
45                 $title = basename($path);
46                 $filename = $path;
47                 $text = load_doc_file('doc/' . $path . '.md');
48                 $a->page['title'] = L10n::t('Help:') . ' ' . str_replace('-', ' ', notags($title));
49         }
50         $home = load_doc_file('doc/Home.md');
51         if (!$text) {
52                 $text = $home;
53                 $filename = "Home";
54                 $a->page['title'] = L10n::t('Help');
55         } else {
56                 $a->page['aside'] = Markdown::convert($home, false);
57         }
58
59         if (!strlen($text)) {
60                 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . L10n::t('Not Found'));
61                 $tpl = get_markup_template("404.tpl");
62                 return replace_macros($tpl, [
63                                         '$message' => L10n::t('Page not found.')
64                                 ]);
65         }
66
67         $html = Markdown::convert($text, false);
68
69         if ($filename !== "Home") {
70                 // create TOC but not for home
71                 $lines = explode("\n", $html);
72                 $toc="<style>aside ul {padding-left: 1em;}aside h1{font-size:2em}</style><h2>TOC</h2><ul id='toc'>";
73                 $lastlevel=1;
74                 $idnum = [0,0,0,0,0,0,0];
75                 foreach($lines as &$line){
76                         if (substr($line,0,2)=="<h") {
77                                 $level = substr($line,2,1);
78                                 if ($level!="r") {
79                                         $level = intval($level);
80                                         if ($level<$lastlevel) {
81                                                 for($k=$level;$k<$lastlevel; $k++) $toc.="</ul>";
82                                                 for($k=$level+1;$k<count($idnum);$k++) $idnum[$k]=0;
83                                         }
84                                         if ($level>$lastlevel) $toc.="<ul>";
85                                         $idnum[$level]++;
86                                         $id = implode("_", array_slice($idnum,1,$level));
87                                         $href = System::baseUrl()."/help/{$filename}#{$id}";
88                                         $toc .= "<li><a href='{$href}'>".strip_tags($line)."</a></li>";
89                                         $line = "<a name='{$id}'></a>".$line;
90                                         $lastlevel = $level;
91                                 }
92                         }
93                 }
94                 for($k=0;$k<$lastlevel; $k++) $toc.="</ul>";
95                 $html = implode("\n",$lines);
96
97                 $a->page['aside'] = '<section class="help-aside-wrapper">' . $toc . $a->page['aside'] . '</section>';
98         }
99
100         $html = "
101                 <style>
102                 .md_warning {
103                         padding: 1em; border: #ff0000 solid 2px;
104                         background-color: #f9a3a3; color: #ffffff;
105                 }
106                 </style>".$html;
107         return $html;
108
109 }