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()) {
41 if(is_array($_SESSION['remote'])) {
42 foreach($_SESSION['remote'] as $v) {
43 if($v['uid'] == $page_owner_uid) {
51 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
53 intval($page_owner_uid)
64 notice( t('Permission denied.') . EOL );
68 if(! x($_FILES,'userfile') && ! x($_FILES,'media'))
71 if(x($_FILES,'userfile')) {
72 $src = $_FILES['userfile']['tmp_name'];
73 $filename = basename($_FILES['userfile']['name']);
74 $filesize = intval($_FILES['userfile']['size']);
75 $filetype = $_FILES['userfile']['type'];
77 elseif(x($_FILES,'media')) {
78 $src = $_FILES['media']['tmp_name'];
79 $filename = basename($_FILES['media']['name']);
80 $filesize = intval($_FILES['media']['size']);
81 $filetype = $_FILES['media']['type'];
84 if ($filetype=="") $filetype=guess_image_type($filename);
85 $maximagesize = get_config('system','maximagesize');
87 if(($maximagesize) && ($filesize > $maximagesize)) {
88 echo sprintf( t('Image exceeds size limit of %d'), $maximagesize) . EOL;
93 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
94 intval($page_owner_uid)
97 $limit = service_class_fetch($page_owner_uid,'photo_upload_limit');
99 if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
100 echo upgrade_message(true) . EOL ;
106 $imagedata = @file_get_contents($src);
107 $ph = new Photo($imagedata, $filetype);
109 if(! $ph->is_valid()) {
110 echo ( t('Unable to process image.') . EOL);
118 $max_length = get_config('system','max_image_length');
120 $max_length = MAX_IMAGE_LENGTH;
122 $ph->scaleImage($max_length);
124 $width = $ph->getWidth();
125 $height = $ph->getHeight();
127 $hash = photo_new_resource();
131 $defperm = '<' . $default_cid . '>';
133 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 0, 0, $defperm);
136 echo ( t('Image upload failed.') . EOL);
140 if($width > 640 || $height > 640) {
141 $ph->scaleImage(640);
142 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 1, 0, $defperm);
147 if($width > 320 || $height > 320) {
148 $ph->scaleImage(320);
149 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 2, 0, $defperm);
154 $basename = basename($filename);
157 /* mod Waitman Gobble NO WARRANTY */
159 //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)
160 if ($_REQUEST['hush']!='yeah') {
163 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
164 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";
166 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 />";
170 $m = '[url=' . $a->get_baseurl() . '/photos/' . $page_owner_nick . '/image/' . $hash . '][img]' . $a->get_baseurl() . "/photo/{$hash}-{$smallest}.".$ph->getExt()."[/img][/url]";
173 /* mod Waitman Gobble NO WARRANTY */