auText

From auWiki
Jump to navigation Jump to search

The auText class is part of the auLib package. It provides functions for formatting text.

Usage

All functions in auText are static, which means they can only be called in the form auText::Function().

Constants

_HOST

If not defined already when auText is included, this will get set to the host name with www or similar removed. For example, with a hostname of www.track7.org, _HOST will be set to track7.org. This is used for removing the domain part of links to the same site.

_CHARSET

If not defined already when auText is included, this will be set to UTF-8. Affects FixLink, BB2HTML, and HTML2BB.

Public Functions

YesNo

YesNo($bool)

Translates a true/false value into yes/no.

  • $bool = True/false value to translate.
  • @return = Yes or no.

FixLink

FixLink($link, $htmlspecialchars)

Takes a contact address (e-mail or website) and forms it into a valid URL.

  • $link = User-entered contact address.
  • $htmlspecialchars = If false, the return value will not be made safe for HTML.
  • @return = Contact address formed into a valid URL.

StripURL

StripURL($url)

Strips both the querystring and any index.* from the end of a URL.

  • $url = URL to strip.
  • @return = URL with querystring and index.* removed.

StripQuery

StripQuery($url)

Strips the querystring from the end of a URL.

  • $url = URL to strip.
  • @return = URL with querystring removed.

StripIndex

StripIndex($url)

Strips any index.* from the end of a URL.

  • $url = URL to strip.
  • @return = URL with index.* removed.

SafeEmail

SafeEmail($email)

Takes an e-mail address and randomly chooses an obfuscation method to avoid spambot harvests.

  • $email = E-mail address to obfuscate.
  • @return = Obfuscated e-mail address.

PhoneFormat

PhoneFormat($input, $areaCodeFormat, $localFormat)

Checks and formats a user-provided phone number. Accepts input with 11 (where the first digit is 1), 10, or 7 digits.

  • $input = User-entered phone number.
  • $areaCodeFormat = Format for phone numbers that specify an area code. For a sample phone number input (101) 555-1234, 101 replaces %ac% in the format string, 555 replaces %lc%, and 1234 replaces %pc%. Default format is (101) 555-1234.
  • $localFormat = Format for phone numbers that do not specify an area code. The same %lc% and %pc% (but not %ac%) placeholders described for $areaCodeFormat also apply here. Default format is 555-1234.
  • @return = Formatted phone number, or false if incorrect number of digits.

EOL2pbr

EOL2pbr($text)

Converts end-of-line (EOL) characters to HTML equivalents of p and br tags. It is assumed that the end result will be contained within a p tag. It properly recognizes the three EOL forms of \r\n, \r, and \n. Multiple spaces are converted to a non-breaking space followed by a normal space. An odd number of spaces greater than 2 will get rounded down to the next even number of spaces.

  • $text = User-entered text that may contain EOL characters or multiple spaces.
  • @return = Text converted to HTML.

EOL2br

EOL2br($text)

Converts end-of-line (EOL) characters to HTML equivalent of br tags. It properly recognizes the three EOL forms of \r\n, \r, and \n. Multiple spaces are converted to a non-breaking space followed by a normal space. An odd number of spaces greater than 2 will get rounded down to the next even number of spaces.

  • $text = User-entered text that may contain EOL characters or multiple spaces.
  • @return = Text converted to HTML.

pbr2EOL

pbr2EOL($text)

Undoes what EOL2pbr() does. Generally this should be used when the user wants to edit something they previously entered. It can also be used to undo EOL2br() as it simply wouldn't contain any p tags in that case.

  • $text = HTML-formatted text.
  • @return = Text converted back to what the user entered.

BB2HTML

BB2HTML($bb, $head, $assumeP)

Converts user-entered text that may contain BBcode into HTML.

  • $bb = User-entered BBcode text.
  • $head = Allows [head] and [subhead] BBcode tags if true. Default is to not allow these tags.
  • $assumeP = Assume the HTML will be enclosed within a paragragh tag if true. Default is to assume a paragraph tag.
  • @return = Text converted to HTML.

HTML2BB

HTML2BB($html)

Converts HTML generated from BBcode back to BBcode. This should only need to be used when a user is editing text they previously entered, or quoting text entered by another user.

  • $html = HTML code to convert back to BBcode.
  • @return = Text converted to BBcode.

Diff

Diff($old, $new)

Perform a wordwise diff on two strings, highlighting old words with del and new words with ins tags.

  • $old = Old version of the string.
  • $new = New version of the string.
  • @return = Combined string with changes highlighted.

HowLongAgo

HowLongAgo($timestamp)

Takes a unix timestamp and determines how long before now it occurred.

  • $timestamp = Unix timestamp.
  • @return = How long ago the timestamp was, in the form <value> <units>.

SmartTime

SmartTime($timestamp, $tz)

Takes a Unix timestamp and intelligently converts it to a human-readable time format with an appropriate level of detail.

  • $timestamp = Unix timestamp to convert.
  • $tz = Object that can handle timezones, providing a tzdate function. The standard php date function is used by default.
  • @return = Human-readable time.

SmartDate

SmartDate($timestamp, $tz)

Takes a Unix timestamp and intelligently converts it to a human-readable date format with an appropriate level of detail.

  • $timestamp = Unix timestamp to convert.
  • $tz = Object that can handle timezones, providing a tzdate function. The standard php date function is used by default.
  • @return = Human-readable date.

Tomorrow

Tomorrow($today)

Takes a Unix timestamp and finds the timestamp for the following day.

  • $today = Unix timestamp of current day.
  • @return = Unix timestamp of following day.

FormatDay

FormatDay($day, $format, $tz)

Takes a formatted date and converts it to a different format.

  • $day = Date in yyyy-mm-dd format (or something strtotime() understands).
  • $format = Format string -- see php date() for options.
  • $tz = Object that can handle timezones, providing a tzdate function. The standard php date function is used by default.
  • @return = Formatted date.

FormatMonth

FormatMonth($month, $format, $tz)

Takes a formatted date and converts it to a different format.

  • $month = Month in yyyy-mm format.
  • $format = Format string -- see php date() for options.
  • $tz = Object that can handle timezones, providing a tzdate function. The standard php date function is used by default.
  • @return = Formatted date.