WIKINDX API 6.6.8

UTILS

Table of Contents

Functions

listCoreMandatoryPHPExtensions()  : array<string|int, string>
Return an array of mandatory PHP extensions used by the WIKINDX core
listCoreOptionalPHPExtensions()  : array<string|int, string>
Return an array of optional PHP extensions used by the WIKINDX core
OSName()  : string
Return the normalized name of the current os
matchPrefix()  : bool
Check if a prefix match against a string
matchSuffix()  : bool
Check if a suffix match against a string
readComponentsList()  : array<string|int, mixed>
Read and return the list of all components installed
writeComponentsList()  : mixed
Write a list of components from an array
refreshComponentsListCache()  : mixed
Refresh the components list if needed, or forced by the caller
isBuiltinComponent()  : bool
Is a component builtin?
checkComponentsList()  : array<string|int, mixed>
Return a structured list of installed components
computeComponentVersion()  : int
Compute a component version number from the current date
computeComponentSignature()  : string
Compute the hash signature of a component from its installed code
createComponentMetadataFile()  : mixed
Create the component.json file of a component
enableComponent()  : bool
Enable a component
disableComponent()  : bool
Disable a component
checkComponentIntegrity()  : int
Check the integrity of a component
componentIntegrityErrorMessage()  : string
Return the message of an error code of the function checkComponentIntegrity()
curl_download_file_http()  : bool
Download a file from an url with HTTP
uuid()  : string
Return a (pseudo) unique string of variable length using random_bytes().
checkFoldersPerms()  : mixed
Check the permissions of various folders and files which must be writable
arrayCombinations()  : mixed
Generate an array of all possible combinations of array values From https://stackoverflow.com/questions/10834393/php-how-to-get-all-possible-combinations-of-1d-array with minor adaptation ($space)
splitDate()  : array<string|int, mixed>
Take input from HTML FORM <input type=date> and split into separate fields.
balanceBraces()  : string
Balance braces after removing noSort in resource input/edit of title or for bibTeX input
sumBraces()  : int
Balance braces after removing noSort or for bibTeX input — return result of sum of open - close braces
noSortPattern()  : string
Create a preg pattern for checking presence of a WIKINDX_NO_SORT value at the beginning of a string.
writeUserPassword()  : mixed
Write a hashed version of a user password in users table
verifyUserPassword()  : bool
Verify that a password matches a password hash of a user
array_value_select()  : mixed
Return the corresponding value of an array key or a default value
createHelpTopicLink()  : string
Create a popup link for a Help Topic on the website
canIResumeExecution()  : bool
Can I resume execution?
command_exists()  : bool
Does an unix command exist?
suhosin_function_exists()  : bool
Does a function exist or is enabled with (or without) the suhosin security extension?
insertExportImages()  : mixed
Insert cached images inside exported files, and delete them
reduceLongText()  : string
Reduce the size of long text (in select boxes usually) to keep web browser display tidy.

Functions

listCoreMandatoryPHPExtensions()

Return an array of mandatory PHP extensions used by the WIKINDX core

listCoreMandatoryPHPExtensions() : array<string|int, string>

The name of each extension is the value of an array entry. An extension name use the same casing as get_loaded_extensions().

Return values
array<string|int, string>

listCoreOptionalPHPExtensions()

Return an array of optional PHP extensions used by the WIKINDX core

listCoreOptionalPHPExtensions() : array<string|int, string>

The name of each extension is the value of an array entry. An extension name use the same casing as get_loaded_extensions().

Return values
array<string|int, string>

OSName()

Return the normalized name of the current os

OSName() : string

Values can be:

  • "windows" for Cygwin, mingw, msys, or Windows
  • "mac" forall version of MAC OSX
  • The raw name in lowercase (a-z chars only) for others
Return values
string

matchPrefix()

Check if a prefix match against a string

matchPrefix(string $string, string $prefix) : bool
Parameters
$string : string

A string

$prefix : string

A prefix

Return values
bool

matchSuffix()

Check if a suffix match against a string

matchSuffix(string $string, string $suffix) : bool
Parameters
$string : string

A string

$suffix : string

A suffix

Return values
bool

readComponentsList()

Read and return the list of all components installed

readComponentsList([bool $force = FALSE ]) : array<string|int, mixed>

Status of activation are kept in /data/components.json file, other data are in /cache/components.json file because the status must be be persistent between two upgrades, or a component is uninstalled. This function merges status after reading the two files.

Use only this function to read the components list.

Parameters
$force : bool = FALSE

Forces the cache overwriting if it already exists (optional, FALSE by default)

Return values
array<string|int, mixed>

writeComponentsList()

Write a list of components from an array

writeComponentsList(array<string|int, mixed> $ComponentsList) : mixed

Status of activation are kept in /data/components.json file, other data are in /cache/components.json file because the status must be be persistent between two upgrades, or a component is uninstalled. This function separates the status from the other fields and saves them in separate files.

