diff options
author | Malf Furious <m@lfurio.us> | 2017-05-13 18:48:09 -0400 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2017-05-13 18:48:09 -0400 |
commit | ed7b14b506094577a4b727f6f962777c245a3c64 (patch) | |
tree | a70c3bc525df54327ffec9af148f64d956c3bfce /app/class/object.class.php | |
parent | e2d3d894f024169cd84c93913db88f3864954532 (diff) | |
parent | 0cceafe1831487c61eaac1d3a71a8d3039a9a5b8 (diff) | |
download | scrott-ed7b14b506094577a4b727f6f962777c245a3c64.tar.gz scrott-ed7b14b506094577a4b727f6f962777c245a3c64.zip |
Merge branch 'feature/heads' into dev
Diffstat (limited to '')
-rw-r--r-- | app/class/object.class.php | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/app/class/object.class.php b/app/class/object.class.php index 14ab891..7c80b5b 100644 --- a/app/class/object.class.php +++ b/app/class/object.class.php @@ -13,6 +13,7 @@ */ require_once "class/table.class.php"; +require_once "class/image.php"; /* * This is a generic database object. This is a supertype of all Scrott @@ -21,6 +22,17 @@ require_once "class/table.class.php"; class object extends table { /* + * Constants used for uploading images + */ + public const HEAD_MAXSIZE = 1048576; // 1Mb + public const BG_MAXSIZE = 1048576; // 1Mb + public const IMAGE_MIME = array( + "image/jpeg", + "image/jpg", + "image/png", + ); + + /* * Constructor */ public function __construct(?string $guid = NULL) @@ -149,6 +161,82 @@ class object extends table database::query($query); return true; } + + /* + * Get the URL to the head image resource for this object + */ + public function getHeadImg() : string + { + return ar() . "/df.php?d=heads&f=" . $this->guid; + } + + /* + * Set the head image for this object, overwriting any existing + * image. $image should be an uploaded file to PHP, still + * unhandled. + */ + public function setHeadImg(array $image) : bool + { + $path = "dynmic/heads/" . $this->guid; + + if (!saveFile($image, $path, self::HEAD_MAXSIZE, self::IMAGE_MIME)) + return false; + + if (!imageSquareCrop($path)) + { + $this->rmHeadImg(); + return false; + } + + return true; + } + + /* + * Remove the head image for this object. This deletes the image + * on disk. + */ + public function rmHeadImg() : bool + { + if (!is_file("dynmic/heads/" . $this->guid)) + return true; + + return unlink("dynmic/heads/" . $this->guid); + } + + /* + * Get the URL to the background image resource for this + * object. If no image is set, NULL is returned. + */ + public function getBgImg() : ?string + { + if (!is_file("dynmic/bgs/" . $this->guid)) + return NULL; + + return ar() . "/df.php?d=bgs&f=" . $this->guid; + } + + /* + * Set the background image for this object, overwriting any + * existing image. $image should be an uploaded file to PHP, + * still unhandled. + */ + public function setBgImg(array $image) : bool + { + $path = "dynmic/bgs/" . $this->guid; + return saveFile($image, $path, self::BG_MAXSIZE, self::IMAGE_MIME); + } + + /* + * Remove the background image for this object. This deletes + * the image on disk. + */ + public function rmBgImg() : bool + { + if (!is_file("dynmic/bgs/" . $this->guid)) + return true; + + return unlink("dynmic/bgs/" . $this->guid); + } } ?> |