Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-20-2011, 07:43 AM
Marco64Th Marco64Th is offline
 
Join Date: Aug 2011
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Bug in 4.1.5 enhanced editor with custom bb-code?

When using 4.1.5 with the Enhanced (WYSIWYG) editor i can not edit a post that contains a custom bb-code that was added with a plugin. In the editor the parsed text is shown instead of the original bb-code.

It could also be of course that i am setting an option wrong.

I performed the following test:

- Create 2 identical bb-codes, 1 using the BB-Code Manager ("test") and 1 added by plugins ("test2").

BB-Code Manager:
Attachment 132151

- Next i created 2 plugins:
--- Hook location: bbcode_create
PHP Code:
if (!function_exists("handle_bbcode_test2"))
{
    function 
handle_bbcode_test2(&$parser$code$type)
    {
        global 
$vbulletin$vbphrase$show;

        
$result "Option: $type<br />Param: $code";
        return 
$result;
    }

--- Hook Location: bbcode_fetch_tags
PHP Code:
$tag_list['option']['test2'] = array(
        
'callback' => 'handle_external',
        
'strip_empty' => 0,
        
'stop_parse' => 0
        
'disable_smilies' => 0,
        
'disable_wordwrap' => 0,
        
'strip_space_after' => 0,
        
'external_callback' => 'handle_bbcode_test2'
); 
- Now i created a test post using both the test bb-codes (screen shows editing the test post using the Basic Editor):

Attachment 132152

- The result of the post shows like:

Attachment 132153

Now i can edit this post as many times as i want using the basic editor (or standard editor) and it will always be the same: when editing the tag is preserved, when viewing the tag is processed.

- If i now edit the same post with the enhanced editor however, i only get the parsed text in the edit window. But only for the bb-code that was added with a plugin:

Attachment 132154

This makes it impossible to edit the post and preserve the bb-code.

Am i doing something wrong or is this a bug?
Reply With Quote
  #2  
Old 08-20-2011, 01:17 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It looks like the problem is that the code that converts from standard to wysiwyg is set up not to parse custom bbcodes, so they stay bbcode tags even in wysiwyg mode. fetch_tag_list() doesn't return the custom bbcodes, and when code in class_wysiwygparser.php does the standard to wysiwyg conversion, when it loads the custom tags, it changes the callback to 'handle_wysiwyg_unparsable'.

In any case, I don't know what you can do abut it short of editing vb files because there doesn't seem to be hooks in the right places. But if you were to edit the files, you could add your tag to the list of unparsed tags in class_bbcode_alt:

PHP Code:
    /**
    * List of tags the WYSIWYG BB code parser should not parse.
    *
    * @var    array
    */
    
var $unparsed_tags = array( 
Reply With Quote
  #3  
Old 08-20-2011, 03:38 PM
Marco64Th Marco64Th is offline
 
Join Date: Aug 2011
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
It looks like the problem is that the code that converts from standard to wysiwyg is set up not to parse custom bbcodes, so they stay bbcode tags even in wysiwyg mode.
We probably mean the same, but it is the other way round. In WYSIWYG mode they do not stay as bb-codes, but you get the parsed result in your edit window.

I have done some more testing and in 4.1.3 it still worked as expected, this started with 4.1.4.

I have by now also posted it in the bug tracker: http://tracker.vbulletin.com/browse/VBIV-13004

Will look into solving it tomorrow, but as you say i doubt that can be done without patching vB, so not a real option.
Reply With Quote
  #4  
Old 08-20-2011, 03:41 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Marco64Th View Post
We probably mean the same, but it is the other way round. In WYSIWYG mode they do not stay as bb-codes,
Right, I believe it's the conversion of the text from "non-wysiwyg" to wysiwyg mode that is the problem.
Reply With Quote
  #5  
Old 08-20-2011, 04:26 PM
Marco64Th Marco64Th is offline
 
Join Date: Aug 2011
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Might be able to do something at the bbcode_fetch_tags hook, but then i would need to be able to know if the taglist is for the Wysiwyg editor or not. Will look into it tomorrow.
Reply With Quote
  #6  
Old 08-21-2011, 01:13 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, I was thinking that you could change your callback there if you knew where it was called from, but I think I gave up on that when I noticed that the tag list is cached. But maybe it would still work.

You could probably have your callback do something different if you knew where it was being called from. Maybe there's some global you can check or something. (I think you can actually get an array of calling functions using the debug_backtrace() function, but that seems pretty ugly).
Reply With Quote
  #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
  #8  
Old 08-21-2011, 12:21 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nice, thanks for posting your fix.


Quote:
Originally Posted by Marco64Th View Post
- We are now operating inside the class, so we can simply check the class.
I don't know if I ever would have thought of that.
Reply With Quote
  #9  
Old 08-21-2011, 12:41 PM
Marco64Th Marco64Th is offline
 
Join Date: Aug 2011
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It would still fail if they decided to rename the class somewhere in the future. Don't really like to depend on such a constant, but got to do something.
Reply With Quote
Reply


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 01:55 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.07682 seconds
  • Memory Usage 2,297KB
  • Queries Executed 12 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (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)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_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • 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
  • 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