|
#1
|
|||
|
|||
tinymce bbcode
TinyMCE bbcode plugin.js :
PHP Code:
Code:
$img_count=0; // 3 functions for the bbcode. Have to be declared outside the function to be able to call bbcode more than once. function dosize($matches) { return '<span style="font-size: '.(50*$matches[3]).'%">'.$matches[4].'</span>'; } function noparsed($matches) { // any character that is parsed, must be here static $replace=array( '://' => '://', '(' => '(', ')' => ')', '-' => '-', '/' => '/', ':' => ':', '[' => '[', ']' => ']', '_' => '_',); return str_replace( array_keys($replace), array_values($replace) ,$matches[2]); } function formatlist($matches) { if ($matches[3]=='') { $content.='<ul>'; $end='</ul>'; } elseif(strtolower($matches[3])=="a" || strtolower($matches[3])=="i") { $content.="<ol type=\"{$matches[3]}\">"; $end='</ol>'; } elseif (strtolower($matches[3])=="1") { $content.="<ol>"; $end='</ol>'; } else { $content.="<ul type=\"{$matches[3]}\">"; $end='</ul>'; } return $content.$matches[4].$end; } function parseimage($matches) { global $img_count; $img_count++; return "<div id=\"img{$img_count}\" style=\"font-size:'1'; display:inline;\"><a href=\"$matches[3]://$matches[4]\" data-fancybox=\"images\" ><img name=\"img{$img_count}\" onload='resize(this);' src='$matches[3]://$matches[4]' border='0' alt='' /></a></div>"; } function bbcode($content) { global $language; // Fix & to be & unless it's already & or a special character like ▀ or some regualr ones like <,>,",(c), . More can be found here: http://www.utexas.edu/learn/html/spchar.html But they can use the decimal verisons if the want those $content=preg_replace('/&(?!(amp|[#0-9]+|lt|gt|quot|copy|nbsp);)/ix','&',$content); // But some special chars are bad, at least according to vB, so strip them. Most are just blank characters used to bypass filters, except for which is just awesome! $content=str_replace(array(' ','','','','',''),'',$content); // Change new lines to <br />. nl2br function probably would work also. It's probably the same as this though. And gets rid of htmlchars. htmlentities screws up the & stuff. $content=str_replace(array('<','>','\'','"',"\r\n","\r","\n"),array('<','>',''','"','<br />','<br />','<br />'),$content); do{ // No parse. Just replace anything that is parsed, into their HTML equivalents $content=preg_replace_callback('/\[(noparse(?:\d|))\](.+?)\[\/\1\]/i','noparsed',$content, -1, $count); }while($count); do{ // code tags must be parsed first, because their contents are not parsed. $content=preg_replace('/\[(code(?:\d|))\](.+?)\[\/\1\]/i','<br /><b>Code</b><br /><table width="100%" border="1" cellspacing="0" cellpadding="10" class="code"><tr><td>[tt][noparse9]$2[/noparse9][/tt]</td></tr></table><br />',$content, -1, $count); }while($count); //[align=(center|left|right|justify)]text[/align] $content = preg_replace("/\[align=([a-zA-Z]+)\](.+?)\[\/align\]/is","<div style=\"text-align:\\1\">\\2</div>", $content); $content = preg_replace("/\[indent=([0-9]+)px\](.+?)\[\/indent\]/is","<p style=\"padding-left: \\1px;\">\\2</p>", $content); // Video tag [video=url] // YouTube Vids $content = preg_replace("/\[video=[^\s'\"<>]*youtube.com.*v=([^\s'\"<>]+)\]/ims", "<object width=\"500\" height=\"410\"><param name=\"movie\" value=\"http://www.youtube.com/v/\\1\"></param><embed src=\"http://www.youtube.com/v/\\1\" type=\"application/x-shockwave-flash\" width=\"500\" height=\"410\"></embed></object>", $content); $content = preg_replace("/\[video=[^\s'\"<>]*youtu.be.*\/([^\s'\"<>]+)\]/ims", "<object width=\"500\" height=\"410\"><param name=\"movie\" value=\"http://www.youtube.com/v/\\1\"></param><embed src=\"http://www.youtube.com/v/\\1\" type=\"application/x-shockwave-flash\" width=\"500\" height=\"410\"></embed></object>", $content); // Google Vids //$content = preg_replace("/\[video=[^\s'\"<>]*video.google.com.*docid=(-?[0-9]+).*\]/ims", "<embed style=\"width:500px; height:410px;\" id=\"VideoPlayback\" align=\"middle\" type=\"application/x-shockwave-flash\" src=\"http://video.google.com/googleplayer.swf?docId=\\1\" allowScriptAccess=\"sameDomain\" quality=\"best\" bgcolor=\"#ffffff\" scale=\"noScale\" wmode=\"window\" salign=\"TL\" FlashVars=\"playerMode=embedded\"> </embed>", $content); //[video=http://somesite.com/test.swf] // "<param name=movie value=\\1/><embed width=470 height=350 src=\\1></embed>", $content); do{ // code blocks insert the noparse tag. Can't parse the code block first, or you can't use noparse on it. $content=preg_replace_callback('/\[(noparse(?:\d|))\](.+?)\[\/\1\]/i','noparsed',$content, -1, $count); }while($count); // Quotes! do{ $content = preg_replace('/\[(quote(?:\d|))\](.+?)\[\/\1\]/i','<br /><b>'.$language['QUOTE'].':</b><br /><table width="100%" border="1" cellspacing="0" cellpadding="10" class="quote"><tr><td >$2</td></tr></table><br />',$content, -1, $count); }while($count); do{ $content = preg_replace('/\[(quote(?:\d|))=("|&#(?:0|)39;|"|\'|)(.+?)\2\](.+?)\[\/\1\]/i','<br /><b>$3 '.$language['WROTE'].':</b><br /><table width="100%" border="1" cellspacing="0" cellpadding="10" class="quote"><tr><td>$4</td></tr></table><br />',$content, -1, $count); }while($count); // .userquoteinfo { font-size:85%; font-weight: bold; font-style: italic; } // Images. They have to have http://. src attributes are XSSable in IE 6.0, Netscape, and Opera. http://ha.ckers.org/xss.html. Even though it's hard to do without () or \, best not to mess around with it. $content=preg_replace_callback('/\[(img(?:\d|))\]("|&#(?:0|)39;|"|\'|)(http|https|ftp|ftps):\/\/([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]*)\2\[\/\1\]/i','parseimage',$content); $content=preg_replace_callback('/\[(img(?:\d|))=("|&#(?:0|)39;|"|\'|)(http|https|ftp|ftps):\/\/([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]*)\2\]/i','parseimage',$content); // text $content=preg_replace('/\[(url(?:\d|))\=("|&#(?:0|)39;|"|\'|)(http|https|ftp|ftps|ed2k|irc):\/\/([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]*)\2\](.+?)\[\/\1\]/i', '<a href="$3://$4" target="_blank">$5</a>', $content); // For people too lazy to put http:// on the uri. /Shouldn't/ be XSSable $content=preg_replace('/\[(url(?:\d|))\=("|&#(?:0|)39;|"|\'|)([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]*)\2\](.+?)\[\/\1\]/i', '<a href="http://$3" target="_blank">$4</a>', $content); // uri $content=preg_replace('/\[(url(?:\d|))\](http|https|ftp|ftps|ed2k|irc):\/\/([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]*)\[\/\1\]/i','<a href="$2://$3" target="_blank">$2://$3</a>',$content); // lazy http:// people... $content=preg_replace('/\[(url(?:\d|))\]([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]*)\[\/\1\]/i','<a href="http://$2" target="_blank">http://$2</a>',$content); // http://www.google.com -> <a href="http://www.google.com">http://www.google.com</a> $content=preg_replace('/(?<![href|src]=["|&#(?:0|)39;|"|\'])(http|https|ftp|ftps|ed2k|irc):\/\/([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]*)/i','<a href="$1://$2" target="_blank">$1://$2</a>',$content); // Email. Do people even use this? Yes, so they can get revenge on someone by posting their email address. $content=preg_replace('/\[(email(?:\d|))\]([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]+)@([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]+)\[\/\1\]/i','<a href="mailto:$2@$3">$2@$3</a>',$content); //[Spoiler]TEXT[/Spoiler] $content=preg_replace("/\[Spoiler\]((\s|.)+?)\[\/Spoiler\]/", "<div style="padding: 3px; border: 1px solid #d8d8d8; font-size: 1em;"><div style="text-transform: uppercase; border-bottom: 1px solid #CCCCCC; margin-bottom: 3px; font-size: 0.8em; font-weight: bold; display: block;"><span onClick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = ''; this.innerHTML = '<b>Spoiler: </b><a href=\'#\' onClick=\'return false;\'>hide</a>'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerHTML = '<b>Spoiler: </b><a href=\'#\' onClick=\'return false;\'>show</a>'; }" /><b>Spoiler:</b><a href="#" onClick="return false;">show</a></span></div><div class="quotecontent"><div style="display: none;">\\1</div></div></div>",$content); // [marquee]Marquee[/marquee] $content=preg_replace("/\[scroll=([a-zA-Z ,]+)\]((\s|.)+?)\[\/scroll\]/i","<marquee class="tableb" direction="\\1" scrollamount="3" scrolldelay="2" onmouseover="this.stop();" onmouseout="this.start();">\\2</marquee>",$content); do{ // bold, big, italics, strike through, tt, underline, em, strong, subscript, superscript, overline, pre $content=preg_replace('/\[((none|b|big|i|s|strike|tt|u|o|underline|em|strong|sub|sup|pre)(?:\d|))\](.+?)\[\/\1\]/i','<$2>$3</$2>',$content, -1, $count); }while($count); do{ // [left], [center], [right] and [justify] tags $content=preg_replace('/\[((left|right|center|justify)(?:\d|))\](.+?)\[\/\1\]/i', '<div align="$2">$3</div>',$content, -1, $count); }while($count); do{ // the color is the tag itself, like [fgyellow]yellow text[/fgyellow], or [fg-blue]blue text[/fg-blue] // If the color is the tag itself, like [green], then it must ALWAYS be a whitelist of accepted colors. $content=preg_replace('/\[((?:fg|fg-|)(black|silver|gray|white|maroon|red|purple|fuchsia|green|lime|olive|yellow|navy|blue|teal|aqua)(?:\d|))\](.+?)\[\/\1\]/i','<font color="$2">$3</font>',$content, -1, $count); }while($count); do{ // font color. Word type, like RED not limited in name, for backwards compatability. $content=preg_replace('/\[((?:fg|fg-|)colo(?:u|)r(?:\d|))=("|&#(?:0|)39;|"|\'|)([a-z]{0,25})\2\](.+?)\[\/\1\]/i','<font color="$3">$4</font>',$content, -1, $count); } /* while($count); do{ // Color specified in RGB triplet, like GREY $content=preg_replace('/\[((?:fg|fg-|)colo(?:u|)r(?:\d|))=("|#|&#(?:0|)39;|"|\'|)([\dA-F]{0,9})\2\](.+?)\[\/\1\]/i','<span style="color:#$3;">$4</span>',$content, -1, $count); } */ while($count); do{ // Color specified in RGB triplet, like GREY $content=preg_replace('/\[color=(.+?)](.+?)\[\/color]/i','<span style="color:$1;">$2</span>',$content, -1, $count); } while($count); // background colors do{ // background color specified in RGB triplet, like [bg-color=ff0000]red background[/bg-color] $content=preg_replace('/\[bg-color=(.+?)](.+?)\[\/bg-color]/i','<span style="background: $1;">$2</span>',$content, -1, $count); }while($count); do{ // but since the bgcolor tag is new, I will limit the colors, for maximum web compatability. Of course you can set any color you like with the RGB background tag. Maybe remove color whitelist, dependong on user feedback. $content=preg_replace('/\[((?:bg|bg-)colo(?:u|)r(?:\d|))=("|&#(?:0|)39;|"|\'|)(black|silver|gray|white|maroon|red|purple|fuchsia|green|lime|olive|yellow|navy|blue|teal|aqua)\2\](.+?)\[\/\1\]/i','<span style="background: $3;">$4</span>',$content, -1, $count); }while($count); do{ // This background tag uses the following syntax, for a red background: [bgred] or [bg-red] $content=preg_replace('/\[((?:bg|bg-)(black|silver|gray|white|maroon|red|purple|fuchsia|green|lime|olive|yellow|navy|blue|teal|aqua)(?:\d|))\](.+?)\[\/\1\]/i','<span style="background: $2;">$3</span>',$content, -1, $count); }while($count); do{ // background color specified in RGB triplet, like [bg-color=ff0000]red background[/bg-color] $content=preg_replace('/\[((?:bg|bg-)colo(?:u|)r(?:\d|))=("|&#(?:0|)39;|"|\'|)([0-9A-F]{3,6})\2\](.+?)\[\/\1\]/i','<span style="background: #$3;">$4</span>',$content, -1, $count); }while($count); //font-family $content=preg_replace('/\[font=([a-zA-Z ,]+)\]((\s|.)+?)\[\/font\]/i', '<span style="font-family:\'\1\'">$2</span>',$content); do{ // Size. 1,2,3,4...8 = 50%, 100%, 150%, 200%...400% Algo: 50 * size $content = preg_replace_callback('/\[(size(?:\d|))=("|&#(?:0|)39;|"|\'|)([1-8])\2\](.+?)\[\/\1\]/i','dosize',$content, -1, $count); }while($count); do{ // Size. 1,2,3,4...8 = 50%, 100%, 150%, 200%...400% Algo: 50 * size $content = preg_replace('/\[size=(8pt|10pt|12pt|14pt|18pt|24pt|36pt)](.+?)\[\/size]/i','<span style="font-size: $1;">$2</span>',$content, -1, $count); }while($count); do{ // [size=xx-small] style tag $content = preg_replace('/\[(size(?:\d|))=("|&#(?:0|)39;|"|\'|)((xx-small|x-small|small|medium|large|x-large|xx-large|larger|smaller)(?:\d|))\2\](.+?)\[\/\1\]/i','<font style="font-size: $4;">$5</font>',$content, -1, $count); }while($count); do{ // [xx-large] style tag $content = preg_replace('/\[((xx-small|x-small|small|medium|large|x-large|xx-large|larger|smaller)(?:\d|))\](.+?)\[\/\1\]/i','<font style="font-size: $2;">$3</font>',$content, -1, $count); }while($count); //Lists do{ // [list] or [list=a] or [list=circle] etc $content=preg_replace_callback('/\[(list(?:\d|))(?:=("|&#(?:0|)39;|"|\'|)(a|i|1|disc|square|circle)\2|)\](.+?)\[\/\1\]/i','formatlist',$content, -1, $count); }while($count); // just some little things I thought might be nice to have. static $replace=array( " " => " ", "[*]" => "<li>", "[li]" => "<li>", "[/li]" => "</li>", "[hr]" => "<hr>", "[br]" => "<br />", "(c)" => "©", "[c]" => "©", "(p)" => "℗", "[p]" => "℗", "(r)" => "®", "[r]" => "®", "(tm)" => "™", "[tm]" => "™", "1/2" => "½", "1/3" => "⅓", "2/3" => "⅔", "1/4" => "¼", "3/4" => "¾", "1/5" => "⅕", "2/5" => "⅖", "3/5" => "⅗", "4/5" => "⅘", "1/6" => "⅙", "5/6" => "⅚", "1/8" => "⅛", "3/8" => "⅜", "5/8" => "⅝", "7/8" => "⅞" ); $content=str_ireplace(array_keys($replace), array_values($replace) ,$content); return $content; } function dehtml($content) { $content=preg_replace('/&(?!(amp|[#0-9]+|lt|gt|quot|copy|nbsp);)/ix','&',$content); $content=str_replace(array(' ','','','','',''),'',$content); return str_replace(array('<','>','\'','"'),array('<','>',''','"'),$content); } unable to parse smiley / errors occuring when using list if i use another editor , i need to redo all bbcodes |
#2
|
||||
|
||||
first of you need to fix this line
its backing on this so u get error page // Change new lines to <br />. nl2br function probably would work also. It's probably the same as this though. And gets rid of htmlchars. htmlentities screws up the & stuff. Code:
$content=str_replace(array(' ','','','','','// Change new lines to <br />. nl2br function probably would work also. It's probably the same as this though. And gets rid of htmlchars. htmlentities screws up the & stuff.'),'',$content); Last edited by xblade; 14th February 2021 at 13:10. |
#3
|
|||
|
|||
PHP Code:
the code is getting filtered by bvlist editor , here is the function. by the way parse is working for now except for the emotes / smilies (i think the unicodes are getting filtered.) Bump: that line is getting filtered :( Bump: line is getting filtered :( |
|
|