Mercurial > owls
view Includes/Bbcodeparser.inc.php @ 10:144bc36a6c27
moved login form from nav to top of content
added last modified date
author | meillo@marmaro.de |
---|---|
date | Sun, 27 May 2007 02:13:46 +0200 |
parents | 2672cd855fa2 |
children |
line wrap: on
line source
<?php /** * BB-Code-Parser * * @author Meillo r e t u r n s <meillo@marmaro.de> */ /// path to smilies define('SMILIE_DIR', 'Smilies/'); /** * parses recursive quotes without a source mentioned * * @param $textinput the bbcode-text * @param $level number of levels to go inside * @return HTML-text */ function parse_quote1($textinput,$level = 1) { $pattern = '#\[quote\](((?R)|(.*))*)\[/quote\]#isUe'; $replacement = "'<br />[nl]<span class=\"quote0\">Zitat:</span>[nl]<div class=\"quote1\">[nl]'.parse_quote1('$1', ". ($level + 1) ." ).'[nl]</div>[nl]'"; return preg_replace($pattern, $replacement, $textinput); } /** * parses recursive quotes with a source mentioned * * @param $textinput the bbcode-text * @param $level number of levels to go inside * @return HTML-text */ function parse_quote2($textinput,$level = 1) { $pattern = '#\[quote\=(.*)\](((?R)|(.*))*)\[/quote\]#isUe'; $replacement = "'<br />[nl]<span class=\"quote0\">Zitat: ($1)</span>[nl]<div class=\"quote2\">[nl]'.parse_quote2('$2', ". ($level + 1) ." ).'[nl]</div>[nl]'"; return preg_replace($pattern, $replacement, $textinput); } /** * replaces smilies * * @param $text text with ASCII-smilies * @return text with [img]-smilies */ function smilies($text) { $smilies = array( ':-)' => 'Smile.gif', ':)' => 'Smile.gif', ';-)' => 'Wink.gif', ';)' => 'Wink.gif', ':-D' => 'Biggrin.gif', ':D' => 'Biggrin.gif', ':-(' => 'Sad.gif', ':(' => 'Sad.gif', ':-P' => 'Lick.gif', ':P' => 'Lick.gif', ':o' => 'Talk.gif', ':-S' => 'Dontknow.gif', ':dontknow:' => 'Dontknow.gif', ':-@' => 'Angry.gif', ':cool:' => 'Cool.gif', 'B-)' => 'Cool.gif', '%-)' => 'Crosseyed.gif', '%-(' => 'Crosseyed.gif', ':rolleyes:' => 'Rolleyes.gif', ':eek:' => 'Shocked.gif'); while(list($key, $val) = each($smilies)) { $text = str_replace($key,'[img]'. SMILIE_DIR . $val .'[/img]', $text); } return $text; } /** * turns bbcode in HTML * * @param $text the text with bbcode inside * @param $smilies set to 1 causes smilies to be replaced with pics * @param $images set to 1 causes images to be displayed ([img]-tag) * @return text with HTML-code */ function bbcode($text, $smilies = 0, $images = 0) { // smilies if ($smilies == 1) { $text = smilies($text); } // new-lines $text = preg_replace("#(\r\n)|(\r)#", "\n", $text); $text = str_replace("\n", '<br />[nl]', htmlentities($text)); // bold $text = preg_replace("#\[b\](.*?)\[/b\]#i", "<strong>$1</strong>", $text); // italic $text = preg_replace("#\[i\](.*?)\[/i\]#i", "<i>$1</i>", $text); // links $text = preg_replace("#\[url\](.*)\[/url\]#iU", "<a href=\"$1\">$1</a>", $text); $text = preg_replace("#\[url=(.*)\](.*)\[/url\]#iU", "<a href=\"$1\">$2</a>", $text); // lists //$text = preg_replace("#\[list\]\<br /\>(.*)\[/list\]#iU", "<ul>$1</ul>", $text); //$text = preg_replace("#\[\*\](.*)\<br \/\>#iU", "<li>$1</li>", $text); // quotes $text = parse_quote1($text); $text = parse_quote2($text); // images if ($images == 1) { $text = preg_replace("#\[img\](.*?)\[/img\]#i", "<img src=\"$1\" alt=\"<[Bild]>\" />", $text); } // remove backslashes $text = preg_replace("#\\\#is", "", $text); // new-lines $text = str_replace('[nl]', "\n", $text); return $text; } ?>