/** * Returns an XML valid attachment HTML string that handles missing thumbnail URLs. * * @param \App\Board $board The board this thumbnail will belong to. * @param int $maxWidth Optional. Maximum width constraint. Defaults null. * @return string as HTML */ public function getThumbnailHTML(Board $board, $maxDimension = null) { $ext = $this->guessExtension(); $mime = $this->mime; $url = media_url("static/img/filetypes/{$ext}.svg", false); $spoil = $this->isSpoiler(); $deleted = $this->isDeleted(); $md5 = $deleted ? null : $this->hash; if ($deleted) { $url = $board->getAssetUrl('file_deleted'); } else { if ($spoil) { $url = $board->getAssetUrl('file_spoiler'); } else { if ($this->isImageVector()) { $url = $this->getDownloadURL($board); } else { if ($this->isAudio() || $this->isImage() || $this->isVideo() || $this->isDocument()) { if ($this->hasThumb()) { $url = $this->getThumbnailURL($board); } else { if ($this->isAudio()) { $url = media_url("static/img/assets/audio.gif", false); } } } } } } $classHTML = $this->getThumbnailClasses(); // Measure dimensions. $height = "auto"; $width = "auto"; $maxWidth = "none"; $maxHeight = "none"; $minWidth = "none"; $minHeight = "none"; $oHeight = $this->thumbnail_height; $oWidth = $this->thumbnail_width; if ($this->has_thumbnail && !$this->isSpoiler() && !$this->isDeleted()) { $height = $oHeight . "px"; $width = $this->thumbnail_width . "px"; if (is_integer($maxDimension) && ($oWidth > $maxDimension || $oHeight > $maxDimension)) { if ($oWidth > $oHeight) { $height = "auto"; $width = $maxDimension . "px"; } else { if ($oWidth < $oHeight) { $height = $maxDimension . "px"; $width = "auto"; } else { $height = $maxDimension; $width = $maxDimension; } } } $minWidth = $width; $minHeight = $height; } else { $maxWidth = Settings::get('attachmentThumbnailSize') . "px"; $maxHeight = $maxWidth; $width = $maxWidth; $height = "auto"; if (is_integer($maxDimension)) { $maxWidth = "{$maxDimension}px"; $maxHeight = "{$maxDimension}px"; } if ($this->isSpoiler() || $this->isDeleted()) { $minHeight = "none"; $minWidth = "none"; $width = $maxWidth; } } return "<div class=\"attachment-wrapper\" style=\"height: {$height}; width: {$width};\">" . "<img class=\"attachment-img {$classHTML}\" src=\"{$url}\" data-mime=\"{$mime}\" data-md5=\"{$md5}\" style=\"height: {$height}; width: {$width};\"/>" . "</div>"; }
/** * Returns an XML valid attachment HTML string that handles missing thumbnail URLs. * * @return string as HTML */ public function getThumbnailHTML(Board $board) { $ext = $this->guessExtension(); $mime = $this->mime; $url = asset("static/img/filetypes/{$ext}.svg"); $type = "other"; $html = ""; $stock = true; $spoil = $this->isSpoiler(); if ($spoil) { $url = $board->getAssetUrl('file_spoiler'); } else { if ($this->isVideo()) { if ($this->hasThumb()) { $stock = false; $url = $this->getThumbnailURL($board); $type = "video"; } } else { if ($this->isAudio()) { $stock = false; $type = "audio"; $url = $this->getThumbnailURL($board); } else { if ($this->isImage()) { if ($this->hasThumb()) { $stock = false; $url = $this->getThumbnailURL($board); $type = "img"; } } else { if ($this->isImageVector()) { $stock = false; $url = $this->getDownloadURL($board); $type = "img"; } } } } } $classes = []; $classes['type'] = "attachment-type-{$type}"; $classes['ext'] = "attachent-ext-{$ext}"; $classes['stock'] = $stock ? "thumbnail-stock" : "thumbnail-content"; $classes['spoil'] = $spoil ? "thumbnail-spoiler" : "thumbnail-not-spoiler"; $classHTML = implode(" ", $classes); return "<div class=\"attachment-wrapper {$classHTML}\"><img class=\"attachment-img {$classHTML}\" src=\"{$url}\" data-mime=\"{$mime}\" /></div>"; }
/** * Returns an XML valid attachment HTML string that handles missing thumbnail URLs. * * @return string as HTML */ public function getThumbnailHTML(Board $board) { $ext = $this->guessExtension(); $mime = $this->mime; $url = asset("static/img/filetypes/{$ext}.svg"); $spoil = $this->isSpoiler(); if ($spoil) { $url = $board->getAssetUrl('file_spoiler'); } else { if ($this->isImageVector()) { $url = $this->getDownloadURL($board); } else { if ($this->isAudio() || $this->isImage() || $this->isVideo()) { if ($this->hasThumb()) { $url = $this->getThumbnailURL($board); } else { if ($this->isAudio()) { $url = asset("static/img/assets/audio.gif"); } } } } } $classHTML = $this->getThumbnailClasses(); // Measure dimensions. $height = "auto"; $width = "auto"; if ($this->has_thumbnail) { $oHeight = $this->thumbnail_width; $oWidth = $this->thumbnailWidth; if ($this->thumbnail_width > $this->thumbnail_height) { $width = $this->thumbnail_width . "px"; } else { if ($this->thumbnail_width < $this->thumbnail_height) { $height = $this->thumbnail_height . "px"; } } } else { $oHeight = Settings::get('attachmentThumbnailSize') . "px"; $oWidth = $oHeight; $width = $oHeight; $height = $oHeight; } return "<div class=\"attachment-wrapper\" style=\"height: {$oHeight}; width: {$oWidth};\">" . "<img class=\"attachment-img {$classHTML}\" src=\"{$url}\" data-mime=\"{$mime}\" style=\"height: {$height}; width: {$width};\"/>" . "</div>"; }