PHP Класс Gdn_Format, vanilla

Utility class that helps to format strings, objects, and arrays.
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$DisplayNoFollow Flag which allows plugins to decide if the output should include rel="nofollow" on any links.
$FormatLinks Whether or not to replace plain text links with anchors.
$MentionsUrlFormat string

Защищенные свойства (Protected)

Свойство Тип Описание
$SanitizedFormats array
$_CleanChars Unicode to ascii conversion table.
$_UrlTranslations array

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

Метод Описание
activityHeadline ( object $Activity, integer $ProfileUserID = '', $ViewingUserID = '' ) : string The ActivityType table has some special sprintf search/replace values in the FullHeadline and ProfileHeadline fields.
alphaNumeric ( string $Mixed ) : string Removes all non-alpha-numeric characters (except for _ and -) from
arrayAsAttributes ( array $Array ) : string
arrayAsObject ( array $Array ) : stdClass Takes an object and convert's it's properties => values to an associative array of $Array[Property] => Value sets.
arrayValueForPhp ( $String ) : string Formats a string so that it can be saved to a PHP file in double-quotes of an array value assignment.
auto ( mixed $Mixed ) : string Takes a mixed variable, filters unsafe things, renders BBCode and returns it.
bbCode ( mixed $Mixed ) : string Takes a mixed variable.
bigNumber ( mixed $Number, $Format = '' ) : string Format a number by putting K/M/B suffix after it when appropriate.
bytes ( integer $Bytes, integer $Precision = 2 ) : string Format a number as if it's a number of bytes by adding the appropriate B/K/M/G/T suffix.
clean ( mixed $Mixed ) : string Convert certain unicode characters into their ascii equivalents.
date ( string $Timestamp = '', string $Format = '' ) : string Formats a Mysql DateTime string in the specified format.
dateFull ( integer $Timestamp, string $Format = '' ) Formats a MySql datetime or a unix timestamp for display in the system.
defaultFormat ( boolean | null $is_mobile = null ) : string Return the default input formatter.
deleted ( mixed $Mixed ) : string Format a string from of "Deleted" content (comment, message, etc).
display ( mixed $Mixed ) : string Takes a mixed variable, formats it for display on the screen, and returns it.
email ( string $Email ) : string Formats an email address in a non-scrapable format.
form ( mixed $Mixed ) : string Takes a mixed variable, formats it for display in a form, and returns it.
fuzzyTime ( $Timestamp = null, $MorePrecise = false ) : string Show times relative to now, e.g. "4 hours ago".
getEmbedSize ( ) : array Returns embedded video width and height, based on configuration.
html ( mixed $Mixed ) : string Takes a mixed variable, filters unsafe HTML and returns it.
htmlFilter ( mixed $Mixed ) : string Takes a mixed variable, filters unsafe HTML and returns it.
image ( string $Body ) : string Format an encoded string of image properties as HTML.
links ( mixed $Mixed ) : string Formats the anchor tags around the links in text.
markdown ( mixed $Mixed, boolean $Flavored = true ) : string Format a string using Markdown syntax. Also purifies the output HTML.
mentions ( $Mixed ) : mixed | string Handle mentions formatting.
objectAsArray ( object $Object ) : unknown Takes an object and converts its properties => values to an associative array of $Array[Property] => Value sets.
plainText ( string $Body, string $Format = 'Html' ) : string Format a string as plain text.
raw ( string | object | array $Mixed ) : string Return the input without any operations performed at all.
reduceWhiteSpaces ( string $String ) Reduces multiple whitespaces including line breaks and tabs to one single space character.
replaceButProtectCodeBlocks ( mixed $Search, mixed $Replace, mixed $Subject, boolean $IsCallback = false ) : string Do a preg_replace, but don't affect things inside tags.
rssHtml ( string $Text, string $Format = 'Html' ) : string Format some text in a way suitable for passing into an rss/atom feed.
seconds ( integer $Seconds ) : string Formats seconds in a human-readable way (ie. 45 seconds, 15 minutes, 2 hours, 4 days, 2 months, etc).
serialize ( mixed $Mixed ) : string Takes any variable and serializes it.
spoilerHtml ( string $spoilerText ) : string Returns spoiler text wrapped in a HTML spoiler wrapper.
tagContent ( string $html, callable $callback, boolean $skipAnchors = true, boolean $skipCode = true ) : string Executes the callback function on parts of the string excluding html tags.
text ( mixed $mixed, $addBreaks = true ) : string Takes a mixed variable, formats it for display on the screen as plain text.
textEx ( string $Str ) : string Process as plain text + our magic formatting.
timespan ( integer $timespan ) : string
to ( mixed $Mixed, string $FormatMethod ) : mixed Takes a mixed variable, formats it in the specified format type, and returns it.
toDate ( integer $Timestamp = '' ) : string Format a timestamp or the current time to go into the database.
toDateTime ( integer $Timestamp = '' ) : string Format a timestamp or the current time to go into the database.
toTimestamp ( string $DateTime = '' ) : string | boolean Convert a datetime to a timestamp.
toTimezone ( integer $Timestamp ) : integer Formats a timestamp to the current user's timezone.
unembedContent ( mixed $Mixed ) : HTML Strips out embed/iframes we support and replaces with placeholder.
unserialize ( string $SerializedString ) : mixed Takes a serialized variable and unserializes it back into its original state.
url ( mixed $Mixed ) : string Creates URL codes containing only lowercase Roman letters, digits, and hyphens.
vanillaSprintf ( $PlaceholderString, $ReplaceWith ) : mixed
wysiwyg ( $Mixed ) : mixed | string Format text from WYSIWYG editor input.

