Manage BB Code functions from your AdminCP. These can be internal PHP functions, or custom (derived from a specified PHP file).
Apply a BB Code function to a custom BB Code tag, and you can use it (when the correct arguments are provided) in posts, etc.
You may choose for a function to be static, or update everytime upon page refresh. If it's static, the first time a function is called the value returned will be replaced with the tag in the post (hard-coded).
Known bugs
One must have posted in the WYSIWYG editor in order for function tags that are unchecked for "update upon page refresh" to work correctly. This is an annoying bug I discovered an hour from releasing this hack, and it will prevent functions tags from being replaced with their return values (hard-coded) in the post. It's only significant if you are using a function that returns a random/dynamic value, and wish not for the value to be updated upon page refresh, but stay unique. I will be looking into a solution when I have the time.
Know of another? Please PM me of it, or post it in the thread.
Notes
This script can only be maliciously taken advantage of if you provide functions that access your server. For example, don't create a custom function that queries your database and returns something. A user could place 100 of these tags into a post, and it would make 100 queries. Even worse, if the "update upon refresh" is enabled, it'll call 100 queries for every view of the page. Especially don't create functions that manipulate data on your server or in your database!
Everything is at your risk, but I implore you to stick with simple functions.
More important notes inside install.html.
Screenshots
See attachments.
Enjoy. Remember to click install if you do use this hack.
Show Your Support
This modification may not be copied, reproduced or published elsewhere without author's permission.
Just send me a link to a file with the function, or PM me the working code, and I'll display it in this post.
1. Evaluate mathematical expression
Here is a useful function that will take a mathematical expression and return the answer for it. Valid operators include plus + minus - multiply * divide / modulus % carrot/power ^ and parentheses ().
When used in BB Code, have one argument and it should function like so:
[math]5*6%3+((45/5)/4)[/math]
5*6%3 = 0
(45/5)/4 = 2.25
= 2.25
Here is the function:
PHP Code:
function arithmetic($expression)
{
$expression = preg_replace('([^0-9\+\-*\/%\^\(\)])', '', trim($expression));
eval('$answer ='.$expression.';');
return $answer;
}
Careful with parentheses. If you have (5/5)5 it will result in an error, and nothing will be returned.