owls
view Includes/Bbcodeparser.inc.php @ 1:6268cdb5fc0b
Added tag owls-0.5 for changeset 3021ce32ee142c32840dbc01d6db34487f9daab8
author | "Meillo r e t u r n s <meillo@marmaro.de>" |
---|---|
date | Sun, 03 Dec 2006 22:32:33 +0100 |
parents | |
children | ab74e95a8040 |
line source
1 <?php
3 /**
4 *
5 * BB-Code-Parser
6 *
7 * by Meillo r e t u r n s
8 *
9 */
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 }
27 function smilies($text) {
28 $smilieDir = 'Pics/Smilies/'; // path to smilies
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 }
57 function bbcode($text, $smilies = 0, $images = 0) {
59 // smilies
60 if ($smilies == 1) {
61 $text = smilies($text);
62 }
64 // new-lines
65 $text = preg_replace("#(\r\n)|(\r)#", "\n", $text);
66 $text = str_replace("\n", '<br />[nl]', htmlentities($text));
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 }
86 // remove backslashes
87 $text = preg_replace("#\\\#is", "", $text);
88 // new-lines
89 $text = str_replace('[nl]', "\n", $text);
91 return $text;
92 }
94 ?>