Helpers
Various functions used throughout Chyrp’s code.
Summary
| Helpers | Various functions used throughout Chyrp’s code. |
| Variables | |
| $time_start | Times Chyrp. |
| $l10n | Stores loaded gettext domains. |
| Functions | |
| session | Begins Chyrp’s custom session storage whatnots. |
| error | Shows an error message. |
| show_403 | Shows an error message with a 403 HTTP header. |
| logged_in | Returns whether or not they are logged in by returning the Visitor.$id (which defaults to 0). |
| load_translator | Loads a .mo file for gettext translation. |
| __ | Returns a translated string. |
| _p | Returns a plural (or not) form of a translated string. |
| _f | Returns a formatted translated string. |
| redirect | Redirects to the given URL and exits immediately. |
| url | Mask for Route->url(). |
| pluralize | Returns a pluralized string. This is a port of Rails’s pluralizer. |
| depluralize | Returns a depluralized string. This is the inverse of pluralize. |
| truncate | Truncates a string to the given length, optionally taking into account HTML tags, and/or keeping words in tact. |
| when | Returns date formatting for a string that isn’t a regular time() value |
| datetime | Returns a standard datetime string based on either the passed timestamp or their time offset, usually for MySQL inserts. |
| fix | Returns a HTML-sanitized version of a string. |
| unfix | Returns the reverse of fix(). |
| lang_code | Returns the passed language code (e.g. en_US) to the human-readable text (e.g. English (US)) |
| sanitize | Returns a sanitized string, typically for URLs. |
| trackback_respond | Responds to a trackback request. |
| trackback_send | Sends a trackback request. |
| send_pingbacks | Sends pingback requests to the URLs in a string. |
| grab_urls | Crawls a string for links. |
| pingback_url | Checks if a URL is pingback-capable. |
| camelize | Converts a given string to camel-case. |
| decamelize | Decamelizes a string. |
| selected | If $val1 == $val2, outputs or returns selected=”selected” |
| checked | If $val == 1 (true), outputs ‘ checked=”checked”’ |
| module_enabled | Returns whether the given module is enabled or not. |
| feather_enabled | Returns whether the given feather is enabled or not. |
| fallback | Sets a given variable if it is not set. |
| oneof | Returns the first argument that is set and non-empty. |
| random | Returns a random string. |
| unique_filename | Makes a given filename unique for the uploads directory. |
| upload | Moves an uploaded file to the uploads directory. |
| upload_from_url | Copy a file from a specified URL to their upload directory. |
| uploaded | Returns a URL to an uploaded file. |
| timer_start | Starts the timer. |
| timer_stop | Stops the timer and returns the total time. |
| normalize | Attempts to normalize all newlines and whitespace into single spaces. |
| get_remote | Grabs the contents of a website/location. |
| self_url | Returns the current URL. |
| show_404 | Shows a 404 error message and immediately exits. |
| set_locale | Set locale in a platform-independent way |
| sanitize_input | Makes sure no inherently broken ideas such as magic_quotes break our application |
| match | Try to match a string against an array of regular expressions. |
| cancel_module | Temporarily removes a module from $config->enabled_modules. |
| time_in_timezone | Returns the appropriate time() for representing a timezone. |
| timezones | Returns an array of timezones that have unique offsets. Doesn’t count deprecated timezones. |
| set_timezone | Sets the timezone. |
| get_timezone() | Returns the current timezone. |
| error_panicker | Exits and states where the error occurred. |
| keywords | Handle keyword-searching. |
| init_extensions | Initialize all Modules and Feathers. |
| xml2arr | Recursively converts a SimpleXML object (and children) to an array. |
| arr2xml | Recursively adds an array (or object I guess) to a SimpleXML object. |
| relative_time | Returns the difference between the given timestamps or now. |
| list_notate | Notates an array as a list of things. |
| Send an email. Function arguments are exactly the same as the PHP mail() function. | |
| now | Alias to strtotime, for prettiness like now(“+1 day”). |
| comma_sep | Convert a comma-seperated string into an array of the listed values. |
logged_in
function logged_in()
Returns whether or not they are logged in by returning the Visitor.$id (which defaults to 0).
redirect
| function redirect( | $url, | |||
| $use_chyrp_url | = | false | ) |
Redirects to the given URL and exits immediately.
Parameters
| $url | The URL to redirect to. If it begins with / it will be relative to the Config.chyrp_url. |
| $use_chyrp_url | Use the Config.chyrp_url instead of Config.url for $urls beginning with /? |
depluralize
| function depluralize( | $string, | |||
| $number | = | null | ) |
Returns a depluralized string. This is the inverse of pluralize.
Parameters
| $string | The string to depluralize. |
| $number | If passed, and this number is not 1, it will not depluralize. |
truncate
| function truncate( | $text, | |||
| $length | = | 100, | ||
| $ending | = | "...", | ||
| $exact | = | false, | ||
| $html | = | false | ) |
Truncates a string to the given length, optionally taking into account HTML tags, and/or keeping words in tact.
Parameters
| $text | String to shorten. |
| $length | Length to truncate to. |
| $ending | What to place at the end, e.g. “...”. |
| $exact | Break words? |
| $html | Auto-close cut-off HTML tags? |
Author
CakePHP team, code style modified.
unique_filename
| function unique_filename( | $name, | |||
| $path | = | "", | ||
| $num | = | 2 | ) |
Makes a given filename unique for the uploads directory.
Parameters
| $name | The name to check. |
| $path | Path to check in. |
| $num | Number suffix from which to start increasing if the filename exists. |
Returns
A unique version of the given $name.
upload
| function upload( | $file, | |||
| $extension | = | null, | ||
| $path | = | "", | ||
| $put | = | false | ) |
Moves an uploaded file to the uploads directory.
Parameters
| $file | The $_FILES value. |
| $extension | An array of valid extensions (case-insensitive). |
| $path | A sub-folder in the uploads directory (optional). |
| $put | Use copy() instead of move_uploaded_file()? |
Returns
The resulting filename from the upload.
keywords
| function keywords( | $query, | |||
| $plain, | ||||
| $table | = | null | ) |
Handle keyword-searching.
Parameters
| $query | The query to parse. |
| $plain | WHERE syntax to search for non-keyword queries. |
| $table | If specified, the keywords will be checked against this table’s columns for validity. |
Returns
An array containing the “WHERE” queries and the corresponding parameters.