Advertisement:

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

Offline Suki

  • Customizer
  • SMF Super Hero
  • *
  • Posts: 15,088
  • Kaizoku Jotei
    • MissAllSunday on GitHub
    • SMF mods
[2.1] Hooks in 2.1
« on: October 05, 2011, 04:13:04 PM »
Hi all, the Devs are considering an overhaul for the existing hooks system

We will like to hear all opinions about this, ways to improve the usage, handling, structure, design, scope, removal from database, etc.

Please share your thoughts on this :)
« Last Edit: January 19, 2012, 04:42:31 PM by Norv »
Look at them. They're just asking for it. Maybe the human race deserves to be wiped out.

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
« Reply #1 on: October 05, 2011, 05:50:19 PM »
Overhaul how, exactly?
Try not to become a man of success, but rather try to become a man of value.
- Albert Einstein

Offline ziycon

  • Support Specialist
  • SMF Hero
  • *
  • Posts: 2,667
  • Gender: Male
Re: Hooks
« Reply #2 on: October 05, 2011, 05:53:06 PM »
LDAP...............................

 I know a good few people that would like this authentication option, I was going to write it myself but haven't had the time to look at how to write mod packages for SMF just yet due to life and work getting in the way.

Offline Illori

  • Project Manager
  • SMF Master
  • *
  • Posts: 48,078
Re: Hooks
« Reply #3 on: October 05, 2011, 05:54:55 PM »
and how does LDAP apply to the overhaul of hooks?

Offline Suki

  • Customizer
  • SMF Super Hero
  • *
  • Posts: 15,088
  • Kaizoku Jotei
    • MissAllSunday on GitHub
    • SMF mods
Re: Hooks
« Reply #4 on: October 05, 2011, 05:56:00 PM »
Overhaul how, exactly?

in general, in every possible way, in every possible approach.

An example, some of us are thinking in hooks having its own table.
find a better way to handle hooks on uninstall/upgrading
finding a solution on the current system where you load a file everytime.

things like that.
Look at them. They're just asking for it. Maybe the human race deserves to be wiped out.

Offline ziycon

  • Support Specialist
  • SMF Hero
  • *
  • Posts: 2,667
  • Gender: Male
Re: Hooks
« Reply #5 on: October 05, 2011, 06:01:05 PM »
and how does LDAP apply to the overhaul of hooks?
Maybe I picked it up wrong or it means different things depending what community your in but I would interpret it to be considered the extension of existing functions/functionality to allow new options or features.

Please correct me if I'm wrong in the sense of SMF :)

Offline Illori

  • Project Manager
  • SMF Master
  • *
  • Posts: 48,078
Re: Hooks
« Reply #6 on: October 05, 2011, 06:25:55 PM »
we mean the already built in hooks, that mod authors can use when creating mods.

http://wiki.simplemachines.org/smf/Integration_hooks

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
« Reply #7 on: October 05, 2011, 06:27:46 PM »
Overhaul how, exactly?

in general, in every possible way, in every possible approach.

An example, some of us are thinking in hooks having its own table.
find a better way to handle hooks on uninstall/upgrading
finding a solution on the current system where you load a file everytime.

things like that.
Oh.... so not only the core hook functions, but also the package manager.


Perhaps, in package-info, blocks could be used for hooks, like

<install>
    <hook point="pre_load">my_plugin</hook>
</install>

Same for uninstall.

I saw Sinan mention he wanted hooks to also call files. I'd say to do it. Then such pseudo-hooks could be removed like admin_include, pre_include,  theme_include.

I don't know about hooks living in their own table. Where they are seems fine to me. They could even be a serialized array instead of CSV which could also help in storing multiple values such as file, class, function.

I remember hearing that Matt put a mod with tons of hooks for the core on the team boards before he left. In anticipation of that, I did not suggest any new hooks (even when Norv asked me to :P)
Try not to become a man of success, but rather try to become a man of value.
- Albert Einstein

Offline Suki

  • Customizer
  • SMF Super Hero
  • *
  • Posts: 15,088
  • Kaizoku Jotei
    • MissAllSunday on GitHub
    • SMF mods
