+function add_page_info($url, $no_photos = false, $photo = "") {
+ require_once("mod/parse_url.php");
+
+ $data = parseurl_getsiteinfo($url, true);
+
+ logger('add_page_info: fetch page info for '.$url.' '.print_r($data, true), LOGGER_DEBUG);
+
+ // It maybe is a rich content, but if it does have everything that a link has,
+ // then treat it that way
+ if (($data["type"] == "rich") AND is_string($data["title"]) AND
+ is_string($data["text"]) AND (sizeof($data["images"]) > 0))
+ $data["type"] = "link";
+
+ if ((($data["type"] != "link") AND ($data["type"] != "video") AND ($data["type"] != "photo")) OR ($data["title"] == $url))
+ return("");
+
+ if ($no_photos AND ($data["type"] == "photo"))
+ return("");
+
+ if (($data["type"] != "photo") AND is_string($data["title"]))
+ $text .= "[bookmark=".$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 (($data["type"] != "photo") AND is_string($data["text"]))
+ $text .= "[quote]".$data["text"]."[/quote]";
+
+ return("\n[class=type-".$data["type"]."]".$text."[/class]");
+}
+
+function add_page_info_to_body($body, $texturl = false, $no_photos = false) {
+
+ logger('add_page_info_to_body: fetch page info for body '.$body, LOGGER_DEBUG);
+
+ $URLSearchString = "^\[\]";
+
+ // Adding these spaces is a quick hack due to my problems with regular expressions :)
+ preg_match("/[^!#@]\[url\]([$URLSearchString]*)\[\/url\]/ism", " ".$body, $matches);
+
+ if (!$matches)
+ preg_match("/[^!#@]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", " ".$body, $matches);
+
+ // Convert urls without bbcode elements
+ if (!$matches AND $texturl) {
+ preg_match("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", " ".$body, $matches);
+
+ // Yeah, a hack. I really hate regular expressions :)
+ if ($matches)
+ $matches[1] = $matches[2];
+ }
+
+ if ($matches)
+ $footer = add_page_info($matches[1], $no_photos);
+
+ // Remove the link from the body if the link is attached at the end of the post
+ if (isset($footer) AND (trim($footer) != "") AND (strpos($footer, $matches[1]))) {
+ $removedlink = trim(str_replace($matches[1], "", $body));
+ if (($removedlink == "") OR strstr($body, $removedlink))
+ $body = $removedlink;
+
+ $url = str_replace(array('/', '.'), array('\/', '\.'), $matches[1]);
+ $removedlink = preg_replace("/\[url\=".$url."\](.*?)\[\/url\]/ism", '', $body);
+ if (($removedlink == "") OR strstr($body, $removedlink))
+ $body = $removedlink;
+ }
+
+ // Add the page information to the bottom
+ if (isset($footer) AND (trim($footer) != ""))
+ $body .= $footer;
+
+ return $body;
+}
+