PluginProbe
Front End PM / 1.2
Front End PM v1.2
trunk 1.1 1.2 1.3 10.1.1 10.1.2 10.1.3 10.1.4 10.1.5 10.1.6 10.1.7 10.2.1 11.1.1 11.2.1 11.2.2 11.2.3 11.3.1 11.3.3 11.3.4 11.3.5 11.3.6 11.3.7 11.3.8 11.3.9 11.4.1 All 58 releases
front-end-pm / bbcode.php

bbcode.php in Front End PM 1.2, at bbcode.php

63 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Class for parsing BBCode
4 * @author Shamim, http://www.banglardokan.com/blog/recent/project/front-end-pm-2215/
5 *Ui = 1 line
6 *Uis = Multiple Lines
7 */
8 class fepBBCParser {
9
10 var $patterns = array
11 (
12 '/\[list\](.+)\[\/list\]/Uis',
13 '/\[\*\](.+)(\\\r\\\n|\\r|\\n)/Ui',
14 '/\[b\](.+)\[\/b\]/Uis',
15 '/\[i\](.+)\[\/i\]/Uis',
16 '/\[u\](.+)\[\/u\]/Uis',
17 '/\[s\](.+)\[\/s\]/Uis',
18 '/\[url=(.+)\](.+)\[\/url\]/Ui',
19 '/\[url](.+)\[\/url\]/Ui',
20 '/\[email](.+)\[\/email\]/Ui',
21 '/\[email=(.+)\](.+)\[\/email\]/Ui',
22 '/\[img\](.+)\[\/img\]/Ui',
23 '/\[img=(.+)\](.+)\[\/img\]/Ui',
24 '/\[code\](.+)\[\/code\]/Uis',
25 '/\[color=(\#[0-9a-f]{6}|[a-z]+)\](.+)\[\/color\]/Ui',
26 '/\[color=(\#[0-9a-f]{6}|[a-z]+)\](.+)\[\/color\]/Uis',
27 '/\[embed](.+)\[\/embed\]/Ui'
28 );
29
30 var $replacements = array
31 (
32 '<ul>\1</ul>',
33 '<li>\1</li>',
34 '<b>\1</b>',
35 '<i>\1</i>',
36 '<u>\1</u>',
37 '<s>\1</s>',
38 '<a href = "\1" target = "_blank">\2</a>',
39 '<a href = "\1" target = "_blank">\1</a>',
40 '<a href = "mailto:\1">\1</a>',
41 '<a href = "mailto:\1">\2</a>',
42 '<img src = "\1" alt = "Image" />',
43 '<img src = "\1" alt = "\2" />',
44 '<pre class = "code">\1</pre>',
45 '<span style = "color: \1;">\2</span>',
46 '<div style = "color: \1;">\2</div>',
47 '\1'
48 );
49
50 function bbc2html($subject)
51 {
52 //$subject = nl2br($subject); //UCOMMENT THIS LINE TO REPLACE \n's with <br />'s
53 $subject = preg_replace($this->patterns, $this->replacements, $subject);
54 $subject = str_replace(array("\\r\\n", "\\r", "\\n"), "<br />", $subject);
55
56 $findQ = array("[quote]", "[/quote]", "[QUOTE]", "[/QUOTE]");
57 $replaceQ = array("<blockquote>", "</blockquote>", "<blockquote>", "</blockquote>");
58 $subjectTwo = str_replace($findQ, $replaceQ, $subject);
59
60 return $subjectTwo;
61 }
62 }
63 ?>