From 6613884a60cdf399cd8a3a908bc44247c646bb1b Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 11:37:27 -0400 Subject: [PATCH 01/21] [feature/add_events] Added core.posting_refresh event PHPBB3-9550 --- phpBB/posting.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/phpBB/posting.php b/phpBB/posting.php index a17578e343..77b3c8c861 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -39,6 +39,19 @@ $delete = (isset($_POST['delete'])) ? true : false; $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false; $refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load || $preview) ? true : false; + +/** +* This event allows you to alter the $refresh boolean variable. +* +* If $refresh is true the posting form retains previously submitted form data +* +* @event core.posting_refresh +* @var bool refresh Whether or not to retain previously submitted data +* @since 3.1-A1 +*/ +$vars = array('refresh'); +extract($phpbb_dispatcher->trigger_event('core.posting_refresh', compact($vars))); + $mode = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', ''); $error = $post_data = array(); From fbdc956a1cc2352e3392a392e54a2125c297b78e Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 11:52:06 -0400 Subject: [PATCH 02/21] [feature/add_events] Replaced current append_sid() hook with new event The new event, core.append_sid_override can either supplement or override the append_sid() function. PHPBB3-9550 --- phpBB/includes/functions.php | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index ecec1e5e4a..584d88aaf6 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2238,14 +2238,34 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) $params = false; } - // 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)) + $append_sid_override = false; + + /** + * This event can either supplement or override the append_sid() function + * + * To override this function, the event must set $append_sid_override to + * the new URL value, which will be returned following the event + * + * @event core.append_sid_override + * @var string url The url the session id needs to be + * appended to (can have params) + * @var mixed params String or array of additional url + * parameters + * @var bool is_amp Is url using & (true) or + * & (false) + * @var bool|string session_id Possibility to use a custom session + * id (string) instead of the global + * one (false) + * @var bool|string append_sid_override Overwrite function (string URL) + * or not (false) + * @since 3.1-A1 + */ + $vars = array('url', 'params', 'is_amp', 'session_id', 'append_sid_override'); + extract($phpbb_dispatcher->trigger_event('core.append_sid_override', compact($vars))); + + if ($append_sid_override) { - if ($phpbb_hook->hook_return(__FUNCTION__)) - { - return $phpbb_hook->hook_return_result(__FUNCTION__); - } + return $append_sid; } $params_is_array = is_array($params); From abc0ee753d4799270a20bfe756e1b7f9c302394d Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 11:57:43 -0400 Subject: [PATCH 03/21] [feature/add_events] Return the correct variable PHPBB3-9550 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 584d88aaf6..8ca15a4908 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2265,7 +2265,7 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) if ($append_sid_override) { - return $append_sid; + return $append_sid_override; } $params_is_array = is_array($params); From 808af65819d447d35a8129c98fcc2feecb03e25e Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 12:01:08 -0400 Subject: [PATCH 04/21] [feature/add_events] Globalize the event dispatcher object PHPBB3-9550 --- phpBB/includes/functions.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 8ca15a4908..3c26337f91 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2231,6 +2231,7 @@ function phpbb_on_page($template, $user, $base_url, $num_items, $per_page, $star function append_sid($url, $params = false, $is_amp = true, $session_id = false) { global $_SID, $_EXTRA_URL, $phpbb_hook; + global $phpbb_dispatcher; if ($params === '' || (is_array($params) && empty($params))) { From e80e3809b9c1a2139817aa180aae87576570acaa Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 12:21:44 -0400 Subject: [PATCH 05/21] [feature/add_events] Add event core.alter_username_string to change username PHPBB3-9550 --- phpBB/includes/functions_content.php | 29 ++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 6b2ee98d7a..1638b5c1c6 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -1175,6 +1175,7 @@ function truncate_string($string, $max_length = 60, $max_store_length = 255, $al function get_username_string($mode, $user_id, $username, $username_colour = '', $guest_username = false, $custom_profile_url = false) { static $_profile_cache; + global $phpbb_dispatcher; // We cache some common variables we need within this function if (empty($_profile_cache)) @@ -1252,10 +1253,34 @@ function get_username_string($mode, $user_id, $username, $username_colour = '', if (($mode == 'full' && !$profile_url) || $mode == 'no_profile') { - return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_noprofile'] : $_profile_cache['tpl_noprofile_colour']); + $username_string = str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_noprofile'] : $_profile_cache['tpl_noprofile_colour']); } + else + { + $username_string = str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_profile'] : $_profile_cache['tpl_profile_colour']); + } + + /** + * Use this event to change the output of get_username_string() + * + * @event core.alter_username_string + * @var string mode profile|username|colour|full|no_profile + * @var int user_id String or array of additional url + * parameters + * @var string username The user's username + * @var string username_colour Is url using & (true) or + * & (false) + * @var string guest_username optional parameter to specify the + * guest username. + * @var string custom_profile_url Optional parameter to specify a + * profile url. + * @var string username_string The string that has been generated + * @since 3.1-A1 + */ + $vars = array('mode', 'user_id', 'username', 'username_colour', 'guest_username', 'custom_profile_url', 'username_string'); + extract($phpbb_dispatcher->trigger_event('core.alter_username_string', compact($vars))); - return str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_profile'] : $_profile_cache['tpl_profile_colour']); + return $username_string; } /** From 0ba755f1bdc6329be1e58f6392b67e125abfbff5 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 20:45:09 -0400 Subject: [PATCH 06/21] [feature/add_events] Rename core.append_sid_override to just core.append_sid Also, I added the hook back in below the event for backwards compatibility. PHPBB3-9550 --- phpBB/includes/functions.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 3c26337f91..404288083b 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2247,7 +2247,7 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) * To override this function, the event must set $append_sid_override to * the new URL value, which will be returned following the event * - * @event core.append_sid_override + * @event core.append_sid * @var string url The url the session id needs to be * appended to (can have params) * @var mixed params String or array of additional url @@ -2262,13 +2262,25 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) * @since 3.1-A1 */ $vars = array('url', 'params', 'is_amp', 'session_id', 'append_sid_override'); - extract($phpbb_dispatcher->trigger_event('core.append_sid_override', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.append_sid', compact($vars))); if ($append_sid_override) { return $append_sid_override; } + // 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 From efe9b1010ac7fc38dec0e5182c1902830685f5e3 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 21:22:29 -0400 Subject: [PATCH 07/21] [feature/add_events] Fix append_sid() test PHPBB3-9550 --- tests/bootstrap.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 1017e0c72f..89268ddbab 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -22,6 +22,7 @@ $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path $phpbb_class_loader_ext->register(); $phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".php"); $phpbb_class_loader->register(); +$phpbb_dispatcher = new phpbb_event_dispatcher(); require_once 'test_framework/phpbb_test_case_helpers.php'; require_once 'test_framework/phpbb_test_case.php'; From 008cf967ab176958126582b58941bd7649732315 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 11:18:53 -0400 Subject: [PATCH 08/21] [feature/add_events] Re-fix broken test PHPBB3-9550 --- tests/bootstrap.php | 1 - tests/session/append_sid_test.php | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 89268ddbab..1017e0c72f 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -22,7 +22,6 @@ $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path $phpbb_class_loader_ext->register(); $phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".php"); $phpbb_class_loader->register(); -$phpbb_dispatcher = new phpbb_event_dispatcher(); require_once 'test_framework/phpbb_test_case_helpers.php'; require_once 'test_framework/phpbb_test_case.php'; diff --git a/tests/session/append_sid_test.php b/tests/session/append_sid_test.php index 88f6f0718e..34f6dea8ca 100644 --- a/tests/session/append_sid_test.php +++ b/tests/session/append_sid_test.php @@ -45,6 +45,9 @@ class phpbb_session_append_sid_test extends phpbb_test_case */ public function test_append_sid($url, $params, $is_amp, $session_id, $expected, $description) { + global $phpbb_dispatcher; + + $phpbb_dispatcher = new phpbb_mock_event_dispatcher; $this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id)); } } From 6c6b179dd4b239030891fcc3b72472fbf4f78bc9 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 11:25:52 -0400 Subject: [PATCH 09/21] [feature/add_events] Rename override to overwrite, made docs 79 chars/line PHPBB3-9550 --- phpBB/includes/functions.php | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 404288083b..9f1172e61e 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2239,38 +2239,39 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) $params = false; } - $append_sid_override = false; + $append_sid_overwrite = false; /** * This event can either supplement or override the append_sid() function * - * To override this function, the event must set $append_sid_override to + * To override this function, the event must set $append_sid_overwrite to * the new URL value, which will be returned following the event * * @event core.append_sid - * @var string url The url the session id needs to be - * appended to (can have params) - * @var mixed params String or array of additional url - * parameters - * @var bool is_amp Is url using & (true) or - * & (false) - * @var bool|string session_id Possibility to use a custom session - * id (string) instead of the global - * one (false) - * @var bool|string append_sid_override Overwrite function (string URL) - * or not (false) + * @var string url The url the session id needs + * to be appended to (can have + * params) + * @var mixed params String or array of additional + * url parameters + * @var bool is_amp Is url using & (true) or + * & (false) + * @var bool|string session_id Possibility to use a custom + * session id (string) instead of + * the global one (false) + * @var bool|string append_sid_overwrite Overwrite function (string + * URL) or not (false) * @since 3.1-A1 */ - $vars = array('url', 'params', 'is_amp', 'session_id', 'append_sid_override'); + $vars = array('url', 'params', 'is_amp', 'session_id', 'append_sid_overwrite'); extract($phpbb_dispatcher->trigger_event('core.append_sid', compact($vars))); - if ($append_sid_override) + if ($append_sid_overwrite) { - return $append_sid_override; + return $append_sid_overwrite; } // The following hook remains for backwards compatibility, though use of - // the event above is preferred. + // 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)) From c0cd1fcb4f42e373dad6317ec85fe33474079de2 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 11:27:28 -0400 Subject: [PATCH 10/21] [feature/add_events] Change alter -> modify in event name PHPBB3-9550 --- phpBB/includes/functions_content.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 1638b5c1c6..b1f9cf4434 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -1263,7 +1263,7 @@ function get_username_string($mode, $user_id, $username, $username_colour = '', /** * Use this event to change the output of get_username_string() * - * @event core.alter_username_string + * @event core.modify_username_string * @var string mode profile|username|colour|full|no_profile * @var int user_id String or array of additional url * parameters @@ -1278,7 +1278,7 @@ function get_username_string($mode, $user_id, $username, $username_colour = '', * @since 3.1-A1 */ $vars = array('mode', 'user_id', 'username', 'username_colour', 'guest_username', 'custom_profile_url', 'username_string'); - extract($phpbb_dispatcher->trigger_event('core.alter_username_string', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.modify_username_string', compact($vars))); return $username_string; } From 05755e1b3798d7fdb95bee462890ff94ae76533a Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 11:31:18 -0400 Subject: [PATCH 11/21] [feature/add_events] Fixed docs, added _profile_cache to event parameters PHPBB3-9550 --- phpBB/includes/functions_content.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index b1f9cf4434..8b7565d8f1 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -1268,16 +1268,16 @@ function get_username_string($mode, $user_id, $username, $username_colour = '', * @var int user_id String or array of additional url * parameters * @var string username The user's username - * @var string username_colour Is url using & (true) or - * & (false) - * @var string guest_username optional parameter to specify the + * @var string username_colour The user's colour + * @var string guest_username Optional parameter to specify the * guest username. * @var string custom_profile_url Optional parameter to specify a * profile url. * @var string username_string The string that has been generated + * @var array _profile_cache Array of original return templates * @since 3.1-A1 */ - $vars = array('mode', 'user_id', 'username', 'username_colour', 'guest_username', 'custom_profile_url', 'username_string'); + $vars = array('mode', 'user_id', 'username', 'username_colour', 'guest_username', 'custom_profile_url', 'username_string', '_profile_cache'); extract($phpbb_dispatcher->trigger_event('core.modify_username_string', compact($vars))); return $username_string; From a02bfcc83a3c9a107bc2b840d07409a93628bbdc Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 11:50:38 -0400 Subject: [PATCH 12/21] [feature/add_events] core.posting_refresh -> core.modify_posting_paramters The event now lets extensions modify the posting paramters, not just refresh PHPBB3-9550 --- phpBB/posting.php | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/phpBB/posting.php b/phpBB/posting.php index 77b3c8c861..33f0bae353 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -39,24 +39,37 @@ $delete = (isset($_POST['delete'])) ? true : false; $cancel = (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false; $refresh = (isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) || $save || $load || $preview) ? true : false; - -/** -* This event allows you to alter the $refresh boolean variable. -* -* If $refresh is true the posting form retains previously submitted form data -* -* @event core.posting_refresh -* @var bool refresh Whether or not to retain previously submitted data -* @since 3.1-A1 -*/ -$vars = array('refresh'); -extract($phpbb_dispatcher->trigger_event('core.posting_refresh', compact($vars))); - $mode = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var('mode', ''); $error = $post_data = array(); $current_time = time(); +/** +* This event allows you to alter the above parameters, such as submit and mode +* +* Note: $refresh must be true to retain previously submitted form data. +* +* @event core.modify_posting_parameters +* @var bool submit Whether or not the form has been submitted +* @var bool preview Whether or not the post is being previewed +* @var bool save Whether or not a draft is being saved +* @var bool load Whether or not a draft is being loaded +* @var bool delete Whether or not the post is being deleted +* @var bool cancel Whether or not to cancel the form (returns to +* viewtopic or viewforum depending on if the user +* is posting a new topic or editing a post) +* @var bool refresh Whether or not to retain previously submitted data +* @var string mode What action to take if the form has been sumitted +* post|reply|quote|edit|delete|bump|smilies|popup +* @var array error Any error strings; a non-empty array aborts +* form submission. +* NOTE: Should be actual language strings, NOT +* language keys. +* @since 3.1-A1 +*/ +$vars = array('submit', 'preview', 'save', 'load', 'delete', 'cancel', 'refresh', 'mode', 'error'); +extract($phpbb_dispatcher->trigger_event('core.modify_posting_parameters', compact($vars))); + // Was cancel pressed? If so then redirect to the appropriate page if ($cancel || ($current_time - $lastclick < 2 && $submit)) { From 1e29f064e87dcab1a3bb65c63d254bde03d6422d Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 12:51:41 -0400 Subject: [PATCH 13/21] [feature/add_events] Added events for modifying generate_text_for_display() The events allow you to perform extra functions on the text before nad/or after it has been parsed for BBCode and Smilies. PHPBB3-9550 --- phpBB/includes/functions_content.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 8b7565d8f1..6bad2111ef 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -411,12 +411,26 @@ function strip_bbcode(&$text, $uid = '') function generate_text_for_display($text, $uid, $bitfield, $flags) { static $bbcode; + global $phpbb_dispatcher; if (!$text) { return ''; } + /** + * Use this event to modify the text before it is parsed + * + * @event core.modify_text_for_display_before + * @var string text The text to parse + * @var string uid The BBCode UID + * @var string bitfield The BBCode Bitfield + * @var int flags The BBCode Flags + * @since 3.1-A1 + */ + $vars = array('text', 'uid', 'bitfield', 'flags'); + extract($phpbb_dispatcher->trigger_event('core.modify_text_for_display_before', compact($vars))); + $text = censor_text($text); // Parse bbcode if bbcode uid stored and bbcode enabled @@ -443,6 +457,19 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) $text = bbcode_nl2br($text); $text = smiley_text($text, !($flags & OPTION_FLAG_SMILIES)); + /** + * Use this event to modify the text after it is parsed + * + * @event core.modify_text_for_display_after + * @var string text The text to parse + * @var string uid The BBCode UID + * @var string bitfield The BBCode Bitfield + * @var int flags The BBCode Flags + * @since 3.1-A1 + */ + $vars = array('text', 'uid', 'bitfield', 'flags'); + extract($phpbb_dispatcher->trigger_event('core.modify_text_for_display_after', compact($vars))); + return $text; } From 0358db2184885dfec6c9b73573ee457cfccdd644 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 16:42:30 -0400 Subject: [PATCH 14/21] [feature/add_events] Before and after events for generate_text_for_* functions PHPBB3-9550 --- phpBB/includes/functions_content.php | 80 +++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 6bad2111ef..f6319284b0 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -418,23 +418,31 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) return ''; } + $censor_text = $allow_bbcode = $allow_smilies = true; + /** * Use this event to modify the text before it is parsed * * @event core.modify_text_for_display_before - * @var string text The text to parse - * @var string uid The BBCode UID - * @var string bitfield The BBCode Bitfield - * @var int flags The BBCode Flags + * @var string text The text to parse + * @var string uid The BBCode UID + * @var string bitfield The BBCode Bitfield + * @var int flags The BBCode Flags + * @var bool censor_text Whether or not to apply word censors + * @var bool allow_bbcode Whether or not to parse BBCode + * @var bool allow_smilies Whether or not to parse Smilies * @since 3.1-A1 */ - $vars = array('text', 'uid', 'bitfield', 'flags'); + $vars = array('text', 'uid', 'bitfield', 'flags', 'censor_text', 'allow_bbcode', 'allow_smilies'); extract($phpbb_dispatcher->trigger_event('core.modify_text_for_display_before', compact($vars))); - $text = censor_text($text); + if ($censor_text) + { + $text = censor_text($text); + } // Parse bbcode if bbcode uid stored and bbcode enabled - if ($uid && ($flags & OPTION_FLAG_BBCODE)) + if ($uid && ($flags & OPTION_FLAG_BBCODE) && $allow_bbcode) { if (!class_exists('bbcode')) { @@ -455,7 +463,11 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) } $text = bbcode_nl2br($text); - $text = smiley_text($text, !($flags & OPTION_FLAG_SMILIES)); + + if ($allow_smilies) + { + $text = smiley_text($text, !($flags & OPTION_FLAG_SMILIES)); + } /** * Use this event to modify the text after it is parsed @@ -482,6 +494,22 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bb { global $phpbb_root_path, $phpEx; + /** + * Use this event to modify the text before it is prepared for storage + * + * @event core.modify_text_for_storage_before + * @var string text The text to parse + * @var string uid The BBCode UID + * @var string bitfield The BBCode Bitfield + * @var int flags The BBCode Flags + * @var bool allow_bbcode Whether or not to parse BBCode + * @var bool allow_urls Whether or not to parse URLs + * @var bool allow_smilies Whether or not to parse Smilies + * @since 3.1-A1 + */ + $vars = array('text', 'uid', 'bitfield', 'flags', 'allow_bbcode', 'allow_urls', 'allow_smilies'); + extract($phpbb_dispatcher->trigger_event('core.modify_text_for_storage_before', compact($vars))); + $uid = $bitfield = ''; $flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0); @@ -509,6 +537,19 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bb $bitfield = $message_parser->bbcode_bitfield; + /** + * Use this event to modify the text after it is prepared for storage + * + * @event core.modify_text_for_storage_after + * @var string text The text to parse + * @var string uid The BBCode UID + * @var string bitfield The BBCode Bitfield + * @var int flags The BBCode Flags + * @since 3.1-A1 + */ + $vars = array('text', 'uid', 'bitfield', 'flags'); + extract($phpbb_dispatcher->trigger_event('core.modify_text_for_storage_after', compact($vars))); + return; } @@ -520,8 +561,31 @@ function generate_text_for_edit($text, $uid, $flags) { global $phpbb_root_path, $phpEx; + /** + * Use this event to modify the text before it is decoded for editing + * + * @event core.modify_text_for_edit_before + * @var string text The text to parse + * @var string uid The BBCode UID + * @var int flags The BBCode Flags + * @since 3.1-A1 + */ + $vars = array('text', 'uid', 'flags'); + extract($phpbb_dispatcher->trigger_event('core.modify_text_for_edit_before', compact($vars))); + decode_message($text, $uid); + /** + * Use this event to modify the text after it is decoded for editing + * + * @event core.modify_text_for_edit_after + * @var string text The text to parse + * @var int flags The BBCode Flags + * @since 3.1-A1 + */ + $vars = array('text', 'flags'); + extract($phpbb_dispatcher->trigger_event('core.modify_text_for_edit_after', compact($vars))); + return array( 'allow_bbcode' => ($flags & OPTION_FLAG_BBCODE) ? 1 : 0, 'allow_smilies' => ($flags & OPTION_FLAG_SMILIES) ? 1 : 0, From 4f6f0c08979d420a47f5cc4bcab2709d27853222 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 17:04:16 -0400 Subject: [PATCH 15/21] [feature/add_events] Event to modify the data array for when a user is added PHPBB3-9550 --- phpBB/includes/functions_user.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 9e33a5122e..f4ecb7cdc3 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -255,6 +255,16 @@ function user_add($user_row, $cp_data = false) } } + /** + * Use this event to modify the values to be inserted when a user is added + * + * @event core.user_add_modify_data + * @var array sql_ary Array of data to be inserted when a user is added + * @since 3.1-A1 + */ + $vars = array('sql_ary'); + extract($phpbb_dispatcher->trigger_event('core.user_add_modify_data', compact($vars))); + $sql = 'INSERT INTO ' . USERS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $db->sql_query($sql); From 46597be1a372f1215ffc18cfd645c1e977b44d84 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 22 Aug 2012 08:37:33 -0400 Subject: [PATCH 16/21] [feature/add_events] Globalize event dispatcher object in some functions PHPBB3-9550 --- phpBB/includes/functions_content.php | 2 ++ phpBB/includes/functions_user.php | 1 + 2 files changed, 3 insertions(+) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index f6319284b0..81ac15f168 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -493,6 +493,7 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bbcode = false, $allow_urls = false, $allow_smilies = false) { global $phpbb_root_path, $phpEx; + global $phpbb_dispatcher; /** * Use this event to modify the text before it is prepared for storage @@ -560,6 +561,7 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bb function generate_text_for_edit($text, $uid, $flags) { global $phpbb_root_path, $phpEx; + global $phpbb_dispatcher; /** * Use this event to modify the text before it is decoded for editing diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index f4ecb7cdc3..f843902dd5 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -162,6 +162,7 @@ function user_update_name($old_name, $new_name) function user_add($user_row, $cp_data = false) { global $db, $user, $auth, $config, $phpbb_root_path, $phpEx; + global $phpbb_dispatcher; if (empty($user_row['username']) || !isset($user_row['group_id']) || !isset($user_row['user_email']) || !isset($user_row['user_type'])) { From 575980cba981c2522cc7d3e66e64b9c8fbc36511 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 22 Aug 2012 09:37:47 -0400 Subject: [PATCH 17/21] [feature/add_events] Remove $allow_bbcode and $allow_smilies Upon testing it was discovered that these did not work as originally intended. PHPBB3-9550 --- phpBB/includes/functions_content.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 81ac15f168..7fb6ff44cf 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -418,7 +418,7 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) return ''; } - $censor_text = $allow_bbcode = $allow_smilies = true; + $censor_text = true; /** * Use this event to modify the text before it is parsed @@ -429,11 +429,9 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) * @var string bitfield The BBCode Bitfield * @var int flags The BBCode Flags * @var bool censor_text Whether or not to apply word censors - * @var bool allow_bbcode Whether or not to parse BBCode - * @var bool allow_smilies Whether or not to parse Smilies * @since 3.1-A1 */ - $vars = array('text', 'uid', 'bitfield', 'flags', 'censor_text', 'allow_bbcode', 'allow_smilies'); + $vars = array('text', 'uid', 'bitfield', 'flags', 'censor_text'); extract($phpbb_dispatcher->trigger_event('core.modify_text_for_display_before', compact($vars))); if ($censor_text) @@ -442,7 +440,7 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) } // Parse bbcode if bbcode uid stored and bbcode enabled - if ($uid && ($flags & OPTION_FLAG_BBCODE) && $allow_bbcode) + if ($uid && ($flags & OPTION_FLAG_BBCODE)) { if (!class_exists('bbcode')) { @@ -463,11 +461,7 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) } $text = bbcode_nl2br($text); - - if ($allow_smilies) - { - $text = smiley_text($text, !($flags & OPTION_FLAG_SMILIES)); - } + $text = smiley_text($text, !($flags & OPTION_FLAG_SMILIES)); /** * Use this event to modify the text after it is parsed From e67b010846389b649aa46729fc4180f2a177e24d Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 22 Aug 2012 10:41:59 -0400 Subject: [PATCH 18/21] [feature/add_events] Put globals on one line PHPBB3-9550 --- phpBB/includes/functions_content.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 7fb6ff44cf..e7772e14fe 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -486,8 +486,7 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) */ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bbcode = false, $allow_urls = false, $allow_smilies = false) { - global $phpbb_root_path, $phpEx; - global $phpbb_dispatcher; + global $phpbb_root_path, $phpEx, $phpbb_dispatcher; /** * Use this event to modify the text before it is prepared for storage @@ -554,8 +553,7 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bb */ function generate_text_for_edit($text, $uid, $flags) { - global $phpbb_root_path, $phpEx; - global $phpbb_dispatcher; + global $phpbb_root_path, $phpEx, $phpbb_dispatcher; /** * Use this event to modify the text before it is decoded for editing From 7ee3eb16ac1a4f11003c72b77352ad7fda53050d Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 23 Aug 2012 12:49:09 -0400 Subject: [PATCH 19/21] [feature/add_events] Add more parameters to core.modify_posting_parameters PHPBB3-9550 --- phpBB/posting.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/phpBB/posting.php b/phpBB/posting.php index 33f0bae353..f37d6128de 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -50,6 +50,11 @@ $current_time = time(); * Note: $refresh must be true to retain previously submitted form data. * * @event core.modify_posting_parameters +* @var int post_id ID of the post +* @var int topic_id ID of the topic +* @var int forum_id ID of the forum +* @var int draft_id ID of the draft +* @var int lastclick Timestamp of when the form was last loaded * @var bool submit Whether or not the form has been submitted * @var bool preview Whether or not the post is being previewed * @var bool save Whether or not a draft is being saved @@ -67,7 +72,7 @@ $current_time = time(); * language keys. * @since 3.1-A1 */ -$vars = array('submit', 'preview', 'save', 'load', 'delete', 'cancel', 'refresh', 'mode', 'error'); +$vars = array('post_id', 'topic_id', 'forum_id', 'draft_id', 'lastclick', 'submit', 'preview', 'save', 'load', 'delete', 'cancel', 'refresh', 'mode', 'error'); extract($phpbb_dispatcher->trigger_event('core.modify_posting_parameters', compact($vars))); // Was cancel pressed? If so then redirect to the appropriate page From ca62b1ffb0c1f37877fbb59beef7cd38c012b827 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 25 Aug 2012 21:41:04 -0400 Subject: [PATCH 20/21] [feature/add_events] Added note in modify_posting_parameters The template assignment methods do not work until $user->setup() has been run. This event is called before it, so extensions requiring template methods must put such calls in a later event. PHPBB3-9550 --- phpBB/posting.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/posting.php b/phpBB/posting.php index f37d6128de..ff959bb4b7 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -49,6 +49,10 @@ $current_time = time(); * * Note: $refresh must be true to retain previously submitted form data. * +* Note: The template class will not work properly until $user->setup() is +* called, and it has not been called yet. Extensions requiring template +* assignments should use an event that comes later in this file. +* * @event core.modify_posting_parameters * @var int post_id ID of the post * @var int topic_id ID of the topic From 02644c02b9d6bed5e4a8e20323bdafb2ca9749b4 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 26 Aug 2012 15:09:50 -0400 Subject: [PATCH 21/21] [feature/add_events] Added core.posting_modify_template_vars Can be used to set template variables and such, as the template assignment methods are not available to the modify_posting_paramters event. PHPBB3-9550 --- phpBB/posting.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpBB/posting.php b/phpBB/posting.php index ff959bb4b7..81ef31f96c 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -1452,6 +1452,14 @@ $template->assign_vars(array( 'S_HIDDEN_FIELDS' => $s_hidden_fields) ); +/** +* This event allows you to modify template variables for the posting screen +* +* @event core.posting_modify_template_vars +* @since 3.1-A1 +*/ +$phpbb_dispatcher->trigger_event('core.posting_modify_template_vars'); + // Build custom bbcodes array display_custom_bbcodes();