PDA

View Full Version : BB Code Functions


Velocd
03-28-2004, 10:00 PM
http://www.animesystem.com/temp/bbcf1.0.jpg


As requested by mudpyr8:
https://vborg.vbsupport.ru/showthread.php?t=62933


Features

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. ;)

Velocd
03-29-2004, 04:35 AM
Have a custom function that is useful?

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:

5*6%3+((45/5)/4)

5*6%3 = 0
(45/5)/4 = 2.25
= 2.25

Here is the function:
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.

Boofo
03-29-2004, 05:27 AM
Sorry to sound so deft here, but what does this actually do and how would we use it?

Also, I have to know. How did you do that with that screenshot at the top of the post? That is wild. ;)

xware
03-29-2004, 09:02 AM
Sorry to sound so deft here, but what does this actually do and how would we use it?

lasto
03-29-2004, 09:15 AM
Sorry to sound so deft here, but what does this actually do and how would we use it?


ditto LOL im confused as well

Boofo
03-29-2004, 09:29 AM
Sorry to sound so deft here, but what does this actually do and how would we use it?

Just curious here ... was there a reason you didn't quote the message instead of just repeating it? ;)

Charlie Argueta
03-29-2004, 10:41 AM
This is amazing, but some of them are too hardcored, may be I will use some of them.

See Ya

Velocd
03-29-2004, 02:48 PM
I thought the attached screenshots would be enough of an explanation.

This hack allows you to give bb code PHP functions (internal or custom).

For example, if I assigned the PHP function rand() to a tag called , it would generate a random value.

[rand="0"]100

Would generate a random value from 0 - 100.

Dean C
03-29-2004, 03:13 PM
This looks great - could be used to resize an image right? And all sorts ....

Btw love that image at the top ;)

Bad Bunny
03-29-2004, 04:00 PM
I thought the attached screenshots would be enough of an explanation.

This hack allows you to give bb code PHP functions (internal or custom).

For example, if I assigned the PHP function rand() to a tag called , it would generate a random value.

[rand="0"]100

Would generate a random value from 0 - 100.
Wow. So it is possibly to simulate dice with this (amongst many other things)?! That's pretty hardcore!

Velocd
03-29-2004, 08:21 PM
Also, I have to know. How did you do that with that screenshot at the top of the post? That is wild.

Although it wouldn't be too hard to do in photoshop, it's made through a German site called LetterJames (http://www.letterjames.de/motive/listMotive.html?rubrikId=14), which allows you to add your own captions to signs, etc.

Wow. So it is possibly to simulate dice with this (amongst many other things)?! That's pretty hardcore!

Yes, but at the moment there is a bug requiring you to use the WYSIWYG editor when posting, if you want a random generated value by the function to be hard-coded into that post (replaced with its bbcode tag). Otherwise, you could keep refreshing the page and a new random value would show.

could be used to resize an image right?

I imagine you could do something like that with this, by passing a image URL and using the GD2 library.

Velocd
03-29-2004, 10:38 PM
So..

If anyone has this installed and working, could you let me know? It's a sort of long (although quick) hack to install, so I just want to confirm everything is in place. ;)

Link14716
03-29-2004, 10:44 PM
Wow, kickass hack. I won't install it just yet (trying to find a good file comparison program for Linux to upgrade to vB3 Gold - and I'm not digging myself into a bigger hole before I upgrade (31 modified files is enough for RC3, thank you very much) ;) Well definately install it when I finally get vB3 Gold up and running. :)

* Link14716 clicks install anyways. :)

Velocd
03-30-2004, 12:01 AM
The following is a useful function I made that evaluates a mathematical expression.
https://vborg.vbsupport.ru/showpost.php?p=492102&postcount=2

Boofo
03-30-2004, 12:08 AM
Although it wouldn't be too hard to do in photoshop, it's made through a German site called LetterJames (http://www.letterjames.de/motive/listMotive.html?rubrikId=14), which allows you to add your own captions to signs, etc.

Thank you, sir. Although I can't read ANY German, once you figure things out at that site, It's pretty impressive. ;)

AlexanderT
03-30-2004, 10:26 AM
Btw love that image at the top ;)
It's from Frankfurt Airport/Germany - I knew I've seen that sign before :)

