vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Calling PHP in BBCode (https://vborg.vbsupport.ru/showthread.php?t=212048)

Milez 04-24-2009 02:18 AM

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?

Dismounted 04-24-2009 09:46 AM

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.

Milez 04-25-2009 07:32 AM

Sorry I do not see this hook. What is its name?

Dismounted 04-25-2009 09:24 AM

I did not mean literally "at the end"... bbcode_fetch_tags

Gargi 07-15-2009 03:59 AM

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

Dismounted 07-15-2009 05:40 AM

The BB code parser is expecting an "option" (e.g. [TAG=OPTION]), instead of $tag_list['option']['hwelt'], try $tag_list['no_option']['hwelt'].

Gargi 07-15-2009 08:05 AM

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

Dismounted 07-15-2009 08:46 AM

Quote:

Originally Posted by Gargi (Post 1849093)
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...

Gargi 07-15-2009 09:00 AM

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

Link14716 07-15-2009 09:10 AM

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;
    }  




All times are GMT. The time now is 11:19 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.01893 seconds
  • Memory Usage 1,764KB
  • 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
  • (6)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete