X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fplaintext.php;h=a5031e7d81ce2ae0f7ede3e947af1f3effad4677;hb=391c5913227c7f62f19b4f08906b0b1b0b618b33;hp=86acad6cfe730209cce2c3070ac4bb02c526ac69;hpb=390d5706f46ce58cbed24b292d5c1f1b9789a8a8;p=friendica.git diff --git a/include/plaintext.php b/include/plaintext.php index 86acad6cfe..a5031e7d81 100644 --- a/include/plaintext.php +++ b/include/plaintext.php @@ -26,14 +26,14 @@ require_once "include/network.php"; */ function get_old_attachment_data($body) { - $post = array(); + $post = []; // Simplify image codes $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body); if (preg_match_all("(\[class=(.*?)\](.*?)\[\/class\])ism",$body, $attached, PREG_SET_ORDER)) { foreach ($attached AS $data) { - if (!in_array($data[1], array("type-link", "type-video", "type-photo"))) + if (!in_array($data[1], ["type-link", "type-video", "type-photo"])) continue; $post["type"] = substr($data[1], 5); @@ -63,7 +63,7 @@ function get_old_attachment_data($body) { $post["url"] = $matches[1]; $post["title"] = $matches[2]; } - if (($post["url"] == "") && (in_array($post["type"], array("link", "video"))) + if (($post["url"] == "") && (in_array($post["type"], ["link", "video"])) && preg_match("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", $attacheddata, $matches)) { $post["url"] = $matches[1]; } @@ -90,12 +90,13 @@ function get_old_attachment_data($body) { * 'title' -> Title of the attachment * 'description' -> Description of the attachment */ -function get_attachment_data($body) { - - $data = array(); +function get_attachment_data($body) +{ + $data = []; - if (!preg_match("/(.*)\[attachment(.*?)\](.*?)\[\/attachment\](.*)/ism", $body, $match)) + if (!preg_match("/(.*)\[attachment(.*?)\](.*?)\[\/attachment\](.*)/ism", $body, $match)) { return get_old_attachment_data($body); + } $attributes = $match[2]; @@ -103,82 +104,98 @@ function get_attachment_data($body) { $type = ""; preg_match("/type='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") + if (x($matches, 1)) { $type = strtolower($matches[1]); + } preg_match('/type="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") + if (x($matches, 1)) { $type = strtolower($matches[1]); + } - if ($type == "") - return(array()); + if ($type == "") { + return []; + } - if (!in_array($type, array("link", "audio", "photo", "video"))) - return(array()); + if (!in_array($type, ["link", "audio", "photo", "video"])) { + return []; + } - if ($type != "") + if ($type != "") { $data["type"] = $type; + } $url = ""; preg_match("/url='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") + if (x($matches, 1)) { $url = $matches[1]; + } preg_match('/url="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") + if (x($matches, 1)) { $url = $matches[1]; + } - if ($url != "") + if ($url != "") { $data["url"] = html_entity_decode($url, ENT_QUOTES, 'UTF-8'); + } $title = ""; preg_match("/title='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") + if (x($matches, 1)) { $title = $matches[1]; + } preg_match('/title="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") + if (x($matches, 1)) { $title = $matches[1]; + } if ($title != "") { $title = bbcode(html_entity_decode($title, ENT_QUOTES, 'UTF-8'), false, false, true); $title = html_entity_decode($title, ENT_QUOTES, 'UTF-8'); - $title = str_replace(array("[", "]"), array("[", "]"), $title); + $title = str_replace(["[", "]"], ["[", "]"], $title); $data["title"] = $title; } $image = ""; preg_match("/image='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") + if (x($matches, 1)) { $image = $matches[1]; + } preg_match('/image="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") + if (x($matches, 1)) { $image = $matches[1]; + } - if ($image != "") + if ($image != "") { $data["image"] = html_entity_decode($image, ENT_QUOTES, 'UTF-8'); + } $preview = ""; preg_match("/preview='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") + if (x($matches, 1)) { $preview = $matches[1]; + } preg_match('/preview="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") + if (x($matches, 1)) { $preview = $matches[1]; + } - if ($preview != "") + if ($preview != "") { $data["preview"] = html_entity_decode($preview, ENT_QUOTES, 'UTF-8'); + } $data["description"] = trim($match[3]); $data["after"] = trim($match[4]); - return($data); + return $data; } -function get_attached_data($body, $item = array()) { +function get_attached_data($body, $item = []) { /* - text: - type: link, video, photo