init
[garradin.git] / include / libs / template_lite / plugins / modifier.bbcode2html.php
1 <?php
2 /**
3 * Template_Lite bbcode modifier plugin
4 *
5 * Type: modifier
6 * Name: bbcode2html
7 * Purpose: converts special bbcode syntax into standard html
8 * Input:<br>
9 * - string: data to convert
10 */
11 function tpl_modifier_bbcode2html($data)
12 {
13 $data = nl2br(stripslashes(addslashes($data)));
14
15 $search = array("\n", "\r", "[b]", "[/b]", "[i]", "[/i]", "[u]", "[/u]");
16 $replace = array("", "", "<b>", "</b>", "<i>", "</i>", "<u>", "</u>");
17 $data = str_replace($search, $replace, $data);
18
19 $search = array(
20 "/\[email\](.*?)\[\/email\]/si",
21 "/\[email=(.*?)\](.*?)\[\/email\]/si",
22 "/\[url\](.*?)\[\/url\]/si",
23 "/\[url=(.*?)\](.*?)\[\/url\]/si",
24 "/\[img\](.*?)\[\/img\]/si",
25 "/\[code\](.*?)\[\/code\]/si",
26 "/\[pre\](.*?)\[\/pre\]/si",
27 "/\[list\](.*?)\[\/list\]/si",
28 "/\[\*\](.*?)/si"
29 );
30 $replace = array(
31 "<a href=\"mailto:\\1\">\\1</a>",
32 "<a href=\"mailto:\\1\">\\2</a>",
33 "<a href=\"\\1\" target=\"_blank\">\\1</a>",
34 "<a href=\"\\1\" target=\"_blank\">\\2</a>",
35 "<img src=\"\\1\" border=\"0\">",
36 "<p><blockquote><font size=\"1\">code:</font><hr noshade size=\"1\"><pre>\\1</pre><br><hr noshade size=\"1\"></blockquote></p>",
37 "<pre>\\1<br></pre>",
38 "<ul>\\1</ul>",
39 "<li>\\1</li>"
40 );
41 $data = preg_replace($search, $replace, $data);
42 return $data;
43 }
44 ?>