+ if (!preg_match("/(.*)\[attachment(.*?)\](.*?)\[\/attachment\](.*)/ism", $body, $match))
+ return get_old_attachment_data($body);
+
+ $attributes = $match[2];
+
+ $data["text"] = trim($match[1]);
+
+ $type = "";
+ preg_match("/type='(.*?)'/ism", $attributes, $matches);
+ if ($matches[1] != "")
+ $type = strtolower($matches[1]);
+
+ preg_match('/type="(.*?)"/ism', $attributes, $matches);
+ if ($matches[1] != "")
+ $type = strtolower($matches[1]);
+
+ if ($type == "")
+ return(array());
+
+ if (!in_array($type, array("link", "audio", "photo", "video")))
+ return(array());
+
+ if ($type != "")
+ $data["type"] = $type;
+
+ $url = "";
+ preg_match("/url='(.*?)'/ism", $attributes, $matches);
+ if ($matches[1] != "")
+ $url = $matches[1];
+
+ preg_match('/url="(.*?)"/ism', $attributes, $matches);
+ if ($matches[1] != "")
+ $url = $matches[1];
+
+ if ($url != "")
+ $data["url"] = html_entity_decode($url, ENT_QUOTES, 'UTF-8');
+
+ $title = "";
+ preg_match("/title='(.*?)'/ism", $attributes, $matches);
+ if ($matches[1] != "")
+ $title = $matches[1];
+
+ preg_match('/title="(.*?)"/ism', $attributes, $matches);
+ if ($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);
+ $data["title"] = $title;
+ }
+
+ $image = "";
+ 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"] = html_entity_decode($image, ENT_QUOTES, 'UTF-8');
+
+ $preview = "";
+ 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 ($preview != "")
+ $data["preview"] = html_entity_decode($preview, ENT_QUOTES, 'UTF-8');
+
+ $data["description"] = trim($match[3]);
+
+ $data["after"] = trim($match[4]);
+
+ return($data);
+}
+
+function get_attached_data($body) {
+/*
+ - text:
+ - type: link, video, photo
+ - title:
+ - url:
+ - image:
+ - description:
+ - (thumbnail)
+*/
+
+ $post = get_attachment_data($body);