Methods

get_db()

get_db() : \adodb

A convenience function to get an adodb object that supports exceptions.

Note: This function creates a new database abstraction object.

Returns

\adodb —

object

db_time()

db_time(integer  $unixtime, boolean  $trim = true) 

Convert the supplied unixtime into a database compatible datetime string

Parameters

integer $unixtime
boolean $trim

Wether or not to trim quotes from the output return string

unix_time()

unix_time(string|null  $string = null) : integer

Given a datatime string convert it to a unix time

Parameters

string|null $string

The datetime string

Returns

integer

get_image_extensions()

get_image_extensions() : string

A convenience method to return the list of allowed image extensions that a user is allowed to upload

Returns

string

get_module()

get_module(string  $module_name = '', string  $version = '') : object

A quick wrapper around cms_utils::get_module that will try to use a module name saved in tmpdata (the module name is stored in tmpdata in each request, for CGExtensions derived modules)

Parameters

string $module_name
string $version

The desired module version

Returns

object —

The module object. or null

get_cge()

get_cge() : object

A convenience function to get the CGExtensions module object reference

Returns

object —

The CGExtensions module object.

get_mime_type()

get_mime_type(string  $filename) : string

Given a file name, return it's mime type

Requires the fileinfo php extension (which is included by default since PHP 5.3) Throws an exception if the fileinfo extension is not available.

Parameters

string $filename
  • The file name.

Returns

string —

The returned mime type or null

send_data_and_exit()

send_data_and_exit(string  $data, string  $content_type = 'text/plain', string  $filename = 'report.txt') 

A convenience method to send a text file (like a CSV file) to the browser and exit This is a convenience method. It also handles clearing any data that has already been sent to output buffers.

Parameters

string $data

The output data

string $content_type

The output MIME type

string $filename

The output filename

view_file_and_exit()

view_file_and_exit(string  $file, string  $mime_type = null, string  $filename = null) 

A convenience method to view a file in the browser.

This is a convenience method. It also handles clearing any data that has already been sent to output buffers.

Parameters

string $file

The absolute path to the output file

string $mime_type

The output mime type

string $filename

The output filename (suggested to the browser)

send_file_and_exit()

send_file_and_exit(string  $file, integer  $chunksize = 65535, string  $mime_type = '', string  $filename = '') 

A convenience method to download a file to the browser, and then exit the current request This method is useful when the user has requested to download a large file.

This is a convenience method. It also handles clearing any data that has already been sent to output buffers.

Parameters

string $file

The absolute path to the output file

integer $chunksize

The amount of data to read from the file at one time

string $mime_type

The output mime type

string $filename

The output filename (suggested to the browser)

send_ajax_and_exit()

send_ajax_and_exit(mixed  $output) 

Given an output array or object, encode it to json, and exit.

This is a convenience method. It also handles clearing any data that has already been sent to output buffers.

Parameters

mixed $output

get_real_ip()

get_real_ip() : string

Use various methods to return the users real IP address.

including when using a proxy server.

Returns

string

to_bool()

to_bool(mixed  $in, boolean  $strict = FALSE) : boolean

Given a string input that theoretically represents a boolean value return either true or false.

Parameters

mixed $in

input value

boolean $strict

Whether strict testing should be used.

Returns

boolean

get_browser()

get_browser() : \cge_browser

Get the singleton cge_browser object.

Returns

\cge_browser

fgets()

fgets(resource  $fh) : string

A platform independent fgets utility.

This method understands MAC (\r) as well as DOS/Unix line endings

Parameters

resource $fh

Returns

string —

or null

coalesce()

coalesce() : \The

Return the first non null argument.

This method accepts a variable number of arguments.

Returns

\The —

first non null argument

get_param()

get_param(\hash  $params, string  $key, mixed  $dflt = null) : mixed

Given an associative array, extract the value of one key, with a default.

If the key does not exist in the array

Parameters

\hash $params

The input associative array

string $key

The input key to search for

mixed $dflt

The default value

Returns

mixed —

The value of the element in the array, or the default

get_empty_param()

get_empty_param(\hash  $params, string  $key, mixed  $dflt = null) : mixed

Given an associative array, extract the value of one key, with a default.

If the key does not exist in the array, or it's value is empty, then the default is used.

Parameters

\hash $params

The input associative array

string $key

The input key to search for

mixed $dflt

The default value

Returns

mixed —

The value of the element in the array, or the default

src_to_file()

src_to_file(string  $src) : string

Given a src specification attempt to resolve it into a filename on the server