Защищенные методы

Метод Описание
formatMentionsCallback ( string $str ) : string Adds a link to all mentions in a given string.
isHtml ( $Text ) : boolean Detect HTML for the purposes of doing advanced filtering.
legacySpoilers ( string $html ) : string Spoilers with backwards compatibility.
linksCallback ( array $Matches ) : string Transform match to clickable links or to embedded equivalent.
listCallback ( array $Matches ) : string Formats BBCode list items.
processHTML ( $html ) : string Performs replacing operations on a HTML string. Usually for formatting posts.
replaceListItems ( string $html ) : string Replaces opening html list tags with an asterisk and closing list tags with new lines.
replaceSpoilers ( string $html, string $replaceWith = '(Spoiler)' ) : string Check to see if a string has spoilers and replace them with an innocuous string.
vanillaSprintfCallback ( $Match, boolean $InternalReplacementList = false ) : mixed

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

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

The ProfileHeadline field is to be used on this page (the user profile page). The FullHeadline field is to be used on the main activity page. The replacement definitions are as follows: %1$s = ActivityName %2$s = ActivityName Possessive %3$s = RegardingName %4$s = RegardingName Possessive %5$s = Link to RegardingName's Wall %6$s = his/her %7$s = he/she %8$s = route & routecode %9$s = gender suffix (some languages require this).
public static activityHeadline ( object $Activity, integer $ProfileUserID = '', $ViewingUserID = '' ) : string
$Activity object An object representation of the activity being formatted.
$ProfileUserID integer If looking at a user profile, this is the UserID of the profile we are looking at.
Результат string

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

Removes all non-alpha-numeric characters (except for _ and -) from
public static alphaNumeric ( string $Mixed ) : string
$Mixed string An object, array, or string to be formatted.
Результат string

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

Устаревший: 9 Nov 2016
public static arrayAsAttributes ( array $Array ) : string
$Array array
Результат string

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

Takes an object and convert's it's properties => values to an associative array of $Array[Property] => Value sets.
public static arrayAsObject ( array $Array ) : stdClass
$Array array An array to be converted to object.
Результат stdClass

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

Formats a string so that it can be saved to a PHP file in double-quotes of an array value assignment.
public static arrayValueForPhp ( $String ) : string
Результат string

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

Takes a mixed variable, filters unsafe things, renders BBCode and returns it.
public static auto ( mixed $Mixed ) : string
$Mixed mixed An object, array, or string to be formatted.
Результат string

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

Takes a mixed variable.
public static bbCode ( mixed $Mixed ) : string
$Mixed mixed An object, array, or string to be formatted.
Результат string

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

Format a number by putting K/M/B suffix after it when appropriate.
public static bigNumber ( mixed $Number, $Format = '' ) : string
$Number mixed The number to format. If a number isn't passed then it is returned as is.
Результат string The formatted number.

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

Format a number as if it's a number of bytes by adding the appropriate B/K/M/G/T suffix.
public static bytes ( integer $Bytes, integer $Precision = 2 ) : string
$Bytes integer The bytes to format.
$Precision integer The number of decimal places to return.
Результат string The formatted bytes.

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

Convert certain unicode characters into their ascii equivalents.
public static clean ( mixed $Mixed ) : string
$Mixed mixed The text to clean.
Результат string

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

For instructions on how the format string works:
public static date ( string $Timestamp = '', string $Format = '' ) : string
$Timestamp string A timestamp or string in Mysql DateTime format. ie. YYYY-MM-DD HH:MM:SS
$Format string The format string to use. Defaults to the application's default format.
Результат string

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

Formats a MySql datetime or a unix timestamp for display in the system.
С версии: 2.1
public static dateFull ( integer $Timestamp, string $Format = '' )
$Timestamp integer
$Format string

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

