-
Notifications
You must be signed in to change notification settings - Fork 0
/
bbcode.php
85 lines (61 loc) · 3.46 KB
/
bbcode.php
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
<?php
function bbcode_decode($messageStr) {
// $messageStr = strip_tags($messageStr);
// Bold
$messageStr = eregi_replace("\\[b]([^\\[]*)\\[/b\\]","<b>\\1</b>",$messageStr);
// Italic
$messageStr = eregi_replace("\\[i]([^\\[]*)\\[/i\\]","<i>\\1</i>",$messageStr);
// Underline
$messageStr = eregi_replace("\\[u]([^\\[]*)\\[/u\\]","<u>\\1</u>",$messageStr);
// Code
$messageStr = eregi_replace("\\[code]([^\\[]*)\\[/code\\]","<code>\\1</code>",$messageStr);
// URL
$messageStr = eregi_replace("\\[url]http://([^\\[]*)\\[/url\\]","<a href=\"http://\\1\" target=\"_blank\">\\1</a>",$messageStr);
$messageStr = eregi_replace("\\[url]([^\\[]*)\\[/url\\]","<a href=\"http://\\1\" target=\"_blank\">\\1</a>",$messageStr);
$messageStr = eregi_replace("\\[url=http://([^\\[]*)\\]([^\\[]*)\\[/url\\]","<a href=\"http://\\1\" target=\"_blank\">\\2</a>",$messageStr);
$messageStr = eregi_replace("\\[url=([^\\[]*)\\]([^\\[]*)\\[/url\\]","<a href=\"http://\\1\" target=\"_blank\">\\2</a>",$messageStr);
// Email
$messageStr = eregi_replace("\\[email=([^\\[]*)\\]([^\\[]*)\\[/email\\]","<a href=\"mailto:\\1\">\\2</a>",$messageStr);
// Images
$messageStr = eregi_replace("\\[img]([^\\[]*)\\[/img\\]","<img src=\"\\1\" border=0>",$messageStr);
// Quote
$messageStr = eregi_replace("quote\\]","quote]",$messageStr); // make lower case
$messageStr = eregi_replace("\[quote\]\r\n", '<blockquote><smallfont>Quote:</smallfont><hr>', $messageStr);
$messageStr = eregi_replace("\[quote\]", '<blockquote><smallfont>Quote:</smallfont><hr>', $messageStr);
$messageStr = eregi_replace("\[/quote\]\r\n", '<hr></blockquote>', $messageStr);
$messageStr = eregi_replace("\[/quote\]", '<hr></blockquote>', $messageStr);
return nl2br($messageStr);
}
// The following function is not used currently, however, it may be used in future version of peoGuest,
// so I recommend you keep them both up to date, as then you could simply keep this file to preserve your
// custom BBCode.
function bbcode_encode($messageStr) {
// Bold
$messageStr = eregi_replace("\<b\>", '[b]', $messageStr);
$messageStr = eregi_replace("\</b\>", '[/b]', $messageStr);
// Italic
$messageStr = eregi_replace("\<i\>", '[i]', $messageStr);
$messageStr = eregi_replace("\</i\>", '[/i]', $messageStr);
// Underline
$messageStr = eregi_replace("\<u\>", '[u]', $messageStr);
$messageStr = eregi_replace("\</u\>", '[/u]', $messageStr);
// Code
$messageStr = eregi_replace("\<code\>", '[code]', $messageStr);
$messageStr = eregi_replace("\</code\>", '[/code]', $messageStr);
// Url
$messageStr = eregi_replace("\\<a href=\"([^\\[\"]*)\"\\ target=\"_blank\">([^<\[]*)</a>","[url=\\1]\\2[/url]", $messageStr);
// Mailto
$messageStr = eregi_replace("\\<a href=\"mailto:([^\\[]*)\"\\>([^<\[]*)</a>","[email=\\1]\\2[/email]",$messageStr);
// Image
$messageStr = eregi_replace("\\<img src=\"([^\\[]*)\"\\ border=0>([^<\[]*)","[img]\\1[/img]",$messageStr);
// Quote
$messageStr = eregi_replace("\<blockquote><smallfont>Quote:</smallfont><hr>", '[quote]', $messageStr);
$messageStr = eregi_replace("\<hr></blockquote>", '[/quote]', $messageStr);
$messageStr = eregi_replace("\<hr></blockquote>", '[/quote]', $messageStr);
// BR
$messageStr = eregi_replace("\<br />\n", '/n', $messageStr);
// BR
$messageStr = eregi_replace("\<br>", '/n', $messageStr);
return $messageStr;
}
?>