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

@@ -8,7 +8,7 @@
<h1>{{ lang('MCHAT_TITLE') }}</h1> <h1>{{ lang('MCHAT_TITLE') }}</h1>
{{ lang('MCHAT_VERSION') ~ lang('COLON') }} <em>{{ MCHAT_VERSION }}</em> {{ lang('MCHAT_VERSION') ~ lang('COLON') }} <em>{{ MCHAT_VERSION }}</em> | <span>{{ lang('MCHAT_REPARSER_STATUS') ~ lang('COLON') }} <span{{ S_REPARSER_ACTIVE ? ' class="errorbox"' }}>{{ lang(S_REPARSER_ACTIVE ? 'MCHAT_REPARSER_ACTIVE' : 'MCHAT_REPARSER_FINISHED') }}</span></span> <a href="https://www.phpbb.com/customise/db/extension/mchat_extension/faq/3311" title="{{ lang('MCHAT_REPARSER_STATUS') }}"><i class="icon fa-question-circle-o fa-fw" aria-hidden="true"></i></a>
{% if MCHAT_ERROR %} {% if MCHAT_ERROR %}
<div class="errorbox"> <div class="errorbox">

View File

@@ -1,52 +1,47 @@
{ {
"name": "dmzx/mchat", "name": "dmzx/mchat",
"type": "phpbb-extension", "type": "phpbb-extension",
"description": "mChat", "description": "mChat",
"homepage": "https://www.phpbb.com/customise/db/extension/mchat_extension/", "homepage": "https://www.phpbb.com/customise/db/extension/mchat_extension/",
"version": "2.1.3", "version": "2.1.4",
"time": "2019-06-06", "time": "2020-08-08",
"keywords": [ "keywords": ["phpbb", "extension", "mchat"],
"phpbb", "license": "GPL-2.0-only",
"extension", "authors": [
"mchat" {
], "name": "kasimi",
"license": "GPL-2.0-only", "homepage": "https://kasimi.net",
"authors": [ "email": "mail@kasimi.net",
{ "role": "Lead Developer"
"name": "kasimi", },
"homepage": "https://kasimi.net", {
"email": "mail@kasimi.net", "name": "dmzx",
"role": "Lead Developer" "homepage": "http://www.dmzx-web.net",
}, "email": "info@dmzx-web.net",
{ "role": "Former Developer"
"name": "dmzx", },
"homepage": "http://www.dmzx-web.net", {
"email": "info@dmzx-web.net", "name": "RMcGirr83",
"role": "Former Developer" "homepage": "http://rmcgirr83.org",
}, "role": "Original MOD author"
{ }
"name": "RMcGirr83", ],
"homepage": "http://rmcgirr83.org", "require": {
"role": "Original MOD author" "php": ">=5.4.7",
} "composer/installers": "~1.0"
], },
"require": { "require-dev": {
"php": ">=5.4.7", "phpbb/epv": "dev-master"
"composer/installers": "~1.0.0", },
"phpbb/phpbb": ">=3.2.0" "extra": {
}, "display-name": "mChat",
"require-dev": { "soft-require": {
"phpbb/epv": "dev-master" "phpbb/phpbb": ">=3.2.0"
}, },
"extra": { "version-check": {
"display-name": "mChat", "host": "www.phpbb.com",
"soft-require": { "directory": "/customise/db/extension/mchat_extension",
"phpbb/phpbb": ">=3.2.0" "filename": "version_check"
}, }
"version-check": { }
"host": "www.phpbb.com", }
"directory": "/customise/db/extension/mchat_extension",
"filename": "version_check"
}
}
}

View File

@@ -1,37 +1,37 @@
dmzx_mchat_page_custom_controller: dmzx_mchat_page_custom_controller:
path: /mchat path: '/mchat'
methods: [GET] methods: ['GET']
defaults: { _controller: dmzx.mchat.core:page_custom } defaults: { _controller: 'dmzx.mchat.core:page_custom' }
dmzx_mchat_page_archive_controller: dmzx_mchat_page_archive_controller:
path: /mchat/archive path: '/mchat/archive'
methods: [GET] methods: ['GET']
defaults: { _controller: dmzx.mchat.core:page_archive } defaults: { _controller: 'dmzx.mchat.core:page_archive' }
dmzx_mchat_page_rules_controller: dmzx_mchat_page_rules_controller:
path: /mchat/rules path: '/mchat/rules'
methods: [GET] methods: ['GET']
defaults: { _controller: dmzx.mchat.core:page_rules } defaults: { _controller: 'dmzx.mchat.core:page_rules' }
dmzx_mchat_page_whois_controller: dmzx_mchat_page_whois_controller:
path: /mchat/whois/{ip} path: '/mchat/whois/{ip}'
methods: [GET] methods: ['GET']
defaults: { _controller: dmzx.mchat.core:page_whois } defaults: { _controller: 'dmzx.mchat.core:page_whois' }
dmzx_mchat_action_add_controller: dmzx_mchat_action_add_controller:
path: /mchat/action/add path: '/mchat/action/add'
methods: [POST] methods: ['POST']
defaults: { _controller: dmzx.mchat.core:action_add } defaults: { _controller: 'dmzx.mchat.core:action_add' }
dmzx_mchat_action_edit_controller: dmzx_mchat_action_edit_controller:
path: /mchat/action/edit path: '/mchat/action/edit'
methods: [POST] methods: ['POST']
defaults: { _controller: dmzx.mchat.core:action_edit } defaults: { _controller: 'dmzx.mchat.core:action_edit' }
dmzx_mchat_action_del_controller: dmzx_mchat_action_del_controller:
path: /mchat/action/del path: '/mchat/action/del'
methods: [POST] methods: ['POST']
defaults: { _controller: dmzx.mchat.core:action_del } defaults: { _controller: 'dmzx.mchat.core:action_del' }
dmzx_mchat_action_refresh_controller: dmzx_mchat_action_refresh_controller:
path: /mchat/action/refresh path: '/mchat/action/refresh'
methods: [POST] methods: ['POST']
defaults: { _controller: dmzx.mchat.core:action_refresh } defaults: { _controller: 'dmzx.mchat.core:action_refresh' }
dmzx_mchat_action_whois_controller: dmzx_mchat_action_whois_controller:
path: /mchat/action/whois path: '/mchat/action/whois'
methods: [POST] methods: ['POST']
defaults: { _controller: dmzx.mchat.core:action_whois } defaults: { _controller: 'dmzx.mchat.core:action_whois' }

View File