Return the default input formatter.
public static defaultFormat ( boolean | null $is_mobile = null ) : string
$is_mobile boolean | null Whether or not you want the format for mobile browsers.
Результат string

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

Format a string from of "Deleted" content (comment, message, etc).
public static deleted ( mixed $Mixed ) : string
$Mixed mixed An object, array, or string to be formatted.
Результат string

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

Takes a mixed variable, formats it for display on the screen, and returns it.
public static display ( mixed $Mixed ) : string
$Mixed mixed An object, array, or string to be formatted.
Результат string

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

Formats an email address in a non-scrapable format.
public static email ( string $Email ) : string
$Email string
Результат string

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

Takes a mixed variable, formats it for display in a form, and returns it.
public static form ( mixed $Mixed ) : string
$Mixed mixed An object, array, or string to be formatted.
Результат string

formatMentionsCallback() защищенный статический Метод

Supports most usernames by using double-quotes, for example: @"a $pecial user's! name." Without double-quotes, a mentioned username is terminated by any of the following characters: whitespace | . | , | ; | ? | ! | : | '
С версии: 2.3
protected static formatMentionsCallback ( string $str ) : string
$str string The html-formatted string to format mentions in.
Результат string The formatted string.

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

Credit goes to: http://byteinn.com/res/426/Fuzzy_Time_function/
public static fuzzyTime ( $Timestamp = null, $MorePrecise = false ) : string
Результат string

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

Returns embedded video width and height, based on configuration.
public static getEmbedSize ( ) : array
Результат array array(Width, Height)

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

Does "magic" formatting of links, mentions, link embeds, emoji, & linebreaks.
public static html ( mixed $Mixed ) : string
$Mixed mixed An object, array, or string to be formatted.
Результат string HTML

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

Use this instead of Gdn_Format::Html() when you do not want magic formatting.
public static htmlFilter ( mixed $Mixed ) : string
$Mixed mixed An object, array, or string to be formatted.
Результат string HTML

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

Format an encoded string of image properties as HTML.
public static image ( string $Body ) : string
$Body string a encoded array of image properties (Image, Thumbnail, Caption)
Результат string HTML

isHtml() защищенный статический Метод

Detect HTML for the purposes of doing advanced filtering.
protected static isHtml ( $Text ) : boolean
$Text
Результат boolean

legacySpoilers() защищенный статический Метод

In the Spoilers plugin, we would render BBCode-style spoilers in any format post and allow a title.
protected static legacySpoilers ( string $html ) : string
$html string
Результат string

linksCallback() защищенный статический Метод

URLs are typically matched against, which are then translated into a clickable link or transformed into their equivalent embed, if supported. There is a universal config to disable automatic embedding.
protected static linksCallback ( array $Matches ) : string
$Matches array Captured and grouped matches against string.
Результат string

listCallback() защищенный статический Метод

Formats BBCode list items.
protected static listCallback ( array $Matches ) : string
$Matches array
Результат string

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

Format a string using Markdown syntax. Also purifies the output HTML.
public static markdown ( mixed $Mixed, boolean $Flavored = true ) : string
$Mixed mixed An object, array, or string to be formatted.
$Flavored boolean Optional. Parse with Vanilla-flavored settings? Default true
Результат string

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

Handle mentions formatting.
public static mentions ( $Mixed ) : mixed | string
$Mixed
Результат mixed | string

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

Takes an object and converts its properties => values to an associative array of $Array[Property] => Value sets.
public static objectAsArray ( object $Object ) : unknown
$Object object The object to be converted to an array.
Результат unknown

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

Format a string as plain text.
С версии: 2.1
public static plainText ( string $Body, string $Format = 'Html' ) : string
$Body string The text to format.
$Format string The current format of the text.
Результат string

processHTML() защищенный статический Метод

Runs an HTML string through the links, mentions, emoji and spoilers formatters.
protected static processHTML ( $html ) : string
$html An unparsed HTML string.
Результат string The formatted HTML string.

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

This format should only be used when administrators have access.
Устаревший: 9 Nov 2016
public static raw ( string | object | array $Mixed ) : string
$Mixed string | object | array The data to format.
Результат string

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

Reduces multiple whitespaces including line breaks and tabs to one single space character.
public static reduceWhiteSpaces ( string $String )
$String string The string which should be optimized

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

The three parameters are identical to the ones you'd pass preg_replace.
public static replaceButProtectCodeBlocks ( mixed $Search, mixed $Replace, mixed $Subject, boolean $IsCallback = false ) : string
$Search mixed The value being searched for, just like in preg_replace or preg_replace_callback.
$Replace mixed The replacement value, just like in preg_replace or preg_replace_callback.
$Subject mixed The string being searched.
$IsCallback boolean If true, do preg_replace_callback. Do preg_replace otherwise.
Результат string

replaceListItems() защищенный статический Метод

