Advertisement:

Author Topic: Adding multiple functions to a single hook (in this case for multiple bbc tags)  (Read 2390 times)

Offline ElusiveEagle

  • Semi-Newbie
  • *
  • Posts: 29
Hello!

I have spent a good deal of time reading and rereading the integration information to get a better grasp of how they work. My goal with the mod I am currently coding is to add four new bbc tags (these tags are specific to my community--I'll just get that out there):
  • [spoiler][/spoiler] (inline spoiler)
  • [spoiler2][/spoiler2] (block spoiler)
  • [nsfw][/nsfw]
  • [picturespam][/picturespam]
I'm using integrate_bbc_codes and integrate_bbc_buttons to add the tags. However, when my code to add the integration functions runs, it only stores the last 3 hooks in the database. In other words, the earlier hooks are being "overwritten". I figure there must be some way to add multiple functions to a single hook, but I'm not sure how and I can't find any documentation for it. Below is my current code to add the integration functions. The last three hooks in the array are the only three that are stored properly in the database (picturespam and the pre-include file).

Code: [Select]
<?php

if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF')) 
require_once(dirname(__FILE__) . '/SSI.php');
elseif (!
defined('SMF'))
exit('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php.');

if (!empty(
$smcFunc['db_query'])) {
$hooks = array(
'integrate_bbc_codes' => 'spoiler_bbc_code',
'integrate_bbc_buttons' => 'spoiler_bbc_button',
'integrate_bbc_codes' => 'spoiler2_bbc_code',
'integrate_bbc_buttons' => 'spoiler2_bbc_button',
'integrate_bbc_codes' => 'nsfw_bbc_code',
'integrate_bbc_buttons' => 'nsfw_bbc_button',
'integrate_bbc_codes' => 'picturespam_bbc_code',
'integrate_bbc_buttons' => 'picturespam_bbc_button',
'integrate_pre_include' => $sourcedir '/Subs-BBCode.php',
);

foreach ($hooks as $hook => $function)
add_integration_function($hook$functiontrue);
}

?>

So, is there some way to add multiple functions to a single hook? Using an array? A comma-delimited list? (lol) I just want to do it the right way. I guess alternatively I could try to put all of the button functions into one and all of the code functions into one, but that really doesn't solve the problem. I just think about future mods: For example, if I install one mod that assigns a function to the integrate_bbc_codes hook and then later install another mod that also assigns a function to the integrate_bbc_codes hook, how do both functions coexist (so they can run properly)? I would think the second mod would overwrite the first mod based on my current experience.

Thanks again for the help! I greatly appreciate it. :)

Sincerely,

EE

Offline IchBin™

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,115
  • Gender: Male
  • I don't speak German.
It's because each key in the array has to be unique. When you have this set in your array:

'integrate_bbc_codes' => 'spoiler_bbc_code',

And then you do this in the array later:
'integrate_bbc_codes' => 'spoiler2_bbc_code',
    (key)                                    (value)
The last entry over-writes any other entry with the same name in the key. You should do multiple arrays and foreach loops to add them.
IchBin™        TinyPortal
Coding Guidelines       

Offline ElusiveEagle

  • Semi-Newbie
  • *
  • Posts: 29
Ack, doh. *facepalm* Gotta love when it's staring at me right in the face. Thanks for the reply! :)

Offline IchBin™

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,115
  • Gender: Male
  • I don't speak German.
Don't feel bad, I didn't see the answer right away. I first put the array into a file and then did a print_r() on the array. When I noticed only the last item for each key was shown I then knew the answer. lol
IchBin™        TinyPortal
Coding Guidelines