enhance url parse

This commit is contained in:
Mike Macgirvin 2010-07-22 23:17:41 -07:00
parent 36b66dccb6
commit 7a07a2cf31
2 changed files with 40 additions and 21 deletions

View File

@ -3,15 +3,20 @@
require_once('library/HTML5/Parser.php'); require_once('library/HTML5/Parser.php');
function parse_url_content(&$a) { function parse_url_content(&$a) {
$url = trim($_GET['url']); $url = trim($_GET['url']);
$template = "<a href=\"%s\" >%s</a>"; $template = "<a href=\"%s\" >%s</a>%s";
if($url) if($url)
$s = fetch_url($url); $s = fetch_url($url);
else {
echo '';
killme();
}
if(! $s) { if(! $s) {
echo sprintf($template,$url,$url); echo sprintf($template,$url,$url,'');
killme(); killme();
} }
@ -21,12 +26,30 @@ function parse_url_content(&$a) {
return $ret; return $ret;
$items = $dom->getElementsByTagName('title'); $items = $dom->getElementsByTagName('title');
foreach($items as $item) { if($items) {
$title = $item->textContent; foreach($items as $item) {
break; $title = $item->textContent;
break;
}
} }
echo sprintf($template,$url,$title); $items = $dom->getElementsByTagName('p');
if($items) {
foreach($items as $item) {
$text = $item->textContent;
$text = strip_tags($text);
if(strlen($text) < 100)
continue;
$text = substr($text,0,250) . '...' ;
break;
}
}
if(strlen($text)) {
$text = '<br />' . $text;
}
echo sprintf($template,$url,$title,$text);
killme(); killme();
} }

View File

@ -5,8 +5,8 @@ require_once('Photo.php');
function wall_upload_post(&$a) { function wall_upload_post(&$a) {
if(! local_user()) { if(! local_user()) {
notice ( "Permission denied." . EOL ); echo ( "Permission denied." . EOL );
return; killme();
} }
$src = $_FILES['userfile']['tmp_name']; $src = $_FILES['userfile']['tmp_name'];
@ -17,9 +17,9 @@ function wall_upload_post(&$a) {
$ph = new Photo($imagedata); $ph = new Photo($imagedata);
if(! ($image = $ph->getImage())) { if(! ($image = $ph->getImage())) {
notice("Unable to process image." . EOL); echo ("Unable to process image." . EOL);
@unlink($src); @unlink($src);
return; killme();
} }
@unlink($src); @unlink($src);
@ -43,10 +43,10 @@ function wall_upload_post(&$a) {
intval($height), intval($height),
intval($width), intval($width),
dbesc($str_image)); dbesc($str_image));
if($r) if(! $r) {
notice("Image uploaded successfully." . EOL); echo ("Image upload failed." . EOL);
else killme();
notice("Image upload failed." . EOL); }
if($width > 640 || $height > 640) { if($width > 640 || $height > 640) {
$ph->scaleImage(640); $ph->scaleImage(640);
@ -63,9 +63,7 @@ function wall_upload_post(&$a) {
intval($ph->getWidth()), intval($ph->getWidth()),
dbesc($ph->imageString()) dbesc($ph->imageString())
); );
if($r === false) if($r)
notice("Image size reduction (640) failed." . EOL );
else
$smallest = 1; $smallest = 1;
} }
@ -84,9 +82,7 @@ function wall_upload_post(&$a) {
intval($ph->getWidth()), intval($ph->getWidth()),
dbesc($ph->imageString()) dbesc($ph->imageString())
); );
if($r === false) if($r)
notice("Image size reduction (320) failed." . EOL );
else
$smallest = 2; $smallest = 2;
} }