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

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-02-2011, 01:20 AM
AusPhotography's Avatar
AusPhotography AusPhotography is offline
 
Join Date: Nov 2007
Location: Hobart & Adelaide .au
Posts: 521
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Plugin based CKeditor friendly BBcode in vB4.1.8+ - howto

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>
Reply With Quote
Благодарность от:
miiax6
 


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 09:22 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.05926 seconds
  • Memory Usage 2,432KB
  • Queries Executed 14 (?)
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
  • (2)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (1)post_thanks_box_bit
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)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_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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • 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