Static Public Member Functions | Static Public Attributes

Utils Class Reference

List of all members.

Static Public Member Functions

static get_params ($params)
static end_in_slash ($value)
static redirect ($url= '', $continue=false)
static atomtime ($t)
static nonce ()
static WSSE ($nonce= '', $timestamp= '')
static stripslashes ($value)
static addslashes ($value)
static de_amp ($value)
static revert_magic_quotes_gpc ()
static quote_spaced ($value)
static implode_quoted ($separator, $values)
static placeholder_string ($count)
static archive_pages ($item_total, $items_per_page=null)
static map_array ($value, $prefix= '{$', $postfix= '}')
static debug_reveal ($show, $hide, $debugid, $close=false)
static debug ()
static firedebug ()
static firebacktrace ($backtrace)
static crypt ($password, $hash=null)
static sha1 ($password, $hash=null)
static md5 ($password, $hash=null)
static ssha ($password, $hash=null)
static ssha512 ($password, $hash=null)
static getdate ($timestamp)
static locale_date ($format, $timestamp)
static slugify ($string, $separator= '-')
static html_select ($name, $options, $current=null, $properties=array())
static html_checkboxes ($name, $options)
static truncate ($str, $len=10, $middle=true)
static php_check_syntax ($code, &$error=null)
static php_check_file_syntax ($file, &$error=null)
static glob ($pattern, $flags=0)
static human_size ($bytesize)
static single_array ($element)
static mimetype ($filename)
static trail ($value=false)
static mail ($to, $subject, $message, $headers=array(), $parameters= '')
static random_password ($length=10)
static array_or ($input)
static ror ($v, $w)
static check_request_method ($expected)
static glob_to_regex ($glob)
static scheme_ports ($scheme=null)
static is_traversable ($data)
static get_ip ()
static htmlspecialchars ($string, $quote_flag=ENT_COMPAT, $encoding= 'UTF-8')
static regexdelim ($string, $choices=null)
static html_attr ($attrs)

Static Public Attributes

static $debug_defined = false

Detailed Description

Habari Utility Class

Definition at line 11 of file utils.php.


Member Function Documentation

static Utils::addslashes ( value  )  [static]

function addslashes Adds slashes to escape strings, including strings in arrays

Definition at line 140 of file utils.php.

Referenced by firebacktrace(), and firedebug().

static Utils::archive_pages ( item_total,
items_per_page = null 
) [static]

function archive_pages Returns the number of pages in an archive using the number of items per page set in options

Parameters:
integer Number of items in the archive
integer Number of items per page
Returns:
integer Number of pages based on pagination option.

Definition at line 230 of file utils.php.

Referenced by Theme::theme_next_page_link(), and Theme::theme_page_selector().

static Utils::array_or ( input  )  [static]

Does a bitwise OR of all the numbers in an array

Parameters:
array $input An array of integers
Returns:
int The bitwise OR of the input array

Definition at line 951 of file utils.php.

Referenced by Post::get_access(), Comment::get_access(), and ACL::grant_group().

static Utils::atomtime ( t  )  [static]

function atomtime Returns RFC-3339 time from a time string or integer timestamp

Parameters:
mixed A string of time or integer timestamp
Returns:
string An RFC-3339 formatted time

Definition at line 73 of file utils.php.

static Utils::check_request_method ( expected  )  [static]
static Utils::crypt ( password,
hash = null 
) [static]

Crypt a given password, or verify a given password against a given hash.

Todo:
Enable best algo selection after DB schema change.
Parameters:
string $password the password to crypt or verify
string $hash (optional) if given, verify $password against $hash
Returns:
crypted password, or boolean for verification

Definition at line 400 of file utils.php.

Referenced by UserHandler::act_password_reset(), User::authenticate(), AdminUsersHandler::form_user_success(), AdminUsersHandler::post_users(), CronTab::run_cron(), and WSSE().

static Utils::de_amp ( value  )  [static]

function de_amp Returns & entities in a URL querystring to their previous & glory, for use in redirects

Parameters:
string $value A URL, maybe with a querystring

Definition at line 156 of file utils.php.

static Utils::debug (  )  [static]

Outputs a call stack with parameters, and a dump of the parameters passed. mixed Any number of parameters to output in the debug box.

Definition at line 272 of file utils.php.

Referenced by UserThemeHandler::act(), and Term::setslug().

static Utils::debug_reveal ( show,
hide,
debugid,
close = false 
) [static]

Helper function used by debug() Not for external use.

Definition at line 257 of file utils.php.

Referenced by debug().

static Utils::end_in_slash ( value  )  [static]

function end_in_slash Forces a string to end in a single slash