mudpyr8
03-31-2004, 01:05 AM
Big kudos to VeloCD for doing this hack. He was willing to write the code after an initial request I made for my dice roller. I like to have the ability for members to roll dice in my forums, but I didn't want to have to hack up the bbcode parser to do it. I thought it would be great to have an adminCP that would allow for php functions to be called by bbcodes, but had NO idea how to do it.

Luckily VeloCD saw my post and said he knew how to do it and here it is.

BIG BIG THANKS.

I will be posting my dice roller soon. If you'd like to see it in action, here you go:
http://www.tekhed.com/dice/

Feel free to email me with game system support requests.

wcbryant
03-31-2004, 09:39 AM
I'm going to have to add a line of credit to my site just to cover you Velocd. I don't go looking for your hacks specifically, but it seems you're often behind the ones I end up on when I have a focused need. Great work, again.

Now that I've blown a little sunshine, I have a "clueless" question to ask. I need to figure out some method of allowing users to make text in their post 'secure'. 'Secure' in the sense that other users can't just highlight, right click, copy, and then paste elsewhere. I know nothing is entirely safe (they could simply just View Source), but the primary goal is to prevent someone from absentmindedly cutting and pasting something sensitive into an email to someone else. I could just do it for all my pages, but in many cases the content my site covers needs to be able to be copied and pasted into other posts, so that's no good. Needs to be only there when people want it so.

I've found JavaScript that can accomplish this (I'll quote below in case this is a bad way to do it (it did come from someone named Bart with an AOL account after all), and someone can recommend better -- or in case I haven't expressed my desire well enough), but no PHP. PHP *seems* to be what your hack speaks to though. So my question, and it's coming from a layman to be sure, is can I accomplish what I want with your hack?

<SCRIPT language=JavaScript>
<!--
/*
No rightclick script v.2.5
(c) 1998 barts1000
barts1000@aol.com
Don't delete this header!
*/

var message="Oops, that function is disabled.";

// Don't edit below!

function click(e) {
if (document.all) {
if (event.button == 2) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
// -->

</SCRIPT>

mudpyr8
03-31-2004, 11:41 AM
One control that might be necessary is the ability to prohibit the use of a particular code in a signature. BBCodes are normally allowed in signatures, but someone who puts [power] into their sig, or 50d1000 could generate a lot of server activity. If this isn't possible, the admin will just have to watch for such sigs, but it is important to note that. 100 people with factorials in their sigs is gonna be bad.

mudpyr8
03-31-2004, 11:44 AM
wcbryant: I think you can. You would just have to write a php function that wraps the bbcode param in the javascript:

insert message here would then wrap "insert message here" in the javascript.

Velocd
04-01-2004, 04:35 AM
wcbryant, I understand what you're trying to do, but I don't think this hack serves the purpose. (unless my interpretation is wrong, and mudpyr8 is closer to your question)

One control that might be necessary is the ability to prohibit the use of a particular code in a signature. BBCodes are normally allowed in signatures, but someone who puts [power] into their sig, or 50d1000 could generate a lot of server activity. If this isn't possible, the admin will just have to watch for such sigs, but it is important to note that. 100 people with factorials in their sigs is gonna be bad.

In the case you have a server-extensive function, it would. If you have the feature for not calling a function every time upon page refresh (although there is a bug right now where you must post in the WYSIWYG editor for this to apply) then it wouldn't be that big of a deal.

I will look into disabling it for signatures, as well fixing that bug, over the weekend. ;)

wcbryant
04-01-2004, 09:18 AM
wcbryant, I understand what you're trying to do, but I don't think this hack serves the purpose. (unless my interpretation is wrong, and mudpyr8 is closer to your question)

My explanation was convoluted at best, but despite that I think you both understood. I've looked at the hack some more, and while I think it walks a line very near to what I want to do -- may even be able to function loosely in that capacity in the manner mudpyr8 suggested -- it's probably not the 'right' approach. Which might be somehow just adding a 'no text copy' flag to the Additional Options field when posting.

You can turn off 'email to a friend' or 'printer friendly format' in threads, all I want to be able to do is turn off user's ability to copy and paste. Disable text highlighting (not that I think the JS I found does that), and disable right clicking. Again, I understand people can always just view source, but my goal is the prevention of accidental leaks, rather than intentional/malicious ones.

Anyway, thanks to you both for the responses.

mudpyr8
04-13-2004, 03:08 PM
VeloCD, thanks. I got it working and it is superb. A couple of things:

1. In your install notes, steps 49 & 50 refer to 'allowsmilie". It should be 'allowsmilies'.

2. It reevaluates on edit of the message. It would be nice if this could be disabled. For my dice roller, I only want it to roll once. Not a big deal since when rolling dice it is a faux pas to edit your post anyway.

3. It only accepts one instance of the code (the last one). If I put two [roll] tags in one message, it only evaluates the last one.

Again, thanks a lot. This rocks.

Velocd
04-13-2004, 04:15 PM
1. Thanks, will correct. ;)

