misc.functions.php
Miscellaneous support functions
Tags
Table of Contents
Functions
- redirect() : mixed
- Redirects to relative URL on the current site.
- redirect_to_alias() : mixed
- Given a page ID or an alias, redirect to it.
- microtime_diff() : int
- Calculate the difference in seconds between two microtime() values.
- cms_join_path() : string
- Joins a path together using platform specific directory separators.
- cms_relative_path() : string
- Return the relative portion of a path
- cms_htmlentities() : string
- Perform HTML entity conversion on a string.
- debug_bt_to_log() : mixed
- A function to output a backtrace into the generated log file.
- debug_bt() : mixed
- A function to generate a backtrace in a readable format.
- debug_display() : string
- Debug function to display $var nicely in html.
- debug_output() : mixed
- Display $var nicely only if $config["debug"] is set.
- debug_to_log() : mixed
- Debug function to output debug information about a variable in a formatted matter to a debug file.
- debug_buffer() : mixed
- Display $var nicely to the CmsApp::get_instance()->errors array if $config['debug'] is set.
- get_parameter_value() : mixed
- Retrieve the $value from the $parameters array checking for $parameters[$value] and $params[$id.$value].
- is_directory_writable() : bool
- Check the permissions of a directory recursively to make sure that we have write permission to all files.
- get_recursive_file_list() : array<string|int, string>
- Return an array containing a list of files in a directory performs a recursive search.
- recursive_delete() : bool
- A function to recursively delete all files and folders in a directory; synonymous with rm -r.
- chmod_r() : mixed
- A function to recursively chmod all files and folders in a directory.
- startswith() : bool
- A convenience function to test wether one string starts with another.
- endswith() : bool
- Similar to the startswith method, this function tests with string A ends with string B.
- munge_string_to_url() : string
- Convert a human readable string into something that is suitable for use in URLS.
- ini_get_boolean() : int
- A convenience function to return a bool variable given a php ini key that represents a bool.
- stack_trace() : mixed
- Another convenience function to output a human-readable function stack trace.
- cms_move_uploaded_file() : mixed
- A wrapper around move_uploaded_file that attempts to ensure permissions on uploaded files are set correctly.
- cms_ipmatches() : bool
- A function to test whether an IP address matches a list of expressions.
- is_email() : bool
- Test if the string provided is a valid email address.
- cms_to_bool() : mixed
- A simple function to convert a string to a bool.
- cms_get_jquery() : mixed
- A function to return the appropriate HTML tags to include the CMSMS included jquery in a web page.
- is_base64() : bool
- Test if a string is a base64 encoded string
Functions
redirect()
Redirects to relative URL on the current site.
redirect(string $to) : mixed
If headers have not been sent this method will use header based redirection. Otherwise javascript redirection will be used.
Parameters
- $to : string
-
The url to redirect to
Tags
redirect_to_alias()
Given a page ID or an alias, redirect to it.
redirect_to_alias(mixed $alias) : mixed
Retrieves the URL of the specified page, and performs a redirect
Parameters
- $alias : mixed
-
An integer page id or a string page alias.
microtime_diff()
Calculate the difference in seconds between two microtime() values.
microtime_diff(string $a, string $b) : int
Parameters
- $a : string
-
Earlier microtime value
- $b : string
-
Later microtime value
Tags
Return values
int —The difference.
cms_join_path()
Joins a path together using platform specific directory separators.
cms_join_path() : string
Taken from: http://www.php.net/manual/en/ref.dir.php
This method should NOT be used for building URLS.
This method accepts a variable number of string arguments. i.e: $out = cms_join_path($dir1,$dir2,$dir3,$filename); or $out = cms_join_path($dir1,$dir2,$filename);
Tags
Return values
stringcms_relative_path()
Return the relative portion of a path
cms_relative_path(string $in[, string $relative_to = null ]) : string
Parameters
- $in : string
-
The input path or file specification
- $relative_to : string = null
-
The optional path to compute relative to. If not supplied the cmsms root path will be used.
Tags
Return values
string —The relative portion of the input string.
cms_htmlentities()
Perform HTML entity conversion on a string.
cms_htmlentities(string $val[, string $param = ENT_QUOTES ][, string $charset = "UTF-8" ][, bool $convert_single_quotes = false ]) : string
Parameters
- $val : string
-
The input string
- $param : string = ENT_QUOTES
-
A flag indicating how quotes should be handled (see htmlentities) (ignored)
- $charset : string = "UTF-8"
-
$val The input character set (ignored)
- $convert_single_quotes : bool = false
-
A flag indicating wether single quotes should be converted to entities.
Tags
Return values
string —the converted string.
debug_bt_to_log()
A function to output a backtrace into the generated log file.
debug_bt_to_log() : mixed
Tags
debug_bt()
A function to generate a backtrace in a readable format.
debug_bt() : mixed
This function does not return but echoes output.
debug_display()
Debug function to display $var nicely in html.
debug_display(mixed $var[, string $title = "" ][, bool $echo_to_screen = true ][, bool $use_html = true ][, bool $showtitle = TRUE ]) : string
Parameters
- $var : mixed
-
The data to display
- $title : string = ""
-
(optional) title for the output. If null memory information is output.
- $echo_to_screen : bool = true
-
(optional) Flag indicating wether the output should be echoed to the screen or returned.
- $use_html : bool = true
-
(optional) flag indicating wether html or text should be used in the output.
- $showtitle : bool = TRUE
-
(optional) flag indicating wether the title field should be displayed in the output.
Return values
stringdebug_output()
Display $var nicely only if $config["debug"] is set.
debug_output(mixed $var[, string $title = "" ]) : mixed
Parameters
- $var : mixed
- $title : string = ""
debug_to_log()
Debug function to output debug information about a variable in a formatted matter to a debug file.
debug_to_log(mixed $var[, string $title = '' ][, string $filename = '' ]) : mixed
Parameters
- $var : mixed
-
data to display
- $title : string = ''
-
optional title.
- $filename : string = ''
-
optional output filename
debug_buffer()
Display $var nicely to the CmsApp::get_instance()->errors array if $config['debug'] is set.
debug_buffer(mixed $var[, string $title = "" ]) : mixed
Parameters
- $var : mixed
- $title : string = ""
get_parameter_value()
Retrieve the $value from the $parameters array checking for $parameters[$value] and $params[$id.$value].
get_parameter_value(array<string|int, mixed> $parameters, string $value[, mixed $default_value = '' ][, string $session_key = '' ]) : mixed
Returns $default if $value is not in $params array. Note: This function will also trim() string values.
Parameters
- $parameters : array<string|int, mixed>
- $value : string
- $default_value : mixed = ''
- $session_key : string = ''
is_directory_writable()
Check the permissions of a directory recursively to make sure that we have write permission to all files.
is_directory_writable(string $path) : bool
Parameters
- $path : string
-
Start directory.
Return values
boolget_recursive_file_list()
Return an array containing a list of files in a directory performs a recursive search.
get_recursive_file_list(string $path, array<string|int, mixed> $excludes[, int $maxdepth = -1 ][, string $mode = "FULL" ][, d $d = 0 ]) : array<string|int, string>
Parameters
- $path : string
-
Start Path.
- $excludes : array<string|int, mixed>
-
Array of regular expressions indicating files to exclude.
- $maxdepth : int = -1
-
How deep to browse (-1=unlimited)
- $mode : string = "FULL"
-
"FULL"|"DIRS"|"FILES"
- $d : d = 0
-
for internal use only
Return values
array<string|int, string>recursive_delete()
A function to recursively delete all files and folders in a directory; synonymous with rm -r.
recursive_delete(string $dirname) : bool
Parameters
- $dirname : string
-
The directory name
Return values
boolchmod_r()
A function to recursively chmod all files and folders in a directory.
chmod_r(string $path, int $mode) : mixed
Parameters
- $path : string
-
The start location
- $mode : int
-
The octal mode Rolf: only used in admin/listmodules.php
Tags
startswith()
A convenience function to test wether one string starts with another.
startswith(string $str, string $sub) : bool
i.e: startswith('The Quick Brown Fox','The');
Parameters
- $str : string
-
The string to test against
- $sub : string
-
The search string
Return values
boolendswith()
Similar to the startswith method, this function tests with string A ends with string B.
endswith(string $str, string $sub) : bool
i.e: endswith('The Quick Brown Fox','Fox');
Parameters
- $str : string
-
The string to test against
- $sub : string
-
The search string
Return values
boolmunge_string_to_url()
Convert a human readable string into something that is suitable for use in URLS.
munge_string_to_url(string $alias[, bool $tolower = false ][, bool $withslash = false ]) : string
Parameters
- $alias : string
-
String to convert
- $tolower : bool = false
-
Indicates whether output string should be converted to lower case
- $withslash : bool = false
-
Indicates wether slashes should be allowed in the input.
Return values
stringini_get_boolean()
A convenience function to return a bool variable given a php ini key that represents a bool.
ini_get_boolean(string $str) : int
Parameters
- $str : string
-
The php ini key
Return values
intstack_trace()
Another convenience function to output a human-readable function stack trace.
stack_trace() : mixed
This method uses echo.
cms_move_uploaded_file()
A wrapper around move_uploaded_file that attempts to ensure permissions on uploaded files are set correctly.
cms_move_uploaded_file(string $tmpfile, string $destination) : mixed
Parameters
- $tmpfile : string
-
The temporary file specification
- $destination : string
-
The destination file specification
Tags
cms_ipmatches()
A function to test whether an IP address matches a list of expressions.
cms_ipmatches(string $ip, array<string|int, mixed> $checklist) : bool
Credits to J.Adams jna@retins.net
Expressions can be of the form xxx.xxx.xxx.xxx (exact) xxx.xxx.xxx.[yyy-zzz] (range) xxx.xxx.xxx.xxx/nn (nn = # bits, cisco style -- i.e. /24 = class C)
Parameters
- $ip : string
-
IP address to test
- $checklist : array<string|int, mixed>
-
Array of match expressions
Return values
bool —Rolf: only used in lib/content.functions.php
is_email()
Test if the string provided is a valid email address.
is_email(string $email[, bool $checkDNS = false ]) : bool
Parameters
- $email : string
- $checkDNS : bool = false
Return values
boolcms_to_bool()
A simple function to convert a string to a bool.
cms_to_bool(string $str) : mixed
accepts, 'y','yes','true',1 as TRUE (case insensitive) all other values represent FALSE.
Parameters
- $str : string
-
Input string to test. Rolf: only used in lib/classes/contenttypes/Content.inc.php
cms_get_jquery()
A function to return the appropriate HTML tags to include the CMSMS included jquery in a web page.
cms_get_jquery([string $exclude = '' ][, bool $ssl = null ][, bool $cdn = false ][, string $append = '' ][, string $custom_root = '' ][, bool $include_css = TRUE ]) : mixed
CMSMS is distributed with a recent version of jQuery, jQueryUI and various other jquery based libraries. This function generates the HTML code that will include these scripts.
See the {cms_jquery} smarty plugin for a convenient way of including the CMSMS provided jquery libraries from within a smarty template.
Known libraries: jquery jquery-ui nestedSortable json migrate
Parameters
- $exclude : string = ''
-
A comma separated list of script names or aliases to exclude.
- $ssl : bool = null
-
Force use of the ssl_url for the root url to necessary scripts.
- $cdn : bool = false
-
Force the use of a CDN url for the libraries if one is known
- $append : string = ''
-
A comma separated list of library URLS to the output
- $custom_root : string = ''
-
A custom root URL for all scripts (when using local mode). If this is spefied the $ssl param will be ignored.
- $include_css : bool = TRUE
-
Optionally output stylesheet tags for the included javascript libraries.
Tags
is_base64()
Test if a string is a base64 encoded string
is_base64(string $s) : bool
Parameters
- $s : string
-
The input string