]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Debug/Babel.php
Merge remote-tracking branch 'upstream/develop' into item-notification
[friendica.git] / src / Module / Debug / Babel.php
index 1ce1ac4c6e92ab5f91db0235244c45c15ca6479a..edd897be87c608d4f2b478cc8ffc49e427a56460 100644 (file)
@@ -14,7 +14,7 @@ use Friendica\Util\XML;
  */
 class Babel extends BaseModule
 {
-       public static function content()
+       public static function content(array $parameters = [])
        {
                function visible_whitespace($s)
                {
@@ -25,7 +25,7 @@ class Babel extends BaseModule
 
                $results = [];
                if (!empty($_REQUEST['text'])) {
-                       switch (defaults($_REQUEST, 'type', 'bbcode')) {
+                       switch (($_REQUEST['type'] ?? '') ?: 'bbcode') {
                                case 'bbcode':
                                        $bbcode = trim($_REQUEST['text']);
                                        $results[] = [
@@ -59,10 +59,14 @@ class Babel extends BaseModule
                                        $markdown = Text\BBCode::toMarkdown($bbcode);
                                        $results[] = [
                                                'title'   => L10n::t('BBCode::toMarkdown'),
-                                               'content' => visible_whitespace($markdown)
+                                               'content' => visible_whitespace(htmlspecialchars($markdown))
                                        ];
 
                                        $html2 = Text\Markdown::convert($markdown);
+                                       $results[] = [
+                                               'title'   => L10n::t('BBCode::toMarkdown => Markdown::convert (raw HTML)'),
+                                               'content' => visible_whitespace(htmlspecialchars($html2))
+                                       ];
                                        $results[] = [
                                                'title'   => L10n::t('BBCode::toMarkdown => Markdown::convert'),
                                                'content' => $html2
@@ -148,26 +152,38 @@ class Babel extends BaseModule
                                                'content' => htmlspecialchars($html2)
                                        ];
 
+                                       $bbcode2plain = Text\BBCode::toPlaintext($bbcode);
+                                       $results[] = [
+                                               'title'   => L10n::t('HTML::toBBCode => BBCode::toPlaintext'),
+                                               'content' => '<pre>' . $bbcode2plain . '</pre>'
+                                       ];
+
                                        $markdown = Text\HTML::toMarkdown($html);
                                        $results[] = [
                                                'title'   => L10n::t('HTML::toMarkdown'),
                                                'content' => visible_whitespace($markdown)
                                        ];
 
-                                       $text = Text\HTML::toPlaintext($html);
+                                       $text = Text\HTML::toPlaintext($html, 0);
                                        $results[] = [
                                                'title'   => L10n::t('HTML::toPlaintext'),
                                                'content' => '<pre>' . $text . '</pre>'
                                        ];
+
+                                       $text = Text\HTML::toPlaintext($html, 0, true);
+                                       $results[] = [
+                                               'title'   => L10n::t('HTML::toPlaintext (compact)'),
+                                               'content' => '<pre>' . $text . '</pre>'
+                                       ];
                        }
                }
 
                $tpl = Renderer::getMarkupTemplate('babel.tpl');
                $o = Renderer::replaceMacros($tpl, [
-                       '$text'          => ['text', L10n::t('Source text'), defaults($_REQUEST, 'text', ''), ''],
-                       '$type_bbcode'   => ['type', L10n::t('BBCode'), 'bbcode', '', defaults($_REQUEST, 'type', 'bbcode') == 'bbcode'],
-                       '$type_markdown' => ['type', L10n::t('Markdown'), 'markdown', '', defaults($_REQUEST, 'type', 'bbcode') == 'markdown'],
-                       '$type_html'     => ['type', L10n::t('HTML'), 'html', '', defaults($_REQUEST, 'type', 'bbcode') == 'html'],
+                       '$text'          => ['text', L10n::t('Source text'), $_REQUEST['text'] ?? '', ''],
+                       '$type_bbcode'   => ['type', L10n::t('BBCode'), 'bbcode', '', (($_REQUEST['type'] ?? '') ?: 'bbcode') == 'bbcode'],
+                       '$type_markdown' => ['type', L10n::t('Markdown'), 'markdown', '', (($_REQUEST['type'] ?? '') ?: 'bbcode') == 'markdown'],
+                       '$type_html'     => ['type', L10n::t('HTML'), 'html', '', (($_REQUEST['type'] ?? '') ?: 'bbcode') == 'html'],
                        '$results'       => $results
                ]);