Parameters:
string A string, usually a path
Returns:
string The string with the slash added or extra slashes removed, but with one slash only

Definition at line 46 of file utils.php.

Referenced by Themes::get_active().

static Utils::firebacktrace ( backtrace  )  [static]

Utils::firebacktrace()

Parameters:
array $backtrace An array of backtrace details from debug_backtrace()
Returns:
string Javascript output that will display the backtrace in the Firebug console.

Definition at line 359 of file utils.php.

Referenced by firedebug().

static Utils::firedebug (  )  [static]

Outputs debug information like debug() but using Firebug's Console. mixed Any number of parameters to output in the debug box.

Definition at line 338 of file utils.php.

static Utils::get_ip (  )  [static]

Get the remote IP address, but try and take into account users who are behind proxies, whether they know it or not.

Returns:
The client's IP address.

Definition at line 1050 of file utils.php.

Referenced by FeedbackHandler::add_comment(), SpamChecker::get_code(), EventLog::log(), Session::read(), Session::write(), and Pingback::xmlrpc_pingback__ping().

static Utils::get_params ( params  )  [static]

function get_params Returns an associative array of parameters, whether the input value is a querystring or an associative array.

Parameters:
mixed An associative array or querystring parameter list
Returns:
array An associative array of parameters

Definition at line 30 of file utils.php.

Referenced by QueryRecord::__construct(), CronJob::__construct(), ActionHandler::act_redirect(), URL::extract_args(), UserGroups::get(), Post::get(), LogEntry::get(), EventLog::get(), Users::get(), Posts::get(), Comments::get(), and Format::more().

static Utils::getdate ( timestamp  )  [static]

Return an array of date information Just like getdate() but also returns 0-padded versions of day and month in mday0 and mon0

Parameters:
integer $timestamp A unix timestamp
Returns:
array An array of date data

Definition at line 544 of file utils.php.

static Utils::glob ( pattern,
flags = 0 
) [static]

Replacement for system glob that returns an empty array if there are no results

Parameters:
string $pattern The glob() file search pattern
integer $flags Standard glob() flags
Returns:
array An array of result files, or an empty array if no results found

Definition at line 749 of file utils.php.

Referenced by FileCache::_purge(), Themes::get_all(), Themes::get_all_data(), Site::get_dir(), AdminHandler::get_sysinfo(), HabariLocale::list_all(), Plugins::list_all(), HabariSilo::silo_dir(), HabariSilo::silo_get(), RawPHPEngine::template_exists(), and DatabaseConnection::upgrade().

static Utils::glob_to_regex ( glob  )  [static]

Returns a regex pattern equivalent to the given glob pattern

Returns:
string regex pattern with '/' delimiter

Definition at line 988 of file utils.php.

Referenced by FileCache::_expire(), and APCCache::_expire().

static Utils::html_attr ( attrs  )  [static]

Create a list of html element attributes from an associative array

Parameters:
array $attrs An associative array of parameters
Returns:
string The parameters turned into a string of tag attributes

Definition at line 1144 of file utils.php.

Referenced by Format::term_tree().

static Utils::html_checkboxes ( name,
options 
) [static]

Creates one or more HTML checkboxes

Parameters:
string The name of the checkbox element. If there are multiple checkboxes for the same name, this method will automatically apply "[]" at the end of the name
array An array of checkbox options. Each element should be an array containing "name" and "value". If the checkbox should be checked, it should have a "checked" element.
Returns:
string The HTML of the checkboxes

Definition at line 630 of file utils.php.

static Utils::html_select ( name,
options,
current = null,
properties = array() 
) [static]

Create an HTML select tag with options and a current value

Parameters:
string $name The name and id of the select control
array $options An associative array of values to use as the select options
string $current The value of the currently selected option
array $properties An associative array of additional properties to assign to the select control
Returns:
string The select control markup

Definition at line 602 of file utils.php.

Referenced by AdminUsersHandler::get_user().

static Utils::htmlspecialchars ( string,
quote_flag = ENT_COMPAT,
encoding = 'UTF-8' 
) [static]

Call htmlspecialchars() with the correct flags and encoding, without double escaping strings. See http://php.net/manual/en/function.htmlspecialchars.php for details on the parameters and purpose of the function.

Todo:
Should htmlspecialchars_decode() be used instead of html_entity_decode()?
Parameters:
$string. string. The string to escape
$quote_flag. integer. Sets what quotes and doublequotes are escaped
$encoding. string. The encoding of the passed string
Returns:
The escaped string

Definition at line 1086 of file utils.php.

