From adb80bad9eba1b3d68fdae3c5fe0053560ad16bf Mon Sep 17 00:00:00 2001 From: flashwave Date: Mon, 8 Jan 2024 13:42:22 +0000 Subject: [PATCH] Added server side image map support. --- src/Parsers/BBCode/Tags/ImageTag.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Parsers/BBCode/Tags/ImageTag.php b/src/Parsers/BBCode/Tags/ImageTag.php index ac60172..af2daba 100644 --- a/src/Parsers/BBCode/Tags/ImageTag.php +++ b/src/Parsers/BBCode/Tags/ImageTag.php @@ -5,8 +5,11 @@ use Misuzu\Parsers\BBCode\BBCodeTag; final class ImageTag extends BBCodeTag { public function parseText(string $text): string { - return preg_replace_callback("/\[img\]((?:https?:)?\/\/.+?)\[\/img\]/", function ($matches) { - $url = parse_url($matches[1]); + return preg_replace_callback("/\[(img|imgmap)\]((?:https?:)?\/\/.+?)\[\/(img|imgmap)\]/", function($matches) { + if($matches[1] !== $matches[3]) + return $matches[0]; + + $url = parse_url($matches[2]); if(!empty($url['scheme']) && !in_array(mb_strtolower($url['scheme']), ['http', 'https'], true)) return $matches[0]; @@ -17,7 +20,11 @@ final class ImageTag extends BBCodeTag { // $matches[1] // ); - return sprintf('%1$s', $matches[1]); + return sprintf( + '%1$s', + $matches[2], + $matches[1] === 'imgmap' ? ' ismap' : '', + ); }, $text); } }