diff options
author | Mario <mario@mariovavti.com> | 2025-06-24 07:53:43 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2025-06-24 07:53:43 +0000 |
commit | 0e31d618680c4c5e65eb47e2beb6ac7e0c8896c6 (patch) | |
tree | d9457250c1373c583882436529091d86b2845bef /include | |
parent | 9a410f57e671cd5ae635afeebab9861d26fe00e4 (diff) | |
parent | 66e02c5e3a3c012787b37009b3aad2884d00941a (diff) | |
download | volse-hubzilla-0e31d618680c4c5e65eb47e2beb6ac7e0c8896c6.tar.gz volse-hubzilla-0e31d618680c4c5e65eb47e2beb6ac7e0c8896c6.tar.bz2 volse-hubzilla-0e31d618680c4c5e65eb47e2beb6ac7e0c8896c6.zip |
Merge branch 'some-account-cleanup' into 'dev'
A bit of cleanup for account functions
See merge request hubzilla/core!2210
Diffstat (limited to 'include')
-rw-r--r-- | include/account.php | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/include/account.php b/include/account.php index ad69b4d9a..e0b643d7b 100644 --- a/include/account.php +++ b/include/account.php @@ -17,10 +17,38 @@ require_once('include/crypto.php'); require_once('include/channel.php'); -function get_account_by_id($account_id) { - $r = q("select * from account where account_id = %d", - intval($account_id) - ); +/** + * Returns the id of a locally logged in account or false. + * + * Returns the numeric account id of the current session if authenticated, or + * false otherwise. + * + * @note It is possible to be authenticated, and not connected to a channel. + * + * @return int|false Numeric account id or false. + */ +function get_account_id(): int|false { + if (isset($_SESSION['account_id'])) { + return intval($_SESSION['account_id']); + } + + if (App::$account) { + return intval(App::$account['account_id']); + } + + return false; +} + +/** + * Get the account with the given id from the database. + * + * @param int $account_id The numeric id of the account to fetch. + * + * @return array|false An array containing the attributes of the requested + * account, or false if it could not be retreived. + */ +function get_account_by_id(int $account_id): array|false { + $r = q("select * from account where account_id = %d", $account_id); return (($r) ? $r[0] : false); } |