Skip to main content
Topic: Hooks? (Read 2802 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Hooks?

So far my searches in this forum have proved futile regarding hooks......

Since I am using 1.1, I've been trying to manually install add ons..

Take "Users Online Today" Mod for example..

Code: [Select]
	<install for="1.0 - 1.0.99">
<require-file name="OnlineToday.class.php" destination="SUBSDIR" />
<require-file name="OnlineToday.template.php" destination="THEMEDIR" />
<require-file name="OnlineToday.english.php" destination="LANGUAGEDIR" />
<hook hook="integrate_action_boardindex_after" file="SUBSDIR/OnlineToday.class.php" function="Online_Today_Integrate::get" />
<hook hook="integrate_general_mod_settings" file="SUBSDIR/OnlineToday.class.php" function="Online_Today_Integrate::settings" />
</install>

What I did was, I manually uploaded the three files..

And then..... I'm stuck. Hook what? I searched through all the files in Elkarte, but there's not much going on about hooks (which I can understand at least)..

I thought that all I needed to do was to add the hook codes to a file which stores all hooks... boy was I wrong.. :p

Anyone patient enough to explain to me about hooks and how it works and what I should do, etc? :D

 niloc is hopeful
Facta, non verba.

Re: Hooks?

Reply #1

Quote from: niloc – Since I am using 1.1, I've been trying to manually install add ons..
Is the package manager not working with them?
Bugs creator.
Features destroyer.
Template killer.

Re: Hooks?

Reply #2

Yeah it wouldn't install it.. :(
Facta, non verba.

Re: Hooks?

Reply #3

Did you actually enable it in admin > config > addons-settings > miscellaneous?
Because:
http://www.elkarte.it/elk1.1/index.php
it's not exactly up-to-date, but I don't remember anything major changed between this and beta1.
Bugs creator.
Features destroyer.
Template killer.

Re: Hooks?

Reply #4

OMG.. I didn't know online today was a built in function in 1.1!!!!!!!!!!!!!

Wow, you saved me a lot of work! :D :D :D

I still don't get all the hooks stuff and all that but yeah this solved the problem for this feature I need....... :D Thanks!
Facta, non verba.

Re: Hooks?

Reply #5

No, it's not a built in function, I installed the addon from http://addons.elkarte.net/enhancement/Users-Online-Today.html , went to the admin page and picked the "version" of the online I wanted to display.

Let's solve this one, later I'll explain hooks. :P
Bugs creator.
Features destroyer.
Template killer.

Re: Hooks?

Reply #6

Ahh I see the problem now. I installed a fresh Beta 1.1 and yeah it doesn't have that add on.......

I think what happened was that I installed that add on....... and the installation failed (and isn't showing in the installed packages as well), BUT SOMEHOW.... the hooks were installed. :D LOL
Facta, non verba.

Re: Hooks?

Reply #7

at would be a bug, though! :P

Anyway, hooks are "places" in the code where functions defined by addons (or by the "core") can be run to extend functionalities.
For example, let's take: integrate_general_mod_settings
If you search the code, you'l find:
Code: [Select]
call_integration_hook('integrate_general_mod_settings', array(&$config_vars));
in AddonsSettings.controller.php.
What does that mean?
It means that every time the code hits that point, any function "attached" to the "integrate_general_mod_settings" hook will be called passing the variable $config_vars (by reference).
How are functions "attached" to a certain hook?
Two ways:
Code: [Select]
<hook hook="hook_name" file="SOURCEDIR/my_file_to_include.php" function="my_function_to_call" />
in package-info.xml, or calling something like:
Code: [Select]
add_integration_function('hook_name', 'my_function_to_call', 'SOURCEDIR/my_file_to_include.php');
the fist is simply an alternative way to call the second method.

These will add or update an entry in the {db_prefix}settings table adding the relevant data to let Elk know there is a function to call at a certain point in the code.

In 1.1 I also added another way to extend Elk, the things I called "events".

More stuff:
http://www.elkarte.net/community/index.php?topic=2192.0
http://www.elkarte.net/community/index.php?topic=831.msg16689#msg16689 (and following)

Maybe there is more... for sure it should be consolidated on the wiki or something...
Bugs creator.
Features destroyer.
Template killer.

Re: Hooks?

Reply #8


This is what happenes when I install add ons..

Code: [Select]
Connection Problems

Sorry, we were unable to connect to the database. This may be caused by the server being busy. Please try again later.



Ps: still processing what you wrote.. lots to read and understand. :)
Facta, non verba.

Re: Hooks?

Reply #9

Any time you install any addon?
And only when you install addons?
O_O
Bugs creator.
Features destroyer.
Template killer.

Re: Hooks?

Reply #10

Yeah, like the "Users Online Today" mod, it gives that error, and nothing is shown as installed....

BUT the hooks are added already.. and as for the files, they uploaded empty files, but I manually uploaded the right files already.

So yeah it works in the end. :D But only after "hacking" it...
Facta, non verba.