Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Input Formatter - how to

edited November 2011 in Vanilla 2.0 - 2.8
Now I do so

/*================================================= // forum\applications\vanilla\views\post\preview.php , // forum\applications\vanilla\views\discussion\helper_functions.php ================================================== include_once ("/var/www/hosting/domains.com/htdocs/ forum_additions/BBCode2GeShi.php"); $Object->Body = fBBCode2Geshi($Object->Body, 0 , true); $Object->FormatBody = Gdn_Format::To($Object->Body, $Object->Format); $Sender->FireEvent('AfterCommentFormat'); $Object = $Sender->EventArguments['Object']; echo fBBCode2Geshi($Object->FormatBody, 1 ); */

and have to rewrite the code after forum updates.

I beleive there is a more applicable way to write a formatting wrapper.

Best Answer

  • Options
    x00x00 MVP
    Answer ✓
    1. Pre-format by changing [code][/code] into recoverable format.
    2. Allow standard formatting to take place
    3. Post-format with GeShi
    That is all the help I can give you.

    grep is your friend.

Answers

  • Options
    x00x00 MVP
    edited November 2011
    This is a bad way to do this. Look at the textile plugin.

    You need to register the factory through a plugin. then enable it as the default formatter through config.

    It is the Format column in the database that is applied. So if you want post in the past to have this formatter then you need to update those records.

    I presume you have a problem with the BBCode formatter shipped with vanilla?

    grep is your friend.

  • Options
    edited November 2011
    I found textile . Thanx . Maybe there's some solution in it.

    As for BBCode formatter - yes, I got some problem while connecting GeShi .

    BBCode formatter in formatters chain makes text inside CODE tag unreadable for GeShi.
    Besides I need some additional tags inside of [code]. So above there's my first working code - change [code]asdfasdf[/code] to ABACABADABACABA%nn, then format with inner vanilla bbcode formatters, then unpack ABACABADABACABA%nn from static array.

    Actually i'm finding an external link to formatting chain.
  • Options
    x00x00 MVP
    edited November 2011
    Ok I wouldn't do this with a format. I would pre and post format using a plug-in. This is done with hooks rather than registering a formatter. You could use [GeShi][/GeShi]

    Formatter is one at a time. Compound formatters made by registering a compound formatter, but I wouldn't do it this way.

    But in any event this shouldn't be done in the views. Views are for output, not hunks of code.

    grep is your friend.

  • Options
    edited November 2011
    But in any event this shouldn't be done in the views. Views are for output, not hunks of code.
    But the goal is to show viewable content to the forum users.

    [code]asdfasdfas[/code] is contained in the database.
    and it is unpacked when user loades a page.
    Formatter is one at a time. Compound formatters made by registering a compound formatter, but I wouldn't do it this way.
    i really need some formatter chain. so I have no way besides wrapper in the engine.
    You could use [GeShi][/GeShi]
    it is not the best idea because of standarted tag names. but I'm interested how to use GeShi tag. also i need inner markup-tag to mark some code inside [code][/code] [GeShi][/GeShi].
  • Options
    x00x00 MVP
    edited November 2011
    you are not understanding what I'm saying

    Do you know what model, controller, view is? Views aren't for putting large chunks of code in. This is bad practice.

    I have given you advice about how to do it, if you choose to ignore that that is your problem. You have no need to register more formatters but might use the functionality for cosmetic reasons, just do as I explained.

    Over and out.

    grep is your friend.

  • Options
    [GeShi][/GeShi] is pre-formating suggestion, not input.

    Btw BBcode has no standard. that is why I don't encourage it.

    grep is your friend.

  • Options
    Do you know what model, controller, view is? Views aren't for putting large chunks of code in. This is bad practice.
    :)

    Is really BBCode is a bad practice in the Internet ?

    Of course I understand that CPU works much more, while unpacking text from BBCode to HTML to show page content. But my additional not huge formatter is no problem when we have been already running bbcode plugin in Gdn_Format::To($Object->Body, $Object->Format);
    Btw BBcode has no standard.
    :) You may visit a lot of bbcode sites and the main list of tags is standarted. For showing sources are usually used tags [SRC] and [CODE].

    ps
    I'm ready to change CODE to SRC :)
  • Options
    422422 Developer MVP

    There was an error rendering this rich post.

  • Options
    [GeShi][/GeShi] is pre-formating suggestion, not input.
    Ok,

    So I need NNBC to work with [GeShi][/GeShi] tag and not let NNBC to damage text inside of this tag.
  • Options
    There is no where where bbcode is standardised formally, that is what I meant. If you want to use it then fine.

    grep is your friend.

  • Options
    [GeShi][/GeShi] is pre-formating suggestion, not input.
    Ok,

    So I need NNBC to work with [GeShi][/GeShi] tag and not let NNBC to damage text inside of this tag.
    No it is more like labelling it for later. You might need to safeguard it also, but putting it is a recoverable format.

    grep is your friend.

  • Options
    422422 Developer MVP
    http://en.wikipedia.org/wiki/BBCode
    https://www.vbulletin.com/forum/misc.php?do=bbcode

    Bbcode used incorrectly can lead to server attack.

    Ckeditor and geshi can be used.

    Incidentally i released over twenty bbcode plugins for vb.org when i was coding for vb

    There was an error rendering this rich post.

  • Options
    x00x00 MVP
    Answer ✓
    1. Pre-format by changing [code][/code] into recoverable format.
    2. Allow standard formatting to take place
    3. Post-format with GeShi
    That is all the help I can give you.

    grep is your friend.

  • Options
    x00x00 MVP
    edited November 2011
    Are you using the GeSHi plugin? it use <pre>, you can simply change the ParseSyntax method.

    grep is your friend.

  • Options
    edited November 2011
    1. Pre-format by changing [code][/code] into recoverable format.
    2. Allow standard formatting to take place
    3. Post-format with GeShi
    That is all the help I can give you.
    I do the same in the wrapper function
    Are you using the GeSHi plugin? it use <pre>, you can simply change the ParseSyntax method.
    No, not plugin -

    <?php /*==================================================================== // preview.php , // forum\applications\vanilla\views\discussion\helper_functions.php //==================================================================== include_once ("/var/www/hosting/domain.com/htdocs/forum_additions/BBCode2GeShi.php"); $Object->Body = fBBCode2Geshi($Object->Body, 0 , true); $Object->FormatBody = Gdn_Format::To($Object->Body, $Object->Format); $Sender->FireEvent('AfterCommentFormat'); $Object = $Sender->EventArguments['Object']; echo fBBCode2Geshi($Object->FormatBody, 1 ); */ if (class_exists("GeSHi")==false){ include ("/var/www/hosting/domain.com/htdocs/geshi/geshi.php");} function fBBCode2Geshi ($s, $mode, $showlines) { if (1==1) { //clear WYSIWIG trash $s=preg_replace("@ @"," ",$s); $s=preg_replace("@]<\/p[/>]@","\n",$s); $s=preg_replace("@]@","\n",$s); $s=preg_replace("@]@","",$s); $s=preg_replace("@<\/p[/>]@","\n",$s); $s=trim($s); } $CHANGE_NN="_ABACABAiiiDABACABA_"; $DEVIDER="_a789qwertyFF_"; static $STATIC_ARR_CODE; if ($mode==0) { $STATIC_ARR_CODE=''; $regexp_code = "/\[CODE](.*)\[\/CODE]/imsU"; preg_match_all($regexp_code, $s, $matches); $arr=$matches[0]; $maxarr=count($arr)-1; if (!empty($arr)) { for ($i=0; $i <= $maxarr; $i++) { $s=preg_replace($regexp_code,"$CHANGE_NN$i%",$s,1); //cut off [code] and [/code] $code=$arr[$i]; $len=strlen($code); $val=substr($code, 6, $len-13); // // get GeShi <div> // $language = 'vb'; $code = htmlspecialchars_decode($code); $geshi = new GeSHi($code, $language); $geshi->enable_keyword_links(false); $geshi->enable_classes(); $output .= ""; $output .= ""; $output .= ""; $output .= $geshi->parse_code(); $output .= ""; $output .= ""; unset($geshi); $output .= ""; // SAVE TO STATIC ARRAY $STATIC_ARR_CODE = $STATIC_ARR_CODE.$output.$DEVIDER; } // FOR }// EMPTY } else { // // RESTORE FROM ARRAY // $arr=explode($DEVIDER,$STATIC_ARR_CODE); if (!empty($arr)) { $maxarr=count($arr)-1; for ($i=0; $i <= $maxarr; $i++) { $CODE=$arr[$i]; $s=preg_replace("/$CHANGE_NN$i%/",$CODE,$s); } }  } //ELSE ENDIF return $s; } //end function ?>
  • Options
    Look at the plugin for your starting point.

    grep is your friend.

  • Options
    Looked. Began to write my own handlers in the Geshi plugin..................

    $String="0".$String."0";

    add this string before return $String

    in ParseSyntax - and you'll see some surprise;
Sign In or Register to comment.