From: Marcel Werk Date: Sun, 19 Jun 2016 22:00:38 +0000 (+0200) Subject: Added methods to get the dimensions of a thumbnail X-Git-Tag: 3.0.0_Beta_1~1395 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=622fb275495738fc56d1fdc669caf34a17bc3dab;p=GitHub%2FWoltLab%2FWCF.git Added methods to get the dimensions of a thumbnail --- diff --git a/wcfsetup/install/files/lib/data/media/Media.class.php b/wcfsetup/install/files/lib/data/media/Media.class.php index f20ba89e98..0e6e933b2f 100644 --- a/wcfsetup/install/files/lib/data/media/Media.class.php +++ b/wcfsetup/install/files/lib/data/media/Media.class.php @@ -116,6 +116,10 @@ class Media extends DatabaseObject implements ILinkableObject, IRouteController, throw new SystemException("Unknown thumbnail size '".$size."'"); } + if (!$this->{$size.'ThumbnailType'}) { + return $this->getLink(); + } + return LinkHandler::getInstance()->getLink('Media', [ 'forceFrontend' => true, 'object' => $this, @@ -123,6 +127,44 @@ class Media extends DatabaseObject implements ILinkableObject, IRouteController, ]); } + /** + * Returns the width of the thumbnail file with the given size. + * + * @param string $size + * @return integer + * @throws SystemException + */ + public function getThumbnailWidth($size) { + if (!isset(self::$thumbnailSizes[$size])) { + throw new SystemException("Unknown thumbnail size '".$size."'"); + } + + if ($this->{$size.'ThumbnailType'}) { + return $this->{$size.'ThumbnailWidth'}; + } + + return $this->width; + } + + /** + * Returns the height of the thumbnail file with the given size. + * + * @param string $size + * @return integer + * @throws SystemException + */ + public function getThumbnailHeight($size) { + if (!isset(self::$thumbnailSizes[$size])) { + throw new SystemException("Unknown thumbnail size '".$size."'"); + } + + if ($this->{$size.'ThumbnailType'}) { + return $this->{$size.'ThumbnailHeight'}; + } + + return $this->height; + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/data/media/ViewableMedia.class.php b/wcfsetup/install/files/lib/data/media/ViewableMedia.class.php index c621f1b311..af180a8132 100644 --- a/wcfsetup/install/files/lib/data/media/ViewableMedia.class.php +++ b/wcfsetup/install/files/lib/data/media/ViewableMedia.class.php @@ -68,7 +68,7 @@ class ViewableMedia extends DatabaseObjectDecorator { throw new SystemException("Unknown thumbnail size '".$size."'"); } - return ''.StringUtil::encodeHTML($this->altText).'title ? 'title="'.StringUtil::encodeHTML($this->title).'" ' : '').'/>'; + return ''.StringUtil::encodeHTML($this->altText).'title ? 'title="'.StringUtil::encodeHTML($this->title).'" ' : '').'style="width: ' . $this->getThumbnailWidth($size) . 'px; height: ' . $this->getThumbnailHeight($size) . 'px;">'; } /**