Use only this function to save the components list.

Parameters
$ComponentsList : array<string|int, mixed>

Components list (with activation status)

refreshComponentsListCache()

Refresh the components list if needed, or forced by the caller

refreshComponentsListCache([bool $force = FALSE ]) : mixed
Parameters
$force : bool = FALSE

Forces the file overwriting if it already exists (optional, FALSE by default)

isBuiltinComponent()

Is a component builtin?

isBuiltinComponent(string $component_type, string $component_id) : bool

A builtin component is packed with the core. It can be updated and cannot be disabled or uninstalled.

Parameters
$component_type : string
$component_id : string
Return values
bool

checkComponentsList()

Return a structured list of installed components

checkComponentsList() : array<string|int, mixed>

The list is extracted form the component.json file of each component and an integrity check is performed against the component. A default activation status is computed from this minimal integrity check and the configuration read.

Return values
array<string|int, mixed>

computeComponentVersion()

Compute a component version number from the current date

computeComponentVersion() : int

The component version number is the number of days elapsed since the launch of the system of components (v6 on 2020-01-12)

Return values
int

computeComponentSignature()

Compute the hash signature of a component from its installed code

computeComponentSignature(string $component_type, string $component_id) : string

The algorithm used is defined implicitly by the WIKINDX_PACKAGE_HASH_ALGO constant.

During the hashing a temp folder is created inside cache/cmpsigning/<type_id>

Parameters
$component_type : string

(plugin, style, template)

$component_id : string
Return values
string

createComponentMetadataFile()

Create the component.json file of a component

createComponentMetadataFile(string $component_type, string $component_id) : mixed

Do not overwrite the file if it already exists.

Parameters
$component_type : string

(plugin, style, template)

$component_id : string

enableComponent()

Enable a component

enableComponent(string $component_type, string $component_id) : bool
Parameters
$component_type : string

(plugin, style, template)

$component_id : string
Return values
bool

TRUE on success, FALSE otherwise

disableComponent()

Disable a component

disableComponent(string $component_type, string $component_id) : bool
Parameters
$component_type : string

(plugin, style, template)

$component_id : string
Return values
bool

TRUE on success, FALSE otherwise

checkComponentIntegrity()

Check the integrity of a component

checkComponentIntegrity(string $componentDirPath) : int
Parameters
$componentDirPath : string

A path to the folder of a component

Return values
int

Error code: 0 is for OK and others issues.

componentIntegrityErrorMessage()

Return the message of an error code of the function checkComponentIntegrity()

componentIntegrityErrorMessage(int $error_code) : string
Parameters
$error_code : int
Return values
string

An error message

curl_download_file_http()

Download a file from an url with HTTP

curl_download_file_http(string $url, string $file) : bool

NB: follow 32 redirects (for SourceForge) and don't check certificats and fingerprints

Parameters
$url : string
  • the url of a web resource
$file : string
  • the path of a local file
Return values
bool

TRUE if the download is successful, FALSE otherwise

uuid()

Return a (pseudo) unique string of variable length using random_bytes().

uuid([int $length = 16 ]) : string
Parameters
$length : int = 16

length of the returned string (Default is 16)

Return values
string

checkFoldersPerms()

Check the permissions of various folders and files which must be writable

checkFoldersPerms() : mixed

arrayCombinations()

Generate an array of all possible combinations of array values From https://stackoverflow.com/questions/10834393/php-how-to-get-all-possible-combinations-of-1d-array with minor adaptation ($space)

arrayCombinations(array<string|int, mixed> $arr, string $temp_string, string $space, array<string|int, mixed> &$collect) : mixed
Parameters
$arr : array<string|int, mixed>
$temp_string : string
$space : string
$collect : array<string|int, mixed>

splitDate()

Take input from HTML FORM <input type=date> and split into separate fields.

splitDate(string $dateInput) : array<string|int, mixed>

Date comes in as 'yyyy-mm-dd' (but displayed on web form as 'dd / mm / yyyy'). All three fields must have a valid value else the form input is FALSE. This should be tested before calling this function.

Parameters
$dateInput : string
Return values
array<string|int, mixed>

array(year, month, day)

balanceBraces()

Balance braces after removing noSort in resource input/edit of title or for bibTeX input

balanceBraces(string $string) : string
Parameters
$string : string
Return values
string

sumBraces()

Balance braces after removing noSort or for bibTeX input — return result of sum of open - close braces

sumBraces(string $string) : int
Parameters
$string : string
Return values
int

noSortPattern()

Create a preg pattern for checking presence of a WIKINDX_NO_SORT value at the beginning of a string.

noSortPattern([array<string|int, mixed> $noSortArray = [] ]) : string

If empty($noSortArray), then we use WIKINDX_NO_SORT (and assume that WIKINDX_NO_SORT has been checked for content). Otherwise, $noSortArray is from admin::configure::updateNoSort()

Parameters
$noSortArray : array<string|int, mixed> = []

