diff options
author | Mike Macgirvin <mike@macgirvin.com> | 2010-07-22 22:41:45 -0700 |
---|---|---|
committer | Mike Macgirvin <mike@macgirvin.com> | 2010-07-22 22:41:45 -0700 |
commit | 36b66dccb60a7d65724da542f9d7a2d6722fc6aa (patch) | |
tree | c44dd1fae5d16c393b789ca814e31b4c90f4ce55 /mod | |
parent | 88bfe21bead769c3ba81e181b79f9d6426ace351 (diff) | |
download | volse-hubzilla-36b66dccb60a7d65724da542f9d7a2d6722fc6aa.tar.gz volse-hubzilla-36b66dccb60a7d65724da542f9d7a2d6722fc6aa.tar.bz2 volse-hubzilla-36b66dccb60a7d65724da542f9d7a2d6722fc6aa.zip |
ajaxify the wall poster
Diffstat (limited to 'mod')
-rw-r--r-- | mod/parse_url.php | 32 | ||||
-rw-r--r-- | mod/wall_upload.php | 88 |
2 files changed, 117 insertions, 3 deletions
diff --git a/mod/parse_url.php b/mod/parse_url.php new file mode 100644 index 000000000..33381a0d2 --- /dev/null +++ b/mod/parse_url.php @@ -0,0 +1,32 @@ +<?php + +require_once('library/HTML5/Parser.php'); + +function parse_url_content(&$a) { + $url = trim($_GET['url']); + + $template = "<a href=\"%s\" >%s</a>"; + + if($url) + $s = fetch_url($url); + + if(! $s) { + echo sprintf($template,$url,$url); + killme(); + } + + $dom = HTML5_Parser::parse($s); + + if(! $dom) + return $ret; + + $items = $dom->getElementsByTagName('title'); + + foreach($items as $item) { + $title = $item->textContent; + break; + } + + echo sprintf($template,$url,$title); + killme(); +}
\ No newline at end of file diff --git a/mod/wall_upload.php b/mod/wall_upload.php index 769e5dcbc..d74eae302 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -1,16 +1,98 @@ <?php +require_once('Photo.php'); function wall_upload_post(&$a) { + if(! local_user()) { + notice ( "Permission denied." . EOL ); + return; + } - $src = $_FILES['userfile']['tmp_name']; + $src = $_FILES['userfile']['tmp_name']; + $filename = basename($_FILES['userfile']['name']); + $filesize = intval($_FILES['userfile']['size']); + $imagedata = @file_get_contents($src); + $ph = new Photo($imagedata); -unlink($src); + if(! ($image = $ph->getImage())) { + notice("Unable to process image." . EOL); + @unlink($src); + return; + } + @unlink($src); - echo "<img src=\"".$a->get_baseurl(). "/images/default-profile.jpg\" alt=\"default\" />"; + $width = $ph->getWidth(); + $height = $ph->getHeight(); + + $hash = hash('md5',uniqid(mt_rand(),true)); + + $str_image = $ph->imageString(); + $smallest = 0; + + $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, + `height`, `width`, `data`, `scale` ) + VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 0 )", + intval($_SESSION['uid']), + dbesc($hash), + datetime_convert(), + datetime_convert(), + dbesc(basename($filename)), + intval($height), + intval($width), + dbesc($str_image)); + if($r) + notice("Image uploaded successfully." . EOL); + else + notice("Image upload failed." . EOL); + + if($width > 640 || $height > 640) { + $ph->scaleImage(640); + + $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, + `height`, `width`, `data`, `scale` ) + VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 1 )", + intval($_SESSION['uid']), + dbesc($hash), + datetime_convert(), + datetime_convert(), + dbesc(basename($filename)), + intval($ph->getHeight()), + intval($ph->getWidth()), + dbesc($ph->imageString()) + ); + if($r === false) + notice("Image size reduction (640) failed." . EOL ); + else + $smallest = 1; + } + + if($width > 320 || $height > 320) { + $ph->scaleImage(320); + + $r = q("INSERT INTO `photo` ( `uid`, `resource-id`, `created`, `edited`, `filename`, + `height`, `width`, `data`, `scale` ) + VALUES ( %d, '%s', '%s', '%s', '%s', %d, %d, '%s', 2 )", + intval($_SESSION['uid']), + dbesc($hash), + datetime_convert(), + datetime_convert(), + dbesc(basename($filename)), + intval($ph->getHeight()), + intval($ph->getWidth()), + dbesc($ph->imageString()) + ); + if($r === false) + notice("Image size reduction (320) failed." . EOL ); + else + $smallest = 2; + } + + $basename = basename($filename); + + echo "<img src=\"".$a->get_baseurl(). "/photo/{$hash}-{$smallest}.jpg\" alt=\"$basename\" />"; killme(); }
\ No newline at end of file |