@@ -1,10 +1,10 @@
imports: imports:
- { resource: tables.yml } - { resource: 'tables.yml' }
services: services:
dmzx.mchat.acp.controller: dmzx.mchat.acp.controller:
class: dmzx\mchat\controller\acp_controller class: 'dmzx\mchat\controller\acp_controller'
arguments: arguments:
- '@dmzx.mchat.functions' - '@dmzx.mchat.functions'
- '@template' - '@template'
@@ -12,13 +12,14 @@ services:
- '@user' - '@user'
- '@language' - '@language'
- '@dbal.conn' - '@dbal.conn'
- '@config_text'
- '@cache.driver' - '@cache.driver'
- '@request' - '@request'
- '@dispatcher' - '@dispatcher'
- '@dmzx.mchat.settings' - '@dmzx.mchat.settings'
dmzx.mchat.ucp.controller: dmzx.mchat.ucp.controller:
class: dmzx\mchat\controller\ucp_controller class: 'dmzx\mchat\controller\ucp_controller'
arguments: arguments:
- '@template' - '@template'
- '@user' - '@user'
@@ -30,7 +31,7 @@ services:
- '@dispatcher' - '@dispatcher'
dmzx.mchat.notifications: dmzx.mchat.notifications:
class: dmzx\mchat\core\notifications class: 'dmzx\mchat\core\notifications'
arguments: arguments:
- '@dmzx.mchat.settings' - '@dmzx.mchat.settings'
- '@user' - '@user'
@@ -41,7 +42,7 @@ services:
- '@text_formatter.parser' - '@text_formatter.parser'
dmzx.mchat.log: dmzx.mchat.log:
class: dmzx\mchat\core\log class: 'dmzx\mchat\core\log'
arguments: arguments:
- '@dmzx.mchat.settings' - '@dmzx.mchat.settings'
- '@user' - '@user'
@@ -50,7 +51,7 @@ services:
- '@dispatcher' - '@dispatcher'
dmzx.mchat.core: dmzx.mchat.core:
class: dmzx\mchat\core\mchat class: 'dmzx\mchat\core\mchat'
arguments: arguments:
- '@dmzx.mchat.functions' - '@dmzx.mchat.functions'
- '@dmzx.mchat.notifications' - '@dmzx.mchat.notifications'
@@ -70,7 +71,7 @@ services:
- '@?rmcgirr83.authorizedforurls.listener' - '@?rmcgirr83.authorizedforurls.listener'
dmzx.mchat.functions: dmzx.mchat.functions:
class: dmzx\mchat\core\functions class: 'dmzx\mchat\core\functions'
arguments: arguments:
- '@dmzx.mchat.settings' - '@dmzx.mchat.settings'
- '@dmzx.mchat.notifications' - '@dmzx.mchat.notifications'
@@ -85,7 +86,7 @@ services:
- '@group_helper' - '@group_helper'
dmzx.mchat.settings: dmzx.mchat.settings:
class: dmzx\mchat\core\settings class: 'dmzx\mchat\core\settings'
arguments: arguments:
- '@user' - '@user'
- '@language' - '@language'
@@ -100,7 +101,7 @@ services:
- '%dmzx.mchat.table.mchat_sessions%' - '%dmzx.mchat.table.mchat_sessions%'
dmzx.mchat.acp.listener: dmzx.mchat.acp.listener:
class: dmzx\mchat\event\acp_listener class: 'dmzx\mchat\event\acp_listener'
arguments: arguments:
- '@template' - '@template'
- '@request' - '@request'
@@ -108,10 +109,10 @@ services:
- '@dmzx.mchat.settings' - '@dmzx.mchat.settings'
- '@dmzx.mchat.functions' - '@dmzx.mchat.functions'
tags: tags:
- { name: event.listener } - { name: 'event.listener' }
dmzx.mchat.main.listener: dmzx.mchat.main.listener:
class: dmzx\mchat\event\main_listener class: 'dmzx\mchat\event\main_listener'
arguments: arguments:
- '@dmzx.mchat.core' - '@dmzx.mchat.core'
- '@dmzx.mchat.notifications' - '@dmzx.mchat.notifications'
@@ -121,30 +122,30 @@ services:
- '@request' - '@request'
- '%core.php_ext%' - '%core.php_ext%'
tags: tags:
- { name: event.listener } - { name: 'event.listener' }
dmzx.mchat.cron.task.mchat_prune: dmzx.mchat.cron.task.mchat_prune:
class: dmzx\mchat\cron\mchat_prune class: 'dmzx\mchat\cron\mchat_prune'
arguments: arguments:
- '@dmzx.mchat.functions' - '@dmzx.mchat.functions'
- '@dmzx.mchat.settings' - '@dmzx.mchat.settings'
calls: calls:
- [set_name, [cron.task.mchat_prune]] - ['set_name', ['cron.task.mchat_prune']]
tags: tags:
- { name: cron.task } - { name: 'cron.task' }
dmzx.mchat.text_reparser.mchat_messages: dmzx.mchat.text_reparser.mchat_messages:
class: dmzx\mchat\textreparser\plugins\mchat_messages class: 'dmzx\mchat\textreparser\plugins\mchat_messages'
arguments: arguments:
- '@dbal.conn' - '@dbal.conn'
- '%dmzx.mchat.table.mchat%' - '%dmzx.mchat.table.mchat%'
calls: calls:
- [set_name, [dmzx.mchat.text_reparser.mchat_messages]] - ['set_name', ['dmzx.mchat.text_reparser.mchat_messages']]
tags: tags:
- { name: text_reparser.plugin } - { name: 'text_reparser.plugin' }
dmzx.mchat.text_reparser.reparser: dmzx.mchat.text_reparser.reparser:
class: phpbb\cron\task\text_reparser\reparser class: 'phpbb\cron\task\text_reparser\reparser'
arguments: arguments:
- '@config' - '@config'
- '@config_text' - '@config_text'
@@ -152,7 +153,7 @@ services:
- '@text_reparser.manager' - '@text_reparser.manager'
- '@text_reparser_collection' - '@text_reparser_collection'
calls: calls:
- [set_name, [dmzx.mchat.text_reparser.reparser]] - ['set_name', ['dmzx.mchat.text_reparser.reparser']]
- [set_reparser, [dmzx.mchat.text_reparser.mchat_messages]] - ['set_reparser', ['dmzx.mchat.text_reparser.mchat_messages']]
tags: tags:
- { name: cron.task } - { name: 'cron.task' }

View File

@@ -1,4 +1,4 @@
parameters: parameters:
dmzx.mchat.table.mchat: %core.table_prefix%mchat dmzx.mchat.table.mchat: '%core.table_prefix%mchat'
dmzx.mchat.table.mchat_log: %core.table_prefix%mchat_log dmzx.mchat.table.mchat_log: '%core.table_prefix%mchat_log'
dmzx.mchat.table.mchat_sessions: %core.table_prefix%mchat_sessions dmzx.mchat.table.mchat_sessions: '%core.table_prefix%mchat_sessions'

View File

