+ if ($error !== UPLOAD_ERR_OK) {
+ switch ($error) {
+ case UPLOAD_ERR_INI_SIZE:
+ $this->systemMessages->addNotice($this->t('Image exceeds size limit of %s', ini_get('upload_max_filesize')));
+ break;
+ case UPLOAD_ERR_FORM_SIZE:
+ $this->systemMessages->addNotice($this->t('Image exceeds size limit of %s', Strings::formatBytes($request['MAX_FILE_SIZE'] ?? 0)));
+ break;
+ case UPLOAD_ERR_PARTIAL:
+ $this->systemMessages->addNotice($this->t('Image upload didn\'t complete, please try again'));
+ break;
+ case UPLOAD_ERR_NO_FILE:
+ $this->systemMessages->addNotice($this->t('Image file is missing'));
+ break;
+ case UPLOAD_ERR_NO_TMP_DIR:
+ case UPLOAD_ERR_CANT_WRITE:
+ case UPLOAD_ERR_EXTENSION:
+ $this->systemMessages->addNotice($this->t('Server can\'t accept new file upload at this time, please contact your administrator'));
+ break;
+ }
+ @unlink($src);
+ $foo = 0;
+ Hook::callAll('photo_post_end', $foo);
+ return;
+ }
+
+ $type = Images::getMimeTypeBySource($src, $filename, $type);
+
+ $this->logger->info('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes');
+
+ $maximagesize = Strings::getBytesFromShorthand($this->config->get('system', 'maximagesize'));
+
+ if ($maximagesize && ($filesize > $maximagesize)) {
+ $this->systemMessages->addNotice($this->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)));
+ @unlink($src);
+ $foo = 0;
+ Hook::callAll('photo_post_end', $foo);
+ return;
+ }
+
+ if (!$filesize) {
+ $this->systemMessages->addNotice($this->t('Image file is empty.'));
+ @unlink($src);
+ $foo = 0;
+ Hook::callAll('photo_post_end', $foo);
+ return;
+ }
+
+ $this->logger->debug('loading contents', ['src' => $src]);
+
+ $imagedata = @file_get_contents($src);
+
+ $image = new Image($imagedata, $type);
+
+ if (!$image->isValid()) {
+ $this->logger->notice('unable to process image');
+ $this->systemMessages->addNotice($this->t('Unable to process image.'));
+ @unlink($src);
+ $foo = 0;
+ Hook::callAll('photo_post_end',$foo);
+ return;
+ }
+
+ $exif = $image->orient($src);
+ @unlink($src);
+
+ $max_length = $this->config->get('system', 'max_image_length');
+ if ($max_length > 0) {
+ $image->scaleDown($max_length);
+ }
+
+ $width = $image->getWidth();
+ $height = $image->getHeight();
+
+ $smallest = 0;
+
+ $resource_id = Photo::newResource();
+
+ $r = Photo::store($image, $this->owner['uid'], 0, $resource_id, $filename, $album, 0 , Photo::DEFAULT, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
+
+ if (!$r) {
+ $this->logger->warning('image store failed');
+ $this->systemMessages->addNotice($this->t('Image upload failed.'));
+ return;
+ }
+
+ if ($width > 640 || $height > 640) {
+ $image->scaleDown(640);
+ Photo::store($image, $this->owner['uid'], 0, $resource_id, $filename, $album, 1, Photo::DEFAULT, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
+ $smallest = 1;
+ }
+
+ if ($width > 320 || $height > 320) {
+ $image->scaleDown(320);
+ Photo::store($image, $this->owner['uid'], 0, $resource_id, $filename, $album, 2, Photo::DEFAULT, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
+ $smallest = 2;
+ }
+
+ $uri = Item::newURI();
+
+ // Create item container
+ $lat = $lon = null;
+ if (!empty($exif['GPS']) && Feature::isEnabled($this->owner['uid'], 'photo_location')) {
+ $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
+ $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
+ }
+
+ $arr = [];
+ if ($lat && $lon) {
+ $arr['coord'] = $lat . ' ' . $lon;
+ }
+
+ $arr['guid'] = System::createUUID();
+ $arr['uid'] = $this->owner['uid'];
+ $arr['uri'] = $uri;
+ $arr['post-type'] = Item::PT_IMAGE;
+ $arr['wall'] = 1;
+ $arr['resource-id'] = $resource_id;
+ $arr['contact-id'] = $this->owner['id'];
+ $arr['owner-name'] = $this->owner['name'];
+ $arr['owner-link'] = $this->owner['url'];
+ $arr['owner-avatar'] = $this->owner['thumb'];
+ $arr['author-name'] = $this->owner['name'];
+ $arr['author-link'] = $this->owner['url'];
+ $arr['author-avatar'] = $this->owner['thumb'];
+ $arr['title'] = '';
+ $arr['allow_cid'] = $str_contact_allow;
+ $arr['allow_gid'] = $str_group_allow;
+ $arr['deny_cid'] = $str_contact_deny;
+ $arr['deny_gid'] = $str_group_deny;
+ $arr['visible'] = $visible;
+ $arr['origin'] = 1;
+
+ $arr['body'] = '[url=' . $this->baseUrl . '/photos/' . $this->owner['nickname'] . '/image/' . $resource_id . ']'
+ . '[img]' . $this->baseUrl . "/photo/{$resource_id}-{$smallest}.".$image->getExt() . '[/img]'
+ . '[/url]';
+
+ $item_id = Item::insert($arr);
+ // Update the photo albums cache
+ Photo::clearAlbumCache($this->owner['uid']);
+
+ Hook::callAll('photo_post_end', $item_id);
+
+ // addon uploaders should call "exit()" within the photo_post_end hook
+ // if they do not wish to be redirected
+
+ $this->baseUrl->redirect($this->session->get('photo_return') ?? 'profile/' . $this->owner['nickname'] . '/photos');
+ }
+
+ protected function content(array $request = []): string
+ {
+ parent::content($request);
+
+ if ($this->config->get('system', 'block_public') && !$this->session->isAuthenticated()) {
+ throw new HttpException\ForbiddenException($this->t('Public access denied.'));
+ }
+
+ $owner_uid = $this->owner['uid'];
+ $is_owner = $this->session->getLocalUserId() == $owner_uid;
+
+ if ($this->owner['hidewall'] && !$this->session->isAuthenticated()) {
+ $this->baseUrl->redirect('profile/' . $this->owner['nickname'] . '/restricted');