]> git.mxchange.org Git - friendica.git/blob - mod/babel.php
Refactor bbcode() into BBCode::convert()
[friendica.git] / mod / babel.php
1 <?php
2 /**
3  * @file mod/babel.php
4  */
5
6 use Friendica\Content\Text\BBCode;
7 use Friendica\Content\Text\Markdown;
8 use Friendica\Core\L10n;
9
10 require_once 'include/bbcode.php';
11 require_once 'include/bb2diaspora.php';
12 require_once 'include/html2bbcode.php';
13
14 function visible_lf($s)
15 {
16         return str_replace("\n", '<br />', $s);
17 }
18
19 function babel_content()
20 {
21         $o = '<h1>Babel Diagnostic</h1>';
22
23         $o .= '<form action="babel" method="post">';
24         $o .= L10n::t("Source \x28bbcode\x29 text:") . EOL;
25         $o .= '<textarea name="text" cols="80" rows="10">' . htmlspecialchars($_REQUEST['text']) . '</textarea>' . EOL;
26         $o .= '<input type="submit" name="submit" value="Submit" /></form>';
27
28         $o .= '<br /><br />';
29
30         $o .= '<form action="babel" method="post">';
31         $o .= L10n::t("Source \x28Diaspora\x29 text to convert to BBcode:") . EOL;
32         $o .= '<textarea name="d2bbtext" cols="80" rows="10">' . htmlspecialchars($_REQUEST['d2bbtext']) . '</textarea>' . EOL;
33         $o .= '<input type="submit" name="submit" value="Submit" /></form>';
34
35         $o .= '<br /><br />';
36
37         if (x($_REQUEST, 'text')) {
38                 $text = trim($_REQUEST['text']);
39                 $o .= '<h2>' . L10n::t('Source input: ') . '</h2>' . EOL . EOL;
40                 $o .= visible_lf($text) . EOL . EOL;
41
42                 $html = BBCode::convert($text);
43                 $o .= '<h2>' . L10n::t("bbcode \x28raw HTML\x28: ") . '</h2>' . EOL . EOL;
44                 $o .= htmlspecialchars($html) . EOL . EOL;
45
46                 //$html = bbcode($text);
47                 $o .= '<h2>' . L10n::t('bbcode: ') . '</h2>' . EOL . EOL;
48                 $o .= $html . EOL . EOL;
49
50                 $bbcode = html2bbcode($html);
51                 $o .= '<h2>' . L10n::t('bbcode => html2bbcode: ') . '</h2>' . EOL . EOL;
52                 $o .= visible_lf($bbcode) . EOL . EOL;
53
54                 $diaspora = bb2diaspora($text);
55                 $o .= '<h2>' . L10n::t('bb2diaspora: ') . '</h2>' . EOL . EOL;
56                 $o .= visible_lf($diaspora) . EOL . EOL;
57
58                 $html = Markdown::convert($diaspora);
59                 $o .= '<h2>' . L10n::t('bb2diaspora => Markdown: ') . '</h2>' . EOL . EOL;
60                 $o .= $html . EOL . EOL;
61
62                 $bbcode = diaspora2bb($diaspora);
63                 $o .= '<h2>' . L10n::t('bb2diaspora => diaspora2bb: ') . '</h2>' . EOL . EOL;
64                 $o .= visible_lf($bbcode) . EOL . EOL;
65
66                 $bbcode = html2bbcode($html);
67                 $o .= '<h2>' . L10n::t('bbcode => html2bbcode: ') . '</h2>' . EOL . EOL;
68                 $o .= visible_lf($bbcode) . EOL . EOL;
69         }
70
71         if (x($_REQUEST, 'd2bbtext')) {
72                 $d2bbtext = trim($_REQUEST['d2bbtext']);
73                 $o .= '<h2>' . L10n::t("Source input \x28Diaspora format\x29: ") . '</h2>' . EOL . EOL;
74                 $o .= '<pre>' . $d2bbtext . '</pre>' . EOL . EOL;
75
76                 $bb = diaspora2bb($d2bbtext);
77                 $o .= '<h2>' . L10n::t('diaspora2bb: ') . '</h2>' . EOL . EOL;
78                 $o .= '<pre>' . $bb . '</pre>' . EOL . EOL;
79         }
80
81         return $o;
82 }