@@ -14,6 +14,7 @@ namespace dmzx\mchat\controller;
use dmzx\mchat\core\functions; use dmzx\mchat\core\functions;
use dmzx\mchat\core\settings; use dmzx\mchat\core\settings;
use phpbb\cache\driver\driver_interface as cache_interface; use phpbb\cache\driver\driver_interface as cache_interface;
use phpbb\config\db_text as config_text;
use phpbb\db\driver\driver_interface as db_interface; use phpbb\db\driver\driver_interface as db_interface;
use phpbb\event\dispatcher_interface; use phpbb\event\dispatcher_interface;
use phpbb\language\language; use phpbb\language\language;
@@ -42,6 +43,9 @@ class acp_controller
/** @var db_interface */ /** @var db_interface */
protected $db; protected $db;
/** @var config_text */
protected $config_text;
/** @var cache_interface */ /** @var cache_interface */
protected $cache; protected $cache;
@@ -63,6 +67,7 @@ class acp_controller
* @param user $user * @param user $user
* @param language $lang * @param language $lang
* @param db_interface $db * @param db_interface $db
* @param config_text $config_text
* @param cache_interface $cache * @param cache_interface $cache
* @param request_interface $request * @param request_interface $request
* @param dispatcher_interface $dispatcher * @param dispatcher_interface $dispatcher
@@ -75,6 +80,7 @@ class acp_controller
user $user, user $user,
language $lang, language $lang,
db_interface $db, db_interface $db,
config_text $config_text,
cache_interface $cache, cache_interface $cache,
request_interface $request, request_interface $request,
dispatcher_interface $dispatcher, dispatcher_interface $dispatcher,
@@ -87,6 +93,7 @@ class acp_controller
$this->user = $user; $this->user = $user;
$this->lang = $lang; $this->lang = $lang;
$this->db = $db; $this->db = $db;
$this->config_text = $config_text;
$this->cache = $cache; $this->cache = $cache;
$this->request = $request; $this->request = $request;
$this->dispatcher = $dispatcher; $this->dispatcher = $dispatcher;
@@ -123,6 +130,10 @@ class acp_controller
} }
} }
// Enable Emojis and rich text in Rules and Static Message
$mchat_new_config['mchat_rules'] = utf8_encode_ncr($mchat_new_config['mchat_rules']);
$mchat_new_config['mchat_static_message'] = utf8_encode_ncr($mchat_new_config['mchat_static_message']);
// Remove leading & trailing | characters to not break allowed BBCodes // Remove leading & trailing | characters to not break allowed BBCodes
$mchat_new_config['mchat_bbcode_disallowed'] = trim($mchat_new_config['mchat_bbcode_disallowed'], '|'); $mchat_new_config['mchat_bbcode_disallowed'] = trim($mchat_new_config['mchat_bbcode_disallowed'], '|');
@@ -212,6 +223,7 @@ class acp_controller
'S_MCHAT_PRUNE_MODE_OPTIONS' => $this->get_prune_mode_options($this->settings->cfg('mchat_prune_mode')), 'S_MCHAT_PRUNE_MODE_OPTIONS' => $this->get_prune_mode_options($this->settings->cfg('mchat_prune_mode')),
'L_MCHAT_BBCODES_DISALLOWED_EXPLAIN' => $this->lang->lang('MCHAT_BBCODES_DISALLOWED_EXPLAIN', '<a href="' . append_sid($this->settings->url('adm/index'), ['i' => 'bbcodes']) . '">', '</a>'), 'L_MCHAT_BBCODES_DISALLOWED_EXPLAIN' => $this->lang->lang('MCHAT_BBCODES_DISALLOWED_EXPLAIN', '<a href="' . append_sid($this->settings->url('adm/index'), ['i' => 'bbcodes']) . '">', '</a>'),
'L_MCHAT_TIMEOUT_EXPLAIN' => $this->lang->lang('MCHAT_TIMEOUT_EXPLAIN','<a href="' . append_sid($this->settings->url('adm/index'), ['i' => 'board', 'mode' => 'load']) . '">', '</a>', $this->settings->cfg('session_length')), 'L_MCHAT_TIMEOUT_EXPLAIN' => $this->lang->lang('MCHAT_TIMEOUT_EXPLAIN','<a href="' . append_sid($this->settings->url('adm/index'), ['i' => 'board', 'mode' => 'load']) . '">', '</a>', $this->settings->cfg('session_length')),
'S_REPARSER_ACTIVE' => $this->is_reparser_active('dmzx.mchat.text_reparser.mchat_messages'),
'U_ACTION' => $u_action, 'U_ACTION' => $u_action,
]; ];
@@ -376,4 +388,27 @@ class acp_controller
return $prune_mode_options; return $prune_mode_options;
} }
/**
* @param string $reparser_name
* @return bool
*/
protected function is_reparser_active($reparser_name)
{
$reparser_resume = $this->config_text->get('reparser_resume');
if (empty($reparser_resume))
{
return false;
}
$reparser_resume = @unserialize($reparser_resume);
if (!isset($reparser_resume[$reparser_name]['range-min']) || !isset($reparser_resume[$reparser_name]['range-max']))
{
return false;
}
return $reparser_resume[$reparser_name]['range-max'] >= $reparser_resume[$reparser_name]['range-min'];
}
} }

View File

@@ -212,7 +212,7 @@ class functions
{ {
if (!$row['session_viewonline']) 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; continue;
} }
@@ -324,7 +324,7 @@ class functions
$sql_array['WHERE'] = $this->db->sql_in_set('m.user_id', $user_ids); $sql_array['WHERE'] = $this->db->sql_in_set('m.user_id', $user_ids);
$offset = 0; $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 // Skip fixed number of messages, delete all others
$sql_array['ORDER_BY'] = 'm.message_id DESC'; $sql_array['ORDER_BY'] = 'm.message_id DESC';
@@ -499,6 +499,7 @@ class functions
* @var int offset SQL offset * @var int offset SQL offset
* @var array sql_array Array containing the SQL query data * @var array sql_array Array containing the SQL query data
* @since 2.0.0-RC6 * @since 2.0.0-RC6
* @deprecated 2.1.4-RC1, to be removed in 2.1.0.
*/ */
$vars = [ $vars = [
'message_ids', '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; return $rows;
} }

View File

