PHP Класс Habari\Utils

Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$debug_defined

Открытые методы

Метод Описание
WSSE ( string | array $nonce = '', string $timestamp = '' ) : array Returns an array of tokens used for WSSE authentication http://www.xml.com/pub/a/2003/12/17/dive.html http://www.sixapart.com/developers/atom/protocol/atom_authentication.html
addslashes ( $value ) Adds slashes to escape strings, including strings in arrays
amp ( string $value ) : string Escape the ampersands in a URL for ouptut
archive_pages ( integer $item_total, integer $items_per_page = null ) : integer Returns the number of pages in an archive using the number of items per page set in options
array_map_field ( Countable $array, string $field, string $key = null ) : array 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);
array_or ( array $input ) : integer Does a bitwise OR of all the numbers in an array
atomtime ( mixed $t ) : string Returns RFC-3339 time from a time string or integer timestamp
check_request_method ( array $expected ) Checks whether the correct HTTP method was used for the request
class_only ( string | object $classname ) : string Strip the namespace off of the fully-qualified class name
crypt ( string $password, string $hash = null ) : string | boolean Crypt a given password, or verify a given password against a given hash.
de_amp ( string $value ) : boolean | string Return & entities in a URL querystring to their previous & glory, for use in redirects
debug ( ) Outputs a call stack with parameters, and a dump of the parameters passed.
debug_reveal ( $show, $hide, $debugid, $close = false ) Helper function used by debug() Not for external use.
end_in_slash ( string $value ) : string Forces a string to end in a single slash
env_is ( string $env, string $key = '_useenv' ) : boolean Are we in a specific environment?
env_test ( string $key = '_useenv' ) : boolean Are we in a testing environment?
firebacktrace ( array $backtrace ) : string Utils::firebacktrace()
firedebug ( ) Outputs debug information like ::debug() but using Firebug's Console.
get_ini_settings ( ) : Array Get a list of the PHP ini settings relevant to Habari
get_ip ( string $default = '0.0.0.0' ) : string Get the remote IP address, but try and take into account users who are behind proxies, whether they know it or not.
get_params ( mixed $params ) : array Returns an associative array of parameters, whether the input value is a querystring or an associative array.
getdate ( integer $timestamp ) : array Return an array of date information Just like getdate() but also returns 0-padded versions of day and month in mday0 and mon0
glob ( string $pattern, integer $flags ) : array Replacement for system glob that returns an empty array if there are no results
glob_to_regex ( string $glob ) : string Returns a regex pattern equivalent to the given glob pattern
html_attr ( array $attrs, integer $quote_flag = ENT_COMPAT, string $encoding = 'UTF-8', boolean $decode = true, boolean $double_encode = true ) : string Create a list of html element attributes from an associative array
html_checkboxes ( string $name, array $options ) : string Creates one or more HTML checkboxes
html_inputs ( array $options ) : string Creates one or more HTML inputs
html_select ( string $name, array $options, string $current = null, array $properties = [] ) : string Create an HTML select tag with options and a current value
htmlspecialchars ( string | array $string, integer $quote_flag = null, string $encoding = 'UTF-8', boolean $decode = true, boolean $double_encode = true ) : string Call htmlspecialchars() with the correct flags and encoding, without double escaping strings.
human_size ( integer $bytesize ) : string Produces a human-readable size string.
implode_quoted ( string $separator, array $values ) : string Behaves like the implode() function, except it quotes values that contain spaces
is_traversable ( mixed $data ) : boolean determines if the given that is travesable in foreach
locale_date ( string $format, integer $timestamp ) : string Return a formatted date/time trying to use strftime() AND date()
mail ( string $to, string $subject, string $message, array $headers = [], string $parameters = '' ) : boolean Send email
map_array ( string $value, string $prefix = '{$', string $postfix = '}' ) : string Used with array_map to create an array of PHP stringvar-style search/replace strings using optional pre/postfixes $mapped_values= array_map(array('\Habari\Utils', 'map_array'), $values);
md5 ( $password, $hash = null ) Crypt or verify a given password using MD5.
mimetype ( string $filename ) : string Return the mimetype of a file
nonce ( ) Returns a random 12-digit hex number
php_check_file_syntax ( $file, &$error = null ) Check the PHP syntax of (and execute) the specified file.
php_check_syntax ( string $code, null | string &$error = null ) : boolean Check the PHP syntax of the specified code.
placeholder_string ( integer $count ) : string Returns a string of question mark parameter placeholders.
quote_spaced ( string $value ) : string Adds quotes around values that have spaces in them
random_password ( integer $length = 10 ) : string Create a random password of a specific length
redirect ( string $url = '', boolean $continue = false ) Redirects the request to a new URL
regexdelim ( string $string, string $choices = null ) : string 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.)
replace_shortcodes ( string $content, Object $obj_context ) : string Replace shortcodes in content with shortcode output
ror ( $v, $w ) Helper function for array_or
scheme_ports ( string $scheme = null ) : integer Return the port used for a specific URL scheme
setup_wsse ( ) : string Produce a set of inputs that can be used to validate WSSE
sha1 ( $password, $hash = null ) Crypt or verify a given password using SHA.
single_array ( mixed $element ) : array Convert a single non-array variable into an array with that one element
slugify ( string $string, string $separator = '-' ) : string Return a sanitized slug, replacing non-alphanumeric characters to dashes
ssha ( string $password, string $hash = null ) : string Crypt or verify a given password using SSHA.
ssha512 ( string $password, string $hash = null ) : string Crypt or verify a given password using SSHA512.
stripslashes ( $value ) Removes slashes from escaped strings, including strings in arrays
trail ( mixed $value = false ) : string Returns a trailing slash or a string, depending on the value passed in
truncate ( string $str, integer $len = 10, boolean $middle = true ) : string Trims longer phrases to shorter ones with elipsis in the middle
verify_wsse ( array $data, boolean $anyverb = false ) : boolean Verify WSSE values passed in.

