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 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_inputs ($options)
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 ($default= '0.0.0.0')
static htmlspecialchars ($string, $quote_flag=ENT_COMPAT, $encoding= 'UTF-8', $decode=true, $double_encode=true)
static regexdelim ($string, $choices=null)
static html_attr ($attrs, $quote_flag=ENT_COMPAT, $encoding= 'UTF-8', $decode=true, $double_encode=true)
static get_ini_settings ()
static env_test ($key= '_useenv')
static env_is ($env, $key= '_useenv')
static array_map_field ($array, $field, $key=null)
static replace_shortcodes ($content, $obj_context)
static setup_wsse ()
static verify_wsse ($data, $anyverb=false)
static class_only ($classname)

Static Public Attributes

static $debug_defined = false

Detailed Description

Habari Utility Class

Definition at line 13 of file utils.php.


Member Function Documentation

static Utils::addslashes ( value  )  [static]

Adds slashes to escape strings, including strings in arrays

Definition at line 142 of file utils.php.

Referenced by firebacktrace(), firedebug(), and FormControlSubmit::get().

static Utils::amp ( value  )  [static]

Escape the ampersands in a URL for ouptut

Parameters:
string $value A URL for output
Returns:
string The URL with escaped ampersands

Definition at line 170 of file utils.php.

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

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

Parameters:
int $item_total Number of items in the archive
int $items_per_page Number of items per page
Returns:
int Number of pages based on pagination option.

Definition at line 239 of file utils.php.

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

static Utils::array_map_field ( array,
field,
key = null 
) [static]

Given an array of arrays, return an array that contains the value of a particular common field Example: $a = array( array('foo'=>1, 'bar'=>2), array('foo'=>3, 'bar'=>4), ); $b = Utils::array_map_field($a, 'foo'); // $b = array(1, 3);

Parameters:
\Countable $array An array of arrays or objects with similar keys or properties
string $field The name of a common field within each array/object
string $key Optional field to use as the key in the result array
Returns:
array An array of the values of the specified field within each array/object

Definition at line 1308 of file utils.php.

Referenced by AdminUsersHandler::__construct(), RewriteRules::add_system_rules(), Plugins::changed_since_last_activation(), Update::check(), Menus::get_menu_type_ids(), AdminThemesHandler::get_themes(), Format::summarize(), Theme::theme_query_time(), and Themes::validate_theme().

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 1001 of file utils.php.

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

static Utils::atomtime ( t  )  [static]

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

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

Definition at line 71 of file utils.php.

static Utils::check_request_method ( expected  )  [static]
static Utils::class_only ( classname  )  [static]

Strip the namespace off of the fully-qualified class name

Parameters:
string|object $classname The fully-qualified name of the class, or an object instance
Returns:
string The class name, with namespace removed

Definition at line 1420 of file utils.php.

Referenced by Theme::theme_content().

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

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

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

Definition at line 415 of file utils.php.

Referenced by UserHandler::act_password_reset(), WPImport::action_auth_ajax_wp_import_users(), User::authenticate(), AdminUsersHandler::do_add_user(), AdminUsersHandler::edit_user_apply(), CronHandler::run_cron(), and WSSE().

static Utils::de_amp ( value  )  [static]

Return & entities in a URL querystring to their previous & glory, for use in redirects

Parameters:
string $value A URL, maybe with a querystring
Returns:
bool|string The valid, de-amped URL

Definition at line 158 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 285 of file utils.php.

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

static Utils::debug_reveal ( show,
hide,
debugid,
close = false 
) [static]
Todo:
Pull all of these debug functions out into their own class

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

Definition at line 270 of file utils.php.

Referenced by debug().

static Utils::end_in_slash ( value  )  [static]

Forces a string to end in a single slash

Parameters:
string $value 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(), Controller::get_full_url(), Site::get_url(), Theme::get_url(), Theme::load_assets(), and RawPHPEngine::queue_dirs().

static Utils::env_is ( env,
key = '_useenv' 
) [static]

Are we in a specific environment?

Parameters:
string $env The environment to test for
string $key The querystring key that can specify the environment to use
Returns:
bool True if this is a test environment.

Definition at line 1276 of file utils.php.

Referenced by env_test().

static Utils::env_test ( key = '_useenv'  )  [static]

Are we in a testing environment?

Parameters:
string $key The querystring key that can specify the environment to use
Returns:
bool True if this is a test environment.

Definition at line 1264 of file utils.php.

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 376 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 355 of file utils.php.

static Utils::get_ini_settings (  )  [static]

Get a list of the PHP ini settings relevant to Habari

Returns:
Array The relevant PHP ini settings as array of strings

Definition at line 1234 of file utils.php.

Referenced by AdminHandler::get_sysinfo().

static Utils::get_ip ( default = '0.0.0.0'  )  [static]

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

Parameters:
string $default a default IP address
Returns:
string The client's IP address.

Definition at line 1102 of file utils.php.

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

static Utils::get_params ( params  )  [static]

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

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

Definition at line 31 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 559 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 795 of file utils.php.

Referenced by MemcacheCache::_purge(), FileCache::_purge(), Themes::get_all(), Themes::get_all_data(), Site::get_dir(), AdminHandler::get_sysinfo(), Locale::list_all(), Plugins::list_all(), Theme::load_assets(), RawPHPEngine::queue_dirs(), HabariSilo::silo_dir(), and HabariSilo::silo_get().

static Utils::glob_to_regex ( glob  )  [static]

