X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fplaintext.php;h=793f9935a74ba061ce1b5b5ba4c8af7e90838dbf;hb=8a11a60932115725d65791d99a817aefbde174b7;hp=c6e02a5b24f3e21352752ba033d7fa5e62d93dc2;hpb=502b660ca91a0eaab05f9a881d21c8fec0ed0bb3;p=friendica.git diff --git a/include/plaintext.php b/include/plaintext.php index c6e02a5b24..793f9935a7 100644 --- a/include/plaintext.php +++ b/include/plaintext.php @@ -1,11 +1,15 @@ Message type ("link", "video", "photo") - * 'text' -> Text outside of the shared message + * 'text' -> Text before the shared message + * 'after' -> Text after the shared message * 'image' -> Preview image of the message * 'url' -> Url to the attached message * 'title' -> Title of the attachment @@ -25,14 +29,26 @@ function get_old_attachment_data($body) { $post["type"] = substr($data[1], 5); - $post["text"] = trim(str_replace($data[0], "", $body)); + $pos = strpos($body, $data[0]); + if ($pos > 0) { + $post["text"] = trim(substr($body, 0, $pos)); + $post["after"] = trim(substr($body, $pos + strlen($data[0]))); + } else + $post["text"] = trim(str_replace($data[0], "", $body)); $attacheddata = $data[2]; $URLSearchString = "^\[\]"; - if (preg_match("/\[img\]([$URLSearchString]*)\[\/img\]/ism", $attacheddata, $matches)) - $post["image"] = $matches[1]; + if (preg_match("/\[img\]([$URLSearchString]*)\[\/img\]/ism", $attacheddata, $matches)) { + + $picturedata = get_photo_info($matches[1]); + + if (($picturedata[0] >= 500) AND ($picturedata[0] >= $picturedata[1])) + $post["image"] = $matches[1]; + else + $post["preview"] = $matches[1]; + } if (preg_match("/\[bookmark\=([$URLSearchString]*)\](.*?)\[\/bookmark\]/ism", $attacheddata, $matches)) { $post["url"] = $matches[1]; @@ -85,7 +101,7 @@ function get_attachment_data($body) { if ($type == "") return(array()); - if (!in_array($type, array("link", "audio", "video"))) + if (!in_array($type, array("link", "audio", "photo", "video"))) return(array()); if ($type != "") @@ -101,7 +117,7 @@ function get_attachment_data($body) { $url = $matches[1]; if ($url != "") - $data["url"] = $url; + $data["url"] = html_entity_decode($url, ENT_QUOTES, 'UTF-8'); $title = ""; preg_match("/title='(.*?)'/ism", $attributes, $matches); @@ -112,42 +128,36 @@ function get_attachment_data($body) { if ($matches[1] != "") $title = $matches[1]; - //$title = htmlentities($title, ENT_QUOTES, 'UTF-8', false); - $title = bbcode(html_entity_decode($title, ENT_QUOTES, 'UTF-8'), false, false, true); - $title = str_replace(array("[", "]"), array("[", "]"), $title); - - if ($title != "") + 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); $data["title"] = $title; + } $image = ""; - if ($type != "video") { - preg_match("/image='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $image = $matches[1]; - - preg_match('/image="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $image = $matches[1]; - } + preg_match("/image='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $image = $matches[1]; + + preg_match('/image="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $image = $matches[1]; if ($image != "") - $data["image"] = $image; + $data["image"] = html_entity_decode($image, ENT_QUOTES, 'UTF-8'); $preview = ""; - if ($type != "video") { - preg_match("/preview='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $preview = $matches[1]; - - preg_match('/preview="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $preview = $matches[1]; - } + preg_match("/preview='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $preview = $matches[1]; - if (($image == "") AND ($preview != "")) - $data["image"] = $preview; - else - $data["preview"] = $preview; + preg_match('/preview="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $preview = $matches[1]; + + if ($preview != "") + $data["preview"] = html_entity_decode($preview, ENT_QUOTES, 'UTF-8'); $data["description"] = trim($match[3]); @@ -179,6 +189,13 @@ function get_attached_data($body) { if (count($pictures) == 1) { // Checking, if the link goes to a picture $data = parseurl_getsiteinfo_cached($pictures[0][1], true); + + // Workaround: + // Sometimes photo posts to the own album are not detected at the start. + // So we seem to cannot use the cache for these cases. That's strange. + if (($data["type"] != "photo") AND strstr($pictures[0][1], "/photos/")) + $data = parseurl_getsiteinfo($pictures[0][1], true); + if ($data["type"] == "photo") { $post["type"] = "photo"; if (isset($data["images"][0])) { @@ -333,7 +350,7 @@ function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2, $t } } - $html = bbcode($post["text"], false, false, $htmlmode); + $html = bbcode($post["text"].$post["after"], false, false, $htmlmode); $msg = html2plain($html, 0, true); $msg = trim(html_entity_decode($msg,ENT_QUOTES,'UTF-8'));