auText: Difference between revisions
Misterhaan (talk | contribs) New page: {{RightTOC}} 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... |
Misterhaan (talk | contribs) m →FixLink: param name change $htmlspecialchars -> $htmlentities |
||
Line 18: | Line 18: | ||
===FixLink=== | ===FixLink=== | ||
<code>FixLink($link, ''$ | <code>FixLink($link, ''$htmlentities'')</code> | ||
Takes a contact address (e-mail or website) and forms it into a valid URL. | Takes a contact address (e-mail or website) and forms it into a valid URL. | ||
* $link = User-entered contact address. | * $link = User-entered contact address. | ||
* ''$ | * ''$htmlentities'' = If false, the return value will not be made safe for HTML. | ||
* @return = Contact address formed into a valid URL. | * @return = Contact address formed into a valid URL. | ||
Revision as of 21:01, 11 February 2007
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.
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, $htmlentities)
Takes a contact address (e-mail or website) and forms it into a valid URL.
- $link = User-entered contact address.
- $htmlentities = 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.
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)
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.
- @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.
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.