2. If you are using the WYSIWYG editor and have the update option disabled, it shouldn't do so, since the return value of the function is hard-coded into the post. But, I haven't had time to look into making the update work for non-WYSIWYG.

3. That's odd. I'll check this out, although it should evaluate all tags. If you place two custom BB Code function tags that aren't your roll function, say maybe [random], does this generate two random values?

Sven
06-21-2004, 12:38 PM
I have installed this hack so far since I was looking for something that enables me to use php functions in bbcodes...
But I'm fiddling around and it's not working....
Here's the function to include:
<?php
// ###################### Start fetch_countdown_timer ######################
// returns the time left untill $dateline
function fetch_countdown_timer($dateline) {

global $vboptions;

$diff = $dateline - (time() - $vboptions['hourdiff']);

$days = ($diff - ($diff % 86400)) / 86400;
$diff = $diff - ($days * 86400);
$hours = ($diff - ($diff % 3600)) / 3600;
$diff = $diff - ($hours * 3600);
$minutes = ($diff - ($diff % 60)) / 60;
$diff = $diff - ($minutes * 60);
$seconds = ($diff - ($diff % 1)) / 1;

return iif($days > 0, $days.'d ', '').iif("$hours > 0 && $days != 0", $hours.'h ', '').$minutes.'m';

}
?>
Now I added a function like this:
Title: countdown
Handle: fetch_countdown_timer
Include File: countdown.php (containing above code)

Also I added a bbcode 'countdown' and have choosen the function in there....
It's just not working, what am I doing wrong?
As an example I used
03, July 2004 and the function returns something like -13h -40m instead of 11d and something....

How do I pass the date of interest to the function?

Sven
06-22-2004, 08:40 AM
sorry for double posting but I didn't want to edit in case someone read my previous posting and wouldn't recognize this posting then.

I think I found out what's going wrong, it's because If I'm trying to pass a date it will be passed as Unix Timestamp.

Is there any way to pass the variable to the function as formatted date?

Sven
06-25-2004, 08:24 AM
^bump^

Wasser
07-15-2004, 03:36 AM
it would be perfect to have a countdown timer intergrated with the calendar. =)

KW802
08-03-2004, 08:29 PM
OK, I'm those of those guys that hated math classes in school.... besides the mathematical functions, what are some other uses that you guys have come up with?

Borisch
09-12-2004, 07:40 PM
From the description...this hack is the King!
Installing and testing tomorrow.

Sven
09-30-2004, 10:09 AM
After the upgrade to 3.03 I had to re-install this hack and, as an outcome, here are the instructions for the countdown:

Install the hack
Add the following code to includes/functions.php:
// ###################### Start fetch_countdown_timer ######################
// returns the time left untill $dateline
function fetch_countdown_timer($dateline) {

global $vboptions;

$diff = $dateline - (time() - $vboptions['hourdiff']);

$days = ($diff - ($diff % 86400)) / 86400;
$diff = $diff - ($days * 86400);
$hours = ($diff - ($diff % 3600)) / 3600;
$diff = $diff - ($hours * 3600);
$minutes = ($diff - ($diff % 60)) / 60;
$diff = $diff - ($minutes * 60);
$seconds = ($diff - ($diff % 1)) / 1;

return iif($days > 0, $days.'d ', '').iif("$hours > 0 && $days != 0", $hours.'h ', '').$minutes.'m';

}
Create a custom bb code function like this:
title: countdown
handle: fetch_countdown_timer
description: whatever you want
include file: [leave blank]
Update upon page refresh?: yes

