3 namespace wcf\data\user\cover\photo
;
6 use wcf\util\ImageUtil
;
9 * Represents a user's cover photo.
11 * @author Alexander Ebert
12 * @copyright 2001-2019 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package WoltLabSuite\Core\Data\User\Cover\Photo
16 class UserCoverPhoto
implements IUserCoverPhoto
22 protected $coverPhotoExtension;
28 protected $coverPhotoHash;
33 protected $coverPhotoHasWebP = 0;
41 const MAX_HEIGHT
= 800;
43 const MAX_WIDTH
= 2000;
45 const MIN_HEIGHT
= 200;
47 const MIN_WIDTH
= 500;
50 * UserCoverPhoto constructor.
53 * @param string $coverPhotoHash
54 * @param string $coverPhotoExtension
56 public function __construct($userID, $coverPhotoHash, $coverPhotoExtension, int $coverPhotoHasWebP)
58 $this->userID
= $userID;
59 $this->coverPhotoHash
= $coverPhotoHash;
60 $this->coverPhotoExtension
= $coverPhotoExtension;
61 $this->coverPhotoHasWebP
= $coverPhotoHasWebP;
67 public function delete()
69 if (\file_exists
($this->getLocation(false))) {
70 @\
unlink($this->getLocation(false));
73 if (\file_exists
($this->getLocation(true))) {
74 @\
unlink($this->getLocation(true));
81 public function getLocation(?
bool $forceWebP = null): string
83 return WCF_DIR
. 'images/coverPhotos/' . $this->getFilename();
89 public function getURL(?
bool $forceWebP = null): string
91 return WCF
::getPath() . 'images/coverPhotos/' . $this->getFilename();
97 public function getFilename(?
bool $forceWebP = null): string
99 $useWebP = $forceWebP ||
($forceWebP === null && ImageUtil
::browserSupportsWebP());
102 $this->coverPhotoHash
,
105 ) . '/' . $this->userID
. '-' . $this->coverPhotoHash
. '.' . ($useWebP ?
'webp' : $this->coverPhotoExtension
);
109 * Returns the minimum and maximum dimensions for cover photos.
113 public static function getCoverPhotoDimensions()
117 'height' => self
::MAX_HEIGHT
,
118 'width' => self
::MAX_WIDTH
,
121 'height' => self
::MIN_HEIGHT
,
122 'width' => self
::MIN_WIDTH
,