vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Plugin based CKeditor friendly BBcode in vB4.1.8+ - howto (https://vborg.vbsupport.ru/showthread.php?t=274926)

AusPhotography 12-02-2011 01:20 AM

Plugin based CKeditor friendly BBcode in vB4.1.8+ - howto
 
1 Attachment(s)
Plugin based CKeditor friendly BBcode in vB4.1.8+ - howto

I've put all the Ausphotography (AP) custom BBcodes into a plugin.
Here is a skeleton example (with detailed comments) of how to do it.

Skills needed: Intermediate PHP and vBulletin admin.

Tutorial
In the example the BBcode is 'w' which allows a warning to be posted in a thread.
Make sure you BBcode does not conflict with the standard BBcodes or
any other product BBcodes you have on your system.
You can add multiple BBcodes using one plugin, just code a call back function
for each and set the tags for each BBcode following the example.

The syntax is (no option and option to change the Warning text):
Code:

[w]Warning Message[/w]
[w="Notice"]Notice Message[/w]

ICON
If you want an icon for your BBcode create and copy a small icon
(say) APwarning.png (18x18) to your ./images/editor directory,
the record insert will need the icon path in the buttonimage field.
Attachment 134799

Product xml file
Write a small product xml file that looks like the example below.
Name it 'product_my_bbcodes.xml'
You will need to write a call back function and set the tag list entries.
Install the product via AdminCP.

You will need to adjust the insert records.
The options are a bit field based on:
- strip_empty - 1
- stop_parse - 2
- disable_smilies - 4
- disable_wordwrap - 8
- disable_urlconversion - 16

Call back function
Each BBcode will require a call back function as shown in the example and the tag_list definitions.
The return function is what is put in the parsed post.
You can implement database accesses in the BBcode processor (you need global $vbulletin; enabled per normal.
Note this code is CKeditor friendly in that it tells CKeditor to ignore your BBcode in WYSIWYG mode.

Tag list
The tag list defines which options are active on the BBcode tag and should match the options of the insert record.



Enjoy!

Kym

__________________________________________________

Code:

<?xml version="1.0" encoding="ISO-8859-1"?>

<product productid="my_bbcodes" active="1">
        <title>AP BBcode processor</title>
        <description><![CDATA[Provides BBcodes eg. w (WARNING)]]></description>
        <version>4.1.8</version>
        <url><![CDATA[http://www.ausphotography.net.au/forum/index.php]]></url>
        <versioncheckurl></versioncheckurl>
        <dependencies>
                <dependency dependencytype="vbulletin" minversion="4.1.8" maxversion="" />
        </dependencies>
        <codes>
        <code>
        <installcode><![CDATA[
// Put '' in the buttonimage field if you  are NOT using an icon in the editor
// Eg. 'images/editor/APwarning.png' becomes '' if you dont want an icon.
// twoparams needs to be 1 if your BBcode has options, or 0 if it does not.

        $db->query_write("
                INSERT INTO " . TABLE_PREFIX . "bbcode (bbcodetag, bbcodereplacement, bbcodeexample, bbcodeexplanation, twoparams, title, buttonimage, options)
                VALUES
                ('w', 'Please refresh this page.', '[w=\"Warn:\"]Demo Text[/w]', 'Warning BB code.', 1, 'Warning', 'images/editor/APwarning.png', 1)
                ON DUPLICATE KEY UPDATE
                        bbcodereplacement = VALUES(bbcodereplacement),
                    bbcodeexample = VALUES(bbcodeexample),
                    bbcodeexplanation = VALUES(bbcodeexplanation),
                        twoparams = VALUES(twoparams),
                        title = VALUES(title),
                        buttonimage = VALUES(buttonimage),
                        options = VALUES(options);
                ");
               
        build_bbcode_cache();  // force the BBcode cache to update

        ]]></installcode>
        <uninstallcode><![CDATA[

        $db->query_write("
                DELETE FROM " . TABLE_PREFIX . "bbcode WHERE bbcodetag = 'w' LIMIT 1;
                ");       
               
        build_bbcode_cache();  // force the BBcode cache to update

        ]]></uninstallcode>
        </code>
        </codes>
        <templates>
        </templates>
        <stylevardfns>
        </stylevardfns>
        <stylevars>
        </stylevars>
        <plugins>
                <plugin active="1" executionorder="5">
                        <title>AP BBcode processing</title>
                        <hookname>bbcode_create</hookname>
                        <phpcode><![CDATA[
// ****************************
// W Warning call back function
if(!function_exists('handle_w_callback')) 

    function handle_w_callback(&$parsed, $valuex, $option='') 
    { 
                // global $vbulletin;  // needed if you are going to database accesses in the BBcode processing
                if (!empty($option))
                {
                        $apwtxt = $option;
                }
                else
                {
                        $apwtxt = 'Warning'; // Default option
                }
          return '<blockquote class="blockrow postcontent restore preview postcontainer forumcontent"> <div class="contentnote" style="border: 1px solid;padding:5px;"><span style="color:DarkOrange;"><b>'.$apwtxt.': </b></span>'.$valuex.'</div> </blockquote>';
    }  // end handle_w_callback.
} // end of handler
$this->tag_list['no_option']['w'] = array( // tag the call back when option is not present
    'callback' => 'handle_external',
    'external_callback' => 'handle_w_callback',
    'strip_empty' => true,                // remove empty tags
    'stop_parse' => false,                // allow the tag to contain other BBcodes
        'wysiwyg_no_parse' => 1,        // tell CKeditor to ignore this tag
    'disable_smilies' => false,        // allow smilies
    'disable_wordwrap' => false        // allow word wrapping
);
$this->tag_list['option']['w'] = array(  // tag the call back when option present
    'callback' => 'handle_external',
    'external_callback' => 'handle_w_callback',
    'strip_empty' => true,                // remove empty tags
    'stop_parse' => false,                // allow the tag to contain other BBcodes
        'wysiwyg_no_parse' => 1,        // tell CKeditor to ignore this tag
    'disable_smilies' => false,        // allow smilies
    'disable_wordwrap' => false        // allow word wrapping
);
]]></phpcode>
                </plugin>
        </plugins>
        <phrases>
        </phrases>
        <options>
        </options>
        <helptopics>
        </helptopics>
        <cronentries>
        </cronentries>
        <faqentries>
        </faqentries>
</product>


AusPhotography 12-02-2011 01:21 AM

1 Attachment(s)
Sample...

Attachment 134798

Boofo 12-02-2011 01:45 AM

Looks confusing, but good. ;)

AusPhotography 12-02-2011 03:55 AM

Quote:

Originally Posted by Boofo (Post 2273878)
Looks confusing, but good. ;)

Ha ha!

The main issues that you need to deal with are:
  1. Create a BBcode database record, optionally with an ICON path defined
  2. Have a plugin @ hook: bbcode_create that
    1. defines a handler function to parse the BBcode and return some HTML
    2. set the tag_list entries, pointing at the handler

miiax6 03-08-2012 01:52 PM

Hello snoopytas
my join date is 12 Aug 2006
and it's first time to say thanks

thanks Very much

the most tip i searched for was
wysiwyg_no_parse

vbulletin api are sucks

--------------- Added [DATE]1331220081[/DATE] at [TIME]1331220081[/TIME] ---------------

could you tell me how can i fin iformation like this wysiwyg_no_parse

--------------- Added [DATE]1331220205[/DATE] at [TIME]1331220205[/TIME] ---------------

also how could i ask editor for coustome view for user but use the bbcode on save

AusPhotography 04-05-2012 01:38 AM

@miiax6
-- I find the information by looking at the vB code.
The vB API etc. is very powerful, but there is not a lot of deep documentation.

>also how could i ask editor for coustome view for user but use the bbcode on save
This is very hard as you have to know the internals of CKeditor.


All times are GMT. The time now is 10:31 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.01043 seconds
  • Memory Usage 1,749KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete