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