From f21d04e01e940a932ed3198e771225cfc3a52bb2 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 19 Apr 2021 04:18:43 +0000 Subject: [PATCH] Simplified code --- src/Content/Text/BBCode.php | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 505756aad4..039eda9462 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -170,16 +170,8 @@ class BBCode $data['text'] = trim($match[1]); foreach (['type', 'url', 'title', 'image', 'preview', 'publisher_name', 'publisher_url', 'author_name', 'author_url'] as $field) { - $value = ''; - preg_match("/" . $field . "='(.*?)'/ism", $attributes, $matches); - if (!empty($matches[1])) { - $value = $matches[1]; - } - - preg_match('/' . $field . '="(.*?)"/ism', $attributes, $matches); - if (!empty($matches[1])) { - $value = $matches[1]; - } + preg_match('/' . preg_quote($field, '/') . '=("|\')(.*?)\1/ism', $attributes, $matches); + $value = $matches[2] ?? ''; if ($value != '') { switch ($field) { @@ -334,19 +326,17 @@ class BBCode } } } elseif (preg_match_all("(\[img\](.*?)\[\/img\])ism", $body, $pictures, PREG_SET_ORDER)) { - if ((count($pictures) > 0) && !$has_title) { - $post['type'] = 'photo'; - } elseif (count($pictures) > 0) { + if ($has_title) { $post['type'] = 'link'; $post['url'] = $plink; + } else { + $post['type'] = 'photo'; } - if (count($pictures) > 0) { - $post['image'] = $pictures[0][1]; - $post['text'] = $body; - foreach ($pictures as $picture) { - $post['text'] = trim(str_replace($picture[0], '', $post['text'])); - } + $post['image'] = $pictures[0][1]; + $post['text'] = $body; + foreach ($pictures as $picture) { + $post['text'] = trim(str_replace($picture[0], '', $post['text'])); } } -- 2.39.5