From 16fd618380d2f88524b3545f751690b39be084f5 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 29 Feb 2020 13:08:16 -0800 Subject: rework img alt text - preserve legacy bbcode --- include/bbcode.php | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index bb7b9e2dd..b2e3f1d3b 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -668,15 +668,60 @@ function bb_imgoptions($match) { $alt = false; $style = EMPTY_STR; + + $attributes = $match[3]; + + $x = preg_match("/alt='(.*?)'/ism", $attributes, $matches); + if ($x) { + $alt = $matches[1]; + } + + $x = preg_match("/alt=\"\;(.*?)\"\;/ism", $attributes, $matches); + if ($x) { + $alt = $matches[1]; + } + + $x = preg_match("/width='(.*?)'/ism", $attributes, $matches); + if ($x) { + $width = $matches[1]; + } + + $x = preg_match("/width=\"\;(.*?)\"\;/ism", $attributes, $matches); + if ($x) { + $width = $matches[1]; + } + + $x = preg_match("/height='(.*?)'/ism", $attributes, $matches); + if ($x) { + $height = $matches[1]; + } + + $x = preg_match("/height=\"\;(.*?)\"\;/ism", $attributes, $matches); + if ($x) { + $height = $matches[1]; + } + + $x = preg_match("/style='(.*?)'/ism", $attributes, $matches); + if ($x) { + $style = $matches[1]; + } + + $x = preg_match("/style=\"\;(.*?)\"\;/ism", $attributes, $matches); + if ($x) { + $style = $matches[1]; + } + + // legacy img options if ($match[2] === '=') { - // pull out (optional) size declarations first + // pull out (optional) legacy size declarations first if (preg_match("/([0-9]*)x([0-9]*)/ism",$match[3],$local_match)) { $width = intval($local_match[1]); } $match[3] = substr($match[3],strpos($match[3],' ')); } - // then (optional) float specifiers + + // then (optional) legacy float specifiers if ($n = strpos($match[3],'float=left') !== false) { $float = 'left'; $match[3] = substr($match[3],$n + 10); @@ -685,8 +730,9 @@ function bb_imgoptions($match) { $float = 'right'; $match[3] = substr($match[3],$n + 11); } + // finally alt text which extends to the close of the tag - if ($n = strpos($match[3],'alt=') !== false) { + if ((! $alt) && ($n = strpos($match[3],'alt=') !== false)) { $alt = substr($match[3],$n + 4); } -- cgit v1.2.3