From 87dd0fbdb65f53b1cacabd1eedf3c3e14625fffe Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Wed, 4 May 2016 11:34:50 +0200 Subject: [PATCH 1/6] UseFileAsThumbnailException uses direct File object now --- classes/File.php | 2 +- lib/imagefile.php | 8 ++++++-- lib/usefileasthumbnailexception.php | 8 ++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/classes/File.php b/classes/File.php index 46d4d5498d..4489b4ecc1 100644 --- a/classes/File.php +++ b/classes/File.php @@ -498,7 +498,7 @@ class File extends Managed_DataObject return File_thumbnail::byFile($this); } catch (NoResultException $e) { // and if it's not a remote file, it'll be safe to use the locally stored File - throw new UseFileAsThumbnailException($this->id); + throw new UseFileAsThumbnailException($this); } } } diff --git a/lib/imagefile.php b/lib/imagefile.php index 85fc597126..156e3c6fd2 100644 --- a/lib/imagefile.php +++ b/lib/imagefile.php @@ -132,7 +132,7 @@ class ImageFile // First some mimetype specific exceptions switch ($file->mimetype) { case 'image/svg+xml': - throw new UseFileAsThumbnailException($file->id); + throw new UseFileAsThumbnailException($file); } // And we'll only consider it an image if it has such a media type @@ -282,7 +282,11 @@ class ImageFile } if (!file_exists($outpath)) { - throw new UseFileAsThumbnailException($this->id); + if ($this->fileRecord instanceof File) { + throw new UseFileAsThumbnailException($this->fileRecord); + } else { + throw new UnsupportedMediaException('No local File object exists for ImageFile.'); + } } return $outpath; diff --git a/lib/usefileasthumbnailexception.php b/lib/usefileasthumbnailexception.php index cafbe692b2..5ad33cb0a9 100644 --- a/lib/usefileasthumbnailexception.php +++ b/lib/usefileasthumbnailexception.php @@ -34,13 +34,9 @@ class UseFileAsThumbnailException extends UnsupportedMediaException { public $file = null; - public function __construct($file_id) + public function __construct(File $file) { - $this->file = File::getKV('id', $file_id); - if (!$this->file instanceof File) { - throw new ServerException('No File ID supplied to exception'); - } - + $this->file = $file; parent::__construct('Thumbnail not generated', $this->file->getPath()); } } From a5a96dd857574ba6bc21fa7d2c6057ea3f6d5a94 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Wed, 4 May 2016 11:44:00 +0200 Subject: [PATCH 2/6] Misplaced break/continue statements. --- lib/accountmover.php | 1 - lib/useractivitystream.php | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/accountmover.php b/lib/accountmover.php index 83314b4997..f8fb4512bd 100644 --- a/lib/accountmover.php +++ b/lib/accountmover.php @@ -114,7 +114,6 @@ class AccountMover extends QueueHandler $svcDocUrl = $link->href; if (isset($link['http://apinamespace.org/atom/username'])) { $username = $link['http://apinamespace.org/atom/username']; - break; } } diff --git a/lib/useractivitystream.php b/lib/useractivitystream.php index bb60485164..cc0e4297e6 100644 --- a/lib/useractivitystream.php +++ b/lib/useractivitystream.php @@ -219,7 +219,6 @@ class UserActivityStream extends AtomUserNoticeFeed } } catch (Exception $e) { common_log(LOG_ERR, $e->getMessage()); - continue; } } } From 6d6db77f06ab00b05ab3cf5aaecc2a931dc8a319 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Wed, 4 May 2016 11:44:14 +0200 Subject: [PATCH 3/6] Documentation update in File class file --- classes/File.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/classes/File.php b/classes/File.php index 4489b4ecc1..c85d919fd7 100644 --- a/classes/File.php +++ b/classes/File.php @@ -478,6 +478,8 @@ class File extends Managed_DataObject * @param $width int Max width of thumbnail in pixels. (if null, use common_config values) * @param $height int Max height of thumbnail in pixels. (if null, square-crop to $width) * @param $crop bool Crop to the max-values' aspect ratio + * @param $force_still bool Don't allow fallback to showing original (such as animated GIF) + * @param $upscale mixed Whether or not to scale smaller images up to larger thumbnail sizes. (null = site default) * * @return File_thumbnail * From 3a6733dc982c879ee728f2f001f13ab69e2e0ab9 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Wed, 4 May 2016 11:57:55 +0200 Subject: [PATCH 4/6] 2-frame GIF animations weren't recognised as animated --- lib/imagefile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/imagefile.php b/lib/imagefile.php index 156e3c6fd2..b0cd13089f 100644 --- a/lib/imagefile.php +++ b/lib/imagefile.php @@ -548,7 +548,7 @@ class ImageFile } fclose($fh); - return $count > 1; + return $count >= 1; // number of animated frames apart from the original image } public function getFileThumbnail($width, $height, $crop, $upscale=false) From bc70ec1263baa5d90cb8db4a574b271b4c06fdcc Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Wed, 4 May 2016 11:59:52 +0200 Subject: [PATCH 5/6] Don't warp attachment page thumbnails --- theme/base/css/display.css | 2 ++ 1 file changed, 2 insertions(+) diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 03cb4644ee..e87e87fbf8 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -851,6 +851,8 @@ clear:both; } #attachment_view img, #attachment_view .attachment_player { +height: auto; +width: auto; max-width:480px; max-height:480px; } From bd306bdb9fb43e80f9092784602a9508a7d52031 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Mon, 9 May 2016 22:08:36 +0200 Subject: [PATCH 6/6] Add /download action for attachments --- actions/attachment_download.php | 20 ++++++++++++++++++++ lib/router.php | 4 ++++ 2 files changed, 24 insertions(+) create mode 100644 actions/attachment_download.php diff --git a/actions/attachment_download.php b/actions/attachment_download.php new file mode 100644 index 0000000000..6792c45993 --- /dev/null +++ b/actions/attachment_download.php @@ -0,0 +1,20 @@ + + * @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link https:/gnu.io/social + */ +class Attachment_downloadAction extends AttachmentAction +{ + public function showPage() + { + common_redirect($this->attachment->getUrl(), 302); + } +} diff --git a/lib/router.php b/lib/router.php index 5a51f3d7d4..b01c9a7677 100644 --- a/lib/router.php +++ b/lib/router.php @@ -223,6 +223,10 @@ class Router array('action' => 'attachment'), array('attachment' => '[0-9]+')); + $m->connect('attachment/:attachment/download', + array('action' => 'attachment_download'), + array('attachment' => '[0-9]+')); + $m->connect('attachment/:attachment/thumbnail', array('action' => 'attachment_thumbnail'), array('attachment' => '[0-9]+'));