3 require_once('include/Photo.php');
5 function wall_upload_post(&$a) {
7 logger("wall upload: starting new upload", LOGGER_DEBUG);
10 if(! x($_FILES,'media')) {
12 $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 $user_info = api_get_user($a);
21 $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",
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 $src = $_FILES['media']['tmp_name'];
81 $filename = basename($_FILES['media']['name']);
82 $filesize = intval($_FILES['media']['size']);
83 $filetype = $_FILES['media']['type'];
86 if ($filetype=="") $filetype=guess_image_type($filename);
87 $maximagesize = get_config('system','maximagesize');
89 if(($maximagesize) && ($filesize > $maximagesize)) {
90 echo sprintf( t('Image exceeds size limit of %d'), $maximagesize) . EOL;
95 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
96 intval($page_owner_uid)
99 $limit = service_class_fetch($page_owner_uid,'photo_upload_limit');
101 if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
102 echo upgrade_message(true) . EOL ;
108 $imagedata = @file_get_contents($src);
109 $ph = new Photo($imagedata, $filetype);
111 if(! $ph->is_valid()) {
112 echo ( t('Unable to process image.') . EOL);
120 $max_length = get_config('system','max_image_length');
122 $max_length = MAX_IMAGE_LENGTH;
124 $ph->scaleImage($max_length);
126 $width = $ph->getWidth();
127 $height = $ph->getHeight();
129 $hash = photo_new_resource();
133 $defperm = '<' . $default_cid . '>';
135 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 0, 0, $defperm);
138 echo ( t('Image upload failed.') . EOL);
142 if($width > 640 || $height > 640) {
143 $ph->scaleImage(640);
144 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 1, 0, $defperm);
149 if($width > 320 || $height > 320) {
150 $ph->scaleImage(320);
151 $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 2, 0, $defperm);
156 $basename = basename($filename);
159 /* mod Waitman Gobble NO WARRANTY */
161 //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)
162 if ($_REQUEST['hush']!='yeah') {
163 if(local_user() && (! feature_enabled(local_user(),'richtext') || x($_REQUEST['nomce'])) ) {
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";
167 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 />";
171 $m = '[url=' . $a->get_baseurl() . '/photos/' . $page_owner_nick . '/image/' . $hash . '][img]' . $a->get_baseurl() . "/photo/{$hash}-{$smallest}.".$ph->getExt()."[/img][/url]";
174 /* mod Waitman Gobble NO WARRANTY */