Framework functions
BPFW includes a lot of utility functions for different usages. Some are used by the core framework and some were just useful over the last years.
You can find them in /bpfw/core/functions/*.inc.php in files sorted by functionality.
The most essential functions are:
commonFunctions.inc.php and other core files
bpfw_is_windows
/**
* @return bool is on windows?
*/
function bpfw_is_windows(): bool
{
getorpost
checks if the key exists in GET or POST and returns it. returns null otherwise.
/**
* @param $name string key to search in get or post
* @return mixed|null value or null
*/
function getorpost($name)
{
if (isset($_POST[$name])) return $_POST[$name];
if (isset($_GET[$name])) return $_GET[$name];
return null;
}
isJson
checks if a string (a response for example) can be converted to json
/**
* @param $string mixed json string (or not)
* @return bool string is a json string
*/
function isJson(mixed $string): bool
bpfw_createModelByName
checks if a string (a response for example) can be converted to json
/**
* Create a model by name. Looks for modelfiles, includes them and returns an object. respects the hierarchy (look at app first, then parent, then bpfs core)
* @param string $name name of the model
* @param bool $cache enable caching
* @param bool $throwExceptionOnNotExisting
* @return ?BpfwModel model or null
* @throws Exception
*/
function bpfw_createModelByName(string $name, bool $cache = false, bool $throwExceptionOnNotExisting = true): ?BpfwModel
{
bpfw_modelExists
check if the model exists
/**
* check if the model exists
* @param $name string name name of the model
* @throws Exception
*/
function bpfw_modelExists(string $name): bool
{
bpfw_getModelValues
get model values as array from modelname and keyvalue
/**
* @throws Exception
* @noinspection PhpUnused
*/
function bpfw_getModelValues($name, $keyValue): ?array
{
bpfw_add_action
add an action. An action is a callback function that is called when the corresponding do_action is called
(there are predefined actions, for a list see the corresponding documentation page)
/**
* register a new Action (BEFORE do_action is called)
* add an action. An action is a callback function that is called when the corresponding do_action is called
* @param string $tag
* @param string|null $contextName
* @param callable $function_to_add
* @param int $priority
* @param int $accepted_args
*/
function bpfw_add_action(string $tag, string|null $contextName, callable $function_to_add, int $priority = 10, int $accepted_args = 0): void
{
bpfw_do_action
execute previously registered Actions
(there are predefined actions, for a list see the corresponding documentation page)
/**
* execute previously registered Actions
* @param string $tag
* @param string|null $contextName
* @param array $params
* @param object|null $contextClass
* @return mixed
* @throws Exception
*/
function bpfw_do_action(string $tag, string|null $contextName, array $params = array(), object|null $contextClass = null): mixed
{
bpfw_add_filter
A filter is a special form of action. the first parameter is returned from the callback and can be manipulated that way. besides from that it behaves like an action.
(there are predefined filters, for a list see the corresponding documentation page)
/**
* register a new Filter (BEFORE do_action is called)
* A filter is a special form of action. the first parameter is returned and can be manipulated. besides from that it behaves like an action.
* @param string $tag
* @param string|null $contextname
* @param callable $function_to_add
* @param int $priority
* @param int $accepted_args
* @throws Exception
*/
function bpfw_add_filter(string $tag, string|null $contextname, callable $function_to_add, int $priority = 10, int $accepted_args = 1): void
{
bpfw_do_filter
execute previously registered Filter
(there are predefined filters, for a list see the corresponding documentation page)
/**
* execute previously registered Filter
* @param string $tag
* @param string|null $contextName
* @param array $params
* @param object|null $contextClass // only execute callbacks from this class
* @return false|mixed
* @throws Exception
*/
function bpfw_do_filter(string $tag, string|null $contextName, array $params = array(), object|null $contextClass = null): mixed
{
Actions/Callbacks in Javascript: registerBpfwEvent, handleBpfwEvent
You can also do callback actions in javascript:
(there are predefined events, for a list see the corresponding documentation page)
register:
registerBpfwEvent("someAction", function (params) {});
call:
handleBpfwEvent("someAction", {value:123});
Functions in arrayFunctions.inc.php
bpfw_compare_arrayvalues
Compare arrayvalues of two arrays. Returns true on an exact match.
/** * true if array values are identical * @param mixed $array1 * @param mixed $array2 * @return bool */ function bpfw_compare_arrayvalues(mixed $array1, mixed $array2): bool
Functions in bpfwcoreFunctions.inc.php
bpfw_isEditAction, bpfw_isDuplicateAction, bpfw_isEditOrDuplicateAction, bpfw_isAddAction, bpfw_isDeleteAction
checks if the current call is a call to edit/delete/add/duplicate something.
function bpfw_isDeleteAction(): bool
{
return isset($_GET['delete']) && is_numeric($_GET['delete']);
}
function bpfw_isAddAction(): bool
{
return isset($_GET['addAction']) && is_numeric($_GET['addAction']) || isset($_GET['openadd']) || isset($_GET['openAdd']);
}
function bpfw_isEditOrDuplicateAction(): bool
{
return bpfw_isEditAction() || bpfw_isDuplicateAction();
}
function bpfw_isEditAction(): bool
{
return isset($_GET['editAction']) && is_numeric($_GET['editAction']) || isset($_GET['edit']) && is_numeric($_GET['edit']);
}
function bpfw_isDuplicateAction(): bool
{
return isset($_GET['editAction']) && is_numeric($_GET['editAction']) || isset($_GET['duplicate']) && is_numeric($_GET['duplicate']);
}
bpfw_get_unsubscribe_link
get the link to unsubscribe a user from the newsletter.
/**
* @param $type string user or customer
* @param $id int user or customerid
* @return string the url the user has to click
*/
function bpfw_get_unsubscribe_link(string $type, int $id): string
bpfw_countEditableFields
Count how many form elements are editable. Used to disable some functionality if not necessary.
/**
* @param $data_header BpfwModelFormfield[] fieldheader you can get with (model)->getDbModel()
* @return int editable fields in model
* @throws Exception
*/
function bpfw_countEditableFields(array $data_header): int
bpfw_isAjax
Is the current call an ajax call?
/**
* is the current page that is loading an ajax call
*
* @return bool
*/
function bpfw_isAjax(): bool
bpfw_setVariables
Add values of a dbmodel entry to the $variables array.
/**
* set values in variable array with assigned prefix. used a lot for pdf generation
* @param DbModelEntry|null $dbModelEntry kvp array value
* @param string $prefix variable is saved as prefix.value example: user.name
* @param array $variables array with previous set variables
* @return array
* @throws Exception
*/
function bpfw_setVariables(?DbModelEntry $dbModelEntry, string $prefix, array $variables): array
bpfw_setMetadata, bpfw_getMetadata
quick way to save and load some properties for a model outside of the default schema.
Those are stored in the database, so you can access them anytime
bpfw_setMetadata("user", 123, array("hello"=>"world"));
// anytime and anywhere:
$array = bpfw_getMetadata("user", 123);
/**
* Sets Metadata for type/id pair. For Exampe "User" 23.
* @param mixed $type string as type ("user", "order" ... )
* @param mixed $id id - typically the PK of the table
* @param array|string $json_data json or array of additional metadata
* @param mixed|bool $updateExisting update/overwrite data if existing in database
* @return int metadataId of new or existing entry
* @throws Exception
*/
function bpfw_setMetadata(mixed $type, mixed $id, array|string $json_data, bool $updateExisting = true): int
---
/**
* Get Metadata by modelname/id
* @param mixed $type string as type ("user", "order" ...
* @param mixed $id id - typically the PK of the table
* @return null|array if existing returns array with values (metadataId, type, id, json_data) NULL otherwise
* @throws Exception
*/
function bpfw_getMetadata(mixed $type, mixed $id): ?array
{
return bpfw_createModelByName("metadata")->getMetadata($type, $id);
}
bpfw_getActiveApp
get the slug of the active app
/**
* return slug of active app
* @return string
*/
function bpfw_getActiveApp() : string
bpfw_addSpoilerHint
Adds a spoiler info icon to a text. That’s a ? that gives you some information about the functionality etc. when hovered over with the mouse or clicked
/**
* add Spoiler hint to text
* @param array|string $label
* @param string $spoilertext
* @return array|string
*/
function bpfw_addSpoilerHint(array|string $label, string $spoilertext): array|string
Functions of datetimeFunctions.inc.php
bpfw_TimestampTodatestring
Convert unix timestamp to given format. If no format is set, global format is used. If timestamp is “NOW()”, it will return “NOW()”
/**
* @param mixed $timestamp
* @param string $format
* @return string
*/
function bpfw_TimestampTodatestring(mixed $timestamp, string $format = "default"): string
bpfw_TimestampToDateTimeString
Convert unix timestamp to date in given format. If no format is set, global format is used. If timestamp is “NOW()”, it will return “NOW()”
**
*
* @param $timestamp2 mixed unix timestamp or NOW() or empty
* @param $format string format to convert the datetime
* @param $allowEmptyTime boolean if timestamp is empty return "". throw exception otherwise
* @return string formatted date
* @throws Exception
*/
function bpfw_TimestampToDateTimeString(mixed $timestamp2, string $format = "d.m.Y H:i:s", $allowEmptyTime = false): string
{
if (!$allowEmptyTime && empty($timestamp2)) {
return "";
}
if (!is_numeric($timestamp2) && $timestamp2 != "NOW()") {
throw new Exception("invalid timestamp (not numeric) in bpfw_TimestampToDateTimeString: '$timestamp2'");
}
$timestamp = $timestamp2;
if ($timestamp2 == "NOW()") {
$timestamp = time();
}
if (is_string($timestamp2)) {
$timestamp = intval(trim($timestamp));
}
if ($timestamp2 == 0) {
$timestamp = 0;
}
return date($format, $timestamp);
}
bpfw_set_defaultdateformat, bpfw_get_defaultDateFormat
get and set the default date format
/**
* set the default date format used in the system
* @param string $format format as used in php date function
* @return void
*/
function bpfw_set_defaultdateformat(string $format = "d.m.Y"): void
/**
* @return string default format for BPFW - as used in php date function
*/
function bpfw_get_defaultDateFormat(): string
bpfw_DateStringToDateTime
gets a datestring and returns a DateTime object
/**
* gets a datestring and returns a DateTime object
* @param string|DbSubmitValue|null $dateString
* @return DateTime
* @throws Exception
*/
function bpfw_DateStringToDateTime(string|DbSubmitValue|null $dateString): DateTime
{
bpfw_mysqlDateStringToFormat
convert a mysql datestring
/**
* @param string|DbSubmitValue $dateString mysql date (format Y-m-d H:i:s or Y-m-d H:i:s h:i:s)
* @param string $newFormat format as in php date()
* @param bool $replacePlaceholders replace NOW() or keep it?
* @return string
* @throws Exception
*/
function bpfw_mysqlDateStringToFormat(string|DbSubmitValue $dateString, string $newFormat = "d.m.Y", bool $replacePlaceholders = true): string
bpfw_current_mysql_datetimestring
Get current date as mysql format (Y-m-d H:i:s)
/**
* Get current date as mysql format (Y-m-d H:i:s)
* @return string current date as mysql format
*/
function bpfw_current_mysql_datetimestring(): string
bpfw_DateStringToMysqlDateString
/**
* d.m.y/d.m.Y to Y-m-d
* @param ?string $dateString
* @return string
*/
function bpfw_DateStringToMysqlDateString(?string $dateString): string
convert d.m.y or d.m.Y format to mysql datestring
bpfw_isWeekend
/**
* @param mixed $timestampOrString timestamp or time string
* @return bool is weekend?
* @throws Exception
*/
function bpfw_isWeekend(mixed $timestampOrString): bool
is current timestamp or datestring a weekend?
bpfw_emptydate
check if date is empty. also checks for empty strings like 0000-00-00
/**
* check if date is empty. also checks for empty strings like 0000-00-00
* @param $date mixed
* @return bool
*/
function bpfw_emptydate(mixed $date): bool
{
if (empty($date)) return true;
if ($date == "0000-00-00") return true;
if ($date == "1970-01-01") return true;
if ($date == "0000-00-00 00:00:00") return true;
if ($date == "1970-01-01 00:00:00") return true;
return false;
}
Functions in debugFunctions.inc.php
bpfw_logDataEntry
Log data in datalog table (can be viewed as an admin in datalog “?p=datalog”)
/**
* Log data in datalog table (can be viewed as an admin in datalog "?p=datalog")
* @param string $modelName
* @param mixed $key
* @param string $logType
* @param string $metadata
* @throws Exception
*/
function bpfw_logDataEntry(string $modelName, mixed $key, string $logType, string $metadata = "{{{readEntries}}}"): void
bpfw_is_debug_sql
check if sql debug is active
/**
* @return bool debug sql active?
*/
function bpfw_is_debug_sql(): bool
bpfw_isLocalTestserver
/**
* check if server is running locally, so we can disable or change some functionality
* @return bool Server is local
*/
function bpfw_isLocalTestserver(): bool
{
check if server is running locally, so we can disable or change some functionality
bpfw_debug_string_backtrace
return a string with the current stacktrace inside
/**
* @return string return a string with the current stacktrace inside
*/
function bpfw_debug_string_backtrace(): string
Functions in fileFunctions.inc.php
bpfw_handleFileUpload
copy a file to the correct directory and return the data to be saved
/**
* copy a file to the correct directory and return the data to be saved
* @param $subdirectory string subdir in uploads folder
* @param $key mixed key of the file.
* @param $fileData array filedata as array as in php $_FILE (name, size, type, tmp_name, error)
* @return bool|string
*/
function bpfw_handleFileUpload(string $subdirectory, mixed $key, array $fileData): bool|string
{
bpfw_copy_dir_as_zip
copy a folder to a zip file
/**
* copy a folder to a zip file
* @param $source string path to folder
* @param $dest string path to zipfile to be created
* @return void
*/
function bpfw_copy_dir_as_zip(string $source, string $dest): void
{
bpfw_copy_dir
Copy a file, or recursively copy a folder and its contents
/**
* Copy a file, or recursively copy a folder and its contents
*
* @param string $source Source path
* @param string $dest Destination path
* @return bool Returns TRUE on success, FALSE on failure
*/
function bpfw_copy_dir(string $source, string $dest): bool
bpfw_foldersize
get the size of a directory (includes all subdirectories)
/**
* get the size of a directory (includes all subdirectories)
* @param $path string path to folder
* @return int size in byte
*/
function bpfw_foldersize($path): int
bpfw_fileCount
count the number of files in a directory
/**
* count the number of files in a directory
* @param $path string path to directory
* @return int files found
*/
function bpfw_fileCount(string $path): int
{
bpfw_format_size
formats a byte number to a more readable format string(22 KB, 33 MB etc.)
/**
* formats a byte number to a more readable format string(22 KB, 33 MB etc.)
* @param $size int size in byte
* @return string formatted size
*/
function bpfw_format_size(int $size): string
bpfw_delete_dir
delete directory with its subdirectories
/**
* delete directory with its subdirectories
* @param $dir string path to dir
* @return bool success
*/
function bpfw_delete_dir(string $dir): bool
{
Functions in i18nFunctions.inc.php
__() or bpfw_getTranslation()
get a translated word. __(“Cookie”) will return “Keks” if german is active etc.
/**
* get a translated word (alias for bpfw_getTranslation());
* @param $word_orig string original word
* @param $parameters array parameters if existing. can be used with {{{keyname}}} inside the translation
* @param $domain_orig string textdomain
* @param $lang string language if not autodetected
* @param $addIfNotExisting boolean add to database as if not existing
* @return string
*/
function __(string $word_orig, array $parameters = array(), string $domain_orig = 'default', string $lang = 'current', bool $addIfNotExisting = true): string
{
bpfw_get_active_languages
get array of active languages in format array(“de”=>”Deutsch, “en”=>English”)
/**
* get array of active languages
* @return array array like array("de"=>"Deutsch, "en"=>English")
* @throws Exception
*/
function bpfw_get_active_languages(): array
{
bpfw_getLanguagesArray
get array of all commonly used languages
/**
* get array of all languages
* @throws Exception
* @return string[] array with array('ab' => 'Abkhazian','aa' => 'Afar','af' => 'Afrikaans', [...] )
*/
function bpfw_getLanguagesArray() : array
{
bpfw_getCountryArray
get array of all countries
/**
* @return string[]
*/
function bpfw_getCountryArray(): array
{
bpfw_getCurrentLanguageCode
get the language code of the currently active language
/**
* get the language code of the currently active language
* @return string currently used language code. might return null if l18n is disabled
* @throws Exception
*/
function bpfw_getCurrentLanguageCode() : ?string
{
bpfw_js_announce_translation
if you want to use translations in js, announce them first. After that they can be used inside JS with __(“original word”);
/**
* if you want to use translations in js, announce them first. After that they can be used inside JS with __("original word");
* @throws Exception
*/
function bpfw_js_announce_translation($word, $translation = "{auto}"): void
Functions in mailerFunctions.inc.php
bpfw_sendmail
Send a mail through the system. Not saved in outbox.
/**
* Send a mail through the system
* @param string $subject
* @param string $text
* @param BpfwMailAddress|$to |BpfwMailAddress[] $to
* @param BpfwMailAddress|null $cc |BpfwMailAddress[]||null $cc
* @param BpfwMailAddress|null $bcc |BpfwMailAddress[]||null $bcc
* @param BpfwMailAddress|null $from |null $from
* @param array|BpfwMailAttachmentInterface $attachments |BpfwMailAttachmentInterface[]||null $attachments
* @param boolean $debug
* @return bool
* @throws \PHPMailer\PHPMailer\Exception
* @throws Exception
*/
function bpfw_sendmail(string $subject, string $text, BpfwMailAddress $to, BpfwMailAddress $cc = null, BpfwMailAddress $bcc = null, BpfwMailAddress $from = null, array|BpfwMailAttachmentInterface $attachments = array(), bool $debug = false): bool
{
bpfw_create_mailer
create a php mailer. you should prefer to use the bpfw_sendmail function if there is no reason againstit
/**
* create a php mailer. you should prefer to use the bpfw_sendmail function if there is no reason againstit
* @param string $sender
* @param string $sender_name
* @param bool $debug
* @return PHPMailer
* @throws \PHPMailer\PHPMailer\Exception
* @throws Exception
*/
function bpfw_create_mailer(string $sender = "", string $sender_name = "", bool $debug = false): PHPMailer
{
bpfw_sendmail_with_mailer
save a mail to the outbox. unless $sendDirectly is true it is sent when the next sent interval is triggered (cronjob or button)
/**
* save a mail to the outbox. unless $sendDirectly is true it is sent when the next sent interval is triggered (cronjob or button)
* @param string $subject
* @param string $text
* @param $to
* @param null $cc
* @param null $bcc
* @param null $from
* @param array $attachments
* @param boolean $sendDirectly
* @param boolean $debug
* @param bool $testmode
* @return bool
* @throws Exception
*/
function bpfw_sendmail_with_mailer(string $subject, string $text, $to, $cc = null, $bcc = null, $from = null, array $attachments = array(), bool $sendDirectly = false, bool $debug = false, bool $testmode = false): bool
{
bpfw_sendmail_with_mailer_send_directly
save a mail in the outbox and send it without delay
/**
* save a mail in the outbox and send it without delay
* @param string $subject
* @param string $text
* @param $to
* @param null $cc
* @param null $bcc
* @param null $from
* @param array $attachments
* @param boolean $debug
* @param bool $testmode
* @return bool
* @throws Exception
*/
function bpfw_sendmail_with_mailer_send_directly(string $subject, string $text, $to, $cc = null, $bcc = null, $from = null, array $attachments = array(), bool $debug = false, bool $testmode = false): bool
{
bpfw_get_last_mailerror
get the last error that occured when sending mails
/**
* get the last error that occured when sending mails
* @return string
*/
function bpfw_get_last_mailerror(): string
{
bpfw_findMailAddress
Search for the mail address in users and customers and create a BpfwMailAddress with the correct user first and lastname
/**
* Search for the mail address in users and customers and create a BpfwMailAddress with the correct user first and lastname
* @param mixed $email
* @param array|mixed $types array with user and/or customer
* @return BpfwMailAddress|null
* @throws Exception
*/
function bpfw_findMailAddress(mixed $email, array $types = array("user", "customer")): ?BpfwMailAddress
{
bpfw_getDefaultMailFrom, bpfw_getDefaultMailIntern, bpfw_getDefaultMailBcc
returns the default mail addresses for from, intern and bcc.
/**
* returns default Mail From Adress as bpfw class
* @return BpfwMailAddress
* @throws Exception
*/
function bpfw_getDefaultMailFrom(): BpfwMailAddress
{
return new BpfwMailAddress(bpfw_loadSetting(SETTING_EMAIL_ABSENDER), bpfw_loadSetting(SETTING_EMAIL_ABSENDER_NAME), bpfw_getUserId(), "user");
}
/**
* returns default Mail internal Adress as bpfw class
* @return BpfwMailAddress
* @throws Exception
*/
function bpfw_getDefaultMailIntern(): BpfwMailAddress
{
return new BpfwMailAddress(bpfw_loadSetting(SETTING_EMAIL_INTERN), bpfw_loadSetting(SETTING_EMAIL_INTERN), null, "user");
}
/**
* returns default Mail bcc Adress as bpfw class
* @return BpfwMailAddress
* @throws Exception
*/
function bpfw_getDefaultMailBcc(): BpfwMailAddress
{
return new BpfwMailAddress(bpfw_loadSetting(SETTING_EMAIL_INTERN), bpfw_loadSetting(SETTING_EMAIL_BCC_EMPFAENGER), null, "user");
}
Functions in numberFunctions.inc.php
bpfw_float_to_eur
converts a float to eur. 12,21/12.21 becomes 12 Euro 21 Cents
/**
* converts a float to eur. 12,21/12.21 becomes 12 Euro 21 Cents
* @param $input float
* @return string
*/
function bpfw_float_to_eur(float $input): string
bpfw_toUsNumberFormat
converts 122,222.11 to 122.222,11
/** * 122,222.11 to 122.222,11 * @param string $value * @return string */ function bpfw_toUsNumberFormat(string $value): string {
bpfw_fromUsNumberFormat
converts 122,222.11 to 122.222,11
/** * converts 122,222.11 to 122.222,11 * @param string $value * @return string */ function bpfw_fromUsNumberFormat(string $value): string {
Functions in settingsFunctions.inc.php
bpfw_loadSetting
converts 122,222.11 to 122.222,11
/**
* @param $settingValue string setting variable This is a name of a field in settingsModel. Default settings are also defined as SETTING_ constants in settingsFunctions.inc.php
* @param $where string additional where clause if you have more than one set of settings
* @return mixed|null
* @throws Exception
*/
function bpfw_loadSetting(string $settingValue, string $where = "1"): mixed
{
Functions in stringFunctions.inc.php
bpfw_cutStringToLength
cut a string to a specific length if it is too long
/**
* @param $string string string to cut
* @param $maxLength int max length
* @return string
*/
function bpfw_cutStringToLength(string $string, int $maxLength) : string
{
bpfw_sanitize
sanitize string – can be used to make any string to a filename
/**
* sanitize string - can be used to make any string to a filename
* @param $string string
* @param $force_lowercase bool all chars lowercase
* @param $onlyAlphabetAndNumbersAllowed bool only allow chars and numbers
* @param $replaceSpaces bool no spaces
* @return array|string|null
*/
function bpfw_sanitize(string $string, bool $force_lowercase = false, bool $onlyAlphabetAndNumbersAllowed = false, bool $replaceSpaces = false): array|string|null
{
bpfw_boolToString
bool to string bool with “true” and “false”
/**
* bool to string bool with "true" and "false"
* @param boolean $boolVal
* @return string
*/
function bpfw_boolToString(bool $boolVal): string
Functions in userFunctions.inc.php
bpfw_isAdmin, bpfw_isDeveloper
current User is an admin or developer/superadmin
/**
* @return bool current user is an admin
*/
function bpfw_isAdmin(): bool
{
---
/**
* @return bool is developer
*/
function bpfw_isDeveloper(): bool
{
bpfw_getUsertypeArray
array of all default user ranks and their name.
/**
* @return array array of all default user ranks and their name
* @throws Exception
*/
function bpfw_getUsertypeArray(): array
{
bpfw_hasPermission
user has at least the given rank
/**
* user has at least the given rank
* @param $minUserRank int rank (0=superadmin, higher = less permissions)
* @return bool
*/
function bpfw_hasPermission(int $minUserRank): bool
bpfw_getCurrentUsertype
get usertype/rank of current user
/**
* @return int usertype of current user
*/
function bpfw_getCurrentUsertype() : int
{
bpfw_generatePassword
Generates a strong password of N length containing at least one lower case letter, one uppercase letter, one digit, and one special character. The remaining characters
in the password are chosen at random from those four sets.
The available characters in each set are user-friendly – there are no ambiguous
characters such as i, l, 1, o, 0, etc. This, coupled with the $add_dashes option,
makes it much easier for users to manually type or speak their passwords.
Note: the $add_dashes option will increase the length of the password by floor(sqrt(N)) characters.
/**
* Generates a strong password of N length containing at least one lower case letter,
* one uppercase letter, one digit, and one special character. The remaining characters
* in the password are chosen at random from those four sets.
*
* The available characters in each set are user-friendly - there are no ambiguous
* characters such as i, l, 1, o, 0, etc. This, coupled with the $add_dashes option,
* makes it much easier for users to manually type or speak their passwords.
*
* Note: the $add_dashes option will increase the length of the password by floor(sqrt(N)) characters.
* @param $length int length of password
* @param $add_dashes bool
* @param $available_sets string string out of "luds" (lowercase, uppercase, numbers, special chars). defines the set the password can contain.
* @return string
*/
function bpfw_generatePassword(int $length = 9, bool $add_dashes = false, string $available_sets = 'luds'): string
{
bpfw_getSalutationArray
get a salutation array for comboboxes etc.
/**
* get a salutation array for comboboxes etc.
*
* @return array
* @throws Exception
*/
function bpfw_getSalutationArray(): array
{
bpfw_isLoggedIn
Is the visiting user logged in?
/**
* is visitor user logged in?
* @return bool is logged in
*/
function bpfw_isLoggedIn(): bool
{
bpfw_getUser, bpfw_getUserId, bpfw_getUserName, bpfw_getUsertype
get all userdata or the userid or the username of the current user
/**
* get all userdata. contains the data of the userModel like username, rank and userId
* @return array|null
*/
function bpfw_getUser() : array | null
{
if (bpfw_isLoggedIn()) {
return $_SESSION['userdata'];
}
return null;
}
/**
* gets the username
* @return ?string
*/
function bpfw_getUserName()
{
if (bpfw_isLoggedIn()) {
return $_SESSION['userdata']['username'];
}
return null;
}
/**
* Userid of logged in User
* @return mixed
*/
function bpfw_getUserId(): mixed
{
if (bpfw_isLoggedIn()) {
return $_SESSION['userdata']['userId'];
}
return -1;
}
/**
* Is the visiting user logged in?
* @return bool is logged in
*/
function bpfw_isLoggedIn(): bool
{
return !empty($_SESSION['userdata']);
}