/usr/share/php/Horde/Text/Filter/Bbcode.php is in php-horde-text-filter 2.3.3-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | <?php
/**
* The Horde_Text_Filter_Bbcode:: class finds bbcode-style markup (see below)
* in a block of text and turns it into HTML.
*
* Parameters:
* <pre>
* entities - (boolean) Before replacing bbcode with HTML tags, replace HTML
* entities?
* DEFAULT: false
* </pre>
*
* Supported bbcode:
* <pre>
* [b]Bold Text[/b]
* [i]Italics Text[/i]
* [u]Underlined Text[/u]
* [quote]Quoted Text[/quote]
* [center]Centered Text[/center]
*
* List of items
* [list]
* [*] Item one
* [*] Item two
* [/list]
*
* Numbered list
* [numlist]
* [*] Item one
* [*] Item two
* [/numlist]
*
* [url]http://www.horde.org[/url] -> Link to the address using the
* address itself for the text. You can specify the protocol: http or
* https and the port.
* [url]www.horde.org[/url] -> Link to the address using the address
* itself for the text. You can specify the port. The protocol is by
* default http.
* [url=http://www.horde.org]Link to Horde[/url] -> Link to the address
* using "Link to Horde" for the text. You can specify the protocol:
* http or https and the port.
* [url=www.horde.org]Link to Horde[/url] -> Link to the address using
* "Link to Horde" for the text. You can specify the port. The
* protocol is by default http
* [email]cpedrinaci@yahoo.es[/email] -> sets a mailto link.
* [email=cpedrinaci@yahoo.es]Mail to Carlos[/email] -> Sets a mailto link
* and the text is "Mail to Carlos".
* </pre>
*
* Copyright 2003-2016 Horde LLC (http://www.horde.org/)
*
* Email validation based on Chuck Hagenbuch's
* Mail_RFC822::isValidInetAddress().
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @author Carlos Pedrinaci <cpedrinaci@yahoo.es>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Text_Filter
*/
class Horde_Text_Filter_Bbcode extends Horde_Text_Filter_Base
{
/**
* Filter parameters.
*
* @var array
*/
protected $_params = array(
'entities' => false
);
/**
* Executes any code necessary before applying the filter patterns.
*
* @param string $text The text before the filtering.
*
* @return string The modified text.
*/
public function preProcess($text)
{
if ($this->_params['entities']) {
$text = @htmlspecialchars($text);
}
return $text;
}
/**
* Returns a hash with replace patterns.
*
* @return array Patterns hash.
*/
public function getPatterns()
{
$replace = array(
'[i]' => '<em>', '[/i]' => '</em>',
'[u]' => '<u>', '[/u]' => '</u>',
'[b]' => '<strong>', '[/b]' => '</strong>',
'[s]' => '<strike>', '[/s]' => '</strike>',
'[sub]' => '<sub>', '[/sub]' => '</sub>',
'[sup]' => '<sup>', '[/sup]' => '</sup>',
'[center]' => '<center>', '[/center]' => '</center>',
'[quote]' => '<blockquote>', '[/quote]' => '</blockquote>',
'[list]' => '<ul>', '[/list]' => '</ul>',
'[numlist]' => '<ol>', '[/numlist]' => '</ol>',
'[*]' => '<li>'
);
/* When checking URLs we validate part of them, but it is up
* to the user to write them correctly (in particular the
* query string). Concerning mails we use the regular
* expression in Mail_RFC822's isValidInetAddress() function,
* slightly modified. */
$regexp = array(
"#\[url\]((http|https)://([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\[/url\]#U" => $this->_link("$1", "$1") . "$1</a>",
"#\[url\=((http|https)://([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\]([^<>]+)\[/url\]#U" => $this->_link("$1", "$1") . "$9</a>",
"#\[url\](([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\[/url\]#U" => $this->_link("http://$1", "http://$1") . "$1</a>",
"#\[url\=(([a-zA-Z\d][\w-]*)(\.[a-zA-Z\d][\w-]*)+(:(\d+))?(/([^<>]+))*)\]([^<>]+)\[/url\]#U" => $this->_link("http://$1", "http://$1") . "$8</a>",
"#\[email\](([*+!.&\#$|\'\\%\/0-9a-zA-Z^_`{}=?~:-]+)@(([0-9a-zA-Z-]+\.)+[0-9a-zA-Z]{2,4}))\[/email\]#U" => $this->_link("mailto:$1", "mailto:$1") . "$1</a>",
"#\[email\=(([*+!.&\#$|\'\\%\/0-9a-zA-Z^_`{}=?~:-]+)@(([0-9a-zA-Z-]+\.)+[0-9a-zA-Z]{2,4}))\]([^<>]+)\[/email\]#U" => $this->_link("mailto:$1", "mailto:$1") . "$5</a>",
"#\[img\](.*)\[/img\]#U" => "<img src=\"$1\" alt=\"$1\" />",
"#\[img\=(.*)\](.*)\[/img\]#U" => "<img src=\"$1\" alt=\"$2\" title=\"$2\" />",
"#\[color\=(.*)\](.*)\[/color\]#U" => "<span style=\"color: $1;\">$2</span>"
);
return array(
'regexp' => $regexp,
'replace' => $replace
);
}
/**
* Return link for use in getPatterns() regexp.
*
* @var string $url The URL.
* @var string $title The link title.
*
* @return string The opening <a> tag.
*/
protected function _link($url, $title)
{
return '<a href="' . $url . '" title="' . $title . '">';
}
}
|