-
Notifications
You must be signed in to change notification settings - Fork 0
/
modifier.bbcode2html.php
44 lines (42 loc) · 1.27 KB
/
modifier.bbcode2html.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
<?php
/**
* Template_Lite bbcode modifier plugin
*
* Type: modifier
* Name: bbcode2html
* Purpose: converts special bbcode syntax into standard html
* Input:<br>
* - string: data to convert
*/
function tpl_modifier_bbcode2html($data)
{
$data = nl2br(stripslashes(addslashes($data)));
$search = array("\n", "\r", "[b]", "[/b]", "[i]", "[/i]", "[u]", "[/u]");
$replace = array("", "", "<b>", "</b>", "<i>", "</i>", "<u>", "</u>");
$data = str_replace($search, $replace, $data);
$search = array(
"/\[email\](.*?)\[\/email\]/si",
"/\[email=(.*?)\](.*?)\[\/email\]/si",
"/\[url\](.*?)\[\/url\]/si",
"/\[url=(.*?)\](.*?)\[\/url\]/si",
"/\[img\](.*?)\[\/img\]/si",
"/\[code\](.*?)\[\/code\]/si",
"/\[pre\](.*?)\[\/pre\]/si",
"/\[list\](.*?)\[\/list\]/si",
"/\[\*\](.*?)/si"
);
$replace = array(
"<a href=\"mailto:\\1\">\\1</a>",
"<a href=\"mailto:\\1\">\\2</a>",
"<a href=\"\\1\" target=\"_blank\">\\1</a>",
"<a href=\"\\1\" target=\"_blank\">\\2</a>",
"<img src=\"\\1\" border=\"0\">",
"<p><blockquote><font size=\"1\">code:</font><hr noshade size=\"1\"><pre>\\1</pre><br><hr noshade size=\"1\"></blockquote></p>",
"<pre>\\1<br></pre>",
"<ul>\\1</ul>",
"<li>\\1</li>"
);
$data = preg_replace($search, $replace, $data);
return $data;
}
?>