aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/docs/hook_system.html')
-rw-r--r--phpBB/docs/hook_system.html887
1 files changed, 887 insertions, 0 deletions
diff --git a/phpBB/docs/hook_system.html b/phpBB/docs/hook_system.html
new file mode 100644
index 0000000000..b23ebab869
--- /dev/null
+++ b/phpBB/docs/hook_system.html
@@ -0,0 +1,887 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en" xml:lang="en">
+<head>
+
+<meta http-equiv="content-type" content="text/html; charset=utf-8" />
+<meta http-equiv="content-style-type" content="text/css" />
+<meta http-equiv="content-language" content="en" />
+<meta http-equiv="imagetoolbar" content="no" />
+<meta name="resource-type" content="document" />
+<meta name="distribution" content="global" />
+<meta name="copyright" content="2007 phpBB Group" />
+<meta name="keywords" content="" />
+<meta name="description" content="Hook System explanation" />
+<title>phpBB3 &bull; Hook System</title>
+
+<style type="text/css">
+/* <![CDATA[ */
+
+/*
+ The original "prosilver" theme for phpBB3
+ Created by subBlue design :: http://www.subBlue.com
+*/
+
+* { margin: 0; padding: 0; }
+
+html { font-size: 100%; height: 100%; margin-bottom: 1px; }
+
+body {
+ font-family: Verdana, Helvetica, Arial, sans-serif;
+ color: #828282;
+ background-color: #FFFFFF;
+ font-size: 12px;
+ margin: 0;
+ padding: 12px 0;
+}
+
+img { border-width: 0; }
+
+p {
+ line-height: 1.3em;
+ font-size: 1.1em;
+ margin-bottom: 1.5em;
+}
+
+hr {
+ border: 0 none #FFFFFF;
+ border-top: 1px solid #CCCCCC;
+ height: 1px;
+ margin: 5px 0;
+ display: block;
+ clear: both;
+}
+
+html, body {
+ color: #536482;
+ background-color: #FFFFFF;
+}
+
+#doc-description h1 {
+ font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
+ margin-right: 200px;
+ color: #FFFFFF;
+ margin-top: 15px;
+ font-weight: bold;
+ font-size: 2em;
+ color: #fff;
+}
+
+h1 {
+ font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
+ font-weight: normal;
+ color: #000;
+ font-size: 2em;
+ margin: 0.8em 0 0.2em 0;
+}
+
+h2 {
+ font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
+ font-weight: normal;
+ color: #28313F;
+ font-size: 1.5em;
+ margin: 0.8em 0 0.2em 0;
+}
+
+h3 {
+ font-family: Arial, Helvetica, sans-serif;
+ font-weight: bold;
+ border-bottom: 1px solid #CCCCCC;
+ margin-bottom: 3px;
+ padding-bottom: 2px;
+ font-size: 1.05em;
+ color: #115098;
+ margin-top: 20px;
+}
+
+.good { color: green; }
+.bad { color: red; }
+
+.version {
+ margin-top: 20px;
+ text-align: left;
+ font-size: 70%;
+ color: #006600;
+ border-top: 1px solid #ccc;
+}
+
+code {
+ color: #006600;
+ font-weight: normal;
+ font-family: 'Courier New', monospace;
+ border-color: #D1D7DC;
+ border-width: 1px;
+ border-style: solid;
+ background-color: #FAFAFA;
+}
+
+#wrap {
+ padding: 0 20px;
+ min-width: 650px;
+}
+
+#simple-wrap {
+ padding: 6px 10px;
+}
+
+#page-body {
+ margin: 4px 0;
+ clear: both;
+}
+
+#page-footer {
+ clear: both;
+}
+
+#logo {
+ float: left;
+ width: auto;
+ padding: 10px 13px 0 10px;
+}
+
+a#logo:hover {
+ text-decoration: none;
+}
+
+#doc-description {
+ float: left;
+ width: 70%;
+}
+
+#doc-description h1 {
+ margin-right: 0;
+}
+
+.headerbar {
+ background: #ebebeb none repeat-x 0 0;
+ color: #FFFFFF;
+ margin-bottom: 4px;
+ padding: 0 5px;
+}
+
+span.corners-top, span.corners-bottom, span.corners-top span, span.corners-bottom span {
+ font-size: 1px;
+ line-height: 1px;
+ display: block;
+ height: 5px;
+ background-repeat: no-repeat;
+}
+
+span.corners-top {
+ background-image: none;
+ background-position: 0 0;
+ margin: 0 -5px;
+}
+
+span.corners-top span {
+ background-image: none;
+ background-position: 100% 0;
+}
+
+span.corners-bottom {
+ background-image: none;
+ background-position: 0 100%;
+ margin: 0 -5px;
+ clear: both;
+}
+
+span.corners-bottom span {
+ background-image: none;
+ background-position: 100% 100%;
+}
+
+.paragraph {
+ padding: 0 10px;
+ margin-bottom: 4px;
+ background-repeat: no-repeat;
+ background-position: 100% 0;
+ background-color: #ECF3F7;
+}
+
+.paragraph:target .content {
+ color: #000000;
+}
+
+.paragraph:target h3 a {
+ color: #000000;
+}
+
+.content {
+ color: #333333;
+}
+
+.content h2, .panel h2 {
+ color: #115098;
+ border-bottom-color: #CCCCCC;
+}
+
+a:link { color: #898989; text-decoration: none; }
+a:visited { color: #898989; text-decoration: none; }
+a:hover { color: #d3d3d3; text-decoration: underline; }
+a:active { color: #d2d2d2; text-decoration: none; }
+
+hr {
+ border-color: #FFFFFF;
+ border-top-color: #CCCCCC;
+}
+
+.menu {
+ background-color: #cadceb;
+}
+
+.headerbar {
+ background-color: #12A3EB;
+ background-image: url("bg_header.gif");
+ color: #FFFFFF;
+}
+
+.panel {
+ background-color: #ECF1F3;
+ color: #28313F;
+}
+
+
+span.corners-top {
+ background-image: url("corners_left.png");
+}
+
+span.corners-top span {
+ background-image: url("corners_right.png");
+}
+
+span.corners-bottom {
+ background-image: url("corners_left.png");
+}
+
+span.corners-bottom span {
+ background-image: url("corners_right.png");
+}
+
+.error {
+ color: #BC2A4D;
+}
+
+a:link { color: #105289; }
+a:visited { color: #105289; }
+a:hover { color: #D31141; }
+a:active { color: #368AD2; }
+
+.paragraph span.corners-top, .paragraph span.corners-bottom {
+ margin: 0 -10px;
+}
+
+.content {
+ padding: 0;
+ line-height: 1.48em;
+ color: #333333;
+}
+
+.content h2, .panel h2 {
+ color: #115098;
+ border-bottom-color: #CCCCCC;
+}
+
+.notice {
+ border-top-color: #CCCCCC;
+}
+
+.codebox {
+ padding: 3px;
+ background-color: #FFFFFF;
+ border: 1px solid #C9D2D8;
+ font-size: 1em;
+ margin-bottom: 10px;
+ display: block;
+ font: 0.9em Monaco, "Andale Mono","Courier New", Courier, mono;
+ line-height: 1.3em;
+}
+
+* html hr { margin: 0; }
+* html span.corners-top, * html span.corners-bottom { background-image: url("corners_left.gif"); }
+* html span.corners-top span, * html span.corners-bottom span { background-image: url("corners_right.gif"); }
+
+.back2top {
+ clear: both;
+ height: 11px;
+ text-align: right;
+}
+
+.content ol {
+ margin-left: 25px;
+}
+
+/* ]]> */
+</style>
+
+</head>
+
+<body id="phpbb" class="section-docs">
+
+<div id="wrap">
+ <a id="top" name="top" accesskey="t"></a>
+ <div id="page-header">
+ <div class="headerbar">
+ <div class="inner"><span class="corners-top"><span></span></span>
+
+ <div id="doc-description">
+ <a href="../index.php" id="logo"><img src="site_logo.gif" alt="" /></a>
+ <h1>Hook System</h1>
+ <p>This is an explanation of how to use the phpBB3 hook system.</p>
+ <p style="display: none;"><a href="#start_here">Skip</a></p>
+ </div>
+
+ <span class="corners-bottom"><span></span></span></div>
+ </div>
+ </div>
+
+ <a name="start_here"></a>
+
+ <div id="page-body">
+
+ <h1>Hook System</h1>
+
+ <div class="paragraph menu">
+ <div class="inner"><span class="corners-top"><span></span></span>
+
+ <div class="content">
+
+ <ol>
+ <li><a href="#intro">Introduction</a></li>
+ <li><a href="#use">Allow hooks in functions/methods</a></li>
+ <li><a href="#register">Registering hooks</a></li>
+ <li><a href="#return">Result returning</a></li>
+ <li><a href="#embed">Embedding your hook files/classes/methods</a></li>
+ <li><a href="#disclaimer">Copyright and disclaimer</a></li>
+ </ol>
+
+ </div>
+
+ <span class="corners-bottom"><span></span></span></div>
+ </div>
+
+ <hr />
+
+ <a name="intro"></a><h2>1. Introduction</h2>
+
+ <div class="paragraph">
+ <div class="inner"><span class="corners-top"><span></span></span>
+
+ <div class="content">
+
+<h3>What is it?</h3>
+
+<p>The hook system allows applicaton and mod developers to hook into phpBB's or their own functions.</p>
+
+<h3>Pre-defined hookable phpBB3 functions</h3>
+
+<p>In phpBB3 there are four functions you are able to hook into with your custom functions:</p>
+
+<p><code>phpbb_user_session_handler();</code> which is called within user::setup after the session and the user object is correctly initialized.<br />
+<code>append_sid($url, $params = false, $is_amp = true, $session_id = false);</code> which is called for building urls (appending the session id)<br />
+<code>$template-&gt;display($handle, $include_once = true);</code> which is called directly before outputting the (not-yet-compiled) template.<br />
+<code>exit_handler();</code> which is called at the very end of phpBB3's execution.</p>
+
+<p>There are also valid external constants you may want to use if you embed phpBB3 into your application:</p>
+
+<div class="codebox"><pre>
+PHPBB_MSG_HANDLER (overwrite message handler)
+PHPBB_DB_NEW_LINK (overwrite new_link parameter for sql_connect)
+PHPBB_ROOT_PATH (overwrite $phpbb_root_path)
+PHPBB_ADMIN_PATH (overwrite $phpbb_admin_path)
+PHPBB_USE_BOARD_URL_PATH (use generate_board_url() for image paths instead of $phpbb_root_path)
+</pre></div>
+
+<p>If the <code>PHPBB_USE_BOARD_URL_PATH</code> constant is set to true, phpBB uses generate_board_url() (this will return the boards url with the script path included) on all instances where web-accessible images are loaded. The exact locations are:</p>
+
+<ul>
+ <li>/includes/session.php - user::img()</li>
+ <li>/includes/functions_content.php - smiley_text()</li>
+</ul>
+
+<p>Path locations for the following template variables are affected by this too:</p>
+
+<ul>
+ <li>{T_THEME_PATH} - styles/xxx/theme</li>
+ <li>{T_TEMPLATE_PATH} - styles/xxx/template</li>
+ <li>{T_SUPER_TEMPLATE_PATH} - styles/xxx/template</li>
+ <li>{T_IMAGESET_PATH} - styles/xxx/imageset</li>
+ <li>{T_IMAGESET_LANG_PATH} - styles/xxx/imageset/yy</li>
+ <li>{T_IMAGES_PATH} - images/</li>
+ <li>{T_SMILIES_PATH} - $config['smilies_path']/</li>
+ <li>{T_AVATAR_PATH} - $config['avatar_path']/</li>
+ <li>{T_AVATAR_GALLERY_PATH} - $config['avatar_gallery_path']/</li>
+ <li>{T_ICONS_PATH} - $config['icons_path']/</li>
+ <li>{T_RANKS_PATH} - $config['ranks_path']/</li>
+ <li>{T_UPLOAD_PATH} - $config['upload_path']/</li>
+ <li>{T_STYLESHEET_LINK} - styles/xxx/theme/stylesheet.css (or link to style.php if css is parsed dynamically)</li>
+ <li>New template variable {BOARD_URL} for the board url + script path.</li>
+</ul>
+
+
+ </div>
+
+ <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
+
+ <span class="corners-bottom"><span></span></span></div>
+ </div>
+
+ <a name="use"></a><h2>2. Allow hooks in functions/methods</h2>
+
+ <div class="paragraph">
+ <div class="inner"><span class="corners-top"><span></span></span>
+
+ <div class="content">
+
+<p>The following examples explain how phpBB3 utilize the in-build hook system. You will be more interested in registering your hooks, but showing you this may help you understand the system better along the way.</p>
+
+<p>First of all, this is how a function need to be layed out if you want to allow it to be hookable...</p>
+
+<div class="codebox"><pre>
+function my_own_function($my_first_parameter, $my_second_parameter)
+{
+ global $phpbb_hook;
+
+ if ($phpbb_hook-&gt;call_hook(__FUNCTION__, $my_first_parameter, $my_second_parameter))
+ {
+ if ($phpbb_hook-&gt;hook_return(__FUNCTION__))
+ {
+ return $phpbb_hook-&gt;hook_return_result(__FUNCTION__);
+ }
+ }
+
+ [YOUR CODE HERE]
+}
+</pre></div>
+
+<p>Above, the call_hook function should always be mapping your function call... in regard to the number of parameters passed.</p>
+
+<p>This is how you could make a method being hookable...</p>
+
+<div class="codebox"><pre>
+class my_hookable_object
+{
+ function hook_me($my_first_parameter, $my_second_parameter)
+ {
+ global $phpbb_hook;
+
+ if ($phpbb_hook-&gt;call_hook(array(__CLASS__, __FUNCTION__), $my_first_parameter, $my_second_parameter))
+ {
+ if ($phpbb_hook-&gt;hook_return(array(__CLASS__, __FUNCTION__)))
+ {
+ return $phpbb_hook-&gt;hook_return_result(array(__CLASS__, __FUNCTION__));
+ }
+ }
+
+ [YOUR CODE HERE]
+ }
+}
+</pre></div>
+
+<p>The only difference about calling it is the way you define the first parameter. For a function it is only <code>__FUNCTION__</code>, for a method it is <code>array(__CLASS__, __FUNCTION__)</code>. In PHP4 __CLASS__ is always returning the class in lowercase.</p>
+
+<p>Now, in phpBB there are some pre-defined hooks available, but how do you make your own hookable function available (and therefore allowing others to hook into it)? For this, there is the add_hook() method:</p>
+
+<div class="codebox"><pre>
+// Adding your own hookable function:
+$phpbb_hook-&gt;add_hook('my_own_function');
+
+// Adding your own hookable method:
+$phpbb_hook-&gt;add_hook(array('my_hookable_object', 'hook_me'));
+</pre></div>
+
+<p>You are also able to remove the possibility of hooking a function/method by calling <code>$phpbb_hook-&gt;remove_hook()</code> with the same parameters as add_hook().<br />
+This comes in handy if you want to force some hooks not to be called - at all.</p>
+
+ </div>
+
+ <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
+
+ <span class="corners-bottom"><span></span></span></div>
+ </div>
+
+ <a name="register"></a><h2>3. Registering hooks</h2>
+
+ <div class="paragraph">
+ <div class="inner"><span class="corners-top"><span></span></span>
+
+ <div class="content">
+
+ <h3>Registering hooks</h3>
+
+<p>Now to actually defining your functions which should be called. For this we take the append_sid() function as an example (this function is able to be hooked by default). We create two classes, one being static and a function:</p>
+
+<div class="codebox"><pre>
+class my_append_sid_class
+{
+ // Our functions
+ function my_append_sid(&amp;$hook, $url, $params = false, $is_amp = true, $session_id = false)
+ {
+ // Get possible previous results
+ $result = $hook-&gt;previous_hook_result('append_sid');
+
+ return $result['result'] . '&lt;br /&gt;And i was the second one.';
+ }
+}
+
+// Yet another class :o
+class my_second_append_sid_class
+{
+ function my_append_sid(&amp;$hook, $url, $params = false, $is_amp = true, $session_id = false)
+ {
+ // Get possible previous results
+ $result = $hook-&gt;previous_hook_result('append_sid');
+
+ echo $result['result'] . '&lt;br /&gt;I was called as the third one.';
+ }
+}
+
+// And a normal function
+function my_append_sid(&amp;$hook, $url, $params = false, $is_amp = true, $session_id = false)
+{
+ // Get possible previous results
+ $result = $hook-&gt;previous_hook_result('append_sid');
+
+ return 'I was called as the first one';
+}
+
+// Initializing the second class
+$my_second_append_sid_class = new my_second_append_sid_class();
+</pre></div>
+
+<p>Make sure you add the same parameters to your function as is defined for the hookable function with one exception: The first variable is always <code>&amp;$hook</code>... this is the hook object itself you are able to operate on.</p>
+
+<p>Now we register the hooks one by one with the <code>$phpbb_hook-&gt;register()</code> method:</p>
+
+<div class="codebox"><pre>
+// Now, we register our append_sid &quot;replacements&quot; in a stacked way...
+// Registering the function (this is called first)
+$phpbb_hook-&gt;register('append_sid', 'my_append_sid');
+
+// Registering the first class
+$phpbb_hook-&gt;register('append_sid', array('my_append_sid_class', 'my_append_sid'));
+$phpbb_hook-&gt;register('append_sid', array(&amp;$my_second_append_sid_class, 'my_append_sid'));
+</pre></div>
+
+<p>With this you are even able to make your own functions that are already hooked itself being hooked again...</p>
+
+<div class="codebox"><pre>
+// Registering hook, which will be called
+$phpbb_hook-&gt;register('append_sid', 'my_own_append_sid');
+
+// Add hook to our called hook function
+$phpbb_hook-&gt;add_hook('my_own_append_sid');
+
+// Register added hook
+$phpbb_hook-&gt;register('my_own_append_sid', 'also_my_own_append_sid');
+</pre></div>
+
+ <h3>Special treatment/chains</h3>
+
+ <p>The <code>register</code> method is able to take a third argument to specify a special 'chain' mode. The valid modes are <code>first</code>, <code>last</code> and <code>standalone</code></p>
+
+ <p><code>$phpbb_hook-&gt;register('append_sid', 'my_own_append_sid', 'first')</code> would make sure that the function is called in the beginning of the chain. It is possible that more than one function is called within the first block - here the FIFO principle is used.</p>
+
+ <p><code>$phpbb_hook-&gt;register('append_sid', 'my_own_append_sid', 'last')</code> would make sure that the function is called at the very end of the chain. It is possible that more than one function is called within the last block - here the FIFO principle is used.</p>
+
+ <p><code>$phpbb_hook-&gt;register('append_sid', 'my_own_append_sid', 'standalone')</code> makes sure only the defined function is called. All other functions are removed from the chain and no other functions are added to it later on. If two applications try to trigger the standalone mode a PHP notice will be printed and the second function being discarded.</p>
+
+ <h3>Only allowing hooks for some objects</h3>
+
+ <p>Because the hook system is not able to differate between initialized objects and only operate on the class, you need to solve this on the code level.</p>
+
+ <p>One possibility would be to use a property:</p>
+
+ <div class="codebox"><pre>
+class my_hookable_object
+{
+ function blabla()
+ {
+ }
+}
+
+class my_hookable_object2 extends my_hookable_object
+{
+ var $call_hook = true;
+
+ function hook_me($my_first_parameter, $my_second_parameter)
+ {
+ if ($this-&gt;call_hook)
+ {
+ global $phpbb_hook;
+
+ if ($phpbb_hook-&gt;call_hook(array(__CLASS__, __FUNCTION__), $my_first_parameter, $my_second_parameter))
+ {
+ if ($phpbb_hook-&gt;hook_return(array(__CLASS__, __FUNCTION__)))
+ {
+ return $phpbb_hook-&gt;hook_return_result(array(__CLASS__, __FUNCTION__));
+ }
+ }
+ }
+
+ return 'not hooked';
+ }
+}
+
+function hooking(&amp;$hook, $first, $second)
+{
+ return 'hooked';
+}
+
+$first_object = new my_hookable_object2();
+$second_object = new my_hookable_object2();
+
+$phpbb_hook-&gt;add_hook(array('my_hookable_object2', 'hook_me'));
+
+$phpbb_hook-&gt;register(array('my_hookable_object2', 'hook_me'), 'hooking');
+
+// Do not call the hook for $first_object
+$first_object-&gt;call_hook = false;
+
+echo $first_object-&gt;hook_me('first', 'second') . '&lt;br /&gt;';
+echo $second_object-&gt;hook_me('first', 'second') . '&lt;br /&gt;';
+</pre></div>
+
+<p>OUTPUT:</p>
+
+<div class="codebox"><pre>
+not hooked
+hooked
+</pre></div>
+
+ <p>A different possibility would be using a function variable (which could be left out on passing the function variables to the hook):</p>
+
+ <div class="codebox"><pre>
+class my_hookable_object
+{
+ function blabla()
+ {
+ }
+}
+
+class my_hookable_object2 extends my_hookable_object
+{
+ function hook_me($my_first_parameter, $my_second_parameter, $hook_me = true)
+ {
+ if ($hook_me)
+ {
+ global $phpbb_hook;
+
+ if ($phpbb_hook-&gt;call_hook(array(__CLASS__, __FUNCTION__), $my_first_parameter, $my_second_parameter))
+ {
+ if ($phpbb_hook-&gt;hook_return(array(__CLASS__, __FUNCTION__)))
+ {
+ return $phpbb_hook-&gt;hook_return_result(array(__CLASS__, __FUNCTION__));
+ }
+ }
+ }
+
+ return 'not hooked';
+ }
+}
+
+function hooking(&amp;$hook, $first, $second)
+{
+ return 'hooked';
+}
+
+$first_object = new my_hookable_object2();
+$second_object = new my_hookable_object2();
+
+$phpbb_hook-&gt;add_hook(array('my_hookable_object2', 'hook_me'));
+
+$phpbb_hook-&gt;register(array('my_hookable_object2', 'hook_me'), 'hooking');
+
+echo $first_object-&gt;hook_me('first', 'second', false) . '&lt;br /&gt;';
+echo $second_object-&gt;hook_me('first', 'second') . '&lt;br /&gt;';
+ </pre></div>
+
+ <p>OUTPUT:</p>
+
+ <div class="codebox"><pre>
+not hooked
+hooked
+ </pre></div>
+
+ </div>
+
+ <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
+
+ <span class="corners-bottom"><span></span></span></div>
+ </div>
+
+ <a name="return"></a><h2>4. Result returning</h2>
+
+ <div class="paragraph">
+ <div class="inner"><span class="corners-top"><span></span></span>
+
+ <div class="content">
+
+<p>Generally, the distinction has to be made if a function returns the result obtained from the called function or continue the execution. Based on the needs of the application this may differ. Therefore, the function returns the results only if the called hook function is returning a result.</p>
+
+<h3>Case 1 - Returning the result</h3>
+
+<p>Imagine the following function supporting hooks:</p>
+
+<div class="codebox"><pre>
+function append_sid($url, $params = false, $is_amp = true, $session_id = false)
+{
+ global $_SID, $_EXTRA_URL, $phpbb_hook;
+
+ // Developers using the hook function need to globalise the $_SID and $_EXTRA_URL on their own and also handle it appropiatly.
+ // They could mimick most of what is within this function
+ if ($phpbb_hook-&gt;call_hook(__FUNCTION__, $url, $params, $is_amp, $session_id))
+ {
+ if ($phpbb_hook-&gt;hook_return(__FUNCTION__))
+ {
+ return $phpbb_hook-&gt;hook_return_result(__FUNCTION__);
+ }
+ }
+
+ [...]
+}
+</pre></div>
+
+<p>Now, the following function is yours. Since you return a value, the append_sid() function itself is returning it as is:</p>
+
+<div class="codebox"><pre>
+// The function called
+function my_append_sid(&amp;$hook, $url, $params = false, $is_amp = true, $session_id = false)
+{
+ // Get possible previous results
+ $result = $hook-&gt;previous_hook_result('append_sid');
+
+ return 'Since i return something the append_sid() function will return my result.';
+}
+</pre></div>
+
+<p>To be able to get the results returned from functions higher in the change the <code>previous_hook_result()</code> method should always be used, it returns an <code>array('result' => [your result])</code> construct.</p>
+
+<h3>Case 2 - Not Returning any result</h3>
+
+<p>Sometimes applications want to return nothing and therefore force the underlying function to continue it's execution:</p>
+
+<div class="codebox"><pre>
+function append_sid($url, $params = false, $is_amp = true, $session_id = false)
+{
+ global $_SID, $_EXTRA_URL, $phpbb_hook;
+
+ // Developers using the hook function need to globalise the $_SID and $_EXTRA_URL on their own and also handle it appropiatly.
+ // They could mimick most of what is within this function
+ if ($phpbb_hook-&gt;call_hook(__FUNCTION__, $url, $params, $is_amp, $session_id))
+ {
+ if ($phpbb_hook-&gt;hook_return(__FUNCTION__))
+ {
+ return $phpbb_hook-&gt;hook_return_result(__FUNCTION__);
+ }
+ }
+
+ [...]
+}
+
+// The function called
+function my_append_sid(&amp;$hook, $url, $params = false, $is_amp = true, $session_id = false)
+{
+ // Get possible previous results
+ $result = $hook-&gt;previous_hook_result('append_sid');
+
+ [...]
+
+ // I only rewrite some variables, but return nothing. Therefore, the append_sid() function will not return my (non)result.
+}
+</pre></div>
+
+<p>Please Note: The decision to return or not return is solely made of the very last function call within the hook chain. An example:</p>
+
+<div class="codebox"><pre>
+// The function called
+function my_append_sid(&amp;$hook, $url, $params = false, $is_amp = true, $session_id = false)
+{
+ // Get possible previous results
+ $result = $hook-&gt;previous_hook_result('append_sid');
+
+ // $result is not filled
+
+ return 'FILLED';
+}
+
+// This function is registered too and gets executed after my_append_sid()
+function my_own_append_sid(&amp;$hook, $url, $params = false, $is_amp = true, $session_id = false)
+{
+ $result = $hook->previous_hook_result('append_sid');
+
+ // $result is actually filled with $result['result'] = 'FILLED'
+ // But i return nothing, therefore append_sid() continues it's execution.
+}
+
+// The way both functions are registered.
+$phpbb_hook->register('append_sid', 'my_append_sid');
+$phpbb_hook->register('append_sid', 'my_own_append_sid');
+</pre></div>
+
+ </div>
+
+ <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
+
+ <span class="corners-bottom"><span></span></span></div>
+ </div>
+
+ <a name="embed"></a><h2>5. Embedding your hook files/classes/methods</h2>
+
+ <div class="paragraph">
+ <div class="inner"><span class="corners-top"><span></span></span>
+
+ <div class="content">
+
+<p>There are basically two methods you are able to choose from:</p>
+
+<p>1) Add a file to includes/hooks/. The file need to be prefixed by <code>hook_</code>. This file is included within common.php, you are able to register your hooks, include other files or functions, etc. It is advised to only include other files if needed (within a function call for example).</p>
+
+<p>Please be aware that you need to purge your cache within the ACP to make your newly placed file available to phpBB3.</p>
+
+<p>2) The second method is meant for those wanting to wrap phpBB3 without placing a custom file to the hooks directory. This is mostly done by including phpBB's files within the application file. To be able to register your hooks you need to create a function within your application:</p>
+
+<div class="codebox"><pre>
+// My function which gets executed within the hooks constuctor
+function phpbb_hook_register(&amp;$hook)
+{
+ $hook-&gt;register('append_sid', 'my_append_sid');
+}
+
+[...]
+</pre></div>
+
+<p>You should get the idea. ;)</p>
+
+ </div>
+
+ <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
+
+ <span class="corners-bottom"><span></span></span></div>
+ </div>
+
+ <a name="disclaimer"></a><h2>6. Copyright and disclaimer</h2>
+
+ <div class="paragraph">
+ <div class="inner"><span class="corners-top"><span></span></span>
+
+ <div class="content">
+
+ <p>This application is opensource software released under the <a href="http://opensource.org/licenses/gpl-license.php">GPL</a>. Please see source code and the docs directory for more details. This package and its contents are Copyright (c) 2000, 2002, 2005, 2007 <a href="http://www.phpbb.com/">phpBB Group</a>, All Rights Reserved.</p>
+
+ </div>
+
+ <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
+
+ <span class="corners-bottom"><span></span></span></div>
+ </div>
+
+ <div id="page-footer">
+ <div class="version">$Id$</div>
+ </div>
+</div></div>
+
+<div>
+ <a id="bottom" name="bottom" accesskey="z"></a>
+</div>
+
+</body>
+</html>