algorithm:

  1. Check for an absolute filename
  2. Test if the string starts with the uploads url
    • replace with uploads path
    • check if file exists
  3. Test if the string starts with the root url
    • replace with root path
    • check if file exists
  4. If string starts with /
    • prepend root path
    • check if file exists
  5. assume string is relative to uploads path
    • checkk if file exists
  6. Test if string starts with the ssl url
    • replace with root path
    • check if file exists

Parameters

string $src

the source

Returns

string —

The filename (if possible).

ssl_request()

ssl_request() : boolean

Test if the current request is for a secure connection

Returns

boolean

file_to_url()

file_to_url(string  $file, boolean  $force_ssl = FALSE) : string

Convert a filename to a URL.

If an absolute path is specified tests are done to compare the input to the image uploads path, the uploads path or the root path of the system. If a relative URL path is passed a file relative to the root url is assumed.

Parameters

string $file

the filename to convert to a URL

boolean $force_ssl

Force the output url to use HTTPS

Returns

string —

or null

have_enough_memory()

have_enough_memory(integer  $needed_memory, float  $fudge = 2.0) : boolean

An experimental method that attempts to determine if there is enough available PHP memory for a given operation.

Parameters

integer $needed_memory

The estimated amount of memory required

float $fudge

The fudge factor (multiplier) used to buffer available memory.

Returns

boolean

get_available_memory()

get_available_memory() : integer

An experimental method to determine the amount of available PHP memory remaining

Returns

integer

clean_input_html()

clean_input_html(string  $html) : string

Pretty up, sanitize, and clean user entered html code.

Parameters

string $html

Returns

string

parse_float()

parse_float(string  $floatString, string  $thousands_sep = null, string  $decimal_pt = null) 

a convenience method to convert a string representing a float value into a float

Parameters

string $floatString

the input string

string $thousands_sep

The thousands separator

string $decimal_pt

The decimal point

encrypt_params()

encrypt_params(array  $params) : array

A utility function to encrypt parameters for passing through different URL's.

This method accepts a parameter array, encrypts it, and returns a parameter array with a single element: _d.

Parameters

array $params

an associative array

Returns

array

decrypt_params()

decrypt_params(array  $params) : array

A utility function to decrypt previously encrypted parameters.

This method accepts a parameter array (the output from it's companion method) and decrypts the input.

Parameters

array $params

an encrypted associative array with at least one element: _d.

Returns

array

done_today()

done_today(string  $key) : boolean

A convenience function to assist in doing certain tasks only once per day.

This method will convert the key into a preference, and then check the value of that preference if it is more than 24 hours since the last time this method was called for this preference then the value of the preference is updated to the current time and FALSE is returned. Otherwise TRUE is returned.

Parameters

string $key

Returns

boolean

swap()

swap(mixed  $a, mixed  $b) 

Swap to variables.

Probably should not be used where cloning may be required.

Parameters

mixed $a
mixed $b

log_exception()

log_exception(\Exception  $e) 

Dump an exception to the error log.

Parameters

\Exception $e

create_guid()

create_guid() : string

Create a unique guid

Returns

string

find_image_thumbnail()

find_image_thumbnail(string  $filename) : string|null

Given a thumbnail, return the path to the thumbnail if it exists.

Parameters

string $filename

Returns

string|null

create_image_thumbnail()

create_image_thumbnail(string  $filename) : string|null

A convenience function to generate a standardized thumbnail for an image.

Parameters

string $filename

The complete path to the image file

Returns

string|null —

The path to the thumbnail file.

get_obfuscated_file_url()

get_obfuscated_file_url(integer  $page_id, string  $filename, boolean  $download = null) : string

A convenience function to generate a URL that obfuscates a filename, but allows download.

Parameters

integer $page_id

A page id to use for displaying the file.

string $filename

The complete pathname

boolean $download

Whether the file should be forced to download, or whether the browser can handle it

Returns

string —

A url that allows view or download of the image, but obfuscates the file name and path.

create_csrf_inputs()

create_csrf_inputs() : string

Create HTML elements for a form that contain CSRF keys.

this method also stores data in the session for use by the valid_form_csrf() method.

Returns

string —

HTML form elements as a string.

valid_form_csrf()

valid_form_csrf() : true|null

Given variables available in $_POST generated by the create_csrf_inputs() method validate their values with the data stored in the session.

This method will always return true if 'ignore_cge_csrf' is enabled in the config.php

Returns

true|null —

True if the CSRF data in $_POST matches that in the session. Null/fallse otherwise.

get_thumbnail_name()

get_thumbnail_name(string  $filename) : string

Given a complete path and filename get a proposed filename for the thumbnail.

Parameters

string $filename

A complete path to an image file

Returns

string —

or null