From a6a828521c61ebed3ec7038b2a53c002312a8bd0 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 19 Apr 2017 02:32:38 -0400 Subject: Add object function setHeadImg() --- app/class/object.class.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'app/class/object.class.php') diff --git a/app/class/object.class.php b/app/class/object.class.php index 14ab891..0dacd87 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 @@ -20,6 +21,16 @@ require_once "class/table.class.php"; */ class object extends table { + /* + * Constants used for uploading images + */ + public const HEAD_MAXSIZE = 1048576; // 1Mb + public const IMAGE_MIME = array( + "image/jpeg", + "image/jpg", + "image/png", + ); + /* * Constructor */ @@ -149,6 +160,27 @@ class object extends table database::query($query); return true; } + + /* + * 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; + } } ?> -- cgit v1.2.3 From ae94f42a59c1f308d973dc91214a63a1afb6cae3 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 19 Apr 2017 21:47:52 -0400 Subject: Add object function rmHeadImg() --- app/class/object.class.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'app/class/object.class.php') diff --git a/app/class/object.class.php b/app/class/object.class.php index 0dacd87..55d0874 100644 --- a/app/class/object.class.php +++ b/app/class/object.class.php @@ -181,6 +181,18 @@ class object extends table 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); + } } ?> -- cgit v1.2.3 From 77d16dcad807e80e439d636301ccf588195f53fc Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 19 Apr 2017 21:50:58 -0400 Subject: Add object function getHeadImg() --- app/class/object.class.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app/class/object.class.php') diff --git a/app/class/object.class.php b/app/class/object.class.php index 55d0874..8d889e7 100644 --- a/app/class/object.class.php +++ b/app/class/object.class.php @@ -161,6 +161,14 @@ class object extends table 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 -- cgit v1.2.3 From 3c4d7755d0a88c148884e0cbb90b327a96d87973 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 19 Apr 2017 22:45:18 -0400 Subject: Add object function setBgImg() --- app/class/object.class.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'app/class/object.class.php') diff --git a/app/class/object.class.php b/app/class/object.class.php index 8d889e7..f8f5460 100644 --- a/app/class/object.class.php +++ b/app/class/object.class.php @@ -25,6 +25,7 @@ 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", @@ -201,6 +202,17 @@ class object extends table return unlink("dynmic/heads/" . $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); + } } ?> -- cgit v1.2.3 From 07a1a1b7f207101ad27084ad37082f96afad8ac6 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 19 Apr 2017 22:47:00 -0400 Subject: Add object function rmBgImg() --- app/class/object.class.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'app/class/object.class.php') diff --git a/app/class/object.class.php b/app/class/object.class.php index f8f5460..3bf64ec 100644 --- a/app/class/object.class.php +++ b/app/class/object.class.php @@ -213,6 +213,18 @@ class object extends table $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); + } } ?> -- cgit v1.2.3 From 8256cbd7976d463ddfd31660995540a9c8adc315 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 19 Apr 2017 22:49:05 -0400 Subject: Add object function getBgImg() --- app/class/object.class.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'app/class/object.class.php') diff --git a/app/class/object.class.php b/app/class/object.class.php index 3bf64ec..7c80b5b 100644 --- a/app/class/object.class.php +++ b/app/class/object.class.php @@ -203,6 +203,18 @@ class object extends table 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, -- cgit v1.2.3