3
require_once 'Horde.php';
6
* The Text_Filter_bbcode:: class finds bbcode-style markup (see below) in a
7
* block of text and turns it into HTML.
11
* entities -- If true before replacing bbcode with HTML tags, any HTML
12
* entities will be replaced.
19
* [u]Underlined Text[/u]
20
* [quote]Quoted Text[/quote]
21
* [center]Centered Text[/center]
35
* [url]http://www.horde.org[/url] -> Link to the address using the
36
* address itself for the text. You can specify the protocol: http or
38
* [url]www.horde.org[/url] -> Link to the address using the address
39
* itself for the text. You can specify the port. The protocol is by
41
* [url=http://www.horde.org]Link to Horde[/url] -> Link to the address
42
* using "Link to Horde" for the text. You can specify the protocol:
43
* http or https and the port.
44
* [url=www.horde.org]Link to Horde[/url] -> Link to the address using
45
* "Link to Horde" for the text. You can specify the port. The
46
* protocol is by default http
47
* [email]cpedrinaci@yahoo.es[/email] -> sets a mailto link.
48
* [email=cpedrinaci@yahoo.es]Mail to Carlos[/email] -> Sets a mailto link
49
* and the text is "Mail to Carlos".
52
* $Horde: framework/Text_Filter/Filter/bbcode.php,v 1.8.10.2 2005/01/11 20:44:48 chuck Exp $
54
* Copyright 2003-2005 Carlos Pedrinaci <cpedrinaci@yahoo.es>
56
* Email validation based on Chuck Hagenbuch's
57
* Mail_RFC822::isValidInetAddress.
59
* See the enclosed file COPYING for license information (LGPL). If you did
60
* not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
62
* @author Carlos Pedrinaci <cpedrinaci@yahoo.es>
65
class Text_Filter_bbcode extends Text_Filter {
72
var $_params = array('entities' => false);
75
* Executes any code necessary before applying the filter patterns.
77
* @param string $text The text before the filtering.
79
* @return string The modified text.
81
function preProcess($text)
83
if ($this->_params['entities']) {
84
$text = @htmlspecialchars($text);
91
* Returns a hash with replace patterns.
93
* @return array Patterns hash.
95
function getPatterns()
98
'[i]' => '<i>', '[/i]' => '</i>',
99
'[u]' => '<u>', '[/u]' => '</u>',
100
'[b]' => '<b>', '[/b]' => '</b>',
101
'[center]' => '<center>', '[/center]' => '</center>',
102
'[quote]' => '<blockquote>', '[/quote]' => '</blockquote>',
103
'[list]' => '<ul>', '[/list]' => '</ul>',
104
'[numlist]' => '<ol>', '[/numlist]' => '</ol>',
107
/* When checking URLs we validate part of them, but it is up
108
* to the user to write them correctly (in particular the
109
* query string). Concerning mails we use the regular
110
* expression in Mail_RFC822's isValidInetAddress() function,
111
* slightly modified. */
113
"#\[url\]((http|https)://([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\[/url\]#U" =>
114
Horde::link("$1", "$1") . "$1</a>",
116
"#\[url\=((http|https)://([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\]([^<>]+)\[/url\]#U" =>
117
Horde::link("$1", "$1") . "$9</a>",
119
"#\[url\](([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\[/url\]#U" =>
120
Horde::link("http://$1", "http://$1") . "$1</a>",
122
"#\[url\=(([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\]([^<>]+)\[/url\]#U" =>
123
Horde::link("http://$1", "http://$1") . "$8</a>",
125
"#\[email\](([*+!.&\#$|\'\\%\/0-9a-zA-Z^_`{}=?~:-]+)@(([0-9a-zA-Z-]+\.)+[0-9a-zA-Z]{2,4}))\[/email\]#U" =>
126
Horde::link("mailto:$1", "mailto:$1") . "$1</a>",
128
"#\[email\=(([*+!.&\#$|\'\\%\/0-9a-zA-Z^_`{}=?~:-]+)@(([0-9a-zA-Z-]+\.)+[0-9a-zA-Z]{2,4}))\]([^<>]+)\[/email\]#U" =>
129
Horde::link("mailto:$1", "mailto:$1") . "$5</a>"
132
return array('replace' => $replace, 'regexp' => $regexp);