Приватные методы

Метод Описание
__construct ( ) Utils constructor This class should not be instantiated.

Описание методов

WSSE() публичный статический Метод

Returns an array of tokens used for WSSE authentication http://www.xml.com/pub/a/2003/12/17/dive.html http://www.sixapart.com/developers/atom/protocol/atom_authentication.html
public static WSSE ( string | array $nonce = '', string $timestamp = '' ) : array
$nonce string | array a string nonce or an existing array to add nonce parameters to
$timestamp string a timestamp
Результат array an array of WSSE authentication elements

addslashes() публичный статический Метод

Adds slashes to escape strings, including strings in arrays
public static addslashes ( $value )

amp() публичный статический Метод

Escape the ampersands in a URL for ouptut
public static amp ( string $value ) : string
$value string A URL for output
Результат string The URL with escaped ampersands

archive_pages() публичный статический Метод

Returns the number of pages in an archive using the number of items per page set in options
public static archive_pages ( integer $item_total, integer $items_per_page = null ) : integer
$item_total integer Number of items in the archive
$items_per_page integer Number of items per page
Результат integer Number of pages based on pagination option.

array_map_field() публичный статический Метод

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);
public static array_map_field ( Countable $array, string $field, string $key = null ) : array
$array Countable An array of arrays or objects with similar keys or properties
$field string The name of a common field within each array/object
$key string Optional field to use as the key in the result array
Результат array An array of the values of the specified field within each array/object

array_or() публичный статический Метод

Does a bitwise OR of all the numbers in an array
public static array_or ( array $input ) : integer
$input array An array of integers
Результат integer The bitwise OR of the input array

atomtime() публичный статический Метод

Returns RFC-3339 time from a time string or integer timestamp
public static atomtime ( mixed $t ) : string
$t mixed A string of time or integer timestamp
Результат string An RFC-3339 formatted time

check_request_method() публичный статический Метод

Checks whether the correct HTTP method was used for the request
public static check_request_method ( array $expected )
$expected array Expected HTTP methods for the request

class_only() публичный статический Метод

