owls

annotate Bbcodeparser.inc.php @ 15:bae203f70c9b

Added tag owls-0.6 for changeset cebc198276ebb36f21e36170d85364bf70b0a822
author meillo@marmaro.de
date Sun, 27 May 2007 03:04:52 +0200
parents 144bc36a6c27
children
rev   line source
meillo@0 1 <?php
meillo@0 2 /**
meillo@0 3 * BB-Code-Parser
meillo@0 4 *
meillo@8 5 * @author Meillo r e t u r n s <meillo@marmaro.de>
meillo@0 6 */
meillo@0 7
meillo@0 8
meillo@8 9 /// path to smilies
meillo@8 10 define('SMILIE_DIR', 'Smilies/');
meillo@2 11
meillo@2 12
meillo@2 13
meillo@8 14 /**
meillo@8 15 * parses recursive quotes without a source mentioned
meillo@8 16 *
meillo@8 17 * @param $textinput the bbcode-text
meillo@8 18 * @param $level number of levels to go inside
meillo@8 19 * @return HTML-text
meillo@8 20 */
meillo@8 21 function parse_quote1($textinput,$level = 1) {
meillo@0 22 $pattern = '#\[quote\](((?R)|(.*))*)\[/quote\]#isUe';
meillo@0 23 $replacement = "'<br />[nl]<span class=\"quote0\">Zitat:</span>[nl]<div class=\"quote1\">[nl]'.parse_quote1('$1',
meillo@0 24 ". ($level + 1) ."
meillo@0 25 ).'[nl]</div>[nl]'";
meillo@0 26 return preg_replace($pattern, $replacement, $textinput);
meillo@0 27 }
meillo@8 28
meillo@8 29 /**
meillo@8 30 * parses recursive quotes with a source mentioned
meillo@8 31 *
meillo@8 32 * @param $textinput the bbcode-text
meillo@8 33 * @param $level number of levels to go inside
meillo@8 34 * @return HTML-text
meillo@8 35 */
meillo@8 36 function parse_quote2($textinput,$level = 1) {
meillo@0 37 $pattern = '#\[quote\=(.*)\](((?R)|(.*))*)\[/quote\]#isUe';
meillo@0 38 $replacement = "'<br />[nl]<span class=\"quote0\">Zitat: ($1)</span>[nl]<div class=\"quote2\">[nl]'.parse_quote2('$2',
meillo@0 39 ". ($level + 1) ."
meillo@0 40 ).'[nl]</div>[nl]'";
meillo@0 41 return preg_replace($pattern, $replacement, $textinput);
meillo@0 42 }
meillo@0 43
meillo@8 44 /**
meillo@8 45 * replaces smilies
meillo@8 46 *
meillo@8 47 * @param $text text with ASCII-smilies
meillo@8 48 * @return text with [img]-smilies
meillo@8 49 */
meillo@0 50 function smilies($text) {
meillo@0 51 $smilies = array( ':-)' => 'Smile.gif',
meillo@0 52 ':)' => 'Smile.gif',
meillo@0 53 ';-)' => 'Wink.gif',
meillo@0 54 ';)' => 'Wink.gif',
meillo@0 55 ':-D' => 'Biggrin.gif',
meillo@0 56 ':D' => 'Biggrin.gif',
meillo@0 57 ':-(' => 'Sad.gif',
meillo@0 58 ':(' => 'Sad.gif',
meillo@0 59 ':-P' => 'Lick.gif',
meillo@0 60 ':P' => 'Lick.gif',
meillo@0 61 ':o' => 'Talk.gif',
meillo@0 62 ':-S' => 'Dontknow.gif',
meillo@0 63 ':dontknow:' => 'Dontknow.gif',
meillo@0 64 ':-@' => 'Angry.gif',
meillo@2 65 ':cool:' => 'Cool.gif',
meillo@2 66 'B-)' => 'Cool.gif',
meillo@0 67 '%-)' => 'Crosseyed.gif',
meillo@0 68 '%-(' => 'Crosseyed.gif',
meillo@0 69 ':rolleyes:' => 'Rolleyes.gif',
meillo@0 70 ':eek:' => 'Shocked.gif');
meillo@0 71 while(list($key, $val) = each($smilies)) {
meillo@2 72 $text = str_replace($key,'[img]'. SMILIE_DIR . $val .'[/img]', $text);
meillo@0 73 }
meillo@0 74 return $text;
meillo@0 75 }
meillo@0 76
meillo@0 77
meillo@8 78 /**
meillo@8 79 * turns bbcode in HTML
meillo@8 80 *
meillo@8 81 * @param $text the text with bbcode inside
meillo@8 82 * @param $smilies set to 1 causes smilies to be replaced with pics
meillo@8 83 * @param $images set to 1 causes images to be displayed ([img]-tag)
meillo@8 84 * @return text with HTML-code
meillo@8 85 */
meillo@0 86 function bbcode($text, $smilies = 0, $images = 0) {
meillo@0 87
meillo@0 88 // smilies
meillo@0 89 if ($smilies == 1) {
meillo@0 90 $text = smilies($text);
meillo@0 91 }
meillo@0 92
meillo@0 93 // new-lines
meillo@0 94 $text = preg_replace("#(\r\n)|(\r)#", "\n", $text);
meillo@0 95 $text = str_replace("\n", '<br />[nl]', htmlentities($text));
meillo@0 96
meillo@0 97 // bold
meillo@0 98 $text = preg_replace("#\[b\](.*?)\[/b\]#i", "<strong>$1</strong>", $text);
meillo@0 99 // italic
meillo@0 100 $text = preg_replace("#\[i\](.*?)\[/i\]#i", "<i>$1</i>", $text);
meillo@0 101 // links
meillo@0 102 $text = preg_replace("#\[url\](.*)\[/url\]#iU", "<a href=\"$1\">$1</a>", $text);
meillo@0 103 $text = preg_replace("#\[url=(.*)\](.*)\[/url\]#iU", "<a href=\"$1\">$2</a>", $text);
meillo@0 104 // lists
meillo@0 105 //$text = preg_replace("#\[list\]\<br /\>(.*)\[/list\]#iU", "<ul>$1</ul>", $text);
meillo@0 106 //$text = preg_replace("#\[\*\](.*)\<br \/\>#iU", "<li>$1</li>", $text);
meillo@0 107 // quotes
meillo@0 108 $text = parse_quote1($text);
meillo@0 109 $text = parse_quote2($text);
meillo@0 110 // images
meillo@0 111 if ($images == 1) {
meillo@0 112 $text = preg_replace("#\[img\](.*?)\[/img\]#i", "<img src=\"$1\" alt=\"&lt;[Bild]&gt;\" />", $text);
meillo@0 113 }
meillo@0 114
meillo@0 115 // remove backslashes
meillo@0 116 $text = preg_replace("#\\\#is", "", $text);
meillo@0 117 // new-lines
meillo@0 118 $text = str_replace('[nl]', "\n", $text);
meillo@0 119
meillo@0 120 return $text;
meillo@0 121 }
meillo@0 122
meillo@8 123 ?>