1
0
Fork 0

parse_url: Fetch multiple pictures so that the user can decide what to take.

This commit is contained in:
Michael Vogel 2012-07-12 08:20:27 +02:00
parent 48f67ead9b
commit 09034ce0ee

View file

@ -1,4 +1,6 @@
<?php <?php
require_once('include/Photo.php');
if(!function_exists('deletenode')) { if(!function_exists('deletenode')) {
function deletenode(&$doc, $node) function deletenode(&$doc, $node)
{ {
@ -107,7 +109,6 @@ function parseurl_getsiteinfo($url) {
} }
if ($siteinfo["image"] == "") { if ($siteinfo["image"] == "") {
require_once('include/Photo.php');
$list = $xpath->query("//img[@src]"); $list = $xpath->query("//img[@src]");
foreach ($list as $node) { foreach ($list as $node) {
$attr = array(); $attr = array();
@ -121,10 +122,33 @@ function parseurl_getsiteinfo($url) {
$i = fetch_url($attr["src"]); $i = fetch_url($attr["src"]);
$ph = new Photo($i, $type); $ph = new Photo($i, $type);
if(($ph->getWidth() > 200) and ($ph->getHeight() > 200)) if($ph->is_valid() and ($ph->getWidth() > 200) and ($ph->getHeight() > 200)) {
$siteinfo["image"] = $attr["src"]; 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"] == "") { if ($siteinfo["text"] == "") {
$text = ""; $text = "";
@ -172,8 +196,8 @@ function parse_url_content(&$a) {
if(local_user() && intval(get_pconfig(local_user(),'system','plaintext'))) if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
$textmode = true; $textmode = true;
if($textmode) //if($textmode)
$br = (($textmode) ? "\n" : '<br /?'); $br = (($textmode) ? "\n" : '<br />');
if(x($_GET,'binurl')) if(x($_GET,'binurl'))
$url = trim(hex2bin($_GET['binurl'])); $url = trim(hex2bin($_GET['binurl']));
@ -234,12 +258,19 @@ function parse_url_content(&$a) {
echo sprintf($template,$url,$url,'') . $str_tags; echo sprintf($template,$url,$url,'') . $str_tags;
killme(); killme();
} else { } else {
$image = $siteinfo["image"];
$text = $siteinfo["text"]; $text = $siteinfo["text"];
$title = $siteinfo["title"]; $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 .= '<img height="'.$imagedata["height"].'" width="'.$imagedata["width"].'" src="'.$imagedata["src"].'" alt="photo" />';
/* if ($image != "") {
$i = fetch_url($image); $i = fetch_url($image);
if($i) { if($i) {
require_once('include/Photo.php'); require_once('include/Photo.php');
@ -264,17 +295,17 @@ function parse_url_content(&$a) {
} }
} }
} }
} }*/
if(strlen($text)) { if(strlen($text)) {
if($textmode) if($textmode)
$text = $br.$br.'[quote]'.trim($text).'[/quote]'.$br ; $text = $br.'[quote]'.trim($text).'[/quote]'.$br ;
else else
$text = '<br /><br /><blockquote>'.trim($text).'</blockquote><br />'; $text = '<br /><blockquote>'.trim($text).'</blockquote><br />';
} }
if($image) { if($image) {
$text = $image.$br.$text; $text = $br.$br.$image.$br.$text;
} }
$title = str_replace(array("\r","\n"),array('',''),$title); $title = str_replace(array("\r","\n"),array('',''),$title);