PHP Class Habari\Format

Provides formatting functions for use in themes. Extendable.
Show file Open project: habari/system Class Usage Examples

Public Methods

Method Description
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.

Method Details

and_list() public static method

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() public static method

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() public static method

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() public static method

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() public static method

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.
return Format The formatter object requested

format_date() public static method

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
return string The formatted string

html_messages() public static method

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
return string HTML output

humane_messages() public static method

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
return string JS output

json_messages() public static method

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
return string JS output

load_all() public static method

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

more() public static method

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
return string The post content, suitable for display

nice_date() public static method

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() public static method

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() public static method

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]
return string The string, shortened

tag_and_list() public static method

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?
return string HTML links with specified separators.

term_tree() public static method

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
return string The transformed vocabulary.