Then create a custom bb code:
title: countdown
tag: countdown
function: countdown
replacement: [leave blank]
example: 1088859600 (choose any unix timestamp here)
description: [whatever you want]
use parameter: no
button image: [any image you want]

Now, to make this usable to your users:
Add a link to a calculation script like this one (I did this on the editor toolbars):
http://www.php4scripte.de/umrechner/
it converts a real time into a unix timestamp which can then be used within the BB Code.

I'd really appreciate if one could help me to avoid the conversion between realtime and unix timestamp... so the function can work with realtime formats

Sven
11-18-2004, 08:08 AM
I just tried to add a new cutom bbcode to our forums - well, that worked - but the new created code won't show up in the bbcode manager.

I edited all the files, according to the install.html, once again - with no effect at all.

Any help on what's wrong here?
Can anyone, who has this hack properly installed, send me this three files:
bbcode.php
adminfunctions.php
functions_bbcodeparse.php
??

Send them to sven@cncforen.de

TCM
01-16-2005, 09:26 PM
Does anyone yet know if this hack is compatiable with .5? It looks like a great hack, but I don't want to install it if it won't work yet, or will cause errors.

thamyeuvn
02-09-2005, 04:24 PM
I need Flash BB code, can anyone here help me?
I need to import flash in to my forum but I dont know how to do that.
Thanks.

TCM
02-12-2005, 04:48 PM
Hey. I'm trying to get this hack installed, but I don't understand how to run the queries from PHPMyAdmin. I go to my database, select Querey, but I don't know where to enter it. Entering it in the box labeled "SQL-query on database tcmutt_Source" just gives me the error "You have to choose at least one Column to display". =/ Can anyone tell me what I'm doing wrong?

EDIT: Whoops. My mistake. I think I found out where to do it.

EDIT2: Alright, it's installed correctly now. Thanks for making this, it should prove very useful. :D

smju
04-01-2005, 12:48 PM
Are the instructions for installation still valid with 3.0.7?

TCM
04-01-2005, 07:46 PM
Are the instructions for installation still valid with 3.0.7?Yup. I've got vB 3.0.7 and this works great on mine. :)

smju
04-12-2005, 02:32 PM
Well, I did everything the instructions said and I got an error, so backed it all out.

The error was in the functions_bbcodeparse file. The error message was "unexpected $ at line 1767" (which is the line with the ?>).

I have checked all the hacks and they seem correct.

Here is the final code you can find all the changes and the step numbers by finding "SMJU001"

I tried pasting the code in here BUT it made the message too big. Thus you can find it [Removed by moderator]** Here **

Marco van Herwaarden
04-12-2005, 06:24 PM
Well, I did everything the instructions said and I got an error, so backed it all out.

The error was in the functions_bbcodeparse file. The error message was "unexpected $ at line 1767" (which is the line with the ?>).

I have checked all the hacks and they seem correct.

Here is the final code you can find all the changes and the step numbers by finding "SMJU001"

I tried pasting the code in here BUT it made the message too big. Thus you can find it ** Here ** (http://www.smjunwin.demon.co.uk/Development/temp/functions_bbcodeparse_new.php)You should immediate remove that file. It is against your license agreement and our Forum Rules to paste significant parts of vB files, or vB files in whole.

smju
04-12-2005, 08:51 PM
Whoops.

Consider it removed.

How then do I get help, because I am convinced that I made the hack changes correctly.

Marco van Herwaarden
04-13-2005, 03:49 AM
Just copy & paste the edited lines (with a few lines above and under).

smju
04-13-2005, 11:43 AM
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.


Hack Steps 27/28

$bbcodes['custom']['recurse']['highlight'][0] = array('replace_html' => "<span class=\"highlight\">\\7</span>");

return $bbcodes;
}

// ###################### 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

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 checkparam #######################


Hack Steps 31/32

$return = preg_replace('#%(?!\d+\$s)#', '%%', $return);
return sprintf($return, $param, $option);
}

// ###################### 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

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

if ($wysiwygtype == 'ie')


