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.
Content handler before default filters
msikma
New
Hi there, I'm new to Vanilla2 and in order to teach myself the ropes I've started working on a simple BBCode parser plugin.
I ran into a problem when writing the function for [img] tags. Normally you'd format the [img] tag like this:
Here's my code: http://pastie.org/1407521
Thanks!
I ran into a problem when writing the function for [img] tags. Normally you'd format the [img] tag like this:
[img]http://link-to-image.com/img.jpg[/img]The problem is that by BBCode parsing script is performed *after* the regular filters have been applied, so the [img] tag receives an HTML link as the content instead of just a plain text image URI.
Here's my code: http://pastie.org/1407521
I would assume that the
<?php if (!defined('APPLICATION')) exit();
$PluginInfo['SaltCode'] = array(
'Name' => 'SaltCode',
'Description' => 'Blha blah blah',
'Version' => '1.0',
'Author' => 'Michiel Sikma',
'AuthorEmail' => 'michiel@wedemandhtml.com',
'AuthorUrl' => 'http://wedemandhtml.com/',
'License' => 'GNU GPLv2'
);
/*TODO You can set up some options here. */
$options = array(
/* Convert two
tags to wraps. */
'br_to_p' => true,
/* Removes superfluous
tags if there are more than two consecutive ones. */
'trim_br' => false,
/* Avoid using browser-specific CSS prefixes. */
'avoid_css_prefix' => false,
);
/* Install the SaltCode class as a singleton. */
Gdn::FactoryInstall('SaltCodeFormatter', 'SaltCode', dirname(__FILE__).DS.'classSaltCode.php', Gdn::FactorySingleton);
Gdn::Factory('SaltCodeFormatter')->Setup('saltcode', $options);
class SaltCodePlugin extends Gdn_Plugin
{
/**
* Format each comment using the SaltCode class.
*/
public function DiscussionController_AfterCommentFormat_Handler(&$Sender)
{
$Sender->EventArguments['Object']->FormatBody = Gdn::Factory('SaltCodeFormatter')->Filter($Sender->EventArguments['Object']->FormatBody);
}
/**
* Only performed on enable.
*/
public function Setup()
{
SaveToConfig('Plugins.SaltCode.Enabled', TRUE);
}
/**
* Only performed on disable.
*/
public function OnDisable()
{
SaveToConfig('Plugins.SaltCode.Enabled', FALSE);
}
}
DiscussionController_AfterCommentFormat_Handler
needs to be something else, but what? (I got that function name from another plugin.)Thanks!
Tagged:
0
Comments
I actually tried that before but it didn't work. The reason, however, was that the FormatBody attribute isn't available in the $Sender->EventArguments['Object'] at that time; it's just Body, which gets copied to FormatBody later.