From e18a037fb254cdb462838463e020ae32a6110011 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 14 Sep 2017 05:16:23 +0000 Subject: [PATCH 1/2] API: Improvements for clients with bad HTML support --- include/api.php | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/include/api.php b/include/api.php index e7c320e62d..3c84f46f76 100644 --- a/include/api.php +++ b/include/api.php @@ -2233,7 +2233,7 @@ $called_api = null; //don't send title to regular StatusNET requests to avoid confusing these apps if (x($_GET, 'getText')) { - $ret['title'] = $item['title'] ; + $ret['title'] = $item['title']; if ($_GET['getText'] == 'html') { $ret['text'] = bbcode($item['body'], false, false); } elseif ($_GET['getText'] == 'plain') { @@ -2280,14 +2280,31 @@ $called_api = null; "

", "

", "

", "

", "

", "

", "

", "

", "
", "
", "
", "
"); - $replace = array("
\n", "\n
", "
\n", - "\n

", "

\n", "\n

", "

\n", - "\n

", "

\n", "\n

", "

\n", - "\n
", "
\n", "\n
", "
\n"); +// $replace = array(" \n
", " \n
", "
\n ", +// " \n

", "

\n ", " \n

", "

\n ", +// " \n

", "

\n ", " \n

", "

\n ", +// " \n
", "
\n ", " \n
", "
\n "); + $replace = array("
", "
", "

", + "

", "


", "

", "


", + "

", "


", "

", "


", + "
", "

", "
", "

"); $statushtml = str_replace($search, $replace, $statushtml); if ($item['title'] != "") { - $statushtml = "

" . bbcode($item['title']) . "

\n" . $statushtml; + $statushtml = "

" . bbcode($item['title']) . "


" . $statushtml; + } + + do { + $oldtext = $statushtml; + $statushtml = str_replace("

", "
", $statushtml); + } while ($oldtext != $statushtml); + + if (substr($statushtml, 0, 4) == '
') { + $statushtml = substr($statushtml, 4); + } + + if (substr($statushtml, 0, -4) == '
') { + $statushtml = substr($statushtml, -4); } // feeds without body should contain the link From 4b99d122dd7734c8f1c6aad3b6ab4316f3c5738d Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 14 Sep 2017 05:48:43 +0000 Subject: [PATCH 2/2] Added explanation --- include/api.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/api.php b/include/api.php index 3c84f46f76..45c9ed2554 100644 --- a/include/api.php +++ b/include/api.php @@ -2276,14 +2276,11 @@ $called_api = null; $statushtml = trim(bbcode($body, false, false)); + // Workaround for clients with limited HTML parser functionality $search = array("
", "
", "
", "

", "

", "

", "

", "

", "

", "

", "

", "
", "
", "
", "
"); -// $replace = array(" \n
", " \n
", "
\n ", -// " \n

", "

\n ", " \n

", "

\n ", -// " \n

", "

\n ", " \n

", "

\n ", -// " \n
", "
\n ", " \n
", "
\n "); $replace = array("
", "
", "

", "

", "


", "

", "


", "

", "


", "

", "


",