3 require_once('Photo.php');
5 function wall_upload_post(&$a) {
8 if(! x($_FILES,'media')) {
10 $r = q("SELECT `user`.*, `contact`.`id` FROM `user` LEFT JOIN `contact` on `user`.`uid` = `contact`.`uid` WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1",
18 $user_info = api_get_user($a);
19 $r = q("SELECT `user`.*, `contact`.`id` FROM `user` LEFT JOIN `contact` on `user`.`uid` = `contact`.`uid` WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1",
20 dbesc($user_info['screen_name'])
31 $page_owner_uid = $r[0]['uid'];
32 $default_cid = $r[0]['id'];
33 $page_owner_nick = $r[0]['nickname'];
34 $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
36 if((local_user()) && (local_user() == $page_owner_uid))
39 if($community_page && remote_user()) {
40 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
41 intval(remote_user()),
42 intval($page_owner_uid)
46 $visitor = remote_user();
47 $default_cid = $visitor;
53 notice( t('Permission denied.') . EOL );
57 if(! x($_FILES,'userfile') && ! x($_FILES,'media'))
60 if(x($_FILES,'userfile')) {
61 $src = $_FILES['userfile']['tmp_name'];
62 $filename = basename($_FILES['userfile']['name']);
63 $filesize = intval($_FILES['userfile']['size']);
65 elseif(x($_FILES,'media')) {
66 $src = $_FILES['media']['tmp_name'];
67 $filename = basename($_FILES['media']['name']);
68 $filesize = intval($_FILES['media']['size']);
71 $maximagesize = get_config('system','maximagesize');
73 if(($maximagesize) && ($filesize > $maximagesize)) {
74 echo sprintf( t('Image exceeds size limit of %d'), $maximagesize) . EOL;
79 $imagedata = @file_get_contents($src);
80 $ph = new Photo($imagedata);
82 if(! $ph->is_valid()) {
83 echo ( t('Unable to process image.') . EOL);
90 $width = $ph->getWidth();
91 $height = $ph->getHeight();
93 $hash = photo_new_resource();
97 $defperm = '<' . $default_cid . '>';
99 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 0, 0, $defperm);
102 echo ( t('Image upload failed.') . EOL);
106 if($width > 640 || $height > 640) {
107 $ph->scaleImage(640);
108 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 1, 0, $defperm);
113 if($width > 320 || $height > 320) {
114 $ph->scaleImage(320);
115 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 2, 0, $defperm);
120 $basename = basename($filename);
123 /* mod Waitman Gobble NO WARRANTY */
125 //if we get the signal then return the image url info in BBCODE, otherwise this outputs the info and bails (for the ajax image uploader on wall post)
126 if ($_REQUEST['hush']!='yeah') {
129 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
130 echo "\n\n" . '[url=' . $a->get_baseurl() . '/photos/' . $page_owner_nick . '/image/' . $hash . '][img]' . $a->get_baseurl() . "/photo/{$hash}-{$smallest}.jpg[/img][/url]\n\n";
132 echo '<br /><br /><a href="' . $a->get_baseurl() . '/photos/' . $page_owner_nick . '/image/' . $hash . '" ><img src="' . $a->get_baseurl() . "/photo/{$hash}-{$smallest}.jpg\" alt=\"$basename\" /></a><br /><br />";
136 $m = '[url=' . $a->get_baseurl() . '/photos/' . $page_owner_nick . '/image/' . $hash . '][img]' . $a->get_baseurl() . "/photo/{$hash}-{$smallest}.jpg[/img][/url]";
139 /* mod Waitman Gobble NO WARRANTY */