class Core (View source)

Core functions used all over the scripts.

Methods

static string
securePath(string $path)

Removes insecure parts in a path; used before include() or require() when a part of the path comes from an insecure source like a cookie or form.

static string
getPHPDocLink(string $target)

Returns a link to the PHP documentation

static void
warnMissingExtension(string $extension, bool $fatal = false, string $extra = '')

Warn or fail on missing extension.

static int
getRealSize(string|int $size = 0)

Converts numbers like 10M into bytes Used with permission from Moodle (https://moodle.org) by Martin Dougiamas (renamed with PMA prefix to avoid double definition when embedded in Moodle)

static bool
checkPageValidity(string $page)

Checks if the given $page is index.php and returns true if valid.

static string
getEnv(string $variableName)

Tries to find the value for the given environment variable name

static array
headerJSON()

Returns application/json headers. This includes no caching.

static array
getNoCacheHeaders()

No description

static void
downloadHeader(string $filename, string $mimetype, int $length = 0, bool $noCache = true)

Sends header indicating file download.

static mixed
arrayRead(string $path, array $array, mixed $default = null)

Returns value of an element in $array given by $path.

static void
arrayWrite(string $path, array $array, mixed $value)

Stores value in an array

static void
arrayRemove(string $path, array $array)

Removes value from an array

static string
linkURL(string $url)

Returns link to (possibly) external site using defined redirector.

static bool
isAllowedDomain(string $url)

Checks whether domain of URL is an allowed domain or not.

static string
mimeDefaultFunction(string $buffer)

Replace some html-unfriendly stuff

static void
previewSQL(array|string $queryData)

Displays SQL query before executing.

static bool
emptyRecursive(mixed $value)

recursively check if variable is empty

static string|bool
getIp()

Gets the "true" IP address of the current user

static string
sanitizeMySQLHost(string $name)

Sanitizes MySQL hostname

static string
sanitizeMySQLUser(string $name)

Sanitizes MySQL username

static mixed
safeUnserialize(string $data)

Safe unserializer wrapper

static string
signSqlQuery(string $sqlQuery)

Sign the sql query using hmac using the session token

static bool
checkSqlQuerySignature(string $sqlQuery, string $signature)

Check that the sql query has a valid hmac signature

Details

static string securePath(string $path)

Removes insecure parts in a path; used before include() or require() when a part of the path comes from an insecure source like a cookie or form.

Parameters

string $path

The path to check

Return Value

string

Returns a link to the PHP documentation

Parameters

string $target

anchor in documentation

Return Value

string

the URL

static void warnMissingExtension(string $extension, bool $fatal = false, string $extra = '')

Warn or fail on missing extension.

Parameters

string $extension

Extension name

bool $fatal

Whether the error is fatal.

string $extra

Extra string to append to message.

Return Value

void

static int getRealSize(string|int $size = 0)

Converts numbers like 10M into bytes Used with permission from Moodle (https://moodle.org) by Martin Dougiamas (renamed with PMA prefix to avoid double definition when embedded in Moodle)

Parameters

string|int $size

size (Default = 0)

Return Value

int

static bool checkPageValidity(string $page)

Checks if the given $page is index.php and returns true if valid.

It ignores query parameters in $page (script.php?ignored)

Parameters

string $page

Return Value

bool

static string getEnv(string $variableName)

Tries to find the value for the given environment variable name

Searches in $_SERVER, $_ENV then tries getenv() and apache_getenv() in this order.

Parameters

string $variableName

Return Value

string

static array headerJSON()

Returns application/json headers. This includes no caching.

Return Value

array

static array getNoCacheHeaders()

No description

Return Value

array

static void downloadHeader(string $filename, string $mimetype, int $length = 0, bool $noCache = true)

Sends header indicating file download.

Parameters

string $filename

Filename to include in headers if empty, none Content-Disposition header will be sent.

string $mimetype

MIME type to include in headers.

int $length

Length of content (optional)

bool $noCache

Whether to include no-caching headers.

Return Value

void

static mixed arrayRead(string $path, array $array, mixed $default = null)

Returns value of an element in $array given by $path.

$path is a string describing position of an element in an associative array, eg. Servers/1/host refers to $array[Servers][1][host]

Parameters

string $path

path in the array

array $array

the array

mixed $default

default value

Return Value

mixed

array element or $default

static void arrayWrite(string $path, array $array, mixed $value)

Stores value in an array

Parameters

string $path

path in the array

array $array

the array

mixed $value

value to store

Return Value

void

static void arrayRemove(string $path, array $array)

Removes value from an array

Parameters

string $path

path in the array

array $array

the array

Return Value

void

static string linkURL(string $url)

Returns link to (possibly) external site using defined redirector.

Parameters

string $url

URL where to go.

Return Value

string

URL for a link.

static bool isAllowedDomain(string $url)

Checks whether domain of URL is an allowed domain or not.

Use only for URLs of external sites.

Parameters

string $url

URL of external site.

Return Value

bool

static string mimeDefaultFunction(string $buffer)

Replace some html-unfriendly stuff

Parameters

string $buffer

String to process

Return Value

string

Escaped and cleaned up text suitable for html

static void previewSQL(array|string $queryData)

Displays SQL query before executing.

Parameters

array|string $queryData

Array containing queries or query itself

Return Value

void

static bool emptyRecursive(mixed $value)

recursively check if variable is empty

Parameters

mixed $value

the variable

Return Value

bool

static string|bool getIp()

Gets the "true" IP address of the current user

Return Value

string|bool

the ip of the user

static string sanitizeMySQLHost(string $name)

Sanitizes MySQL hostname

  • strips p: prefix(es)

Parameters

string $name

User given hostname

Return Value

string

static string sanitizeMySQLUser(string $name)

Sanitizes MySQL username

  • strips part behind null byte

Parameters

string $name

User given username

Return Value

string

static mixed safeUnserialize(string $data)

Safe unserializer wrapper

It does not unserialize data containing objects

Parameters

string $data

Data to unserialize

Return Value

mixed

static string signSqlQuery(string $sqlQuery)

Sign the sql query using hmac using the session token

Parameters

string $sqlQuery

The sql query

Return Value

string

static bool checkSqlQuerySignature(string $sqlQuery, string $signature)

Check that the sql query has a valid hmac signature

Parameters

string $sqlQuery

The sql query

string $signature

The Signature to check

Return Value

bool

static ServerRequest populateRequestWithEncryptedQueryParams(ServerRequest $request)

No description

Parameters

ServerRequest $request

Return Value

ServerRequest