]> git.mxchange.org Git - friendica.git/blob - mod/babel.php
The central item fetch does work now and the API now uses these functions
[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
9 function visible_lf($s)
10 {
11         return str_replace("\n", '<br />', $s);
12 }
13
14 function babel_content()
15 {
16         $results = [];
17         if (!empty($_REQUEST['text'])) {
18                 switch (defaults($_REQUEST, 'type', 'bbcode')) {
19                         case 'bbcode':
20                                 $bbcode = trim($_REQUEST['text']);
21                                 $results[] = [
22                                         'title' => L10n::t('Source input'),
23                                         'content' => visible_lf($bbcode)
24                                 ];
25
26                                 $plain = Text\BBCode::toPlaintext($bbcode, false);
27                                 $results[] = [
28                                         'title' => L10n::t('BBCode::toPlaintext'),
29                                         'content' => visible_lf($plain)
30                                 ];
31
32                                 $html = Text\BBCode::convert($bbcode);
33                                 $results[] = [
34                                         'title' => L10n::t("BBCode::convert \x28raw HTML\x29"),
35                                         'content' => htmlspecialchars($html)
36                                 ];
37
38                                 $results[] = [
39                                         'title' => L10n::t('BBCode::convert'),
40                                         'content' => $html
41                                 ];
42
43                                 $bbcode2 = Text\HTML::toBBCode($html);
44                                 $results[] = [
45                                         'title' => L10n::t('BBCode::convert => HTML::toBBCode'),
46                                         'content' => visible_lf($bbcode2)
47                                 ];
48
49                                 $markdown = Text\BBCode::toMarkdown($bbcode);
50                                 $results[] = [
51                                         'title' => L10n::t('BBCode::toMarkdown'),
52                                         'content' => visible_lf($markdown)
53                                 ];
54
55                                 $html2 = Text\Markdown::convert($markdown);
56                                 $results[] = [
57                                         'title' => L10n::t('BBCode::toMarkdown => Markdown::convert'),
58                                         'content' => $html2
59                                 ];
60
61                                 $bbcode3 = Text\Markdown::toBBCode($markdown);
62                                 $results[] = [
63                                         'title' => L10n::t('BBCode::toMarkdown => Markdown::toBBCode'),
64                                         'content' => visible_lf($bbcode3)
65                                 ];
66
67                                 $bbcode4 = Text\HTML::toBBCode($html2);
68                                 $results[] = [
69                                         'title' => L10n::t('BBCode::toMarkdown =>  Markdown::convert => HTML::toBBCode'),
70                                         'content' => visible_lf($bbcode4)
71                                 ];
72                                 break;
73                         case 'markdown':
74                                 $markdown = trim($_REQUEST['text']);
75                                 $results[] = [
76                                         'title' => L10n::t('Source input \x28Diaspora format\x29'),
77                                         'content' => '<pre>' . $markdown . '</pre>'
78                                 ];
79
80                                 $bbcode = Text\Markdown::toBBCode($markdown);
81                                 $results[] = [
82                                         'title' => L10n::t('Markdown::toBBCode'),
83                                         'content' => '<pre>' . $bbcode . '</pre>'
84                                 ];
85                                 break;
86                         case 'html' :
87                                 $html = trim($_REQUEST['text']);
88                                 $results[] = [
89                                         'title' => L10n::t("Raw HTML input"),
90                                         'content' => htmlspecialchars($html)
91                                 ];
92
93                                 $results[] = [
94                                         'title' => L10n::t('HTML Input'),
95                                         'content' => $html
96                                 ];
97
98                                 $bbcode = Text\HTML::toBBCode($html);
99                                 $results[] = [
100                                         'title' => L10n::t('HTML::toBBCode'),
101                                         'content' => visible_lf($bbcode)
102                                 ];
103
104                                 $text = Text\HTML::toPlaintext($html);
105                                 $results[] = [
106                                         'title' => L10n::t('HTML::toPlaintext'),
107                                         'content' => '<pre>' . $text . '</pre>'
108                                 ];
109                 }
110         }
111
112         $tpl = get_markup_template('babel.tpl');
113         $o = replace_macros($tpl, [
114                 '$text'          => ['text', L10n::t('Source text'), defaults($_REQUEST, 'text', ''), ''],
115                 '$type_bbcode'   => ['type', L10n::t('BBCode'), 'bbcode', '', defaults($_REQUEST, 'type', 'bbcode') == 'bbcode'],
116                 '$type_markdown' => ['type', L10n::t('Markdown'), 'markdown', '', defaults($_REQUEST, 'type', 'bbcode') == 'markdown'],
117                 '$type_html'     => ['type', L10n::t('HTML'), 'html', '', defaults($_REQUEST, 'type', 'bbcode') == 'html'],
118                 '$results'       => $results
119         ]);
120
121         return $o;
122 }