]> git.mxchange.org Git - friendica.git/blob - mod/help.php
Merge pull request #1338 from annando/1501-global-contacts
[friendica.git] / mod / help.php
1 <?php
2 define( 'MARKDOWN_PARSER_CLASS',  'ExtendedMarkdown' );
3 require_once('library/markdown.php');
4
5 class ExtendedMarkdown extends MarkdownExtra_Parser {
6
7         function ExtendedMarkdown() {
8                 $this->block_gamut += array(
9                         "doBlockWarning" => 45,
10                 );
11                 parent::MarkdownExtra_Parser();
12         }
13
14         function doBlockWarning($text) {
15                 $text = preg_replace_callback('/
16                           (                                                             # Wrap whole match in $1
17                                 (?>
18                                   ^[ ]*![ ]?                            # "!" at the start of a line
19                                         .+\n                                    # rest of the first line
20                                   (.+\n)*                                       # subsequent consecutive lines
21                                   \n*                                           # blanks
22                                 )+
23                           )
24                         /xm', array(&$this, '_doBlockWarning_callback'), $text);
25
26                 return $text;
27         }
28
29         function _doBlockWarning_callback($matches) {
30                 $bq = $matches[1];
31                 # trim one level of quoting - trim whitespace-only lines
32                 $bq = preg_replace('/^[ ]*![ ]?|^[ ]+$/m', '', $bq);
33                 $bq = $this->runBlockGamut($bq);  # recurse
34
35                 $bq = preg_replace('/^/m', "  ", $bq);
36                 # These leading spaces cause problem with <pre> content, 
37                 # so we need to fix that:
38 //              $bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx', array(&$this, '__doBlockWarning_callback2'), $bq);
39
40                 return "\n" . $this->hashBlock("<div class='md_warning'>\n$bq\n</div>") . "\n\n";
41         }
42
43         function _doBlockWarning_callback2($matches) {
44                 $pre = $matches[1];
45                 $pre = preg_replace('/^  /m', '', $pre);
46                 return $pre;
47         }
48
49 }
50
51 if (!function_exists('load_doc_file')) {
52
53         function load_doc_file($s) {
54                 global $lang;
55                 if (!isset($lang))
56                         $lang = 'en';
57                 $b = basename($s);
58                 $d = dirname($s);
59                 if (file_exists("$d/$lang/$b"))
60                         return file_get_contents("$d/$lang/$b");
61                 if (file_exists($s))
62                         return file_get_contents($s);
63                 return '';
64         }
65
66 }
67
68 function help_content(&$a) {
69         
70         
71         nav_set_selected('help');
72
73         global $lang;
74
75         $text = '';
76
77         if ($a->argc > 1) {
78                 $text = load_doc_file('doc/' . $a->argv[1] . '.md');
79                 $a->page['title'] = t('Help:') . ' ' . str_replace('-', ' ', notags($a->argv[1]));
80         }
81         $home = load_doc_file('doc/Home.md');
82         if (!$text) {
83                 $text = $home;
84                 $a->page['title'] = t('Help');
85         } else {
86                 $a->page['aside'] = Markdown($home);
87         }
88
89         if (!strlen($text)) {
90                 header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found'));
91                 $tpl = get_markup_template("404.tpl");
92                 return replace_macros($tpl, array(
93                                         '$message' => t('Page not found.')
94                                 ));
95         }
96         
97         $html = Markdown($text);
98         $html = "<style>.md_warning { padding: 1em; border: #ff0000 solid 2px; background-color: #f9a3a3; color: #ffffff;</style>".$html;
99         return $html;
100                 
101 }