FText
Text processing utilities. The class wrapper is mostly to help keep your namespace clean.
Summary
- Introduction
- Legal Copyright (C) 2008 Stephane Lavergne http://www.imars.com/
- Functions
- msgWrap Perform word-wrap on a text message.
- msgFormat Reformat text/plain messages for user-friendly display.
- msgAbstract Extract most relevant start of a message body.
Introduction
Legal
Copyright (C) 2008 Stephane Lavergne http://www.imars.com/
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Functions
msgWrap
function msgWrap($body, $width = 76)
Perform word-wrap on a text message. Takes care of quote indentations.
Usually called from msgFormat(), but useful when saving messages coming from forms as well. (Messages coming from an e-mail gateway should be stored as-is in your database and formatted for displaying only, to avoid data loss if any reformatting were to have a bug.)
Parameters
- $body
- String containing the possibly multiline text.
- $width
- Number of columns to use. (Optional.)
Note
Formerly named “wrap_message()” in rtphp.
Returns
The reformatted text string.
msgFormat
function msgFormat($body, $width = 76, $html_markup = false, $html_quotes = false)
Reformat text/plain messages for user-friendly display. A lot of cleaning up is performed:
- Signatures, Hotmail signatures, and Outlook quotes are removed. (Sadly, Outlook makes it impossible for us to distinguish legitimate signatures from useless quotes.) Similarly, if the message ends with a quote, that last quote is removed. This strict policy does wonders for threaded (Gmail-like) views. If an Outlook user decided to use rich text colours to insert replies in a full quote (a horrible practice), this will miss it, unfortunately. It is thus always a good idea to offer the possibility of viewing message sources unmodified as an alternative, or perhaps to display text/html parts although that opens a whole different can of worms, namely MS Office mark-up pollution and viewer exploit vulnerabilities.
- Removes angle brackets, noticing those used to surround URLs or of course those which start quote lines.
- If XHTML quotes were requested, each quote level is wrapped in a blockquote. (I use this to darken the background with increasing quote depths.) Also, lines beginning with any of SPACE, TAB, '+', '-', '*', '|' or '$', go in 'pre' blocks to preserve their line separations, to help with ASCII art and lists.
- If XHTML quotes were not requested,, then the message is rewrapped to a fixed width, taking care of quotes, with msgWrap().
- If XHTML markup was requested, then words surrounded by '*' are cleaned up in a 'strong' block, those with '_' with 'u' block, and URLs are made into hyperlinks.
Parameters
- $body
- Raw body to process.
- $width
- Rewrapping number of columns, useful in text output. (Optional.)
- $html_markup
- Set true to request XHTML formatting. (Optional.)
- $html_quotes
- Set true to request BLOCKQUOTE for quotes. (Optional.)
Note
Formerly named “prettify()” in rtphp.
Returns
Reformatted content.
msgAbstract
function msgAbstract($body, $max = 500)
Extract most relevant start of a message body. If you've used Gmail before, you've seen the usefulness of this kind of logic for displaying alongside message subjects in lists. This is more intelligent than Gmail (as of 2008/03/26) and skips quotes and quote introductions. Often, message threads can be read just with one-line abstracts this way, saving a lot of time to the user.
Parameters
- $body
- The raw message body to extract an abstract from.
- $max
- Maximum number of characters. (Optional.)
Returns
The abstract string.