Strip the namespace off of the fully-qualified class name
public static class_only ( string | object $classname ) : string
$classname string | object The fully-qualified name of the class, or an object instance
Результат string The class name, with namespace removed

crypt() публичный статический Метод

Crypt a given password, or verify a given password against a given hash.
public static crypt ( string $password, string $hash = null ) : string | boolean
$password string the password to crypt or verify
$hash string (optional) if given, verify $password against $hash
Результат string | boolean Encrypted password, or boolean for verification

de_amp() публичный статический Метод

Return & entities in a URL querystring to their previous & glory, for use in redirects
public static de_amp ( string $value ) : boolean | string
$value string A URL, maybe with a querystring
Результат boolean | string The valid, de-amped URL

debug() публичный статический Метод

Outputs a call stack with parameters, and a dump of the parameters passed.
public static debug ( )

debug_reveal() публичный статический Метод

Helper function used by debug() Not for external use.
public static debug_reveal ( $show, $hide, $debugid, $close = false )

end_in_slash() публичный статический Метод

Forces a string to end in a single slash
public static end_in_slash ( string $value ) : string
$value string A string, usually a path
Результат string The string with the slash added or extra slashes removed, but with one slash only

env_is() публичный статический Метод

Are we in a specific environment?
public static env_is ( string $env, string $key = '_useenv' ) : boolean
$env string The environment to test for
$key string The querystring key that can specify the environment to use
Результат boolean True if this is a test environment.

env_test() публичный статический Метод

Are we in a testing environment?
public static env_test ( string $key = '_useenv' ) : boolean
$key string The querystring key that can specify the environment to use
Результат boolean True if this is a test environment.

firebacktrace() публичный статический Метод

Utils::firebacktrace()
public static firebacktrace ( array $backtrace ) : string
$backtrace array An array of backtrace details from debug_backtrace()
Результат string Javascript output that will display the backtrace in the Firebug console.

firedebug() публичный статический Метод

Outputs debug information like ::debug() but using Firebug's Console.
public static firedebug ( )

get_ini_settings() публичный статический Метод

Get a list of the PHP ini settings relevant to Habari
public static get_ini_settings ( ) : Array
Результат Array The relevant PHP ini settings as array of strings

get_ip() публичный статический Метод

Get the remote IP address, but try and take into account users who are behind proxies, whether they know it or not.
public static get_ip ( string $default = '0.0.0.0' ) : string
$default string a default IP address
Результат string The client's IP address.

get_params() публичный статический Метод

Returns an associative array of parameters, whether the input value is a querystring or an associative array.
public static get_params ( mixed $params ) : array
$params mixed An associative array or querystring parameter list
Результат array An associative array of parameters

getdate() публичный статический Метод

Return an array of date information Just like getdate() but also returns 0-padded versions of day and month in mday0 and mon0
public static getdate ( integer $timestamp ) : array
$timestamp integer A unix timestamp
Результат array An array of date data

glob() публичный статический Метод

Replacement for system glob that returns an empty array if there are no results
public static glob ( string $pattern, integer $flags ) : array
$pattern string The glob() file search pattern
$flags integer Standard glob() flags
Результат array An array of result files, or an empty array if no results found

glob_to_regex() публичный статический Метод

Returns a regex pattern equivalent to the given glob pattern
public static glob_to_regex ( string $glob ) : string
$glob string Glob to return
Результат string regex pattern with '/' delimiter

html_attr() публичный статический Метод

Create a list of html element attributes from an associative array
public static html_attr ( array $attrs, integer $quote_flag = ENT_COMPAT, string $encoding = 'UTF-8', boolean $decode = true, boolean $double_encode = true ) : string
$attrs array An associative array of parameters
$quote_flag integer Sets what quotes and doublequotes are escaped
$encoding string The encoding of the passed string
$decode boolean Whether or not to unescape any html entities first
$double_encode boolean Whether or not to double escape any html entities
Результат string The parameters turned into a string of tag attributes

html_checkboxes() публичный статический Метод

