diff options
author | Malf Furious <m@lfurio.us> | 2017-01-17 03:56:28 -0500 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2017-01-17 03:56:28 -0500 |
commit | 66cf5c4d36ed6020c6ee6b7ca99aecd5a8f3bcf4 (patch) | |
tree | 643bd98dc2608e65e06154029acdad54ccbbf5ad /app | |
parent | ea0b5e57956985b360afae948553aaad5cbb75d7 (diff) | |
download | scrott-66cf5c4d36ed6020c6ee6b7ca99aecd5a8f3bcf4.tar.gz scrott-66cf5c4d36ed6020c6ee6b7ca99aecd5a8f3bcf4.zip |
Add helper functions to table class
Diffstat (limited to '')
-rw-r--r-- | app/class/table.class.php | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/app/class/table.class.php b/app/class/table.class.php index 62f95d3..0edff9d 100644 --- a/app/class/table.class.php +++ b/app/class/table.class.php @@ -168,6 +168,45 @@ abstract class table $query = "DELETE FROM views WHERE guid = '" . $guid . "' OR viewer = '" . $guid . "'"; $this->db->query($query); } + + /* + * Get a random sha256 blob, returned as a hexadecimal string + */ + public function getBlob() : string + { + return hash("sha256", openssl_random_pseudo_bytes(64)); + } + + /* + * Get current timestamp as a string for object database purposes + */ + private function getCurrentTimestamp() : string + { + $query = "SELECT now() AS stamp"; + $res = $this->db->query($query); + return $res[0]['stamp']; + } + + /* + * Check whether the given GUID exists + */ + private function isGUID(string $guid) : bool + { + $guid = $this->db->esc($guid); + $query = "SELECT guid FROM objects WHERE guid = '" . $guid . "'"; + $res = $this->db->query($query); + return count($res) > 0; + } + + /* + * Get a new, unique GUID for a new system object + */ + private function getNewGUID() : string + { + do $guid = substr($this->getBlob(), 0, 8); + while ($this->isGUID($guid)); + return $guid; + } } ?> |