Version 2.1.4

This commit is contained in:
dmzx
2020-09-11 15:46:11 +02:00
parent 4d7253f0f0
commit 4e2fcec44a
22 changed files with 572 additions and 249 deletions

View File

@@ -212,7 +212,7 @@ class functions
{
if (!$row['session_viewonline'])
{
if (!$can_view_hidden && $row['user_id'] !== $this->user->data['user_id'])
if (!$can_view_hidden && $row['user_id'] != $this->user->data['user_id'])
{
continue;
}
@@ -324,7 +324,7 @@ class functions
$sql_array['WHERE'] = $this->db->sql_in_set('m.user_id', $user_ids);
$offset = 0;
}
else if ($this->mchat_settings->prune_modes[$prune_mode] === 'messages')
else if ($this->mchat_settings->prune_modes[$prune_mode] == 'messages')
{
// Skip fixed number of messages, delete all others
$sql_array['ORDER_BY'] = 'm.message_id DESC';
@@ -499,6 +499,7 @@ class functions
* @var int offset SQL offset
* @var array sql_array Array containing the SQL query data
* @since 2.0.0-RC6
* @deprecated 2.1.4-RC1, to be removed in 2.1.0.
*/
$vars = [
'message_ids',
@@ -523,6 +524,26 @@ class functions
}
}
/**
* Event to modify message rows before being processed and displayed
*
* @event dmzx.mchat.get_messages_modify_rowset
* @var array message_ids IDs of specific messages to fetch, e.g. for fetching edited messages
* @var int last_id The ID of the latest message that the user has, for fetching new messages
* @var int total SQL limit
* @var int offset SQL offset
* @var array rows Array containing message data
* @since 2.1.4-RC1
*/
$vars = [
'message_ids',
'last_id',
'total',
'offset',
'rows',
];
extract($this->dispatcher->trigger_event('dmzx.mchat.get_messages_modify_rowset', compact($vars)));
return $rows;
}

View File

