Topic: What are "hooks"?
What the title says
You are not logged in. Please login or register.
PunBB Forums → PunBB 1.3 extensions → What are "hooks"?
What the title says
Yes, please
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 © 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 :-)
Oh, I get it now Thanks!
@anatoly:
Hint: Nice tutorial, but it's not manifex.xml neither manifest.php, but manifest.xml
You should edit it.
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... ))
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
You're supposed to look for them on the PunBB files.
Is there a list of hooks somewhere?
You can create your own: http://fluxbb.org/forums/post/18531/#p18531
There really is no point in having a hooks list when you don't know where they are (line-wise).
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.
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
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.
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.
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...
PunBB Forums → PunBB 1.3 extensions → What are "hooks"?
Powered by PunBB, supported by Informer Technologies, Inc.