Bravo List

Bravo List (http://www.bvlist.com/index.php)
-   xBTiT (http://www.bvlist.com/forumdisplay.php?f=30)
-   -   tinymce bbcode (http://www.bvlist.com/showthread.php?t=12336)

JohnHasher 13th February 2021 23:06

tinymce bbcode
 
TinyMCE bbcode plugin.js :

PHP Code:

/**
 * Copyright (c) Tiny Technologies, Inc. All rights reserved.
 * Licensed under the LGPL or a commercial license.
 * For LGPL see License.txt in the project root for license information.
 * For commercial licenses see https://www.tiny.cloud/
 *
 * Version: 5.4.1 (2020-07-08)
 *
 * FParadise Customs - DO NOT TRY!
 */
!function(){"use strict";var o=tinymce.util.Tools.resolve("tinymce.PluginManager"),e=tinymce.util.Tools.resolve("tinymce.util.Tools"),t=function(t){t=e.trim(t);var o=function(o,e){t=t.replace(o,e)};return o(/\n/gi,""),o(/\[b\]/gi,"<strong>"),o(/\[\/b\]/gi,"</strong>"),o(/\[i\]/gi,"<em>"),o(/\[\/i\]/gi,"</em>"),o(/\[u\]/gi,"<u>"),o(/\[hr\]/gi,"<hr />"),o(/\[\/u\]/gi,"</u>"),o(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,'<a href="$1">$2</a>'),o(/\[url\](.*?)\[\/url\]/gi,'<a href="$1">$1</a>'),o(/\[img\](.*?)\[\/img\]/gi,'<img src="$1" />'),o(/\[color=(.*?)\](.*?)\[\/color\]/gi,'<font color="$1">$2</font>'),o(/\[bg-color=(.*?)\](.*?)\[\/bg-color\]/gi,'<span style="background-color: $1;">$2</span>'),o(/\[(right|left|center|justify)\](.*?)\[\/(right|left|center|justify)\]/gi,'<p style="text-align: $1;">$2</p>'),o(/\[list=disc\](.*?)\[\/list\]/gi,'<ul>$1</ul>'),o(/\[list=1\](.*?)\[\/list\]/gi,'<ol>$1</ol>'),o(/\[indent=(.*?)px\](.*?)\[\/indent\]/gi,'<p style="padding-left: $1px;">$2</p>'),o(/\[li\](.*?)\[\/li\]/gi,'<li>$1</li>'),o(/\[size=(.*?)\](.*?)\[\/size\]/gi,'<span style="font-size:$1;">$2</span>'),o(/\[align=(left|right)\] \[video=(.*?)\] \[\/align\]/gi,'<video style="float: $1;" width="500" height="410"><source src="$2"></video>'),o(/\[align=center\] \[video=(.*?)\] \[\/align\]/gi,'<video style="display: block; margin-left: auto; margin-right: auto;" width="500" height="410"><source src="$1"></video>'),o(/\[video=(.*?)\]/gi,'<video width="500" height="410"><source src="$1"></video>'),o(/\[code\](.*?)\[\/code\]/gi,'<span class="codeStyle">$1</span>&nbsp;'),o(/\<<<@!1!@>>>"),o(/<font.*?class="codeStyle".*?color="(.*?)".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]"),o(/<font.*?class="quoteStyle".*?color="(.*?)".*?>(.*?)<\/font>/gi,"<<<@!2!@>>>"),o(/<span style="color: ?(.*?);">(.*?)<\/span>/gi,"[color=$1]$2[/color]"),o(/<h(1|2|3|4|5|6)>(.*?)<\/h(1|2|3|4|5|6)>/gi,"[size=$1]$2[/size]"),o(/<p style="text-align: (right|left|center|justify);">(.*?)<\/p>/gi,"[$1] $[/$1]"),o(/<hr \/>/gi,"[hr]"),o(/<font.*?color="(.*?)".*?>(.*?)<\/font>/gi,"[color=$1]$2[/color]"),o(/<ul>(.*?)<\/ul>/gi,"[list=disc]$1[/list]"),o(/<ul style="text-align: (center|right|left|justify);">(.*?)<\/ul>/gi,"[$1][list=disc]$2[/list][/$1]"),o(/<ol>(.*?)<\/ol>/gi,"[list=1]$1[/list]"),o(/<span style="font-size: (8pt|10pt|12pt|14pt|18pt|24pt|36pt); background-color: (.*?);">(.*?)<\/span>/gi,"[size=$1][bg-color=$2]$3[/bg-color][/size]"),o(/<span style="font-size: (8pt|10pt|12pt|14pt|18pt|24pt|36pt); color: (.*?);">(.*?)<\/span>/gi,"[size=$1][color=$2]$3[/color][/size]"),o(/<ul><li style="list-style-typenone;">(.*?)<\/li><\/ul>/gi,"$1"),o(/<li style="list-style-typenone;">(.*?)<\/li>/gi,"$1"),o(/<span style="font-size: (8pt|10pt|12pt|14pt|18pt|24pt|36pt);">(.*?)<\/span>/gi,"[size=$1]$2[/size]"),o(/<video width="500" height="410"><source src="(.*?)"><\/video>/gi,"[video=$1]"),o(/<video style="displayblockmargin-leftautomargin-rightauto;" width="500" height="410"><source src="(.*?)"><\/video>/gi,"[align=center] [video=$1] [/align]"),o(/<p style="text-alignjustify;"><video width="500" height="410"><source src="(.*?)"><\/video><\/p>/gi,"[align=left] [video=$2] [/align]"),o(/<video style="float: (right|left);" width="500" height="410"><source src="(.*?)"><\/video>/gi,"[align=$1] [video=$2] [/align]"),o(/<font>(.*?)<\/font>/gi,"$1"),o(/<img src="(.*?)".*?\/>/gi,"[img]$1[/img]"),o(/<img style="float: (right|left|center);" src="(.*?)".*?\/>/gi,"[$1][img]$2[/img][/$1]"),o(/<img style="displayblockmargin-leftautomargin-rightauto;" src="(.*?)".*?\/>/gi,"[center][img]$1[/img][/center]"),o(/<p style="padding-left: (.*?)pxtext-align: (center|left|right|justify);">(.*?)<\/p>/gi,"[$2][indent=$1px]$3[/indent][/$2]"),o(/<span class="codeStyle">(.*?)<\/span>/gi,"[code]$1[/code]"),o(/<li>(.*?)<\/li>/gi,"[li]$1[/li]"),o(/<li style="text-align: (center|right|left|justify);">(.*?)<\/li>/gi,"[li]$2[/li]"),o(/<p style="padding-left: (.*?)px;">(.*?)<\/p>/gi,"[indent=$1px]$2[/indent]"),o(/<span class="quoteStyle">(.*?)<\/span>/gi,"<<<@!3!@>>>"),o(/<strong class="codeStyle">(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]"),o(/<strong class="quoteStyle">(.*?)<\/strong>/gi,"<<<@!4!@>>>"),o(/<em class="codeStyle">(.*?)<\/em>/gi,"[code][i]$1[/i][/code]"),o(/<span style="background-color: (.*?);">(.*?)<\/span>/gi,"[bg-color=$1]$2[/bg-color]"),o(/<em class="quoteStyle">(.*?)<\/em>/gi,"<<<@!5!@>>>"),o(/<u class="codeStyle">(.*?)<\/u>/gi,"[code][u]$1[/u][/code]"),o(/<u class="quoteStyle">(.*?)<\/u>/gi,"<<<@!6!@>>>"),o(/<\/(strong|b)>/gi,"[/b]"),o(/<(strong|b)>/gi,"[b]"),o(/<\/(em|i)>/gi,"[/i]"),o(/<(em|i)>/gi,"[i]"),o(/<\/u>/gi,"[/u]"),o(/<span style="text-decoration: ?underline;">(.*?)<\/span>/gi,"[u]$1[/u]"),o(/<u>/gi,"[u]"),o(/<blockquote[^>]*>/gi,"<<<@!7!@>>>"),o(/<br \/>/gi,"\n"),o(/<br\/>/gi,"\n"),o(//gi,"\n"),o(/<p>/gi,""),o(/<\/p>/gi,"\n"),o(/&nbsp;|\u00a0/gi," "),o(/"/gi,'"'),o(/</gi,"<"),o(/>/gi,">"),o(/&/gi,"&"),t}(o.content))})})}()}(); 