@@ -733,6 +733,27 @@ class mchat
$template_data['MCHAT_TITLE'] = $active_users['users_count_title']; $template_data['MCHAT_TITLE'] = $active_users['users_count_title'];
$template_data['MCHAT_TITLE_HINT'] = strip_tags($active_users['users_total']); $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); $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'); $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'); $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 = [ $template_data = [
'MCHAT_PAGE' => $page, 'MCHAT_PAGE' => $page,
'MCHAT_CURRENT_URL' => $this->mchat_settings->get_current_page(), 'MCHAT_CURRENT_URL' => $this->mchat_settings->get_current_page(),
@@ -787,6 +810,7 @@ class mchat
'MCHAT_STATIC_MESS' => htmlspecialchars_decode($static_message), 'MCHAT_STATIC_MESS' => htmlspecialchars_decode($static_message),
'MCHAT_MAX_INPUT_HEIGHT' => $this->mchat_settings->cfg('mchat_max_input_height'), '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_MAX_MESSAGE_LENGTH' => $this->mchat_settings->cfg('mchat_max_message_lngth'),
'MCHAT_TOTAL_MESSAGES' => $total_messages,
'MCHAT_JUMP_TO' => $jump_to_id, 'MCHAT_JUMP_TO' => $jump_to_id,
'COOKIE_NAME' => $this->mchat_settings->cfg('cookie_name', true) . '_', '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 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 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 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 * @since 2.1.1
* @changed 2.1.4-RC1 added total_messages
*/ */
$vars = [ $vars = [
'page', 'page',
@@ -861,26 +887,44 @@ class mchat
'jump_to_id', 'jump_to_id',
'actions', 'actions',
'template_data', 'template_data',
'total_messages',
]; ];
extract($this->dispatcher->trigger_event('dmzx.mchat.render_page_get_messages_before', compact($vars))); 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_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 // Render pagination
if ($is_archive) if ($is_archive)
{ {
$archive_url = $this->helper->route('dmzx_mchat_page_archive_controller'); $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 to modify mChat pagination on the archive page
* *
* @event dmzx.mchat.render_page_pagination_before * @event dmzx.mchat.render_page_pagination_before
* @var string archive_url Pagination base URL * @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 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 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 * @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([ $user_avatars[$row['user_id']] = !$display_avatar || !$row['user_avatar'] ? '' : phpbb_get_user_avatar([
'avatar' => $row['user_avatar'], 'avatar' => $row['user_avatar'],
'avatar_type' => $row['user_avatar_type'], 'avatar_type' => $row['user_avatar_type'],
'avatar_width' => $row['user_avatar_width'] >= $row['user_avatar_height'] ? 40 : 0, 'avatar_width' => $row['user_avatar_width'] >= $row['user_avatar_height'] ? 36 : 0,
'avatar_height' => $row['user_avatar_width'] >= $row['user_avatar_height'] ? 0 : 40, 'avatar_height' => $row['user_avatar_width'] >= $row['user_avatar_height'] ? 0 : 36,
]); ]);
} }
} }
@@ -1235,8 +1279,26 @@ class mchat
*/ */
protected function assign_bbcodes_smilies() 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 // Display BBCodes
if ($this->mchat_settings->cfg('allow_bbcode') && $this->auth->acl_get('u_mchat_bbcode')) if ($display_bbcodes)
{ {
$bbcode_template_vars = [ $bbcode_template_vars = [
'quote' => [ 'quote' => [
@@ -1275,7 +1337,7 @@ class mchat
} }
// Display smilies // 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'); $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 = ''; $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'); 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) public function process($rows)
{ {
// All language keys of valid notifications for which we need to fetch post information // All language keys of valid notifications. We need to check for them here because
// from the database. We need to check for them here because notifications in < 2.0.0-RC6 // notifications in < 2.0.0-RC6 are plain text and don't need to be processed.
// are plain text and don't need to be processed.
$notification_lang = [ $notification_lang = [
'MCHAT_NEW_POST', 'MCHAT_NEW_POST',
'MCHAT_NEW_QUOTE', 'MCHAT_NEW_QUOTE',
@@ -130,6 +129,20 @@ class notifications
'MCHAT_NEW_LOGIN', '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( $notification_langs = array_merge(
// Raw notification messages in phpBB < 3.2 // Raw notification messages in phpBB < 3.2
array_combine($notification_lang, $notification_lang), array_combine($notification_lang, $notification_lang),
@@ -164,6 +177,24 @@ class notifications
$rows[$i] = $this->process_notification($rows[$i], $type, $lang_key, $post_data); $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; return $rows;
} }
@@ -191,24 +222,15 @@ class notifications
$rows = $this->db->sql_fetchrowset($result); $rows = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
$post_subjects = []; $existing_post_ids = array_column($rows, 'post_id');
$existing_posts = array_combine($existing_post_ids, $rows);
foreach ($rows as $row)
{
$post_subjects[$row['post_id']] = [
'post_subject' => $row['post_subject'],
'forum_id' => $row['forum_id'],
'forum_name' => $row['forum_name'],
];
}
// Map IDs of missing posts to null // 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() * 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 ''; 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\config;
use phpbb\config\db_text; use phpbb\config\db_text;
use phpbb\event\dispatcher_interface; use phpbb\event\dispatcher_interface;
use phpbb\exception\runtime_exception;
use phpbb\language\language; use phpbb\language\language;
use phpbb\user; 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(); $global_text_settings = $this->global_text_settings();
if (isset($global_text_settings[$config])) if (isset($global_text_settings[$config]))
@@ -369,7 +375,7 @@ class settings
return $global_text_values[$config]; return $global_text_values[$config];
} }
return $this->config[$config]; throw new runtime_exception();
} }
/** /**

View File

@@ -84,9 +84,11 @@ class main_listener implements EventSubscriberInterface
'core.page_header' => 'add_page_header_link', 'core.page_header' => 'add_page_header_link',
'core.index_modify_page_title' => 'display_mchat_on_index', 'core.index_modify_page_title' => 'display_mchat_on_index',
'core.submit_post_end' => 'insert_posting', 'core.submit_post_end' => 'insert_posting',
'core.delete_posts_after' => 'delete_posts_after',
'core.display_custom_bbcodes_modify_sql' => [['remove_disallowed_bbcodes'], ['pm_compose_add_quote']], 'core.display_custom_bbcodes_modify_sql' => [['remove_disallowed_bbcodes'], ['pm_compose_add_quote']],
'core.generate_smilies_after' => 'generate_smilies_after', 'core.generate_smilies_after' => 'generate_smilies_after',
'core.user_add_modify_data' => 'user_registration_set_default_values', 'core.user_add_modify_data' => 'user_registration_set_default_values',
'core.mcp_change_poster_after' => 'mcp_change_poster_after',
'core.login_box_redirect' => 'user_login_success', 'core.login_box_redirect' => 'user_login_success',
'core.session_gc_after' => 'session_gc', 'core.session_gc_after' => 'session_gc',
]; ];
@@ -141,6 +143,14 @@ class main_listener implements EventSubscriberInterface
$this->mchat_notifications->insert_post($event['mode'], $event['data']['forum_id'], $event['data']['post_id']); $this->mchat_notifications->insert_post($event['mode'], $event['data']['forum_id'], $event['data']['post_id']);
} }
/**
* @param data $event
*/
public function delete_posts_after(data $event)
{
$this->mchat_notifications->delete_post_notifications($event['post_ids']);
}
/** /**
* @param data $event * @param data $event
*/ */
@@ -167,6 +177,14 @@ class main_listener implements EventSubscriberInterface
$event['sql_ary'] = $this->mchat->set_user_default_values($event['sql_ary']); $event['sql_ary'] = $this->mchat->set_user_default_values($event['sql_ary']);
} }
/**
* @param data $event
*/
public function mcp_change_poster_after(data $event)
{
$this->mchat_notifications->update_post_notification_user($event['post_info']['post_id'], $event['userdata']['user_id']);
}
/** /**
* @param data $event * @param data $event
*/ */

View File

