View Full Version : BB Code
1Unreal
05-16-2009, 10:34 PM
I want to add a new BB Code and handle it with PHP
Ive been looking through the BB Code include file and I really dont understand how its working
Heres what I want to do:
Take a string of links, each link on one line. Then convert that into an array:
$string = '
http://www.site1.com/
http://www.site2.com/
http://www.site3.com/
$string = explode("\n", $string);
foreach($string as $link){
echo '<a href="'. $link . '">'.$link.'</a>';
}
Thats essentially what I want to do, amongst other things.
But Im reallly lost.:o
Dismounted
05-17-2009, 03:24 AM
To add a BB code processed by a custom callback, you need to define it in a plugin at bbcode_fetch_tags.
1Unreal
05-17-2009, 03:53 AM
Ive got that far but I dont know what to do from there.
Dismounted
05-17-2009, 05:38 AM
And you know what is passed to your callback function?
1Unreal
05-17-2009, 10:42 PM
What do you mean?
Dismounted
05-18-2009, 06:55 AM
What are you putting in the plugin @ bbcode_fetch_tags?
1Unreal
05-18-2009, 07:20 AM
I havent done anything yet. Thats what Im saying, Im completly lost.
Could you give a brief explanation/tutorial of how to add custom BB Codes as a plugin?
Dismounted
05-18-2009, 11:49 AM
Look what I found when I did a search.
https://vborg.vbsupport.ru/showthread.php?p=1712936
1Unreal
05-19-2009, 12:29 AM
Ok this is what ive started off with.
bbcode_create:
function handle_bbcode_parts($value)
{
return 'Your videos:'. $value;
}
bbcode_fetch_tags:
// [PARTS]
$tag_list['no_option']['parts'] = array(
'callback' => 'handle_bbcode_parts',
'strip_empty' => true
);
However when I view a thread I get this error.
Fatal error: Call to undefined method vB_BbCodeParser::handle_bbcode_parts() in /home/tvbtfz/public_html/includes/class_bbcode.php on line 1143
Dismounted
05-19-2009, 07:06 AM
Look carefully at the plugin example @ bbcode_fetch_tags (especially at what value is what).
1Unreal
05-19-2009, 07:26 AM
Does the callback have to direct to an external file?
Dismounted
05-19-2009, 07:33 AM
Look at the plugin:
// [VIDEO]
$tag_list['no_option']['video'] = array(
'callback' => 'handle_external',
'external_callback' => 'handle_bbcode_video',
'strip_empty' => true
);
Which value do you think is the custom one?
1Unreal
05-19-2009, 07:38 AM
callback/external_callback depending which way you do it.
Dismounted
05-19-2009, 11:10 AM
You change "external_callback"... "callback" only calls methods that are defined in the class.
1Unreal
05-20-2009, 01:15 AM
Ok, I dont really understand. Do I have to use 'callback' somewhere within the function?
Dismounted
05-20-2009, 05:53 AM
Read the entire bits of code I posted. Find the correlations between "external_callback" and defined function names.
1Unreal
05-20-2009, 08:02 AM
The callback has to correlate with the function name. Which mine does :\
Dismounted
05-20-2009, 09:39 AM
Again, "callback" only calls methods that are defined in the class. This type of custom BB code defines a function that is global - hence the need to use "handle_external" as the callback. You specify your own callback in "external_callback". Hoping you could figure this out yourself.
1Unreal
05-20-2009, 10:04 AM
bbcode_fetch_tags:
// [VIDEO]
$tag_list['no_option']['video'] = array(
'callback' => 'handle_external',
'external_callback' => 'handle_bbcode_video',
'strip_empty' => true
);
bbcode_create:
// include our custom functions
require_once(DIR . '/inc.php');
Contents of inc.php:
<?php
function handle_bbcode_video($value)
{
return 'Your videos:'. $value;
}
?>
Thats what ive got. It doesnt work.
Can I not simply do a return like that? Do I have to do it with a class?
Dismounted
05-20-2009, 11:20 AM
Look at the comments on the handle_external() method in class_bbcode.php. ;)
1Unreal
05-21-2009, 07:55 AM
Im really lost, its not making sense. Its like its not detecting the callback. :|
Also, is this possible with the BB Code parser in vB. I know there are some limitations. $string would have to be the bit picked up between the tags. I dont want to be doing this then realise its not possible :p
<?php
$string = 'http://www.link1.com
http://www.link2.com
http://www.link3.com';
$string = explode("\n", $string);
$num = 0;
foreach($string as $item){
$num++;
$item = trim($item);
echo '<a href="'.$item.'" class="parts">'.$num.'</a>';
}
?>
Dismounted
05-21-2009, 10:17 AM
Use the code I posted in the other thread, and modify:
The function name handle_video_bbcode() (or whatever it was).
"external_callback" to new function name.
Code inside the [previous] handle_video_bbcode() function.
Look at the arguments in the function.
You do not need to do anything else - that is - don't modify "callback".
1Unreal
05-21-2009, 10:54 AM
She lives! Thank you so much. That made lots more sense lol.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.