meillo@0: meillo@0: */ meillo@0: meillo@0: meillo@8: /// path to smilies meillo@17: 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@17: $smilies = array( ':-?\)' => 'Smile.gif', meillo@17: ';-?\)' => 'Wink.gif', meillo@17: ':-?D' => 'Biggrin.gif', meillo@17: ':-?\(' => 'Sad.gif', meillo@17: ':-?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@17: 'B-\)' => 'Cool.gif', meillo@17: '%-\)' => 'Crosseyed.gif', meillo@17: '%-\(' => 'Crosseyed.gif', meillo@0: ':rolleyes:' => 'Rolleyes.gif', meillo@0: ':eek:' => 'Shocked.gif'); meillo@0: while(list($key, $val) = each($smilies)) { meillo@17: $key = '/(\s|^)'.$key.'(\s|$)/'; meillo@17: $text = preg_replace($key, '$1[img]'. SMILIE_DIR . $val .'[/img]$2', $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@17: // line breaks and special chars meillo@17: $text = preg_replace("#(\r\n)|(\r)#", "\n", htmlentities($text, ENT_COMPAT, 'UTF-8')); meillo@17: $text = preg_replace("#(\n){3,}#", "\n\n", $text); meillo@17: meillo@0: // smilies meillo@0: if ($smilies == 1) { meillo@0: $text = smilies($text); meillo@0: } meillo@0: meillo@17: /* meillo@0: // new-lines meillo@0: $text = preg_replace("#(\r\n)|(\r)#", "\n", $text); meillo@17: $text = str_replace("\n", '
[nl]', htmlentities($text, ENT_COMPAT, 'UTF-8')); 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@17: */ 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", "\"<[Bild]>\"", $text); meillo@0: } meillo@0: meillo@17: /* meillo@0: // remove backslashes meillo@0: $text = preg_replace("#\\\#is", "", $text); meillo@0: // new-lines meillo@0: $text = str_replace('[nl]', "\n", $text); meillo@17: */ meillo@0: meillo@17: meillo@17: // inline meillo@17: $text = preg_replace('#\[b\](.*)\[/b\]#iU', '$1', $text); meillo@17: $text = preg_replace('#\*(.*)\*#iU', '$1', $text); meillo@17: $text = preg_replace('#\[i\](.*)\[/i\]#iU', '$1', $text); meillo@17: $text = preg_replace('#[^A-Za-z0-9]_(.*)_[^A-Za-z0-9]#iU', '$1', $text); meillo@17: $text = preg_replace('#{{{(.*)}}}#iUs', '$1', $text); meillo@17: $text = preg_replace("#\[url\](.*)\[/url\]#iU","$1",$text); meillo@17: $text = preg_replace("#\[url=(.*)\](.*)\[/url\]#iU","$2",$text); meillo@17: $text = preg_replace("#\[img\](.*)\[/img\]#iU","\"[Bild]\"", $text); meillo@17: $text = preg_replace("#^-{3,}$#iUm","
    ", $text); meillo@17: meillo@17: // Listen meillo@17: # $text = preg_replace("#\[list\](.*)\[/list\]#i","", $text); meillo@17: $text = preg_replace("#^\s*\*(.*)\n#imU", "
  • $1
  • ", $text); meillo@17: $text = preg_replace("#^((\s*\(.*)\\s*)+)$#im", "", $text); meillo@17: meillo@17: meillo@17: meillo@17: meillo@17: // boxes meillo@17: meillo@17: meillo@17: $text = preg_replace('#^(.+)$#mU', "

    \n $1\n

    ", $text); meillo@17: meillo@17: # nicht wenn oder