user_functions.php
Table of Contents
Functions
- validate_user() : bool|array<string|int, mixed>
- Validate user - check we have a valid user based on SQL criteria e.g. session that is passed in as $user_select_sql Will always return false if matches criteria but the user account is not approved or has expired
- setup_user() : bool
- Given an array of user data loaded from the user table, set up all necessary global variables for this user including permissions, current collection, config overrides and so on.
- get_users() : array<string|int, mixed>|object
- Returns a user list. Group or search term is optional. The standard user group names are translated using $lang. Custom user group names are i18n translated.
- get_users_with_permission() : array<string|int, mixed>
- Returns all the users who have the permission $permission.
- get_user_by_email() : array<string|int, mixed>
- Retrieve user records by e-mail address
- get_user_by_username() : mixed
- Retrieve user ID by username
- get_usergroups() : array<string|int, mixed>
- Returns a list of user groups. The standard user groups are translated using $lang. Custom user groups are i18n translated.
- get_usergroup() : mixed
- Returns the user group corresponding to the $ref. A standard user group name is translated using $lang. A custom user group name is i18n translated.
- get_user() : array<string|int, mixed>|bool
- Return the user group record matching $ref
- save_user() : bool|string
- Function used to update or delete a user.
- email_user_welcome() : void
- E-mail the user the welcome message on account creation.
- email_reset_link() : bool|string
- Email password reset link to the user
- auto_create_user_account() : bool
- Automatically creates a user account The request can be auto approved if $auto_approve_accounts is true Otherwise the approval is managed by admins via notification messages and/or emails
- email_user_request() : bool
- Send user request to admins in form of notification messages and/or emails Send email confirmation to requesting user
- user_limit_reached() : bool
- Check to see if the user limit has been reached.
- new_user() : bool|int
- Create a new user *
- get_active_users() : array<string|int, mixed>
- Returns a list of active users
- change_password() : mixed
- Sets a new password for the current user.
- make_password() : string
- Generate a password using the configured settings.
- bulk_mail() : string
- Send a bulk e-mail using the bulk e-mail tool.
- get_user_log() : array<string|int, mixed>
- Returns a user action log for $user.
- resolve_userlist_groups() : string
- Given an array or comma separated user list (from the user select include file) turn all Group: entries into fully resolved list of usernames.
- resolve_userlist_groups_smart() : string
- Given a comma separated user list (from the user select include file) turn all Group: entries into fully resolved list of usernames.
- remove_groups_smart_from_userlist() : string
- Remove smart lists from the provided user lists.
- check_password() : mixed
- Checks that a password conforms to the configured paramaters.
- resolve_users() : string
- For a given comma-separated list of user refs (e.g. returned from a group_concat()), return a string of matching usernames.
- check_access_key() : bool
- Verify a supplied external access key
- check_access_key_collection() : bool
- Check access key for a collection. For a featured collection category, the check will be done on all sub featured collections.
- make_username() : string
- Generates a unique username for the given name
- get_registration_selectable_usergroups() : array<string|int, mixed>
- Returns a list of user groups selectable in the registration . The standard user groups are translated using $lang. Custom user groups are i18n translated.
- open_access_to_user() : bool
- Give the user full access to the given resource. Used when approving requests.
- open_access_to_group() : bool
- Give the user full access to the given resource. Used when approving requests.
- resolve_open_access() : void
- Grants open access to the user list for the specified resource.
- remove_access_to_user() : bool
- Remove any user-specific access granted by an 'approve'. Used when declining requests.
- user_email_exists() : bool
- Returns true if a user account exists with e-mail address $email
- resolve_user_emails() : array<string|int, mixed>
- Return an array of emails from a list of usernames and email addresses.
- mark_email_as_invalid() : bool
- Finds all users with matching email and marks them as having an invalid email
- check_email_invalid() : bool
- Checks if the email entered is marked as invalid for any users
- create_password_reset_key() : string
- Creates a reset key for password reset e-mails
- get_rs_session_id() : mixed
- For anonymous access - a unique session key to identify the user (e.g. so they can still have their own collections)
- get_notification_users() : array<string|int, mixed>
- Returns an array of users (refs and emails) for use when sending email notifications (messages that in the past went to $email_notify, which can be emulated by using $email_notify_usergroups)
- verify_antispam() : bool
- Validates the user entered antispam code
- check_share_password() : bool
- Check that access for given external share key is correct
- offset_user_local_timezone() : string
- Offset a datetime to user local time zone
- checkPermission_anonymoususer() : bool
- Returns whether a user is anonymous or not
- checkPermission_dashadmin() : bool
- Does the current user have the ability to administer the dash (the tiles for all users)
- checkPermission_dashuser() : bool
- Can the user manage their own dash tiles.
- checkPermission_dashmanage() : bool
- Can the user manage their dash?
- checkPermission_dashcreate() : bool
- Can the user create tiles?
- checkperm() : bool
- Check that the user has the $perm permission
- checkperm_user_edit() : bool
- Check if the current user is allowed to edit user with passed reference
- checkperm_login_as_user() : bool
- Check if the current user has sufficient permissions to log in as the specified user
- internal_share_access() : bool
- Determine if this is an internal share access request
- save_usergroup() : mixed
- Save changes to a usergroup or create usergroup
- copy_usergroup_permissions() : mixed
- Copy the permissions string from another usergroup
- set_user_profile() : bool
- Set user's profile image and profile description (bio). Used by ../pages/user/user_profile_edit.php to setup user's profile.
- delete_profile_image() : void
- Delete a user's profile image. This will first remove the file and then update the db to clear the existing value.
- get_profile_image() : string
- Generate the url to the user's profile image. Fetch the url by the user's id or by the profile image filename.
- get_profile_text() : string
- Return user profile for a defined user.
- get_languages_notify_users() : array<string|int, mixed>
- load language files for all users that need to be notified into an array - use for message and email notification load in default language strings first and then overwrite with preferred language strings
- get_upload_url() : string
- Generate upload URL - alters based on $upload_then_edit setting and external uploads
- emulate_user() : void
- Used to emulate system users when accessing system anonymously or via external shares Sets global array such as $userpermissions, $username and sets any relevant config options
- is_authenticated() : mixed
- get_approver_usergroups() : array<string|int, mixed>
- Returns an array of the user groups the supplied user group acts as an approver for.
- get_usergroup_approvers() : array<string|int, mixed>
- Returns an array of user groups who act as user request approvers to the user group supplied.
- get_users_by_permission() : array<string|int, mixed>
- Retrieve all user records in groups with/without the specified permissions
- is_anonymous_user() : bool
- Determine whether user is anonymous user
- get_users_by_preference() : array<string|int, mixed>
- Retrieve all user records with the user preference specified
- get_default_notify_states() : array<string|int, mixed>
- Get the default notification workflow states for the current user. Used by setup_user() and get_user_actions() if no user preference has been set
- generate_temp_download_key() : string
- Generate a temporary download key for user. Used to enable temporary resource access to a file via download.php so that API can access resources after calling get_resource_path()
- validate_temp_download_key() : bool
- Validate the provided download key to authenticate a download or override an access check.
- setup_command_line_user() : bool
- Set up a dummy user with required permissions etc. to pass permission checks if running scripts from the command line
- update_user_access() : bool
- Update user table to record access by a user
- checkPermission_manage_users() : bool
- Check if the user can manage users.
- get_processing_message() : false|array<string|int, mixed>
- Get the processing status message for the current user.
- set_processing_message() : mixed
- can_set_admin_usergroup() : bool
- Consider if the current user is able to escalate the permissions of a user to the level of a "super admin".
- cors_is_origin_allowed() : bool
- Checks if the origin matches a whitelist entry, supporting wildcards like "*.example.com".
- delete_usergroup() : bool
- Delete a user group and associated records.
- browser_check() : mixed
- Check that this is a real browser by executing JS to set an expected cookie.
- xor_base64_encode() : string
- Obfuscates a string using a fixed XOR pattern and encodes it in Base64.
- load_site_text_for_usergroup() : void
- Load site text for a user group. To preserve the original state of global language values, this function will always revert previous changes first.
Functions
validate_user()
Validate user - check we have a valid user based on SQL criteria e.g. session that is passed in as $user_select_sql Will always return false if matches criteria but the user account is not approved or has expired
validate_user(object $user_select_sql[, bool $getuserdata = true ]) : bool|array<string|int, mixed>
$user_select_sql example u.session=$variable. Joins to usergroup table as g which can be used in criteria
Parameters
- $user_select_sql : object
-
PreparedStatementQuery instance - to validate user usually session hash or key
- $getuserdata : bool = true
-
default true. Return user data as required by authenticate.php
Return values
bool|array<string|int, mixed>setup_user()
Given an array of user data loaded from the user table, set up all necessary global variables for this user including permissions, current collection, config overrides and so on.
setup_user(array<string|int, mixed> $userdata) : bool
Parameters
- $userdata : array<string|int, mixed>
-
Array of user data obtained by validate_user() from user/usergroup tables
Return values
bool —success/failure flag - used for example to prevent certain users from making API calls
get_users()
Returns a user list. Group or search term is optional. The standard user group names are translated using $lang. Custom user group names are i18n translated.
get_users([int $group = 0 ][, string $find = "" ][, string $order_by = "u.username" ][, bool $usepermissions = false ][, int $fetchrows = -1 ][, string $approvalstate = "" ][, bool $returnsql = false ][, string $selectcolumns = "" ][, bool $exact_username_match = false ]) : array<string|int, mixed>|object
Parameters
- $group : int = 0
-
Can be a single group, or a comma separated list of groups used to limit the results If blank, zero or NULL then all users will be returned irrespective of their group
- $find : string = ""
-
Search string to filter returned results
- $order_by : string = "u.username"
- $usepermissions : bool = false
- $fetchrows : int = -1
- $approvalstate : string = ""
- $returnsql : bool = false
-
Return prepared statement object containing sql query and parameters.
- $selectcolumns : string = ""
- $exact_username_match : bool = false
-
Denotes $find must be an exact username
Return values
array<string|int, mixed>|object —Matching user records Returns an array of user information or prepared statement object containing sql query and parameters.
get_users_with_permission()
Returns all the users who have the permission $permission.
get_users_with_permission(string $permission) : array<string|int, mixed>
The standard user group names are translated using $lang. Custom user group names are i18n translated.
Parameters
- $permission : string
-
The permission code to search for
Return values
array<string|int, mixed> —Matching user records
get_user_by_email()
Retrieve user records by e-mail address
get_user_by_email(string $email) : array<string|int, mixed>
Parameters
- $email : string
-
The e-mail address to search for
Return values
array<string|int, mixed> —Matching user records
get_user_by_username()
Retrieve user ID by username
get_user_by_username(string $username) : mixed
Parameters
- $username : string
-
The username to search for (will match email if not found)
Return values
mixed —The matching user ID or false if not found
get_usergroups()
Returns a list of user groups. The standard user groups are translated using $lang. Custom user groups are i18n translated.
get_usergroups([bool $usepermissions = false ][, string $find = '' ][, bool $id_name_pair_array = false ]) : array<string|int, mixed>
Puts anything starting with 'General Staff Users' - in the English default names - at the top (e.g. General Staff).
Parameters
- $usepermissions : bool = false
-
Use permissions (user access)
- $find : string = ''
-
Search string
- $id_name_pair_array : bool = false
-
Return an array of ID->name instead of full records
Return values
array<string|int, mixed> —Matching user group records
get_usergroup()
Returns the user group corresponding to the $ref. A standard user group name is translated using $lang. A custom user group name is i18n translated.
get_usergroup(int $ref) : mixed
Parameters
- $ref : int
-
User group ID
Return values
mixed —False if not found, or the user group record if found.
get_user()
Return the user group record matching $ref
get_user(int $ref) : array<string|int, mixed>|bool
Parameters
- $ref : int
Return values
array<string|int, mixed>|boolsave_user()
Function used to update or delete a user.
save_user(string $ref[, array<string|int, mixed> $data = [] ]) : bool|string
Note: data is taken from the submitted form
Parameters
- $ref : string
-
ID of the user
- $data : array<string|int, mixed> = []
-
Data to save (optional, will use posted data otherwise)
Return values
bool|string —True if successful or a descriptive string if there's an issue
email_user_welcome()
E-mail the user the welcome message on account creation.
email_user_welcome(string $email, string $username, int $usergroup) : void
Parameters
- $email : string
- $username : string
- $usergroup : int
email_reset_link()
Email password reset link to the user
email_reset_link(string $email[, string $newuser = false ]) : bool|string
Parameters
- $email : string
-
Email address of user
- $newuser : string = false
-
Is this a new user account? If so a welcome message template will be used
Return values
bool|string —true if success or error message
auto_create_user_account()
Automatically creates a user account The request can be auto approved if $auto_approve_accounts is true Otherwise the approval is managed by admins via notification messages and/or emails
auto_create_user_account([string $hash = "" ]) : bool
Parameters
- $hash : string = ""
Return values
bool —Success?
email_user_request()
Send user request to admins in form of notification messages and/or emails Send email confirmation to requesting user
email_user_request() : bool
Return values
booluser_limit_reached()
Check to see if the user limit has been reached.
user_limit_reached() : bool
Return values
bool —- true if user limit has been reached or exceeded
new_user()
Create a new user *
new_user(string $newuser[, int $usergroup = 0 ]) : bool|int
Parameters
- $newuser : string
-
- username to create
- $usergroup : int = 0
-
- optional usergroup to assign
Return values
bool|int —- id of new user or false if user already exists / permission denied, or -2 if user limit reached
get_active_users()
Returns a list of active users
get_active_users() : array<string|int, mixed>
Return values
array<string|int, mixed>change_password()
Sets a new password for the current user.
change_password(string $password) : mixed
Parameters
- $password : string
Return values
mixed —True if a success or a descriptive string if there's an issue.
make_password()
Generate a password using the configured settings.
make_password() : string
Return values
string —The generated password
bulk_mail()
Send a bulk e-mail using the bulk e-mail tool.
bulk_mail(string $userlist, string $subject, string $text[, string $html = false ][, int $message_type = MESSAGE_ENUM_NOTIFICATION_TYPE_EMAIL ][, string $url = "" ]) : string
Parameters
- $userlist : string
- $subject : string
- $text : string
- $html : string = false
- $message_type : int = MESSAGE_ENUM_NOTIFICATION_TYPE_EMAIL
- $url : string = ""
Return values
string —The empty string if all OK, a descriptive string if there's an issue.
get_user_log()
Returns a user action log for $user.
get_user_log(int $user[, int $fetchrows = -1 ]) : array<string|int, mixed>
Standard field titles are translated using $lang. Custom field titles are i18n translated.
Parameters
- $user : int
- $fetchrows : int = -1
-
How many rows to fetch?
Return values
array<string|int, mixed>resolve_userlist_groups()
Given an array or comma separated user list (from the user select include file) turn all Group: entries into fully resolved list of usernames.
resolve_userlist_groups(string|array<string|int, mixed> $userlist) : string
Note that this function can't decode default groupnames containing special characters.
Parameters
- $userlist : string|array<string|int, mixed>
Return values
string —The resolved list
resolve_userlist_groups_smart()
Given a comma separated user list (from the user select include file) turn all Group: entries into fully resolved list of usernames.
resolve_userlist_groups_smart(string $userlist[, bool $return_usernames = false ]) : string
Note that this function can't decode default groupnames containing special characters.
Parameters
- $userlist : string
- $return_usernames : bool = false
Return values
string —The resolved list
remove_groups_smart_from_userlist()
Remove smart lists from the provided user lists.
remove_groups_smart_from_userlist(string|array<string|int, mixed> $ulist) : string
Parameters
- $ulist : string|array<string|int, mixed>
-
Comma separated list of user list names
Return values
string —The updated list with smart groups removed.
check_password()
Checks that a password conforms to the configured paramaters.
check_password(string $password) : mixed
Parameters
- $password : string
-
The password
Return values
mixed —True if OK, or a descriptive string if it isn't
resolve_users()
For a given comma-separated list of user refs (e.g. returned from a group_concat()), return a string of matching usernames.
resolve_users(string $users) : string
Parameters
- $users : string
-
User list - caution, used directly in SQL so must not contain user input
Return values
string —Matching usernames.
check_access_key()
Verify a supplied external access key
check_access_key(array<string|int, mixed>|int $resources, string $key[, bool $checkcollection = true ][, bool $is_category = false ]) : bool
Parameters
- $resources : array<string|int, mixed>|int
-
Resource ID | Array of resource IDs
- $key : string
-
The external access key
- $checkcollection : bool = true
-
Check collection access key? true by default but required to prevent infinite recursion
- $is_category : bool = false
-
True if checking featured collection category. Silently checks collection resources by preventing excessive updating of external_access_keys. Resource keys will update if collection viewed later.
Return values
bool —Valid?
check_access_key_collection()
Check access key for a collection. For a featured collection category, the check will be done on all sub featured collections.
check_access_key_collection(int $collection, string $key[, bool $checkresource = true ]) : bool
Parameters
- $collection : int
-
Collection ID
- $key : string
-
Access key
- $checkresource : bool = true
-
Check for resource access key? true by default but required to prevent infinite recursion
Return values
boolmake_username()
Generates a unique username for the given name
make_username(string $name[, string $email = "" ]) : string
Parameters
- $name : string
-
The user's full name
- $email : string = ""
-
Optional email address
Return values
string —The username to use
get_registration_selectable_usergroups()
Returns a list of user groups selectable in the registration . The standard user groups are translated using $lang. Custom user groups are i18n translated.
get_registration_selectable_usergroups() : array<string|int, mixed>
Return values
array<string|int, mixed>open_access_to_user()
Give the user full access to the given resource. Used when approving requests.
open_access_to_user(int $user, int $resource, string $expires) : bool
Parameters
- $user : int
- $resource : int
- $expires : string
Return values
boolopen_access_to_group()
Give the user full access to the given resource. Used when approving requests.
open_access_to_group(int $group, int $resource, string $expires) : bool
Parameters
- $group : int
- $resource : int
- $expires : string
Return values
boolresolve_open_access()
Grants open access to the user list for the specified resource.
resolve_open_access(string $userlist, int $resource, string $expires) : void
Parameters
- $userlist : string
- $resource : int
- $expires : string
remove_access_to_user()
Remove any user-specific access granted by an 'approve'. Used when declining requests.
remove_access_to_user(int $user, int $resource) : bool
Parameters
- $user : int
- $resource : int
Return values
booluser_email_exists()
Returns true if a user account exists with e-mail address $email
user_email_exists(string $email) : bool
Parameters
- $email : string
Return values
boolresolve_user_emails()
Return an array of emails from a list of usernames and email addresses.
resolve_user_emails(array<string|int, mixed> $user_list) : array<string|int, mixed>
with 'key_required' sibling array preserving the intent of internal/external sharing
Parameters
- $user_list : array<string|int, mixed>
Return values
array<string|int, mixed>mark_email_as_invalid()
Finds all users with matching email and marks them as having an invalid email
mark_email_as_invalid(string $email) : bool
Parameters
- $email : string
Return values
boolcheck_email_invalid()
Checks if the email entered is marked as invalid for any users
check_email_invalid(string $email) : bool
Parameters
- $email : string
Return values
bool —true if email is marked invalid for any users with matching email address
create_password_reset_key()
Creates a reset key for password reset e-mails
create_password_reset_key(string $username) : string
Parameters
- $username : string
-
The user's username
Return values
string —The reset key
get_rs_session_id()
For anonymous access - a unique session key to identify the user (e.g. so they can still have their own collections)
get_rs_session_id([bool $create = false ]) : mixed
Parameters
- $create : bool = false
-
Create one if it doesn't already exist
Return values
mixed —False on failure, the key on success
get_notification_users()
Returns an array of users (refs and emails) for use when sending email notifications (messages that in the past went to $email_notify, which can be emulated by using $email_notify_usergroups)
get_notification_users([string $userpermission = "SYSTEM_ADMIN" ][, int|null $usergroup = null ]) : array<string|int, mixed>
Can be passed a specific user type or an array of permissions Types supported:- SYSTEM_ADMIN RESOURCE_ACCESS RESEARCH_ADMIN USER_ADMIN RESOURCE_ADMIN
Parameters
- $userpermission : string = "SYSTEM_ADMIN"
-
Permission string
- $usergroup : int|null = null
-
Optional id of usergroup to find notification users for e.g. the parent group of new user or as defined in $usergroup_approval_mappings
Return values
array<string|int, mixed>verify_antispam()
Validates the user entered antispam code
verify_antispam([string $spamcode = "" ][, string $usercode = "" ][, string $spamtime = 0 ]) : bool
Parameters
- $spamcode : string = ""
-
The antispam hash to check against
- $usercode : string = ""
-
The antispam code the user entered
- $spamtime : string = 0
-
The antispam timestamp
Return values
bool —Return true if the code was successfully validated, otherwise false
check_share_password()
Check that access for given external share key is correct
check_share_password(array<string|int, mixed> $key, string $password, string $cookie) : bool
Parameters
- $key : array<string|int, mixed>
-
External access key
- $password : string
-
Share password to check
- $cookie : string
-
Share session cookie that has been set previously
Return values
booloffset_user_local_timezone()
Offset a datetime to user local time zone
offset_user_local_timezone(string $datetime, string $format) : string
IMPORTANT: the offset is fixed, there is no calculation for summertime!
Parameters
- $datetime : string
-
A date/time string. @see https://www.php.net/manual/en/datetime.formats.php
- $format : string
-
The format of the outputted date string. @see https://www.php.net/manual/en/function.date.php
Tags
Return values
string —The date in the specified format
checkPermission_anonymoususer()
Returns whether a user is anonymous or not
checkPermission_anonymoususer() : bool
Tags
Return values
boolcheckPermission_dashadmin()
Does the current user have the ability to administer the dash (the tiles for all users)
checkPermission_dashadmin() : bool
Return values
boolcheckPermission_dashuser()
Can the user manage their own dash tiles.
checkPermission_dashuser() : bool
Return values
boolcheckPermission_dashmanage()
Can the user manage their dash?
checkPermission_dashmanage() : bool
Logic: Home_dash is on, And not the Anonymous user with default dash, And (Dash tile user (Not with a managed dash) || Dash Tile Admin)
Return values
boolcheckPermission_dashcreate()
Can the user create tiles?
checkPermission_dashcreate() : bool
Logic: Home_dash is on, And not Anonymous use, And (Dash tile user (Not with a managed dash) || Dash Tile Admin)
Return values
boolcheckperm()
Check that the user has the $perm permission
checkperm(string $perm) : bool
Parameters
- $perm : string
Tags
Return values
bool —Do they have the permission?
checkperm_user_edit()
Check if the current user is allowed to edit user with passed reference
checkperm_user_edit(int $user) : bool
Parameters
- $user : int
-
The user to be edited
Return values
boolcheckperm_login_as_user()
Check if the current user has sufficient permissions to log in as the specified user
checkperm_login_as_user(mixed $user) : bool
The regex used is to check if the a permission is present in the permission string of the target user
Parameters
- $user : mixed
-
Either a user reference or user array
Return values
boolinternal_share_access()
Determine if this is an internal share access request
internal_share_access() : bool
Return values
boolsave_usergroup()
Save changes to a usergroup or create usergroup
save_usergroup(int $ref, array<string|int, mixed> $groupoptions) : mixed
Parameters
- $ref : int
-
Group ref. Set to 0 to create a new group
- $groupoptions : array<string|int, mixed>
-
array of options to set for group in the form array("columnname" => $value)
Return values
mixed —bool|int True to indicate existing group has been updated or ID of newly created group
copy_usergroup_permissions()
Copy the permissions string from another usergroup
copy_usergroup_permissions(int $src_id, int $dst_id) : mixed
Parameters
- $src_id : int
-
The group ID to copy from
- $dst_id : int
-
The group ID to copy to
Return values
mixed —bool|int True to indicate existing group has been updated or ID of newly created group
set_user_profile()
Set user's profile image and profile description (bio). Used by ../pages/user/user_profile_edit.php to setup user's profile.
set_user_profile(int $user_ref, string $profile_text, string $image_path) : bool
Parameters
- $user_ref : int
-
User id of user who's profile is being set.
- $profile_text : string
-
User entered profile description text (bio).
- $image_path : string
-
Path to temp file created if user chose to upload a profile image.
Return values
bool —If an error is encountered saving the profile image return will be false.
delete_profile_image()
Delete a user's profile image. This will first remove the file and then update the db to clear the existing value.
delete_profile_image(mixed $user_ref) : void
Parameters
- $user_ref : mixed
-
User id of the user who's profile image is to be deleted.
get_profile_image()
Generate the url to the user's profile image. Fetch the url by the user's id or by the profile image filename.
get_profile_image([int $user_ref = "" ][, string $by_image = "" ]) : string
Parameters
- $user_ref : int = ""
-
User id of the user who's profile image is requested.
- $by_image : string = ""
-
The filename of the profile image to fetch having been collected from the db separately: user.profile_image
Return values
string —The url to the user's profile image if available or blank if not set.
get_profile_text()
Return user profile for a defined user.
get_profile_text(int $user_ref) : string
Parameters
- $user_ref : int
-
User id to fetch profile details for.
Return values
string —Profile details for the requested user.
get_languages_notify_users()
load language files for all users that need to be notified into an array - use for message and email notification load in default language strings first and then overwrite with preferred language strings
get_languages_notify_users([array<string|int, mixed> $languages = array() ]) : array<string|int, mixed>
Parameters
- $languages : array<string|int, mixed> = array()
-
- array of language strings
Return values
array<string|int, mixed> —$language_strings_all
get_upload_url()
Generate upload URL - alters based on $upload_then_edit setting and external uploads
get_upload_url([string $collection = "" ][, mixed $k = "" ]) : string
Parameters
- $collection : string = ""
-
- optional collection
- $k : mixed = ""
Return values
stringemulate_user()
Used to emulate system users when accessing system anonymously or via external shares Sets global array such as $userpermissions, $username and sets any relevant config options
emulate_user(int $user[, int $usergroup = "" ]) : void
Parameters
- $user : int
-
User ID
- $usergroup : int = ""
-
usergroup ID
is_authenticated()
is_authenticated() : mixed
get_approver_usergroups()
Returns an array of the user groups the supplied user group acts as an approver for.
get_approver_usergroups([int $usergroup = "" ]) : array<string|int, mixed>
Uses config $usergroup_approval_mappings.
Parameters
- $usergroup : int = ""
-
Approving user group
Return values
array<string|int, mixed> —Array of subordinate user group ids.
get_usergroup_approvers()
Returns an array of user groups who act as user request approvers to the user group supplied.
get_usergroup_approvers([int $usergroup = "" ]) : array<string|int, mixed>
Uses config $usergroup_approval_mappings.
Parameters
- $usergroup : int = ""
-
Subordinate user group who's approval user group we need to find.
Return values
array<string|int, mixed> —Approval user group ids for supplied user group. Likely one value but its possible to have multiple approving groups.
get_users_by_permission()
Retrieve all user records in groups with/without the specified permissions
get_users_by_permission(array<string|int, mixed> $permissions) : array<string|int, mixed>
Parameters
- $permissions : array<string|int, mixed>
-
array of permission strings to check
Return values
array<string|int, mixed> —Matching user records (only returns a subset of columns)
Note that this can't use a straight FIND_IN_SET for permissions since that is case insensitive
is_anonymous_user()
Determine whether user is anonymous user
is_anonymous_user() : bool
Return values
boolget_users_by_preference()
Retrieve all user records with the user preference specified
get_users_by_preference(string $preference, string $value) : array<string|int, mixed>
Parameters
- $preference : string
-
Preference to check
- $value : string
-
Preference value to check for
Return values
array<string|int, mixed> —Array of user refs with the preference set as specified
get_default_notify_states()
Get the default notification workflow states for the current user. Used by setup_user() and get_user_actions() if no user preference has been set
get_default_notify_states() : array<string|int, mixed>
Return values
array<string|int, mixed> —Array of workflow state references
generate_temp_download_key()
Generate a temporary download key for user. Used to enable temporary resource access to a file via download.php so that API can access resources after calling get_resource_path()
generate_temp_download_key(int $user, int $resource, string $size) : string
Parameters
- $user : int
-
User ID
- $resource : int
-
Resource ID
- $size : string
-
Download size to access.
Return values
string —Access key - empty if not permitted
validate_temp_download_key()
Validate the provided download key to authenticate a download or override an access check.
validate_temp_download_key(int $ref, string $keystring, string $size[, int $expire_seconds = 0 ][, bool $setup_user = true ]) : bool
Parameters
- $ref : int
-
Resource ID
- $keystring : string
-
Key string - includes a nonce prefix
- $size : string
-
Download size to access.
- $expire_seconds : int = 0
-
Optional parameter to set specified expiry time in seconds. Use 0 to set system default.
- $setup_user : bool = true
-
Set to false where there is no need to initialise the user.
Return values
boolsetup_command_line_user()
Set up a dummy user with required permissions etc. to pass permission checks if running scripts from the command line
setup_command_line_user([array<string|int, mixed> $setoptions = [] ]) : bool
Parameters
- $setoptions : array<string|int, mixed> = []
Return values
boolupdate_user_access()
Update user table to record access by a user
update_user_access([int $user = 0 ][, array<string|int, mixed> $set_values = [] ]) : bool
Parameters
- $user : int = 0
-
User ID
- $set_values : array<string|int, mixed> = []
-
Optional array of column names and values to set
Return values
boolcheckPermission_manage_users()
Check if the user can manage users.
checkPermission_manage_users() : bool
Return values
boolget_processing_message()
Get the processing status message for the current user.
get_processing_message() : false|array<string|int, mixed>
Return values
false|array<string|int, mixed>set_processing_message()
set_processing_message(string $message) : mixed
Parameters
- $message : string
can_set_admin_usergroup()
Consider if the current user is able to escalate the permissions of a user to the level of a "super admin".
can_set_admin_usergroup(int $new_usergroup) : bool
Only users with "a" permission should be able to make other users super admins (user groups with "a" permission). Also used to determine if "super admin" level user groups should be displayed.
Parameters
- $new_usergroup : int
-
ID of user group to be set
Return values
boolcors_is_origin_allowed()
Checks if the origin matches a whitelist entry, supporting wildcards like "*.example.com".
cors_is_origin_allowed(string $origin, array<string|int, mixed> $whitelist) : bool
@param string $origin The URL to check.
Parameters
- $origin : string
- $whitelist : array<string|int, mixed>
-
Array of valid URLs - can include wildcards. @return bool True if the origin is allowed, false otherwise.
Return values
booldelete_usergroup()
Delete a user group and associated records.
delete_usergroup(int $usergroup_ref) : bool
Parameters
- $usergroup_ref : int
Return values
boolbrowser_check()
Check that this is a real browser by executing JS to set an expected cookie.
browser_check() : mixed
xor_base64_encode()
Obfuscates a string using a fixed XOR pattern and encodes it in Base64.
xor_base64_encode(string $str) : string
This function performs a basic transformation by XOR-ing each character of the input with a repeating fixed byte pattern, then encodes the result in Base64. Designed to be mirrored easily in JavaScript for lightweight bot detection.
Parameters
- $str : string
-
The input string to obfuscate.
Return values
string —The Base64-encoded, XOR-obfuscated string.
load_site_text_for_usergroup()
Load site text for a user group. To preserve the original state of global language values, this function will always revert previous changes first.
load_site_text_for_usergroup(int $group) : void
Parameters
- $group : int
-
$usergroup value. Normally int however maybe null for activity before login e.g. load user group site text for an activity by supplying a user group id and then return to the defaults by supplying null.