Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
Prev Previous Post   Next Post Next
  #7  
Old 08-21-2011, 04:36 AM
Marco64Th Marco64Th is offline
 
Join Date: Aug 2011
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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".
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:09 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03918 seconds
  • Memory Usage 2,565KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (6)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_threadedmode.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete