Topic: What are "hooks"?

What the title says smile

Re: What are "hooks"?

You mean the hook from hooking as it is used in PunBB 1.3 extension system or the word hook itself?
Should I explain PunBB hooks in details?

Carpe diem

Re: What are "hooks"?

Yes, please smile

Re: What are "hooks"?

1. Extension developer puts his PHP code into manifest.xml file.
He specifies the name of the hook, where he wants his code to be executed.
E.g. I want to print out the list of extensions installed in ft_about_end hook:

        <hook id="ft_about_end" priority="10"><![CDATA[
if (!defined('PUN_EXTENSIONS_USED') && !empty($pun_extensions_used))
{
    define('PUN_EXTENSIONS_USED', 1);
    echo '<p id="extensions-used">Currently used extensions: '.implode(', ', $pun_extensions_used).'. Copyright &copy; 2008 <a href="http://punbb.informer.com/">PunBB</a></p>';
}
        ]]></hook>

(pun_bbcode/manifest.xml)
You may find this hook in footer.php.

2. When you install the extension, PunBB parses its' manifest.xml and places the code for each hook into database. After extension installation, you have pairs (hook_id, code) in DB.

3. Before PunBB generates the page, it caches the code for each hook. It iterates through the pairs (hook_id, code) and creates the PHP array containing all the codes for every hook used by all the extensions enabled. This array is being included on every page hit. You may find the cache file in /cache/cache_hooks.php. Different extensions may use the same hook. Their codes are joined in the cache then (ordered by priority, if given in manifest.xml).

4. PunBB developers has placed hook calls in the code like this:

($hook = get_hook('ft_about_end')) ? eval($hook) : null;

When PHP finds this line, it looks through the cache for the code for the hook name given. E.g. $forum_hooks['ft_about_end'].

5. If the code for the hook is present. It is being evaluated in eval($hook). This means that the code is virtually inserted just in the place of hook. The code has the same variable scope as the hook: you may use all the variables around, create new ones and s.o. (This differs from function call.)

That's it.
Ooh...

UPDATE: Fixed mistakes noted by lie2815 :-)

Carpe diem

Re: What are "hooks"?

Oh, I get it now smile Thanks!

Re: What are "hooks"?

@anatoly:

Hint: Nice tutorial, but it's not manifex.xml neither manifest.php, but manifest.xml

You should edit it.

FluxBB - v1.4.8

Re: What are "hooks"?

lie2815 wrote:

Hint: Nice tutorial, but it's not manifex.xml neither manifest.php, but manifest.xml

Fixed. Thanks.
(it was late evening after long working day... ))

Carpe diem

Re: What are "hooks"?

Is there a list of hooks somewhere? For the moment, I search for them using Google "PunBB [hookname]", which gives decent results but I suppose there is maybe a more efficient way to find them big_smile

Re: What are "hooks"?

You're supposed to look for them on the PunBB files.

10

Re: What are "hooks"?

patheticcockroach wrote:

Is there a list of hooks somewhere?

You can create your own: http://fluxbb.org/forums/post/18531/#p18531

Bert Garcia - When all you have is a keyboard

11

Re: What are "hooks"?

There really is no point in having a hooks list when you don't know where they are (line-wise).

12

Re: What are "hooks"?

Garciat wrote:

There really is no point in having a hooks list when you don't know where they are (line-wise).

I haven't created a Xref for PunBB 1.3, but here is one from the FluxBB 1.3 svn:
http://phpxref.com/xref/fluxbb/_functions/get_hook.html

I do have a PunBB Xref: http://phpxref.com/xref/punbb/ - but it's based off of the 1.2 line.

Bert Garcia - When all you have is a keyboard

Re: What are "hooks"?

Garciat wrote:

There really is no point in having a hooks list when you don't know where they are (line-wise).

Lol, actually I meant a list of hooks telling me where they are. Thought it was obvious wink

hcgtv wrote:

I haven't created a Xref for PunBB 1.3, but here is one from the FluxBB 1.3 svn:
http://phpxref.com/xref/fluxbb/_functions/get_hook.html

Thanks... but I think I'll stick with Google for the moment.

Re: What are "hooks"?

Hooking covers a range of techniques used to alter or augment the behavior of an operating system, of applications, or of other software components by intercepting function calls or messages or events passed between software components.

15 (edited by FlashT 2010-06-02 15:28)

Re: What are "hooks"?

And how do i generate my own content and not add it? I mean replace the original content in hook and not add something...

For example I would like to make extention that displays forum list in different way than original...