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.
OK, just to reiterate. The error received was a Parse error "Unexpected $ at line ... in functions_bbcodeparse.php" (where the line number corresponded to the last line of the php program = "?>".
Here be the areas of code I changed / inserted. As previously described I put comments in "// SMJU001 ..." to indicate what I had done.
// ###################### Start bbcodeparse #######################
// SMJU001 {Step 27/28}
// this line replaced by the following one - function parse_bbcode($bbcode, $forumid = 0, $allowsmilie = 1, $isimgcheck = 0, $parsedtext = '', $parsedhasimages = 0, $iswysiwyg = 0)
function parse_bbcode($bbcode, $forumid = 0, $allowsmilie = 1, $isimgcheck = 0, $parsedtext = '', $parsedhasimages = 0, $iswysiwyg = 0, $postid = '')
{
// $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;
Hack Steps 29/30
PHP Code:
else
{
if ($isimgcheck)
{ // do this since we're only checking for smilies and IMG code
$dobbcode = 0;
}
// SMJU001 {step 29/30}
// this line replaced with the following one return parse_bbcode2($bbcode, $dohtml, $dobbimagecode, $dosmilies, $dobbcode, $iswysiwyg, $donl2br);
return parse_bbcode2($bbcode, $dohtml, $dobbimagecode, $dosmilies, $dobbcode, $iswysiwyg, $donl2br, $postid);
}
}
// ###################### Start bbcodeparse2 #######################
// SMJU001 {steps 31/32}
// this line replaced with the following one function parse_bbcode2($bbcode, $dohtml, $dobbimagecode, $dosmilies, $dobbcode, $iswysiwyg = 0, $donl2br = 1)
function parse_bbcode2($bbcode, $dohtml, $dobbimagecode, $dosmilies, $dobbcode, $iswysiwyg = 0, $donl2br = 1, $postid = '')
{
// parses text for vB code, smilies and censoring
global $DB_site, $vboptions, $bbuserinfo, $templatecache, $smiliecache;
Hack Steps 33/34
PHP Code:
default:
$parsefunc = 'parse_bbcode_regexrecurse';
}
// SMJU001 {steps 33/34}
// this line replaced with the following one $bbcode = $parsefunc($bbcode, $iswysiwyg);
$bbcode = $parsefunc($bbcode, $iswysiwyg, $postid);
return $BBCODE;
}
}
// SMJU001 {step 36} End of inserted code
// ###################### Start bbcodeparse2_regexrecurse #######################
//SMJU001 {steps 37/38}
// this line replaced by the following one - function parse_bbcode_regexrecurse($bbcode, $iswysiwyg)
function parse_bbcode_regexrecurse($bbcode, $iswysiwyg, $postid = '')
{
global $DB_site, $vboptions, $bbuserinfo, $templatecache, $datastore, $wysiwygparse, $session;
static $BBCODES;
Hack Steps 39/40/41/42/43/44
Note that I found the search text in step 43 twice in the file, therefore I inserted the code in step 44 twice. The duplicate area is further down the post.
PHP Code:
$wysiwygparse = $iswysiwyg;
if (empty($BBCODES['standard']))
{
$BBCODES = fetch_bbcode_definitions();
$doubleRegex = '/(\[)(%s)(=)("|"|\'|)([^"]*)(\\4)\](.*)(\[\/%s\])/esiU';
$singleRegex = '/(\[)(%s)(\])(.*)(\[\/%s\])/esiU';
/* SMJU001 {step 39 / 41} This section of code replaced
if (isset($datastore['bbcodecache'])) // get bbcodes from the datastore
{
$bbcodecache = unserialize($datastore['bbcodecache']);
// SMJU001 {step 43 / 44} Inserted Code - start
if ($BBCODES['do_postupdate'] && $postid) // Hard code the retuned function value
{
$DB_site->query("
UPDATE post
SET pagetext='".addslashes(str_replace('<br />', '', html_entity_decode($bbcode)))."'
WHERE postid=$postid");
}
// SMJU001 {step 43 / 44} Inserted Code - End
if ($iswysiwyg) // text to show in the WYSIWYG editor box
{
$bbcode_find = $BBCODES['standard']['find'];
$bbcode_replace = $BBCODES['standard']['replace'];
}
Hack Steps 45/46
PHP Code:
else // text to show everywhere else
{
//$bbcode_find = array_merge($BBCODES['standard']['find'], $BBCODES['custom']['find']);
//$bbcode_replace = array_merge($BBCODES['standard']['replace'], $BBCODES['custom']['replace']);
foreach($bbcode_find AS $tag => $findregex)
{
// if using option, $tag will be '[xxx='
// if not using option, $tag will be '[xxx]'
while (stristr($bbcode, $tag) !== false)
Hack Steps 47/48
PHP Code:
while (stristr($bbcode, $tag) !== false)
{
// SMJU001 {steps 47 / 48} Inserted code - start
if ($include_file["$tag"])
{
@include_once($include_file["$tag"]);
}
// SMJU001 {steps 47 / 48} Inserted text - end
// make a copy of the text pre-replacement for later comparison
$origtext = $bbcode;
// SMJU001 Step 43/44 Inserted Code - start
// I found the search string twice, so I sinserted it twice.
if ($BBCODES['do_postupdate'] && $postid) // Hard code the retuned function value
{
$DB_site->query("
UPDATE post
SET pagetext='".addslashes(str_replace('<br />', '', html_entity_decode($bbcode)))."'
WHERE postid=$postid ");
}
// SMJU001 Inserted Code - End
if ($iswysiwyg) // text to show in the WYSIWYG editor box
{
$bbcode_find = $BBCODES['standard']['find'];
$bbcode_replace = $BBCODES['standard']['replace'];
}
I am wondering if the problem was in step 43 where the instructions only indicate 1 occurance of the search string and I found 2. Should I only have inserted the code once? and if so at which point.
It gratifies me someone else has looked and can't spot a problem, I was pulling my hair out looking for a accidentally erased / misplaced semi-colon.