Referenced by AtomHandler::act_introspection(), FlickrSilo::action_plugin_ui_confirm(), AtomHandler::add_comments(), AtomHandler::add_posts(), AtomHandler::create_atom_wrapper(), AtomHandler::get_entry(), HiEngineParser::hi_command(), html_attr(), and AdminPostsHandler::post_delete_post().

static Utils::human_size ( bytesize  )  [static]

Produces a human-readable size string. For example, converts 12345 into 12.34KB

Parameters:
integer $bytesize Number of bytes
Returns:
string Human-readable string

Definition at line 784 of file utils.php.

Referenced by ViddlerSilo::filter_media_panels().

static Utils::implode_quoted ( separator,
values 
) [static]

function implode_quoted Behaves like the implode() function, except it quotes values that contain spaces

Parameters:
string A separator between each value
array An array of values to separate
Returns:
string The concatenated string

Definition at line 197 of file utils.php.

static Utils::is_traversable ( data  )  [static]

determines if the given that is travesable in foreach

Parameters:
mixed $data
Returns:
bool

Definition at line 1040 of file utils.php.

Referenced by Posts::get(), and placeholder_string().

static Utils::locale_date ( format,
timestamp 
) [static]

Return a formatted date/time trying to use strftime() AND date()

Parameters:
string $format The format for the date. If it contains non-escaped percent signs, it uses strftime(), otherwise date()
integer $timestamp The unix timestamp of the time to format
Returns:
string The formatted time

Definition at line 558 of file utils.php.

static Utils::mail ( to,
subject,
message,
headers = array(),
parameters = '' 
) [static]

Send email

Parameters:
string $to The destination address
string $subject The subject of the message
string $message The message itself
array $headers An array of key=>value pairs for additional email headers
string $parameters Additional parameters to mail()
Returns:
boolean True if sending the message succeeded

Definition at line 899 of file utils.php.

Referenced by UserHandler::act_login(), and UserHandler::act_password_reset().

static Utils::map_array ( value  )  [static]

Used with array_map to create an array of PHP stringvar-style search/replace strings using optional pre/postfixes $mapped_values= array_map(array('Utils', 'map_array'), $values);

Parameters:
string $value The value to wrap
string $prefix The prefix for the returned value
string $postfix The postfix for the returned value
Returns:
string The wrapped value

Definition at line 248 of file utils.php.

static Utils::md5 ( password,
hash = null 
) [static]

Crypt or verify a given password using MD5.

Passwords should not be stored using this method, but legacy systems might require it.

Definition at line 452 of file utils.php.

Referenced by debug().

static Utils::mimetype ( filename  )  [static]

Return the mimetype of a file

Parameters:
string $filename the path of a file
Returns:
string The mimetype of the file.

Definition at line 824 of file utils.php.

Referenced by HabariSilo::silo_get().

static Utils::nonce (  )  [static]

function nonce Returns a random 12-digit hex number

Definition at line 90 of file utils.php.

Referenced by WSSE().

static Utils::php_check_file_syntax ( file,
&$  error = null 
) [static]

Check the PHP syntax of (and execute) the specified file.

See also:
Utils::php_check_syntax()

Definition at line 734 of file utils.php.

Referenced by Plugins::check_every_plugin_syntax(), and AdminPluginsHandler::get_plugins().

static Utils::php_check_syntax ( code,
&$  error = null 
) [static]

Check the PHP syntax of the specified code. Performs a syntax (lint) check on the specified code testing for scripting errors.

Parameters:
string $code The code string to be evaluated. It does not have to contain PHP opening tags.
Returns:
bool Returns true if the lint check passed, and false if the link check failed.

Definition at line 691 of file utils.php.

Referenced by php_check_file_syntax().

static Utils::placeholder_string ( count  )  [static]

Returns a string of question mark parameter placeholders.

Useful when building, for instance, an IN() list for SQL

Parameters:
count Number of placeholders to put in the string
Returns:
string Placeholder string

Definition at line 215 of file utils.php.

Referenced by Vocabulary::delete(), Posts::get(), and Comments::get().

static Utils::quote_spaced ( value  )  [static]

function quote_spaced Adds quotes around values that have spaces in them

Parameters:
string A string value that might have spaces
Returns:
string The string value, quoted if it has spaces

Definition at line 185 of file utils.php.

static Utils::random_password ( length = 10  )  [static]

Create a random password of a specific length

Parameters:
integer $length Length of the password, if not provded, 10
Returns:
string A random password

Definition at line 935 of file utils.php.

Referenced by UserHandler::act_login(), and UserHandler::act_password_reset().

static Utils::redirect ( url = '',
continue = false 
) [static]
static Utils::regexdelim ( string,
choices = null 
) [static]

