Global functions

General purpose functions, globally available.

Functions

getPost

Definition

Name
getPost
Syntax
String|false = getPost( String $which );

Description

Get and sanitize the value of $which from the $_POST array.

Parameters

$which
String index to get from $_POST array.

Return values

String Sanitized value contained in the $which index of $_POST array. false if index is not set.

Examples

getPost("name")

Gets the content of $_POST["name"]

Dependencies

PHP
  • if...else
  • isset
Janitor
  • prepareForDB

getPosts

Definition

Name
getPosts
Syntax
Array|false = getPost( Array $which );

Description

Get and sanitize the values passed in $which from the $_POST array.

Parameters

$which
Array array of indicies to get from $_POST array.

Return values

Array array of sanitized values, using the values of $which as indices of $_POST array. false if index is not set.

Examples

getPosts(["name","address"])

Gets the content of $_POST["name"] and $_POST["address"]

[ "name" => "King Kong", "address" => "New York City" ]

Dependencies

PHP
  • if...else
  • foreach
  • isset
Janitor
  • prepareForDB

getPostPassword

Definition

Name
getPostPassword
Syntax
String|false = getPostPassword( String $which );

Description

Get the value of $which from the $_POST array – without sanitation. Needed for passwords.

Parameters

$which
String index to get from $_POST array.

Return values

String value contained in the $which index of $_POST array. false if index is not set.

Examples

getPostPassword("name")

Gets the content of $_POST["name"]

Dependencies

PHP
  • if...else
  • isset
Janitor

None

prepareForDB

Definition

Name
prepareForDB
Syntax
String|Array = prepareForDB( String|Array $string );

Description

Prepare string for injection in database, by stripping invalid tags and attributes and checking it with the mysqli::escape_string method. This is applied every time you get posted values using getPost or getVar.

Parameters

$string
String|Array String or Array of strings to be prepared for database injection.

Return values

String|Array Sanitized string or array or strings.

Examples

prepareForDB("Hej <script>alert('Hej');</script>");

Returns:

Hej alert(\'Hej\');
prepareForDB("Hej <span>alert(\"Hej\”);</span>");

Returns:

Hej <span>alert(\\\"Hej\\\");</span>

Dependencies

PHP
  • if...else
  • is_array
  • foreach
  • addslashes
  • mysqli::escape_string
Janitor
  • stripDisallowed

prepareForHTML

Definition

Name
prepareForHTML
Syntax
String|Array = prepareForHTML( String|Array $string );

Description

Prepare an already DB prepared string (or array of strings) for being used in HTML context, by stripping any slashes added during data transaction.

This is used if a submitted value needs to be returned to the screen, perhaps due to an error.

Parameters

$string
String|Array String or array of strings.

Return values

String|Array Sanitized string or array of strings.

Examples

prepareForHTML("Hello \'you\'");

Returns:

Hello 'you'

Dependencies

PHP
  • is_array
  • foreach
  • stripslashes
Janitor

none

stripDisallowed

Definition

Name
stripDisallowed
Syntax
String = stripDisallowed( String $string );

Description

Strips string of potential harmful elements. Content of removed elements, will be kept as text.

Only the following tags are allowed: <a>, <strong>, <em>, <sup>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <p>, <label>, <br>, <hr>, <ul>, <ol>, <li>, <dd>, <dl>, <dt>, <span>, <img>, <div>, <table>, <tr>, <td>, <th>, <code>

Only the following attributes are allowed: href, class, width, height, alt, charset. The href must start with /, http://, https://, mailto:, tel:. Otherwise the href property will be removed.

Parameters

$string
String String to sanitize

Return values

String Sanitized string

Examples

stripDisallowed("Hej <script>alert('Hej');</script>");

Removes the script tag and returns:

Hej alert('Hej');
stripDisallowed("Hej <span class="test" style="color: red;">Hej</span>");

Removed the invalid style attribute and returns:

Hej <span class="test">Hej</span>
stripDisallowed("Hej <a href="/test">Hej</a>");

Everything valid, returns:

Hej <a href="/test">Hej</a>
stripDisallowed("Hej <a href="test">Hej</a>");

Removed the invalid relative url and returns:

Hej <a>Hej</a>

Dependencies

PHP
  • strip_tags
  • trim
  • html_entity_decode
Janitor
  • DOM()
  • DOM()->createDOM
  • DOM()->stripAttributes

_functionname_

Definition

Name
_functionname_
Shorthand
_functionshorthand_
Syntax
_returntype_ = _functionname_( String format [, Mixed timestamp ] );

Description

_description_

Parameters

_var_
_type_ _summary_
Options
_value_
_description_
identifier
_type_ _summary_

Return values

_type_ _returnsummary_

Examples

Dependencies

PHP
  • _function_
Janitor
  • _function_

Class shorthands

The following are Class shorthand methods design to make certain classes recyclable and globally available

DOM

Definition

Name
DOM
Syntax
DOM = DOM();

Description

Includes the DOM class and creates a new instance of the class on first use and reuse this instance for all subsequent uses.

Parameters

None

Return values

DOM Returns an instance of the DOM class.

Examples

DOM()->createDom($html);

Returns a DOM object with the content of $html.

Dependencies

PHP
  • include_once
Janitor
  • DOM

mailer

Definition

Name
mailer
Syntax
MailGateway = mailer();

Description

Includes the MailGateway class and creates a new instance of the class on first use and reuse this instance for all subsequent uses.

Parameters

None

Return values

MailGateway Returns an instance of the MailGateway class.

Examples

mailer()->send($data);

Sends a mail based on $data.

Dependencies

PHP
  • include_once
Janitor
  • MailGateway