Go Back   vb.org Archive > Community Discussions > Modification Requests/Questions (Unpaid)

Reply
 
Thread Tools Display Modes
  #1  
Old 03-25-2004, 04:18 PM
mudpyr8's Avatar
mudpyr8 mudpyr8 is offline
 
Join Date: Mar 2004
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default BBCode that calls PHP

I'm going to convert my dice hack over from phpbb to vB. It's a very comprehensive dice mod that has been very useful to me (and well tested).

Is there any way to use the BBCode Manager in the admincp to introduce a new code that calls some php function introduced in an include file?

I have the phpfunction for the dice roller that returns BB Code formatted text. If I could just put that function in an include file and then create a custom code in the BB Code Manager that calls it I would be done.

If this isn't possible, I think it would be an excellent feature.

Could I possibly put the function in a template of some kind and then reference the template somehow?

Thanks.
Reply With Quote
  #2  
Old 03-25-2004, 05:03 PM
Velocd's Avatar
Velocd Velocd is offline
 
Join Date: Mar 2002
Location: CA University
Posts: 1,696
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What's the syntax for this dice bbcode?

Would it be [dice] ?

The quickest way to achieving just the above would be adding a str_replace() in the parse_bbcode function, like:

PHP Code:
function parse_bbcode($bbcode$forumid 0$allowsmilie 1$isimgcheck 0$parsedtext ''$parsedhasimages 0$iswysiwyg 0)
{
    
// $parsedtext contains text that has already been turned into HTML and just needs images checking
    // $parsedhasimages specifies if the text has images in that need parsing

    
global $vboptions$parsed_postcache;

    
$donl2br 1;

$bbcode str_replace('[dice]'dice_function_that_returns_string(), $bbcode);  // look for dice 
Reply With Quote
  #3  
Old 03-25-2004, 05:10 PM
mudpyr8's Avatar
mudpyr8 mudpyr8 is offline
 
Join Date: Mar 2004
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That definitely looks to be the simplest.

What would I pass to
Code:
dice_function_that_returns_string()
so that the {option} and {param} data gets sent?

Also, would I then just put my code in a file named 'functions_diceroller.php' in the includes directory?

Playing around I just created the following in BB Code Manager:
Code:
tag: roll
replacement: <? dieroller({param},{option}); ?>
Reply With Quote
  #4  
Old 03-25-2004, 05:15 PM
Velocd's Avatar
Velocd Velocd is offline
 
Join Date: Mar 2002
Location: CA University
Posts: 1,696
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How does the dice bbcode look?

My above code only works if it's just [dice], and that function would simply return a random value. No AdminCP implementation required.

It's not meant for parameters, but it seems your dice tag might look like [roll=5]{some value?}[/roll]
Reply With Quote
  #5  
Old 03-25-2004, 05:25 PM
mudpyr8's Avatar
mudpyr8 mudpyr8 is offline
 
Join Date: Mar 2004
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Correct. Examples:
Code:
[roll=Hero]5d6[/roll]
Returns (1 STUN/pt, 0 BODY for 1s, 1 BODY for 2-5, 2 BODY for 6):
Code:
5 + 1 + 2 + 6 + 6 
STUN = 20
BODY = 6
Code:
[roll=HoE]5d6[/roll]
Returns (open ended and pick the highest single result)
Code:
5 + 1 + 2 + 10 (6 + 4) + 22  (6 + 6 + 6 + 4) = 22
But
Code:
[roll]5d6[/roll]
Returns:
Code:
5 + 1 + 2 + 6 + 6 = 20
There are of course limits so someone can't write 100000d10000000.
Reply With Quote
  #6  
Old 03-25-2004, 05:55 PM
Velocd's Avatar
Velocd Velocd is offline
 
Join Date: Mar 2002
Location: CA University
Posts: 1,696
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Give me some time, and I'll code up a hack for your original request in post #1. (probably tonight, or tomorrow night)

An AdminCP integration with custom function support in bbcode tags would be easier to use for your hack then hard-coding the bbcodeparse file.
Reply With Quote
  #7  
Old 03-25-2004, 06:39 PM
mudpyr8's Avatar
mudpyr8 mudpyr8 is offline
 
Join Date: Mar 2004
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That would rock on toast and be very useful for many other things.

Thanks. I look forward to the hack, and I am in no rush.
Reply With Quote
  #8  
Old 03-26-2004, 04:10 AM
Velocd's Avatar
Velocd Velocd is offline
 
Join Date: Mar 2002
Location: CA University
Posts: 1,696
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This hack is underway, and works in the following.

In the ACP, there is a new category called BB Code Functions in the left navbar, underneath Custom BB Codes.

The administrator can add functions to be used in bbcode that are user-defined or internal (built in PHP functions, like rand(), str_replace(), and hundreds of others).

Functions are added by specifying a title for the function, the handle of the function (which is how the function is called), a description, and optional file path to a PHP file containing a user defined function.

If no path is specified to a custom PHP file containing your function, the script will check to see if the handle name is an internal function. If it isn't, an error is outputted.

If the path specified points to an empty file, OR non PHP file, OR a correct PHP file but it doesn't contain the function by the handle name, OR the correct function is present but incorrect number of arguments (there must be AT LEAST 1 argument), then an error will be outputted.

Once a function is added, you can edit a bbcode in the bbcode manager, and there is a drop-down list for selection a function the bbcode applies to. There can be a max of 2 user-defined arguments passed in any function, and those are the normal bbcode arguments: {param} and {option}. The bbcode tag itself doesn't have to have the same name as the function handle.

An example of the whole script:

1. User creates a bbcode function that points to the internal function rand()
2. User create a bbcode that is applied to the function rand, one that takes 2 paramters: {param} and {option}.

3.

Usage: [random="100"]200[/random]
Masked: [random="{option}"]{param}[/random]
PHP: rand({option}, {param});

This whole tag when used inside a post would return a random number between 100-200, and uses the PHP function rand() to perform the operation.

4. If by chance you create a tag for the function rand, but with one argument, which would have to be {param}, then you may or may not be lucky about getting a PHP error.

By default the hack substitutes the value 0 for any empty parameter of a function not specified by the user.

In the case with rand(), one is lucky, because {option} which is the left out parameter is replaced with 0 and still functions.

There are some other loop holes with this hack I've yet to address, but will give more thought into solutions as I work on the hack tomorrow (hopefully finishing by saturday).
Reply With Quote
  #9  
Old 03-26-2004, 10:07 AM
PlenoJure's Avatar
PlenoJure PlenoJure is offline
 
Join Date: Aug 2002
Location: Melbourne, FL
Posts: 19
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Very interesting idea, if the security issues can be properly addressed then this could be a very powerfull feature. Issues that come to mind are things things like intentially calling a function with invalid paramaters to cause a parse error & the ability to by inject PHP code. I don't know how you are handling the details, but security will be a very important issue with this. If this can be done securly it's something I'd use, it's a great idea.
Reply With Quote
  #10  
Old 03-26-2004, 02:08 PM
mudpyr8's Avatar
mudpyr8 mudpyr8 is offline
 
Join Date: Mar 2004
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you VeloCD. This is a hack I have been thinking about for a while to facilitate a number of other hacks I have in mind (besides dice rollers). I was always frustrated with the amount of effort I needed to exert to put a hack in for custom bbcodes. This solves it in spades, and is a boon for the entire community, not just my dice rolling hack.

BIG THUMBS UP :up: :banana: :up:
Reply With Quote
Reply

Thread Tools
Display Modes

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 01:55 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.06306 seconds
  • Memory Usage 2,263KB
  • Queries Executed 11 (?)
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
  • (8)bbcode_code
  • (1)bbcode_php
  • (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_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