bbcode.php
<?php function bbcode($text) { $text = preg_replace("/[b](.+?)[/b]/is", '<b>$1</b>', $text); //заменяме bbcode [b]текст[/b] с html-а <b>текст</b>... надолу се прави абсолютно същотото за всеки bbcode $text = preg_replace("/[i](.+?)[/i]/is", '<i>$1</i>', $text); $text = preg_replace("/[u](.+?)[/u]/is", '<u>$1</u>', $text); $text = preg_replace("/[l](.+?)[/l]/is", '<div style="text-align:left;">$1</div>', $text); $text = preg_replace("/[c](.+?)[/c]/is", '<div style="text-align:center;">$1</div>', $text); $text = preg_replace("/[r](.+?)[/r]/is", '<div style="text-align:right;">$1</div>', $text); $text = preg_replace("/[j](.+?)[/j]/is", '<div style="text-align:justify;">$1</div>', $text); $text = preg_replace("/[s](.+?)[/s]/is", '<strike>$1</strike>', $text); $patterns = array(' /[url=(.*?)](.*?)[/url]/is', '/[img=(.*?)](.*?)[/img]/is', '/[url](.*?)[/url]/is', '/[img](.*?)[/img]/is', '/(^(http|https)(S+))/is' ); $replaces = array('<a href="$1" target="_blank">$2</a>', '<a href="$1" target="_blank"><img src="$2" target="_blank"/></a>', '<a href="$1" target="_blank">$1</a>', '<img src="$1" target="_blank"/>', '<a href="$1" target="_blank">$1</a>'); $text = preg_replace($patterns, $replaces, $text); $text = preg_replace("/[list=un](.+?)[/list]/is", '<ul>$1</ul>', $text); $text = preg_replace("/[list=or](.+?)[/list]/is", '<ol>$1</ol>', $text); $text = preg_replace("/[*](.+?)[/*]/is", '<li>$1</li>', $text); $text = preg_replace("/[quote](.+?)[/quote]/is", '<table cellspacing="1" border="0"><tr><td class="quote">Цитат:</td></tr><tr><td>$1</td></tr></table>', $text); $text = preg_replace("/[quote=(.+?)](.+?)[/quote]/is", '<table cellspacing="1" border="0"><tr><td class="quote">$1 каза:</td></tr><tr><td>$2</td></tr></table>', $text); $text = preg_replace("/[color=(.+?)](.+?)[/color]/is", '<span style="color:$1">$2</span>', $text); $text = preg_replace("/[size=(.+?)](.+?)[/size]/is", '<span style="font-size:$1px;">$2</span>', $text); $text = preg_replace("/[code](.+?)[/code]/is", '<table cellspacing="1" border="0"><tr><td>Code:</td></tr><tr><td class="code"><code class="prettyprint">$1</code></td></tr></table>', $text); $dir = "smiles"; //папката в която са картинките $smiles = array(':)', ':(', ':D', ':P', '(shy)', '8)', '(h)', '(angel)', '(bye)', '(thumbsup)', '(chin)', '(bop)', '(crazy)', '(mad)', '(spock)', ':@', '(drool)', '(popcorn)', '(icecream)', '(arms)', '(baby)', '(badday)', '(bananadance)', '(banned)', '(bash)', '(beer)', '(beer2)', '(biggrin)', '(blink)', '(bouncy)', '(bow)', '(cake)', '(chair)', '(cheekkiss)', '(cigar)', '(clap)', '(clover)', '(clown)', '(confused)', '(console)', ';(', ':S', '(cupid)', '(drinks)', '(dry)', '(dumbells)', '(dunce)', '(evil)', '(evilmad)', '(excited)', '(fart)', '(fish)', '(fishing)', '(flowers)', '(gathering)', '(goodgrief)', '(greedy)', '(group)', '(guns)', '(happy)', '(happy2)', '(happyno)', '(happyyes)', '(hbd)', '(hooray)', '(horse)', '(hug)', '(huglove)', '(hump)', '(jawdrop)', ':*', '(kissing2)', '(lol)', '(look)', '(lovers)', '(music)', '(no)', '(ohmy)', '(ouch)', '(poke)', '(puke)', '(rant)', '(rant2)', '(rofl)', '(rolleyes)', '(shoot)', '(shoot2)', ':X', '(sick)', '(slaphead)', '(sleep)', '(sleeping)', '(smartass)', '(snap)', '(stamp)', '(stereo)', '(strongbench)', '(tears)', '(tease)', '(therethere)', '(thumbsdown)', '(unsure)', '(wavecry)', '(weakbench)', '(weirdo)', '(what)', '(whip)', '(whistle)', '(wiggle)', ';)', '(worthy)', '(wub)', '(yawn)', '(yikes)'); //текста който е бил в textarea-та $smileslink = array('smile.gif', 'sad.gif', 'laught.gif', 'bleh.gif', 'shy.gif', 'cool.gif', 'love.gif', 'angel.gif', 'bye.gif', 'thumbsup.gif', 'chin.gif', 'bop.gif', 'crazy.gif', 'mad.gif', 'spock.gif', 'explode.gif', 'drool.gif', 'popcorn.gif', 'icecream.gif', 'arms.gif', 'baby.gif', 'badday.gif', 'bananadance.gif', 'banned.gif', 'bash.gif', 'beer.gif', 'beer2.gif', 'biggrin.gif', 'blink.gif', 'bouncy.gif', 'bow.gif', 'cake.gif', 'chair.gif', 'cheekkiss.gif', 'cigar.gif', 'clap.gif', 'clover.gif', 'clown.gif', 'confused.gif', 'console.gif', 'cry.gif', 'cry2.gif', 'cupid.gif', 'drinks.gif', 'dry.gif', 'dumbells.gif', 'dunce.gif', 'evil.gif', 'evilmad.gif', 'excited.gif', 'fart.gif', 'fish.gif', 'fishing.gif', 'flowers.gif', 'gathering.gif', 'goodgrief.gif', 'greedy.gif', 'group.gif', 'guns.gif', 'happy.gif', 'happy2.gif', 'happyno.gif', 'happyyes.gif', 'hbd.gif', 'hooray.gif', 'horse.gif', 'hug.gif', 'huglove.gif', 'hump.gif', 'jawdrop.gif', 'kissing.gif', 'kissing2.gif', 'lol.gif', 'look.gif', 'lovers.gif', 'music.gif', 'no.gif', 'ohmy.gif', 'ouch.gif', 'poke.gif', 'puke.gif', 'rant.gif', 'rant2.gif', 'rofl.gif', 'rolleyes.gif', 'shoot.gif', 'shoot2.gif', 'shutup.gif', 'sick.gif', 'slaphead.gif', 'sleep.gif', 'sleeping.gif', 'smartass.gif', 'snap.gif', 'stamp.gif', 'stereo.gif', 'strongbench.gif', 'tears.gif', 'tease.gif', 'therethere.gif', 'thumbsdown.gif', 'unsure.gif', 'wavecry.gif', 'weakbench.gif', 'weirdo.gif', 'what.gif', 'whip.gif', 'whistle.gif', 'wiggle.gif', 'wink.gif', 'worthy.gif', 'wub.gif', 'yawn.gif', 'yikes.gif'); //въведи съответното име на всяка една картинка $i = 0; foreach ($smiles as $sm) { $title = preg_replace('/.(png|gif|jpeg|jpg)/i', '', $smileslink[$i]); $text = str_replace(" ".$sm." ", "<img src='$dir/$smileslink[$i]' title='$title'/>", $text); $i++; } $text = nl2br($text); //преобразува всички празни редове до <br /> $s1s = array('/[table]<br />/is', '/[td]<br />/is', '/[/td]<br />/is', '/[tr]<br />/is', '/[/tr]<br />/is', '/<li><br />/is', '/</li><br />/is', '/<ol><br />/is', '/<ul><br />/is'); $bez = array('[table]', '[td]', '[/td]', '[tr]', '[/tr]', '<li>', '</li>', '<ol>', '<ul>'); $text = preg_replace($s1s, $bez, $text); //махам <br /> от някои места за да се изместват нещата $text = preg_replace("/[table](.+?)[/table]/is", '<table border="1" max-width="600">$1</table>', $text); $text = preg_replace("/[tr](.+?)[/tr]/is", '<tr>$1</tr>', $text); $text = preg_replace("/[td](.+?)[/td]/is", '<td>$1</td>', $text); if (preg_match_all('/[youtube](.+?)[/youtube]/is', $text, $answers, PREG_SET_ORDER)) { foreach($answers AS $answer) { if (preg_match('/youtube.com/watch?v=(.+?)([&])/is', $answer[1] . '&', $id)) { $embed = '<iframe width="420" height="315" src="http://www.youtube.com/embed/' . $id[1] . '" frameborder="0" allowfullscreen></iframe>'; $text = str_replace($answer[0], $embed, $text); } else $text = str_replace($answer[0], '', $text); } } if (preg_match_all('/[vbox7](.+?)[/vbox7]/is', $text, $answers, PREG_SET_ORDER)) { foreach($answers AS $answer) { if (preg_match('/vbox7.com/play:(.+?)([&])/is', $answer[1] . '&', $id)) { $embed = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="450" height="403"><param name="movie" value="http://i48.vbox7.com/player/ext.swf?vid=' . $id[1] . '"><param name="quality" value="high"><embed src="http://i48.vbox7.com/player/ext.swf?vid=' . $id[1] . '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="450" height="403"></embed></object>'; $text = str_replace($answer[0], $embed, $text); } else $text = str_replace($answer[0], '', $text); } } $text = preg_replace("/[offtopic](.+?)[/offtopic]/is", '<table class="offtable" cellspacing="1" border="0"><tr><td><input type="button" class="showoff" value="offtopic"/></td></tr><tr><td class="offtopic">$1</td></tr></table>', $text); return stripslashes($text); //връща променото съдържание } ?>