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

Reply
 
Thread Tools Display Modes
  #1  
Old 04-24-2009, 03:18 AM
Milez Milez is offline
 
Join Date: Jan 2002
Posts: 126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Calling PHP in BBCode

I wrote a script that will output a stock quote and I want to make it work with vB's BBcode system. The problem is I cannot make [stock]MSFT[/stock] replace to some PHP as it only allows HTML.

I can see other developers have gotten around this somehow as they are including javascript etc in their BBcode replacements. I plan to release this mod to the public. Can anyone offer some help?
Reply With Quote
  #2  
Old 04-24-2009, 10:46 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Look in class_bbcode.php, more specifically, at the end of this file. You will see a hook that allows you to "create" a BB code handler and define your own callback.
Reply With Quote
  #3  
Old 04-25-2009, 08:32 AM
Milez Milez is offline
 
Join Date: Jan 2002
Posts: 126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry I do not see this hook. What is its name?
Reply With Quote
  #4  
Old 04-25-2009, 10:24 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I did not mean literally "at the end"... bbcode_fetch_tags
Reply With Quote
  #5  
Old 07-15-2009, 04:59 AM
Gargi Gargi is offline
 
Join Date: May 2008
Posts: 49
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmmm... I just wanted to insert a new bbcode calling some php functions but it won't parse.

I created a new plugin at bbcode_fetch_tags

PHP Code:
$tag_list['option']['hwelt'] = array( 
    
'callback' => 'handle_external',
    
'external_callback' => 'handle_bbcode_hwelt_callback'
    
'strip_empty' => true 
); 
  
if(!
function_exists('handle_bbcode_hwelt_callback')) 

    function 
handle_bbcode_hwelt_callback(&$parser$value$option
    { 
        echo 
"Hallo Welt, ich hei?e".$value."!"
        return 
$parsed
    } 

A

[hwelt]Dieter[/hwelt]

won't parse that way. So I also added a second plugin at bbcode_create:

PHP Code:
if ($this->is_wysiwyg())
{
    
$this->unparsed_tags[] = 'hwelt';

But same result: nothing.

Any idea what's wrong with it?

cu
Gargi
Reply With Quote
  #6  
Old 07-15-2009, 06:40 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The BB code parser is expecting an "option" (e.g. [TAG=OPTION]), instead of $tag_list['option']['hwelt'], try $tag_list['no_option']['hwelt'].
Reply With Quote
  #7  
Old 07-15-2009, 09:05 AM
Gargi Gargi is offline
 
Join Date: May 2008
Posts: 49
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The same thing. Activating or not activating (no matter what) the bbcode_create it also will result into an error while clicking onto the submut reply button. A created tag befor activating the pluging and refreshing the post will make the whole string disappear in the posting. Also if I will only parse

echo $value;

Still something wrong with it but I can't see what.

cu
Gargi

Edit:

Next try

PHP Code:
$tag_list['no_option']['hwelt'] = array(  
    
'callback' => 'handle_external'
    
'external_callback' => 'handle_bbcode_hwelt_callback',  
    
'strip_empty' => true  
);  
   
if(!
function_exists('handle_bbcode_hwelt_callback'))  
{  
    function 
handle_bbcode_hwelt_callback($value)  
    {  
      
/*        return $parsed;  */
          
return "Hallo Welt ".$value;
    }  

Works a bit better. This delivers using

[hwelt]Dieter[/hwelt]

just

Hallo Welt

The Tag itself is parsing, but no php parsing I guess and the missing value.

cu
Gargi

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

One step further:

PHP Code:
$tag_list['no_option']['hwelt'] = array(  
    
'callback' => 'handle_external'
    
'external_callback' => 'handle_bbcode_hwelt_callback',  
    
'strip_empty' => true  
);  
   
if(!
function_exists('handle_bbcode_hwelt_callback'))  
{  
    function 
handle_bbcode_hwelt_callback(&$parsed$value)  
    {  
          
          return 
"Hello world, my name is ".$value."!";
          return 
$parsed;

    }  

This will deliver a

Hello world, my name is Dieter!

So far so good. But how to integrate the php code? As I see the echo comand won't work but the return. So I think I have to place the php code elsewhere. But where?

cu
Gargi
Reply With Quote
  #8  
Old 07-15-2009, 09:46 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Gargi View Post
So far so good. But how to integrate the php code? As I see the echo comand won't work but the return. So I think I have to place the php code elsewhere. But where?
Wait a sec - I don't think I understand the problem you are having. Could you explain a little clearer? You seem you have it outputting correctly...
Reply With Quote
  #9  
Old 07-15-2009, 10:00 AM
Gargi Gargi is offline
 
Join Date: May 2008
Posts: 49
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I want to parse some php code using a bbcode tag. Maybe another example with options:

Tag: count
Parameter a Name, Option a number.
e.g: [count="3"]Gargi[/count]

While parsing the number should be added to another value. Output maybe:

Hello this is Gargi,
my number is 10

So I try it with a plugin bbcode_fetch_tags:

PHP Code:
$tag_list['option']['count'] = array(  
    
'callback' => 'handle_external'
    
'external_callback' => 'handle_bbcode_count_callback',  
    
'strip_empty' => true  
);  
   
if(!
function_exists('handle_bbcode_count_callback'))  
{  
    function 
handle_bbcode_count_callback(&$parsed$value$option)  
    {  
          
$result $option;
          return 
"Hello this is ".$value.",<br />";
          return 
"my number is ".$result;
          return 
$parsed;

    }  

This will just result in

Hello this is Gargi,

and nothing more. I also only added this plugin and nothing more. Is there anything else to do for it (another plugin) or where do I have to place the php code to be executed correctly?

cu
Gargi
Reply With Quote
  #10  
Old 07-15-2009, 10:10 AM
Link14716's Avatar
Link14716 Link14716 is offline
 
Join Date: Jun 2002
Location: Georgia, USA
Posts: 2,519
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Once a function has returned something, the function stops executing and the script continues from there. Thus, the two returns below the first do nothing as they will never be executed.

Use this:

PHP Code:
$tag_list['option']['count'] = array(  
    
'callback' => 'handle_external'
    
'external_callback' => 'handle_bbcode_count_callback',  
    
'strip_empty' => true  
);  
   
if(!
function_exists('handle_bbcode_count_callback'))  
{  
    function 
handle_bbcode_count_callback(&$parsed$value$option)  
    {  
          
$result $option;
          return 
"Hello this is ".$value.",<br /> my number is ".$result;
    }  

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 05:47 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.09286 seconds
  • Memory Usage 2,288KB
  • Queries Executed 13 (?)
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
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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_postinfo_query
  • fetch_postinfo
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete