831 |
florian |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
if(!defined("PHORUM")) return;
|
|
|
4 |
|
|
|
5 |
// BB Code Phorum Mod
|
|
|
6 |
function phorum_bb_code($data)
|
|
|
7 |
{
|
|
|
8 |
$PHORUM = $GLOBALS["PHORUM"];
|
|
|
9 |
|
|
|
10 |
$search = array(
|
|
|
11 |
"/\[img\]((http|https|ftp):\/\/[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),~%# ]+?)\[\/img\]/is",
|
|
|
12 |
"/\[url\]((http|https|ftp|mailto):\/\/([a-z0-9\.\-@:]+)[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),\#%~ ]*?)\[\/url\]/is",
|
|
|
13 |
"/\[url=((http|https|ftp|mailto):\/\/[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),~%# ]+?)\](.+?)\[\/url\]/is",
|
|
|
14 |
"/\[email\]([a-z0-9\-_\.\+]+@[a-z0-9\-]+\.[a-z0-9\-\.]+?)\[\/email\]/ies",
|
|
|
15 |
"/\[color=([\#a-z0-9]+?)\](.+?)\[\/color\]/is",
|
|
|
16 |
"/\[size=([+\-\da-z]+?)\](.+?)\[\/size\]/is",
|
|
|
17 |
"/\[b\](.+?)\[\/b\]/is",
|
|
|
18 |
"/\[u\](.+?)\[\/u\]/is",
|
|
|
19 |
"/\[i\](.+?)\[\/i\]/is",
|
|
|
20 |
"/\[s\](.+?)\[\/s\]/is",
|
|
|
21 |
"/\[center\](.+?)\[\/center\]/is",
|
|
|
22 |
"/\[hr\]/i",
|
|
|
23 |
"/\[code\](.+?)\[\/code\]/is",
|
|
|
24 |
"/\[sub\](.+?)\[\/sub\]/is",
|
|
|
25 |
"/\[sup\](.+?)\[\/sup\]/is",
|
|
|
26 |
);
|
|
|
27 |
|
|
|
28 |
// add extra tags to links, if enabled in the admin settings page
|
|
|
29 |
|
|
|
30 |
$extra_link_tags = "";
|
|
|
31 |
|
|
|
32 |
if(isset($PHORUM["mod_bb_code"])){ // check for settings file before using settings-dependent variables
|
|
|
33 |
if ($PHORUM["mod_bb_code"]["links_in_new_window"]){
|
|
|
34 |
$extra_link_tags .= "target=\"_blank\" ";
|
|
|
35 |
}
|
|
|
36 |
if ($PHORUM["mod_bb_code"]["rel_no_follow"]){
|
|
|
37 |
$extra_link_tags .= "rel=\"nofollow\" ";
|
|
|
38 |
}
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
$replace = array(
|
|
|
42 |
"<img src=\"$1\" />",
|
|
|
43 |
"[<a $extra_link_tags href=\"$1\">$3</a>]",
|
|
|
44 |
"<a $extra_link_tags href=\"$1\">$3</a>",
|
|
|
45 |
"'<a $extra_link_tags href=\"'.phorum_html_encode('mailto:$1').'\">'.phorum_html_encode('$1').'</a>'",
|
|
|
46 |
"<span style=\"color: $1\">$2</span>",
|
|
|
47 |
"<span style=\"font-size: $1\">$2</span>",
|
|
|
48 |
"<strong>$1</strong>",
|
|
|
49 |
"<u>$1</u>",
|
|
|
50 |
"<i>$1</i>",
|
|
|
51 |
"<s>$1</s>",
|
|
|
52 |
"<center class=\"bbcode\">$1</center>",
|
|
|
53 |
"<hr class=\"bbcode\" />",
|
|
|
54 |
"<pre class=\"bbcode\">$1</pre>",
|
|
|
55 |
"<sub class=\"bbcode\">$1</sub>",
|
|
|
56 |
"<sup class=\"bbcode\">$1</sup>",
|
|
|
57 |
);
|
|
|
58 |
|
|
|
59 |
$quote_search = array(
|
|
|
60 |
"/\[quote\]/is",
|
|
|
61 |
"/\[quote ([^\]]+?)\]/is",
|
|
|
62 |
"/\[quote=([^\]]+?)\]/is",
|
|
|
63 |
"/\[\/quote\]/is"
|
|
|
64 |
);
|
|
|
65 |
|
|
|
66 |
$quote_replace = array(
|
|
|
67 |
"<blockquote class=\"bbcode\">".$PHORUM["DATA"]["LANG"]["Quote"] . ":<div>",
|
|
|
68 |
"<blockquote class=\"bbcode\">".$PHORUM["DATA"]["LANG"]["Quote"] . ":<div><strong>$1</strong><br />",
|
|
|
69 |
"<blockquote class=\"bbcode\">".$PHORUM["DATA"]["LANG"]["Quote"] . ":<div><strong>$1</strong><br />",
|
|
|
70 |
"</div></blockquote>"
|
|
|
71 |
);
|
|
|
72 |
|
|
|
73 |
foreach($data as $message_id => $message){
|
|
|
74 |
|
|
|
75 |
if(isset($message["body"])){
|
|
|
76 |
|
|
|
77 |
// do BB Code here
|
|
|
78 |
$body = $message["body"];
|
|
|
79 |
|
|
|
80 |
$rnd=substr(md5($body.time()), 0, 4);
|
|
|
81 |
|
|
|
82 |
// convert bare urls into bbcode tags as best we can
|
|
|
83 |
// the haystack has to have a space in front of it for the preg to work.
|
|
|
84 |
$body = preg_replace("/([^='\"(\[url\]|\[img\])])((http|https|ftp):\/\/[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),~%#]+)/i", "$1:$rnd:$2:/$rnd:", " $body");
|
|
|
85 |
|
|
|
86 |
// stip puncuation from urls
|
|
|
87 |
if(preg_match_all("!:$rnd:(.+?):/$rnd:!i", $body, $match)){
|
|
|
88 |
|
|
|
89 |
$urls = array_unique($match[1]);
|
|
|
90 |
|
|
|
91 |
foreach($urls as $key => $url){
|
|
|
92 |
// stip puncuation from urls
|
|
|
93 |
if(preg_match("|[^a-z0-9=&/\+_]+$|i", $url, $match)){
|
|
|
94 |
|
|
|
95 |
$extra = $match[0];
|
|
|
96 |
$true_url = substr($url, 0, -1 * (strlen($match[0])));
|
|
|
97 |
|
|
|
98 |
$body = str_replace("$url:/$rnd:", "$true_url:/$rnd:$extra", $body);
|
|
|
99 |
|
|
|
100 |
$url = $true_url;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
$body = str_replace(":$rnd:$url:/$rnd:", "[url]{$url}[/url]", $body);
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
// no sense doing any of this if there is no [ in the body
|
|
|
109 |
if(strstr($body, "[")){
|
|
|
110 |
|
|
|
111 |
// convert bare email addresses into bbcode tags as best we can.
|
|
|
112 |
$body = preg_replace("/([a-z0-9][a-z0-9\-_\.\+]+@[a-z0-9\-]+\.[a-z0-9\-\.]+[a-z0-9])/i", "[email]$1[/email]", $body);
|
|
|
113 |
|
|
|
114 |
// clean up any BB code we stepped on.
|
|
|
115 |
$body = str_replace("[email][email]", "[email]", $body);
|
|
|
116 |
$body = str_replace("[/email][/email]", "[/email]", $body);
|
|
|
117 |
|
|
|
118 |
// fiddle with white space around quote and code tags.
|
|
|
119 |
$body=preg_replace("/\s*(\[\/*(code|quote)\])\s*/", "$1", $body);
|
|
|
120 |
|
|
|
121 |
// run the pregs defined above
|
|
|
122 |
$body = preg_replace($search, $replace, $body);
|
|
|
123 |
|
|
|
124 |
// quote has to be handled differently because they can be embedded.
|
|
|
125 |
// we only do quote replacement if we have matching start and end tags
|
|
|
126 |
if(strstr($body, "[quote") && substr_count($body, "[quote")==substr_count($body, "[/quote]")){
|
|
|
127 |
$body = preg_replace($quote_search, $quote_replace, $body);
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
$data[$message_id]["body"] = $body;
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
return $data;
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
function phorum_bb_code_quote ($array)
|
|
|
143 |
{
|
|
|
144 |
$PHORUM = $GLOBALS["PHORUM"];
|
|
|
145 |
|
|
|
146 |
if(isset($PHORUM["mod_bb_code"]) && $PHORUM["mod_bb_code"]["quote_hook"]){
|
|
|
147 |
return "[quote $array[0]]$array[1][/quote]";
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
?>
|