PDA

View Full Version : BBCode issues again... Getting another error.


MTGDarkness
01-21-2009, 01:37 PM
Fatal error: Call to undefined function: handle_bbcode_deck() in <snip>/forums/includes/class_bbcode.php on line 1199

:(

Well, here we go again. Errors where there shouldn't be errors. Where am I supposed to define this? When I had the error with a previous BBCode (Mana), I added the function right above the end of class_bbcode_alt.php, and it worked. But this one is giving me trouble.

$tag_list['no_option']['mana'] = array(
'callback' => 'handle_bbcode_manacost',
'strip_empty' => true,
'stop_parse' => true,
);


$tag_list['option']['deck'] = array(
'callback' => 'handle_bbcode_deck',
'strip_space_after' => 2,
'strip_empty' => true,
);

I don't see the massive difference between the two. Meanwhile, the mana tags aren't screwing with me... Is it the option? I have the function for deck defined as "function handle_bbcode_deck($body, $name)", is that enough for the option? Can someone help me out here?

Dismounted
01-22-2009, 02:36 AM
Your callback should be "handle_external". You should then add another element "external_callback" which you should define your handling function. You should define your functions in bbcode_create, using a require_once() to a file with your functions.

MTGDarkness
01-22-2009, 04:12 PM
This is odd. See, the thing that's bugging me is, that one of those two tags works perfectly.

Also, can you explain the "add another element" part? Don't get that...

Dismounted
01-23-2009, 03:06 AM
$foo = array(
'element1' => 'this is an element of this array'
);

MTGDarkness
01-23-2009, 04:47 PM
Dammit. Still getting fatal errors.

Fatal error: Call to undefined function: bbcode_deck() in <snip>/includes/class_bbcode.php on line 1426

Dammit. I can't evaluate which line it is effectively at this point... your method didn't work.

$tag_list['option']['deck'] = array(
'callback' => 'handle_external',
'strip_space_after' => 2,
'strip_empty' => true,
'external_callback' => 'bbcode_deck'
);

Dropped that plugin into BBCode Fetch Tags.

require_once("http://forums.mtgdarkness.com/includes/bbcode_deck.php");

Dropped that into bbcode_create.

The bbcode_deck.php file is basically this:

<?php
function bbcode_deck($body, $name)
{
(working function goes here)
}
?>

:(

Dismounted
01-24-2009, 02:46 AM
You cannot use URLs in includes to include local PHP. It will go to the URL and look at the output from that file, which is not what you want.
require_once(DIR . '/includes/bbcode_deck.php');

MTGDarkness
01-24-2009, 08:36 AM
Ah, I see. Thanks. That fixed it.

And how about adding a little clickable icon like with other bbcodes? Is that possible?

Dismounted
01-24-2009, 09:18 AM
I think you can do that by editing one of the editor templates (I'm not sure, I have not had any need to do it before), editor_toolbar, maybe?

MTGDarkness
01-24-2009, 10:07 AM
Yeah, I looked at that before, but the code there is rather... specialized.

This is from editor_toolbar_on.

<if condition="$show['url_bbcode']">
<td><div class="imagebutton" id="{$editorid}_cmd_createlink"><img src="$stylevar[imgdir_editor]/createlink.gif" width="21" height="20" alt="$vbphrase[insert_link]" /></div></td>


I'm pretty sure that it's {$editorid} that makes the javascript code work, but I'm not sure where to edit or reproduce that.

Also, another thing... For some reason, with all the above functioning correctly, it isn't defining the 'option' correctly.

<?php
function bbcode_deck($body, $name)
{
// Start output and build header row with name.
$output .= '<table width="75%" align="center" cellpadding="0" cellspacing="0" style="border: 1px solid #000000;">
<tr><td class="tcat" style="padding:5px; font-size:20px;">' . $body . '</td></tr>
<tr><td class="alt2"><table cellspacing="0" cellpadding="0" border="0" width="100%" style="margin:5px;">';

(rest of function)
}
?>

The bbcode to that is: number*content1
number*content2

(of course, any number of content items)... For some reason, with this, $body automatically becomes "Object". I dunno why...

Dismounted
01-24-2009, 12:05 PM
You are not structuring your function correctly. Rather than explain it, I will just post the comment from class_bbcode.php.
/**
* Allows extension of the class functionality at run time by calling an
* external function. To use this, your tag must have a callback of
* 'handle_external' and define an additional 'external_callback' entry.
* Your function will receive 3 parameters:
* A reference to this BB code parser
* The value for the tag
* The option for the tag
* Ensure that you accept at least the first parameter by reference!
*
* @param string Value for the tag
* @param string Option for the tag (if it has one)
*
* @return string HTML representation of the tag
*/

MTGDarkness
01-24-2009, 12:26 PM
I found that in the class_bbcode file as well, and it's gibberish to me. At least, the * @param string Value for the tag
* @param string Option for the tag (if it has one)
*
* @return string HTML representation of the tag


Part.

King Kovifor
01-24-2009, 08:09 PM
That means that your function is getting this:

your_function('param', 'option')
{

return 'return';

}

That basically tells you what parameters it takes and what it expects (strings) and what the fuction is to return (a string).

MTGDarkness
01-24-2009, 10:24 PM
Wait. So I should just replace every instance of $body and $name with 'param' and 'option' respectively, and turn the final output variable into 'return'?
I'm stuill really confused...

Dismounted
01-25-2009, 02:31 AM
Please read the description properly:
/*
* Your function will receive 3 parameters:
* A reference to this BB code parser
* The value for the tag
* The option for the tag
* Ensure that you accept at least the first parameter by reference!
*/

MTGDarkness
01-25-2009, 08:08 AM
Parameters tells me nothing. How do I add the parameter to reference the BBCode parser?

Dismounted
01-25-2009, 11:47 AM
Read it again, carefully. Your custom function ("bbcode_deck()") will receive three parameters.

MTGDarkness
01-26-2009, 01:47 PM
I still don't get it. Can someone please just give me a straight answer?

Dismounted
01-27-2009, 03:22 AM
function bbcode_deck(&$parser, $value, $option)
{
// some code here
}
I hope you get it know...

MTGDarkness
01-27-2009, 02:48 PM
Ah-So the &$parsercalls back to the bbcode parser? I think I do get it... Thanks.

Dismounted
01-28-2009, 04:29 AM
The BB code parser calls your function, and provides three parameters for you to use. $parser is the reference for the BB code parser, in case you need it.
/*
* Your function will receive 3 parameters:
* A reference to this BB code parser
* The value for the tag
* The option for the tag
* Ensure that you accept at least the first parameter by reference!
*/