3 require_once('include/Photo.php');
5 function wall_upload_post(&$a, $desktopmode = true) {
7 logger("wall upload: starting new upload", LOGGER_DEBUG);
10 if(! x($_FILES,'media')) {
12 $r = q("SELECT `user`.*, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid` WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1",
20 $user_info = api_get_user($a);
21 $r = q("SELECT `user`.*, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid` WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1",
22 dbesc($user_info['screen_name'])
33 $page_owner_uid = $r[0]['uid'];
34 $default_cid = $r[0]['id'];
35 $page_owner_nick = $r[0]['nickname'];
36 $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
38 if((local_user()) && (local_user() == $page_owner_uid))
41 if($community_page && remote_user()) {
43 if(is_array($_SESSION['remote'])) {
44 foreach($_SESSION['remote'] as $v) {
45 if($v['uid'] == $page_owner_uid) {
53 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
55 intval($page_owner_uid)
66 notice( t('Permission denied.') . EOL );
70 if(! x($_FILES,'userfile') && ! x($_FILES,'media'))
73 if(x($_FILES,'userfile')) {
74 $src = $_FILES['userfile']['tmp_name'];
75 $filename = basename($_FILES['userfile']['name']);
76 $filesize = intval($_FILES['userfile']['size']);
77 $filetype = $_FILES['userfile']['type'];
79 elseif(x($_FILES,'media')) {
80 if (is_array($_FILES['media']['tmp_name']))
81 $src = $_FILES['media']['tmp_name'][0];
83 $src = $_FILES['media']['tmp_name'];
85 if (is_array($_FILES['media']['name']))
86 $filename = basename($_FILES['media']['name'][0]);
88 $filename = basename($_FILES['media']['name']);
90 if (is_array($_FILES['media']['size']))
91 $filesize = intval($_FILES['media']['size'][0]);
93 $filesize = intval($_FILES['media']['size']);
95 if (is_array($_FILES['media']['type']))
96 $filetype = $_FILES['media']['type'][0];
98 $filetype = $_FILES['media']['type'];
101 // This is a special treatment for picture upload from Twidere
102 if (($filename == "octet-stream") AND ($filetype != "")) {
103 $filename = $filetype;
108 $filetype=guess_image_type($filename);
110 // If there is a temp name, then do a manual check
111 // This is more reliable than the provided value
112 $imagedata = getimagesize($src);
114 $filetype = $imagedata['mime'];
116 logger("File upload src: ".$src." - filename: ".$filename.
117 " - size: ".$filesize." - type: ".$filetype, LOGGER_DEBUG);
119 $maximagesize = get_config('system','maximagesize');
121 if(($maximagesize) && ($filesize > $maximagesize)) {
122 echo sprintf( t('Image exceeds size limit of %d'), $maximagesize) . EOL;
127 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
128 intval($page_owner_uid)
131 $limit = service_class_fetch($page_owner_uid,'photo_upload_limit');
133 if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
134 echo upgrade_message(true) . EOL ;
140 $imagedata = @file_get_contents($src);
141 $ph = new Photo($imagedata, $filetype);
143 if(! $ph->is_valid()) {
144 echo ( t('Unable to process image.') . EOL);
152 $max_length = get_config('system','max_image_length');
154 $max_length = MAX_IMAGE_LENGTH;
155 if($max_length > 0) {
156 $ph->scaleImage($max_length);
157 logger("File upload: Scaling picture to new size ".$max_length, LOGGER_DEBUG);
160 $width = $ph->getWidth();
161 $height = $ph->getHeight();
163 $hash = photo_new_resource();
167 $defperm = '<' . $default_cid . '>';
169 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 0, 0, $defperm);
172 echo ( t('Image upload failed.') . EOL);
176 if($width > 640 || $height > 640) {
177 $ph->scaleImage(640);
178 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 1, 0, $defperm);
183 if($width > 320 || $height > 320) {
184 $ph->scaleImage(320);
185 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 2, 0, $defperm);
186 if($r AND ($smallest == 0))
190 $basename = basename($filename);
194 $r = q("SELECT `id`, `datasize`, `width`, `height`, `type` FROM `photo` WHERE `resource-id` = '%s' ORDER BY `width` DESC LIMIT 1", $hash);
200 $picture["id"] = $r[0]["id"];
201 $picture["size"] = $r[0]["datasize"];
202 $picture["width"] = $r[0]["width"];
203 $picture["height"] = $r[0]["height"];
204 $picture["type"] = $r[0]["type"];
205 $picture["albumpage"] = $a->get_baseurl().'/photos/'.$page_owner_nick.'/image/'.$hash;
206 $picture["picture"] = $a->get_baseurl()."/photo/{$hash}-0.".$ph->getExt();
207 $picture["preview"] = $a->get_baseurl()."/photo/{$hash}-{$smallest}.".$ph->getExt();
212 /* mod Waitman Gobble NO WARRANTY */
214 //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)
215 if ($_REQUEST['hush']!='yeah') {
216 if(local_user() && (! feature_enabled(local_user(),'richtext') || x($_REQUEST['nomce'])) ) {
217 echo "\n\n" . '[url=' . $a->get_baseurl() . '/photos/' . $page_owner_nick . '/image/' . $hash . '][img]' . $a->get_baseurl() . "/photo/{$hash}-{$smallest}.".$ph->getExt()."[/img][/url]\n\n";
220 echo '<br /><br /><a href="' . $a->get_baseurl() . '/photos/' . $page_owner_nick . '/image/' . $hash . '" ><img src="' . $a->get_baseurl() . "/photo/{$hash}-{$smallest}.".$ph->getExt()."\" alt=\"$basename\" /></a><br /><br />";
224 $m = '[url='.$a->get_baseurl().'/photos/'.$page_owner_nick.'/image/'.$hash.'][img]'.$a->get_baseurl()."/photo/{$hash}-{$smallest}.".$ph->getExt()."[/img][/url]";
227 /* mod Waitman Gobble NO WARRANTY */