Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: wixi - marraskuu 21, 2013, 02:00:57 AP

Otsikko: Examples of Good Mods using Integration Hooks
Kirjoitti: wixi - marraskuu 21, 2013, 02:00:57 AP
Can you please point me to some good mods that make use of integration hooks? I am a bit confused on how to use them through modifications.xml and would like to study the source to learn more ... Thanks.
Otsikko: Re: Examples of Good Mods using Integration Hooks
Kirjoitti: emanuele - marraskuu 21, 2013, 02:18:08 AP
Just in case you didn't read it yet:
http://wiki.simplemachines.org/smf/Add_a_custom_action_using_integration_hooks

:)
Otsikko: Re: Examples of Good Mods using Integration Hooks
Kirjoitti: wixi - marraskuu 21, 2013, 09:26:41 AP
Thanks, I had read that. But I am a bit confused on how modifications.xml and Integration hooks gel together. They seem like two separate ways of doing things ...
Otsikko: Re: Examples of Good Mods using Integration Hooks
Kirjoitti: Arantor - marraskuu 21, 2013, 10:15:16 AP
That's because they are. modifications.xml (or whatever you want to call it, I've been known to have mods with multiple such files to group changes together) is about raw code editing, integration hooks is about not doing code editing at all.

Some mods find they need to do raw code editing because the choices available in terms of hooks may not be enough.
Otsikko: Re: Examples of Good Mods using Integration Hooks
Kirjoitti: live627 - marraskuu 21, 2013, 12:33:22 IP
modifications.xml = code edits
iinstall.php = usually database edits which includes settings and hooks

Some mods boast of only using hooks.
Otsikko: Re: Examples of Good Mods using Integration Hooks
Kirjoitti: wixi - marraskuu 21, 2013, 02:46:27 IP
So, for example, if I wanted to make a mod that added headers or footers to every post made in the forum the two ways to go about it would be -

Raw editing: Find out the "post message" function and modify it (i.e. change the core function) OR
Using hooks: Check for "post message" hook and attach it with your own custom post message function

Is that right?
Otsikko: Re: Examples of Good Mods using Integration Hooks
Kirjoitti: Arantor - marraskuu 21, 2013, 06:30:54 IP
Sort of. Not every function has a hook - fairly sure there isn't a hook in 2.0 for 'post message' for example. (There is one on creation of a new topic, and one for topic display that can be coerced into doing other things, but it's pretty limited.)
Otsikko: Re: Examples of Good Mods using Integration Hooks
Kirjoitti: wixi - marraskuu 22, 2013, 07:28:18 AP
Ah, ok. One other doubt - after you have added your own custom function to a hook, does the original core function still execute later? Taking the same example I posted - if I add a custom_post_message function to "post message" hook, will the original "post message" core function be called again later (after the custom_post_message function is executed)?
Otsikko: Re: Examples of Good Mods using Integration Hooks
Kirjoitti: Arantor - marraskuu 22, 2013, 01:26:19 IP
The hook is little more than 'when you get to this point, call me' notification. The original code will continue to run exactly as it would otherwise, a hook is merely *additional* code to be run at the selected points.
Otsikko: Re: Examples of Good Mods using Integration Hooks
Kirjoitti: wixi - marraskuu 22, 2013, 03:02:17 IP
So is there an option to decide whether the custom function runs before or after the core function (in case we are calling a hook that deals with a core function)?
Otsikko: Re: Examples of Good Mods using Integration Hooks
Kirjoitti: Arantor - marraskuu 22, 2013, 03:40:55 IP
No.

Hooks run when they run. There is a shortage of hooks anyway, if you don't have a hook for the specific task at hand, you'll have to just make an edit anyway. The available hooks are documented in the wiki (http://wiki.simplemachines.org/smf/Integration_hooks).
Otsikko: Re: Examples of Good Mods using Integration Hooks
Kirjoitti: wixi - marraskuu 26, 2013, 01:08:23 IP
Thanks for all the clarifications. Much appreciated.