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