@@ -733,6 +733,27 @@ class mchat
$template_data['MCHAT_TITLE'] = $active_users['users_count_title'];
$template_data['MCHAT_TITLE_HINT'] = strip_tags($active_users['users_total']);
}
else
{
$active_users = [];
}
/**
* Event that is triggered before data for the navigation bar is assigned to the template
*
* @event dmzx.mchat.header_link_template_data
* @var array template_data The data that is abbout to be assigned to the template
* @var array active_users Array containing information about active users. Available array keys:
* online_userlist, users_count_title, users_total, refresh_message
* Note: This array is empty if the number of active chat sessions is not
* displayed in the navbar.
* @since 2.1.4-RC1
*/
$vars = [
'template_data',
'active_users',
];
extract($this->dispatcher->trigger_event('dmzx.mchat.header_link_template_data', compact($vars)));
$this->template->assign_vars($template_data);
}
@@ -766,6 +787,8 @@ class mchat
$static_message = $this->lang->lang('MCHAT_STATIC_MESSAGE') ?: $this->mchat_settings->cfg('mchat_static_message');
$whois_refresh = $this->mchat_settings->cfg('mchat_whois_index') || $this->mchat_settings->cfg('mchat_navbar_link_count');
$total_messages = $this->mchat_functions->mchat_total_message_count();
$template_data = [
'MCHAT_PAGE' => $page,
'MCHAT_CURRENT_URL' => $this->mchat_settings->get_current_page(),
@@ -787,6 +810,7 @@ class mchat
'MCHAT_STATIC_MESS' => htmlspecialchars_decode($static_message),
'MCHAT_MAX_INPUT_HEIGHT' => $this->mchat_settings->cfg('mchat_max_input_height'),
'MCHAT_MAX_MESSAGE_LENGTH' => $this->mchat_settings->cfg('mchat_max_message_lngth'),
'MCHAT_TOTAL_MESSAGES' => $total_messages,
'MCHAT_JUMP_TO' => $jump_to_id,
'COOKIE_NAME' => $this->mchat_settings->cfg('cookie_name', true) . '_',
];
@@ -850,7 +874,9 @@ class mchat
* @var int jump_to_id The ID of the message that is being jumped to in the archive, usually when a user clicked on a quote reference
* @var array actions Array containing URLs to actions the user is allowed to perform (read only)
* @var array template_data The data that is about to be assigned to the template
* @var int total_messages Total number of messages
* @since 2.1.1
* @changed 2.1.4-RC1 added total_messages
*/
$vars = [
'page',
@@ -861,26 +887,44 @@ class mchat
'jump_to_id',
'actions',
'template_data',
'total_messages',
];
extract($this->dispatcher->trigger_event('dmzx.mchat.render_page_get_messages_before', compact($vars)));
$rows = $this->mchat_functions->mchat_get_messages($message_ids, $last_id, $limit, $start);
$this->assign_global_template_data();
$this->assign_messages($rows, $page);
// Always fetch at least one message so that we can extract the latest_message_id
$soft_limit = max(1, $limit);
$rows = $this->mchat_functions->mchat_get_messages($message_ids, $last_id, $soft_limit, $start);
if ($limit)
{
$this->assign_messages($rows, $page);
}
// Pass the latest_message_id to the template so that we know later where to start looking for new messages
$latest_message_id = 0;
if ($rows)
{
$latest_message = reset($rows);
$latest_message_id = $latest_message['message_id'];
}
$template_data['MCHAT_LATEST_MESSAGE_ID'] = $latest_message_id;
// Render pagination
if ($is_archive)
{
$archive_url = $this->helper->route('dmzx_mchat_page_archive_controller');
$total_messages = $this->mchat_functions->mchat_total_message_count();
/**
* Event to modify mChat pagination on the archive page
*
* @event dmzx.mchat.render_page_pagination_before
* @var string archive_url Pagination base URL
* @var int total_messages Total number of messages
* @var int total_messages Total number of messages in the mChat table
* @var int limit Number of messages to display per page
* @var int start The message which should be considered currently active, used to determine the page we're on
* @var int jump_to_id The ID of the message that is being jumped to in the archive, usually when a user clicked on a quote reference
@@ -1054,8 +1098,8 @@ class mchat
$user_avatars[$row['user_id']] = !$display_avatar || !$row['user_avatar'] ? '' : phpbb_get_user_avatar([
'avatar' => $row['user_avatar'],
'avatar_type' => $row['user_avatar_type'],
'avatar_width' => $row['user_avatar_width'] >= $row['user_avatar_height'] ? 40 : 0,
'avatar_height' => $row['user_avatar_width'] >= $row['user_avatar_height'] ? 0 : 40,
'avatar_width' => $row['user_avatar_width'] >= $row['user_avatar_height'] ? 36 : 0,
'avatar_height' => $row['user_avatar_width'] >= $row['user_avatar_height'] ? 0 : 36,
]);
}
}
@@ -1235,8 +1279,26 @@ class mchat
*/
protected function assign_bbcodes_smilies()
{
$display_bbcodes = $this->mchat_settings->cfg('allow_bbcode') && $this->auth->acl_get('u_mchat_bbcode');
$display_smilies = $this->mchat_settings->cfg('allow_smilies') && $this->auth->acl_get('u_mchat_smilies') && !$this->smilies_generated;
/**
* Event to decide whether or to display BBCodes or smilies
*
* @event dmzx.mchat.assign_bbcodes_smilies_before
* @var bool display_bbcodes Whether or not to render BBCodes
* @var bool display_smilies Whether or not to render smilies
* @since 2.1.4-RC1
*/
$vars = [
'display_bbcodes',
'display_smilies',
];
extract($this->dispatcher->trigger_event('dmzx.mchat.assign_bbcodes_smilies_before', compact($vars)));
// Display BBCodes
if ($this->mchat_settings->cfg('allow_bbcode') && $this->auth->acl_get('u_mchat_bbcode'))
if ($display_bbcodes)
{
$bbcode_template_vars = [
'quote' => [
@@ -1275,7 +1337,7 @@ class mchat
}
// Display smilies
if ($this->mchat_settings->cfg('allow_smilies') && $this->auth->acl_get('u_mchat_smilies') && !$this->smilies_generated)
if ($display_smilies)
{
$this->mchat_settings->include_functions('posting', 'generate_smilies');
@@ -1468,6 +1530,30 @@ class mchat
}
}
/**
* Event to modify the raw mChat message before it is processed
*
* @event dmzx.mchat.process_message_before
* @var string message The raw message as entered by the user
* @var string message_without_bbcode The message stripped of all BBCode tags
* @var array disallowed_bbcodes The list of disallowed BBCode tags
* @var bool mchat_img Whether or not the img BBCode is allowed
* @var bool mchat_flash Whether or not the flash BBCode is allowed
* @var bool mchat_quote Whether or not the quote BBCode is allowed
* @var bool mchat_url Whether or not the url BBCode is allowed
* @since 2.1.4-RC1
*/
$vars = [
'message',
'message_without_bbcode',
'disallowed_bbcodes',
'mchat_img',
'mchat_flash',
'mchat_quote',
'mchat_url',
];
extract($this->dispatcher->trigger_event('dmzx.mchat.process_message_before', compact($vars)));
$uid = $bitfield = $options = '';
generate_text_for_storage($message, $uid, $bitfield, $options, $mchat_bbcode, $mchat_magic_urls, $mchat_smilies, $mchat_img, $mchat_flash, $mchat_quote, $mchat_url, 'mchat');

View File

@@ -119,9 +119,8 @@ class notifications
*/
public function process($rows)
{
// All language keys of valid notifications for which we need to fetch post information
// from the database. We need to check for them here because notifications in < 2.0.0-RC6
// are plain text and don't need to be processed.
// All language keys of valid notifications. We need to check for them here because
// notifications in < 2.0.0-RC6 are plain text and don't need to be processed.
$notification_lang = [
'MCHAT_NEW_POST',
'MCHAT_NEW_QUOTE',
@@ -130,6 +129,20 @@ class notifications
'MCHAT_NEW_LOGIN',
];
/**
* Event that allows to modify rows and language keys before checking for notifications
*
* @event dmzx.mchat.process_notifications_before
* @var array rows Message rows about to be checked for notifications
* @var array notification_lang Unprocessed language keys of valid/known notifications
* @since 2.1.4-RC1
*/
$vars = [
'rows',
'notification_lang',
];
extract($this->dispatcher->trigger_event('dmzx.mchat.process_notifications_before', compact($vars)));
$notification_langs = array_merge(
// Raw notification messages in phpBB < 3.2
array_combine($notification_lang, $notification_lang),
@@ -164,6 +177,24 @@ class notifications
$rows[$i] = $this->process_notification($rows[$i], $type, $lang_key, $post_data);
}
/**
* Event that allows to modify rows after processing their notifications
*
* @event dmzx.mchat.process_notifications_after
* @var array rows Message rows about to be checked for notifications
* @var array notification_lang Unprocessed language keys of valid/known notifications
* @var array notification_langs Processed language keys of valid/known notifications
* @var array notification_post_data Post data of notifications found in the rows array
* @since 2.1.4-RC1
*/
$vars = [
'rows',
'notification_lang',
'notification_langs',
'notification_post_data',
];
extract($this->dispatcher->trigger_event('dmzx.mchat.process_notifications_after', compact($vars)));
return $rows;
}
@@ -191,24 +222,15 @@ class notifications
$rows = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result);
$post_subjects = [];
foreach ($rows as $row)
{
$post_subjects[$row['post_id']] = [
'post_subject' => $row['post_subject'],
'forum_id' => $row['forum_id'],
'forum_name' => $row['forum_name'],
];
}
$existing_post_ids = array_column($rows, 'post_id');
$existing_posts = array_combine($existing_post_ids, $rows);
// Map IDs of missing posts to null
$missing_post_subjects = array_fill_keys(array_diff($post_ids, array_keys($post_subjects)), null);
$missing_posts = array_fill_keys(array_diff($post_ids, $existing_post_ids), null);
return $post_subjects + $missing_post_subjects;
return $existing_posts + $missing_posts;
}
/**
* Converts the message field of the post row so that it can be passed to generate_text_for_display()
*
@@ -399,4 +421,33 @@ class notifications
return '';
}
/**
* Delete post notification messages, for example when disapproving posts
*
* @param array $post_ids
*/
public function delete_post_notifications($post_ids)
{
if ($post_ids)
{
$sql = 'DELETE FROM ' . $this->mchat_settings->get_table_mchat() . '
WHERE forum_id <> 0 AND ' . $this->db->sql_in_set('post_id', $post_ids);
$this->db->sql_query($sql);
}
}
/**
* Change the user to which a post notification belongs
*
* @param int $post_id
* @param int $user_id
*/
public function update_post_notification_user($post_id, $user_id)
{
$sql = 'UPDATE ' . $this->mchat_settings->get_table_mchat() . '
SET user_id = ' . (int) $user_id . '
WHERE forum_id <> 0 AND post_id = ' . (int) $post_id;
$this->db->sql_query($sql);
}
}

View File

@@ -15,6 +15,7 @@ use phpbb\auth\auth;
use phpbb\config\config;
use phpbb\config\db_text;
use phpbb\event\dispatcher_interface;
use phpbb\exception\runtime_exception;
use phpbb\language\language;
use phpbb\user;
@@ -361,6 +362,11 @@ class settings
}
}
if (isset($this->config[$config]))
{
return $this->config[$config];
}
$global_text_settings = $this->global_text_settings();
if (isset($global_text_settings[$config]))
@@ -369,7 +375,7 @@ class settings
return $global_text_values[$config];
}
return $this->config[$config];
throw new runtime_exception();
}
/**