# \cge_utils

A set of high level convenience methods.

## Summary

Methods
Properties
Constants
get_db()
db_time()
unix_time()
get_image_extensions()
get_module()
get_cge()
get_mime_type()
send_data_and_exit()
view_file_and_exit()
send_file_and_exit()
send_ajax_and_exit()
get_real_ip()
to_bool()
get_browser()
fgets()
coalesce()
get_param()
src_to_file()
ssl_request()
file_to_url()
have_enough_memory()
get_available_memory()
clean_input_html()
parse_float()
encrypt_params()
decrypt_params()
done_today()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A
final

File
  lib/class.cge_utils.php
Package
  \CGExtensions
Class hierarchy
  \cge_utils

## Tags

todo |

## Methods

### get_db()

    get_db() : \adodb

A convenience function to get an adodb object that supports exceptions

#### Returns

\adodb —

object

#

static

## Tags

todo |

### db_time()

    db_time(int $unixtime, bool $trim)

Convert the supplied unixtime into a database compatible datetime string

#### Parameters

int | $unixtime |
bool | $trim | Wether or not to trim quotes from the output return string

#

static

#### Deprecated

## Tags

todo |

### unix_time()

    unix_time(string $string) : int

Given a datatime string convert it to a unix time

#### Parameters

string | $string | The datetime string

#### Returns

int

#

static

## Tags

todo |

### 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

#

static

#### Deprecated

## Tags

todo |

### 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

#

static

#### Deprecated

See also

## Tags

todo |

### get_cge()

    get_cge() : object

A convenience function to get the CGExtensions module object reference

#### Returns

object —

The CGExtensions module object.

#

static

See also

## Tags

todo |

### 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.

#

static

## Tags

todo |

### send_data_and_exit()

    send_data_and_exit(string $data, string $content_type, string $filename)

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

#

static

## Tags

todo |

### view_file_and_exit()

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

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)

#

static

## Tags

todo |

### send_file_and_exit()

    send_file_and_exit(string $file, int $chunksize, 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
int | $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)

#

static

## Tags

todo |

### 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 |

#

static

## Tags

todo |

### 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

#

static

## Tags

todo |

### to_bool()

    to_bool(mixed $in, boolean $strict) : bool

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

bool

#

static

## Tags

todo |

### get_browser()

    get_browser() : \cge_browser

Get the singleton cge_browser object.

#### Returns

\cge_browser

#

static

## Tags

todo |

### 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

#

static

See also

## Tags

todo |

### coalesce()

    coalesce() : \The

Return the first non null argument.

This method accepts a variable number of arguments.

#### Returns

\The —

first non null argument

#

static

## Tags

todo |

### get_param()

    get_param(\hash $params, string $key, mixed $dflt) : 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

#

static

## Tags

todo |

### 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).

#

static

## Tags

todo |

### ssl_request()

    ssl_request() : bool

Test if the current request is for a secure connection

#### Returns

bool

#

static

## Tags

todo |

### file_to_url()

    file_to_url(string $file, bool $force_ssl) : 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
bool | $force_ssl | Force the output url to use HTTPS

#### Returns

string

#

static

## Tags

todo |

### have_enough_memory()

    have_enough_memory(int $needed_memory, float $fudge) : bool

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

#### Parameters

int | $needed_memory | The estimated amount of memory required
float | $fudge | The fudge factor (multiplier) used to buffer available memory.

#### Returns

bool

#

static

## Tags

todo |

### get_available_memory()

    get_available_memory() : int

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

#### Returns

int

#

static

## Tags

todo |

### clean_input_html()

    clean_input_html(string $html) : string

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

#### Parameters

string | $html |

#### Returns

string

#

static

## Tags

todo |

### parse_float()

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

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

#

static

#### Deprecated

## Tags

todo |

### encrypt_params()

    encrypt_params( $params)

#### Parameters

| $params |

#

static

## Tags

todo |

### decrypt_params()

    decrypt_params( $params)

#### Parameters

| $params |

#

static

## Tags

todo |

### done_today()

    done_today(string $key) : bool

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

bool

#

static

## Tags

todo |

### class.cge_utils.php