Default = []

Return values
string

writeUserPassword()

Write a hashed version of a user password in users table

writeUserPassword(object $dbo, string $usersId, string $usersPassword) : mixed

Implementation history: see \UTILS\verifyUserPassword()

Parameters
$dbo : object

An SQL object

$usersId : string

A user Id

$usersPassword : string

A clear password to encrypt/hash

verifyUserPassword()

Verify that a password matches a password hash of a user

verifyUserPassword(object $dbo, string $usersId, string $usersPassword) : bool

It hides the implementation changes linked to the evolution of cryptographic techniques.

Parameters
$dbo : object

An SQL object

$usersId : string

A user Id

$usersPassword : string

A clear password to verify

Tags
see
https://www.php.net/manual/en/function.password-hash.php#124138

A goof hash renewal strategy is explained on this page: https://www.michalspacek.com/upgrading-existing-password-hashes

Unfortunately the hashes used with crypt have not been memorized and it is not possible to do the double hash step.

So the option chosen is to hash the password the next time a user connects and in a future version remove the old algorithm and reset the password for users who have never reconnected.

Implementation history

  • v1 (before 5.2.0): use crypt() with a salt generated by: strrev(time()).
  • v2 (5.2.0 to 6.3.10): use crypt() with a salt generated by: \UTF8\mb_strrev(time()).
  • v3 (from 6.4.0): use crypt() with a salt generated by: strrev(time()).
  • v4 (from 6.4.0, v35): use password_hash() with PASSWORD_DEFAULT algo without custom options.

The last version replaced the pre-PHP 5.5 crypt() function by password_hash() which has stronger defaults and is protected against time attacks.

version
4
Return values
bool

array_value_select()

Return the corresponding value of an array key or a default value

array_value_select(array<string|int, mixed> $array, mixed $key[, mixed $defaultKey = NULL ][, mixed $defaultValue = NULL ]) : mixed

This function is an access to the value of an array with fallback solutions in the event of absence.

This function is useful when it is necessary to select a value from a list and one of the inputs is also the default key or it is mandatory to obtain a consistent value at the output of the selection without having to write additional code.

Parameters
$array : array<string|int, mixed>

An array to search the key for

$key : mixed

The key whose value must be returned

$defaultKey : mixed = NULL

The default key whose value must be returned if the key was not found (NULL by default)

$defaultValue : mixed = NULL

The value returned if no key was found (NULL by default)

Create a popup link for a Help Topic on the website

createHelpTopicLink(mixed $helpTopic) : string
Parameters
$helpTopic : mixed
Return values
string

HTML link tag

canIResumeExecution()

Can I resume execution?

canIResumeExecution([int $memorySizeRemaining = 1048576 ][, int $excutionTimeRemaining = 6 ]) : bool

Says if it is possible to continue the execution of the program according to the consumption of memory and time.

Use this for memory or time intensive tasks you intend to interrupt without crash.

Say TRUE:

  • if 10 MB or less remains before the PHP max memory limit
  • or if 6 s. or less time remains before max_execution_time.

Otherwise FALSE.

NB:

  • If memory_limit option is set to -1, the memory condition is not checked.
  • If max_execution_time option is set to 0, the time condition is not checked.
Parameters
$memorySizeRemaining : int = 1048576

Memory size in bytes of remaining before the limit (Default is 10MB = 1024 * 1024 bytes)

$excutionTimeRemaining : int = 6

Execution time remaining before the max executionlimit (Default is 6 seconds)

Return values
bool

command_exists()

Does an unix command exist?

command_exists(string $command) : bool
Parameters
$command : string

Command to test with the default shell

Return values
bool

TRUE on success

suhosin_function_exists()

Does a function exist or is enabled with (or without) the suhosin security extension?

suhosin_function_exists(string $func) : bool
Parameters
$func : string

Function name

Tags
see
https://suhosin.org/stories/index.html
author

webmaster@mamo-net.de

Return values
bool

TRUE if the function is enabled

insertExportImages()

Insert cached images inside exported files, and delete them

insertExportImages(string $fileName) : mixed

The file is written to consume as little memory as possible because the number of images can be large.

Parameters
$fileName : string

reduceLongText()

Reduce the size of long text (in select boxes usually) to keep web browser display tidy.

reduceLongText(string $text[, string $override = FALSE ][, int $words = 0 ][, bool $balance = TRUE ]) : string

Optional $override allows the programmer to override the user set preferences for number of characters. If optional $words is greater than 0, then that number of words is used rather than a number of characters. If optional $balance l= TRUE, the return string is something like 'xxxx ... xxxx' else it is 'xxxx ...' (if there are chars/words removed). If $words is being used, then $balance is ignored and the first $words are returned.

Parameters
$text : string
$override : string = FALSE

Default is FALSE

$words : int = 0

Default is FALSE

$balance : bool = TRUE

Default TRUE

Return values
string

        
On this page

Search results