News:

Wondering if this will always be free?  See why free is better.

Main Menu

[2.1] Hooks in 2.1

Started by Suki, October 05, 2011, 04:13:04 PM

Previous topic - Next topic

Matthew K.

Having a separate table, does not just outright mean it's going to decrease performance. A loaded row, compared to an optimized, indexed, table that was thought through well, and then fed out and cached smartly, is actually possible to INCREASE performance.
Quote from: live627 on October 19, 2011, 08:14:13 PM
Quote from: Labradoodle-360 on October 19, 2011, 01:24:55 PM
Definitely it's own table, that's just the smart thing to do, in my opinion.
Why?


Consider: Which is more important: performance, or elegance?

live627

So then the hooks would be cached? I still think that storing them in smf_settings will save on a query per page load.

Matthew K.

Adding a query doesn't automatically mean performance decrease. If optimized well it can do just fine.

Fustrate

There's no reason not to cache the hooks - it's not like they change every page load or two.
Steven Hoffman
Former Team Member, 2009-2012

feline

caching of the hooks itself is no problem, but the hook code must run on each page load, else dynamic hooks don't work ...

Matthew K.

Well right, that's how it works now. I just think that it should be moved from a row, to a table.
Quote from: feline on October 24, 2011, 04:18:25 PM
caching of the hooks itself is no problem, but the hook code must run on each page load, else dynamic hooks don't work ...

Joshua Dickerson

I just wanted to make a note that the next version will feature a LOT more hooks. Along with that, there is a function loadFile() which has a hook in it before loading of the file and after loading of the file. You can set your plugin to make use of that to completely change any file (as in not include it). Hopefully that doesn't get too much use, but it gives you an idea of how hooks will be used.

Along with that, CSS and JS are loaded through a function as well. So, you can do the same thing.

SlammedDime also gave us a ton of hooks which I implemented a while back.
Come work with me at Promenade Group



Need help? See the wiki. Want to help SMF? See the wiki!

Did you know you can help develop SMF? See us on Github.

How have you bettered the world today?

live627

Nifty! So are plugins or mods  still going  to be installed like now, where package-info dictates where files get copied to, or will they be run from a dedicated folder?

Joshua Dickerson

hmm... hadn't thought much about it. It is an interesting idea - only allow plugins to be placed in a certain directory. Although that is very prone to abuse, it would keep things clean. I like it. Need to add that as a bug report.
Come work with me at Promenade Group



Need help? See the wiki. Want to help SMF? See the wiki!

Did you know you can help develop SMF? See us on Github.

How have you bettered the world today?

Joshua Dickerson

Come work with me at Promenade Group



Need help? See the wiki. Want to help SMF? See the wiki!

Did you know you can help develop SMF? See us on Github.

How have you bettered the world today?

live627

loadFile('require_once_for_plugins_my_ass.php', 'live627:my_plgin');
Same format for loadTemplate?

Joshua Dickerson

/**
* Load a file
* @param string $filename
* @param string $directory_type = 'source' (always lowercase) or used as a directory if no type is found
*/
function loadFile($filename, $type = 'source')
Come work with me at Promenade Group



Need help? See the wiki. Want to help SMF? See the wiki!

Did you know you can help develop SMF? See us on Github.

How have you bettered the world today?

mkress

I think its very important to have a list of available and installed/used hooks in admin area.


Also there have to be much more hooks on several positions in smf...

IchBin™

There are literally over a 100 hooks in the next version of SMF already.
IchBin™        TinyPortal

Joshua Dickerson

I think it is somewhere around 250 new hooks.
Come work with me at Promenade Group



Need help? See the wiki. Want to help SMF? See the wiki!

Did you know you can help develop SMF? See us on Github.

How have you bettered the world today?

inter

#35
 8)

Who.php:

find:
$context['copyrights'] = array(
'smf' => sprintf($forum_copyright, $forum_version),

/* Modification Authors:  You may add a copyright statement to this array for your mods.
Copyright statements should be in the form of a value only without a array key.  I.E.:
'Some Mod by Thantos © 2010',
$txt['some_mod_copyright'],
*/
'mods' => array(
),
);


replace:
$context['copyrights'] = array(
'smf' => sprintf($forum_copyright, $forum_version),

/* Modification Authors:  You may add a copyright statement to this array for your mods.
Copyright statements should be in the form of a value only without a array key.  I.E.:
'Some Mod by Thantos © 2010',
$txt['some_mod_copyright'],
*/
'mods' => array(
),
);
call_integration_hook('modification_authors', array(&$context['copyrights']['mods']));
Sorry for my English

emanuele

Quote from: 4Kstore on October 23, 2011, 03:03:40 AM
For me the use of the hook will exist if there is good documentation on them, so that has to be good translations and good examples of their use.
That is a good point.
But there is a problem: write documentation takes time. I just did a search in the code for "call_integration_hook" and I found 248 matches, considering the function itself, a couple of places where SMF checks if the function exists, some hooks that are used in multiple places, I think we are about 220 unique hooks (*but* some of them are "generic" so that a single hook can cover multiple things (like lists and menus), so in the end the real number of things you can change with hooks in 2.1 is difficult to estimate).

At the moment hooks documentation is on the wiki, but this solution doesn't scale so well. It is okay for a bunch of hooks (15/30), but with the numbers we will have in 2.1 it will be very difficult to document each and every hook that way, so we are considering using comments in the code itself (that will probably be something will be cleaned up during the beta/rc phase and any help would be highly appreciated of course!)

Of course write examples is "easier". There are already few on the wiki (e.g. how to add a custom action) and anybody can (and is encouraged) to write new ones (don't worry if your English is not perfect, we have K@ that can translate anything it into gibberish! :P).

tl;dr: if you want to write some documentation feel free to edit the wiki and if in the process of writing you would have any doubt, feel free to post in the SMF Documentation Help board!


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

inter

to do inquiries in a cycle it is impossible  :-\
I think that it is necessary to alter this code

Who.php
$data = array();
foreach ($url_list as $k => $url)
{
...

// Maybe the action is integrated into another system?
if (count($integrate_actions = call_integration_hook('integrate_whos_online', array($actions))) > 0)
{
foreach ($integrate_actions as $integrate_action)
{
if (!empty($integrate_action))
{
$data[$k] = $integrate_action;
break;
}
}
}
}
Sorry for my English

emanuele

Quote from: Inter on September 04, 2012, 02:33:14 AM
to do inquiries in a cycle it is impossible  :-\
I think that it is necessary to alter this code
Why it should be changed? And how?
Could you please provide an example?
If you think it's a bug, please open a topic in Bug Reports. ;)


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

inter

Quote from: emanuele on September 04, 2012, 03:44:20 AM
Quote from: Inter on September 04, 2012, 02:33:14 AM
to do inquiries in a cycle it is impossible  :-\
I think that it is necessary to alter this code
Why it should be changed? And how?
Could you please provide an example?
If you think it's a bug, please open a topic in Bug Reports. ;)

link
Sorry for my English

Advertisement: