vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   BB Code (https://vborg.vbsupport.ru/showthread.php?t=213876)

1Unreal 05-16-2009 09:34 PM

BB Code
 
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:

PHP Code:

$string '[mybbcode]
http://www.site1.com/
http://www.site2.com/
http://www.site3.com/
[/mybbcode]

$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 02: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 02:53 AM

Ive got that far but I dont know what to do from there.

Dismounted 05-17-2009 04:38 AM

And you know what is passed to your callback function?

1Unreal 05-17-2009 09:42 PM

What do you mean?

Dismounted 05-18-2009 05:55 AM

What are you putting in the plugin @ bbcode_fetch_tags?

1Unreal 05-18-2009 06: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 10:49 AM

Look what I found when I did a search.

https://vborg.vbsupport.ru/showthread.php?p=1712936

1Unreal 05-18-2009 11:29 PM

Ok this is what ive started off with.

bbcode_create:
PHP Code:

function handle_bbcode_parts($value)
{
        return 
'Your videos:'$value;        


bbcode_fetch_tags:
PHP Code:

// [PARTS]
$tag_list['no_option']['parts'] = array(
    
'callback' => 'handle_bbcode_parts',
    
'strip_empty' => true
); 

However when I view a thread I get this error.

Quote:

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 06:06 AM

Look carefully at the plugin example @ bbcode_fetch_tags (especially at what value is what).

1Unreal 05-19-2009 06:26 AM

Does the callback have to direct to an external file?

Dismounted 05-19-2009 06:33 AM

Look at the plugin:
PHP Code:

// [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 06:38 AM

callback/external_callback depending which way you do it.

Dismounted 05-19-2009 10:10 AM

You change "external_callback"... "callback" only calls methods that are defined in the class.

1Unreal 05-20-2009 12:15 AM

Ok, I dont really understand. Do I have to use 'callback' somewhere within the function?

Dismounted 05-20-2009 04:53 AM

Read the entire bits of code I posted. Find the correlations between "external_callback" and defined function names.

1Unreal 05-20-2009 07:02 AM

The callback has to correlate with the function name. Which mine does :\

Dismounted 05-20-2009 08: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 09:04 AM

bbcode_fetch_tags:
PHP Code:

// [VIDEO]
$tag_list['no_option']['video'] = array(
    
'callback' => 'handle_external',
    
'external_callback' => 'handle_bbcode_video',
    
'strip_empty' => true
); 

bbcode_create:
PHP Code:

// include our custom functions
require_once(DIR '/inc.php'); 

Contents of inc.php:
PHP Code:

<?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 10:20 AM

Look at the comments on the handle_external() method in class_bbcode.php. ;)

1Unreal 05-21-2009 06: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 Code:

<?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 09: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 09:54 AM

She lives! Thank you so much. That made lots more sense lol.


All times are GMT. The time now is 09:42 AM.

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.01976 seconds
  • Memory Usage 1,769KB
  • 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
  • (8)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (23)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