edited bbcode :
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 ''.$matches[4].'';
}

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.='
    ';
        $end='
';
  } elseif(strtolower($matches[3])=="a" || strtolower($matches[3])=="i") {
    $content.="
    ";
        $end='
';
  }
  elseif (strtolower($matches[3])=="1") {
    $content.="
    ";
        $end='
';
  } else {
    $content.="
    ";
        $end='
';
  }

  return $content.$matches[4].$end;
}

function parseimage($matches) {
  global $img_count;

  $img_count++;
  return "
";
}

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 . 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('<','>',''','"','','',''),$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','Code
[tt][noparse9]$2[/noparse9][/tt]
',$content, -1, $count);
  }while($count);
          //[align=(center|left|right|justify)]text[/align]
    $content = preg_replace("/\[align=([a-zA-Z]+)\](.+?)\[\/align\]/is","
\\2
", $content);
    $content = preg_replace("/\[indent=([0-9]+)px\](.+?)\[\/indent\]/is","

\\2

", $content);

// Video tag [video=url]
// YouTube Vids
$content = preg_replace("/\[video=[^\s'\"<>]*youtube.com.*v=([^\s'\"<>]+)\]/ims", "", $content);
$content = preg_replace("/\[video=[^\s'\"<>]*youtu.be.*\/([^\s'\"<>]+)\]/ims", "", $content);
// Google Vids
//$content = preg_replace("/\[video=[^\s'\"<>]*video.google.com.*docid=(-?[0-9]+).*\]/ims", " ", $content);

    //[video=http://somesite.com/test.swf]
//        "", $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',''.$language['QUOTE'].':
$2
',$content, -1, $count);
  }while($count);
  do{
    $content = preg_replace('/\[(quote(?:\d|))=("|&#(?:0|)39;|"|\'|)(.+?)\2\](.+?)\[\/\1\]/i','$3 '.$language['WROTE'].':
$4
',$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', '$5', $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', '$4', $content);

  // uri
  $content=preg_replace('/\[(url(?:\d|))\](http|https|ftp|ftps|ed2k|irc):\/\/([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]*)\[\/\1\]/i','$2://$3',$content);
  // lazy http:// people...
  $content=preg_replace('/\[(url(?:\d|))\]([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]*)\[\/\1\]/i','http://$2',$content);

  // http://www.google.com -> http://www.google.com
  $content=preg_replace('/(?$1://$2',$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','$2@$3',$content);

//[Spoiler]TEXT[/Spoiler]
    $content=preg_replace("/\[Spoiler\]((\s|.)+?)\[\/Spoiler\]/", "
Spoiler:show
\\1
",$content);

// [marquee]Marquee[/marquee]
    $content=preg_replace("/\[scroll=([a-zA-Z ,]+)\]((\s|.)+?)\[\/scroll\]/i","\\2",$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',$content, -1, $count);
  }while($count);

  do{ // [left], [center], [right] and [justify] tags
    $content=preg_replace('/\[((left|right|center|justify)(?:\d|))\](.+?)\[\/\1\]/i', '
$3
',$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','$3',$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','$4',$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','$4',$content, -1, $count);
  } */
  while($count);
  do{ // Color specified in RGB triplet, like GREY
    $content=preg_replace('/\[color=(.+?)](.+?)\[\/color]/i','$2',$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','$2',$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','$4',$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','$3',$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','$4',$content, -1, $count);
  }while($count);

//font-family
    $content=preg_replace('/\[font=([a-zA-Z ,]+)\]((\s|.)+?)\[\/font\]/i', '$2',$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','$2',$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','$5',$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','$3',$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]" => "
  • ",
        "[hr]" => "
    ",
        "[br]" => "",
        "(c)"  => "©",
        "[c]"  => "©",
        "(p)"  => "℗",
        "[p]"  => "℗",
        "(r)"  => "®",
        "[r]"  => "®",
        "(tm)" => "™",
        "[tm]" => "™",
        "1/2"  => "½",
        "1/3"  => "⅓",
        "2/3"  => "⅔",
        "1/4"  => "&frac14",
        "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 :sad:

    xblade 14th February 2021 12:46

    first of you need to fix this line
    its backing on this so u get error page
    // Change new lines to
    . 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 . 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);


    JohnHasher 20th February 2021 17:12

    PHP Code:

    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);



    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 :(


    All times are GMT +2. The time now is 22:52.

    Powered by vBulletin® Version 3.8.11 Beta 3
    Copyright ©2000 - 2024, vBulletin Solutions Inc.