News and Announcements

  • entries
    500
  • comments
    13,839
  • views
    4,816,700

Contributors to this blog

IP.Board 3.1.0 Dev Update: Hook System

Entry posted

5,165 views

In IP.Board 3, we introduced the hook system, the goal of which was to cut down on file edits from modifications and make modifications easier to install. We designed the system to be as flexible as possible, primarily using the HTML logic feature to create hooks in virtually every portion of the output generated. However, we knew there were still cases where a file edit was needed, to access certain data or to reach any area of the board that was not a template or an action file.

One of our primary goals with IP.Board 3.1, is to expand the hook system to further reduce the need for file edits, as well as to make installing them even easier. We've read all the feedback on hooks from modification authors and are incorporating as much of it as possible into 3.1. Here's a quick rundown of the changes that we have mode so far:

New Hook Types

Our first goal was to extend the hook system to cover areas of the forum that are not currently accessible to hooks. Toward that end, we are introducing two new hook file types to address this issue:

Data Hooks

Modifications often need access to add their own data to insert/update queries that are run by IPB, at the moment that data is not accessible and must be queried separately and then hook has to run another insert/update query. To address this issue, we have added a new hook file type called a Data Hook. This type of hook allows you to access certain data arrays before they are inserted into the database. For example, you can create a hook that will receive the $post array before it is inserted into the posts table, this will give your hook a chance to add any data it needs or modify any data being saved. Technically, a Data Hook does not even have to modify the actual data array, you can use them as a simple code execution point as well.

Unlike Template Hooks, which are essentially generated automatically, Data hooks are manually specified in the code, so if you have suggestions on where you would like to see these placed, please reply to this blog post and let us know. At the moment, data hooks are used in the posting library, the messenger library, and some areas of the profile screen.

Library Hooks

There are many classes used within IPB that are inaccessible to hooks, as they are not actions or templates. However, it is often useful to be able to modify these classes with your own methods or to add on to existing methods. This leads to the second type of hook file that we are adding in 3.1, the Library Hook. This type of hook will allow you to extend the libraries that we use throughout IPB, a common example would be class_forums. This works in exactly the same way as an action overloader, your hook will extend the library you have selected and allow you to add to it or replace method calls with your own. Like the action overloaders, you will need to remember to call the parent method from your overloaded method.

In order for a library hook to work, we have to update the require call that includes that library. We're going through the code to try and find as many of these require calls as possible, but during beta you should check any includes that you are interested in extending to make sure we haven't missed them.

Other Changes

Hooks in AJAX requests

In the current release, any output returned via AJAX is not passed through the hook system. This has been changed in 3.1, now all returned output is properly run through the hooks system, allowing you to hook into any AJAX generated output.

Export CSS Files

There is a new option when exporting a hook that will allow you to specify CSS files that is used by that hook. The CSS files will be included in the hook xml and then imported along with the hook and cached to the file system.

Access Function Data

One of the most frequent requests we've seen is for a way to access template function data, with IP.Board 3.1 this will now be possible. Any active hooks within a template function will be able to access the function data through a special class property called functionData. To save resources, this data is not saved for any template function that does not contain active hooks. Here's an example of how to access function data inside of the topicViewTemplate function:

Function Declaration:


function topicViewTemplate($forum, $topic, $post_data, $displayData) {

All of this data will be accessible to your hook via $functionData:


$this->registry->output->getTemplate('topic')->functionData['topicViewTemplate']['forum']

$this->registry->output->getTemplate('topic')->functionData['topicViewTemplate']['topic']



Wrapping up

We've also made quite a few minor tweaks throughout the hook system, these changes include updates to the ACP interface, performance enhancements, a toggle to quickly disable/enable all hooks, changing hook positions without IN_DEV enabled, and more. If you have any suggestions regarding these changes or the existing hook system, please do not hesitate to reply to this entry and let us know about them. We're very excited to see what our community will do with these new features!




22 Comments

Posted

WOHOOOOOOOOOOOOO! FINALLY!! Great news Josh!! Keep goin'! :)

Collin1000, Zammbi and Darken like this
  • Loading...

Share this comment


Link to comment

Posted

Very nice, everyday is like Christmas around here lately :)

  • Loading...

