PHP 클래스 Gdn_Format, vanilla

Utility class that helps to format strings, objects, and arrays.
파일 보기 프로젝트 열기: vanilla/vanilla 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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

보호된 프로퍼티들

프로퍼티 타입 설명
$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