- // If the link contains BBCode stuff, make a short link out of this to avoid parsing problems
- if (strpos($data["url"], '[') OR strpos($data["url"], ']')) {
- require_once("include/network.php");
- $data["url"] = short_link($data["url"]);
- }
-
- if (($data["type"] != "photo") AND is_string($data["title"]))
- $text .= "[bookmark=".$data["url"]."]".trim($data["title"])."[/bookmark]";
-
- if (($data["type"] != "video") AND ($photo != ""))
- $text .= '[img]'.$photo.'[/img]';
- elseif (($data["type"] != "video") AND (sizeof($data["images"]) > 0)) {
- $imagedata = $data["images"][0];
- $text .= '[img]'.$imagedata["src"].'[/img]';
+ if (sizeof($data["images"]) > 0)
+ $preview = $data["images"][0];
+ else
+ $preview = "";
+
+ // Escape some bad characters
+ $data["url"] = str_replace(array("[", "]"), array("[", "]"), htmlentities($data["url"], ENT_QUOTES, 'UTF-8', false));
+ $data["title"] = str_replace(array("[", "]"), array("[", "]"), htmlentities($data["title"], ENT_QUOTES, 'UTF-8', false));
+
+ $text = "[attachment type='".$data["type"]."'";
+
+ if ($data["url"] != "")
+ $text .= " url='".$data["url"]."'";
+ if ($data["title"] != "")
+ $text .= " title='".$data["title"]."'";
+ if (sizeof($data["images"]) > 0) {
+ $preview = str_replace(array("[", "]"), array("[", "]"), htmlentities($data["images"][0]["src"], ENT_QUOTES, 'UTF-8', false));
+ // if the preview picture is larger than 500 pixels then show it in a larger mode
+ // But only, if the picture isn't higher than large (To prevent huge posts)
+ if (($data["images"][0]["width"] >= 500) AND ($data["images"][0]["width"] >= $data["images"][0]["height"]))
+ $text .= " image='".$preview."'";
+ else
+ $text .= " preview='".$preview."'";