meillo@0:
meillo@0: */
meillo@0:
meillo@0:
meillo@8: /// path to smilies
meillo@8: define('SMILIE_DIR', 'Smilies/');
meillo@2:
meillo@2:
meillo@2:
meillo@8: /**
meillo@8: * parses recursive quotes without a source mentioned
meillo@8: *
meillo@8: * @param $textinput the bbcode-text
meillo@8: * @param $level number of levels to go inside
meillo@8: * @return HTML-text
meillo@8: */
meillo@8: function parse_quote1($textinput,$level = 1) {
meillo@0: $pattern = '#\[quote\](((?R)|(.*))*)\[/quote\]#isUe';
meillo@0: $replacement = "'
[nl]Zitat:[nl]
[nl]'.parse_quote1('$1',
meillo@0: ". ($level + 1) ."
meillo@0: ).'[nl]
[nl]'";
meillo@0: return preg_replace($pattern, $replacement, $textinput);
meillo@0: }
meillo@8:
meillo@8: /**
meillo@8: * parses recursive quotes with a source mentioned
meillo@8: *
meillo@8: * @param $textinput the bbcode-text
meillo@8: * @param $level number of levels to go inside
meillo@8: * @return HTML-text
meillo@8: */
meillo@8: function parse_quote2($textinput,$level = 1) {
meillo@0: $pattern = '#\[quote\=(.*)\](((?R)|(.*))*)\[/quote\]#isUe';
meillo@0: $replacement = "'
[nl]Zitat: ($1)[nl][nl]'.parse_quote2('$2',
meillo@0: ". ($level + 1) ."
meillo@0: ).'[nl]
[nl]'";
meillo@0: return preg_replace($pattern, $replacement, $textinput);
meillo@0: }
meillo@0:
meillo@8: /**
meillo@8: * replaces smilies
meillo@8: *
meillo@8: * @param $text text with ASCII-smilies
meillo@8: * @return text with [img]-smilies
meillo@8: */
meillo@0: function smilies($text) {
meillo@0: $smilies = array( ':-)' => 'Smile.gif',
meillo@0: ':)' => 'Smile.gif',
meillo@0: ';-)' => 'Wink.gif',
meillo@0: ';)' => 'Wink.gif',
meillo@0: ':-D' => 'Biggrin.gif',
meillo@0: ':D' => 'Biggrin.gif',
meillo@0: ':-(' => 'Sad.gif',
meillo@0: ':(' => 'Sad.gif',
meillo@0: ':-P' => 'Lick.gif',
meillo@0: ':P' => 'Lick.gif',
meillo@0: ':o' => 'Talk.gif',
meillo@0: ':-S' => 'Dontknow.gif',
meillo@0: ':dontknow:' => 'Dontknow.gif',
meillo@0: ':-@' => 'Angry.gif',
meillo@2: ':cool:' => 'Cool.gif',
meillo@2: 'B-)' => 'Cool.gif',
meillo@0: '%-)' => 'Crosseyed.gif',
meillo@0: '%-(' => 'Crosseyed.gif',
meillo@0: ':rolleyes:' => 'Rolleyes.gif',
meillo@0: ':eek:' => 'Shocked.gif');
meillo@0: while(list($key, $val) = each($smilies)) {
meillo@2: $text = str_replace($key,'[img]'. SMILIE_DIR . $val .'[/img]', $text);
meillo@0: }
meillo@0: return $text;
meillo@0: }
meillo@0:
meillo@0:
meillo@8: /**
meillo@8: * turns bbcode in HTML
meillo@8: *
meillo@8: * @param $text the text with bbcode inside
meillo@8: * @param $smilies set to 1 causes smilies to be replaced with pics
meillo@8: * @param $images set to 1 causes images to be displayed ([img]-tag)
meillo@8: * @return text with HTML-code
meillo@8: */
meillo@0: function bbcode($text, $smilies = 0, $images = 0) {
meillo@0:
meillo@0: // smilies
meillo@0: if ($smilies == 1) {
meillo@0: $text = smilies($text);
meillo@0: }
meillo@0:
meillo@0: // new-lines
meillo@0: $text = preg_replace("#(\r\n)|(\r)#", "\n", $text);
meillo@0: $text = str_replace("\n", '
[nl]', htmlentities($text));
meillo@0:
meillo@0: // bold
meillo@0: $text = preg_replace("#\[b\](.*?)\[/b\]#i", "$1", $text);
meillo@0: // italic
meillo@0: $text = preg_replace("#\[i\](.*?)\[/i\]#i", "$1", $text);
meillo@0: // links
meillo@0: $text = preg_replace("#\[url\](.*)\[/url\]#iU", "$1", $text);
meillo@0: $text = preg_replace("#\[url=(.*)\](.*)\[/url\]#iU", "$2", $text);
meillo@0: // lists
meillo@0: //$text = preg_replace("#\[list\]\
(.*)\[/list\]#iU", "", $text);
meillo@0: //$text = preg_replace("#\[\*\](.*)\
#iU", "$1", $text);
meillo@0: // quotes
meillo@0: $text = parse_quote1($text);
meillo@0: $text = parse_quote2($text);
meillo@0: // images
meillo@0: if ($images == 1) {
meillo@0: $text = preg_replace("#\[img\](.*?)\[/img\]#i", "", $text);
meillo@0: }
meillo@0:
meillo@0: // remove backslashes
meillo@0: $text = preg_replace("#\\\#is", "", $text);
meillo@0: // new-lines
meillo@0: $text = str_replace('[nl]', "\n", $text);
meillo@0:
meillo@0: return $text;
meillo@0: }
meillo@0:
meillo@8: ?>