Convenience function to find a usable PCRE regular expression delimiter for a particular string. (I.e., some character that *isn't* found in the string.)

Parameters:
$string. string. The string for which to find a delimiter.
$choices. string. Delimiters from which to choose one.
$encoding. string. The encoding of the passed string
Returns:
A valid regex delimiter, or null if none of the choices work.

Definition at line 1102 of file utils.php.

static Utils::revert_magic_quotes_gpc (  )  [static]

function revert_magic_quotes_gpc Reverts magicquotes_gpc behavior

Definition at line 167 of file utils.php.

static Utils::ror ( v,
w 
) [static]

Helper function for array_or

Definition at line 959 of file utils.php.

static Utils::scheme_ports ( scheme = null  )  [static]

Return the port used for a specific URL scheme

Parameters:
string $scheme The scheme in question
Returns:
integer the port used for the scheme

Definition at line 1011 of file utils.php.

Referenced by InputFilter::glue_url().

static Utils::sha1 ( password,
hash = null 
) [static]

Crypt or verify a given password using SHA.

Passwords should not be stored using this method, but legacy systems might require it.

Definition at line 436 of file utils.php.

Referenced by crypt(), ssha(), and WSSE().

static Utils::single_array ( element  )  [static]

Convert a single non-array variable into an array with that one element

Parameters:
mixed $element Some value, either an array or not
Returns:
array Either the original array value, or the passed value as the single element of an array

Definition at line 810 of file utils.php.

Referenced by UserGroup::add(), Post::add_tokens(), User::can_any(), AdminHandler::filter_menus_by_permission(), Posts::get(), UserGroup::grant(), User::grant(), Post::has_tokens(), UserGroup::remove(), Post::remove_tokens(), UserGroup::revoke(), User::revoke(), Post::set_tokens(), Theme::theme_body_class(), and Theme::theme_content().

static Utils::slugify ( string,
separator = '-' 
) [static]

Return a sanitized slug, replacing non-alphanumeric characters to dashes

Parameters:
string $string The string to sanitize. Non-alphanumeric characters will be replaced by dashes
string $separator The slug separator, '-' by default
Returns:
string The sanitized slug

Definition at line 579 of file utils.php.

Referenced by Term::__construct(), Block::__get(), Theme::act_display(), Post::add_new_type(), Block::content_type(), ACL::create_default_tokens(), Post::delete_post_type(), AdminDashboardHandler::fetch_dashboard_modules(), CoreBlocks::filter_block_content_type_monthly_archives(), CoreBlocks::filter_block_content_type_tag_archives(), FormUI::get(), Posts::get(), Comments::get(), AtomHandler::get_collection(), Tags::parse_url_tags(), AdminOptionsHandler::post_options(), Term::setslug(), FlickrSilo::silo_dir(), Modules::storage_name(), and Format::term_tree().

static Utils::ssha ( password,
hash = null 
) [static]

Crypt or verify a given password using SSHA. Implements the {Seeded,Salted}-SHA algorithm as per RfC 2307.

Parameters:
string $password the password to crypt or verify
string $hash (optional) if given, verify $password against $hash
Returns:
crypted password, or boolean for verification

Definition at line 471 of file utils.php.

static Utils::ssha512 ( password,
hash = null 
) [static]

Crypt or verify a given password using SSHA512. Implements a modified version of the {Seeded,Salted}-SHA algorithm from RfC 2307, using SHA-512 instead of SHA-1.

Requires the new hash*() functions.

Parameters:
string $password the password to crypt or verify
string $hash (optional) if given, verify $password against $hash
Returns:
crypted password, or boolean for verification

Definition at line 514 of file utils.php.

Referenced by crypt().

static Utils::stripslashes ( value  )  [static]

function stripslashes Removes slashes from escaped strings, including strings in arrays

Definition at line 125 of file utils.php.

Referenced by SuperGlobal::process_c(), SuperGlobal::process_gps(), and revert_magic_quotes_gpc().

static Utils::trail ( value = false  )  [static]

Returns a trailing slash or a string, depending on the value passed in

Parameters:
mixed $value A trailing string value
Returns:
string A slash if true, the value if value passed, emptystring if false

Definition at line 878 of file utils.php.

Referenced by Site::get_dir(), Site::get_path(), and Site::get_url().

static Utils::truncate ( str,
len = 10,
middle = true 
) [static]

Trims longer phrases to shorter ones with elipsis in the middle

Parameters:
string The string to truncate
integer The length of the returned string
bool Whether to place the ellipsis in the middle (true) or at the end (false)
Returns:
string The truncated string

Definition at line 659 of file utils.php.

static Utils::WSSE ( nonce = '',
timestamp = '' 
) [static]

The documentation for this class was generated from the following file: