X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fimagefile.php;h=68cfea48e7e01051eb26cbc72b1caad98887a72f;hb=91c1ab601726d6dd1fc13236be7723929d7dad9a;hp=26663eed7b14d8fafb6b9ce8750576783da8539c;hpb=a4af51b5baf80ba550f50107b72c260d79350819;p=quix0rs-gnu-social.git diff --git a/lib/imagefile.php b/lib/imagefile.php index 26663eed7b..68cfea48e7 100644 --- a/lib/imagefile.php +++ b/lib/imagefile.php @@ -61,11 +61,16 @@ class ImageFile { $this->id = $id; if (!empty($this->id)) { - $this->fileRecord = File::getKV('id', $this->id); - if (!$this->fileRecord instanceof File) { - throw new ServerException('Expected File object did not exist.'); + $this->fileRecord = new File(); + $this->fileRecord->id = $this->id; + if (!$this->fileRecord->find(true)) { + // If we have set an ID, we need that ID to exist! + throw new NoResultException($this->fileRecord); } } + + // These do not have to be the same as fileRecord->filename for example, + // since we may have generated an image source file from something else! $this->filepath = $filepath; $this->filename = basename($filepath); @@ -123,6 +128,14 @@ class ImageFile if (empty($file->filename)) { throw new UnsupportedMediaException(_('File without filename could not get a thumbnail source.')); } + + // First some mimetype specific exceptions + switch ($file->mimetype) { + case 'image/svg+xml': + throw new UseFileAsThumbnailException($file->id); + } + + // And we'll only consider it an image if it has such a media type switch ($media) { case 'image': $imgPath = $file->getPath(); @@ -176,6 +189,8 @@ class ImageFile case UPLOAD_ERR_NO_FILE: // No file; probably just a non-AJAX submission. + throw new ClientException(_('No file uploaded.')); + default: common_log(LOG_ERR, __METHOD__ . ": Unknown upload error " . $_FILES[$param]['error']); // TRANS: Exception thrown when uploading an image fails for an unknown reason. @@ -193,31 +208,6 @@ class ImageFile return new ImageFile(null, $_FILES[$param]['tmp_name']); } - /** - * Compat interface for old code generating avatar thumbnails... - * Saves the scaled file directly into the avatar area. - * - * @param int $size target width & height -- must be square - * @param int $x (default 0) upper-left corner to crop from - * @param int $y (default 0) upper-left corner to crop from - * @param int $w (default full) width of image area to crop - * @param int $h (default full) height of image area to crop - * @return string filename - */ - function resize($size, $x = 0, $y = 0, $w = null, $h = null) - { - $targetType = $this->preferredType(); - $outname = Avatar::filename($this->id, - image_type_to_extension($targetType), - $size, - common_timestamp()); - $outpath = Avatar::path($outname); - $this->resizeTo($outpath, array('width'=>$size, 'height'=>$size, - 'x'=>$x, 'y'=>$y, - 'w'=>$w, 'h'=>$h)); - return $outname; - } - /** * Copy the image file to the given destination. *