@@ -64,7 +64,7 @@ $lang = array_merge($lang, [
'MCHAT_VERSION' => 'Version', 'MCHAT_VERSION' => 'Version',
'MCHAT_RULES' => 'Rules', 'MCHAT_RULES' => 'Rules',
'MCHAT_RULES_EXPLAIN' => 'Enter the rules here. HTML code is allowed. Set to empty to disable the display.<br>This message can be translated: edit the MCHAT_RULES_MESSAGE language key in /ext/dmzx/mchat/language/XX/mchat.php.', 'MCHAT_RULES_EXPLAIN' => 'Enter the rules here. HTML code is allowed. Set to empty to disable the display.<br>This message can be translated: edit the MCHAT_RULES_MESSAGE language key in /ext/dmzx/mchat/language/XX/mchat.php.',
'MCHAT_CONFIG_SAVED' => 'mChat configuration has been updated', 'MCHAT_CONFIG_SAVED' => 'mChat configuration has been updated.',
'MCHAT_AVATARS' => 'Display avatars', 'MCHAT_AVATARS' => 'Display avatars',
'MCHAT_AVATARS_EXPLAIN' => 'If set to yes, resized user avatars will be displayed.', 'MCHAT_AVATARS_EXPLAIN' => 'If set to yes, resized user avatars will be displayed.',
'MCHAT_INDEX' => 'Display mChat on the index page', 'MCHAT_INDEX' => 'Display mChat on the index page',
@@ -129,7 +129,11 @@ $lang = array_merge($lang, [
'MCHAT_SOUND' => 'Play sounds for new, edited and deleted messages', 'MCHAT_SOUND' => 'Play sounds for new, edited and deleted messages',
'MCHAT_PURGE' => 'Delete all messages now', 'MCHAT_PURGE' => 'Delete all messages now',
'MCHAT_PURGE_CONFIRM' => 'Confirm deleting all messages', 'MCHAT_PURGE_CONFIRM' => 'Confirm deleting all messages',
'MCHAT_PURGED' => 'All mChat messages have been successfully deleted', 'MCHAT_PURGED' => 'All mChat messages have been successfully deleted.',
'MCHAT_REPARSER_STATUS' => 'Message reparser status',
'MCHAT_REPARSER_ACTIVE' => 'active',
'MCHAT_REPARSER_FINISHED' => 'finished',
// '%1$s' contains 'Retain posts' and 'Delete posts' respectively // '%1$s' contains 'Retain posts' and 'Delete posts' respectively
'MCHAT_RETAIN_MESSAGES' => '%1$s and retain mChat messages', 'MCHAT_RETAIN_MESSAGES' => '%1$s and retain mChat messages',

View File

@@ -0,0 +1,30 @@
<?php
/**
*
* @package phpBB Extension - mChat
* @copyright (c) 2020 kasimi - https://kasimi.net
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace dmzx\mchat\migrations;
use phpbb\db\migration\migration;
class mchat_2_1_4 extends migration
{
public static function depends_on()
{
return [
'\dmzx\mchat\migrations\mchat_2_1_4_rc2',
];
}
public function update_data()
{
return [
['config.update', ['mchat_version', '2.1.4']],
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
*
* @package phpBB Extension - mChat
* @copyright (c) 2020 kasimi - https://kasimi.net
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace dmzx\mchat\migrations;
use phpbb\db\migration\migration;
class mchat_2_1_4_rc1 extends migration
{
public static function depends_on()
{
return [
'\dmzx\mchat\migrations\mchat_2_1_3',
];
}
public function update_data()
{
return [
['config.update', ['mchat_version', '2.1.4-RC1']],
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
*
* @package phpBB Extension - mChat
* @copyright (c) 2020 kasimi - https://kasimi.net
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace dmzx\mchat\migrations;
use phpbb\db\migration\migration;
class mchat_2_1_4_rc2 extends migration
{
public static function depends_on()
{
return [
'\dmzx\mchat\migrations\mchat_2_1_4_rc1',
];
}
public function update_data()
{
return [
['config.update', ['mchat_version', '2.1.4-RC2']],
];
}
}

View File

@@ -45,7 +45,7 @@ ul#mchat-messages {
color: #3a3a3a; color: #3a3a3a;
} }
ul.mchat-buttons .fa { ul.mchat-buttons .icon {
color: #107c10; color: #107c10;
} }

View File

@@ -1,6 +1,6 @@
/*! /*!
autosize 4.0.1 autosize 4.0.2
license: MIT license: MIT
http://www.jacklmoore.com/autosize http://www.jacklmoore.com/autosize
*/ */
!function(e,t){if("function"==typeof define&&define.amd)define(["module","exports"],t);else if("undefined"!=typeof exports)t(module,exports);else{var n={exports:{}};t(n,n.exports),e.autosize=n.exports}}(this,function(e,t){"use strict";var n,o,p="function"==typeof Map?new Map:(n=[],o=[],{has:function(e){return-1<n.indexOf(e)},get:function(e){return o[n.indexOf(e)]},set:function(e,t){-1===n.indexOf(e)&&(n.push(e),o.push(t))},delete:function(e){var t=n.indexOf(e);-1<t&&(n.splice(t,1),o.splice(t,1))}}),c=function(e){return new Event(e,{bubbles:!0})};try{new Event("test")}catch(e){c=function(e){var t=document.createEvent("Event");return t.initEvent(e,!0,!1),t}}function r(r){if(r&&r.nodeName&&"TEXTAREA"===r.nodeName&&!p.has(r)){var e,n=null,o=null,i=null,d=function(){r.clientWidth!==o&&a()},l=function(t){window.removeEventListener("resize",d,!1),r.removeEventListener("input",a,!1),r.removeEventListener("keyup",a,!1),r.removeEventListener("autosize:destroy",l,!1),r.removeEventListener("autosize:update",a,!1),Object.keys(t).forEach(function(e){r.style[e]=t[e]}),p.delete(r)}.bind(r,{height:r.style.height,resize:r.style.resize,overflowY:r.style.overflowY,overflowX:r.style.overflowX,wordWrap:r.style.wordWrap});r.addEventListener("autosize:destroy",l,!1),"onpropertychange"in r&&"oninput"in r&&r.addEventListener("keyup",a,!1),window.addEventListener("resize",d,!1),r.addEventListener("input",a,!1),r.addEventListener("autosize:update",a,!1),r.style.overflowX="hidden",r.style.wordWrap="break-word",p.set(r,{destroy:l,update:a}),"vertical"===(e=window.getComputedStyle(r,null)).resize?r.style.resize="none":"both"===e.resize&&(r.style.resize="horizontal"),n="content-box"===e.boxSizing?-(parseFloat(e.paddingTop)+parseFloat(e.paddingBottom)):parseFloat(e.borderTopWidth)+parseFloat(e.borderBottomWidth),isNaN(n)&&(n=0),a()}function s(e){var t=r.style.width;r.style.width="0px",r.offsetWidth,r.style.width=t,r.style.overflowY=e}function u(){if(0!==r.scrollHeight){var e=function(e){for(var t=[];e&&e.parentNode&&e.parentNode instanceof Element;)e.parentNode.scrollTop&&t.push({node:e.parentNode,scrollTop:e.parentNode.scrollTop}),e=e.parentNode;return t}(r),t=document.documentElement&&document.documentElement.scrollTop;r.style.height="",r.style.height=r.scrollHeight+n+"px",o=r.clientWidth,e.forEach(function(e){e.node.scrollTop=e.scrollTop}),t&&(document.documentElement.scrollTop=t)}}function a(){u();var e=Math.round(parseFloat(r.style.height)),t=window.getComputedStyle(r,null),n="content-box"===t.boxSizing?Math.round(parseFloat(t.height)):r.offsetHeight;if(n!==e?"hidden"===t.overflowY&&(s("scroll"),u(),n="content-box"===t.boxSizing?Math.round(parseFloat(window.getComputedStyle(r,null).height)):r.offsetHeight):"hidden"!==t.overflowY&&(s("hidden"),u(),n="content-box"===t.boxSizing?Math.round(parseFloat(window.getComputedStyle(r,null).height)):r.offsetHeight),i!==n){i=n;var o=c("autosize:resized");try{r.dispatchEvent(o)}catch(e){}}}}function i(e){var t=p.get(e);t&&t.destroy()}function d(e){var t=p.get(e);t&&t.update()}var l=null;"undefined"==typeof window||"function"!=typeof window.getComputedStyle?((l=function(e){return e}).destroy=function(e){return e},l.update=function(e){return e}):((l=function(e,t){return e&&Array.prototype.forEach.call(e.length?e:[e],function(e){return r(e)}),e}).destroy=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],i),e},l.update=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],d),e}),t.default=l,e.exports=t.default}); !function(e,t){if("function"==typeof define&&define.amd)define(["module","exports"],t);else if("undefined"!=typeof exports)t(module,exports);else{var n={exports:{}};t(n,n.exports),e.autosize=n.exports}}(this,function(e,t){"use strict";var n,o,p="function"==typeof Map?new Map:(n=[],o=[],{has:function(e){return-1<n.indexOf(e)},get:function(e){return o[n.indexOf(e)]},set:function(e,t){-1===n.indexOf(e)&&(n.push(e),o.push(t))},delete:function(e){var t=n.indexOf(e);-1<t&&(n.splice(t,1),o.splice(t,1))}}),c=function(e){return new Event(e,{bubbles:!0})};try{new Event("test")}catch(e){c=function(e){var t=document.createEvent("Event");return t.initEvent(e,!0,!1),t}}function r(r){if(r&&r.nodeName&&"TEXTAREA"===r.nodeName&&!p.has(r)){var e,n=null,o=null,i=null,d=function(){r.clientWidth!==o&&a()},l=function(t){window.removeEventListener("resize",d,!1),r.removeEventListener("input",a,!1),r.removeEventListener("keyup",a,!1),r.removeEventListener("autosize:destroy",l,!1),r.removeEventListener("autosize:update",a,!1),Object.keys(t).forEach(function(e){r.style[e]=t[e]}),p.delete(r)}.bind(r,{height:r.style.height,resize:r.style.resize,overflowY:r.style.overflowY,overflowX:r.style.overflowX,wordWrap:r.style.wordWrap});r.addEventListener("autosize:destroy",l,!1),"onpropertychange"in r&&"oninput"in r&&r.addEventListener("keyup",a,!1),window.addEventListener("resize",d,!1),r.addEventListener("input",a,!1),r.addEventListener("autosize:update",a,!1),r.style.overflowX="hidden",r.style.wordWrap="break-word",p.set(r,{destroy:l,update:a}),"vertical"===(e=window.getComputedStyle(r,null)).resize?r.style.resize="none":"both"===e.resize&&(r.style.resize="horizontal"),n="content-box"===e.boxSizing?-(parseFloat(e.paddingTop)+parseFloat(e.paddingBottom)):parseFloat(e.borderTopWidth)+parseFloat(e.borderBottomWidth),isNaN(n)&&(n=0),a()}function s(e){var t=r.style.width;r.style.width="0px",r.offsetWidth,r.style.width=t,r.style.overflowY=e}function u(){if(0!==r.scrollHeight){var e=function(e){for(var t=[];e&&e.parentNode&&e.parentNode instanceof Element;)e.parentNode.scrollTop&&t.push({node:e.parentNode,scrollTop:e.parentNode.scrollTop}),e=e.parentNode;return t}(r),t=document.documentElement&&document.documentElement.scrollTop;r.style.height="",r.style.height=r.scrollHeight+n+"px",o=r.clientWidth,e.forEach(function(e){e.node.scrollTop=e.scrollTop}),t&&(document.documentElement.scrollTop=t)}}function a(){u();var e=Math.round(parseFloat(r.style.height)),t=window.getComputedStyle(r,null),n="content-box"===t.boxSizing?Math.round(parseFloat(t.height)):r.offsetHeight;if(n<e?"hidden"===t.overflowY&&(s("scroll"),u(),n="content-box"===t.boxSizing?Math.round(parseFloat(window.getComputedStyle(r,null).height)):r.offsetHeight):"hidden"!==t.overflowY&&(s("hidden"),u(),n="content-box"===t.boxSizing?Math.round(parseFloat(window.getComputedStyle(r,null).height)):r.offsetHeight),i!==n){i=n;var o=c("autosize:resized");try{r.dispatchEvent(o)}catch(e){}}}}function i(e){var t=p.get(e);t&&t.destroy()}function d(e){var t=p.get(e);t&&t.update()}var l=null;"undefined"==typeof window||"function"!=typeof window.getComputedStyle?((l=function(e){return e}).destroy=function(e){return e},l.update=function(e){return e}):((l=function(e,t){return e&&Array.prototype.forEach.call(e.length?e:[e],function(e){return r(e)}),e}).destroy=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],i),e},l.update=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],d),e}),t.default=l,e.exports=t.default});

