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
This discussion has been closed.
Comments
*asks too much
//actually i guess they were both loading before, just not working. nevermind.
It will be a while before the fix is on there, though.
could it be something to do with the Parse classes from the two extensions conflicting?
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.
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); } ?>
thanks mark. sorry for wasting your time.
*shrinks
and thanks SirNot - you're right about needing to undo HtmlFormatter inside the code.
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.
<?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); ?>