Re: Hooks
« Reply #8 on: October 05, 2011, 06:38:35 PM »
Yes there is some ideas as to provide another tag for hooks.

Yes all the hooks SD left are now on 2.1

I will vote for having a separate table for hooks, settings is already too bloated IMO, plus it will make handling hooks a little better.

We also discuss about having an admin page where you can enable/disable or otherwise administrate hooks
Look at them. They're just asking for it. Maybe the human race deserves to be wiped out.

Offline Bugo

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 1,453
  • Gender: Male
    • dragomano on GitHub
    • @dragomano on Twitter
    • Russian translations for SMF mods
What about new hooks for SMF 2.x
« Reply #9 on: October 14, 2011, 05:48:51 AM »
integrate_message (Display.php)
integrate_member_data (Load.php)
integrate_attachments (Display.template.php)
integrate_message_buttons (Display.template.php)
« Last Edit: October 30, 2011, 06:42:42 PM by Bugo »

Offline feline

  • SMF Hero
  • ******
  • Posts: 1,618
  • Gender: Female
    • Product developer site
Re: What about new hooks for SMF 2.x
« Reply #10 on: October 14, 2011, 07:24:05 AM »
Add a hook in Subs for custom menu functions AFTER the load from cache:

	
call_integration_hook('integrate_dynamic_buttons', array(&$menu_buttons));

	
$context['menu_buttons'] = $menu_buttons;
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 Bugo

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 1,453
  • Gender: Male
    • dragomano on GitHub
    • @dragomano on Twitter
    • Russian translations for SMF mods
Re: What about new hooks for SMF 2.x
« Reply #11 on: October 14, 2011, 07:50:06 AM »
Add a hook in Subs for custom menu functions AFTER the load from cache:

	
call_integration_hook('integrate_dynamic_buttons', array(&$menu_buttons));

	
$context['menu_buttons'] = $menu_buttons;

Yes, it'a great idea.

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: What about new hooks for SMF 2.x
« Reply #12 on: October 14, 2011, 07:44:44 PM »
And this (Oh, you ask what this technocrap is. A unified diff!)

