PHP Класс Habari\Format

Provides formatting functions for use in themes. Extendable.
Показать файл Открыть проект Примеры использования класса

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

Метод Описание
and_list ( array $array, string $between = ', ', string $between_last = null ) function and_list Turns an array of strings into a friendly delimited string separated by commas and an "and"
apply ( string $format, string $onwhat ) Called to register a format function to a plugin hook, only passing the hook's first parameter to the Format function.
apply_with_hook_params ( string $format, string $onwhat ) Called to register a format function to a plugin hook, and passes all of the hook's parameters to the Format function.
autop ( string $value ) function autop Converts non-HTML paragraphs separated with 2 or more new lines into HTML paragraphs while preserving any internal HTML.
by_index ( integer $index ) : Format function by_index Returns an indexed formatter object, for use by lambda functions created to supply additional parameters to plugin filters.
format_date ( DateTime $date, string $format ) : string Format a date using a specially formatted string Useful for using a single string to format multiple date components.
html_messages ( array $notices, array $errors ) : string html_messages Creates an HTML unordered list of an array of messages
humane_messages ( array $notices, array $errors ) : string humane_messages Creates JS calls to display session messages
json_messages ( array $notices, array $errors ) : string json_messages Creates a JSON list of session messages
load_all ( ) function load_all Loads and stores an instance of all declared Format classes for future use
more ( string $content, Post $post, $properties = [] ) : string Returns a truncated version of post content when the post isn't being displayed on its own.
nice_date ( DateTime $date, string $dateformat = 'F j, Y' ) function nice_date Formats a date using a date format string
nice_time ( DateTime $date, string $dateformat = 'H:i:s' ) function nice_time Formats a time using a date format string
summarize ( $text, integer $count = 100, integer $max_paragraphs = 1 ) : string Returns a shortened version of whatever is passed in.
tag_and_list ( $terms, string $between = ', ', string $between_last = null, boolean $sort_alphabetical = false ) : string function tag_and_list Formatting function (should be in Format class?) Turns an array of tag names into an HTML-linked list with commas and an "and".
term_tree ( mixed $terms, string $tree_name, array $config = [] ) : string function term_tree Create nested HTML lists from a hierarchical vocabulary.

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

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

function and_list Turns an array of strings into a friendly delimited string separated by commas and an "and"
public static and_list ( array $array, string $between = ', ', string $between_last = null )
$array array An array of strings
$between string Text to put between each element
$between_last string Text to put between the next-to-last element and the last element

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

Called to register a format function to a plugin hook, only passing the hook's first parameter to the Format function.
public static apply ( string $format, string $onwhat )
$format string A function name that exists in a Format class
$onwhat string A plugin hook to apply that Format function to as a filter

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

Called to register a format function to a plugin hook, and passes all of the hook's parameters to the Format function.
public static apply_with_hook_params ( string $format, string $onwhat )
$format string A function name that exists in a Format class
$onwhat string A plugin hook to apply that Format function to as a filter

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

New lines within the text of block elements are converted to linebreaks. New lines before and after tags are stripped. If you make changes to this, PLEASE add test cases here: http://svn.habariproject.org/habari/trunk/tests/data/autop/
public static autop ( string $value )
$value string The string to apply the formatting

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

function by_index Returns an indexed formatter object, for use by lambda functions created to supply additional parameters to plugin filters.
public static by_index ( integer $index ) : Format
$index integer The index of the formatter object to return.
Результат Format The formatter object requested

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

Example: If $dt is a DateTime for December 10, 2008... echo $dt->format_date('
{F} {j}, {Y}
'); Output:
December 10, 2008
public static format_date ( DateTime $date, string $format ) : string
$date DateTime The date to format
$format string A string with date()-like letters within braces to replace with date components
Результат string The formatted string

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

html_messages Creates an HTML unordered list of an array of messages
public static html_messages ( array $notices, array $errors ) : string
$notices array a list of success messages
$errors array a list of error messages
Результат string HTML output

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

humane_messages Creates JS calls to display session messages
public static humane_messages ( array $notices, array $errors ) : string
$notices array a list of success messages
$errors array a list of error messages
Результат string JS output

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

json_messages Creates a JSON list of session messages
public static json_messages ( array $notices, array $errors ) : string
$notices array a list of success messages
$errors array a list of error messages
Результат string JS output

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

function load_all Loads and stores an instance of all declared Format classes for future use
public static load_all ( )

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

Posts are split either at the comment or at the specified maximums. Use only after applying autop or other paragrpah styling methods. Apply to posts using: Format::apply_with_hook_params( 'more', 'post_content_out' );
public static more ( string $content, Post $post, $properties = [] ) : string
$content string The post content
$post Post The Post object of the post
Результат string The post content, suitable for display

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

function nice_date Formats a date using a date format string
public static nice_date ( DateTime $date, string $dateformat = 'F j, Y' )
$date DateTime A date as a DateTime object
$dateformat string A date format string

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

function nice_time Formats a time using a date format string
public static nice_time ( DateTime $date, string $dateformat = 'H:i:s' )
$date DateTime A date as a DateTime object
$dateformat string A date format string

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

Returns a shortened version of whatever is passed in.
public static summarize ( $text, integer $count = 100, integer $max_paragraphs = 1 ) : string
$count integer Maximum words to display [100]
$max_paragraphs integer Maximum paragraphs to display [1]
Результат string The string, shortened

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

function tag_and_list Formatting function (should be in Format class?) Turns an array of tag names into an HTML-linked list with commas and an "and".
public static tag_and_list ( $terms, string $between = ', ', string $between_last = null, boolean $sort_alphabetical = false ) : string
$between string Text to put between each element
$between_last string Text to put between the next to last element and the last element
$sort_alphabetical boolean Should the tags be sorted alphabetically by `term` first?
Результат string HTML links with specified separators.

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

Turns Terms or an array of terms from a hierarchical vocabulary into a ordered HTML list with list items for each term.
public static term_tree ( mixed $terms, string $tree_name, array $config = [] ) : string
$terms mixed An array of Term objects or a Terms object.
$tree_name string The name of the tree, used for unique node id's
$config array an array of values to use to configure the output of this function
Результат string The transformed vocabulary.