Hack Steps 35/36/37/38

$replace = array("\n", "\n", "\n");
$innertext = str_replace($find, $replace, $innertext);

return '</p>' . $prepend . $innertext . '[/list]<p style="margin:0px">';
// SMJU001 {step 35/36} This code inserted

// ###################### Start handle_bbcode_function #######################

function handle_bbcode_function($BBCODES, $bbcode, $post_bbcode, $singleRegex, $doubleRegex)
{
if ($bbcode['twoparams'])
{
$regex = sprintf($doubleRegex, $bbcode['bbcodetag'], $bbcode['bbcodetag']);
$tagname = "[$bbcode[bbcodetag]=";

$checkparam = 5;
$option_param = ",'\\7'";
}
else
{
$regex = sprintf($singleRegex, $bbcode['bbcodetag'], $bbcode['bbcodetag']);

$tagname = "[$bbcode[bbcodetag]]";
$checkparam = 4;
}

$BBCODES['custom']['find']["$tagname"] = $regex;

if ($bbcode['bbcode_functionid'])
{
if ($bbcode['include_file'])
{
$BBCODES['custom']['include_file']["$tagname"] = $bbcode['include_file'];
}

$BBCODES['custom']['replace']["$tagname"] = "@$bbcode[handle]('\\$checkparam'$option_param)";

if (!$bbcode['refresh'] && $post_bbcode)
{
if ($bbcode['include_file'])
{
@include_once($bbcode['include_file']);
}

if (stristr($post_bbcode, $tagname) !== false)
{
$post_bbcode = preg_replace($BBCODES['custom']['find']["$tagname"], $BBCODES['custom']['replace']["$tagname"], $post_bbcode);
$BBCODES['do_postupdate'] = 1;
}
}
}
else
{
$BBCODES['custom']['replace']["$tagname"] = "handle_bbcode_parameter('\\$checkparam','" . str_replace("'", "\'", $bbcode['bbcodereplacement']) . "')";
}

unset($option_param);


if ($post_bbcode)
{
return $BBCODES;
}
else
{
$BBCODE['replacement'] = $BBCODES['custom']['replace']["$tagname"];
$BBCODE['regex'] = $BBCODES['custom']['find']["$tagname"];
$BBCODE['include_file'] = $BBCODES['custom']['include_file']["$tagname"];

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.

$wysiwygparse = $iswysiwyg;

if (empty($BBCODES['standard']))
{
$BBCODES = fetch_bbcode_definitions();

$doubleRegex = '/(\[)(%s)(=)(&quot;|"|\'|)([^"]*)(\\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']);

foreach ($bbcodecache AS $bbregex)
{
if ($bbregex['twoparams'])
{
$regex = sprintf($doubleRegex, $bbregex['bbcodetag'], $bbregex['bbcodetag']);
$bbregex['bbcodereplacement'] = str_replace(array('\\7', '\\5'), array('%1$s', '%2$s'), $bbregex['bbcodereplacement']);
$tagname = "[$bbregex[bbcodetag]=";
$checkparam = '\\7';
$checkoption = '\\5';
}
else
{
$regex = sprintf($singleRegex, $bbregex['bbcodetag'], $bbregex['bbcodetag']);
$bbregex['bbcodereplacement'] = str_replace('\\4', '%1$s', $bbregex['bbcodereplacement']);
$tagname = "[$bbregex[bbcodetag]]";
$checkparam = '\\4';
$checkoption = '';
}
$BBCODES['custom']['find']["$tagname"] = $regex;
$BBCODES['custom']['replace']["$tagname"] = "handle_custom_bbcode('$checkparam', '$checkoption', '" . str_replace("'", "\'", $bbregex['bbcodereplacement']) . "')";
}
}
else // query bbcodes out of the database
{
$bbcodes = $DB_site->query("
SELECT bbcodetag, bbcodereplacement, twoparams
FROM " . TABLE_PREFIX . "bbcode
");
while ($bbregex = $DB_site->fetch_array($bbcodes))
{
if ($bbregex['twoparams'])
{
$regex = sprintf($doubleRegex, $bbregex['bbcodetag'], $bbregex['bbcodetag']);
$bbregex['bbcodereplacement'] = str_replace(array('\\7', '\\5'), array('%1$s', '%2$s'), $bbregex['bbcodereplacement']);
$tagname = "[$bbregex[bbcodetag]=";
$checkparam = '\\7';
$checkoption = '\\5';
}
else
{
$regex = sprintf($singleRegex, $bbregex['bbcodetag'], $bbregex['bbcodetag']);
$bbregex['bbcodereplacement'] = str_replace('\\4', '%1$s', $bbregex['bbcodereplacement']);
$tagname = "[$bbregex[bbcodetag]]";
$checkparam = '\\4';
$checkoption = '';
}
$BBCODES['custom']['find']["$tagname"] = $regex;
$BBCODES['custom']['replace']["$tagname"] = "handle_custom_bbcode('$checkparam', '$checkoption', '" . str_replace("'", "\'", $bbregex['bbcodereplacement']) . "')";
}
}
// SMJU001 {step 39 / 41} end of code section to be replaced */
// SMJU001 {step 40 / 42} Replacement code - start
if (isset($datastore['bbcodecache'])) // get bbcodes from the datastore
{
$bbcodecache = unserialize($datastore['bbcodecache']);

foreach($bbcodecache AS $bbregex)
{
$BBCODES = handle_bbcode_function($BBCODES, $bbregex, &$bbcode, $singleRegex, $doubleRegex);
}
}
else // query bbcodes out of the database
{
$bbcodes = $DB_site->query("
SELECT bbcode.bbcodetag, bbcode.bbcodereplacement, bbcode.twoparams,
bbcode_function.handle, bbcode_function.include_file
FROM " . TABLE_PREFIX . "bbcode
LEFT JOIN " . TABLE_PREFIX . "bbcode_function
USING (bbcode_functionid)
");

while ($bbregex = $DB_site->fetch_array($bbcodes))
{
$BBCODES = handle_bbcode_function($BBCODES, $bbregex, $bbcode, $singleRegex, $doubleRegex);
}
}
// SMJU001 {step 40 / 42} Replacement code - end
}

// 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

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']);

$bbcode_find = array_merge($BBCODES['custom']['find'], $BBCODES['standard']['find']);
$bbcode_replace = array_merge($BBCODES['custom']['replace'], $BBCODES['standard']['replace']);

// SMJU001 {steps 45 / 46} Inserted code - start
if ($BBCODES['custom']['include_file'])
{
$include_file = $BBCODES['custom']['include_file'];
}
// SMJU001 {steps 45 / 46} Inserted code - end
}

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

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;