Code: [Select]
Index: Load.php
===================================================================
@@ -945,57 +984,49 @@
 
  if ($set == 'normal')
  {
- $select_columns = '
- IFNULL(lo.log_time, 0) AS is_online, IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type,
- mem.signature, mem.personal_text, mem.location, mem.gender, mem.avatar, mem.id_member, mem.member_name,
- mem.real_name, mem.email_address, mem.hide_email, mem.date_registered, mem.website_title, mem.website_url,
- mem.birthdate, mem.member_ip, mem.member_ip2, mem.icq, mem.aim, mem.yim, mem.msn, mem.posts, mem.last_login,
- mem.karma_good, mem.id_post_group, mem.karma_bad, mem.lngfile, mem.id_group, mem.time_offset, mem.show_online,
- mem.buddy_list, mg.online_color AS member_group_color, IFNULL(mg.group_name, {string:blank_string}) AS member_group,
- pg.online_color AS post_group_color, IFNULL(pg.group_name, {string:blank_string}) AS post_group, mem.is_activated, mem.warning,
- CASE WHEN mem.id_group = 0 OR mg.stars = {string:blank_string} THEN pg.stars ELSE mg.stars END AS stars' . (!empty($modSettings['titlesEnable']) ? ',
- mem.usertitle' : '');
- $select_tables = '
- LEFT JOIN {db_prefix}log_online AS lo ON (lo.id_member = mem.id_member)
- LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
- LEFT JOIN {db_prefix}membergroups AS pg ON (pg.id_group = mem.id_post_group)
- LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)';
+ $select_columns = array(
+ 'IFNULL(lo.log_time, 0) AS is_online', 'IFNULL(a.id_attach, 0) AS id_attach', 'a.filename', 'a.attachment_type', 'mem.signature', 'mem.personal_text', 'mem.location', 'mem.gender', 'mem.avatar', 'mem.id_member', 'mem.member_name', 'mem.real_name', 'mem.email_address', 'mem.hide_email', 'mem.date_registered', 'mem.website_title', 'mem.website_url', 'mem.birthdate', 'mem.member_ip', 'mem.member_ip2', 'mem.icq', 'mem.aim', 'mem.yim', 'mem.msn', 'mem.posts', 'mem.last_login', 'mem.karma_good', 'mem.id_post_group', 'mem.karma_bad', 'mem.lngfile', 'mem.id_group', 'mem.time_offset', 'mem.show_online', 'mem.buddy_list', 'mg.online_color AS member_group_color', 'IFNULL(mg.group_name, {string:blank_string}) AS member_group', 'pg.online_color AS post_group_color', 'IFNULL(pg.group_name, {string:blank_string}) AS post_group', 'mem.is_activated', 'mem.warning', 'CASE WHEN mem.id_group = 0 OR mg.stars = {string:blank_string} THEN pg.stars ELSE mg.stars END AS stars',
+ );
+ if (!empty($modSettings['titlesEnable']))
+ $select_columns[] = 'mem.usertitle';
+ $select_tables = array(
+ 'LEFT JOIN {db_prefix}log_online AS lo ON (lo.id_member = mem.id_member)',
+ 'LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)',
+ 'LEFT JOIN {db_prefix}membergroups AS pg ON (pg.id_group = mem.id_post_group)',
+ 'LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)',
+ );
  }
  elseif ($set == 'profile')
  {
- $select_columns = '
- IFNULL(lo.log_time, 0) AS is_online, IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type,
- mem.signature, mem.personal_text, mem.location, mem.gender, mem.avatar, mem.id_member, mem.member_name,
- mem.real_name, mem.email_address, mem.hide_email, mem.date_registered, mem.website_title, mem.website_url,
- mem.openid_uri, mem.birthdate, mem.icq, mem.aim, mem.yim, mem.msn, mem.posts, mem.last_login, mem.karma_good,
- mem.karma_bad, mem.member_ip, mem.member_ip2, mem.lngfile, mem.id_group, mem.id_theme, mem.buddy_list,
- mem.pm_ignore_list, mem.pm_email_notify, mem.pm_receive_from, mem.time_offset' . (!empty($modSettings['titlesEnable']) ? ', mem.usertitle' : '') . ',
- mem.time_format, mem.secret_question, mem.is_activated, mem.additional_groups, mem.smiley_set, mem.show_online,
- mem.total_time_logged_in, mem.id_post_group, mem.notify_announcements, mem.notify_regularity, mem.notify_send_body,
- mem.notify_types, lo.url, mg.online_color AS member_group_color, IFNULL(mg.group_name, {string:blank_string}) AS member_group,
- pg.online_color AS post_group_color, IFNULL(pg.group_name, {string:blank_string}) AS post_group, mem.ignore_boards, mem.warning,
- CASE WHEN mem.id_group = 0 OR mg.stars = {string:blank_string} THEN pg.stars ELSE mg.stars END AS stars, mem.password_salt, mem.pm_prefs';
- $select_tables = '
- LEFT JOIN {db_prefix}log_online AS lo ON (lo.id_member = mem.id_member)
- LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
- LEFT JOIN {db_prefix}membergroups AS pg ON (pg.id_group = mem.id_post_group)
- LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)';
+ $select_columns = array(
+ 'IFNULL(lo.log_time, 0) AS is_online', 'IFNULL(a.id_attach, 0) AS id_attach', 'a.filename', 'a.attachment_type', 'mem.signature', 'mem.personal_text', 'mem.location', 'mem.gender', 'mem.avatar', 'mem.id_member', 'mem.member_name', 'mem.real_name', 'mem.email_address', 'mem.hide_email', 'mem.date_registered', 'mem.website_title', 'mem.website_url', 'mem.openid_uri', 'mem.birthdate', 'mem.icq', 'mem.aim', 'mem.yim', 'mem.msn', 'mem.posts', 'mem.last_login', 'mem.karma_good', 'mem.karma_bad', 'mem.member_ip', 'mem.member_ip2', 'mem.lngfile', 'mem.id_group', 'mem.id_theme', 'mem.buddy_list', 'mem.pm_ignore_list', 'mem.pm_email_notify', 'mem.pm_receive_from', 'mem.time_offset', 'mem.time_format', 'mem.secret_question', 'mem.is_activated', 'mem.additional_groups', 'mem.smiley_set', 'mem.show_online', 'mem.total_time_logged_in', 'mem.id_post_group', 'mem.notify_announcements', 'mem.notify_regularity', 'mem.notify_send_body', 'mem.notify_types', 'lo.url', 'mg.online_color AS member_group_color', 'IFNULL(mg.group_name, {string:blank_string}) AS member_group', 'pg.online_color AS post_group_color', 'IFNULL(pg.group_name, {string:blank_string}) AS post_group', 'mem.ignore_boards', 'mem.warning', 'CASE WHEN mem.id_group = 0 OR mg.stars = {string:blank_string} THEN pg.stars ELSE mg.stars END AS stars', 'mem.password_salt', 'mem.pm_prefs',
+ );
+ if (!empty($modSettings['titlesEnable']))
+ $select_columns[] = 'mem.usertitle';
+ $select_tables = array(
+ 'LEFT JOIN {db_prefix}log_online AS lo ON (lo.id_member = mem.id_member)',
+ 'LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)',
+ 'LEFT JOIN {db_prefix}membergroups AS pg ON (pg.id_group = mem.id_post_group)',
+ 'LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)',
+ );
  }
  elseif ($set == 'minimal')
  {
- $select_columns = '
- mem.id_member, mem.member_name, mem.real_name, mem.email_address, mem.hide_email, mem.date_registered,
- mem.posts, mem.last_login, mem.member_ip, mem.member_ip2, mem.lngfile, mem.id_group';
- $select_tables = '';
+ $select_columns = array(
+ 'mem.id_member', 'mem.member_name', 'mem.real_name', 'mem.email_address', 'mem.hide_email', 'mem.date_registered', 'mem.posts', 'mem.last_login', 'mem.member_ip', 'mem.member_ip2', 'mem.lngfile', 'mem.id_group',
+ );
+ $select_tables = array();
  }
  else
  trigger_error('loadMemberData(): Invalid member data set \'' . $set . '\'', E_USER_WARNING);
 