View File

@@ -114,7 +114,7 @@ jQuery(function($) {
$.ajax({ $.ajax({
url: mChat.actionUrls[mode], url: mChat.actionUrls[mode],
timeout: Math.min(mChat.refreshTime, 10000) - 100, timeout: Math.min(mChat.refreshTime, 10000) - 100,
type: 'POST', method: 'POST',
dataType: 'json', dataType: 'json',
data: data, data: data,
context: { context: {
@@ -207,7 +207,7 @@ jQuery(function($) {
}, },
sound: function(file) { sound: function(file) {
var data = { var data = {
audio: mChat.cached('sound-' + file).get(0), audio: mChat.cached('sound-' + file)[0],
file: file, file: file,
play: !mChat.pageIsUnloading && mChat.cached('sound').hasClass('mchat-nav-item-enabled') play: !mChat.pageIsUnloading && mChat.cached('sound').hasClass('mchat-nav-item-enabled')
}; };
@@ -250,7 +250,7 @@ jQuery(function($) {
var $input = $confirmFields.find(':input:visible:enabled:first'); var $input = $confirmFields.find(':input:visible:enabled:first');
if ($input.length) { if ($input.length) {
var value = $input.val(); var value = $input.val();
$input.focus().val('').val(value); $input.trigger('focus').val('').val(value);
} }
}, 1); }, 1);
phpbb.confirm(data.container.show(), function(success) { phpbb.confirm(data.container.show(), function(success) {
@@ -288,7 +288,7 @@ jQuery(function($) {
mChat.setText(originalInputValue); mChat.setText(originalInputValue);
}).always(function() { }).always(function() {
$add.prop('disabled', false); $add.prop('disabled', false);
$input.delay(1).focus(); $input.delay(1).trigger('focus');
}); });
}, },
edit: function() { edit: function() {
@@ -393,12 +393,12 @@ jQuery(function($) {
whoisDone: function(json) { whoisDone: function(json) {
var $whois = $(json.container); var $whois = $(json.container);
var $userlist = $whois.find('#mchat-userlist'); var $userlist = $whois.find('#mchat-userlist');
if (mChat.storage.get('show_userlist')) {
$userlist.show();
}
mChat.cached('whois').replaceWith($whois); mChat.cached('whois').replaceWith($whois);
mChat.cache.whois = $whois; mChat.cache.whois = $whois;
mChat.cache.userlist = $userlist; mChat.cache.userlist = $userlist;
if (mChat.storage.get('show_userlist')) {
$userlist.show();
}
if (mChat.page === 'custom') { if (mChat.page === 'custom') {
mChat.cached('refresh-pending').hide(); mChat.cached('refresh-pending').hide();
mChat.cached('refresh-explain').show(); mChat.cached('refresh-explain').show();
@@ -411,82 +411,70 @@ jQuery(function($) {
} }
}, },
addMessages: function($messages) { addMessages: function($messages) {
var playSound = true;
mChat.cached('messages').find('.mchat-no-messages').remove(); mChat.cached('messages').find('.mchat-no-messages').remove();
$messages.reverse(mChat.messageTop).hide().each(function(i) { $messages.reverse(mChat.messageTop).hide().each(this.addMessage);
var $message = $(this); },
var dataAddMessageBefore = { addMessage: function(index) {
message: $message, var $message = $(this);
delay: mChat.refreshInterval ? 400 : 0, var dataAddMessageBefore = {
abort: $.inArray($message.data('mchat-id'), mChat.messageIds) !== -1, message: $message,
playSound: playSound delay: mChat.refreshInterval ? 400 : 0,
}; abort: $.inArray($message.data('mchat-id'), mChat.messageIds) !== -1,
$(mChat).trigger('mchat_add_message_before', [dataAddMessageBefore]); playSound: index === 0,
if (dataAddMessageBefore.abort) { titleAlert: index === 0
return; };
} $(mChat).trigger('mchat_add_message_before', [dataAddMessageBefore]);
if (dataAddMessageBefore.playSound) { if (dataAddMessageBefore.abort) {
mChat.sound('add'); return;
mChat.titleAlert(); }
playSound = false; if (dataAddMessageBefore.playSound) {
} mChat.sound('add');
mChat.messageIds.push($message.data('mchat-id')); }
mChat.fixJumpToUrl.call($message); if (dataAddMessageBefore.titleAlert) {
setTimeout(function() { mChat.titleAlert();
var dataAddMessageAnimateBefore = { }
container: mChat.cached('messages'), mChat.messageIds.push($message.data('mchat-id'));
message: $message, mChat.fixJumpToUrl.call($message);
add: function() { var dataAddMessageAnimateBefore = {
if (mChat.messageTop) { container: mChat.cached('messages'),
this.container.prepend(this.message); message: $message,
} else { add: function() {
this.container.append(this.message); if (mChat.messageTop) {
} this.container.prepend(this.message);
}, } else {
show: function() { this.container.append(this.message);
var container = this.container; }
var scrollTop = container.scrollTop(); },
var scrollLeeway = 20; show: function() {
if (mChat.messageTop && scrollTop <= scrollLeeway || !mChat.messageTop && scrollTop >= container.get(0).scrollHeight - container.height() - scrollLeeway) { var scrollLeeway = 20;
var animateOptions = { var scrollTop = this.container.scrollTop();
duration: dataAddMessageBefore.delay - 10, var scrollHeight = this.container[0].scrollHeight;
easing: 'swing' this.message.show();
}; this.message.addClass('mchat-message-flash');
this.message.slideDown(animateOptions); if (mChat.messageTop) {
if (mChat.messageTop) { if (scrollTop <= scrollLeeway) {
container.animate({scrollTop: 0}, animateOptions); this.container.scrollTop(0);
} else {
animateOptions.complete = function() {
var scrollHeight = container.get(0).scrollHeight;
if (container.scrollTop() + container.innerHeight() < scrollHeight) {
container.animate({scrollTop: scrollHeight}, animateOptions);
}
};
animateOptions.complete();
}
} else {
this.message.show();
if (mChat.messageTop) {
this.container.scrollTop(scrollTop + this.message.outerHeight());
}
}
this.message.addClass('mchat-message-flash');
} }
}; } else {
$(mChat).trigger('mchat_add_message_animate_before', [dataAddMessageAnimateBefore]); var height = this.container.height();
dataAddMessageAnimateBefore.add(); if (scrollHeight - height - scrollTop <= scrollLeeway) {
dataAddMessageAnimateBefore.show(); this.container.scrollTop(scrollHeight);
}, i * dataAddMessageBefore.delay); }
if (mChat.editDeleteLimit && $message.data('mchat-edit-delete-limit') && $message.find('[data-mchat-action="edit"], [data-mchat-action="del"]').length > 0) { }
var id = $message.prop('id');
setTimeout(function() {
$('#' + id).find('[data-mchat-action="edit"], [data-mchat-action="del"]').fadeOut(function() {
$(this).closest('li').remove();
});
}, mChat.editDeleteLimit);
} }
mChat.startRelativeTimeUpdate.call($message); };
}); $(mChat).trigger('mchat_add_message_animate_before', [dataAddMessageAnimateBefore]);
dataAddMessageAnimateBefore.add();
dataAddMessageAnimateBefore.show();
if (mChat.editDeleteLimit && $message.data('mchat-edit-delete-limit') && $message.find('[data-mchat-action="edit"], [data-mchat-action="del"]').length > 0) {
var id = $message.prop('id');
setTimeout(function() {
$('#' + id).find('[data-mchat-action="edit"], [data-mchat-action="del"]').fadeOut(function() {
$(this).closest('li').remove();
});
}, mChat.editDeleteLimit);
}
mChat.startRelativeTimeUpdate.call($message);
}, },
updateMessages: function($messages) { updateMessages: function($messages) {
var playSound = true; var playSound = true;
@@ -729,7 +717,22 @@ jQuery(function($) {
mChat.cache[name] = $('#mchat-' + name); mChat.cache[name] = $('#mchat-' + name);
} }
return mChat.cache[name]; return mChat.cache[name];
} },
onKeyPress: function(e, callbacks) {
var isEnter = e.which === 10 || e.which === 13;
if (isEnter && $(e.target).is('textarea')) {
var callback;
var isCtrl = e.ctrlKey || e.metaKey;
if (!mChat.maxInputHeight || !isCtrl === !mChat.storage.get('no_enter')) {
callback = 'submit';
} else if (mChat.maxInputHeight && isCtrl) {
callback = 'newline';
}
if (typeof callbacks[callback] === 'function') {
callbacks[callback].call(this, e);
}
}
},
}); });
mChat.messageIds = mChat.cached('messages').children() mChat.messageIds = mChat.cached('messages').children()
@@ -737,6 +740,10 @@ jQuery(function($) {
.each(mChat.fixJumpToUrl) .each(mChat.fixJumpToUrl)
.map(function() { return $(this).data('mchat-id'); }).get(); .map(function() { return $(this).data('mchat-id'); }).get();
if (!mChat.messageIds.length) {
mChat.messageIds.push(mChat.latestMessageId);
}
mChat.hiddenFields = {}; mChat.hiddenFields = {};
mChat.cached('form').find('input[type=hidden]').each(function() { mChat.cached('form').find('input[type=hidden]').each(function() {
mChat.hiddenFields[this.name] = this.value; mChat.hiddenFields[this.name] = this.value;
@@ -772,10 +779,9 @@ jQuery(function($) {
}); });
$.each(['userlist', 'smilies', 'bbcodes', 'colour'], function(i, elem) { $.each(['userlist', 'smilies', 'bbcodes', 'colour'], function(i, elem) {
if (mChat.storage.get('show_' + elem)) { var isVisible = mChat.storage.get('show_' + elem) === 'yes';
$('.mchat-button-' + elem).addClass('mchat-button-is-down'); $('.mchat-button-' + elem).toggleClass('mchat-button-is-down', isVisible);
mChat.cached(elem).toggle(); mChat.cached(elem).toggle(isVisible);
}
}); });
var toggleRememberColor = function() { var toggleRememberColor = function() {
@@ -827,19 +833,18 @@ jQuery(function($) {
}); });
} }
mChat.cached('form').submit(function(e) { mChat.cached('form').on('submit', function(e) {
e.preventDefault(); e.preventDefault();
}).keypress(function(e) { }).on('keypress', function(e) {
var isEnter = e.which === 10 || e.which === 13; mChat.onKeyPress(e, {
if (isEnter && mChat.cached('input').is(e.target)) { 'submit': function(e) {
var isCtrl = e.ctrlKey || e.metaKey;
if (!mChat.maxInputHeight || !isCtrl === !mChat.storage.get('no_enter')) {
e.preventDefault(); e.preventDefault();
mChat.add(); mChat.add();
} else if (mChat.maxInputHeight && isCtrl) { },
'newline': function() {
mChat.appendText('\n'); mChat.appendText('\n');
} }
} });
}); });
if (mChat.showCharCount || mChat.mssgLngth) { if (mChat.showCharCount || mChat.mssgLngth) {
@@ -870,9 +875,19 @@ jQuery(function($) {
e.preventDefault(); e.preventDefault();
mChat.jumpToMessage.call(this); mChat.jumpToMessage.call(this);
}).on('click', '.mchat-panel-buttons button', function() { }).on('click', '.mchat-panel-buttons button', function() {
var $this = $(this).blur(); var $this = $(this).trigger('blur');
if ($this.hasClass('mchat-button-down')) { if ($this.hasClass('mchat-button-down')) {
$this.toggleClass('mchat-button-is-down'); $this.toggleClass('mchat-button-is-down');
} }
}).on('keydown.phpbb.alert', mChat.cached('confirm'), function(e) {
mChat.onKeyPress(e, {
'newline': function(e) {
e.stopImmediatePropagation();
var $target = $(e.target);
$target.val(function(i, text) {
return text + '\n';
});
}
});
}); });
}); });

View File

@@ -35,6 +35,7 @@
maxInputHeight : {{ MCHAT_MAX_INPUT_HEIGHT }}, maxInputHeight : {{ MCHAT_MAX_INPUT_HEIGHT }},
editDeleteLimit : {{ MCHAT_EDIT_DELETE_LIMIT }}, editDeleteLimit : {{ MCHAT_EDIT_DELETE_LIMIT }},
logId : {{ MCHAT_LOG_ID }}, logId : {{ MCHAT_LOG_ID }},
latestMessageId : {{ MCHAT_LATEST_MESSAGE_ID | default(0) }},
removeBBCodes : '{{ MCHAT_DISALLOWED_BBCODES | escape('js') }}', removeBBCodes : '{{ MCHAT_DISALLOWED_BBCODES | escape('js') }}',
// Language // Language

View File

@@ -84,13 +84,13 @@
{% EVENT dmzx_mchat_static_container_after %} {% EVENT dmzx_mchat_static_container_after %}
{% endif %} {% endif %}
<div id="mchat-main"{% if MCHAT_MESSAGE_TOP %} class="mchat-messages-top"{% endif %}> <div id="mchat-main" class="{{ MCHAT_MESSAGE_TOP ? 'mchat-messages-top' : 'mchat-messages-bottom' }}">
{% EVENT dmzx_mchat_messages_container_before %} {% EVENT dmzx_mchat_messages_container_before %}
<ul id="mchat-messages" class="topiclist forums"> <ul id="mchat-messages" class="topiclist forums">
{% if loops.mchatrow|length %} {% if loops.mchatrow|length %}
{% INCLUDE '@dmzx_mchat/mchat_messages.html' %} {% INCLUDE '@dmzx_mchat/mchat_messages.html' %}
{% else %} {% elseif not MCHAT_TOTAL_MESSAGES %}
<li class="row mchat-static mchat-no-messages">{{ lang('MCHAT_NOMESSAGE') }}</li> <li class="row mchat-static mchat-no-messages">{{ lang('MCHAT_NOMESSAGE') }}</li>
{% endif %} {% endif %}
</ul> </ul>

View File

@@ -12,14 +12,14 @@
{% if definition.MCHAT_ALLOW_MENTION or definition.MCHAT_ALLOW_QUOTE or definition.MCHAT_ALLOW_LIKE or definition.MCHAT_ALLOW_PM or MCHAT_ALLOW_IP or MCHAT_ALLOW_PERMISSIONS or definition.MCHAT_ALLOW_EDIT or definition.MCHAT_ALLOW_DEL or definition.MCHAT_ADD_CUSTOM_BUTTON %} {% if definition.MCHAT_ALLOW_MENTION or definition.MCHAT_ALLOW_QUOTE or definition.MCHAT_ALLOW_LIKE or definition.MCHAT_ALLOW_PM or MCHAT_ALLOW_IP or MCHAT_ALLOW_PERMISSIONS or definition.MCHAT_ALLOW_EDIT or definition.MCHAT_ALLOW_DEL or definition.MCHAT_ADD_CUSTOM_BUTTON %}
<ul class="mchat-buttons"> <ul class="mchat-buttons">
{% EVENT dmzx_mchat_messages_icons_add_before %} {% EVENT dmzx_mchat_messages_icons_add_before %}
{% if definition.MCHAT_ALLOW_MENTION %}<li><a href="#" title="{{ lang('MCHAT_RESPOND') }}" data-mchat-action="mention"><i class="fa fa-at"><span>{{ lang('MCHAT_RESPOND') }}</span></i></a></li>{% endif %} {% if definition.MCHAT_ALLOW_MENTION %}<li><a href="#" title="{{ lang('MCHAT_RESPOND') }}" data-mchat-action="mention"><i class="icon fa-at"><span>{{ lang('MCHAT_RESPOND') }}</span></i></a></li>{% endif %}
{% if definition.MCHAT_ALLOW_QUOTE %}<li><a href="#" title="{{ lang('REPLY_WITH_QUOTE') }}" data-mchat-action="quote"><i class="fa fa-quote-left"><span>{{ lang('REPLY_WITH_QUOTE') }}</span></i></a></li>{% endif %} {% if definition.MCHAT_ALLOW_QUOTE %}<li><a href="#" title="{{ lang('REPLY_WITH_QUOTE') }}" data-mchat-action="quote"><i class="icon fa-quote-left"><span>{{ lang('REPLY_WITH_QUOTE') }}</span></i></a></li>{% endif %}
{% if definition.MCHAT_ALLOW_LIKE %}<li><a href="#" title="{{ lang('MCHAT_LIKE') }}" data-mchat-action="like"><i class="fa fa-thumbs-o-up"><span>{{ lang('MCHAT_LIKE') }}</span></i></a></li>{% endif %} {% if definition.MCHAT_ALLOW_LIKE %}<li><a href="#" title="{{ lang('MCHAT_LIKE') }}" data-mchat-action="like"><i class="icon fa-thumbs-o-up"><span>{{ lang('MCHAT_LIKE') }}</span></i></a></li>{% endif %}
{% if definition.MCHAT_ALLOW_PM %}<li><a href="{{ mchatrow.MCHAT_PM }}" title="{{ lang('MCHAT_SEND_PM') }}"><i class="fa fa-envelope-o"><span>{{ lang('MCHAT_SEND_PM') }}</span></i></a></li>{% endif %} {% if definition.MCHAT_ALLOW_PM %}<li><a href="{{ mchatrow.MCHAT_PM }}" title="{{ lang('MCHAT_SEND_PM') }}"><i class="icon fa-envelope-o"><span>{{ lang('MCHAT_SEND_PM') }}</span></i></a></li>{% endif %}
{% if definition.MCHAT_ALLOW_IP %}<li><a href="{{ mchatrow.MCHAT_U_IP }}" title="{{ mchatrow.MCHAT_WHOIS_USER }}" data-mchat-action="ip"><i class="fa fa-wifi"><span>{{ mchatrow.MCHAT_WHOIS_USER }}</span></i></a></li>{% endif %} {% if definition.MCHAT_ALLOW_IP %}<li><a href="{{ mchatrow.MCHAT_U_IP }}" title="{{ mchatrow.MCHAT_WHOIS_USER }}" data-mchat-action="ip"><i class="icon fa-wifi"><span>{{ mchatrow.MCHAT_WHOIS_USER }}</span></i></a></li>{% endif %}
{% if definition.MCHAT_ALLOW_PERMISSIONS %}<li><a href="{{ mchatrow.MCHAT_U_PERMISSIONS }}" title="{{ lang('MCHAT_PERMISSIONS') }}"><i class="fa fa-exclamation-triangle"><span>{{ lang('MCHAT_PERMISSIONS') }}</span></i></a></li>{% endif %} {% if definition.MCHAT_ALLOW_PERMISSIONS %}<li><a href="{{ mchatrow.MCHAT_U_PERMISSIONS }}" title="{{ lang('MCHAT_PERMISSIONS') }}"><i class="icon fa-exclamation-triangle"><span>{{ lang('MCHAT_PERMISSIONS') }}</span></i></a></li>{% endif %}
{% if definition.MCHAT_ALLOW_EDIT %}<li><a href="#" title="{{ lang('MCHAT_EDIT') }}" data-mchat-action="edit"><i class="fa fa-pencil"><span>{{ lang('MCHAT_EDIT') }}</span></i></a></li>{% endif %} {% if definition.MCHAT_ALLOW_EDIT %}<li><a href="#" title="{{ lang('MCHAT_EDIT') }}" data-mchat-action="edit"><i class="icon fa-pencil"><span>{{ lang('MCHAT_EDIT') }}</span></i></a></li>{% endif %}
{% if definition.MCHAT_ALLOW_DEL %}<li><a href="#" title="{{ lang('DELETE') }}" data-mchat-action="del"><i class="fa fa-trash-o"><span>{{ lang('DELETE') }}</span></i></a></li>{% endif %} {% if definition.MCHAT_ALLOW_DEL %}<li><a href="#" title="{{ lang('DELETE') }}" data-mchat-action="del"><i class="icon fa-trash-o"><span>{{ lang('DELETE') }}</span></i></a></li>{% endif %}
{% EVENT dmzx_mchat_messages_icons_add_after %} {% EVENT dmzx_mchat_messages_icons_add_after %}
</ul> </ul>
{% endif %} {% endif %}

View File

@@ -26,11 +26,11 @@
display: -ms-flexbox; display: -ms-flexbox;
display: flex; display: flex;
-webkit-box-align: center; -webkit-box-align: center;
-ms-flex-align: center; -ms-flex-align: center;
align-items: center; align-items: center;
-webkit-box-pack: left; -webkit-box-pack: start;
-ms-flex-pack: left; -ms-flex-pack: start;
justify-content: left; justify-content: start;
} }
.mchat-wrapper li.header dd { .mchat-wrapper li.header dd {
@@ -118,7 +118,7 @@
.mchat-avatar { .mchat-avatar {
float: left; float: left;
width: 40px; width: 36px;
margin-right: 5px; margin-right: 5px;
} }
@@ -149,7 +149,7 @@
margin: 0 3px; margin: 0 3px;
} }
.mchat-wrapper .mchat-buttons .fa { .mchat-wrapper .mchat-buttons .icon {
font-size: 12pt; font-size: 12pt;
} }
@@ -164,7 +164,7 @@
.mchat-text { .mchat-text {
clear: both; clear: both;
overflow: hidden; overflow: hidden;
padding: 2px 5px; padding: 0 5px 1px;
font-size: 1.2em; font-size: 1.2em;
} }