Advertisement:

Author Topic: Help with new custom BBC?  (Read 24842 times)

Offline JamzTheMan

  • Semi-Newbie
  • *
  • Posts: 12
Help with new custom BBC?
« on: September 16, 2011, 04:35:58 AM »
OK, I'm completely stumped.  And I'm new to php/smf mod so be gentle :)

So, in Subs.php I have added:

Code: [Select]
array(
'tag' => 'xp',
'type' => 'unparsed_equals',
'before' => build_xp_output($user_info['username'], '$1'),
),

I also added the build_xp_output function above the parse_bbc function.

It calls my function on parsing the tag [xp=Karen] just fine but my SQL returns null values.



Code: [Select]
function build_xp_output($characterUserName, $characterName)
{
$xpQuery = "SELECT SUM(xp_earned), SUM(xp_spent), SUM(xp_secondary_earned), SUM(xp_secondary_spent) FROM character_xp WHERE ";
.
.
.
//$characterName = 'Karen';  <--WORKS IF THIS LINE IS ADDED
$xpQueryFinal = $xpQuery . "character_name = '".$characterName."' and user_name = '".$characterUserName."'";

$xpResult = mysql_query($xpQueryFinal, $wodDbLink);
.
.
.

So I got far enough into the debugging to find that the SQL returns null values (always returns 1 row due to the SUM) if I used the $characterName variable passed in, but if I hard code that variable, everthing runs perfect!  I've output the variable every way I could find and don't see anything wrong with it. I've printed the SQL to the screen, copied, ran it manually, and it works. I've checked the encoding (ASCII) and still stumped.

It's like the $1 passed to the function has some hidden characters in it or something :/

Help?

Offline JamzTheMan

  • Semi-Newbie
  • *
  • Posts: 12
Re: Help with new custom BBC?
« Reply #1 on: September 16, 2011, 01:48:13 PM »
Ok, so using a hexdump function, I now see this:

(first line is right after the function is called, second line is when I reassign the variable to 'Karen' for testing.
Code: [Select]
0000  24 31                                              $1
0000  4b 61 72 65 6e                                     Karen

So the parse_bbc function is calling my function and just passing a reference of $1? And then I'm passing a reference vs the string contents to my SQL? Is that the issue?

If so, how do I fix it?

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: Help with new custom BBC?
« Reply #2 on: September 16, 2011, 02:10:01 PM »
after this:
Code: [Select]
array(
'tag' => 'xp',
'type' => 'unparsed_equals',
'before' => build_xp_output($user_info['username'], '$1'),
),
try this:
Code: [Select]
var_dump($1);
exit();
and you'll probably find that your variable is null.

Also, FYI in Subs.php there is an integration hook for adding BBC codes you could use so you wouldn't have to mess with your Subs.php file :)

look for this line:
Code: [Select]
// Let mods add new BBC without hassle.
call_integration_hook('integrate_bbc_codes', array(&$codes));
and if you want to go that route you can use this integration hooks skeleton file I just uploaded 5 min ago :)
http://www.simplemachines.org/community/index.php?topic=452678.0
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline JamzTheMan

  • Semi-Newbie
  • *
  • Posts: 12
Re: Help with new custom BBC?
« Reply #3 on: September 16, 2011, 02:40:59 PM »
that just gave me an error:

Code: [Select]
Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in /.../forums/Sources/Subs.php on line 1853
I get a value in my function, ie on the screen is prints 'Karen' but to the database, it sends '$1'.

It seems $1 is passed by reference to the function? Is there some other/better way to call my function and pass some value from the bbc tag?
« Last Edit: September 16, 2011, 02:51:50 PM by JamzTheMan »

Offline Andre N

  • Jr. Member
  • **
  • Posts: 362
  • Gender: Male
  • My facebook friend tally has recently skyrocketed
    • R2bconcepts
Re: Help with new custom BBC?
« Reply #4 on: September 16, 2011, 04:03:11 PM »
Ok, let's do it your way. You have your variable ($1) in quotes, which makes it a string.
Code: [Select]
'before' => build_xp_output($user_info['username'], '$1'),should be
Code: [Select]
'before' => build_xp_output($user_info['username'], $1),notice the no quotes around your variable. You need to set that variable with a value before you call the function.
"Every generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?"

Offline JamzTheMan

  • Semi-Newbie
  • *
  • Posts: 12
Re: Help with new custom BBC?
« Reply #5 on: September 16, 2011, 11:00:08 PM »
OK, well that gives an error to:

Code: [Select]
Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in /home/content/.../forums/Sources/Subs.php on line 1850
And it's not really "my" way, I'm just copying existing code bits.  I'd love to use the integration piece but don't even know how to start... I figured if I can just get it working here, I could clean it up later.

I'm assuming the parse_bbc function later replaces/injects this $1 with parsed input from the BBC tag and calls my defined function later?

Offline JamzTheMan

  • Semi-Newbie
  • *
  • Posts: 12
Re: Help with new custom BBC?
« Reply #6 on: September 17, 2011, 01:39:14 AM »
OK never mind, I gave up on this and used the Custom BBC mod to call a JavaScript AJAX call to a php script to give me what I needed.

In the end, much cleaner, all code is external to SMF now.