diff options
Diffstat (limited to '')
-rw-r--r-- | app/class/object.class.php | 4 | ||||
-rw-r--r-- | app/class/table.class.php | 44 | ||||
-rw-r--r-- | app/class/user.class.php | 10 |
3 files changed, 27 insertions, 31 deletions
diff --git a/app/class/object.class.php b/app/class/object.class.php index 8ad17f5..6a77b37 100644 --- a/app/class/object.class.php +++ b/app/class/object.class.php @@ -76,8 +76,8 @@ class object extends table public function getMembers() : array { $memb = array(); - $query = "SELECT member FROM members WHERE guid = '" . $this->db->esc($this->guid) . "'"; - $res = $this->db->query($query); + $query = "SELECT member FROM members WHERE guid = '" . database::esc($this->guid) . "'"; + $res = database::query($query); foreach ($res as $m) $memb[] = new user($m['member']); diff --git a/app/class/table.class.php b/app/class/table.class.php index be7a375..0b9a53c 100644 --- a/app/class/table.class.php +++ b/app/class/table.class.php @@ -29,8 +29,6 @@ abstract class table */ protected $fields = array(); - protected $db; - /* * Instanciate an object representing an existing database entity * named by the given GUID. If no such GUID exists, an exception @@ -39,8 +37,6 @@ abstract class table */ public function __construct(?string $guid = NULL) { - $this->db = database::getInstance(); - if ($guid) $this->loadObj($guid); } @@ -52,16 +48,16 @@ abstract class table */ private function loadObj(string $guid) : void { - $guid = $this->db->esc($guid); + $guid = database::esc($guid); if (!$this->isGUID($guid)) throw new Exception("GUID " . $guid . " does not exist"); foreach ($this->fields as $tbl => $flds) { - $tbl = $this->db->esc($tbl); + $tbl = database::esc($tbl); $query = "SELECT * FROM " . $tbl . " WHERE guid = '" . $guid . "'"; - $res = $this->db->query($query)[0]; + $res = database::query($query)[0]; foreach ($flds as $fld) { @@ -85,7 +81,7 @@ abstract class table foreach ($this->fields as $tbl => $flds) { - $tbl = $this->db->esc($tbl); + $tbl = database::esc($tbl); $udstr = ""; foreach ($flds as $fld) @@ -93,15 +89,15 @@ abstract class table if (!isset($this->$fld)) continue; - $fld = $this->db->esc($fld); - $udstr .= $fld . " = '" . $this->db->esc($this->$fld) . "', "; + $fld = database::esc($fld); + $udstr .= $fld . " = '" . database::esc($this->$fld) . "', "; } if (strlen($udstr) > 0) { $udstr = substr($udstr, 0, -2); // remove ", " from the end - $query = "UPDATE " . $tbl . " SET " . $udstr . " WHERE guid = '" . $this->db->esc($this->guid) . "'"; - $this->db->query($query); + $query = "UPDATE " . $tbl . " SET " . $udstr . " WHERE guid = '" . database::esc($this->guid) . "'"; + database::query($query); } } } @@ -115,7 +111,7 @@ abstract class table foreach ($this->fields as $tbl => $flds) { - $tbl = $this->db->esc($tbl); + $tbl = database::esc($tbl); $fldstr = ""; $valstr = ""; @@ -124,9 +120,9 @@ abstract class table if (!isset($this->$fld)) continue; - $fld = $this->db->esc($fld); + $fld = database::esc($fld); $fldstr .= $fld . ", "; - $valstr .= "'" . $this->db->esc($this->$fld) . "', "; + $valstr .= "'" . database::esc($this->$fld) . "', "; } if (strlen($fldstr) > 0) @@ -134,7 +130,7 @@ abstract class table $fldstr = substr($fldstr, 0, -2); // remove ", " $valstr = substr($valstr, 0, -2); $query = "INSERT INTO " . $tbl . " (" . $fldstr . ") VALUES (" . $valstr . ")"; - $this->db->query($query); + database::query($query); } } } @@ -150,21 +146,21 @@ abstract class table if (!isset($this->guid)) throw new Exception("GUID (null) does not exist"); - $guid = $this->db->esc($this->guid); + $guid = database::esc($this->guid); foreach ($this->fields as $tbl => $flds) { - $tbl = $this->db->esc($tbl); + $tbl = database::esc($tbl); $query = "DELETE FROM " . $tbl . " WHERE guid = '" . $guid . "'"; - $this->db->query($query); + database::query($query); } /* garbage collection */ $query = "DELETE FROM members WHERE guid = '" . $guid . "' OR member = '" . $guid . "'"; - $this->db->query($query); + database::query($query); $query = "DELETE FROM views WHERE guid = '" . $guid . "' OR viewer = '" . $guid . "'"; - $this->db->query($query); + database::query($query); } /* @@ -181,7 +177,7 @@ abstract class table private function getCurrentTimestamp() : string { $query = "SELECT now() AS stamp"; - $res = $this->db->query($query); + $res = database::query($query); return $res[0]['stamp']; } @@ -190,9 +186,9 @@ abstract class table */ private function isGUID(string $guid) : bool { - $guid = $this->db->esc($guid); + $guid = database::esc($guid); $query = "SELECT guid FROM objects WHERE guid = '" . $guid . "'"; - $res = $this->db->query($query); + $res = database::query($query); return count($res) > 0; } diff --git a/app/class/user.class.php b/app/class/user.class.php index fc969fa..45fa5a5 100644 --- a/app/class/user.class.php +++ b/app/class/user.class.php @@ -47,10 +47,10 @@ class user extends agent */ public static function getGuidByUname(string $uname) : ?string { - $uname = $this->db->esc($uname); + $uname = database::esc($uname); $query = "SELECT guid FROM objects WHERE objtype = 'user' AND name = '" . $uname . "'"; - $res = $this->db->query($query); + $res = database::query($query); if (count($res) == 0) return NULL; @@ -77,7 +77,7 @@ class user extends agent public static function getAll_ordByUname() : array { $query = "SELECT guid FROM objects WHERE objtype = 'user' ORDER BY name"; - $res = $this->db->query($query); + $res = database::query($query); $users = array(); @@ -95,7 +95,7 @@ class user extends agent { $query = "SELECT o.guid FROM objects o JOIN users u ON o.guid = u.guid " . "WHERE o.objtype = 'user' ORDER BY u.admin DESC, o.name"; - $res = $this->db->query($query); + $res = database::query($query); $users = array(); @@ -112,7 +112,7 @@ class user extends agent { $query = "SELECT o.guid FROM objects o JOIN users u ON o.guid = u.guid " . "WHERE o.objtype = 'user' AND u.admin = 1 ORDER BY o.name"; - $res = $this->db->query($query); + $res = database::query($query); $users = array(); |