]> git.mxchange.org Git - friendica.git/blob - mod/babel.php
Move Composer autoload require out of boot.php
[friendica.git] / mod / babel.php
1 <?php
2 /**
3  * @file mod/babel.php
4  */
5
6 use Friendica\Content\Text;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Renderer;
9
10 function visible_whitespace($s)
11 {
12         $s = str_replace(' ', '&nbsp;', $s);
13
14         return str_replace(["\r\n", "\n", "\r"], '<br />', $s);
15 }
16
17 function babel_content()
18 {
19         $results = [];
20         if (!empty($_REQUEST['text'])) {
21                 switch (defaults($_REQUEST, 'type', 'bbcode')) {
22                         case 'bbcode':
23                                 $bbcode = trim($_REQUEST['text']);
24                                 $results[] = [
25                                         'title' => L10n::t('Source input'),
26                                         'content' => visible_whitespace($bbcode)
27                                 ];
28
29                                 $plain = Text\BBCode::toPlaintext($bbcode, false);
30                                 $results[] = [
31                                         'title' => L10n::t('BBCode::toPlaintext'),
32                                         'content' => visible_whitespace($plain)
33                                 ];
34
35                                 $html = Text\BBCode::convert($bbcode);
36                                 $results[] = [
37                                         'title' => L10n::t('BBCode::convert (raw HTML)'),
38                                         'content' => visible_whitespace(htmlspecialchars($html))
39                                 ];
40
41                                 $results[] = [
42                                         'title' => L10n::t('BBCode::convert'),
43                                         'content' => $html
44                                 ];
45
46                                 $bbcode2 = Text\HTML::toBBCode($html);
47                                 $results[] = [
48                                         'title' => L10n::t('BBCode::convert => HTML::toBBCode'),
49                                         'content' => visible_whitespace($bbcode2)
50                                 ];
51
52                                 $markdown = Text\BBCode::toMarkdown($bbcode);
53                                 $results[] = [
54                                         'title' => L10n::t('BBCode::toMarkdown'),
55                                         'content' => visible_whitespace($markdown)
56                                 ];
57
58                                 $html2 = Text\Markdown::convert($markdown);
59                                 $results[] = [
60                                         'title' => L10n::t('BBCode::toMarkdown => Markdown::convert'),
61                                         'content' => $html2
62                                 ];
63
64                                 $bbcode3 = Text\Markdown::toBBCode($markdown);
65                                 $results[] = [
66                                         'title' => L10n::t('BBCode::toMarkdown => Markdown::toBBCode'),
67                                         'content' => visible_whitespace($bbcode3)
68                                 ];
69
70                                 $bbcode4 = Text\HTML::toBBCode($html2);
71                                 $results[] = [
72                                         'title' => L10n::t('BBCode::toMarkdown =>  Markdown::convert => HTML::toBBCode'),
73                                         'content' => visible_whitespace($bbcode4)
74                                 ];
75                                 break;
76                         case 'markdown':
77                                 $markdown = trim($_REQUEST['text']);
78                                 $results[] = [
79                                         'title' => L10n::t('Source input (Diaspora format)'),
80                                         'content' => '<pre>' . $markdown . '</pre>'
81                                 ];
82
83                                 $html = Text\Markdown::convert($markdown);
84                                 $results[] = [
85                                         'title' => L10n::t('Markdown::convert (raw HTML)'),
86                                         'content' => htmlspecialchars($html)
87                                 ];
88
89                                 $results[] = [
90                                         'title' => L10n::t('Markdown::convert'),
91                                         'content' => $html
92                                 ];
93
94                                 $bbcode = Text\Markdown::toBBCode($markdown);
95                                 $results[] = [
96                                         'title' => L10n::t('Markdown::toBBCode'),
97                                         'content' => '<pre>' . $bbcode . '</pre>'
98                                 ];
99                                 break;
100                         case 'html' :
101                                 $html = trim($_REQUEST['text']);
102                                 $results[] = [
103                                         'title' => L10n::t('Raw HTML input'),
104                                         'content' => htmlspecialchars($html)
105                                 ];
106
107                                 $results[] = [
108                                         'title' => L10n::t('HTML Input'),
109                                         'content' => $html
110                                 ];
111
112                                 $bbcode = Text\HTML::toBBCode($html);
113                                 $results[] = [
114                                         'title' => L10n::t('HTML::toBBCode'),
115                                         'content' => visible_whitespace($bbcode)
116                                 ];
117
118                                 $html2 = Text\BBCode::convert($bbcode);
119                                 $results[] = [
120                                         'title' => L10n::t('HTML::toBBCode => BBCode::convert'),
121                                         'content' => $html2
122                                 ];
123
124                                 $results[] = [
125                                         'title' => L10n::t('HTML::toBBCode => BBCode::convert (raw HTML)'),
126                                         'content' => htmlspecialchars($html2)
127                                 ];
128
129                                 $markdown = Text\HTML::toMarkdown($html);
130                                 $results[] = [
131                                         'title' => L10n::t('HTML::toMarkdown'),
132                                         'content' => visible_whitespace($markdown)
133                                 ];
134
135                                 $text = Text\HTML::toPlaintext($html);
136                                 $results[] = [
137                                         'title' => L10n::t('HTML::toPlaintext'),
138                                         'content' => '<pre>' . $text . '</pre>'
139                                 ];
140                 }
141         }
142
143         $tpl = Renderer::getMarkupTemplate('babel.tpl');
144         $o = Renderer::replaceMacros($tpl, [
145                 '$text'          => ['text', L10n::t('Source text'), htmlentities(defaults($_REQUEST, 'text', '')), ''],
146                 '$type_bbcode'   => ['type', L10n::t('BBCode'), 'bbcode', '', defaults($_REQUEST, 'type', 'bbcode') == 'bbcode'],
147                 '$type_markdown' => ['type', L10n::t('Markdown'), 'markdown', '', defaults($_REQUEST, 'type', 'bbcode') == 'markdown'],
148                 '$type_html'     => ['type', L10n::t('HTML'), 'html', '', defaults($_REQUEST, 'type', 'bbcode') == 'html'],
149                 '$results'       => $results
150         ]);
151
152         return $o;
153 }