Share this comment


Link to comment

Posted

Lots of improvements here that will be greatly appreciated. :thumbsup:

Darken likes this
  • Loading...

Share this comment


Link to comment

Posted

oooh nice addition!

  • Loading...

Share this comment


Link to comment

Posted

Quick question: Hooks created for 3.0.x will be fully compatible with 3.1.x or we can await some err... problems?

  • Loading...

Share this comment


Link to comment

Posted

Hooks created with 3.0.X should work just fine

  • Loading...

Share this comment


Link to comment

Posted

They do work fine, my test board has a few different test hooks and they are still working now. :)

  • Loading...

Share this comment


Link to comment

Posted

For non-programmers, show us how this is beneficial or how it might improve our boards?

  • Loading...

Share this comment


Link to comment

Posted

Basically means those who use hooks for modification will be able to make better hooks :)

Invisiοnist likes this
  • Loading...

Share this comment


Link to comment

Posted

Nice! ,, Glad we can use Hooks with AJAX requests now!,,, and the Function Data Awesome!!
Good work

  • Loading...

Share this comment


Link to comment

Posted

This entire post: :thumbsup:

  • Loading...

Share this comment


Link to comment

Posted

This is good stuff--I've created several mods for my forum that I haven't yet tried packaging into Hooks and sharing. Anything that makes the forum even more extensible without requiring direct modification of the software is a Good Thing. :D

..Al

  • Loading...

Share this comment


Link to comment

Posted

I'm liking the sound off all of this.

:thumbsup:

  • Loading...

Share this comment


Link to comment

Posted

Though I don't understand much of it, I like the sound of it. :)

  • Loading...

Share this comment


Link to comment

Posted

Sounds great :) If I understood how to work with hooks it would be even better ;)

When I get a day or three spare I will try and learn.

IPB Bob likes this
  • Loading...

Share this comment


Link to comment

Posted

[quote name='InvisionHQ' date='13 January 2010 - 02:02 PM']
I hope in a more simple and intuitive IN_DEV mode.

I have to agree, it's a pain in the butt to set IN_DEV mode up, and good luck if you want to use a custom skin with it (actual documentation for how to setup the masterMap.php file would be a huge boon). I just went through this headache yesterday.

..Al

  • Loading...

Share this comment


Link to comment

Posted

Very Nice!!!

  • Loading...

Share this comment


Link to comment

Posted

IP.Board 3.1: :thumbsup:

  • Loading...

Share this comment


Link to comment

Posted

Please make your controller methods shorter. It would give us more action overload hook points. Like people have already mentioned, the IN_DEV mode is a pain in the butt, that would have to be better documented at least.

  • Loading...

Share this comment


Link to comment

Posted

The main areas I see where I would like data hooks are the forum add/edit forms in the ACP, the member edit form in the ACP, and the member info under their avatar (the userInfoPane information).

  • Loading...

Share this comment


Link to comment

Posted

hi there. i had a request for a new data hook point location. i was actually modifying the side pane in topics with a data hook and wanted to do the same modification to the post side bar in the conversation. i was hoping for a data hook point after:



Is there a chance this could be added?


 			/* Get member data */

			$memberData = $this->fetchTopicParticipants( $topicID, TRUE );


			/* Get reading member's data */

			$readingMemberData = $memberData[ $readingMemberID ];


			/* Fetch topic data */

			$topicData = $this->fetchTopicData( $topicID, FALSE );



this is in the file admin/applications/members/sources/classes/messaging/messengerFunctions.php


to this i edit the $memberData but im sure people could find the $topicData useful as well. So could I request:



 			/* Get member data */

			$memberData = $this->fetchTopicParticipants( $topicID, TRUE );

			IPSLib::doDataHooks( &memberData, 'messengerParticipantMemberData' );

			/* Get reading member's data */

			$readingMemberData = $memberData[ $readingMemberID ];


			/* Fetch topic data */

			$topicData = $this->fetchTopicData( $topicID, FALSE );

IPSLib::doDataHooks( &topicData , 'messengerTopicData' );

  • Loading...

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now