X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FContent%2FText%2FBBCode.php;h=a38d2de7856ec39f7c24c38c36d7a5af6c92eee2;hb=a8402109b183e81dad4e5443883dd292df094b86;hp=33f91b43d11ed2b3fd31400eca4fcb19e27c9ae3;hpb=699be97ea124b0ae974c148ebf5497450a3bca74;p=friendica.git diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 33f91b43d1..a38d2de785 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -36,14 +36,10 @@ use Friendica\Core\Renderer; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Event; -use Friendica\Model\Photo; use Friendica\Model\Post; use Friendica\Model\Tag; use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientOptions; -use Friendica\Object\Image; -use Friendica\Protocol\Activity; -use Friendica\Util\Images; use Friendica\Util\Map; use Friendica\Util\ParseUrl; use Friendica\Util\Proxy; @@ -1316,7 +1312,8 @@ class BBCode "\n[tr]", "[tr]\n", " [tr]", "[tr] ", "\n[/tr]", "[/tr]\n", " [/tr]", "[/tr] ", "\n[hr]", "[hr]\n", " [hr]", "[hr] ", "\n[attachment ", " [attachment ", "\n[/attachment]", "[/attachment]\n", " [/attachment]", "[/attachment] ", - "[table]\n", "[table] ", " [table]", "\n[/table]", " [/table]", "[/table] " + "[table]\n", "[table] ", " [table]", "\n[/table]", " [/table]", "[/table] ", + " \n", "\t\n", "[/li]\n", "\n[li]", "\n[*]", ]; $replace = [ "[th]", "[th]", "[th]", "[/th]", "[/th]", "[/th]", @@ -1324,7 +1321,8 @@ class BBCode "[tr]", "[tr]", "[tr]", "[tr]", "[/tr]", "[/tr]", "[/tr]", "[/tr]", "[hr]", "[hr]", "[hr]", "[hr]", "[attachment ", "[attachment ", "[/attachment]", "[/attachment]", "[/attachment]", "[/attachment]", - "[table]", "[table]", "[table]", "[/table]", "[/table]", "[/table]" + "[table]", "[table]", "[table]", "[/table]", "[/table]", "[/table]", + "\n", "\n", "[/li]", "[li]", "[*]", ]; do { $oldtext = $text; @@ -1342,11 +1340,11 @@ class BBCode // removing multiplicated newlines if (DI::config()->get('system', 'remove_multiplicated_lines')) { $search = [ - "\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]", "[/li]\n", "\n[li]", "\n[*]", "\n[ul]", "[/ul]\n", "\n\n[share ", "[/attachment]\n", + "\n\n\n", "[/quote]\n\n", "\n[/quote]", "\n[ul]", "[/ul]\n", "\n[ol]", "[/ol]\n", "\n\n[share ", "[/attachment]\n", "\n[h1]", "[/h1]\n", "\n[h2]", "[/h2]\n", "\n[h3]", "[/h3]\n", "\n[h4]", "[/h4]\n", "\n[h5]", "[/h5]\n", "\n[h6]", "[/h6]\n" ]; $replace = [ - "\n\n", "\n", "\n", "[/quote]\n", "[/quote]", "[/li]", "[li]", "[*]", "[ul]", "[/ul]", "\n[share ", "[/attachment]", + "\n\n", "[/quote]\n", "[/quote]", "[ul]", "[/ul]", "[ol]", "[/ol]", "\n[share ", "[/attachment]", "[h1]", "[/h1]", "[h2]", "[/h2]", "[h3]", "[/h3]", "[h4]", "[/h4]", "[h5]", "[/h5]", "[h6]", "[/h6]" ]; do { @@ -1402,12 +1400,12 @@ class BBCode } // Check for headers - $text = preg_replace("(\[h1\](.*?)\[\/h1\])ism", '

$1

', $text); - $text = preg_replace("(\[h2\](.*?)\[\/h2\])ism", '

$1

', $text); - $text = preg_replace("(\[h3\](.*?)\[\/h3\])ism", '

$1

', $text); - $text = preg_replace("(\[h4\](.*?)\[\/h4\])ism", '

$1

', $text); - $text = preg_replace("(\[h5\](.*?)\[\/h5\])ism", '
$1
', $text); - $text = preg_replace("(\[h6\](.*?)\[\/h6\])ism", '
$1
', $text); + $text = preg_replace("(\[h1\](.*?)\[\/h1\])ism", '

$1

', $text); + $text = preg_replace("(\[h2\](.*?)\[\/h2\])ism", '

$1

', $text); + $text = preg_replace("(\[h3\](.*?)\[\/h3\])ism", '

$1

', $text); + $text = preg_replace("(\[h4\](.*?)\[\/h4\])ism", '

$1

', $text); + $text = preg_replace("(\[h5\](.*?)\[\/h5\])ism", '

$1

', $text); + $text = preg_replace("(\[h6\](.*?)\[\/h6\])ism", '

$1

', $text); // Check for paragraph $text = preg_replace("(\[p\](.*?)\[\/p\])ism", '

$1

', $text); @@ -1460,6 +1458,7 @@ class BBCode // @deprecated since 2021.12, left for backward-compatibility reasons $text = preg_replace("(\[class=(.*?)\](.*?)\[\/class\])ism", '$2', $text); // Add HTML new lines + $text = str_replace("\n\n", '

', $text); $text = str_replace("\n", '
', $text); // handle nested lists @@ -1469,27 +1468,27 @@ class BBCode ((strpos($text, "[/ol]") !== false) && (strpos($text, "[ol]") !== false)) || ((strpos($text, "[/ul]") !== false) && (strpos($text, "[ul]") !== false)) || ((strpos($text, "[/li]") !== false) && (strpos($text, "[li]") !== false))) && (++$endlessloop < 20)) { - $text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '

', $text); - $text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '', $text); - $text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '', $text); - $text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism", '', $text); - $text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '', $text); - $text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '', $text); - $text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '', $text); - $text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '', $text); - $text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '', $text); + $text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '

', $text); + $text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '

', $text); + $text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '

', $text); + $text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism", '

', $text); + $text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '

', $text); + $text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '

', $text); + $text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '

', $text); + $text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '

', $text); + $text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '

    $1

', $text); $text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '

  • $1
  • ', $text); } $text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '$1', $text); $text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '$1', $text); $text = preg_replace("/\[tr\](.*?)\[\/tr\]/sm", '$1', $text); - $text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '$1
    ', $text); + $text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '

    $1

    ', $text); - $text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '$1
    ', $text); - $text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '$1
    ', $text); + $text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '

    $1

    ', $text); + $text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '

    $1

    ', $text); - $text = str_replace('[hr]', '


    ', $text); + $text = str_replace('[hr]', '


    ', $text); if (!$for_plaintext) { $text = self::performWithEscapedTags($text, ['url', 'img', 'audio', 'video', 'youtube', 'vimeo', 'share', 'attachment', 'iframe', 'bookmark'], function ($text) { @@ -1523,7 +1522,7 @@ class BBCode } // Declare the format for [quote] layout - $QuoteLayout = '

    $1
    '; + $QuoteLayout = '

    $1

    '; // Check for [quote] text // handle nested quotes @@ -1565,11 +1564,16 @@ class BBCode $text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '', $text); $text = preg_replace_callback( - "/\[img\=(.*?)\](.*?)\[\/img\]/ism", + "/\[[iz]mg\=(.*?)\](.*?)\[\/[iz]mg\]/ism", function ($matches) use ($simple_html, $uriid) { $matches[1] = self::proxyUrl($matches[1], $simple_html, $uriid); - $matches[2] = htmlspecialchars($matches[2], ENT_COMPAT); - return '' . $matches[2] . ''; + $alt = htmlspecialchars($matches[2], ENT_COMPAT); + // Fix for Markdown problems with Diaspora, see issue #12701 + if (($simple_html != self::DIASPORA) || strpos($matches[2], '"') === false) { + return '' . $alt . ''; + } else { + return '' . $alt . ''; + } }, $text ); @@ -1577,7 +1581,7 @@ class BBCode // Images // [img]pathtoimage[/img] $text = preg_replace_callback( - "/\[img\](.*?)\[\/img\]/ism", + "/\[[iz]mg\](.*?)\[\/[iz]mg\]/ism", function ($matches) use ($simple_html, $uriid) { if (strpos($matches[1], "data:image/") === 0) { return $matches[0]; @@ -1938,6 +1942,10 @@ class BBCode : [] ); + if (strpos($text, '

    ') !== false || strpos($text, '

    ') !== false) { + $text = '

    ' . $text . '

    '; + } + $text = HTML::purify($text, $allowedIframeDomains); DI::profiler()->stopRecording();