3 require_once('Photo.php');
5 function wall_upload_post(&$a) {
9 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
22 $page_owner_uid = $r[0]['uid'];
23 $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
25 if((local_user()) && (local_user() == $page_owner_uid))
28 if($community_page && remote_user()) {
29 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
30 intval(remote_user()),
31 intval($page_owner_uid)
35 $visitor = remote_user();
41 notice( t('Permission denied.') . EOL );
45 if(! x($_FILES,'userfile'))
48 $src = $_FILES['userfile']['tmp_name'];
49 $filename = basename($_FILES['userfile']['name']);
50 $filesize = intval($_FILES['userfile']['size']);
52 $maximagesize = get_config('system','maximagesize');
54 if(($maximagesize) && ($filesize > $maximagesize)) {
55 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
60 $imagedata = @file_get_contents($src);
61 $ph = new Photo($imagedata);
63 if(! $ph->is_valid()) {
64 echo ( t('Unable to process image.') . EOL);
71 $width = $ph->getWidth();
72 $height = $ph->getHeight();
74 $hash = photo_new_resource();
78 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 0 );
81 echo ( t('Image upload failed.') . EOL);
85 if($width > 640 || $height > 640) {
87 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 1 );
92 if($width > 320 || $height > 320) {
94 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 2 );
99 $basename = basename($filename);
100 echo "<br /><br /><img src=\"".$a->get_baseurl(). "/photo/{$hash}-{$smallest}.jpg\" alt=\"$basename\" /><br /><br />";
103 return; // NOTREACHED