core.php
Core: helper methods and main libraries loader
Zed. The immensity of stars. The HyperShip. The people.
(c) 2010, Dereckson, some rights reserved. Released under BSD license.
Tags
Table of Contents
Constants
- LANG = $_SESSION['lang']
Functions
- get_name() : string
- Gets the nickname from the specified perso ID
- get_userid() : int
- Gets the user ID from the specified username
- registry_get() : string
- Gets an information from the application global registry
- registry_set() : void
- Sets an information in the application global registry
- s() : string
- Returns "s" when the $amount request a plural This function is a French plural helper.
- x() : string
- Returns "x" when the $amount request a plural This function is a French plural helper.
- dprint_r() : mixed
- Prints human-readable information about a variable.
- new_guid() : string
- Generates a GUID, or more precisely an UUID
- is_guid() : bool
- Determines if the expression is a valid UUID (a guid without {}).
- get_extension() : string
- Gets file extension
- supralog() : mixed
- Inserts a message into the supralog
- initialize_lang() : void
- Defines the LANG constant, to lang to print
- find_lang() : string
- Gets a common lang spoken by the site and the user's browser
- get_http_accept_languages() : array<string|int, string>
- Gets the languages accepted by the browser, by order of priority.
- lang_load() : void
- Loads specified language Smarty configuration file
- lang_get() : string
- Gets a specified language expression defined in configuration file
- to_unixtime() : int
- Converts a YYYYMMDD or YYYY-MM-DD timestamp to unixtime
- to_timestamp() : string
- Converts a unixtime to the YYYYMMDD or YYYY-MM-DD timestamp format
- get_hypership_time() : string
- Converts a unixtime to the Hypership time format or gets the current hypership time.
- get_url() : string
- Gets the URL matching the specified resource.
- get_page_url() : string
- Gets the current page URL
- get_server_url() : string
- Gets the server URL
- get_current_url() : string
- Gets $_SERVER['PATH_INFO'] or computes the equivalent if not defined.
- get_current_url_fragments() : array<string|int, mixed>
- Gets an array of url fragments to be processed by controller
- get_xhr_hash() : string
- Gets an hash value to check the integrity of URLs in /do.php calls
- get_xhr_hashed_url() : string
- Gets the URL to call do.php, the xmlHttpRequest controller
- get_xhr_url() : string
- Gets the URL to call do.php, the xmlHttpRequest controller
Constants
LANG
public
mixed
LANG
= $_SESSION['lang']
Functions
get_name()
Gets the nickname from the specified perso ID
get_name(int $perso_id) : string
Parameters
- $perso_id : int
-
The specified perso ID
Return values
string —The perso's nickname
get_userid()
Gets the user ID from the specified username
get_userid(string $username) : int
Parameters
- $username : string
-
The username
Return values
int —the user ID
registry_get()
Gets an information from the application global registry
registry_get(DatabaseEngine $db, string $key) : string
Parameters
- $db : DatabaseEngine
- $key : string
Return values
stringregistry_set()
Sets an information in the application global registry
registry_set(DatabaseEngine $db, string $key, string $value) : void
Parameters
- $db : DatabaseEngine
- $key : string
-
the registry key
- $value : string
-
the value to store at the specified registry key
s()
Returns "s" when the $amount request a plural This function is a French plural helper.
s(int $amount) : string
Parameters
- $amount : int
Return values
string —'s' if $amount implies a plural ; '' if it implies a singular.
x()
Returns "x" when the $amount request a plural This function is a French plural helper.
x(int $amount) : string
Parameters
- $amount : int
Return values
string —'x' if $amount implies a plural ; '' if it implies a singular.
dprint_r()
Prints human-readable information about a variable.
dprint_r(mixed $expression) : mixed
It behaves like the print_r command, but the output is enclosed in pre tags, to have a preformatted HTML output.
Parameters
- $expression : mixed
-
The expression to be printed
new_guid()
Generates a GUID, or more precisely an UUID
new_guid() : string
Tags
Return values
string —the UUID
is_guid()
Determines if the expression is a valid UUID (a guid without {}).
is_guid(string $expression) : bool
Parameters
- $expression : string
-
the expression to check
Tags
Return values
bool —true if the specified expression is a valid UUID ; otherwise, false.
get_extension()
Gets file extension
get_extension(string $file) : string
Parameters
- $file : string
-
the file to get the extension
Return values
string —the extension from the specified file
supralog()
Inserts a message into the supralog
supralog(string $category, string $message[, string|null $source = null ]) : mixed
Parameters
- $category : string
-
the entry category
- $message : string
-
the message to log
- $source : string|null = null
-
the entry source.
initialize_lang()
Defines the LANG constant, to lang to print
initialize_lang() : void
This information is contained in the session, or if not yet defined, it's to determine according the user's browser preferences.
Tags
find_lang()
Gets a common lang spoken by the site and the user's browser
find_lang([string|null $fallback = null ]) : string
Parameters
- $fallback : string|null = null
-
The language when no common language is found
Tags
Return values
string —The language to use
get_http_accept_languages()
Gets the languages accepted by the browser, by order of priority.
get_http_accept_languages() : array<string|int, string>
This will read the HTTP_ACCEPT_LANGUAGE variable sent by the browser in the HTTP request.
Return values
array<string|int, string> —list of the languages accepted by browser
lang_load()
Loads specified language Smarty configuration file
lang_load(string $file[, mixed|null $sections = null ]) : void
Parameters
- $file : string
-
the file to load
- $sections : mixed|null = null
-
array of section names, single section or null
lang_get()
Gets a specified language expression defined in configuration file
lang_get(string $key) : string
Parameters
- $key : string
-
the configuration key matching the value to get
Return values
string —The value in the configuration file
to_unixtime()
Converts a YYYYMMDD or YYYY-MM-DD timestamp to unixtime
to_unixtime(string $timestamp) : int
Parameters
- $timestamp : string
-
the timestamp to convert
Tags
Return values
int —the unixtime
to_timestamp()
Converts a unixtime to the YYYYMMDD or YYYY-MM-DD timestamp format
to_timestamp([int $unixtime = null ][, int $format = 8 ]) : string
Parameters
- $unixtime : int = null
-
the time to convert
- $format : int = 8
-
8 or 10. If 8 (default), will output YYYYMMDD. If 10, YYYY-MM-DD.
Tags
Return values
string —the timestamp
get_hypership_time()
Converts a unixtime to the Hypership time format or gets the current hypership time.
get_hypership_time([int $unixtime = null ]) : string
Parameters
- $unixtime : int = null
-
The unixtime to convert to HyperShip time. If omitted, the current unixtime.
Tags
Return values
string —The HyperShip time
get_url()
Gets the URL matching the specified resource.
get_url() : string
Example:
$url = get_url('ship', $ship);
echo $url; //if $ship contains S00001, this should print /ship/S00001
Return values
string —the URL matching the specified resource
get_page_url()
Gets the current page URL
get_page_url() : string
Return values
string —the current page URL
get_server_url()
Gets the server URL
get_server_url() : string
Tags
Return values
string —the server URL
get_current_url()
Gets $_SERVER['PATH_INFO'] or computes the equivalent if not defined.
get_current_url() : string
This function allows the entry point controllers to get the current URL in a consistent way, for any redirection configuration
So with /foo/bar, /index.php/foo/bar, /zed/index.php/foo/bar or /zed/foo/bar get_current_url will return /foo/bar
Return values
string —the relevant URL part
get_current_url_fragments()
Gets an array of url fragments to be processed by controller
get_current_url_fragments() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —an array of string, one for each URL fragment
get_xhr_hash()
Gets an hash value to check the integrity of URLs in /do.php calls
get_xhr_hash(array<string|int, mixed> $args) : string
Parameters
- $args : array<string|int, mixed>
-
the args to compute the hash
Return values
string —the hash parameter for your xmlHttpRequest url
get_xhr_hashed_url()
Gets the URL to call do.php, the xmlHttpRequest controller
get_xhr_hashed_url() : string
Return values
string —the xmlHttpRequest url, with an integrity hash
get_xhr_url()
Gets the URL to call do.php, the xmlHttpRequest controller
get_xhr_url() : string
Return values
string —the xmlHttpRequest url