Simplified code

This commit is contained in:
Michael 2021-04-19 04:18:43 +00:00
parent 02700194c1
commit f21d04e01e

View file

@ -170,16 +170,8 @@ class BBCode
$data['text'] = trim($match[1]); $data['text'] = trim($match[1]);
foreach (['type', 'url', 'title', 'image', 'preview', 'publisher_name', 'publisher_url', 'author_name', 'author_url'] as $field) { foreach (['type', 'url', 'title', 'image', 'preview', 'publisher_name', 'publisher_url', 'author_name', 'author_url'] as $field) {
$value = ''; preg_match('/' . preg_quote($field, '/') . '=("|\')(.*?)\1/ism', $attributes, $matches);
preg_match("/" . $field . "='(.*?)'/ism", $attributes, $matches); $value = $matches[2] ?? '';
if (!empty($matches[1])) {
$value = $matches[1];
}
preg_match('/' . $field . '="(.*?)"/ism', $attributes, $matches);
if (!empty($matches[1])) {
$value = $matches[1];
}
if ($value != '') { if ($value != '') {
switch ($field) { switch ($field) {
@ -334,21 +326,19 @@ class BBCode
} }
} }
} elseif (preg_match_all("(\[img\](.*?)\[\/img\])ism", $body, $pictures, PREG_SET_ORDER)) { } elseif (preg_match_all("(\[img\](.*?)\[\/img\])ism", $body, $pictures, PREG_SET_ORDER)) {
if ((count($pictures) > 0) && !$has_title) { if ($has_title) {
$post['type'] = 'photo';
} elseif (count($pictures) > 0) {
$post['type'] = 'link'; $post['type'] = 'link';
$post['url'] = $plink; $post['url'] = $plink;
} else {
$post['type'] = 'photo';
} }
if (count($pictures) > 0) {
$post['image'] = $pictures[0][1]; $post['image'] = $pictures[0][1];
$post['text'] = $body; $post['text'] = $body;
foreach ($pictures as $picture) { foreach ($pictures as $picture) {
$post['text'] = trim(str_replace($picture[0], '', $post['text'])); $post['text'] = trim(str_replace($picture[0], '', $post['text']));
} }
} }
}
// Test for the external links // Test for the external links
preg_match_all("(\[url\](.*?)\[\/url\])ism", $post['text'], $links1, PREG_SET_ORDER); preg_match_all("(\[url\](.*?)\[\/url\])ism", $post['text'], $links1, PREG_SET_ORDER);