+ DI::profiler()->stopRecording();
+ return $return;
+ }
+
+ /**
+ * Convert complex IMG and ZMG elements
+ *
+ * @param [type] $text
+ * @param integer $simplehtml
+ * @param integer $uriid
+ * @return string
+ */
+ private static function convertImages(string $text, int $simplehtml, int $uriid = 0):string
+ {
+ DI::profiler()->startRecording('rendering');
+ $return = preg_replace_callback(
+ "/\[[zi]mg(.*?)\]([^\[\]]*)\[\/[zi]mg\]/ism",
+ function ($match) use ($simplehtml, $uriid) {
+ $attribute_string = $match[1];
+ $attributes = [];
+ foreach (['alt', 'width', 'height'] as $field) {
+ preg_match("/$field=(['\"])(.+?)\\1/ism", $attribute_string, $matches);
+ $attributes[$field] = html_entity_decode($matches[2] ?? '', ENT_QUOTES, 'UTF-8');
+ }
+
+ $img_str = '<img src="' .
+ self::proxyUrl($match[2], $simplehtml, $uriid) . '"';
+ foreach ($attributes as $key => $value) {
+ if (!empty($value)) {
+ $img_str .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT) . '"';
+ }
+ }
+ return $img_str . '>';
+ },
+ $text
+ );
+
+ DI::profiler()->stopRecording();