From 09034ce0ee78e2906033b79f7844cd63b9bab18c Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 12 Jul 2012 08:20:27 +0200 Subject: [PATCH] parse_url: Fetch multiple pictures so that the user can decide what to take. --- mod/parse_url.php | 55 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/mod/parse_url.php b/mod/parse_url.php index 09722341cb..97e1658c89 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -1,4 +1,6 @@ query("//img[@src]"); foreach ($list as $node) { $attr = array(); @@ -121,10 +122,33 @@ function parseurl_getsiteinfo($url) { $i = fetch_url($attr["src"]); $ph = new Photo($i, $type); - if(($ph->getWidth() > 200) and ($ph->getHeight() > 200)) - $siteinfo["image"] = $attr["src"]; + if($ph->is_valid() and ($ph->getWidth() > 200) and ($ph->getHeight() > 200)) { + if ($siteinfo["image"] == "") + $siteinfo["image"] = $attr["src"]; + + if($ph->getWidth() > 300 || $ph->getHeight() > 300) { + $ph->scaleImage(300); + $siteinfo["images"][] = array("src"=>$attr["src"], + "width"=>$ph->getWidth(), + "height"=>$ph->getHeight()); + } else + $siteinfo["images"][] = array("src"=>$attr["src"], + "width"=>$ph->getWidth(), + "height"=>$ph->getHeight()); + } } - } + } else { + // guess mimetype from headers or filename + $type = guess_image_type($siteinfo["image"],true); + + $i = fetch_url($siteinfo["image"]); + $ph = new Photo($i, $type); + + if($ph->is_valid()) + $siteinfo["images"][] = array("src"=>$siteinfo["image"], + "width"=>$ph->getWidth(), + "height"=>$ph->getHeight()); + } if ($siteinfo["text"] == "") { $text = ""; @@ -172,8 +196,8 @@ function parse_url_content(&$a) { if(local_user() && intval(get_pconfig(local_user(),'system','plaintext'))) $textmode = true; - if($textmode) - $br = (($textmode) ? "\n" : '
'); if(x($_GET,'binurl')) $url = trim(hex2bin($_GET['binurl'])); @@ -234,12 +258,19 @@ function parse_url_content(&$a) { echo sprintf($template,$url,$url,'') . $str_tags; killme(); } else { - $image = $siteinfo["image"]; $text = $siteinfo["text"]; $title = $siteinfo["title"]; } - if ($image != "") { + $image = ""; + + foreach ($siteinfo["images"] as $imagedata) + if($textmode) + $image .= '[img='.$imagedata["width"].'x'.$imagedata["height"].']'.$imagedata["src"].'[/img]'; + else + $image .= 'photo'; + +/* if ($image != "") { $i = fetch_url($image); if($i) { require_once('include/Photo.php'); @@ -264,17 +295,17 @@ function parse_url_content(&$a) { } } } - } + }*/ if(strlen($text)) { if($textmode) - $text = $br.$br.'[quote]'.trim($text).'[/quote]'.$br ; + $text = $br.'[quote]'.trim($text).'[/quote]'.$br ; else - $text = '

'.trim($text).'

'; + $text = '
'.trim($text).'

'; } if($image) { - $text = $image.$br.$text; + $text = $br.$br.$image.$br.$text; } $title = str_replace(array("\r","\n"),array('',''),$title);