Returns a regex pattern equivalent to the given glob pattern

Parameters:
string $glob Glob to return
Returns:
string regex pattern with '/' delimiter

Definition at line 1039 of file utils.php.

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

static Utils::html_attr ( attrs,
quote_flag = ENT_COMPAT,
encoding = 'UTF-8',
decode = true,
double_encode = true 
) [static]

Create a list of html element attributes from an associative array

Parameters:
array $attrs An associative array of parameters
integer $quote_flag Sets what quotes and doublequotes are escaped
string $encoding The encoding of the passed string
boolean $decode Whether or not to unescape any html entities first
boolean $double_encode Whether or not to double escape any html entities
Returns:
string The parameters turned into a string of tag attributes

Definition at line 1217 of file utils.php.

Referenced by FormControl::get(), html_inputs(), Stack::scripts(), Stack::styles(), and Format::term_tree().

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

Creates one or more HTML checkboxes

Parameters:
string $name 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 $options 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 661 of file utils.php.

static Utils::html_inputs ( options  )  [static]

Creates one or more HTML inputs

Parameters:
array $options An array of input elements. Each element should be an array containing "name", "value" and "type".
Returns:
string The HTML of the inputs

Definition at line 613 of file utils.php.

Referenced by setup_wsse().

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 632 of file utils.php.

static Utils::htmlspecialchars ( string,
quote_flag = ENT_COMPAT,
encoding = 'UTF-8',
decode = true,
double_encode = true 
) [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|array $string The string or array of strings to escape
integer $quote_flag Sets what quotes and doublequotes are escaped
string $encoding The encoding of the passed string
boolean $decode Whether or not to unescape any html entities first
boolean $double_encode Whether or not to double escape any html entities
Returns:
string The escaped string

Definition at line 1142 of file utils.php.

Referenced by Locale::_t(), AtomHandler::act_introspection(), FlickrSilo::action_plugin_ui_confirm(), AtomHandler::add_comments(), AtomHandler::add_posts(), AtomHandler::create_atom_wrapper(), CoreDashModules::filter_dash_module_post_types_and_statuses(), Post::form_publish_delete(), FormControlCheckboxes::get(), FormControl::get(), AtomHandler::get_entry(), AdminUsersHandler::get_user(), HiEngineParser::hi_command(), html_attr(), and HTMLTokenSet::token_to_string().

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 830 of file utils.php.

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

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

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

Definition at line 207 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 1091 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 573 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 949 of file utils.php.

Referenced by 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('', '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 257 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 467 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 870 of file utils.php.

Referenced by HabariSilo::silo_get().

static Utils::nonce (  )  [static]

Returns a random 12-digit hex number

Definition at line 87 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 770 of file utils.php.

Referenced by Plugins::check_every_plugin_syntax(), InstallHandler::get_plugins(), 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.
null|string $error Intenal Memoizing parameter
Returns:
bool Returns true if the lint check passed, and false if the link check failed.

Definition at line 722 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:
integer $count Count of placeholders to put in the string
Returns:
string Placeholder string

Definition at line 225 of file utils.php.

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

static Utils::quote_spaced ( value  )  [static]

Adds quotes around values that have spaces in them

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

Definition at line 196 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 985 of file utils.php.

Referenced by 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.
string $choices Delimiters from which to choose one.
Returns:
string A valid regex delimiter, or null if none of the choices work.

Definition at line 1171 of file utils.php.

static Utils::replace_shortcodes ( content,
obj_context 
) [static]

Replace shortcodes in content with shortcode output

Parameters:
string $content The content within which to replace shortcodes
Object $obj_context The object context in which the content was found
Returns:
string The content with shortcodes replaced

Definition at line 1336 of file utils.php.

Referenced by Post::filter_post_get_7().

static Utils::revert_magic_quotes_gpc (  )  [static]

Reverts magicquotes_gpc behavior

Definition at line 179 of file utils.php.

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

Helper function for array_or

Definition at line 1009 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 1062 of file utils.php.

Referenced by InputFilter::glue_url().

static Utils::setup_wsse (  )  [static]

Produce a set of inputs that can be used to validate WSSE

Returns:
string HTML inputs for WSSE support

Definition at line 1365 of file utils.php.

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 451 of file utils.php.

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

static Utils::single_array ( element  )  [static]
static Utils::slugify ( string,
separator = '-' 
) [static]
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:
string Encrypted password, or boolean for verification

Definition at line 486 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:
string encrypted password, or boolean for verification

Definition at line 529 of file utils.php.

Referenced by crypt().

static Utils::stripslashes ( value  )  [static]

Removes slashes from escaped strings, including strings in arrays

Definition at line 128 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 928 of file utils.php.

Referenced by Site::get_dir(), URL::get_from_filesystem(), 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 $str The string to truncate
integer $len The length of the returned string
bool $middle Whether to place the ellipsis in the middle (true) or at the end (false)
Returns:
string The truncated string

Definition at line 689 of file utils.php.

static Utils::verify_wsse ( data,
anyverb = false 
) [static]

Verify WSSE values passed in.

Parameters:
array $data payload from a given request, needs to include 'nonce', 'timestamp', and 'digest' as generated by Utils::WSSE()
bool $anyverb If true, act on any request verb, not just POST.
Returns:
bool True if the WSSE values passed are valid

Definition at line 1381 of file utils.php.

Referenced by Menus::action_admin_theme_get_menus(), and FormValidators::validate_wsse().

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

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