aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2019-11-07 20:21:50 +0100
committerMarc Alexander <admin@m-a-styles.de>2019-11-07 20:21:50 +0100
commitd66960f4d566db163c23bae92f7e276cd1ac2803 (patch)
treeda17a640f96b8e643781a5dc9d34ebe3644277e1
parentMerge branch '3.3.x' (diff)
downloadphpbb-d66960f4d566db163c23bae92f7e276cd1ac2803.tar.gz
phpbb-d66960f4d566db163c23bae92f7e276cd1ac2803.tar.bz2
phpbb-d66960f4d566db163c23bae92f7e276cd1ac2803.zip
[ticket/16204] Remove hooks system
PHPBB3-16204
-rw-r--r--phpBB/common.php4
-rw-r--r--phpBB/includes/functions.php59
-rw-r--r--phpBB/includes/hooks/index.php250
-rw-r--r--phpBB/phpbb/template/base.php22
-rw-r--r--phpBB/phpbb/template/twig/twig.php6
-rw-r--r--phpBB/phpbb/user.php4
6 files changed, 21 insertions, 324 deletions
diff --git a/phpBB/common.php b/phpBB/common.php
index 0870786824..bfdc2c4fd4 100644
--- a/phpBB/common.php
+++ b/phpBB/common.php
@@ -143,10 +143,6 @@ if (@is_file($phpbb_root_path . $config['exts_composer_vendor_dir'] . '/autoload
require_once($phpbb_root_path . $config['exts_composer_vendor_dir'] . '/autoload.php');
}
-// Add own hook handler
-require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
-$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
-
/* @var $phpbb_hook_finder \phpbb\hook\finder */
$phpbb_hook_finder = $phpbb_container->get('hook_finder');
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 0a3cb26041..21aabf6006 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -1514,7 +1514,7 @@ function tracking_unserialize($string, $max_depth = 3)
*/
function append_sid($url, $params = false, $is_amp = true, $session_id = false, $is_route = false)
{
- global $_SID, $_EXTRA_URL, $phpbb_hook, $phpbb_path_helper;
+ global $_SID, $_EXTRA_URL, $phpbb_path_helper;
global $phpbb_dispatcher;
if ($params === '' || (is_array($params) && empty($params)))
@@ -1561,18 +1561,6 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false,
return $append_sid_overwrite;
}
- // The following hook remains for backwards compatibility, though use of
- // the event above is preferred.
- // Developers using the hook function need to globalise the $_SID and $_EXTRA_URL on their own and also handle it appropriately.
- // They could mimic most of what is within this function
- if (!empty($phpbb_hook) && $phpbb_hook->call_hook(__FUNCTION__, $url, $params, $is_amp, $session_id))
- {
- if ($phpbb_hook->hook_return(__FUNCTION__))
- {
- return $phpbb_hook->hook_return_result(__FUNCTION__);
- }
- }
-
$params_is_array = is_array($params);
// Get anchor
@@ -4543,17 +4531,31 @@ function garbage_collection()
* This function supports hooks.
*
* Note: This function is called after the template has been outputted.
+ *
+ * @return void
*/
function exit_handler()
{
- global $phpbb_hook;
+ global $phpbb_dispatcher;
+
+ $exit_handler_override = false;
- if (!empty($phpbb_hook) && $phpbb_hook->call_hook(__FUNCTION__))
+ /**
+ * This event can either supplement or override the exit_handler() function
+ *
+ * To override this function, the event must set $exit_handler_override to
+ * true to force it to exit directly after calling this event.
+ *
+ * @event core.exit_handler
+ * @var bool exit_handler_override Flag to signify exit is handled elsewhere
+ * @since 4.0.0-a1
+ */
+ $vars = ['exit_handler_override'];
+ extract($phpbb_dispatcher->trigger_event('core.exit_handler', compact($vars)));
+
+ if ($exit_handler_override)
{
- if ($phpbb_hook->hook_return(__FUNCTION__))
- {
- return $phpbb_hook->hook_return_result(__FUNCTION__);
- }
+ return;
}
// As a pre-caution... some setups display a blank page if the flush() is not there.
@@ -4563,25 +4565,6 @@ function exit_handler()
}
/**
-* Handler for init calls in phpBB. This function is called in \phpbb\user::setup();
-* This function supports hooks.
-*/
-function phpbb_user_session_handler()
-{
- global $phpbb_hook;
-
- if (!empty($phpbb_hook) && $phpbb_hook->call_hook(__FUNCTION__))
- {
- if ($phpbb_hook->hook_return(__FUNCTION__))
- {
- return $phpbb_hook->hook_return_result(__FUNCTION__);
- }
- }
-
- return;
-}
-
-/**
* Casts a numeric string $input to an appropriate numeric type (i.e. integer or float)
*
* @param string $input A numeric string.
diff --git a/phpBB/includes/hooks/index.php b/phpBB/includes/hooks/index.php
deleted file mode 100644
index 821242cbf4..0000000000
--- a/phpBB/includes/hooks/index.php
+++ /dev/null
@@ -1,250 +0,0 @@
-<?php
-/**
-*
-* This file is part of the phpBB Forum Software package.
-*
-* @copyright (c) phpBB Limited <https://www.phpbb.com>
-* @license GNU General Public License, version 2 (GPL-2.0)
-*
-* For full copyright and license information, please see
-* the docs/CREDITS.txt file.
-*
-*/
-
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-/**
-* phpBB Hook Class
-*/
-class phpbb_hook
-{
- /**
- * Registered hooks
- */
- var $hooks = array();
-
- /**
- * Results returned by functions called
- */
- var $hook_result = array();
-
- /**
- * internal pointer
- */
- var $current_hook = NULL;
-
- /**
- * Initialize hook class.
- *
- * @param array $valid_hooks array containing the hookable functions/methods
- */
- function __construct($valid_hooks)
- {
- foreach ($valid_hooks as $_null => $method)
- {
- $this->add_hook($method);
- }
-
- if (function_exists('phpbb_hook_register'))
- {
- phpbb_hook_register($this);
- }
- }
-
- /**
- * Register function/method to be called within hook
- * This function is normally called by the modification/application to attach/register the functions.
- *
- * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__)
- * @param mixed $hook The replacement function/method to be called. Passing function name or array with object/class definition
- * @param string $mode Specify the priority/chain mode. 'normal' -> hook gets appended to the chain. 'standalone' -> only the specified hook gets called - later hooks are not able to overwrite this (E_NOTICE is triggered then). 'first' -> hook is called as the first one within the chain. 'last' -> hook is called as the last one within the chain.
- */
- function register($definition, $hook, $mode = 'normal')
- {
- $class = (!is_array($definition)) ? '__global' : $definition[0];
- $function = (!is_array($definition)) ? $definition : $definition[1];
-
- // Method able to be hooked?
- if (isset($this->hooks[$class][$function]))
- {
- switch ($mode)
- {
- case 'standalone':
- if (!isset($this->hooks[$class][$function]['standalone']))
- {
- $this->hooks[$class][$function] = array('standalone' => $hook);
- }
- else
- {
- trigger_error('Hook not able to be called standalone, previous hook already standalone.', E_NOTICE);
- }
- break;
-
- case 'first':
- case 'last':
- $this->hooks[$class][$function][$mode][] = $hook;
- break;
-
- case 'normal':
- default:
- $this->hooks[$class][$function]['normal'][] = $hook;
- break;
- }
- }
- }
-
- /**
- * Calling all functions/methods attached to a specified hook.
- * Called by the function allowing hooks...
- *
- * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__)
- * @return bool False if no hook got executed, true otherwise
- */
- function call_hook($definition)
- {
- $class = (!is_array($definition)) ? '__global' : $definition[0];
- $function = (!is_array($definition)) ? $definition : $definition[1];
-
- if (!empty($this->hooks[$class][$function]))
- {
- // Developer tries to call a hooked function within the hooked function...
- if ($this->current_hook !== NULL && $this->current_hook['class'] === $class && $this->current_hook['function'] === $function)
- {
- return false;
- }
-
- // Call the hook with the arguments attached and store result
- $arguments = func_get_args();
- $this->current_hook = array('class' => $class, 'function' => $function);
- $arguments[0] = &$this;
-
- // Call the hook chain...
- if (isset($this->hooks[$class][$function]['standalone']))
- {
- $this->hook_result[$class][$function] = call_user_func_array($this->hooks[$class][$function]['standalone'], $arguments);
- }
- else
- {
- foreach (array('first', 'normal', 'last') as $mode)
- {
- if (!isset($this->hooks[$class][$function][$mode]))
- {
- continue;
- }
-
- foreach ($this->hooks[$class][$function][$mode] as $hook)
- {
- $this->hook_result[$class][$function] = call_user_func_array($hook, $arguments);
- }
- }
- }
-
- $this->current_hook = NULL;
- return true;
- }
-
- $this->current_hook = NULL;
- return false;
- }
-
- /**
- * Get result from previously called functions/methods for the same hook
- *
- * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__)
- * @return mixed False if nothing returned if there is no result, else array('result' => ... )
- */
- function previous_hook_result($definition)
- {
- $class = (!is_array($definition)) ? '__global' : $definition[0];
- $function = (!is_array($definition)) ? $definition : $definition[1];
-
- if (!empty($this->hooks[$class][$function]) && isset($this->hook_result[$class][$function]))
- {
- return array('result' => $this->hook_result[$class][$function]);
- }
-
- return false;
- }
-
- /**
- * Check if the called functions/methods returned something.
- *
- * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__)
- * @return bool True if results are there, false if not
- */
- function hook_return($definition)
- {
- $class = (!is_array($definition)) ? '__global' : $definition[0];
- $function = (!is_array($definition)) ? $definition : $definition[1];
-
- if (!empty($this->hooks[$class][$function]) && isset($this->hook_result[$class][$function]))
- {
- return true;
- }
-
- return false;
- }
-
- /**
- * Give actual result from called functions/methods back.
- *
- * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__)
- * @return mixed The result
- */
- function hook_return_result($definition)
- {
- $class = (!is_array($definition)) ? '__global' : $definition[0];
- $function = (!is_array($definition)) ? $definition : $definition[1];
-
- if (!empty($this->hooks[$class][$function]) && isset($this->hook_result[$class][$function]))
- {
- $result = $this->hook_result[$class][$function];
- unset($this->hook_result[$class][$function]);
- return $result;
- }
-
- return;
- }
-
- /**
- * Add new function to the allowed hooks.
- *
- * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__)
- */
- function add_hook($definition)
- {
- if (!is_array($definition))
- {
- $definition = array('__global', $definition);
- }
-
- $this->hooks[$definition[0]][$definition[1]] = array();
- }
-
- /**
- * Remove function from the allowed hooks.
- *
- * @param mixed $definition Declaring function (with __FUNCTION__) or class with array(__CLASS__, __FUNCTION__)
- */
- function remove_hook($definition)
- {
- $class = (!is_array($definition)) ? '__global' : $definition[0];
- $function = (!is_array($definition)) ? $definition : $definition[1];
-
- if (isset($this->hooks[$class][$function]))
- {
- unset($this->hooks[$class][$function]);
-
- if (isset($this->hook_result[$class][$function]))
- {
- unset($this->hook_result[$class][$function]);
- }
- }
- }
-}
diff --git a/phpBB/phpbb/template/base.php b/phpBB/phpbb/template/base.php
index d502aceab8..314cdc4796 100644
--- a/phpBB/phpbb/template/base.php
+++ b/phpBB/phpbb/template/base.php
@@ -168,26 +168,4 @@ abstract class base implements template
{
return $this->context->find_key_index($blockname, $key);
}
-
- /**
- * Calls hook if any is defined.
- *
- * @param string $handle Template handle being displayed.
- * @param string $method Method name of the caller.
- */
- protected function call_hook($handle, $method)
- {
- global $phpbb_hook;
-
- if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array('template', $method), $handle, $this))
- {
- if ($phpbb_hook->hook_return(array('template', $method)))
- {
- $result = $phpbb_hook->hook_return_result(array('template', $method));
- return array($result);
- }
- }
-
- return false;
- }
}
diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php
index f322778eda..f0736045de 100644
--- a/phpBB/phpbb/template/twig/twig.php
+++ b/phpBB/phpbb/template/twig/twig.php
@@ -308,12 +308,6 @@ class twig extends \phpbb\template\base
*/
public function display($handle)
{
- $result = $this->call_hook($handle, __FUNCTION__);
- if ($result !== false)
- {
- return $result[0];
- }
-
$this->twig->display($this->get_filename_from_handle($handle), $this->get_template_vars());
return $this;
diff --git a/phpBB/phpbb/user.php b/phpBB/phpbb/user.php
index 21d156e060..60cc85e46c 100644
--- a/phpBB/phpbb/user.php
+++ b/phpBB/phpbb/user.php
@@ -342,10 +342,6 @@ class user extends \phpbb\session
$this->img_lang = $this->lang_name;
- // Call phpbb_user_session_handler() in case external application want to "bend" some variables or replace classes...
- // After calling it we continue script execution...
- phpbb_user_session_handler();
-
/**
* Execute code at the end of user setup
*