+ call_hook('load_member_context', array(&$set, $users, &$select_columns, &$select_tables));
+
  if (!empty($users))
  {
  // Load the member's data.
  $request = $smcFunc['db_query']('', '
- SELECT' . $select_columns . '
+ SELECT ' . implode(', ', $select_columns) . '
  FROM {db_prefix}members AS mem' . $select_tables . '
  WHERE mem.' . ($is_name ? 'member_name' : 'id_member') . (count($users) == 1 ? ' = {' . ($is_name ? 'string' : 'int') . ':users}' : ' IN ({' . ($is_name ? 'array_string' : 'array_int') . ':users})'),
  array(
@@ -1268,6 +1299,7 @@
  }
  }
 
+ call_hook('load_member_context', array(&$memberContext[$user]));
  return true;
 }
 
@@ -1319,6 +1351,8 @@
  // Robots shouldn't be logging in or registering.  So, they aren't a bot.  Better to be wrong than sorry (or people won't be able to log in!), anyway.
  if ((isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('login', 'login2', 'register'))) || !$user_info['is_guest'])
  $context['browser']['possibly_robot'] = false;
+
+ call_hook('detect_browser', array(&$context['browser']));
 }
 
 // Load a theme, by ID.
Try not to become a man of success, but rather try to become a man of value.
- Albert Einstein

Offline Suki

  • Customizer
  • SMF Super Hero
  • *
  • Posts: 15,088
  • Kaizoku Jotei
    • MissAllSunday on GitHub
    • SMF mods
Re: What about new hooks for SMF 2.x
« Reply #13 on: October 14, 2011, 10:30:08 PM »
See, this is what I was talking about here  ;)
Look at them. They're just asking for it. Maybe the human race deserves to be wiped out.

Offline Suki

  • Customizer
  • SMF Super Hero
  • *
  • Posts: 15,088
  • Kaizoku Jotei
    • MissAllSunday on GitHub
    • SMF mods
