<?php
+
+require_once("include/Photo.php");
+
+/**
+ * @brief Fetches attachment data that were generated the old way
+ *
+ * @param string $body Message body
+ * @return array
+ * 'type' -> Message type ("link", "video", "photo")
+ * '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
+ * 'description' -> Description of the attachment
+ */
function get_old_attachment_data($body) {
$post = array();
$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];
return $post;
}
+/**
+ * @brief Fetches attachment data that were generated with the "attachment" element
+ *
+ * @param string $body Message body
+ * @return array
+ * 'type' -> Message type ("link", "video", "photo")
+ * '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
+ * 'description' -> Description of the attachment
+ */
function get_attachment_data($body) {
$data = array();
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 != "")
if ($matches[1] != "")
$url = $matches[1];
+ $url = html_entity_decode($url, ENT_QUOTES, 'UTF-8');
+
if ($url != "")
$data["url"] = $url;
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 = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
$title = str_replace(array("[", "]"), array("[", "]"), $title);
-
if ($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;
$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];
+
+ preg_match('/preview="(.*?)"/ism', $attributes, $matches);
+ if ($matches[1] != "")
+ $preview = $matches[1];
- if (($image == "") AND ($preview != ""))
- $data["image"] = $preview;
- else
+ if ($preview != "")
$data["preview"] = $preview;
$data["description"] = trim($match[3]);
}
}
- $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'));