Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Doug Heffernan on April 22, 2019, 04:50:01 PM

Title: Do these hooks exists for smf 2.0x?
Post by: Doug Heffernan on April 22, 2019, 04:50:01 PM
I am working a couple of mods that will add extra options/settings to the Maintenance and Tasks. As far as I could see there are no hooks to add in those 2 areas. Am I right or have I missed them?
Title: Re: Do these hooks exists for smf 2.0x?
Post by: SychO on April 22, 2019, 05:05:05 PM
I don't really know,

All hooks are listed here https://wiki.simplemachines.org/smf/Integration_hooks

Usually when I make a mod, I look for a call to "call_integration_hook" around the area I wish to customize, so if you can't find one, then there isn't. SMF2.0 is very poor in hooks, SMF2.1 on the hand is full of them so I really don't think mod authors will have to modify the code at all except for a few rare cases for that version.
Title: Re: Do these hooks exists for smf 2.0x?
Post by: Suki on April 22, 2019, 05:05:30 PM
Do you mean scheduled tasks? if so, you have to add yours in the corresponding table,  something like scheduled_tasks or so, can't remember correctly the actual table name.  Check a mod that adds a scheduled task to see for yourself, I got one for posting birthdays.

I can't remember if theres a hook for maintenance.
Title: Re: Do these hooks exists for smf 2.0x?
Post by: Doug Heffernan on April 22, 2019, 05:19:04 PM
Quote from: SychO on April 22, 2019, 05:05:05 PM
I don't really know,

All hooks are listed here https://wiki.simplemachines.org/smf/Integration_hooks

Usually when I make a mod, I look for a call to "call_integration_hook" around the area I wish to customize, so if you can't find one, then there isn't. SMF2.0 is very poor in hooks, SMF2.1 on the hand is full of them so I really don't think mod authors will have to modify the code at all except for a few rare cases for that version.

I did look but I could find any. I thought that maybe I missed it, but now I see that I was right in my assumtion that there are no hooks for those areas. I am glad to read that about 2.1. It will make coding/developing mods much much easier.

Quote from: Suki on April 22, 2019, 05:05:30 PM
Do you mean scheduled tasks? if so, you have to add yours in the corresponding table,  something like scheduled_tasks or so, can't remember correctly the actual table name.  Check a mod that adds a scheduled task to see for yourself, I got one for posting birthdays.

I can't remember if theres a hook for maintenance.

Yes, I meant the scheduled tasks. And yes, I have added it to the smf_ scheduled_tasks as well.

Many thanks for your replies guys.
Title: Re: Do these hooks exists for smf 2.0x?
Post by: Kindred on April 22, 2019, 07:23:03 PM
check the RSS Feed importer mod... I know that one adds a scheduled task
Title: Re: Do these hooks exists for smf 2.0x?
Post by: Sesquipedalian on April 23, 2019, 03:14:26 AM
FYI, you can create your own hooks at any arbitrary place in the SMF 2.0.x code that you like. Just use modification.xml to insert a single line like this where appropriate:


call_integration_hook('modname_funcname', array(&var1, &var2));


Then use the normal methods in your mod package for connecting your mod's functions with the hook.

This approach keeps your file edits nice and clean (only one line added), and allows you to use the same code in both 2.0 and 2.1 without any significant rewrites.

For an example of how to do this, feel free to look at the 2.0 install code I use in my Paragrapher mod.
Title: Re: Do these hooks exists for smf 2.0x?
Post by: Arantor on April 23, 2019, 04:12:00 AM
The real trick is hijacking existing hooks to do things because other hooks don't exist ;D LevGal has a great example, there's no hook in 2.0 to do stuff on the back of deleting a group (no tidy up option there) but careful manipulation of other hooks means it does become possible to do...

Just hard work and ugly though :( and the less we say about abusing integrate_buffer the better.
Title: Re: Do these hooks exists for smf 2.0x?
Post by: Doug Heffernan on April 23, 2019, 08:30:31 AM
Thanks for the tips guys, really appreciate it.