Introduction to Helpers

The file helpers.php contains a cornucopia of useful helper functions to assist feather and module development. Each function is fully documented in the source file.


logged_in()Returns whether or not the visitor is logged in.
authenticate()Generates or validates an authentication token for the session.


redirect()Redirects to the supplied URL and exits immediately.
self_url()Returns an absolute URL[note] for the current request.
show_403()Shows an error message with a 403 HTTP header.
show_404()Shows an error message with a 404 HTTP header.
url()Generate the canonical URL[note] for an action e.g. url('login').


lang_code()Converts a language code to a localised display name.
lang_base()Extracts the primary language subtag for the supplied code.
__()Translates a string using PHP-gettext.
_f()Translates a string with sprintf() formatting.
_p()Translates a plural (or not) form of a string.

See also: Localizing Extensions.


datetime()Formats datetime for SQL queries.
now()Alias to strtotime(), for prettiness like now("+1 day").
when()Formats a string that isn't a regular time() value.

Variable Manipulation

fallback()Sets the supplied variable if it is not already set.
keywords()Parse keyword searches for values in specific database columns.
match()Try to match a string against an array of regular expressions.
oneof()Returns a value from the supplied set of arguments.
derezz()Strips tags from the supplied variable and tests it for emptiness.
random()Generates a string of alphanumeric random characters.
shorthand_bytes()Decode shorthand bytes notation from php.ini.
slug()Generates a random slug value for posts and pages.
token()Salt and hash a unique token using the supplied data.

String Manipulation

camelize()Converts a string to camel-case.
decamelize()Undoes camel-case conversion.
depluralize()Singularizes a word.
fix()Neutralizes HTML and quotes in strings for display.
normalize()Attempts to normalize all newlines and whitespace into single spaces.
pluralize()Pluralizes a word.
sanitize()Sanitizes a string of troublesome characters, typically for use in URLs.
sanitize_html()Sanitize HTML to disable scripts and obnoxious attributes.
truncate()Truncates a string to the requested number of characters or less.
unfix()Undoes neutralization of HTML and quotes in strings.

Remote Fetches

get_remote()Retrieve the contents of a URL.
grab_urls()Crawls a string and grabs hyperlinks from it.
merge_urls()Combines a base URL and relative path into a target URL.

Modules and Feathers

feather_enabled()Determines if a feather is currently enabled and not cancelled.
cancel_module()Temporarily declares a module cancelled (disabled).
cancel_feather()Temporarily declares a feather cancelled (disabled).
module_enabled()Determines if a module is currently enabled and not cancelled.

Upload Management

unique_filename()Generates a unique name for the supplied file in the uploads directory.
upload()Validates and moves an uploaded file to the uploads directory.
upload_from_url()Copy a file from a remote URL to the uploads directory.
uploaded()Generates an absolute URL[note] or filesystem path to an uploaded file.
uploaded_search()Returns an array of files discovered in the uploads directory.
upload_tester()Tests uploaded file information to determine if the upload was successful.

Input Validation and Processing

add_scheme()Prefixes a URL with a scheme if none was detected. addScheme() is the client-side equivalent.
check_captchaChecks the response to a captcha.
generate_captcha()Generates a captcha form element.
get_gravatar()Get either a Gravatar URL or complete image tag for a specified email address.
is_email()Does the string look like an email address? isEmail() is the client-side equivalent.
is_url()Does the string look like a web URL? isURL() is the client-side equivalent.
password_strength()Award a numeric score for the strength of a password. passwordStrength() is the client-side equivalent.

Responding to Requests

correspond()Send an email correspondence to a user about an action we took.
file_attachment()Send a file attachment to the visitor.
json_response()Send a structured JSON response.
json_get()JSON decodes a value and checks for errors.
json_set()JSON encodes a value and checks for errors.
zip_archive()Creates a basic flat Zip archive from an array of items.

See also: Adding Ajax Functionality.