Creates one or more HTML checkboxes
public static html_checkboxes ( string $name, array $options ) : string
$name 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
$options 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.
Результат string The HTML of the checkboxes

html_inputs() публичный статический Метод

Creates one or more HTML inputs
public static html_inputs ( array $options ) : string
$options array An array of input elements. Each element should be an array containing "name", "value" and "type".
Результат string The HTML of the inputs

html_select() публичный статический Метод

Create an HTML select tag with options and a current value
public static html_select ( string $name, array $options, string $current = null, array $properties = [] ) : string
$name string The name and id of the select control
$options array An associative array of values to use as the select options
$current string The value of the currently selected option
$properties array An associative array of additional properties to assign to the select control
Результат string The select control markup

htmlspecialchars() публичный статический Метод

See http://php.net/manual/en/function.htmlspecialchars.php for details on the parameters and purpose of the function.
public static htmlspecialchars ( string | array $string, integer $quote_flag = null, string $encoding = 'UTF-8', boolean $decode = true, boolean $double_encode = true ) : string
$string string | array The string or array of strings to escape
$quote_flag integer Sets what quotes and doublequotes are escaped
$encoding string The encoding of the passed string
$decode boolean Whether or not to unescape any html entities first
$double_encode boolean Whether or not to double escape any html entities
Результат string The escaped string

human_size() публичный статический Метод

For example, converts 12345 into 12.34KB
public static human_size ( integer $bytesize ) : string
$bytesize integer Number of bytes
Результат string Human-readable string

implode_quoted() публичный статический Метод

Behaves like the implode() function, except it quotes values that contain spaces
public static implode_quoted ( string $separator, array $values ) : string
$separator string A separator between each value
$values array An array of values to separate
Результат string The concatenated string

is_traversable() публичный статический Метод

determines if the given that is travesable in foreach
public static is_traversable ( mixed $data ) : boolean
$data mixed
Результат boolean

locale_date() публичный статический Метод

Return a formatted date/time trying to use strftime() AND date()
public static locale_date ( string $format, integer $timestamp ) : string
$format string The format for the date. If it contains non-escaped percent signs, it uses strftime(), otherwise date()
$timestamp integer The unix timestamp of the time to format
Результат string The formatted time

mail() публичный статический Метод

Send email
public static mail ( string $to, string $subject, string $message, array $headers = [], string $parameters = '' ) : boolean
$to string The destination address
$subject string The subject of the message
$message string The message itself
$headers array An array of key=>value pairs for additional email headers
$parameters string Additional parameters to mail()
Результат boolean True if sending the message succeeded

map_array() публичный статический Метод

Used with array_map to create an array of PHP stringvar-style search/replace strings using optional pre/postfixes $mapped_values= array_map(array('\Habari\Utils', 'map_array'), $values);
public static map_array ( string $value, string $prefix = '{$', string $postfix = '}' ) : string
$value string The value to wrap
$prefix string The prefix for the returned value
$postfix string The postfix for the returned value
Результат string The wrapped value

md5() публичный статический Метод

Passwords should not be stored using this method, but legacy systems might require it.
public static md5 ( $password, $hash = null )

mimetype() публичный статический Метод

Return the mimetype of a file
public static mimetype ( string $filename ) : string
$filename string the path of a file
Результат string The mimetype of the file.

nonce() публичный статический Метод

Returns a random 12-digit hex number
public static nonce ( )

php_check_file_syntax() публичный статический Метод

Check the PHP syntax of (and execute) the specified file.
См. также: Utils::php_check_syntax()
public static php_check_file_syntax ( $file, &$error = null )

php_check_syntax() публичный статический Метод

Performs a syntax (lint) check on the specified code testing for scripting errors.
public static php_check_syntax ( string $code, null | string &$error = null ) : boolean
$code string The code string to be evaluated. It does not have to contain PHP opening tags.
$error null | string Intenal Memoizing parameter
Результат boolean Returns true if the lint check passed, and false if the link check failed.

placeholder_string() публичный статический Метод