$bbcode = preg_replace($findregex, $bbcode_replace["$tag"], $bbcode);


Hack Steps 43/44: In the hack instructions step 43 gave a search string. I therefore inserted the code twice, in both places.
while($bbregex = $DB_site->fetch_array($bbcodes))
{
if ($bbregex['twoparams'])
{
$regex = sprintf($doubleRegex, $bbregex['bbcodetag'], $bbregex['bbcodetag']);
$checkparam = 7;
}
else
{
$regex = sprintf($singleRegex, $bbregex['bbcodetag'], $bbregex['bbcodetag']);
$checkparam = 4;
}
for ($i = 0; $i < 3; $i++)
{
$BBCODES['custom']['find'][] = $regex;
$BBCODES['custom']['replace'][] = "handle_bbcode_parameter('\\$checkparam','" . str_replace("'","\'",$bbregex['bbcodereplacement']) . "')";
}
}
}
}

// 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'];
}

smju
04-16-2005, 08:07 AM
One bit of info I forgot to add, was that I got the error after selecting the "Custom BB Code" option off the "Admin CP" menu.

smju
04-25-2005, 03:52 PM
Hmmm.

I wonder if the lack of a response is due to me actually applying the changes correctly.

Hmmm.

Marco van Herwaarden
04-25-2005, 08:52 PM
Well i don't see anything wrong when quickly browsing through it.

What editor did you use?

smju
04-28-2005, 08:45 AM
HTML-Kit.

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.

smju
07-05-2005, 11:53 AM
bump

smju
11-27-2005, 02:52 PM
I never did get this implemented, however we are now on 3.5.1 sooooooooo

Any chance that this mod is going to get ported to 3.5?