From c283905537ffb770c2b7e85529238cca9aa96869 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 7 Feb 2018 21:24:29 -0500 Subject: Rename object class Since 'object' is now a reserved word (as of PHP 7.2), I have to rename this class. I really preferred the name object, but obj will have to do. --- app/class/object.class.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/class/object.class.php b/app/class/object.class.php index c1ba85c..5be9ac3 100644 --- a/app/class/object.class.php +++ b/app/class/object.class.php @@ -19,7 +19,7 @@ require_once "class/image.php"; * This is a generic database object. This is a supertype of all Scrott * datatypes and defines fields common to all of them. */ -class object extends table +class obj extends table { /* * Constants used for uploading images @@ -66,7 +66,7 @@ class object extends table */ public static function typeOf(string $guid) : string { - $obj = new object($guid); + $obj = new obj($guid); return $obj->objtype; } @@ -125,19 +125,19 @@ class object extends table * Get the parent of this object. If this object does not have a * parent, NULL will be returned. */ - public function getParent() : ?object + public function getParent() : ?obj { if (!isset($this->parent) || $this->parent == "") return NULL; - $parent = new object($this->parent); + $parent = new obj($this->parent); return new $parent->objtype($parent->guid); } /* * Update the parent of this object */ - public function setParent(object $parent) : void + public function setParent(obj $parent) : void { $this->parent = $parent->guid; $this->saveObj(); -- cgit v1.2.3 From 977e4271c6f27ed2d42fab6bb2706f4a59bf0237 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 7 Feb 2018 21:28:08 -0500 Subject: Rename object.class.php to reflect name of its class --- app/class/obj.class.php | 286 +++++++++++++++++++++++++++++++++++++++++++++ app/class/object.class.php | 286 --------------------------------------------- 2 files changed, 286 insertions(+), 286 deletions(-) create mode 100644 app/class/obj.class.php delete mode 100644 app/class/object.class.php (limited to 'app') diff --git a/app/class/obj.class.php b/app/class/obj.class.php new file mode 100644 index 0000000..5be9ac3 --- /dev/null +++ b/app/class/obj.class.php @@ -0,0 +1,286 @@ +fields['objects'] = array( + "guid", + "owner", + "parent", + "name", + "created", + "updated", + + "membModify", + "membMemb", + "membAccs", + "membCres", + "membModifys", + "membMembs", + "pubAcc", + "pubAccs", + "pubCres", + + "objtype", + ); + + parent::__construct($guid); + } + + /* + * Get the object type for the given GUID + */ + public static function typeOf(string $guid) : string + { + $obj = new obj($guid); + return $obj->objtype; + } + + /* + * Remove duplicate elements from an array of Scrott objects. This + * function compares object GUIDs to check for uniqueness. Array + * keys are preserved. NULL elements are removed. Resulting array + * is returned. + */ + public static function arrayUnique(array $arr) : array + { + $guids = array(); + $ret = array(); + + foreach ($arr as $k => $v) + { + if ($v === NULL) + continue; + + if (in_array($v->guid, $guids)) + continue; + + $guids[] = $v->guid; + $ret[$k] = $v; + } + + return $ret; + } + + /* + * Get the owner of this object. Either a user object or a group + * object will be returned. If this object does not have an owner, + * NULL will be returned. + */ + public function getOwner() : ?agent + { + if (!isset($this->owner) || $this->owner == "") + return NULL; + + if (self::typeOf($this->owner) == "group") + return new group($this->owner); + + return new user($this->owner); + } + + /* + * Update the owner of this object + */ + public function setOwner(agent $owner) : void + { + $this->owner = $owner->guid; + $this->saveObj(); + } + + /* + * Get the parent of this object. If this object does not have a + * parent, NULL will be returned. + */ + public function getParent() : ?obj + { + if (!isset($this->parent) || $this->parent == "") + return NULL; + + $parent = new obj($this->parent); + return new $parent->objtype($parent->guid); + } + + /* + * Update the parent of this object + */ + public function setParent(obj $parent) : void + { + $this->parent = $parent->guid; + $this->saveObj(); + } + + /* + * Get an array of all members of this object + */ + public function getMembers() : array + { + $memb = array(); + $query = "SELECT member FROM members WHERE guid = '" . database::esc($this->guid) . "'"; + $res = database::query($query); + + foreach ($res as $m) + $memb[] = new user($m['member']); + + return $memb; + } + + /* + * Add a user as a member of this object. Returns false if user is + * already a member, or if another error occurs; true otherwise. + */ + public function addMember(user $user) : bool + { + if ($user->isMemberOf($this) || !isset($user->guid)) + return false; + + $query = "INSERT INTO members (guid, member) VALUES ('" . database::esc($this->guid) . "', '" . + database::esc($user->guid) . "')"; + database::query($query); + return true; + } + + /* + * Remove a user as a member of this object. Returns false if user + * is not a member, or if another error occurs; true otherwise. + */ + public function remMember(user $user) : bool + { + if (!$user->isMemberOf($this) || !isset($user->guid)) + return false; + + $query = "DELETE FROM members WHERE guid = '" . database::esc($this->guid) . "' AND " . + "member = '" . database::esc($user->guid) . "'"; + database::query($query); + return true; + } + + /* + * Get all messages on this object. Messages are sorted by date + * created. + */ + public function getMesgs_ordByDatetime() : array + { + $query = "SELECT guid FROM objects WHERE objtype = 'mesg' AND " . + "parent = '" . database::esc($this->guid) . "' ORDER BY created"; + $res = database::query($query); + + $mesgs = array(); + + foreach ($res as $m) + $mesgs[] = new mesg($m['guid']); + + return $mesgs; + } + + /* + * 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); + } +} + +?> diff --git a/app/class/object.class.php b/app/class/object.class.php deleted file mode 100644 index 5be9ac3..0000000 --- a/app/class/object.class.php +++ /dev/null @@ -1,286 +0,0 @@ -fields['objects'] = array( - "guid", - "owner", - "parent", - "name", - "created", - "updated", - - "membModify", - "membMemb", - "membAccs", - "membCres", - "membModifys", - "membMembs", - "pubAcc", - "pubAccs", - "pubCres", - - "objtype", - ); - - parent::__construct($guid); - } - - /* - * Get the object type for the given GUID - */ - public static function typeOf(string $guid) : string - { - $obj = new obj($guid); - return $obj->objtype; - } - - /* - * Remove duplicate elements from an array of Scrott objects. This - * function compares object GUIDs to check for uniqueness. Array - * keys are preserved. NULL elements are removed. Resulting array - * is returned. - */ - public static function arrayUnique(array $arr) : array - { - $guids = array(); - $ret = array(); - - foreach ($arr as $k => $v) - { - if ($v === NULL) - continue; - - if (in_array($v->guid, $guids)) - continue; - - $guids[] = $v->guid; - $ret[$k] = $v; - } - - return $ret; - } - - /* - * Get the owner of this object. Either a user object or a group - * object will be returned. If this object does not have an owner, - * NULL will be returned. - */ - public function getOwner() : ?agent - { - if (!isset($this->owner) || $this->owner == "") - return NULL; - - if (self::typeOf($this->owner) == "group") - return new group($this->owner); - - return new user($this->owner); - } - - /* - * Update the owner of this object - */ - public function setOwner(agent $owner) : void - { - $this->owner = $owner->guid; - $this->saveObj(); - } - - /* - * Get the parent of this object. If this object does not have a - * parent, NULL will be returned. - */ - public function getParent() : ?obj - { - if (!isset($this->parent) || $this->parent == "") - return NULL; - - $parent = new obj($this->parent); - return new $parent->objtype($parent->guid); - } - - /* - * Update the parent of this object - */ - public function setParent(obj $parent) : void - { - $this->parent = $parent->guid; - $this->saveObj(); - } - - /* - * Get an array of all members of this object - */ - public function getMembers() : array - { - $memb = array(); - $query = "SELECT member FROM members WHERE guid = '" . database::esc($this->guid) . "'"; - $res = database::query($query); - - foreach ($res as $m) - $memb[] = new user($m['member']); - - return $memb; - } - - /* - * Add a user as a member of this object. Returns false if user is - * already a member, or if another error occurs; true otherwise. - */ - public function addMember(user $user) : bool - { - if ($user->isMemberOf($this) || !isset($user->guid)) - return false; - - $query = "INSERT INTO members (guid, member) VALUES ('" . database::esc($this->guid) . "', '" . - database::esc($user->guid) . "')"; - database::query($query); - return true; - } - - /* - * Remove a user as a member of this object. Returns false if user - * is not a member, or if another error occurs; true otherwise. - */ - public function remMember(user $user) : bool - { - if (!$user->isMemberOf($this) || !isset($user->guid)) - return false; - - $query = "DELETE FROM members WHERE guid = '" . database::esc($this->guid) . "' AND " . - "member = '" . database::esc($user->guid) . "'"; - database::query($query); - return true; - } - - /* - * Get all messages on this object. Messages are sorted by date - * created. - */ - public function getMesgs_ordByDatetime() : array - { - $query = "SELECT guid FROM objects WHERE objtype = 'mesg' AND " . - "parent = '" . database::esc($this->guid) . "' ORDER BY created"; - $res = database::query($query); - - $mesgs = array(); - - foreach ($res as $m) - $mesgs[] = new mesg($m['guid']); - - return $mesgs; - } - - /* - * 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); - } -} - -?> -- cgit v1.2.3 From e54418762e279a1d7ca0efb7ed89b95464753ee8 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 7 Feb 2018 22:33:19 -0500 Subject: Update class files to use renamed obj class --- app/class/agent.class.php | 62 +++++++++++++++++++++++------------------------ app/class/issue.class.php | 4 +-- app/class/mesg.class.php | 10 ++++---- app/class/pad.class.php | 4 +-- app/class/stage.class.php | 6 ++--- 5 files changed, 43 insertions(+), 43 deletions(-) (limited to 'app') diff --git a/app/class/agent.class.php b/app/class/agent.class.php index ed50b93..6d0e20d 100644 --- a/app/class/agent.class.php +++ b/app/class/agent.class.php @@ -12,7 +12,7 @@ * For more information, please refer to UNLICENSE */ -require_once "class/object.class.php"; +require_once "class/obj.class.php"; require_once "class/pad.class.php"; require_once "class/settings.class.php"; require_once "class/phpmailer.class.php"; @@ -22,7 +22,7 @@ require_once "class/smtp.class.php"; * This is a supertype for users and groups, since these two object types * will often be handled polymorphically and will share some functionality. */ -abstract class agent extends object +abstract class agent extends obj { /* * Constructor @@ -35,7 +35,7 @@ abstract class agent extends object /* * Check whether this agent is the owner of the given object */ - public function isOwnerOf(object $obj) : bool + public function isOwnerOf(obj $obj) : bool { return $obj->getOwner()->guid == $this->guid; } @@ -43,7 +43,7 @@ abstract class agent extends object /* * Check whether this agent is a member of the given object */ - public function isMemberOf(object $obj) : bool + public function isMemberOf(obj $obj) : bool { foreach ($obj->getMembers() as $memb) { @@ -114,7 +114,7 @@ abstract class agent extends object * Check whether this agent has access permission for given * object */ - public function canAccess(object $obj) : bool + public function canAccess(obj $obj) : bool { if ($this->admin) return true; @@ -130,13 +130,13 @@ abstract class agent extends object if ($obj->parent) { - $parent = new object($obj->parent); + $parent = new obj($obj->parent); if ($this->canAccessSub($parent)) return true; } else if ($this->owner) { - $owner = new object($obj->owner); + $owner = new obj($obj->owner); if ($this->canAccessSub($owner)) return true; } @@ -148,7 +148,7 @@ abstract class agent extends object * Check whether this agent has modify permission for given * object */ - public function canModify(object $obj) : bool + public function canModify(obj $obj) : bool { if ($this->admin) return true; @@ -161,13 +161,13 @@ abstract class agent extends object if ($obj->parent) { - $parent = new object($obj->parent); + $parent = new obj($obj->parent); if ($this->canModifySub($parent)) return true; } else if ($obj->owner) { - $owner = new object($obj->owner); + $owner = new obj($obj->owner); if ($this->canModifySub($owner)) return true; } @@ -179,7 +179,7 @@ abstract class agent extends object * Check whether this agent has modify members permission for * given object */ - public function canModifyMembers(object $obj) : bool + public function canModifyMembers(obj $obj) : bool { if ($this->admin) return true; @@ -192,13 +192,13 @@ abstract class agent extends object if ($obj->parent) { - $parent = new object($obj->parent); + $parent = new obj($obj->parent); if ($this->canModifySubMembers($parent)) return true; } else if ($obj->owner) { - $owner = new object($obj->owner); + $owner = new obj($obj->owner); if ($this->canModifySubMembers($owner)) return true; } @@ -210,7 +210,7 @@ abstract class agent extends object * Check whether this agent has modify permissions permission * for given object */ - public function canModifyPermissions(object $obj) : bool + public function canModifyPermissions(obj $obj) : bool { if ($this->admin) return true; @@ -220,13 +220,13 @@ abstract class agent extends object if ($obj->parent) { - $parent = new object($obj->parent); + $parent = new obj($obj->parent); if ($this->canModifySubPermissions($parent)) return true; } else if ($obj->owner) { - $owner = new object($obj->owner); + $owner = new obj($obj->owner); if ($this->canModifySubPermissions($owner)) return true; } @@ -238,7 +238,7 @@ abstract class agent extends object * Check whether this agent has access-sub permission for * given object */ - public function canAccessSub(object $obj) : bool + public function canAccessSub(obj $obj) : bool { if ($this->admin) return true; @@ -254,13 +254,13 @@ abstract class agent extends object if ($obj->parent) { - $parent = new object($obj->parent); + $parent = new obj($obj->parent); if ($this->canAccessSub($parent)) return true; } else if ($obj->owner) { - $owner = new object($obj->owner); + $owner = new obj($obj->owner); if ($this->canAccessSub($owner)) return true; } @@ -272,7 +272,7 @@ abstract class agent extends object * Check whether this agent has create-sub permission * for given object */ - public function canCreateSub(object $obj) : bool + public function canCreateSub(obj $obj) : bool { if ($this->admin) return true; @@ -288,13 +288,13 @@ abstract class agent extends object if ($obj->parent) { - $parent = new object($obj->parent); + $parent = new obj($obj->parent); if ($this->canCreateSub($parent)) return true; } else if ($obj->owner) { - $owner = new object($obj->owner); + $owner = new obj($obj->owner); if ($this->canCreateSub($owner)) return true; } @@ -306,7 +306,7 @@ abstract class agent extends object * Check whether this agent has modify-sub permission * for given object */ - public function canModifySub(object $obj) : bool + public function canModifySub(obj $obj) : bool { if ($this->admin) return true; @@ -319,13 +319,13 @@ abstract class agent extends object if ($obj->parent) { - $parent = new object($obj->parent); + $parent = new obj($obj->parent); if ($this->canModifySub($parent)) return true; } else if ($obj->owner) { - $owner = new object($obj->owner); + $owner = new obj($obj->owner); if ($this->canModifySub($owner)) return true; } @@ -337,7 +337,7 @@ abstract class agent extends object * Check whether this agent has modify-sub-members * permission for given object */ - public function canModifySubMembers(object $obj) : bool + public function canModifySubMembers(obj $obj) : bool { if ($this->admin) return true; @@ -350,13 +350,13 @@ abstract class agent extends object if ($obj->parent) { - $parent = new object($obj->parent); + $parent = new obj($obj->parent); if ($this->canModifySubMembers($parent)) return true; } else if ($obj->owner) { - $owner = new object($obj->owner); + $owner = new obj($obj->owner); if ($this->canModifySubMembers($owner)) return true; } @@ -368,7 +368,7 @@ abstract class agent extends object * Check whether this agent has modify-sub-permissions * permission for given object */ - public function canModifySubPermissions(object $obj) : bool + public function canModifySubPermissions(obj $obj) : bool { if ($this->admin) return true; @@ -378,13 +378,13 @@ abstract class agent extends object if ($obj->parent) { - $parent = new object($obj->parent); + $parent = new obj($obj->parent); if ($this->canModifySubPermissions($parent)) return true; } else if ($obj->owner) { - $owner = new object($obj->owner); + $owner = new obj($obj->owner); if ($this->canModifySubPermissions($owner)) return true; } diff --git a/app/class/issue.class.php b/app/class/issue.class.php index b61a6e3..1c77894 100644 --- a/app/class/issue.class.php +++ b/app/class/issue.class.php @@ -12,7 +12,7 @@ * For more information, please refer to UNLICENSE */ -require_once "class/object.class.php"; +require_once "class/obj.class.php"; require_once "class/stage.class.php"; require_once "class/user.class.php"; require_once "class/mesg.class.php"; @@ -21,7 +21,7 @@ require_once "class/mesg.class.php"; * This class models Scrott issues. Issues represent units of work, can * be assigned to users, and advance through a pipeline. */ -class issue extends object +class issue extends obj { /* * Constructor diff --git a/app/class/mesg.class.php b/app/class/mesg.class.php index 2512d03..1a864c0 100644 --- a/app/class/mesg.class.php +++ b/app/class/mesg.class.php @@ -12,7 +12,7 @@ * For more information, please refer to UNLICENSE */ -require_once "class/object.class.php"; +require_once "class/obj.class.php"; require_once "class/user.class.php"; require_once "class/pad.class.php"; require_once "class/stage.class.php"; @@ -22,7 +22,7 @@ require_once "class/issue.class.php"; * This class models issue activity, private messaging, pad discussions, * and system and object log messages. */ -class mesg extends object +class mesg extends obj { /* * Constants used for uploading attachments @@ -56,7 +56,7 @@ class mesg extends object /* * Initialize a new regular message. */ - public static function initNew(string $message, user $author, object $parent) : mesg + public static function initNew(string $message, user $author, obj $parent) : mesg { $mesg = new mesg(); $mesg->setOwner($author); @@ -106,7 +106,7 @@ class mesg extends object /* * Initialize a new log message. */ - public static function initNewLog(string $message, user $author, object $parent) : mesg + public static function initNewLog(string $message, user $author, obj $parent) : mesg { $owner = $parent->getOwner(); @@ -321,7 +321,7 @@ class mesg extends object break; } - $rcpt = object::arrayUnique($rcpt); + $rcpt = obj::arrayUnique($rcpt); $author = $this->author; $rcpt = array_filter($rcpt, function ($val) use($author) { return $val->guid != $author; }); $attachPath = ($this->getAttachment() ? "dynmic/attach/" . $this->guid : NULL); diff --git a/app/class/pad.class.php b/app/class/pad.class.php index 3966f58..38812d6 100644 --- a/app/class/pad.class.php +++ b/app/class/pad.class.php @@ -12,7 +12,7 @@ * For more information, please refer to UNLICENSE */ -require_once "class/object.class.php"; +require_once "class/obj.class.php"; require_once "class/agent.class.php"; require_once "class/stage.class.php"; @@ -20,7 +20,7 @@ require_once "class/stage.class.php"; * This class models Scrott pads. Pads are the space for projects to track * issues and communicate. */ -class pad extends object +class pad extends obj { /* * Constructor diff --git a/app/class/stage.class.php b/app/class/stage.class.php index 74c5f42..43bb3c3 100644 --- a/app/class/stage.class.php +++ b/app/class/stage.class.php @@ -12,7 +12,7 @@ * For more information, please refer to UNLICENSE */ -require_once "class/object.class.php"; +require_once "class/obj.class.php"; require_once "class/pad.class.php"; require_once "class/issue.class.php"; @@ -20,7 +20,7 @@ require_once "class/issue.class.php"; * This class models Scrott pad stages. Stages form a pipeline through * which issues can progress. */ -class stage extends object +class stage extends obj { /* * Constructor @@ -173,7 +173,7 @@ class stage extends object * moved to the given stage object. Additionally, the pad may be * given, in which case, those issues will be closed. */ - public function removeStage(object $mvt) : void + public function removeStage(obj $mvt) : void { if (!($prev = $this->getPrev())) $prev = $this->getParent(); -- cgit v1.2.3 From 0bae6d4063c82c6522e3a5887bc25a2162504b69 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 7 Feb 2018 22:37:26 -0500 Subject: Update df script to use renamed obj class --- app/df.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/df.php b/app/df.php index 3f648ad..6c23136 100644 --- a/app/df.php +++ b/app/df.php @@ -61,7 +61,7 @@ function checkPermissions(string $guid, bool $allowHeadUser = false) : bool if (!($user = user::getCurrent())) return false; - $obj = new object($guid); + $obj = new obj($guid); if ($allowHeadUser && $obj->objtype == "user") return true; -- cgit v1.2.3