Advertisement:

Author Topic: [2.1] Hooks in 2.1  (Read 55852 times)

Offline Matthew K.

  • SMF Super Hero
  • *******
  • Posts: 12,430
  • Gender: Male
    • matthew.kerle on Facebook
    • @matthew_kerle on Twitter
Re: Hooks in 2.1
« Reply #20 on: October 23, 2011, 11:25:07 PM »
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.
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?

Offline live627

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,265
  • Gender: Male
  • Cat: Destroy!
    • live627 on Facebook
    • live627 on GitHub
    • live627 on LinkedIn
    • @live627 on Twitter
    • livemods
Re: Hooks in 2.1
« Reply #21 on: October 24, 2011, 01:48:41 AM »
So then the hooks would be cached? I still think that storing them in smf_settings will save on a query per page load.
Try not to become a man of success, but rather try to become a man of value.
- Albert Einstein

Offline Matthew K.

  • SMF Super Hero
  • *******
  • Posts: 12,430
  • Gender: Male
    • matthew.kerle on Facebook
    • @matthew_kerle on Twitter
Re: Hooks in 2.1
« Reply #22 on: October 24, 2011, 11:08:30 AM »
Adding a query doesn't automatically mean performance decrease. If optimized well it can do just fine.

Offline Fustrate

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,474
  • Gender: Male
  • Controller of the rum budget
    • Fustrate on GitHub
    • @Fustrate on Twitter
    • Fustrate
Re: Hooks in 2.1
« Reply #23 on: October 24, 2011, 12:36:15 PM »
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

Online feline

  • SMF Hero
  • ******
  • Posts: 1,618
  • Gender: Female
    • Product developer site
Re: Hooks in 2.1
« Reply #24 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 ...
PortaMx has released the official release of PortaMx-Forum 1.2 with a built in SEF engine, a integrated Portal and full support for the EU Cookie Law.
Follow us on our Community


Offline Matthew K.

  • SMF Super Hero
  • *******
  • Posts: 12,430
  • Gender: Male
    • matthew.kerle on Facebook
    • @matthew_kerle on Twitter
Re: Hooks in 2.1
« Reply #25 on: October 24, 2011, 04:25:38 PM »
Well right, that's how it works now. I just think that it should be moved from a row, to a table.
caching of the hooks itself is no problem, but the hook code must run on each page load, else dynamic hooks don't work ...

Offline Joshua Dickerson

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,775
  • Gender: Male
    • joshuaadickerson on GitHub
    • joshuaadickerson on LinkedIn
Re: Hooks in 2.1
« Reply #26 on: December 14, 2011, 11:52:09 PM »
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.
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?

Offline live627

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,265
  • Gender: Male
  • Cat: Destroy!
    • live627 on Facebook
    • live627 on GitHub
    • live627 on LinkedIn
    • @live627 on Twitter
    • livemods
Re: Hooks in 2.1
« Reply #27 on: December 15, 2011, 06:00:59 PM »
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?
Try not to become a man of success, but rather try to become a man of value.
- Albert Einstein

Offline Joshua Dickerson

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,775
  • Gender: Male
    • joshuaadickerson on GitHub
    • joshuaadickerson on LinkedIn
Re: Hooks in 2.1
« Reply #28 on: December 15, 2011, 07:02:58 PM »
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.
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?

Offline Joshua Dickerson

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,775
  • Gender: Male
    • joshuaadickerson on GitHub
    • joshuaadickerson on LinkedIn
Re: Hooks in 2.1
« Reply #29 on: December 15, 2011, 07:06:11 PM »
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?

Offline live627

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,265
  • Gender: Male
  • Cat: Destroy!
    • live627 on Facebook
    • live627 on GitHub
    • live627 on LinkedIn
    • @live627 on Twitter
    • livemods
Re: Hooks in 2.1
« Reply #30 on: December 15, 2011, 07:51:57 PM »
loadFile('require_once_for_plugins_my_ass.php', 'live627:my_plgin');
Same format for loadTemplate?
Try not to become a man of success, but rather try to become a man of value.
- Albert Einstein

Offline Joshua Dickerson

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,775
  • Gender: Male
    • joshuaadickerson on GitHub
    • joshuaadickerson on LinkedIn
Re: Hooks in 2.1
« Reply #31 on: December 15, 2011, 08:14:34 PM »
Code: [Select]
/**
 * 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')
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?

Offline mkress

  • Jr. Member
  • **
  • Posts: 126
  • Gender: Male
    • markus.kress on Facebook
    • mkress on GitHub
    • @mkress on Twitter
    • augs-burg.de joomla templates
Re: [2.1] Hooks in 2.1
« Reply #32 on: April 15, 2012, 01:28:31 PM »
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...

Offline IchBin™

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,115
  • Gender: Male
  • I don't speak German.
    • IchBin.us
Re: [2.1] Hooks in 2.1
« Reply #33 on: April 16, 2012, 04:51:04 PM »
There are literally over a 100 hooks in the next version of SMF already.
Brad "IchBin™" Grow        TinyPortal        Themes
Coding Guidelines       

Offline Joshua Dickerson

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,775
  • Gender: Male
    • joshuaadickerson on GitHub
    • joshuaadickerson on LinkedIn
Re: [2.1] Hooks in 2.1
« Reply #34 on: April 17, 2012, 09:00:21 AM »
I think it is somewhere around 250 new hooks.
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?

Offline inter

  • Jr. Member
  • **
  • Posts: 276
  • Gender: Male
    • interlab on GitHub
Re: [2.1] Hooks in 2.1
« Reply #35 on: August 31, 2012, 03:52:54 AM »
 8)

Who.php:

find:
Code: [Select]
$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:
Code: [Select]
$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']));
« Last Edit: September 03, 2012, 06:52:02 AM by Inter »
Sorry for my English

Offline emanuele

  • SMF Super Hero
  • *******
  • Posts: 14,156
  • Gender: Male
  • THERE'S JUST ME
Re: Hooks in 2.1
« Reply #36 on: August 31, 2012, 04:32:35 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.

Offline inter

  • Jr. Member
  • **
  • Posts: 276
  • Gender: Male
    • interlab on GitHub
Re: [2.1] Hooks in 2.1
« Reply #37 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

Who.php
Code: [Select]
$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

Offline emanuele

  • SMF Super Hero
  • *******
  • Posts: 14,156
  • Gender: Male
  • THERE'S JUST ME
Re: [2.1] Hooks in 2.1
« Reply #38 on: September 04, 2012, 03:44:20 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.

Offline inter

  • Jr. Member
  • **
  • Posts: 276
  • Gender: Male
    • interlab on GitHub
Re: [2.1] Hooks in 2.1
« Reply #39 on: September 04, 2012, 05:05:48 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