Accepts both encoded and decoded html strings.
protected static replaceListItems ( string $html ) : string
$html string An HTML-formatted string.
Результат string Returns the html with all list items removed.

replaceSpoilers() защищенный статический Метод

Good for displaying excerpts from discussions and without showing the spoiler text.
protected static replaceSpoilers ( string $html, string $replaceWith = '(Spoiler)' ) : string
$html string An HTML-formatted string.
$replaceWith string The translation code to replace spoilers with.
Результат string Returns the html with spoilers removed.

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

Format some text in a way suitable for passing into an rss/atom feed.
С версии: 2.1
public static rssHtml ( string $Text, string $Format = 'Html' ) : string
$Text string The text to format.
$Format string The current format of the text.
Результат string

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

Formats seconds in a human-readable way (ie. 45 seconds, 15 minutes, 2 hours, 4 days, 2 months, etc).
public static seconds ( integer $Seconds ) : string
$Seconds integer
Результат string

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

Takes any variable and serializes it.
public static serialize ( mixed $Mixed ) : string
$Mixed mixed An object, array, or string to be serialized.
Результат string The serialized version of the string.

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

Parsers for NBBC and Markdown should use this function to format thier spoilers. All spoilers in HTML-formatted posts are saved in this way. We use javascript in spoilers.js to add markup and render Spoilers with the "Spoiler" css class name.
public static spoilerHtml ( string $spoilerText ) : string
$spoilerText string The inner text of the spoiler.
Результат string
Takes a mixed variable, formats it for display on the screen as plain text.
public static text ( mixed $mixed, $addBreaks = true ) : string
$mixed mixed An object, array, or string to be formatted.
Результат string

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

Process as plain text + our magic formatting.
С версии: 2.1
public static textEx ( string $Str ) : string
$Str string
Результат string

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

public static timespan ( integer $timespan ) : string
$timespan integer
Результат string

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

Takes a mixed variable, formats it in the specified format type, and returns it.
public static to ( mixed $Mixed, string $FormatMethod ) : mixed
$Mixed mixed An object, array, or string to be formatted.
$FormatMethod string The method with which the variable should be formatted.
Результат mixed

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

Format a timestamp or the current time to go into the database.
public static toDate ( integer $Timestamp = '' ) : string
$Timestamp integer
Результат string The formatted date.

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

Format a timestamp or the current time to go into the database.
public static toDateTime ( integer $Timestamp = '' ) : string
$Timestamp integer
Результат string The formatted date and time.

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

Convert a datetime to a timestamp.
public static toTimestamp ( string $DateTime = '' ) : string | boolean
$DateTime string The Mysql-formatted datetime to convert to a timestamp. Should be in one of the following formats: YYYY-MM-DD or YYYY-MM-DD HH:MM:SS.
Результат string | boolean Returns FALSE upon failure.

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

Formats a timestamp to the current user's timezone.
public static toTimezone ( integer $Timestamp ) : integer
$Timestamp integer The timestamp in gmt.
Результат integer The timestamp according to the user's timezone.

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

This allows later parsing to insert a sanitized video video embed normally. Necessary for backwards compatibility from when we allowed embed & object tags. This is not an HTML filter; it enables old YouTube videos to theoretically work, it doesn't effectively block YouTube iframes or objects.
public static unembedContent ( mixed $Mixed ) : HTML
$Mixed mixed
Результат HTML string

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

Takes a serialized variable and unserializes it back into its original state.
public static unserialize ( string $SerializedString ) : mixed
$SerializedString string A json or php serialized string to be unserialized.
Результат mixed

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

Creates URL codes containing only lowercase Roman letters, digits, and hyphens.
public static url ( mixed $Mixed ) : string
$Mixed mixed An object, array, or string to be formatted.
Результат string

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

public static vanillaSprintf ( $PlaceholderString, $ReplaceWith ) : mixed
$PlaceholderString
$ReplaceWith
Результат mixed

vanillaSprintfCallback() защищенный статический Метод

protected static vanillaSprintfCallback ( $Match, boolean $InternalReplacementList = false ) : mixed
$Match
$InternalReplacementList boolean
Результат mixed

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

Format text from WYSIWYG editor input.
public static wysiwyg ( $Mixed ) : mixed | string
$Mixed
Результат mixed | string

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

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

Flag which allows plugins to decide if the output should include rel="nofollow" on any links.
public static $DisplayNoFollow

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

public static string $MentionsUrlFormat
Результат string

$SanitizedFormats защищенное статическое свойство

protected static array $SanitizedFormats
Результат array

$_CleanChars защищенное статическое свойство

Unicode to ascii conversion table.
protected static $_CleanChars

$_UrlTranslations защищенное статическое свойство

protected static array $_UrlTranslations
Результат array