X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fparse_url.php;h=400c248e05d5fd5961f80842449c315caf545f74;hb=5f1ef732e05c79584e6ea1cdb14360a7dd388a9d;hp=4d894969aadbde21c152ac87895da09aba6915d9;hpb=02a1fc9cd08fba2168895d1892a91d8143323848;p=friendica.git diff --git a/mod/parse_url.php b/mod/parse_url.php index 4d894969aa..400c248e05 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -1,4 +1,18 @@ + + + + +

Shiny Trinket

+ +

Shiny trinkets are shiny.

+ +*/ + if(!function_exists('deletenode')) { function deletenode(&$doc, $node) { @@ -22,6 +36,9 @@ function completeurl($url, $scheme) { if ($schemearr["port"] != "") $complete .= ":".$schemearr["port"]; + if(strpos($urlarr['path'],'/') !== 0) + $complete .= '/'; + $complete .= $urlarr["path"]; if ($urlarr["query"] != "") @@ -135,23 +152,23 @@ function parseurl_getsiteinfo($url) { } if ($siteinfo["image"] == "") { - $list = $xpath->query("//img[@src]"); - foreach ($list as $node) { - $attr = array(); - if ($node->attributes->length) - foreach ($node->attributes as $attribute) - $attr[$attribute->name] = $attribute->value; + $list = $xpath->query("//img[@src]"); + foreach ($list as $node) { + $attr = array(); + if ($node->attributes->length) + foreach ($node->attributes as $attribute) + $attr[$attribute->name] = $attribute->value; $src = completeurl($attr["src"], $url); - $photodata = getimagesize($src); + $photodata = @getimagesize($src); - if (($photodata[0] > 150) and ($photodata[1] > 150)) { + if (($photodata) && ($photodata[0] > 150) and ($photodata[1] > 150)) { if ($photodata[0] > 300) { - $photodata[1] = $photodata[1] * (300 / $photodata[0]); + $photodata[1] = round($photodata[1] * (300 / $photodata[0])); $photodata[0] = 300; } if ($photodata[1] > 300) { - $photodata[0] = $photodata[0] * (300 / $photodata[1]); + $photodata[0] = round($photodata[0] * (300 / $photodata[1])); $photodata[1] = 300; } $siteinfo["images"][] = array("src"=>$src, @@ -159,12 +176,15 @@ function parseurl_getsiteinfo($url) { "height"=>$photodata[1]); } - } - } else { + } + } else { $src = completeurl($siteinfo["image"], $url); - $photodata = getimagesize($src); - if (($photodata[0] > 10) and ($photodata[1] > 10)) + unset($siteinfo["image"]); + + $photodata = @getimagesize($src); + + if (($photodata) && ($photodata[0] > 10) and ($photodata[1] > 10)) $siteinfo["images"][] = array("src"=>$src, "width"=>$photodata[0], "height"=>$photodata[1]); @@ -219,6 +239,9 @@ function parse_url_content(&$a) { if(local_user() && intval(get_pconfig(local_user(),'system','plaintext'))) $textmode = true; + if(local_user() && (! feature_enabled(local_user(),'richtext'))) + $textmode = true; + //if($textmode) $br = (($textmode) ? "\n" : '
'); @@ -278,8 +301,7 @@ function parse_url_content(&$a) { $siteinfo = parseurl_getsiteinfo($url); if($siteinfo["title"] == "") { - echo print_r($siteinfo, true); - //echo sprintf($template,$url,$url,'') . $str_tags; + echo sprintf($template,$url,$url,'') . $str_tags; killme(); } else { $text = $siteinfo["text"]; @@ -288,38 +310,26 @@ function parse_url_content(&$a) { $image = ""; - foreach ($siteinfo["images"] as $imagedata) - if($textmode) - $image .= '[img='.$imagedata["width"].'x'.$imagedata["height"].']'.$imagedata["src"].'[/img]'; + if(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 - $image .= 'photo'; - -/* if ($image != "") { - $i = fetch_url($image); - if($i) { - require_once('include/Photo.php'); - // guess mimetype from headers or filename - $type = guess_image_type($image,true); - - $ph = new Photo($i, $type); - if($ph->is_valid()) { - if($ph->getWidth() > 300 || $ph->getHeight() > 300) { - $ph->scaleImage(300); - $new_width = $ph->getWidth(); - $new_height = $ph->getHeight(); - if($textmode) - $image = $br . $br . '[img=' . $new_width . 'x' . $new_height . ']' . $image . '[/img]'; - else - $image = '

photo'; - } else { - if($textmode) - $image = $br.$br.'[img]'.$image.'[/img]'; - else - $image = '

photo'; - } - } - } - }*/ + $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 .= 'photo
'; + $total_images ++; + if($max_images && $max_images >= $total_images) + break; + } + } if(strlen($text)) { if($textmode)