From 7706c71f6d1d179a81a766e8c35482c85b73093e Mon Sep 17 00:00:00 2001 From: Niko Date: Fri, 11 Feb 2022 01:49:13 +0100 Subject: [PATCH] Added methods to retrieve Actor information (by ID, username) --- web/src/database.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/web/src/database.php b/web/src/database.php index 319ab9c..3a7ee1b 100644 --- a/web/src/database.php +++ b/web/src/database.php @@ -27,4 +27,27 @@ class DB { $cursor = $this->manager->executeQuery($this->db_name.'.'.$table, $query); return $cursor->toArray(); } + + + function getActorID($username) { + $domain = getenv('DOMAIN'); + if ($domain === false) + $domain = 'localhost'; + return 'https://'.$domain.'/u/'.$username; + } + + function getActorByUsername($username, $includeMeta = false) { + return $this->getActor($this->getActorID($username), $includeMeta); + } + + function getActor($id, $includeMeta = false) { + $actor = $this->findOne('objects', ['id' => $id]); + if ($actor === null) + return null; + if (!$includeMeta) + unset($actor->_meta); + if (!isset($actor->icon)) + $actor->icon = '/assets/images/default_profile.png'; + return $actor; + } }