+ if ((@$siteinfo["text"] == "") AND (@$siteinfo["title"] != "") AND !$no_guessing) {
+ $text = "";
+
+ $list = $xpath->query("//div[@class='article']");
+ foreach ($list as $node)
+ if (strlen($node->nodeValue) > 40)
+ $text .= " ".trim($node->nodeValue);
+
+ if ($text == "") {
+ $list = $xpath->query("//div[@class='content']");
+ foreach ($list as $node)
+ if (strlen($node->nodeValue) > 40)
+ $text .= " ".trim($node->nodeValue);
+ }
+
+ // If none text was found then take the paragraph content
+ if ($text == "") {
+ $list = $xpath->query("//p");
+ foreach ($list as $node)
+ if (strlen($node->nodeValue) > 40)
+ $text .= " ".trim($node->nodeValue);
+ }
+
+ if ($text != "") {
+ $text = trim(str_replace(array("\n", "\r"), array(" ", " "), $text));
+
+ while (strpos($text, " "))
+ $text = trim(str_replace(" ", " ", $text));
+
+ $siteinfo["text"] = trim(html_entity_decode(substr($text,0,350), ENT_QUOTES, "UTF-8").'...');
+ }
+ }
+
+ logger("parseurl_getsiteinfo: Siteinfo for ".$url." ".print_r($siteinfo, true), LOGGER_DEBUG);
+
+ call_hooks('getsiteinfo', $siteinfo);
+
+ return($siteinfo);
+}
+
+function arr_add_hashes(&$item,$k) {
+ $item = '#' . $item;
+}
+
+function parse_url_content(&$a) {
+
+ $text = null;
+ $str_tags = '';
+
+ $textmode = false;
+
+ if(local_user() && (! feature_enabled(local_user(),'richtext')))
+ $textmode = true;
+
+ //if($textmode)
+ $br = (($textmode) ? "\n" : '<br />');
+
+ if(x($_GET,'binurl'))
+ $url = trim(hex2bin($_GET['binurl']));
+ else
+ $url = trim($_GET['url']);
+
+ if($_GET['title'])
+ $title = strip_tags(trim($_GET['title']));
+
+ if($_GET['description'])
+ $text = strip_tags(trim($_GET['description']));
+
+ if($_GET['tags']) {
+ $arr_tags = str_getcsv($_GET['tags']);
+ if(count($arr_tags)) {
+ array_walk($arr_tags,'arr_add_hashes');
+ $str_tags = $br . implode(' ',$arr_tags) . $br;
+ }
+ }
+
+ // add url scheme if missing
+ $arrurl = parse_url($url);
+ if (!x($arrurl, 'scheme')) {
+ if (x($arrurl, 'host'))
+ $url = "http:".$url;
+ else
+ $url = "http://".$url;
+ }
+
+ logger('parse_url: ' . $url);
+
+ if($textmode)
+ $template = '[bookmark=%s]%s[/bookmark]%s';
+ else
+ $template = "<a class=\"bookmark\" href=\"%s\" >%s</a>%s";
+
+ $arr = array('url' => $url, 'text' => '');
+
+ call_hooks('parse_link', $arr);
+
+ if(strlen($arr['text'])) {
+ echo $arr['text'];
+ killme();
+ }
+
+
+ if($url && $title && $text) {
+
+ $title = str_replace(array("\r","\n"),array('',''),$title);
+
+ if($textmode)
+ $text = '[quote]' . trim($text) . '[/quote]' . $br;
+ else {
+ $text = '<blockquote>' . htmlspecialchars(trim($text)) . '</blockquote><br />';
+ $title = htmlspecialchars($title);
+ }
+
+ $result = sprintf($template,$url,($title) ? $title : $url,$text) . $str_tags;
+
+ logger('parse_url (unparsed): returns: ' . $result);
+
+ echo $result;
+ killme();
+ }
+
+ $siteinfo = parseurl_getsiteinfo($url);
+
+// if ($textmode) {
+// require_once("include/items.php");
+//
+// echo add_page_info_data($siteinfo);
+// killme();
+// }
+
+ $url= $siteinfo["url"];
+
+ // If the link contains BBCode stuff, make a short link out of this to avoid parsing problems
+ if (strpos($url, '[') OR strpos($url, ']')) {
+ require_once("include/network.php");
+ $url = short_link($url);
+ }
+
+ $sitedata = "";
+
+ if($siteinfo["title"] != "") {
+ $text = $siteinfo["text"];
+ $title = $siteinfo["title"];
+ }
+
+ $image = "";
+
+ if (($siteinfo["type"] != "video") AND (sizeof($siteinfo["images"]) > 0)){
+ /* Execute below code only if image is present in siteinfo */
+
+ $total_images = 0;
+ $max_images = get_config('system','max_bookmark_images');
+ if($max_images === false)
+ $max_images = 2;
+ else
+ $max_images = intval($max_images);
+
+ foreach ($siteinfo["images"] as $imagedata) {
+ if($textmode)
+ $image .= '[img='.$imagedata["width"].'x'.$imagedata["height"].']'.$imagedata["src"].'[/img]' . "\n";
+ else
+ $image .= '<img height="'.$imagedata["height"].'" width="'.$imagedata["width"].'" src="'.$imagedata["src"].'" alt="photo" /><br />';
+ $total_images ++;
+ if($max_images && $max_images >= $total_images)