Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

variable scope, $Head->AddString, argh

2

Comments

  • MarkMark Vanilla Staff
    haha - yes, they were both enabled. But I didn't set up those custom attributes you mentioned in your email...
  • in that case it's possible that plusplus wasn't working. are they still enabled? if plusplus is working, it should translate http://server.com[links like this] without needing any custom attributes.

    *asks too much
  • ithcyithcy New
    edited April 2006
    by changing them both to AddChildFormatter i got them both to load. plusplus still doesn't do anything, though, but if i echo "plusplus" before the class definition, it shows up.

    //actually i guess they were both loading before, just not working. nevermind.
  • MarkMark Vanilla Staff
    Well, I just took a look and it seems that everything worked properly for both (except for the language="javascript" one). I didn't change anything in the plusplus extension you gave me. I just threw it in the folder and enabled it. Check it out:

    image
  • NickENickE New
    edited April 2006
    What you'd probably want to do is reverse the actions of the HtmlFormatter on the code your parsing (ie. revert entites to their original characters, change back the 'script' conversions [obviously after reverting entities], etc...). As for the language="javascript", I'd either search for language="javascript"/language="JavaScript" or use language="js" instead. EDIT: mark, I may be wrong, but it seems as if instances of '&' aren't converted to '&' when you're editing a comment, resulting in (intentional) entities to be shown as what they represent, and subsequently saved as such unless manually changed. EDIT2: yep, that definitely seems to be a bug...
  • *cries
  • SirNot: yeah, the same thing happens with &lt;. it turns into < upon edit.
  • MarkMark Vanilla Staff
    That's very annoying. I had it working perfectly before. I wonder what changed?
  • MarkMark Vanilla Staff
    edited April 2006
    Fixed it. There was a typo in the theme file and it was using an inappropriate version of the comment object.

    It will be a while before the fix is on there, though.
  • any other ideas why this won't work for me?
    could it be something to do with the Parse classes from the two extensions conflicting?
  • ithcyithcy New
    edited April 2006
    ok.. i just made geshicolor extend StringFormatter instead of HtmlFormatter, and used AddManipulator("Text" instead of "Html", and posted a Text comment with some code, and both extensions work. so it appears that the two (three, really) Html parsers are conflicting somehow.
  • ithcyithcy New
    edited April 2006
    i think i'm tracking it down. i made it use AddManipulator("Code"), and extend StringFormatter, and both extensions work when you enter a comment with Code selected.

    So it looks like this: when GeshiFormatter is piggybacking on the Html manipulator along with HtmlPlusPlusFormatter, vanilla is maybe confused about which parser to use with Html comments, and picks GeshiFormatter every time.

    I guess i'm somehow overriding HtmlPlusPlus instead of acting as another formatter in the chain.
  • MarkMark Vanilla Staff
    Okay, I wanted to prove that you can add multiple child formatters to existing formatters. So, I made a new extension that creates two different formatters and adds them both to the HtmlFormatter. I enabled it, and it works - both of the formatters get parsed as they should.

    Here is the code:

    <?php /* Extension Name: Formatter Test Extension Url: null Description: Trying to help ithcy Version: 1 Author: mark Author Url: http://markosullivan.ca */ if (@$Context->Session->UserID > 0 && in_array($Context->SelfUrl, array("comments.php", "post.php"))) { class FooFormatter extends StringFormatter { function Parse($String, $Object, $FormatPurpose) { if($FormatPurpose == FORMAT_STRING_FOR_DISPLAY) return str_replace('foo', 'FOO!!', $String); else return $String; } } class FeeFormatter extends StringFormatter { function Parse($String, $Object, $FormatPurpose) { if($FormatPurpose == FORMAT_STRING_FOR_DISPLAY) return str_replace('fee', 'FEE!!', $String); else return $String; } } $Foo = $Context->ObjectFactory->NewObject($Context, "FooFormatter"); $Fee = $Context->ObjectFactory->NewObject($Context, "FeeFormatter"); $Context->StringManipulator->Formatters["Html"]->AddChildFormatter($Foo); $Context->StringManipulator->Formatters["Html"]->AddChildFormatter($Fee); } ?>
  • i got it. i was using AddChildFormatter in the wrong way. i am an idiot.

    thanks mark. sorry for wasting your time.
    *shrinks

    and thanks SirNot - you're right about needing to undo HtmlFormatter inside the code.
  • it is still strange to me that it worked on your installation. oh well.
  • okay - it's all done.

    i came to the conclusion that rather than undo everything that HtmlFormatter does, i'd be better off giving it its own manipulator and then including code from HtmlFormatter to prevent scripting attacks. SirNot, is that okay with you? If so i'll post the extension to the addons directory.
  • Mark, (Maybe this makes me a spaz or a dillitant, but) Your code it perty.
  • MarkMark Vanilla Staff
    Thanks fernando!
  • Well, if you really want to ithcy, but it'd be sort of hard to update one specifically by doing so. Would you mind if I played around with it a little?
  • Here, how about something like this? (actually had to edit the HtmlFormatter extension a little to allow for attributes in code tags)
    <?php /* Extension Name: Html Formatter ++ Extension Url: http://lussumo.com/docs/ Description: An extension for the HtmlFormatter to syntax highlight source code. Version: 1.0 Author: ithcy and SirNotAppearingOnThisForum Author Url: N/A */ define('GESHI_PATH', 'geshi/'); include_once(GESHI_PATH.'geshi.php'); $GeshiLangs = array( 'actionscript-french', 'actionscript', 'ada', 'apache', 'applescript', 'asm', 'asp', 'bash', 'blitzbasic', 'c', 'caddcl', 'cadlisp', 'cpp', 'csharp', 'css', 'c_mac', 'd', 'delphi', 'diff', 'div', 'dos', 'eiffel', 'freebasic', 'gml', 'html4strict', 'ini', 'inno', 'java', 'javascript', 'lisp', 'lua', 'matlab', 'mpasm', 'mysql', 'nsis', 'objc', 'ocaml-brief', 'ocaml', 'oobas', 'oracle8', 'pascal', 'perl', 'php-brief', 'php', 'python', 'qbasic', 'ruby', 'scheme', 'sdlbasic', 'smarty', 'sql', 'vb', 'vbnet', 'vhdl', 'visualfoxpro', 'xml' ); $GeshiLangStr = implode('|', $GeshiLangs); class HtmlFormatterExt extends StringFormatter { function HtmlFormatterExt() { $GLOBALS['Head']->AddString( '<style type="text/css">.syntax_highlight {border-left: 6px solid #ffa;'. 'background: #ffe; padding: 8px 8px 8px 16px; margin: 3px 0;}</style>'); } function ParseCode($Code, $Lang) { //undo htmlformatter's work $Code = str_replace( array( '>', '<', '"', '&', '<br />', '<br>' ), array( '>', '<', '"', '&', "\n", "\n" ), $Code ); $g = new GeSHi($Code, $Lang); //$g->enable_classes(); $g->set_overall_class('syntax_highlight'); $g->set_tab_width(4); $g->set_escape_characters_highlighting(false); $g->set_brackets_highlighting(false); return $g->parse_code(); } function Execute($String) { //undo 'script' conversions where needed, then find what we need to highlight return preg_replace( array( "/<code([^>]+?)language=\"([\w\d]*?)&#(115|83);([\w\d]*?)\"/ei", "/<code([^>]+?)language=\"(".$GLOBALS['GeshiLangStr'].")\"([^>]*?)>(.+?)<\/code>/sei" ), array( '\'<code\\1language="\\2\'.chr(intval(\'\\3\')).\'\\4"\'', '$this->ParseCode(HtmlFormatter::RemoveQuoteSlashes(\'\\4\'), strtolower(\'\\2\'))' ), $String ); } function Parse($String, $Object, $FormatPurpose) { if($FormatPurpose == FORMAT_STRING_FOR_DISPLAY) return $this->Execute($String); else return $String; } } $HtmlFormatterExt = $Context->ObjectFactory->NewObject($Context, 'HtmlFormatterExt'); $Context->StringManipulator->Formatters['Html']->AddChildFormatter($HtmlFormatterExt); ?>
This discussion has been closed.