The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
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. |
#2
|
||||
|
||||
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:
|
#3
|
||||
|
||||
That definitely looks to be the simplest.
What would I pass to Code:
dice_function_that_returns_string() 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}); ?> |
#4
|
||||
|
||||
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] |
#5
|
||||
|
||||
Correct. Examples:
Code:
[roll=Hero]5d6[/roll] Code:
5 + 1 + 2 + 6 + 6 STUN = 20 BODY = 6 Code:
[roll=HoE]5d6[/roll] Code:
5 + 1 + 2 + 10 (6 + 4) + 22 (6 + 6 + 6 + 4) = 22 Code:
[roll]5d6[/roll] Code:
5 + 1 + 2 + 6 + 6 = 20 |
#6
|
||||
|
||||
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. |
#7
|
||||
|
||||
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. |
#8
|
||||
|
||||
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). |
#9
|
||||
|
||||
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.
|
#10
|
||||
|
||||
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: |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|