Re: Hooks
« Reply #14 on: October 15, 2011, 08:56:12 PM »
oh! and magically they were merged :P
Look at them. They're just asking for it. Maybe the human race deserves to be wiped out.

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 #15 on: October 19, 2011, 01:24:55 PM »
No need for Menu Hooks if Menu Editor is implemented. Mods can then simply add their buttons to the database, and then reload the menu cache file.
Add a hook in Subs for custom menu functions AFTER the load from cache:

	
call_integration_hook('integrate_dynamic_buttons', array(&$menu_buttons));

	
$context['menu_buttons'] = $menu_buttons;


I agree that the hooks system should be rethought out. Definitely it's own table, that's just the smart thing to do, in my opinion.

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 #16 on: October 19, 2011, 08:14:13 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?
Try not to become a man of success, but rather try to become a man of value.
- Albert Einstein

Offline 4Kstore

  • SMF Hero
  • ******
  • Posts: 4,298
  • Gender: Male
    • agustintari on Facebook
    • @agustintarifa on Twitter
    • SSIMPLE TEAM PAGE
Re: Hooks in 2.1
« Reply #17 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.
the hooks are a good tool but you have to use and above all we must teach use this tool

integrate_message (Display.php)
integrate_member_data (Load.php)
integrate_attachments (Display.template.php)
integrate_message_buttons (Display.template.php)


x2 agree
¡¡NEW MOD: Sparkles User Names!!!

Offline KensonPlays

  • SMF Hero
  • ******
  • Posts: 4,297
Re: Hooks in 2.1
« Reply #18 on: October 23, 2011, 03:50:26 AM »
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?
Performance, then elegance. And yes hooks (more) would be nice.

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 #19 on: October 23, 2011, 05:33:25 PM »
Performance, then elegance. And yes hooks (more) would be nice.
Exactly! ESPECIALLY when bootstrapping.
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 #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

Offline 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 &copy; 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 &copy; 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

Offline inter

  • Jr. Member
  • **
  • Posts: 276
  • Gender: Male
    • interlab on GitHub
Re: [2.1] Hooks in 2.1
« Reply #40 on: April 08, 2013, 07:19:13 AM »
integrate_clean_cache

for example if you use library which uses own folders of a cache which you too would like to clear in case of forum cache flush

Subs.php

Find:
Code: [Select]
// Invalidate cache, to be sure!
// ... as long as Load.php can be modified, anyway.
@touch($sourcedir . '/' . 'Load.php');
clearstatcache();

Replace:
Code: [Select]
// Invalidate cache, to be sure!
// ... as long as Load.php can be modified, anyway.
@touch($sourcedir . '/' . 'Load.php');

        call_integration_hook('integrate_clean_cache');

clearstatcache();
Sorry for my English

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 #41 on: April 08, 2013, 11:15:08 AM »
That's a good one. Would you mind tracking it as a feature enhancement at https://github.com/SimpleMachines/SMF2.1/issues ? Thanks
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 Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,051
    • Arantor on GitHub
Re: [2.1] Hooks in 2.1
« Reply #42 on: April 08, 2013, 12:19:59 PM »
Um, why is it a good idea? The whole point of the cache subsystem is that its content is not supposed to be relied upon to exist and plugins actually shouldn't be manually dumping stuff into the cache anyway (because that also means if they are, they're not using proper backends that aren't I/O bound, they should be using cache_put_data and cache_get_data which safely abstract away what actual backend is in use)
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline inter

  • Jr. Member
  • **
  • Posts: 276
  • Gender: Male
    • interlab on GitHub
Re: [2.1] Hooks in 2.1
« Reply #43 on: April 09, 2013, 05:53:40 AM »
there are libraries which create temporal files
(the generated files for fast operation of library which are updated only in case of physical deleting manually)
here I also thought that would be quite good if they could be cleared together with the general cache flush of a forum
Sorry for my English

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,051
    • Arantor on GitHub
Re: [2.1] Hooks in 2.1
« Reply #44 on: April 09, 2013, 09:39:44 AM »
Then it should be the library taking care of it itself in the first place, not requiring a hook for that purpose. Or it should be using the proper facilities. Either way, I don't see the need for the hook.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline emanuele

  • SMF Super Hero
  • *******
  • Posts: 14,156
  • Gender: Male
  • THERE'S JUST ME


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.