owls

view Bbcodeparser.inc.php @ 15:bae203f70c9b

Added tag owls-0.6 for changeset cebc198276ebb36f21e36170d85364bf70b0a822
author meillo@marmaro.de
date Sun, 27 May 2007 03:04:52 +0200
parents 144bc36a6c27
children
line source
1 <?php
2 /**
3 * BB-Code-Parser
4 *
5 * @author Meillo r e t u r n s <meillo@marmaro.de>
6 */
9 /// path to smilies
10 define('SMILIE_DIR', 'Smilies/');
14 /**
15 * parses recursive quotes without a source mentioned
16 *
17 * @param $textinput the bbcode-text
18 * @param $level number of levels to go inside
19 * @return HTML-text
20 */
21 function parse_quote1($textinput,$level = 1) {
22 $pattern = '#\[quote\](((?R)|(.*))*)\[/quote\]#isUe';
23 $replacement = "'<br />[nl]<span class=\"quote0\">Zitat:</span>[nl]<div class=\"quote1\">[nl]'.parse_quote1('$1',
24 ". ($level + 1) ."
25 ).'[nl]</div>[nl]'";
26 return preg_replace($pattern, $replacement, $textinput);
27 }
29 /**
30 * parses recursive quotes with a source mentioned
31 *
32 * @param $textinput the bbcode-text
33 * @param $level number of levels to go inside
34 * @return HTML-text
35 */
36 function parse_quote2($textinput,$level = 1) {
37 $pattern = '#\[quote\=(.*)\](((?R)|(.*))*)\[/quote\]#isUe';
38 $replacement = "'<br />[nl]<span class=\"quote0\">Zitat: ($1)</span>[nl]<div class=\"quote2\">[nl]'.parse_quote2('$2',
39 ". ($level + 1) ."
40 ).'[nl]</div>[nl]'";
41 return preg_replace($pattern, $replacement, $textinput);
42 }
44 /**
45 * replaces smilies
46 *
47 * @param $text text with ASCII-smilies
48 * @return text with [img]-smilies
49 */
50 function smilies($text) {
51 $smilies = array( ':-)' => 'Smile.gif',
52 ':)' => 'Smile.gif',
53 ';-)' => 'Wink.gif',
54 ';)' => 'Wink.gif',
55 ':-D' => 'Biggrin.gif',
56 ':D' => 'Biggrin.gif',
57 ':-(' => 'Sad.gif',
58 ':(' => 'Sad.gif',
59 ':-P' => 'Lick.gif',
60 ':P' => 'Lick.gif',
61 ':o' => 'Talk.gif',
62 ':-S' => 'Dontknow.gif',
63 ':dontknow:' => 'Dontknow.gif',
64 ':-@' => 'Angry.gif',
65 ':cool:' => 'Cool.gif',
66 'B-)' => 'Cool.gif',
67 '%-)' => 'Crosseyed.gif',
68 '%-(' => 'Crosseyed.gif',
69 ':rolleyes:' => 'Rolleyes.gif',
70 ':eek:' => 'Shocked.gif');
71 while(list($key, $val) = each($smilies)) {
72 $text = str_replace($key,'[img]'. SMILIE_DIR . $val .'[/img]', $text);
73 }
74 return $text;
75 }
78 /**
79 * turns bbcode in HTML
80 *
81 * @param $text the text with bbcode inside
82 * @param $smilies set to 1 causes smilies to be replaced with pics
83 * @param $images set to 1 causes images to be displayed ([img]-tag)
84 * @return text with HTML-code
85 */
86 function bbcode($text, $smilies = 0, $images = 0) {
88 // smilies
89 if ($smilies == 1) {
90 $text = smilies($text);
91 }
93 // new-lines
94 $text = preg_replace("#(\r\n)|(\r)#", "\n", $text);
95 $text = str_replace("\n", '<br />[nl]', htmlentities($text));
97 // bold
98 $text = preg_replace("#\[b\](.*?)\[/b\]#i", "<strong>$1</strong>", $text);
99 // italic
100 $text = preg_replace("#\[i\](.*?)\[/i\]#i", "<i>$1</i>", $text);
101 // links
102 $text = preg_replace("#\[url\](.*)\[/url\]#iU", "<a href=\"$1\">$1</a>", $text);
103 $text = preg_replace("#\[url=(.*)\](.*)\[/url\]#iU", "<a href=\"$1\">$2</a>", $text);
104 // lists
105 //$text = preg_replace("#\[list\]\<br /\>(.*)\[/list\]#iU", "<ul>$1</ul>", $text);
106 //$text = preg_replace("#\[\*\](.*)\<br \/\>#iU", "<li>$1</li>", $text);
107 // quotes
108 $text = parse_quote1($text);
109 $text = parse_quote2($text);
110 // images
111 if ($images == 1) {
112 $text = preg_replace("#\[img\](.*?)\[/img\]#i", "<img src=\"$1\" alt=\"&lt;[Bild]&gt;\" />", $text);
113 }
115 // remove backslashes
116 $text = preg_replace("#\\\#is", "", $text);
117 // new-lines
118 $text = str_replace('[nl]', "\n", $text);
120 return $text;
121 }
123 ?>