From 0ca7ad66dc8d9173394e0c5fb7e8393977de22ed Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 9 May 2011 22:01:54 -0400 Subject: [PATCH] [feature/template-engine] Refactor hook logic into a separate function. PHPBB3-9726 --- phpBB/includes/template.php | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php index c03b87b13c..9a030ffd35 100644 --- a/phpBB/includes/template.php +++ b/phpBB/includes/template.php @@ -195,14 +195,10 @@ class phpbb_template */ public function display($handle, $include_once = true) { - global $phpbb_hook; - - if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, __FUNCTION__), $handle, $include_once, $this)) + $result = $this->call_hook($handle, $include_once); + if ($result !== false) { - if ($phpbb_hook->hook_return(array(__CLASS__, __FUNCTION__))) - { - return $phpbb_hook->hook_return_result(array(__CLASS__, __FUNCTION__)); - } + return $result[0]; } /* @@ -228,6 +224,27 @@ class phpbb_template } } + /** + * Calls hook if any is defined. + * @param string $handle Template handle being displayed. + * @param bool $include_once Allow multiple inclusions + */ + private function call_hook($handle, $include_once) + { + global $phpbb_hook; + + if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, __FUNCTION__), $handle, $include_once, $this)) + { + if ($phpbb_hook->hook_return(array(__CLASS__, __FUNCTION__))) + { + $result = $phpbb_hook->hook_return_result(array(__CLASS__, __FUNCTION__)); + return array($result); + } + } + + return false; + } + /** * Obtains language array. * This is either lang property of global $user object, or if