owls

view Includes/Bbcodeparser.inc.php @ 5:7ee09b636460

changed some colors in CSS
author Meillo r e t u r n s <meillo@marmaro.de>
date Tue, 12 Dec 2006 22:13:56 +0100
parents 3021ce32ee14
children 2672cd855fa2
line source
1 <?php
3 /**
4 *
5 * BB-Code-Parser
6 *
7 * by Meillo r e t u r n s
8 *
9 */
12 define('SMILIE_DIR', 'Smilies/'); // path to smilies
17 function parse_quote1($textinput,$level = 1) { // ohne Quelle
18 $pattern = '#\[quote\](((?R)|(.*))*)\[/quote\]#isUe';
19 $replacement = "'<br />[nl]<span class=\"quote0\">Zitat:</span>[nl]<div class=\"quote1\">[nl]'.parse_quote1('$1',
20 ". ($level + 1) ."
21 ).'[nl]</div>[nl]'";
22 return preg_replace($pattern, $replacement, $textinput);
23 }
24 function parse_quote2($textinput,$level = 1) { // mit Quelle
25 $pattern = '#\[quote\=(.*)\](((?R)|(.*))*)\[/quote\]#isUe';
26 $replacement = "'<br />[nl]<span class=\"quote0\">Zitat: ($1)</span>[nl]<div class=\"quote2\">[nl]'.parse_quote2('$2',
27 ". ($level + 1) ."
28 ).'[nl]</div>[nl]'";
29 return preg_replace($pattern, $replacement, $textinput);
30 }
32 function smilies($text) {
33 $smilies = array( ':-)' => 'Smile.gif',
34 ':)' => 'Smile.gif',
35 ';-)' => 'Wink.gif',
36 ';)' => 'Wink.gif',
37 ':-D' => 'Biggrin.gif',
38 ':D' => 'Biggrin.gif',
39 ':-(' => 'Sad.gif',
40 ':(' => 'Sad.gif',
41 ':-P' => 'Lick.gif',
42 ':P' => 'Lick.gif',
43 ':o' => 'Talk.gif',
44 ':-S' => 'Dontknow.gif',
45 ':dontknow:' => 'Dontknow.gif',
46 ':-@' => 'Angry.gif',
47 ':cool:' => 'Cool.gif',
48 'B-)' => 'Cool.gif',
49 '%-)' => 'Crosseyed.gif',
50 '%-(' => 'Crosseyed.gif',
51 ':rolleyes:' => 'Rolleyes.gif',
52 ':eek:' => 'Shocked.gif');
53 while(list($key, $val) = each($smilies)) {
54 $text = str_replace($key,'[img]'. SMILIE_DIR . $val .'[/img]', $text);
55 }
56 return $text;
57 }
60 function bbcode($text, $smilies = 0, $images = 0) {
62 // smilies
63 if ($smilies == 1) {
64 $text = smilies($text);
65 }
67 // new-lines
68 $text = preg_replace("#(\r\n)|(\r)#", "\n", $text);
69 $text = str_replace("\n", '<br />[nl]', htmlentities($text));
71 // bold
72 $text = preg_replace("#\[b\](.*?)\[/b\]#i", "<strong>$1</strong>", $text);
73 // italic
74 $text = preg_replace("#\[i\](.*?)\[/i\]#i", "<i>$1</i>", $text);
75 // links
76 $text = preg_replace("#\[url\](.*)\[/url\]#iU", "<a href=\"$1\">$1</a>", $text);
77 $text = preg_replace("#\[url=(.*)\](.*)\[/url\]#iU", "<a href=\"$1\">$2</a>", $text);
78 // lists
79 //$text = preg_replace("#\[list\]\<br /\>(.*)\[/list\]#iU", "<ul>$1</ul>", $text);
80 //$text = preg_replace("#\[\*\](.*)\<br \/\>#iU", "<li>$1</li>", $text);
81 // quotes
82 $text = parse_quote1($text);
83 $text = parse_quote2($text);
84 // images
85 if ($images == 1) {
86 $text = preg_replace("#\[img\](.*?)\[/img\]#i", "<img src=\"$1\" alt=\"&lt;[Bild]&gt;\" />", $text);
87 }
89 // remove backslashes
90 $text = preg_replace("#\\\#is", "", $text);
91 // new-lines
92 $text = str_replace('[nl]', "\n", $text);
94 return $text;
95 }
97 ?>