From 593ef7885957fec3ac5f1a45b9ff04bed9254105 Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Wed, 2 May 2012 17:13:39 +0100 Subject: [ticket/10845] Remove censor from text In order to remove the censor, I added a new parameter to generate_text_for_display(), that new parameter is used to tell if the text should be censored or not. Defaults to true. PHPBB3-10845 --- phpBB/includes/functions_content.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_content.php') diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 6b2ee98d7a..70d826eead 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -408,7 +408,7 @@ function strip_bbcode(&$text, $uid = '') * For display of custom parsed text on user-facing pages * Expects $text to be the value directly from the database (stored value) */ -function generate_text_for_display($text, $uid, $bitfield, $flags) +function generate_text_for_display($text, $uid, $bitfield, $flags, $censor_text = true) { static $bbcode; @@ -417,7 +417,10 @@ function generate_text_for_display($text, $uid, $bitfield, $flags) return ''; } - $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)) -- cgit v1.2.1 From e80e3809b9c1a2139817aa180aae87576570acaa Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 20 Aug 2012 12:21:44 -0400 Subject: [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(-) (limited to 'phpBB/includes/functions_content.php') 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; } /** -- cgit v1.2.1 From c0cd1fcb4f42e373dad6317ec85fe33474079de2 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 11:27:28 -0400 Subject: [feature/add_events] Change alter -> modify in event name PHPBB3-9550 --- phpBB/includes/functions_content.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_content.php') 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; } -- cgit v1.2.1 From 05755e1b3798d7fdb95bee462890ff94ae76533a Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 11:31:18 -0400 Subject: [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(-) (limited to 'phpBB/includes/functions_content.php') 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; -- cgit v1.2.1 From 1e29f064e87dcab1a3bb65c63d254bde03d6422d Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 12:51:41 -0400 Subject: [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(+) (limited to 'phpBB/includes/functions_content.php') 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; } -- cgit v1.2.1 From 0358db2184885dfec6c9b73573ee457cfccdd644 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 16:42:30 -0400 Subject: [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(-) (limited to 'phpBB/includes/functions_content.php') 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, -- cgit v1.2.1 From 46597be1a372f1215ffc18cfd645c1e977b44d84 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 22 Aug 2012 08:37:33 -0400 Subject: [feature/add_events] Globalize event dispatcher object in some functions PHPBB3-9550 --- phpBB/includes/functions_content.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes/functions_content.php') 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 -- cgit v1.2.1 From 575980cba981c2522cc7d3e66e64b9c8fbc36511 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 22 Aug 2012 09:37:47 -0400 Subject: [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(-) (limited to 'phpBB/includes/functions_content.php') 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 -- cgit v1.2.1 From e67b010846389b649aa46729fc4180f2a177e24d Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 22 Aug 2012 10:41:59 -0400 Subject: [feature/add_events] Put globals on one line PHPBB3-9550 --- phpBB/includes/functions_content.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_content.php') 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 -- cgit v1.2.1