Did check early in the morning but didn't see your reply then.
Did a lot of testing and i first thought i was on the right track by changing the hook bbcode_fetch_tags to:
PHP Code:
if (class_exists('vB_BbCodeParser_Wysiwyg'))
{
// If the class is defined we assume that we where called from an Enhanced editor page.
// This will most likely go wrong if there are both a basic editor and an enhanced editor on the same page.
// Set the tag to be preformatted
$tag_list['option']['test2'] = array(
'callback' => 'handle_preformatted_tag',
'strip_empty' => false,
'stop_parse' => true,
'disable_smilies' => true,
'disable_wordwrap' => true,
);
}
else
{
// Set the option for the tag to be handled by the regular (non-Wysiwyg) bbCodeParser
$tag_list['option']['test2'] = array(
'callback' => 'handle_external',
'strip_empty' => false,
'stop_parse' => true,
'disable_smilies' => true,
'disable_wordwrap' => true,
'strip_space_after' => 1,
'external_callback' => 'handle_bbcode_test2'
);
}
This had the risk of 2 editors being used on the same page and class_exists() only checks if the class is
defined. Possible leading to a false positive in some rare situations. But as fetch_tag_list() is defined outside of the class and the class object not available, the other ways of checking can not be used. But that was an acceptable solution for me.
I thought it all worked but when testing a bit more i found out that if there is an option used in the tag (lucky i tested with bb codes that had an option), the option would be stripped due to a call to handle_preformatted_tag() by class vB_BbCodeParser_Wysiwyg:
PHP Code:
function handle_preformatted_tag($code)
{
$current_tag =& $this->current_tag;
$tag_name = (isset($current_tag['name_orig']) ? $current_tag['name_orig'] : $current_tag['name']);
return "[$tag_name]" . $this->emulate_pre_tag($code) . "[/$tag_name]";
}
Notice that this function does not return options.
So i had to do it in another way.
What i finally came up with, and this works in all situation i tested, was to change the handler (hook: bbcode_create) to:
PHP Code:
if (!function_exists("handle_bbcode_test2"))
{
function handle_bbcode_test2(&$parser, $code, $type)
{
global $vbulletin, $vbphrase, $show;
// (Marco64TH) Work around for bug in vB 4.1.4 & 4.1.5 (and maybe higher).
// See bug report: http://tracker.vbulletin.com/browse/VBIV-13004
//
// With vBulletin 4.1.4 and higher if editing a post using the Enhanced (Wysiwyg) editor, the editor window would show the parsed version
// of the bb-code instead of the original bb-code.
if (SIMPLE_VERSION >= 414 AND get_class($parser) == "vB_BbCodeParser_Wysiwyg")
{
$current_tag =& $parser->current_tag;
$tag_name = (isset($current_tag['name_orig']) ? $current_tag['name_orig'] : $current_tag['name']);
// Return the rebuild version of the original tag
return "[$tag_name" . ($type ? "=$type" : "") . "]" . $parser->emulate_pre_tag($code) . "[/$tag_name]";
}
else
{
// Return the parsed version of the tag
return "Option: $type<br />Param: $code";
}
}
}
Some remarks:
- We are now operating inside the class, so we can simply check the class.
- More control over the output.
- This example should work for any tagname with or without options.
- Downside is that i have added a check on the vBulletin versionnumber. If this issue ever is going to be changed, then you will need to update the plugin with the highest versionnumber.
- The emulate_pre_tag() will not be needed for all types of bb-codes. But as i am working on (yet another) Syntax Highlighter i thought it best to stay as close to the default tags like "code" and "php".