mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-06 07:35:29 +02:00
Merge pull request #962 from imkingdavid/feature/add_events
Feature/add events
This commit is contained in:
commit
43190ebeca
@ -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)
|
function append_sid($url, $params = false, $is_amp = true, $session_id = false)
|
||||||
{
|
{
|
||||||
global $_SID, $_EXTRA_URL, $phpbb_hook;
|
global $_SID, $_EXTRA_URL, $phpbb_hook;
|
||||||
|
global $phpbb_dispatcher;
|
||||||
|
|
||||||
if ($params === '' || (is_array($params) && empty($params)))
|
if ($params === '' || (is_array($params) && empty($params)))
|
||||||
{
|
{
|
||||||
@ -2238,6 +2239,39 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false)
|
|||||||
$params = false;
|
$params = 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_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_overwrite Overwrite function (string
|
||||||
|
* URL) or not (false)
|
||||||
|
* @since 3.1-A1
|
||||||
|
*/
|
||||||
|
$vars = array('url', 'params', 'is_amp', 'session_id', 'append_sid_overwrite');
|
||||||
|
extract($phpbb_dispatcher->trigger_event('core.append_sid', compact($vars)));
|
||||||
|
|
||||||
|
if ($append_sid_overwrite)
|
||||||
|
{
|
||||||
|
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.
|
// 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
|
// 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 (!empty($phpbb_hook) && $phpbb_hook->call_hook(__FUNCTION__, $url, $params, $is_amp, $session_id))
|
||||||
|
@ -411,13 +411,33 @@ function strip_bbcode(&$text, $uid = '')
|
|||||||
function generate_text_for_display($text, $uid, $bitfield, $flags)
|
function generate_text_for_display($text, $uid, $bitfield, $flags)
|
||||||
{
|
{
|
||||||
static $bbcode;
|
static $bbcode;
|
||||||
|
global $phpbb_dispatcher;
|
||||||
|
|
||||||
if (!$text)
|
if (!$text)
|
||||||
{
|
{
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$text = censor_text($text);
|
$censor_text = 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 bool censor_text Whether or not to apply word censors
|
||||||
|
* @since 3.1-A1
|
||||||
|
*/
|
||||||
|
$vars = array('text', 'uid', 'bitfield', 'flags', 'censor_text');
|
||||||
|
extract($phpbb_dispatcher->trigger_event('core.modify_text_for_display_before', compact($vars)));
|
||||||
|
|
||||||
|
if ($censor_text)
|
||||||
|
{
|
||||||
|
$text = censor_text($text);
|
||||||
|
}
|
||||||
|
|
||||||
// Parse bbcode if bbcode uid stored and bbcode enabled
|
// Parse bbcode if bbcode uid stored and bbcode enabled
|
||||||
if ($uid && ($flags & OPTION_FLAG_BBCODE))
|
if ($uid && ($flags & OPTION_FLAG_BBCODE))
|
||||||
@ -443,6 +463,19 @@ function generate_text_for_display($text, $uid, $bitfield, $flags)
|
|||||||
$text = bbcode_nl2br($text);
|
$text = bbcode_nl2br($text);
|
||||||
$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
|
||||||
|
*
|
||||||
|
* @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;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,7 +486,23 @@ 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)
|
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_root_path, $phpEx, $phpbb_dispatcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 = '';
|
$uid = $bitfield = '';
|
||||||
$flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0);
|
$flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0);
|
||||||
@ -482,6 +531,19 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bb
|
|||||||
|
|
||||||
$bitfield = $message_parser->bbcode_bitfield;
|
$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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -491,10 +553,33 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bb
|
|||||||
*/
|
*/
|
||||||
function generate_text_for_edit($text, $uid, $flags)
|
function generate_text_for_edit($text, $uid, $flags)
|
||||||
{
|
{
|
||||||
global $phpbb_root_path, $phpEx;
|
global $phpbb_root_path, $phpEx, $phpbb_dispatcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
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(
|
return array(
|
||||||
'allow_bbcode' => ($flags & OPTION_FLAG_BBCODE) ? 1 : 0,
|
'allow_bbcode' => ($flags & OPTION_FLAG_BBCODE) ? 1 : 0,
|
||||||
'allow_smilies' => ($flags & OPTION_FLAG_SMILIES) ? 1 : 0,
|
'allow_smilies' => ($flags & OPTION_FLAG_SMILIES) ? 1 : 0,
|
||||||
@ -1175,6 +1260,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)
|
function get_username_string($mode, $user_id, $username, $username_colour = '', $guest_username = false, $custom_profile_url = false)
|
||||||
{
|
{
|
||||||
static $_profile_cache;
|
static $_profile_cache;
|
||||||
|
global $phpbb_dispatcher;
|
||||||
|
|
||||||
// We cache some common variables we need within this function
|
// We cache some common variables we need within this function
|
||||||
if (empty($_profile_cache))
|
if (empty($_profile_cache))
|
||||||
@ -1252,10 +1338,34 @@ function get_username_string($mode, $user_id, $username, $username_colour = '',
|
|||||||
|
|
||||||
if (($mode == 'full' && !$profile_url) || $mode == 'no_profile')
|
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.modify_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 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', '_profile_cache');
|
||||||
|
extract($phpbb_dispatcher->trigger_event('core.modify_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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -162,6 +162,7 @@ function user_update_name($old_name, $new_name)
|
|||||||
function user_add($user_row, $cp_data = false)
|
function user_add($user_row, $cp_data = false)
|
||||||
{
|
{
|
||||||
global $db, $user, $auth, $config, $phpbb_root_path, $phpEx;
|
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']))
|
if (empty($user_row['username']) || !isset($user_row['group_id']) || !isset($user_row['user_email']) || !isset($user_row['user_type']))
|
||||||
{
|
{
|
||||||
@ -255,6 +256,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);
|
$sql = 'INSERT INTO ' . USERS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
|
||||||
$db->sql_query($sql);
|
$db->sql_query($sql);
|
||||||
|
|
||||||
|
@ -44,6 +44,41 @@ $mode = ($delete && !$preview && !$refresh && $submit) ? 'delete' : request_var
|
|||||||
$error = $post_data = array();
|
$error = $post_data = array();
|
||||||
$current_time = time();
|
$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.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* @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
|
||||||
|
* @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('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
|
// Was cancel pressed? If so then redirect to the appropriate page
|
||||||
if ($cancel || ($current_time - $lastclick < 2 && $submit))
|
if ($cancel || ($current_time - $lastclick < 2 && $submit))
|
||||||
{
|
{
|
||||||
@ -1417,6 +1452,14 @@ $template->assign_vars(array(
|
|||||||
'S_HIDDEN_FIELDS' => $s_hidden_fields)
|
'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
|
// Build custom bbcodes array
|
||||||
display_custom_bbcodes();
|
display_custom_bbcodes();
|
||||||
|
|
||||||
|
@ -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)
|
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));
|
$this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user