aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2020-01-06 22:03:23 +0100
committerGitHub <noreply@github.com>2020-01-06 22:03:23 +0100
commit2a5c7b1d43e5e0a61b92c9ccdb4918563e3b629d (patch)
tree82a2d5c05f01b62784c6503c616ce2cb5683f5f6
parentMerge branch '3.3.x' (diff)
parent[ticket/16204] Remove mentions of hooks (diff)
downloadphpbb-2a5c7b1d43e5e0a61b92c9ccdb4918563e3b629d.tar.gz
phpbb-2a5c7b1d43e5e0a61b92c9ccdb4918563e3b629d.tar.bz2
phpbb-2a5c7b1d43e5e0a61b92c9ccdb4918563e3b629d.zip
Merge pull request #5731 from marc1706/ticket/16204
[ticket/16204] Remove hooks system
-rw-r--r--phpBB/common.php12
-rw-r--r--phpBB/config/default/container/services.yml1
-rw-r--r--phpBB/config/default/container/services_hook.yml7
-rw-r--r--phpBB/includes/functions.php61
-rw-r--r--phpBB/includes/hooks/index.php250
-rw-r--r--phpBB/phpbb/hook/finder.php91
-rw-r--r--phpBB/phpbb/template/base.php22
-rw-r--r--phpBB/phpbb/template/twig/twig.php6
-rw-r--r--phpBB/phpbb/user.php4
9 files changed, 21 insertions, 433 deletions
diff --git a/phpBB/common.php b/phpBB/common.php
index 9cddf4626b..af2a344de6 100644
--- a/phpBB/common.php
+++ b/phpBB/common.php
@@ -143,18 +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');
-
-foreach ($phpbb_hook_finder->find() as $hook)
-{
- @include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
-}
-
/**
* Main event which is triggered on every page
*
diff --git a/phpBB/config/default/container/services.yml b/phpBB/config/default/container/services.yml
index a7ab26f163..679d3d5eb0 100644
--- a/phpBB/config/default/container/services.yml
+++ b/phpBB/config/default/container/services.yml
@@ -13,7 +13,6 @@ imports:
- { resource: services_files.yml }
- { resource: services_filesystem.yml }
- { resource: services_help.yml }
- - { resource: services_hook.yml }
- { resource: services_http.yml }
- { resource: services_language.yml }
- { resource: services_migrator.yml }
diff --git a/phpBB/config/default/container/services_hook.yml b/phpBB/config/default/container/services_hook.yml
deleted file mode 100644
index 10a84184a0..0000000000
--- a/phpBB/config/default/container/services_hook.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-services:
- hook_finder:
- class: phpbb\hook\finder
- arguments:
- - '%core.root_path%'
- - '%core.php_ext%'
- - '@cache.driver'
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 45a7cb2def..7bde4dbc02 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -1481,7 +1481,6 @@ function tracking_unserialize($string, $max_depth = 3)
/**
* Append session id to url.
-* This function supports hooks.
*
* @param string $url The url the session id needs to be appended to (can have params)
* @param mixed $params String or array of additional url parameters
@@ -1502,7 +1501,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)))
@@ -1549,18 +1548,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
@@ -4517,20 +4504,33 @@ function garbage_collection()
/**
* Handler for exit calls in phpBB.
-* 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;
- if (!empty($phpbb_hook) && $phpbb_hook->call_hook(__FUNCTION__))
+ $exit_handler_override = false;
+
+ /**
+ * 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.
@@ -4540,25 +4540,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/hook/finder.php b/phpBB/phpbb/hook/finder.php
deleted file mode 100644
index f5a68a1370..0000000000
--- a/phpBB/phpbb/hook/finder.php
+++ /dev/null
@@ -1,91 +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.
-*
-*/
-
-namespace phpbb\hook;
-
-/**
-* The hook finder locates installed hooks.
-*/
-class finder
-{
- /**
- * @var \phpbb\cache\driver\driver_interface
- */
- protected $cache;
-
- /**
- * @var string
- */
- protected $phpbb_root_path;
-
- /**
- * @var string
- */
- protected $php_ext;
-
- /**
- * Creates a new finder instance.
- *
- * @param string $phpbb_root_path Path to the phpbb root directory
- * @param string $php_ext php file extension
- * @param \phpbb\cache\driver\driver_interface $cache A cache instance or null
- */
- public function __construct($phpbb_root_path, $php_ext, \phpbb\cache\driver\driver_interface $cache = null)
- {
- $this->phpbb_root_path = $phpbb_root_path;
- $this->cache = $cache;
- $this->php_ext = $php_ext;
- }
-
- /**
- * Finds all hook files.
- *
- * @param bool $cache Whether the result should be cached
- * @return array An array of paths to found hook files
- */
- public function find($cache = true)
- {
- if (!defined('DEBUG') && $cache && $this->cache)
- {
- $hook_files = $this->cache->get('_hooks');
- if ($hook_files !== false)
- {
- return $hook_files;
- }
- }
-
- $hook_files = array();
-
- // Now search for hooks...
- $dh = @opendir($this->phpbb_root_path . 'includes/hooks/');
-
- if ($dh)
- {
- while (($file = readdir($dh)) !== false)
- {
- if (strpos($file, 'hook_') === 0 && substr($file, -strlen('.' . $this->php_ext)) === '.' . $this->php_ext)
- {
- $hook_files[] = substr($file, 0, -(strlen($this->php_ext) + 1));
- }
- }
- closedir($dh);
- }
-
- if ($cache && $this->cache)
- {
- $this->cache->put('_hooks', $hook_files);
- }
-
- return $hook_files;
- }
-}
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
*