Useful when building, for instance, an IN() list for SQL
public static placeholder_string ( integer $count ) : string
$count integer Count of placeholders to put in the string
Результат string Placeholder string

quote_spaced() публичный статический Метод

Adds quotes around values that have spaces in them
public static quote_spaced ( string $value ) : string
$value string A string value that might have spaces
Результат string The string value, quoted if it has spaces

random_password() публичный статический Метод

Create a random password of a specific length
public static random_password ( integer $length = 10 ) : string
$length integer Length of the password, if not provded, 10
Результат string A random password

redirect() публичный статический Метод

Redirects the request to a new URL
public static redirect ( string $url = '', boolean $continue = false )
$url string The URL to redirect to, or omit to redirect to the current url
$continue boolean Whether to continue processing the script (default false for security reasons, cf. #749)

regexdelim() публичный статический Метод

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.)
public static regexdelim ( string $string, string $choices = null ) : string
$string string The string for which to find a delimiter.
$choices string Delimiters from which to choose one.
Результат string A valid regex delimiter, or null if none of the choices work.

replace_shortcodes() публичный статический Метод

Replace shortcodes in content with shortcode output
public static replace_shortcodes ( string $content, Object $obj_context ) : string
$content string The content within which to replace shortcodes
$obj_context Object The object context in which the content was found
Результат string The content with shortcodes replaced

ror() публичный статический Метод

Helper function for array_or
public static ror ( $v, $w )

scheme_ports() публичный статический Метод

Return the port used for a specific URL scheme
public static scheme_ports ( string $scheme = null ) : integer
$scheme string The scheme in question
Результат integer the port used for the scheme

setup_wsse() публичный статический Метод

Produce a set of inputs that can be used to validate WSSE
public static setup_wsse ( ) : string
Результат string HTML inputs for WSSE support

sha1() публичный статический Метод

Passwords should not be stored using this method, but legacy systems might require it.
public static sha1 ( $password, $hash = null )

single_array() публичный статический Метод

Convert a single non-array variable into an array with that one element
public static single_array ( mixed $element ) : array
$element mixed Some value, either an array or not
Результат array Either the original array value, or the passed value as the single element of an array

slugify() публичный статический Метод

Return a sanitized slug, replacing non-alphanumeric characters to dashes
public static slugify ( string $string, string $separator = '-' ) : string
$string string The string to sanitize. Non-alphanumeric characters will be replaced by dashes
$separator string The slug separator, '-' by default
Результат string The sanitized slug

ssha() публичный статический Метод

Implements the {Seeded,Salted}-SHA algorithm as per RfC 2307.
public static ssha ( string $password, string $hash = null ) : string
$password string the password to crypt or verify
$hash string (optional) if given, verify $password against $hash
Результат string Encrypted password, or boolean for verification

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.
public static ssha512 ( string $password, string $hash = null ) : string
$password string the password to crypt or verify
$hash string (optional) if given, verify $password against $hash
Результат string encrypted password, or boolean for verification

stripslashes() публичный статический Метод

Removes slashes from escaped strings, including strings in arrays
public static stripslashes ( $value )

trail() публичный статический Метод

Returns a trailing slash or a string, depending on the value passed in
public static trail ( mixed $value = false ) : string
$value mixed A trailing string value
Результат string A slash if true, the value if value passed, emptystring if false

truncate() публичный статический Метод

Trims longer phrases to shorter ones with elipsis in the middle
public static truncate ( string $str, integer $len = 10, boolean $middle = true ) : string
$str string The string to truncate
$len integer The length of the returned string
$middle boolean Whether to place the ellipsis in the middle (true) or at the end (false)
Результат string The truncated string

verify_wsse() публичный статический Метод

Verify WSSE values passed in.
public static verify_wsse ( array $data, boolean $anyverb = false ) : boolean
$data array payload from a given request, needs to include 'nonce', 'timestamp', and 'digest' as generated by Utils::WSSE()
$anyverb boolean If true, act on any request verb, not just POST.
Результат boolean True if the WSSE values passed are valid

Описание свойств

$debug_defined публичное статическое свойство

public static $debug_defined