From 006a4e404e42cf8f56d7524f45fcd34ff8e9087e Mon Sep 17 00:00:00 2001
From: dmzx {{ lang('MCHAT_TITLE') }}
{{ lang('MCHAT_VERSION') ~ lang('COLON') }} {{ MCHAT_VERSION }}
@@ -20,12 +26,12 @@
{{ lang('MCHAT_INDEX_HEIGHT_EXPLAIN') }}
{% EVENT dmzx_mchat_acp_message_num_index_after %}
@@ -41,28 +47,18 @@
{{ lang('MCHAT_MESSAGE_NUM_INDEX_EXPLAIN') }}
-
{{ lang('MCHAT_CUSTOM_HEIGHT_EXPLAIN') }}
-
{{ lang('MCHAT_MESSAGE_NUM_CUSTOM_EXPLAIN') }}
-
-
-
-
-
{% EVENT dmzx_mchat_acp_navbar_link_count_after %}
@@ -76,7 +72,7 @@
{% EVENT dmzx_mchat_acp_message_num_archive_after %}
@@ -84,9 +80,9 @@
{{ lang('MCHAT_MESSAGE_NUM_ARCHIVE_EXPLAIN') }}
@@ -98,45 +94,50 @@
-
-
+
+
+
{{ lang('MCHAT_TIMEOUT_EXPLAIN') }}
{{ lang('MCHAT_REFRESH_EXPLAIN') }}
- {{ lang('MCHAT_EDIT_DELETE_LIMIT_EXPLAIN') }}
-
{{ lang('MCHAT_LIVE_UPDATES_EXPLAIN') }}
{{ lang('MCHAT_FLOOD_TIME_EXPLAIN') }}
+
{{ lang('MCHAT_MAX_MESSAGE_LENGTH_EXPLAIN') }}
+
+ {{ lang('MCHAT_MAX_INPUT_HEIGHT_EXPLAIN') }}
{{ lang('MCHAT_OVERRIDE_MIN_POST_CHARS_EXPLAIN') }}
{{ lang('MCHAT_OVERRIDE_SMILIE_LIMIT_EXPLAIN') }}
@@ -165,44 +166,44 @@
@@ -217,7 +218,12 @@
{{ lang('MCHAT_POSTS_AUTH_CHECK_EXPLAIN') }}
+
{{ lang('MCHAT_WHOIS_REFRESH_EXPLAIN') }}
+
+
{% EVENT dmzx_mchat_acp_whois_refresh_after %}
@@ -231,19 +237,19 @@
-
{{ lang('MCHAT_PRUNE_GC_EXPLAIN') }}
{{ lang('MCHAT_PRUNE_NUM_EXPLAIN') }}
{% EVENT dmzx_mchat_acp_purge_after %}
+
+
+
{% endif %}
@@ -278,8 +300,8 @@
diff --git a/adm/style/acp_mchat_globalusersettings.html b/adm/style/acp_mchat_globalusersettings.html
index f803382..5ac1491 100644
--- a/adm/style/acp_mchat_globalusersettings.html
+++ b/adm/style/acp_mchat_globalusersettings.html
@@ -23,23 +23,23 @@
{{ lang('MCHAT_GLOBALUSERSETTINGS_OVERWRITE_EXPLAIN') }}
diff --git a/adm/style/acp_mchat_globalusersettings_content.html b/adm/style/acp_mchat_globalusersettings_content.html
index 16ccb08..8e0cdf8 100644
--- a/adm/style/acp_mchat_globalusersettings_content.html
+++ b/adm/style/acp_mchat_globalusersettings_content.html
@@ -3,85 +3,78 @@
{{ lang('MCHAT_STATS_INDEX_EXPLAIN') }}
{% EVENT dmzx_mchat_acp_location_after %}
-
+
{% EVENT dmzx_mchat_acp_message_top_before %}
{{ lang('MCHAT_MESSAGE_TOP_EXPLAIN') }}
-
-
{{ lang('MCHAT_PAUSE_ON_INPUT_EXPLAIN') }}
@@ -91,27 +84,31 @@
{{ S_MCHAT_DATEFORMAT_OPTIONS }}
{% EVENT dmzx_mchat_acp_relative_time_after %}
-
{{ lang('MCHAT_RELATIVE_TIME_EXPLAIN') }}
+
{% EVENT dmzx_mchat_acp_posts_before %}
diff --git a/composer.json b/composer.json
index bbd90cd..a65c00d 100644
--- a/composer.json
+++ b/composer.json
@@ -3,10 +3,10 @@
"type": "phpbb-extension",
"description": "mChat",
"homepage": "https://www.phpbb.com/customise/db/extension/mchat_extension/",
- "version": "2.0.3",
- "time": "2017-12-31",
+ "version": "2.1.0",
+ "time": "2018-06-22",
"keywords": ["phpbb", "extension", "mchat"],
- "license": "GPL-2.0",
+ "license": "GPL-2.0-only",
"authors": [
{
"name": "kasimi",
@@ -27,7 +27,7 @@
}
],
"require": {
- "php": ">=5.3.3",
+ "php": ">=5.4.7",
"composer/installers": "~1.0"
},
"require-dev": {
@@ -36,7 +36,7 @@
"extra": {
"display-name": "mChat",
"soft-require": {
- "phpbb/phpbb": ">=3.1.8-RC1"
+ "phpbb/phpbb": ">=3.2.0"
},
"version-check": {
"host": "www.phpbb.com",
diff --git a/config/services.yml b/config/services.yml
index 34fdf6c..1cc5b91 100644
--- a/config/services.yml
+++ b/config/services.yml
@@ -2,6 +2,7 @@ imports:
- { resource: tables.yml }
services:
+
dmzx.mchat.acp.controller:
class: dmzx\mchat\controller\acp_controller
arguments:
@@ -9,89 +10,119 @@ services:
- '@template'
- '@log'
- '@user'
+ - '@language'
- '@dbal.conn'
- '@cache.driver'
- '@request'
- '@dispatcher'
- '@dmzx.mchat.settings'
- - '%dmzx.mchat.table.mchat%'
- - '%dmzx.mchat.table.mchat_log%'
- - '%core.root_path%'
- - '%core.php_ext%'
+
dmzx.mchat.ucp.controller:
class: dmzx\mchat\controller\ucp_controller
arguments:
- '@template'
- '@user'
+ - '@language'
- '@auth'
- '@dbal.conn'
- '@request'
- '@dmzx.mchat.settings'
- '@dispatcher'
- - '%core.root_path%'
- - '%core.php_ext%'
+
+ dmzx.mchat.notifications:
+ class: dmzx\mchat\core\notifications
+ arguments:
+ - '@dmzx.mchat.settings'
+ - '@user'
+ - '@language'
+ - '@auth'
+ - '@dbal.conn'
+ - '@dispatcher'
+ - '@text_formatter.parser'
+
+ dmzx.mchat.log:
+ class: dmzx\mchat\core\log
+ arguments:
+ - '@dmzx.mchat.settings'
+ - '@user'
+ - '@dbal.conn'
+ - '@cache.driver'
+ - '@dispatcher'
+
dmzx.mchat.core:
class: dmzx\mchat\core\mchat
arguments:
- '@dmzx.mchat.functions'
+ - '@dmzx.mchat.notifications'
- '@dmzx.mchat.settings'
+ - '@dmzx.mchat.log'
- '@controller.helper'
- '@template'
- '@user'
+ - '@language'
- '@auth'
- '@pagination'
- '@request'
- '@dispatcher'
- '@ext.manager'
- - '%core.root_path%'
- - '%core.php_ext%'
- - '@?text_formatter.s9e.parser'
+ - '@text_formatter.parser'
- '@?phpbb.collapsiblecategories.operator'
+
dmzx.mchat.functions:
class: dmzx\mchat\core\functions
arguments:
- '@dmzx.mchat.settings'
+ - '@dmzx.mchat.notifications'
+ - '@dmzx.mchat.log'
- '@user'
+ - '@language'
- '@auth'
- '@log'
- '@dbal.conn'
- '@cache.driver'
- '@dispatcher'
+ - '@group_helper'
+ - '@text_formatter.parser'
+
+ dmzx.mchat.settings:
+ class: dmzx\mchat\core\settings
+ arguments:
+ - '@user'
+ - '@language'
+ - '@config'
+ - '@config_text'
+ - '@auth'
+ - '@dispatcher'
- '%core.root_path%'
- '%core.php_ext%'
- '%dmzx.mchat.table.mchat%'
- '%dmzx.mchat.table.mchat_log%'
- '%dmzx.mchat.table.mchat_sessions%'
- dmzx.mchat.settings:
- class: dmzx\mchat\core\settings
- arguments:
- - '@user'
- - '@config'
- - '@config_text'
- - '@auth'
- - '@dispatcher'
+
dmzx.mchat.acp.listener:
class: dmzx\mchat\event\acp_listener
arguments:
- '@template'
- '@request'
- - '@user'
+ - '@language'
- '@dmzx.mchat.settings'
- '@dmzx.mchat.functions'
- - '%core.root_path%'
- - '%core.php_ext%'
tags:
- { name: event.listener }
+
dmzx.mchat.main.listener:
class: dmzx\mchat\event\main_listener
arguments:
- '@dmzx.mchat.core'
+ - '@dmzx.mchat.notifications'
- '@controller.helper'
- '@user'
+ - '@language'
- '@request'
- '%core.php_ext%'
tags:
- { name: event.listener }
+
dmzx.mchat.cron.task.mchat_prune:
class: dmzx\mchat\cron\mchat_prune
arguments:
@@ -101,3 +132,27 @@ services:
- [set_name, [cron.task.mchat_prune]]
tags:
- { name: cron.task }
+
+ dmzx.mchat.text_reparser.mchat_messages:
+ class: dmzx\mchat\textreparser\plugins\mchat_messages
+ arguments:
+ - '@dbal.conn'
+ - '%dmzx.mchat.table.mchat%'
+ calls:
+ - [set_name, [dmzx.mchat.text_reparser.mchat_messages]]
+ tags:
+ - { name: text_reparser.plugin }
+
+ dmzx.mchat.text_reparser.reparser:
+ class: phpbb\cron\task\text_reparser\reparser
+ arguments:
+ - '@config'
+ - '@config_text'
+ - '@text_reparser.lock'
+ - '@text_reparser.manager'
+ - '@text_reparser_collection'
+ calls:
+ - [set_name, [dmzx.mchat.text_reparser.reparser]]
+ - [set_reparser, [dmzx.mchat.text_reparser.mchat_messages]]
+ tags:
+ - { name: cron.task }
diff --git a/controller/acp_controller.php b/controller/acp_controller.php
index 443ee8a..4f17992 100644
--- a/controller/acp_controller.php
+++ b/controller/acp_controller.php
@@ -16,6 +16,7 @@ use dmzx\mchat\core\settings;
use phpbb\cache\driver\driver_interface as cache_interface;
use phpbb\db\driver\driver_interface as db_interface;
use phpbb\event\dispatcher_interface;
+use phpbb\language\language;
use phpbb\log\log_interface;
use phpbb\request\request_interface;
use phpbb\template\template;
@@ -24,7 +25,7 @@ use phpbb\user;
class acp_controller
{
/** @var functions */
- protected $functions;
+ protected $mchat_functions;
/** @var template */
protected $template;
@@ -35,6 +36,9 @@ class acp_controller
/** @var user */
protected $user;
+ /** @var language */
+ protected $lang;
+
/** @var db_interface */
protected $db;
@@ -50,64 +54,43 @@ class acp_controller
/** @var settings */
protected $settings;
- /** @var string */
- protected $mchat_table;
-
- /** @var string */
- protected $mchat_log_table;
-
- /** @var string */
- protected $root_path;
-
- /** @var string */
- protected $php_ext;
-
/**
* Constructor
*
- * @param functions $functions
+ * @param functions $mchat_functions
* @param template $template
* @param log_interface $log
* @param user $user
+ * @param language $lang
* @param db_interface $db
* @param cache_interface $cache
* @param request_interface $request
* @param dispatcher_interface $dispatcher
* @param settings $settings
- * @param string $mchat_table
- * @param string $mchat_log_table
- * @param string $root_path
- * @param string $php_ext
*/
public function __construct(
- functions $functions,
+ functions $mchat_functions,
template $template,
log_interface $log,
user $user,
+ language $lang,
db_interface $db,
cache_interface $cache,
request_interface $request,
dispatcher_interface $dispatcher,
- settings $settings,
- $mchat_table,
- $mchat_log_table,
- $root_path,
- $php_ext
+ settings $settings
)
{
- $this->functions = $functions;
+ $this->mchat_functions = $mchat_functions;
$this->template = $template;
$this->log = $log;
$this->user = $user;
+ $this->lang = $lang;
$this->db = $db;
$this->cache = $cache;
$this->request = $request;
$this->dispatcher = $dispatcher;
$this->settings = $settings;
- $this->mchat_table = $mchat_table;
- $this->mchat_log_table = $mchat_log_table;
- $this->root_path = $root_path;
- $this->php_ext = $php_ext;
}
/**
@@ -119,7 +102,7 @@ class acp_controller
{
add_form_key('acp_mchat');
- $error = array();
+ $error = [];
$is_founder = $this->user->data['user_type'] == USER_FOUNDER;
@@ -127,8 +110,8 @@ class acp_controller
if ($this->request->is_set_post('submit'))
{
- $mchat_new_config = array();
- $validation = array();
+ $mchat_new_config = [];
+ $validation = [];
foreach ($settings as $config_name => $config_data)
{
$default = $this->settings->cfg($config_name);
@@ -143,19 +126,19 @@ class acp_controller
// Remove leading & trailing | characters to not break allowed BBCodes
$mchat_new_config['mchat_bbcode_disallowed'] = trim($mchat_new_config['mchat_bbcode_disallowed'], '|');
- // Don't allow changing pruning settings for non founders
if (!$is_founder)
{
+ // Don't allow changing pruning settings for non founders
unset($mchat_new_config['mchat_prune']);
unset($mchat_new_config['mchat_prune_gc']);
unset($mchat_new_config['mchat_prune_mode']);
unset($mchat_new_config['mchat_prune_num']);
+
+ // Don't allow changing log settings for non founders
+ unset($mchat_new_config['mchat_log_enabled']);
}
- if (!function_exists('validate_data'))
- {
- include($this->root_path . 'includes/functions_user.' . $this->php_ext);
- }
+ $this->settings->include_functions('user', 'validate_data');
$error = array_merge($error, validate_data($mchat_new_config, $validation));
@@ -172,10 +155,10 @@ class acp_controller
* @var array error Array with error lang keys
* @since 2.0.0-RC7
*/
- $vars = array(
+ $vars = [
'mchat_new_config',
'error',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.acp_globalsettings_update_data', compact($vars)));
if (!$error)
@@ -187,41 +170,50 @@ class acp_controller
}
// Add an entry into the log table
- $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_CONFIG_UPDATE', false, array($this->user->data['username']));
+ $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_CONFIG_UPDATE', false, [$this->user->data['username']]);
- trigger_error($this->user->lang('MCHAT_CONFIG_SAVED') . adm_back_link($u_action));
+ trigger_error($this->lang->lang('MCHAT_CONFIG_SAVED') . adm_back_link($u_action));
}
// Replace "error" strings with their real, localised form
- $error = array_map(array($this->user, 'lang'), $error);
+ $error = array_map([$this->lang, 'lang'], $error);
}
if (!$error)
{
if ($is_founder && $this->request->is_set_post('mchat_purge') && $this->request->variable('mchat_purge_confirm', false) && check_form_key('acp_mchat'))
{
- $this->db->sql_query('DELETE FROM ' . $this->mchat_table);
- $this->db->sql_query('DELETE FROM ' . $this->mchat_log_table);
- $this->cache->destroy('sql', $this->mchat_log_table);
- $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PURGED', false, array($this->user->data['username']));
- trigger_error($this->user->lang('MCHAT_PURGED') . adm_back_link($u_action));
+ /**
+ * Event that is triggered right before all mChat messages are
+ * deleted when using the Delete all messages button in the ACP
+ *
+ * @event dmzx.mchat.purge_before
+ * @since 2.1.0-RC1
+ */
+ $this->dispatcher->dispatch('dmzx.mchat.purge_before');
+
+ $this->db->sql_query('DELETE FROM ' . $this->settings->get_table_mchat());
+ $this->db->sql_query('DELETE FROM ' . $this->settings->get_table_mchat_log());
+ $this->cache->destroy('sql', $this->settings->get_table_mchat_log());
+ $this->mchat_functions->phpbb_log('LOG_MCHAT_TABLE_PURGED');
+ trigger_error($this->lang->lang('MCHAT_PURGED') . adm_back_link($u_action));
}
else if ($is_founder && $this->request->is_set_post('mchat_prune_now') && $this->request->variable('mchat_prune_now_confirm', false) && check_form_key('acp_mchat'))
{
- $num_pruned_messages = count($this->functions->mchat_prune());
- trigger_error($this->user->lang('MCHAT_PRUNED', $num_pruned_messages) . adm_back_link($u_action));
+ $num_pruned_messages = count($this->mchat_functions->mchat_prune());
+ trigger_error($this->lang->lang('MCHAT_PRUNED', $num_pruned_messages) . adm_back_link($u_action));
}
}
- $template_data = array(
+ $template_data = [
'MCHAT_ERROR' => implode('
', $error),
'MCHAT_VERSION' => $this->settings->cfg('mchat_version'),
'MCHAT_FOUNDER' => $is_founder,
'S_MCHAT_PRUNE_MODE_OPTIONS' => $this->get_prune_mode_options($this->settings->cfg('mchat_prune_mode')),
- 'L_MCHAT_BBCODES_DISALLOWED_EXPLAIN' => $this->user->lang('MCHAT_BBCODES_DISALLOWED_EXPLAIN', 'root_path}adm/index.$this->php_ext", 'i=bbcodes', true, $this->user->session_id) . '">', ''),
- 'L_MCHAT_TIMEOUT_EXPLAIN' => $this->user->lang('MCHAT_TIMEOUT_EXPLAIN','root_path}adm/index.$this->php_ext", 'i=board&mode=load', true, $this->user->session_id) . '">', '', $this->settings->cfg('session_length')),
+ 'L_MCHAT_BBCODES_DISALLOWED_EXPLAIN' => $this->lang->lang('MCHAT_BBCODES_DISALLOWED_EXPLAIN', '', ''),
+ 'L_MCHAT_TIMEOUT_EXPLAIN' => $this->lang->lang('MCHAT_TIMEOUT_EXPLAIN','', '', $this->settings->cfg('session_length')),
'U_ACTION' => $u_action,
- );
+ ];
foreach (array_keys($settings) as $key)
{
@@ -236,10 +228,10 @@ class acp_controller
* @var array error Array with error lang keys
* @since 2.0.0-RC7
*/
- $vars = array(
+ $vars = [
'template_data',
'error',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.acp_globalsettings_modify_template_data', compact($vars)));
$this->template->assign_vars($template_data);
@@ -252,12 +244,12 @@ class acp_controller
{
add_form_key('acp_mchat');
- $error = array();
+ $error = [];
if ($this->request->is_set_post('submit'))
{
- $mchat_new_config = array();
- $validation = array();
+ $mchat_new_config = [];
+ $validation = [];
foreach ($this->settings->ucp_settings() as $config_name => $config_data)
{
$default = $this->settings->cfg($config_name, true);
@@ -270,10 +262,7 @@ class acp_controller
}
}
- if (!function_exists('validate_data'))
- {
- include($this->root_path . 'includes/functions_user.' . $this->php_ext);
- }
+ $this->settings->include_functions('user', 'validate_data');
$error = array_merge($error, validate_data($mchat_new_config, $validation));
@@ -282,7 +271,7 @@ class acp_controller
$error[] = 'FORM_INVALID';
}
- $mchat_new_user_config = array();
+ $mchat_new_user_config = [];
if ($this->request->variable('mchat_overwrite', 0) && $this->request->variable('mchat_overwrite_confirm', 0))
{
@@ -301,11 +290,11 @@ class acp_controller
* @var array error Array with error lang keys
* @since 2.0.0-RC7
*/
- $vars = array(
+ $vars = [
'mchat_new_config',
'mchat_new_user_config',
'error',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.acp_globalusersettings_update_data', compact($vars)));
if (!$error)
@@ -323,13 +312,13 @@ class acp_controller
}
// Add an entry into the log table
- $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_CONFIG_UPDATE', false, array($this->user->data['username']));
+ $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_CONFIG_UPDATE', false, [$this->user->data['username']]);
- trigger_error($this->user->lang('MCHAT_CONFIG_SAVED') . adm_back_link($u_action));
+ trigger_error($this->lang->lang('MCHAT_CONFIG_SAVED') . adm_back_link($u_action));
}
// Replace "error" strings with their real, localised form
- $error = array_map(array($this->user, 'lang'), $error);
+ $error = array_map([$this->lang, 'lang'], $error);
}
// Force global date format for $selected_date value, not user-specific
@@ -341,12 +330,12 @@ class acp_controller
$template_data[strtoupper($key)] = $this->settings->cfg($key, true);
}
- $template_data = array_merge($template_data, array(
+ $template_data = array_merge($template_data, [
'MCHAT_POSTS_ENABLED_LANG' => $this->settings->get_enabled_post_notifications_lang(),
'MCHAT_ERROR' => implode('
', $error),
'MCHAT_VERSION' => $this->settings->cfg('mchat_version'),
'U_ACTION' => $u_action,
- ));
+ ]);
/**
* Event to modify ACP global user settings template data
@@ -356,10 +345,10 @@ class acp_controller
* @var array error Array with error lang keys
* @since 2.0.0-RC7
*/
- $vars = array(
+ $vars = [
'template_data',
'error',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.acp_globalusersettings_modify_template_data', compact($vars)));
$this->template->assign_vars($template_data);
@@ -381,7 +370,7 @@ class acp_controller
foreach ($this->settings->prune_modes as $i => $prune_mode)
{
$prune_mode_options .= '';
}
diff --git a/controller/ucp_controller.php b/controller/ucp_controller.php
index fece87d..cb74236 100644
--- a/controller/ucp_controller.php
+++ b/controller/ucp_controller.php
@@ -15,6 +15,7 @@ use dmzx\mchat\core\settings;
use phpbb\auth\auth;
use phpbb\db\driver\driver_interface as db_interface;
use phpbb\event\dispatcher_interface;
+use phpbb\language\language;
use phpbb\request\request_interface;
use phpbb\template\template;
use phpbb\user;
@@ -27,6 +28,9 @@ class ucp_controller
/** @var user */
protected $user;
+ /** @var language */
+ protected $lang;
+
/** @var auth */
protected $auth;
@@ -37,51 +41,42 @@ class ucp_controller
protected $request;
/** @var settings */
- protected $settings;
+ protected $mchat_settings;
/** @var dispatcher_interface */
protected $dispatcher;
- /** @var string */
- protected $root_path;
-
- /** @var string */
- protected $php_ext;
-
/**
* Constructor
*
* @param template $template
* @param user $user
+ * @param language $lang
* @param auth $auth
* @param db_interface $db
* @param request_interface $request
- * @param settings $settings
+ * @param settings $mchat_settings
* @param dispatcher_interface $dispatcher
- * @param string $root_path
- * @param string $php_ext
*/
public function __construct(
template $template,
user $user,
+ language $lang,
auth $auth,
db_interface $db,
request_interface $request,
- settings $settings,
- dispatcher_interface $dispatcher,
- $root_path,
- $php_ext
+ settings $mchat_settings,
+ dispatcher_interface $dispatcher
)
{
- $this->template = $template;
- $this->user = $user;
- $this->auth = $auth;
- $this->db = $db;
- $this->request = $request;
- $this->settings = $settings;
- $this->dispatcher = $dispatcher;
- $this->root_path = $root_path;
- $this->php_ext = $php_ext;
+ $this->template = $template;
+ $this->user = $user;
+ $this->lang = $lang;
+ $this->auth = $auth;
+ $this->db = $db;
+ $this->request = $request;
+ $this->mchat_settings = $mchat_settings;
+ $this->dispatcher = $dispatcher;
}
/**
@@ -93,13 +88,13 @@ class ucp_controller
{
add_form_key('ucp_mchat');
- $error = array();
+ $error = [];
if ($this->request->is_set_post('submit'))
{
- $mchat_new_config = array();
- $validation = array();
- foreach ($this->settings->ucp_settings() as $config_name => $config_data)
+ $mchat_new_config = [];
+ $validation = [];
+ foreach ($this->mchat_settings->ucp_settings() as $config_name => $config_data)
{
if ($this->auth->acl_get('u_' . $config_name))
{
@@ -114,10 +109,7 @@ class ucp_controller
}
}
- if (!function_exists('validate_data'))
- {
- include($this->root_path . 'includes/functions_user.' . $this->php_ext);
- }
+ $this->mchat_settings->include_functions('user', 'validate_data');
$error = array_merge($error, validate_data($mchat_new_config, $validation));
@@ -134,10 +126,10 @@ class ucp_controller
* @var array error Array with error lang keys
* @since 2.0.0-RC7
*/
- $vars = array(
+ $vars = [
'mchat_new_config',
'error',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.ucp_update_data', compact($vars)));
if (!$error)
@@ -148,25 +140,25 @@ class ucp_controller
$this->db->sql_query($sql);
meta_refresh(3, $u_action);
- $message = $this->user->lang('PROFILE_UPDATED') . '
' . $this->user->lang('RETURN_UCP', '', '');
+ $message = $this->lang->lang('PROFILE_UPDATED') . '
' . $this->lang->lang('RETURN_UCP', '', '');
trigger_error($message);
}
// Replace "error" strings with their real, localised form
- $error = array_map(array($this->user, 'lang'), $error);
+ $error = array_map([$this->lang, 'lang'], $error);
}
- $selected_date = $this->settings->cfg('mchat_date');
- $template_data = $this->settings->get_date_template_data($selected_date);
+ $selected_date = $this->mchat_settings->cfg('mchat_date');
+ $template_data = $this->mchat_settings->get_date_template_data($selected_date);
$auth_count = 0;
- foreach (array_keys($this->settings->ucp_settings()) as $config_name)
+ foreach (array_keys($this->mchat_settings->ucp_settings()) as $config_name)
{
$upper = strtoupper($config_name);
$auth = $this->auth->acl_get('u_' . $config_name);
- $template_data[$upper] = $this->settings->cfg($config_name);
+ $template_data[$upper] = $this->mchat_settings->cfg($config_name);
$template_data[$upper . '_AUTH'] = $auth;
if ($auth)
@@ -175,13 +167,13 @@ class ucp_controller
}
}
- $template_data = array_merge($template_data, array(
- 'MCHAT_ALLOW_USE' => $this->auth->acl_get('u_mchat_use'),
- 'MCHAT_POSTS_ENABLED_LANG' => $this->settings->get_enabled_post_notifications_lang(),
- 'ERROR' => sizeof($error) ? implode('
', $error) : '',
- 'MCHAT_AUTH_COUNT' => $auth_count,
- 'S_UCP_ACTION' => $u_action,
- ));
+ $template_data = array_merge($template_data, [
+ 'MCHAT_ALLOW_USE' => $this->auth->acl_get('u_mchat_use'),
+ 'MCHAT_POSTS_ENABLED_LANG' => $this->mchat_settings->get_enabled_post_notifications_lang(),
+ 'ERROR' => sizeof($error) ? implode('
', $error) : '',
+ 'MCHAT_AUTH_COUNT' => $auth_count,
+ 'S_UCP_ACTION' => $u_action,
+ ]);
/**
* Event to modify UCP settings template data
@@ -192,11 +184,11 @@ class ucp_controller
* @var array error Array with error lang keys
* @since 2.0.0-RC7
*/
- $vars = array(
+ $vars = [
'template_data',
'auth_count',
'error',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.ucp_modify_template_data', compact($vars)));
$this->template->assign_vars($template_data);
diff --git a/core/functions.php b/core/functions.php
index 5995ad2..50d0b82 100644
--- a/core/functions.php
+++ b/core/functions.php
@@ -15,17 +15,28 @@ use phpbb\auth\auth;
use phpbb\cache\driver\driver_interface as cache_interface;
use phpbb\db\driver\driver_interface as db_interface;
use phpbb\event\dispatcher_interface;
+use phpbb\group\helper;
+use phpbb\language\language;
use phpbb\log\log_interface;
use phpbb\user;
class functions
{
/** @var settings */
- protected $settings;
+ protected $mchat_settings;
+
+ /** @var notifications */
+ protected $mchat_notifications;
+
+ /** @var log */
+ protected $mchat_log;
/** @var user */
protected $user;
+ /** @var language */
+ protected $lang;
+
/** @var auth */
protected $auth;
@@ -41,85 +52,53 @@ class functions
/** @var dispatcher_interface */
protected $dispatcher;
- /** @var string */
- protected $root_path;
-
- /** @var string */
- protected $php_ext;
-
- /** @var string */
- protected $mchat_table;
-
- /** @var string */
- protected $mchat_log_table;
-
- /** @var string */
- protected $mchat_sessions_table;
+ /** @var helper */
+ protected $group_helper;
/** @var array */
protected $active_users;
- /** @var array */
- public $log_types = array(
- 1 => 'edit',
- 2 => 'del',
- );
-
/**
- * Value of the phpbb_mchat.post_id field for login notification
- * messages if the user session is visible at the time of login
+ * Constructor
+ *
+ * @param settings $mchat_settings
+ * @param notifications $mchat_notifications
+ * @param log $mchat_log
+ * @param user $user
+ * @param language $lang
+ * @param auth $auth
+ * @param log_interface $log
+ * @param db_interface $db
+ * @param cache_interface $cache
+ * @param dispatcher_interface $dispatcher
+ * @param helper $group_helper
+
*/
- const LOGIN_VISIBLE = 1;
-
- /**
- * Value of the phpbb_mchat.post_id field for login notification
- * messages if the user session is hidden at the time of login
- */
- const LOGIN_HIDDEN = 2;
-
- /**
- * Constructor
- *
- * @param settings $settings
- * @param user $user
- * @param auth $auth
- * @param log_interface $log
- * @param db_interface $db
- * @param cache_interface $cache
- * @param dispatcher_interface $dispatcher
- * @param string $root_path
- * @param string $php_ext
- * @param string $mchat_table
- * @param string $mchat_log_table
- * @param string $mchat_sessions_table
- */
function __construct(
- settings $settings,
+ settings $mchat_settings,
+ notifications $mchat_notifications,
+ log $mchat_log,
user $user,
+ language $lang,
auth $auth,
log_interface $log,
db_interface $db,
cache_interface $cache,
dispatcher_interface $dispatcher,
- $root_path,
- $php_ext,
- $mchat_table,
- $mchat_log_table,
- $mchat_sessions_table
+ helper $group_helper
)
{
- $this->settings = $settings;
+ $this->mchat_settings = $mchat_settings;
+ $this->mchat_notifications = $mchat_notifications;
+ $this->mchat_log = $mchat_log;
$this->user = $user;
+ $this->lang = $lang;
$this->auth = $auth;
$this->log = $log;
$this->db = $db;
$this->cache = $cache;
$this->dispatcher = $dispatcher;
- $this->root_path = $root_path;
- $this->php_ext = $php_ext;
- $this->mchat_table = $mchat_table;
- $this->mchat_log_table = $mchat_log_table;
- $this->mchat_sessions_table = $mchat_sessions_table;
+ $this->group_helper = $group_helper;
}
/**
@@ -130,29 +109,29 @@ class functions
*/
protected function mchat_format_seconds($time)
{
- $times = array();
+ $times = [];
$hours = floor($time / 3600);
if ($hours)
{
$time -= $hours * 3600;
- $times[] = $this->user->lang('MCHAT_HOURS', $hours);
+ $times[] = $this->lang->lang('MCHAT_HOURS', $hours);
}
$minutes = floor($time / 60);
if ($minutes)
{
$time -= $minutes * 60;
- $times[] = $this->user->lang('MCHAT_MINUTES', $minutes);
+ $times[] = $this->lang->lang('MCHAT_MINUTES', $minutes);
}
$seconds = ceil($time);
if ($seconds)
{
- $times[] = $this->user->lang('MCHAT_SECONDS', $seconds);
+ $times[] = $this->lang->lang('MCHAT_SECONDS', $seconds);
}
- return $this->user->lang('MCHAT_ONLINE_EXPLAIN', implode(' ', $times));
+ return $this->lang->lang('MCHAT_ONLINE_EXPLAIN', implode(' ', $times));
}
/**
@@ -162,19 +141,19 @@ class functions
*/
protected function mchat_session_time()
{
- $mchat_timeout = $this->settings->cfg('mchat_timeout');
+ $mchat_timeout = $this->mchat_settings->cfg('mchat_timeout');
if ($mchat_timeout)
{
return $mchat_timeout;
}
- $load_online_time = $this->settings->cfg('load_online_time');
+ $load_online_time = $this->mchat_settings->cfg('load_online_time');
if ($load_online_time)
{
return $load_online_time * 60;
}
- return $this->settings->cfg('session_length');
+ return $this->mchat_settings->cfg('session_length');
}
/**
@@ -192,24 +171,22 @@ class functions
$check_time = time() - $this->mchat_session_time();
- $sql_array = array(
+ $sql_array = [
'SELECT' => 'u.user_id, u.username, u.user_colour, s.session_viewonline',
- 'FROM' => array(
- $this->mchat_sessions_table => 'ms'
- ),
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(SESSIONS_TABLE => 's'),
+ 'FROM' => [$this->mchat_settings->get_table_mchat_sessions() => 'ms'],
+ 'LEFT_JOIN' => [
+ [
+ 'FROM' => [SESSIONS_TABLE => 's'],
'ON' => 'ms.user_id = s.session_user_id',
- ),
- array(
- 'FROM' => array(USERS_TABLE => 'u'),
+ ],
+ [
+ 'FROM' => [USERS_TABLE => 'u'],
'ON' => 'ms.user_id = u.user_id',
- ),
- ),
+ ],
+ ],
'WHERE' => 'u.user_id <> ' . ANONYMOUS . ' AND s.session_viewonline IS NOT NULL AND ms.user_lastupdate > ' . (int) $check_time,
'ORDER_BY' => 'u.username ASC',
- );
+ ];
/**
* Event to modify the SQL query that fetches active mChat users
@@ -218,9 +195,9 @@ class functions
* @var array sql_array Array with SQL query data to fetch the current active sessions
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'sql_array',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.active_users_sql_before', compact($vars)));
$sql = $this->db->sql_build_query('SELECT', $sql_array);
@@ -228,7 +205,7 @@ class functions
$rows = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result);
- $mchat_users = array();
+ $mchat_users = [];
$can_view_hidden = $this->auth->acl_get('u_viewonline');
foreach ($rows as $row)
@@ -243,15 +220,15 @@ class functions
$row['username'] = '' . $row['username'] . '';
}
- $mchat_users[$row['user_id']] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang('GUEST'));
+ $mchat_users[$row['user_id']] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->lang->lang('GUEST'));
}
- $active_users = array(
- 'online_userlist' => implode($this->user->lang('COMMA_SEPARATOR'), $mchat_users),
- 'users_count_title' => $this->user->lang('MCHAT_TITLE_COUNT', count($mchat_users)),
- 'users_total' => $this->user->lang('MCHAT_ONLINE_USERS_TOTAL', count($mchat_users)),
+ $active_users = [
+ 'online_userlist' => implode($this->lang->lang('COMMA_SEPARATOR'), $mchat_users),
+ 'users_count_title' => $this->lang->lang('MCHAT_TITLE_COUNT', count($mchat_users)),
+ 'users_total' => $this->lang->lang('MCHAT_ONLINE_USERS_TOTAL', count($mchat_users)),
'refresh_message' => $this->mchat_format_seconds($this->mchat_session_time()),
- );
+ ];
/**
* Event to modify collected data about active mChat users
@@ -261,10 +238,10 @@ class functions
* @var array active_users Array containing info about currently active mChat users
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'mchat_users',
'active_users',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.active_users_after', compact($vars)));
$this->active_users = $active_users;
@@ -284,7 +261,7 @@ class functions
return false;
}
- $sql = 'UPDATE ' . $this->mchat_sessions_table . '
+ $sql = 'UPDATE ' . $this->mchat_settings->get_table_mchat_sessions() . '
SET user_lastupdate = ' . time() . '
WHERE user_id = ' . (int) $this->user->data['user_id'];
$this->db->sql_query($sql);
@@ -293,11 +270,11 @@ class functions
if ($is_new_session)
{
- $sql = 'INSERT INTO ' . $this->mchat_sessions_table . ' ' . $this->db->sql_build_array('INSERT', array(
+ $sql = 'INSERT INTO ' . $this->mchat_settings->get_table_mchat_sessions() . ' ' . $this->db->sql_build_array('INSERT', [
'user_id' => (int) $this->user->data['user_id'],
'user_ip' => $this->user->ip,
'user_lastupdate' => time(),
- ));
+ ]);
$this->db->sql_query($sql);
}
@@ -311,7 +288,7 @@ class functions
{
$check_time = time() - $this->mchat_session_time();
- $sql = 'DELETE FROM ' . $this->mchat_sessions_table . '
+ $sql = 'DELETE FROM ' . $this->mchat_settings->get_table_mchat_sessions() . '
WHERE user_lastupdate <= ' . (int) $check_time;
$this->db->sql_query($sql);
}
@@ -322,32 +299,32 @@ class functions
* @param int|array $user_ids
* @return array
*/
- public function mchat_prune($user_ids = array())
+ public function mchat_prune($user_ids = [])
{
- $prune_num = (int) $this->settings->cfg('mchat_prune_num');
- $prune_mode = (int) $this->settings->cfg('mchat_prune_mode');
+ $prune_num = (int) $this->mchat_settings->cfg('mchat_prune_num');
+ $prune_mode = (int) $this->mchat_settings->cfg('mchat_prune_mode');
- if (empty($this->settings->prune_modes[$prune_mode]))
+ if (empty($this->mchat_settings->prune_modes[$prune_mode]))
{
- return array();
+ return [];
}
- $sql_array = array(
+ $sql_array = [
'SELECT' => 'message_id',
- 'FROM' => array($this->mchat_table => 'm'),
- );
+ 'FROM' => [$this->mchat_settings->get_table_mchat() => 'm'],
+ ];
if ($user_ids)
{
if (!is_array($user_ids))
{
- $user_ids = array($user_ids);
+ $user_ids = [$user_ids];
}
$sql_array['WHERE'] = $this->db->sql_in_set('m.user_id', $user_ids);
$offset = 0;
}
- else if ($this->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';
@@ -368,10 +345,10 @@ class functions
* @var array sql_array SQL query data
* @since 2.0.2
*/
- $vars = array(
+ $vars = [
'user_ids',
'sql_array',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.prune_sql_before', compact($vars)));
$sql = $this->db->sql_build_query('SELECT', $sql_array);
@@ -379,7 +356,7 @@ class functions
$rows = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result);
- $prune_ids = array();
+ $prune_ids = [];
foreach ($rows as $row)
{
@@ -395,22 +372,22 @@ class functions
* @since 2.0.0-RC6
* @changed 2.0.1 Added user_ids
*/
- $vars = array(
+ $vars = [
'prune_ids',
'user_ids',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.prune_before', compact($vars)));
if ($prune_ids)
{
- $this->db->sql_query('DELETE FROM ' . $this->mchat_table . ' WHERE ' . $this->db->sql_in_set('message_id', $prune_ids));
- $this->db->sql_query('DELETE FROM ' . $this->mchat_log_table . ' WHERE ' . $this->db->sql_in_set('message_id', $prune_ids));
- $this->cache->destroy('sql', $this->mchat_log_table);
+ $this->db->sql_query('DELETE FROM ' . $this->mchat_settings->get_table_mchat() . ' WHERE ' . $this->db->sql_in_set('message_id', $prune_ids));
+ $this->db->sql_query('DELETE FROM ' . $this->mchat_settings->get_table_mchat_log() . ' WHERE ' . $this->db->sql_in_set('message_id', $prune_ids));
+ $this->cache->destroy('sql', $this->mchat_settings->get_table_mchat_log());
// Only add a log entry if message pruning was not triggered by user pruning
if (!$user_ids)
{
- $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED', false, array($this->user->data['username'], count($prune_ids)));
+ $this->phpbb_log('LOG_MCHAT_TABLE_PRUNED', [count($prune_ids)]);
}
}
@@ -424,13 +401,11 @@ class functions
*/
public function mchat_total_message_count()
{
- $sql_where_ary = $this->get_sql_where_for_notifcation_messages();
-
- $sql_array = array(
+ $sql_array = [
'SELECT' => 'COUNT(*) AS rows_total',
- 'FROM' => array($this->mchat_table => 'm'),
- 'WHERE' => $sql_where_ary ? $this->db->sql_escape('(' . implode(') AND (', $sql_where_ary) . ')') : '',
- );
+ 'FROM' => [$this->mchat_settings->get_table_mchat() => 'm'],
+ 'WHERE' => $this->mchat_notifications->get_sql_where(),
+ ];
/**
* Event to modifying the SQL query that fetches the total number of mChat messages
@@ -439,9 +414,9 @@ class functions
* @var array sql_array Array with SQL query data to fetch the total message count
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'sql_array',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.total_message_count_modify_sql', compact($vars)));
$sql = $this->db->sql_build_query('SELECT', $sql_array);
@@ -463,7 +438,7 @@ class functions
*/
public function mchat_get_messages($message_ids, $last_id = 0, $total = 0, $offset = 0)
{
- $sql_where_message_id = array();
+ $sql_where_message_id = [];
// Fetch new messages
if ($last_id)
@@ -476,35 +451,33 @@ class functions
{
if (!is_array($message_ids))
{
- $message_ids = array($message_ids);
+ $message_ids = [$message_ids];
}
$sql_where_message_id[] = $this->db->sql_in_set('m.message_id', array_map('intval', $message_ids));
}
- $sql_where_ary = $this->get_sql_where_for_notifcation_messages();
+ $sql_where_ary = array_filter([
+ implode(' OR ', $sql_where_message_id),
+ $this->mchat_notifications->get_sql_where(),
+ ]);
- if ($sql_where_message_id)
- {
- $sql_where_ary[] = implode(' OR ', $sql_where_message_id);
- }
-
- $sql_array = array(
+ $sql_array = [
'SELECT' => 'm.*, u.username, u.user_colour, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, u.user_allow_pm, p.post_visibility',
- 'FROM' => array($this->mchat_table => 'm'),
- 'LEFT_JOIN' => array(
- array(
- 'FROM' => array(USERS_TABLE => 'u'),
+ 'FROM' => [$this->mchat_settings->get_table_mchat() => 'm'],
+ 'LEFT_JOIN' => [
+ [
+ 'FROM' => [USERS_TABLE => 'u'],
'ON' => 'm.user_id = u.user_id',
- ),
- array(
- 'FROM' => array(POSTS_TABLE => 'p'),
+ ],
+ [
+ 'FROM' => [POSTS_TABLE => 'p'],
'ON' => 'm.post_id = p.post_id AND m.forum_id <> 0',
- ),
- ),
+ ],
+ ],
'WHERE' => $sql_where_ary ? $this->db->sql_escape('(' . implode(') AND (', $sql_where_ary) . ')') : '',
'ORDER_BY' => 'm.message_id DESC',
- );
+ ];
/**
* Event to modify the SQL query that fetches mChat messages
@@ -517,13 +490,13 @@ class functions
* @var array sql_array Array containing the SQL query data
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'message_ids',
'last_id',
'total',
'offset',
'sql_array',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.get_messages_modify_sql', compact($vars)));
$sql = $this->db->sql_build_query('SELECT', $sql_array);
@@ -543,88 +516,6 @@ class functions
return $rows;
}
- /**
- * Generates SQL where conditions to include or exlude notifacation
- * messages based on the current user's settings and permissions
- *
- * @return array
- */
- protected function get_sql_where_for_notifcation_messages()
- {
- $sql_where_ary = array();
-
- if ($this->settings->cfg('mchat_posts'))
- {
- // If the current user doesn't have permission to see hidden users, exclude their login posts
- if (!$this->auth->acl_get('u_viewonline'))
- {
- $sql_where_ary[] = 'm.post_id <> ' . (int) self::LOGIN_HIDDEN . // Exclude all notifications that were created by hidden users ...
- ' OR m.user_id = ' . (int) $this->user->data['user_id'] . // ... but include all login notifications of the current user
- ' OR m.forum_id <> 0'; // ... and include all post notifications
- }
- }
- else
- {
- // Exclude all post notifications
- $sql_where_ary[] = 'm.post_id = 0';
- }
-
- return $sql_where_ary;
- }
-
- /**
- * Fetches log entries from the database and sorts them
- *
- * @param int $log_id The ID of the latest log entry that the user has
- * @return array
- */
- public function mchat_get_logs($log_id)
- {
- $sql_array = array(
- 'SELECT' => 'ml.*',
- 'FROM' => array($this->mchat_log_table => 'ml'),
- 'WHERE' => 'ml.log_id > ' . (int) $log_id,
- );
-
- $sql = $this->db->sql_build_query('SELECT', $sql_array);
- $result = $this->db->sql_query($sql, 3600);
- $rows = $this->db->sql_fetchrowset($result);
- $this->db->sql_freeresult($result);
-
- $logs = array(
- 'id' => $log_id,
- );
-
- foreach ($rows as $row)
- {
- $logs['id'] = max((int) $logs['id'], (int) $row['log_id']);
- $logs[] = $row;
- }
-
- return $logs;
- }
-
- /**
- * Fetches the highest log ID
- *
- * @return int
- */
- public function get_latest_log_id()
- {
- $sql_array = array(
- 'SELECT' => 'ml.log_id',
- 'FROM' => array($this->mchat_log_table => 'ml'),
- 'ORDER_BY' => 'log_id DESC',
- );
-
- $sql = $this->db->sql_build_query('SELECT', $sql_array);
- $result = $this->db->sql_query_limit($sql, 1);
- $max_log_id = (int) $this->db->sql_fetchfield('log_id');
- $this->db->sql_freeresult($result);
-
- return $max_log_id;
- }
-
/**
* Generates the user legend markup
*
@@ -633,23 +524,23 @@ class functions
public function mchat_legend()
{
// Grab group details for legend display for who is online on the custom page
- $order_legend = $this->settings->cfg('legend_sort_groupname') ? 'group_name' : 'group_legend';
+ $order_legend = $this->mchat_settings->cfg('legend_sort_groupname') ? 'group_name' : 'group_legend';
- $sql_array = array(
- 'SELECT' => 'g.group_id, g.group_name, g.group_colour, g.group_type',
- 'FROM' => array(GROUPS_TABLE => 'g'),
- 'WHERE' => 'group_legend <> 0',
+ $sql_array = [
+ 'SELECT' => 'g.group_id, g.group_name, g.group_colour',
+ 'FROM' => [GROUPS_TABLE => 'g'],
+ 'WHERE' => 'g.group_legend <> 0',
'ORDER_BY' => 'g.' . $order_legend . ' ASC',
- );
+ ];
if ($this->auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
{
- $sql_array['LEFT_JOIN'] = array(
- array(
- 'FROM' => array(USER_GROUP_TABLE => 'ug'),
+ $sql_array['LEFT_JOIN'] = [
+ [
+ 'FROM' => [USER_GROUP_TABLE => 'ug'],
'ON' => 'g.group_id = ug.group_id AND ug.user_id = ' . (int) $this->user->data['user_id'] . ' AND ug.user_pending = 0',
- ),
- );
+ ],
+ ];
$sql_array['WHERE'] .= ' AND (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . (int) $this->user->data['user_id'] . ')';
}
@@ -659,18 +550,18 @@ class functions
$rows = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result);
- $legend = array();
+ $legend = [];
foreach ($rows as $row)
{
$colour_text = $row['group_colour'] ? ' style="color:#' . $row['group_colour'] . '"' : '';
- $group_name = $row['group_type'] == GROUP_SPECIAL ? $this->user->lang('G_' . $row['group_name']) : $row['group_name'];
+ $group_name = $this->group_helper->get_name($row['group_name']);
if ($row['group_name'] == 'BOTS' || $this->user->data['user_id'] != ANONYMOUS && !$this->auth->acl_get('u_viewprofile'))
{
$legend[] = '' . $group_name . '';
}
else
{
- $legend[] = 'root_path}memberlist.{$this->php_ext}", 'mode=group&g='. $row['group_id']) . '">' . $group_name . '';
+ $legend[] = '' . $group_name . '';
}
}
@@ -684,15 +575,18 @@ class functions
*/
public function mchat_foes()
{
- $sql = 'SELECT zebra_id
- FROM ' . ZEBRA_TABLE . '
- WHERE foe = 1
- AND user_id = ' . (int) $this->user->data['user_id'];
+ $sql_array = [
+ 'SELECT' => 'z.zebra_id',
+ 'FROM' => [ZEBRA_TABLE => 'z'],
+ 'WHERE' => 'z.foe = 1 AND z.user_id = ' . (int) $this->user->data['user_id'],
+ ];
+
+ $sql = $this->db->sql_build_query('SELECT', $sql_array);
$result = $this->db->sql_query($sql);
$rows = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result);
- $foes = array();
+ $foes = [];
foreach ($rows as $row)
{
@@ -702,50 +596,6 @@ class functions
return $foes;
}
- /**
- * Fetches post subjects and their forum names
- *
- * @param array $post_ids
- * @return array
- */
- public function mchat_get_post_data($post_ids)
- {
- if (!$post_ids)
- {
- return array();
- }
-
- $sql = 'SELECT p.post_id, p.post_subject, f.forum_id, f.forum_name
- FROM ' . POSTS_TABLE . ' p, ' . FORUMS_TABLE . ' f
- WHERE p.forum_id = f.forum_id
- AND ' . $this->db->sql_in_set('p.post_id', $post_ids);
-
- $result = $this->db->sql_query($sql);
- $rows = $this->db->sql_fetchrowset($result);
- $this->db->sql_freeresult($result);
-
- $post_subjects = array();
-
- foreach ($rows as $row)
- {
- $post_subjects[$row['post_id']] = array(
- 'post_subject' => $row['post_subject'],
- 'forum_id' => $row['forum_id'],
- 'forum_name' => $row['forum_name'],
- );
- }
-
- // Handle deleted posts
- $non_existent_post_ids = array_diff($post_ids, array_keys($post_subjects));
-
- foreach ($non_existent_post_ids as $post_id)
- {
- $post_subjects[$post_id] = null;
- }
-
- return $post_subjects;
- }
-
/**
* Adds forbidden BBCodes to the passed SQL where statement
*
@@ -754,7 +604,7 @@ class functions
*/
public function mchat_sql_append_forbidden_bbcodes($sql_where)
{
- $disallowed_bbcodes = explode('|', $this->settings->cfg('mchat_bbcode_disallowed'));
+ $disallowed_bbcodes = explode('|', $this->mchat_settings->cfg('mchat_bbcode_disallowed'));
if (!empty($disallowed_bbcodes))
{
@@ -764,72 +614,6 @@ class functions
return $sql_where;
}
- /**
- * Inserts a message with posting information into the database
- *
- * @param string $mode One of post|quote|edit|reply|login
- * @param int $forum_id
- * @param int $post_id
- * @param bool $is_hidden_login
- */
- public function mchat_insert_posting($mode, $forum_id, $post_id, $is_hidden_login)
- {
- $mode_config = array(
- 'post' => 'mchat_posts_topic',
- 'quote' => 'mchat_posts_quote',
- 'edit' => 'mchat_posts_edit',
- 'reply' => 'mchat_posts_reply',
- 'login' => 'mchat_posts_login',
- );
-
- $is_mode_enabled = !empty($mode_config[$mode]) && $this->settings->cfg($mode_config[$mode]) && (!$this->settings->cfg('mchat_posts_auth_check') || $this->auth->acl_get('u_mchat_use'));
-
- // Special treatment for login notifications
- if ($mode === 'login')
- {
- $forum_id = 0;
- $post_id = $is_hidden_login ? self::LOGIN_HIDDEN : self::LOGIN_VISIBLE;
- }
-
- $sql_array = array(
- 'forum_id' => (int) $forum_id,
- 'post_id' => (int) $post_id,
- 'user_id' => (int) $this->user->data['user_id'],
- 'user_ip' => $this->user->ip,
- 'message' => 'MCHAT_NEW_' . strtoupper($mode),
- 'message_time' => time(),
- );
-
- /**
- * Event that allows to modify data of a posting notification before it is inserted in the database
- *
- * @event dmzx.mchat.insert_posting_before
- * @var string mode The posting mode, one of post|quote|edit|reply|login
- * @var int forum_id The ID of the forum where the post was made, or 0 if mode is login.
- * @var int post_id The ID of the post that was made. If mode is login this value is
- * one of the constants LOGIN_HIDDEN|LOGIN_VISIBLE
- * @var bool is_hidden_login Whether or not the user session is hidden. Only used if mode is login.
- * @var array is_mode_enabled Whether or not the posting should be added to the database.
- * @var array sql_array An array containing the data that is about to be inserted into the messages table.
- * @since 2.0.0-RC6
- */
- $vars = array(
- 'mode',
- 'forum_id',
- 'post_id',
- 'is_hidden_login',
- 'is_mode_enabled',
- 'sql_array',
- );
- extract($this->dispatcher->trigger_event('dmzx.mchat.insert_posting_before', compact($vars)));
-
- if ($is_mode_enabled)
- {
- $sql = 'INSERT INTO ' . $this->mchat_table . ' ' . $this->db->sql_build_array('INSERT', $sql_array);
- $this->db->sql_query($sql);
- }
- }
-
/**
* Checks if the current user is flooding the chat
*
@@ -837,20 +621,24 @@ class functions
*/
public function mchat_is_user_flooding()
{
- if (!$this->settings->cfg('mchat_flood_time') || $this->auth->acl_get('u_mchat_flood_ignore'))
+ if (!$this->mchat_settings->cfg('mchat_flood_time') || $this->auth->acl_get('u_mchat_flood_ignore'))
{
return false;
}
- $sql = 'SELECT message_time
- FROM ' . $this->mchat_table . '
- WHERE user_id = ' . (int) $this->user->data['user_id'] . '
- ORDER BY message_time DESC';
+ $sql_array = [
+ 'SELECT' => 'm.message_time',
+ 'FROM' => [$this->mchat_settings->get_table_mchat() => 'm'],
+ 'WHERE' => 'm.user_id = ' . (int) $this->user->data['user_id'],
+ 'ORDER_BY' => 'm.message_time DESC',
+ ];
+
+ $sql = $this->db->sql_build_query('SELECT', $sql_array);
$result = $this->db->sql_query_limit($sql, 1);
$message_time = (int) $this->db->sql_fetchfield('message_time');
$this->db->sql_freeresult($result);
- return $message_time && time() - $message_time < $this->settings->cfg('mchat_flood_time');
+ return $message_time && time() - $message_time < $this->mchat_settings->cfg('mchat_flood_time');
}
/**
@@ -861,9 +649,13 @@ class functions
*/
public function mchat_author_for_message($message_id)
{
- $sql = 'SELECT m.user_id, m.message_time, m.post_id
- FROM ' . $this->mchat_table . ' m
- WHERE m.message_id = ' . (int) $message_id;
+ $sql_array = [
+ 'SELECT' => 'm.user_id, m.message_time, m.post_id',
+ 'FROM' => [$this->mchat_settings->get_table_mchat() => 'm'],
+ 'WHERE' => 'm.message_id = ' . (int) $message_id,
+ ];
+
+ $sql = $this->db->sql_build_query('SELECT', $sql_array);
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
@@ -871,6 +663,42 @@ class functions
return $row;
}
+ /**
+ * Adds an entry to phpBB's admin log
+ *
+ * @param string $log_lang_key
+ * @param array $additional_data
+ */
+ public function phpbb_log($log_lang_key, $additional_data = [])
+ {
+ $mode = 'admin';
+ $log_enabled = $this->mchat_settings->cfg('mchat_log_enabled');
+ $additional_data = array_merge([$this->user->data['username']], $additional_data);
+
+ /**
+ * Event to modify the phpBB log data before it is added to the log table
+ *
+ * @event dmzx.mchat.phpbb_log_add_before
+ * @var string mode The log mode, one of admin|mod|user|critical
+ * @var string log_lang_key The language key of the log entry
+ * @var bool log_enabled Flag indicating whether this log entry should be added or not
+ * @var array additional_data Array with additional data for the log message
+ * @since 2.1.0-RC1
+ */
+ $vars = [
+ 'mode',
+ 'log_lang_key',
+ 'log_enabled',
+ 'additional_data',
+ ];
+ extract($this->dispatcher->trigger_event('dmzx.mchat.phpbb_log_add_before', compact($vars)));
+
+ if ($log_enabled)
+ {
+ $this->log->add($mode, $this->user->data['user_id'], $this->user->ip, $log_lang_key, false, $additional_data);
+ }
+ }
+
/**
* Performs AJAX actions
*
@@ -893,12 +721,12 @@ class functions
* @var bool update_session_infos Whether or not to update the user session
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'action',
'sql_ary',
'message_id',
'update_session_infos',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.action_before', compact($vars)));
$is_new_session = false;
@@ -912,7 +740,7 @@ class functions
$this->user->update_session_infos();
}
$is_new_session = $this->mchat_add_user_session();
- $this->db->sql_query('INSERT INTO ' . $this->mchat_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary));
+ $this->db->sql_query('INSERT INTO ' . $this->mchat_settings->get_table_mchat() . ' ' . $this->db->sql_build_array('INSERT', $sql_ary));
break;
// User edits a message
@@ -922,9 +750,9 @@ class functions
$this->user->update_session_infos();
}
$is_new_session = $this->mchat_add_user_session();
- $this->db->sql_query('UPDATE ' . $this->mchat_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE message_id = ' . (int) $message_id);
- $this->mchat_insert_log('edit', $message_id);
- $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EDITED_MCHAT', false, array($this->user->data['username']));
+ $this->db->sql_query('UPDATE ' . $this->mchat_settings->get_table_mchat() . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE message_id = ' . (int) $message_id);
+ $this->mchat_log->add_log('edit', $message_id);
+ $this->phpbb_log('LOG_EDITED_MCHAT');
break;
// User deletes a message
@@ -934,34 +762,12 @@ class functions
$this->user->update_session_infos();
}
$is_new_session = $this->mchat_add_user_session();
- $this->db->sql_query('DELETE FROM ' . $this->mchat_table . ' WHERE message_id = ' . (int) $message_id);
- $this->mchat_insert_log('del', $message_id);
- $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DELETED_MCHAT', false, array($this->user->data['username']));
+ $this->db->sql_query('DELETE FROM ' . $this->mchat_settings->get_table_mchat() . ' WHERE message_id = ' . (int) $message_id);
+ $this->mchat_log->add_log('del', $message_id);
+ $this->phpbb_log('LOG_DELETED_MCHAT');
break;
}
return $is_new_session;
}
-
- /**
- * @param string $log_type The log type, one of edit|del
- * @param int $message_id The ID of the message to which this log entry belongs
- * @return int The ID of the newly added log row
- */
- public function mchat_insert_log($log_type, $message_id)
- {
- $this->db->sql_query('INSERT INTO ' . $this->mchat_log_table . ' ' . $this->db->sql_build_array('INSERT', array(
- 'log_type' => array_search($log_type, $this->log_types),
- 'user_id' => (int) $this->user->data['user_id'],
- 'message_id' => (int) $message_id,
- 'log_ip' => $this->user->ip,
- 'log_time' => time(),
- )));
-
- $log_id = (int) $this->db->sql_nextid();
-
- $this->cache->destroy('sql', $this->mchat_log_table);
-
- return $log_id;
- }
}
diff --git a/core/log.php b/core/log.php
new file mode 100644
index 0000000..e0bae89
--- /dev/null
+++ b/core/log.php
@@ -0,0 +1,210 @@
+mchat_settings = $mchat_settings;
+ $this->user = $user;
+ $this->db = $db;
+ $this->cache = $cache;
+ $this->dispatcher = $dispatcher;
+ }
+
+ /**
+ * Returns an array with all registered log types
+ *
+ * @return array
+ */
+ public function get_types()
+ {
+ if (!$this->log_types)
+ {
+ // Default log types
+ $log_types = [
+ 1 => 'edit',
+ 2 => 'del',
+ ];
+
+ /**
+ * Event that allows adding log types
+ *
+ * @event dmzx.mchat.log_types_init
+ * @var array log_types Array containing log types
+ * @since 2.1.0-RC1
+ */
+ $vars = [
+ 'log_types',
+ ];
+ extract($this->dispatcher->trigger_event('dmzx.mchat.log_types_init', compact($vars)));
+
+ $this->log_types = $log_types;
+ }
+
+ return $this->log_types;
+ }
+
+ /**
+ * Returns the log type ID for the given string type
+ *
+ * @param string $type
+ * @return int
+ */
+ public function get_type_id($type)
+ {
+ return (int) array_search($type, $this->get_types());
+ }
+
+ /**
+ * @param string $log_type The log type, one of edit|del
+ * @param int $message_id The ID of the message to which this log entry belongs
+ * @return int The ID of the newly added log row
+ */
+ public function add_log($log_type, $message_id)
+ {
+ $this->db->sql_query('INSERT INTO ' . $this->mchat_settings->get_table_mchat_log() . ' ' . $this->db->sql_build_array('INSERT', [
+ 'log_type' => $this->get_type_id($log_type),
+ 'user_id' => (int) $this->user->data['user_id'],
+ 'message_id' => (int) $message_id,
+ 'log_ip' => $this->user->ip,
+ 'log_time' => time(),
+ ]));
+
+ $log_id = (int) $this->db->sql_nextid();
+
+ $this->cache->destroy('sql', $this->mchat_settings->get_table_mchat_log());
+
+ return $log_id;
+ }
+
+ /**
+ * Fetches log entries from the database and sorts them
+ *
+ * @param int $log_id The ID of the latest log entry that the user has
+ * @return array
+ */
+ public function get_logs($log_id)
+ {
+ $sql_array = [
+ 'SELECT' => 'ml.*',
+ 'FROM' => [$this->mchat_settings->get_table_mchat_log() => 'ml'],
+ 'WHERE' => 'ml.log_id > ' . (int) $log_id,
+ ];
+
+ $sql = $this->db->sql_build_query('SELECT', $sql_array);
+ $result = $this->db->sql_query($sql, 3600);
+ $rows = $this->db->sql_fetchrowset($result);
+ $this->db->sql_freeresult($result);
+
+ $log_rows = array_merge(array_fill_keys($this->get_types(), []), [
+ 'latest' => (int) $log_id,
+ ]);
+
+ $log_types = $this->get_types();
+ $edit_delete_limit = $this->mchat_settings->cfg('mchat_edit_delete_limit');
+ $time_limit = $edit_delete_limit ? time() - $edit_delete_limit : 0;
+
+ foreach ($rows as $log_row)
+ {
+ $log_rows['latest'] = max($log_rows['latest'], (int) $log_row['log_id']);
+
+ $log_type = $log_row['log_type'];
+
+ if (isset($log_types[$log_type]))
+ {
+ if ($log_row['user_id'] != $this->user->data['user_id'] && $log_row['log_time'] > $time_limit)
+ {
+ $log_type_name = $log_types[$log_type];
+ $log_rows[$log_type_name][] = (int) $log_row['message_id'];
+ }
+ }
+
+ /**
+ * Event that allows processing log messages
+ *
+ * @event dmzx.mchat.action_refresh_process_log_row
+ * @var array response The data that is sent back to the user (still incomplete at this point)
+ * @var array log_row The log data (read only)
+ * @since 2.0.0-RC6
+ */
+ $vars = [
+ 'response',
+ 'log_row',
+ ];
+ extract($this->dispatcher->trigger_event('dmzx.mchat.action_refresh_process_log_row', compact($vars)));
+
+ unset($log_row);
+ }
+
+ return $log_rows;
+ }
+
+ /**
+ * Fetches the highest log ID
+ *
+ * @return int
+ */
+ public function get_latest_id()
+ {
+ $sql_array = [
+ 'SELECT' => 'ml.log_id',
+ 'FROM' => [$this->mchat_settings->get_table_mchat_log() => 'ml'],
+ 'ORDER_BY' => 'log_id DESC',
+ ];
+
+ $sql = $this->db->sql_build_query('SELECT', $sql_array);
+ $result = $this->db->sql_query_limit($sql, 1);
+ $max_log_id = (int) $this->db->sql_fetchfield('log_id');
+ $this->db->sql_freeresult($result);
+
+ return $max_log_id;
+ }
+}
diff --git a/core/mchat.php b/core/mchat.php
index 199ed93..bcf5a34 100644
--- a/core/mchat.php
+++ b/core/mchat.php
@@ -17,6 +17,7 @@ use phpbb\controller\helper;
use phpbb\event\dispatcher_interface;
use phpbb\exception\http_exception;
use phpbb\extension\manager;
+use phpbb\language\language;
use phpbb\pagination;
use phpbb\request\request_interface;
use phpbb\template\template;
@@ -27,10 +28,16 @@ use Symfony\Component\HttpFoundation\JsonResponse;
class mchat
{
/** @var functions */
- protected $functions;
+ protected $mchat_functions;
+
+ /** @var notifications */
+ protected $mchat_notifications;
/** @var settings */
- protected $settings;
+ protected $mchat_settings;
+
+ /** @var log */
+ protected $mchat_log;
/** @var helper */
protected $helper;
@@ -41,6 +48,9 @@ class mchat
/** @var user */
protected $user;
+ /** @var language */
+ protected $lang;
+
/** @var auth */
protected $auth;
@@ -56,14 +66,8 @@ class mchat
/** @var manager */
protected $extension_manager;
- /** @var string */
- protected $root_path;
-
- /** @var string */
- protected $php_ext;
-
/** @var parser_interface */
- protected $parser;
+ protected $textformatter_parser;
/** @var cc_operator */
protected $cc_operator;
@@ -71,63 +75,67 @@ class mchat
/** @var boolean */
protected $remove_disallowed_bbcodes = false;
+ /** @var bool */
+ protected $custom_bbcodes_generated = false;
+
+ /** @var bool */
+ protected $smilies_generated = false;
+
/** @var array */
protected $foes = null;
/**
* Constructor
*
- * @param functions $functions
- * @param settings $settings
+ * @param functions $mchat_functions
+ * @param notifications $mchat_notifications
+ * @param settings $mchat_settings
+ * @param log $mchat_log
* @param helper $helper
* @param template $template
* @param user $user
+ * @param language $lang
* @param auth $auth
* @param pagination $pagination
* @param request_interface $request
* @param dispatcher_interface $dispatcher
* @param manager $extension_manager
- * @param string $root_path
- * @param string $php_ext
- * @param parser_interface $parser
+ * @param parser_interface $textformatter_parser
* @param cc_operator $cc_operator
*/
public function __construct(
- functions $functions,
- settings $settings,
+ functions $mchat_functions,
+ notifications $mchat_notifications,
+ settings $mchat_settings,
+ log $mchat_log,
helper $helper,
template $template,
user $user,
+ language $lang,
auth $auth,
pagination $pagination,
request_interface $request,
dispatcher_interface $dispatcher,
manager $extension_manager,
- $root_path,
- $php_ext,
- parser_interface $parser = null,
+ parser_interface $textformatter_parser,
cc_operator $cc_operator = null
)
{
- $this->functions = $functions;
- $this->settings = $settings;
+ $this->mchat_functions = $mchat_functions;
+ $this->mchat_notifications = $mchat_notifications;
+ $this->mchat_settings = $mchat_settings;
+ $this->mchat_log = $mchat_log;
$this->helper = $helper;
$this->template = $template;
$this->user = $user;
+ $this->lang = $lang;
$this->auth = $auth;
$this->pagination = $pagination;
$this->request = $request;
$this->dispatcher = $dispatcher;
$this->extension_manager = $extension_manager;
- $this->root_path = $root_path;
- $this->php_ext = $php_ext;
- $this->parser = $parser;
+ $this->textformatter_parser = $textformatter_parser;
$this->cc_operator = $cc_operator;
-
- $this->template->assign_vars(array(
- 'IS_PHPBB31' => $this->settings->is_phpbb31,
- 'IS_PHPBB32' => $this->settings->is_phpbb32,
- ));
}
/**
@@ -142,12 +150,12 @@ class mchat
$this->assign_whois();
- if (!$this->settings->cfg('mchat_index'))
+ if (!$this->mchat_settings->cfg('mchat_index'))
{
return;
}
- $this->user->add_lang_ext('dmzx/mchat', 'mchat');
+ $this->lang->add_lang('mchat', 'dmzx/mchat');
$this->assign_bbcodes_smilies();
@@ -171,14 +179,14 @@ class mchat
throw new http_exception(403, 'NOT_AUTHORISED');
}
- $this->user->add_lang_ext('dmzx/mchat', 'mchat');
+ $this->lang->add_lang('mchat', 'dmzx/mchat');
- if (!$this->settings->cfg('mchat_custom_page'))
+ if (!$this->mchat_settings->cfg('mchat_custom_page'))
{
throw new http_exception(404, 'MCHAT_NO_CUSTOM_PAGE');
}
- $this->functions->mchat_add_user_session();
+ $this->mchat_functions->mchat_add_user_session();
$this->assign_whois();
@@ -187,12 +195,12 @@ class mchat
$this->render_page('custom');
// Add to navlinks
- $this->template->assign_block_vars('navlinks', array(
- 'FORUM_NAME' => $this->user->lang('MCHAT_TITLE'),
+ $this->template->assign_block_vars('navlinks', [
+ 'FORUM_NAME' => $this->lang->lang('MCHAT_TITLE'),
'U_VIEW_FORUM' => $this->helper->route('dmzx_mchat_page_custom_controller'),
- ));
+ ]);
- return $this->helper->render('mchat_body.html', $this->user->lang('MCHAT_TITLE'));
+ return $this->helper->render('mchat_body.html', $this->lang->lang('MCHAT_TITLE'));
}
/**
@@ -202,7 +210,7 @@ class mchat
*/
public function page_archive()
{
- $this->user->add_lang_ext('dmzx/mchat', 'mchat');
+ $this->lang->add_lang('mchat', 'dmzx/mchat');
if (!$this->auth->acl_get('u_mchat_view') || !$this->auth->acl_get('u_mchat_archive'))
{
@@ -217,18 +225,18 @@ class mchat
$this->render_page('archive');
// Add to navlinks
- $this->template->assign_block_vars_array('navlinks', array(
- array(
- 'FORUM_NAME' => $this->user->lang('MCHAT_TITLE'),
+ $this->template->assign_block_vars_array('navlinks', [
+ [
+ 'FORUM_NAME' => $this->lang->lang('MCHAT_TITLE'),
'U_VIEW_FORUM' => $this->helper->route('dmzx_mchat_page_custom_controller'),
- ),
- array(
- 'FORUM_NAME' => $this->user->lang('MCHAT_ARCHIVE'),
+ ],
+ [
+ 'FORUM_NAME' => $this->lang->lang('MCHAT_ARCHIVE'),
'U_VIEW_FORUM' => $this->helper->route('dmzx_mchat_page_archive_controller'),
- ),
- ));
+ ],
+ ]);
- return $this->helper->render('mchat_body.html', $this->user->lang('MCHAT_ARCHIVE_PAGE'));
+ return $this->helper->render('mchat_body.html', $this->lang->lang('MCHAT_ARCHIVE_PAGE'));
}
/**
@@ -249,16 +257,13 @@ class mchat
throw new http_exception(403, 'NOT_AUTHORISED');
}
- $this->user->add_lang_ext('dmzx/mchat', 'mchat');
+ $this->lang->add_lang('mchat', 'dmzx/mchat');
- if (!function_exists('user_ipwhois'))
- {
- include($this->root_path . 'includes/functions_user.' . $this->php_ext);
- }
+ $this->mchat_settings->include_functions('user', 'user_ipwhois');
$this->template->assign_var('WHOIS', user_ipwhois($ip));
- return $this->helper->render('viewonline_whois.html', $this->user->lang('WHO_IS_ONLINE'));
+ return $this->helper->render('viewonline_whois.html', $this->lang->lang('WHO_IS_ONLINE'));
}
/**
@@ -278,23 +283,22 @@ class mchat
throw new http_exception(403, 'NOT_AUTHORISED');
}
- $this->user->add_lang_ext('dmzx/mchat', 'mchat');
+ $this->lang->add_lang('mchat', 'dmzx/mchat');
- $lang_rules = $this->user->lang('MCHAT_RULES_MESSAGE');
+ // If the rules are not empty in the language file, use them, else use the entry in the database
+ $mchat_rules = $this->lang->lang('MCHAT_RULES_MESSAGE') ?: $this->mchat_settings->cfg('mchat_rules');
- if (!$lang_rules && !$this->settings->cfg('mchat_rules'))
+ if (!$mchat_rules)
{
throw new http_exception(404, 'MCHAT_NO_RULES');
}
- // If the rules are defined in the language file use them, else just use the entry in the database
- $mchat_rules = $lang_rules ?: $this->settings->cfg('mchat_rules');
$mchat_rules = htmlspecialchars_decode($mchat_rules);
$mchat_rules = str_replace("\n", '
', $mchat_rules);
$this->template->assign_var('MCHAT_RULES', $mchat_rules);
- return $this->helper->render('mchat_rules.html', $this->user->lang('MCHAT_RULES'));
+ return $this->helper->render('mchat_rules.html', $this->lang->lang('MCHAT_RULES'));
}
/**
@@ -316,7 +320,7 @@ class mchat
define('PHPBB_USE_BOARD_URL_PATH', true);
}
- $this->user->add_lang_ext('dmzx/mchat', 'mchat');
+ $this->lang->add_lang('mchat', 'dmzx/mchat');
}
/**
@@ -329,25 +333,30 @@ class mchat
{
$this->init_action('u_mchat_use');
- if ($this->functions->mchat_is_user_flooding())
+ if ($this->mchat_functions->mchat_is_user_flooding())
{
throw new http_exception(400, 'MCHAT_FLOOD');
}
$message = $this->request->variable('message', '', true);
- if ($this->settings->cfg('mchat_capital_letter'))
+ if (!$this->mchat_settings->cfg('mchat_max_input_height'))
+ {
+ $message = preg_replace('/\s+/', ' ', $message);
+ }
+
+ if ($this->mchat_settings->cfg('mchat_capital_letter'))
{
$message = utf8_ucfirst($message);
}
$message_data = $this->process_message($message);
- $message_data = array_merge($message_data, array(
+ $message_data = array_merge($message_data, [
'user_id' => $this->user->data['user_id'],
'user_ip' => $this->user->ip,
'message_time' => time(),
- ));
+ ]);
/**
* Event to modify a new message before it is inserted in the database
@@ -357,13 +366,13 @@ class mchat
* @var array message_data Array containing additional information that is added to the database
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'message',
'message_data',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.action_add_before', compact($vars)));
- $is_new_session = $this->functions->mchat_action('add', $message_data);
+ $is_new_session = $this->mchat_functions->mchat_action('add', $message_data);
$response = $this->action_refresh(true);
@@ -383,13 +392,13 @@ class mchat
* @var boolean return_raw Whether to return a raw array or a JsonResponse object
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'message',
'message_data',
'is_new_session',
'response',
'return_raw',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.action_add_after', compact($vars)));
return $return_raw ? $response : new JsonResponse($response);
@@ -412,15 +421,15 @@ class mchat
throw new http_exception(403, 'NO_AUTH_OPERATION');
}
- $author = $this->functions->mchat_author_for_message($message_id);
+ $author = $this->mchat_functions->mchat_author_for_message($message_id);
if (!$author)
{
throw new http_exception(410, 'MCHAT_MESSAGE_DELETED');
}
- // If post_id is not 0 it's a notification and notifications can't be edited
- if ($author['post_id'] || !$this->auth_message('edit', $author['user_id'], $author['message_time']))
+ // Notifications can't be edited
+ if ($this->mchat_notifications->is_notification($author) || !$this->auth_message('edit', $author['user_id'], $author['message_time']))
{
throw new http_exception(403, 'NO_AUTH_OPERATION');
}
@@ -429,14 +438,14 @@ class mchat
$message = $this->request->variable('message', '', true);
$sql_ary = $this->process_message($message);
- $this->functions->mchat_action('edit', $sql_ary, $message_id);
+ $this->mchat_functions->mchat_action('edit', $sql_ary, $message_id);
- $rows = $this->functions->mchat_get_messages($message_id);
+ $rows = $this->mchat_functions->mchat_get_messages($message_id);
$this->assign_global_template_data();
$this->assign_messages($rows);
- $response = array('edit' => $this->render_template('mchat_messages.html'));
+ $response = ['edit' => $this->render_template('mchat_messages.html')];
/**
* Event to modify the data of an edited message
@@ -449,13 +458,13 @@ class mchat
* @var boolean return_raw Whether to return a raw array or a JsonResponse object
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'message_id',
'message',
'author',
'response',
'return_raw',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.action_edit_after', compact($vars)));
return $return_raw ? $response : new JsonResponse($response);
@@ -478,7 +487,7 @@ class mchat
throw new http_exception(403, 'NO_AUTH_OPERATION');
}
- $author = $this->functions->mchat_author_for_message($message_id);
+ $author = $this->mchat_functions->mchat_author_for_message($message_id);
if (!$author)
{
@@ -490,9 +499,9 @@ class mchat
throw new http_exception(403, 'NO_AUTH_OPERATION');
}
- $this->functions->mchat_action('del', null, $message_id);
+ $this->mchat_functions->mchat_action('del', null, $message_id);
- $response = array('del' => true);
+ $response = ['del' => $message_id];
/**
* Event that is triggered after an mChat message was deleted
@@ -504,12 +513,12 @@ class mchat
* @var boolean return_raw Whether to return a raw array or a JsonResponse object
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'message_id',
'author',
'response',
'return_raw',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.action_delete_after', compact($vars)));
return $return_raw ? $response : new JsonResponse($response);
@@ -526,10 +535,10 @@ class mchat
$this->init_action('u_mchat_view', false);
// Keep the session alive forever if there is no session timeout
- $keep_session_alive = !$this->settings->cfg('mchat_timeout');
+ $keep_session_alive = !$this->mchat_settings->cfg('mchat_timeout');
// Whether to check the log table for new entries
- $need_log_update = $this->settings->cfg('mchat_live_updates');
+ $need_log_update = $this->mchat_settings->cfg('mchat_live_updates');
/**
* Event that is triggered before new mChat messages are checked
@@ -539,10 +548,10 @@ class mchat
* @var bool need_log_update Whether to check the log table for new entries
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'keep_session_alive',
'need_log_update',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.action_refresh_before', compact($vars)));
if ($keep_session_alive)
@@ -550,52 +559,21 @@ class mchat
$this->user->update_session_infos();
}
- $response = array('refresh' => true);
- $log_edit_del_ids = array(
- 'edit' => array(),
- 'del' => array(),
- );
+ $response = ['refresh' => true];
if ($need_log_update)
{
$log_id = $this->request->variable('log', 0);
- $log_rows = $this->functions->mchat_get_logs($log_id);
+ $logs = $this->mchat_log->get_logs($log_id);
- $response['log'] = $log_rows['id'];
- unset($log_rows['id']);
+ $response['log'] = $logs['latest'];
+ unset($logs['latest']);
- $edit_delete_limit = $this->settings->cfg('mchat_edit_delete_limit');
- $time_limit = $edit_delete_limit ? time() - $edit_delete_limit : 0;
-
- foreach ($log_rows as $log_row)
- {
- $log_type = $log_row['log_type'];
-
- if (isset($this->functions->log_types[$log_type]))
- {
- if ($log_row['user_id'] != $this->user->data['user_id'] && $log_row['log_time'] > $time_limit)
- {
- $log_type_name = $this->functions->log_types[$log_type];
- $log_edit_del_ids[$log_type_name][] = (int) $log_row['message_id'];
- }
- }
-
- /**
- * Event that allows processing log messages
- *
- * @event dmzx.mchat.action_refresh_process_log_row
- * @var array response The data that is sent back to the user (still incomplete at this point)
- * @var array log_row The log data (read only)
- * @since 2.0.0-RC6
- */
- $vars = array(
- 'response',
- 'log_row',
- );
- extract($this->dispatcher->trigger_event('dmzx.mchat.action_refresh_process_log_row', compact($vars)));
-
- unset($log_row);
- }
+ $log_edit_del_ids = $logs;
+ }
+ else
+ {
+ $log_edit_del_ids = array_fill_keys($this->mchat_log->get_types(), []);
}
$last_id = $this->request->variable('last', 0);
@@ -613,18 +591,18 @@ class mchat
* @var int offset The number of messages to skip
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'response',
'log_edit_del_ids',
'last_id',
'total',
'offset',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.action_refresh_get_messages_before', compact($vars)));
- $rows = $this->functions->mchat_get_messages($log_edit_del_ids['edit'], $last_id, $total, $offset);
- $rows_refresh = array();
- $rows_edit = array();
+ $rows = $this->mchat_functions->mchat_get_messages($log_edit_del_ids['edit'], $last_id, $total, $offset);
+ $rows_refresh = [];
+ $rows_edit = [];
foreach ($rows as $row)
{
@@ -672,11 +650,11 @@ class mchat
* @var boolean return_raw Whether to return a raw array or a JsonResponse object
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'rows',
'response',
'return_raw',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.action_refresh_after', compact($vars)));
return $return_raw ? $response : new JsonResponse($response);
@@ -694,16 +672,16 @@ class mchat
$this->assign_whois();
- $response = array('whois' => true);
+ $response = ['whois' => true];
- if ($this->settings->cfg('mchat_whois_index'))
+ if ($this->mchat_settings->cfg('mchat_whois_index'))
{
$response['container'] = $this->render_template('mchat_whois.html');
}
- if ($this->settings->cfg('mchat_custom_page') && $this->settings->cfg('mchat_navbar_link') && $this->settings->cfg('mchat_navbar_link_count'))
+ if ($this->mchat_settings->cfg('mchat_navbar_link_count'))
{
- $active_users = $this->functions->mchat_active_users();
+ $active_users = $this->mchat_functions->mchat_active_users();
$response['navlink'] = $active_users['users_count_title'];
$response['navlink_title'] = strip_tags($active_users['users_total']);
}
@@ -716,10 +694,10 @@ class mchat
* @var boolean return_raw Whether to return a raw array or a JsonResponse object
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'response',
'return_raw',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.action_whois_after', compact($vars)));
return $return_raw ? $response : new JsonResponse($response);
@@ -735,20 +713,21 @@ class mchat
return;
}
- $navbar_link = $this->settings->cfg('mchat_navbar_link');
- $custom_page = $this->settings->cfg('mchat_custom_page');
+ $custom_page = $this->mchat_settings->cfg('mchat_custom_page');
+ $archive = $this->auth->acl_get('u_mchat_archive');
+ $rules = $this->lang->lang('MCHAT_RULES_MESSAGE') ?: $this->mchat_settings->cfg('mchat_rules');
- $template_data = array(
- 'MCHAT_NAVBAR_LINK' => $navbar_link,
- 'MCHAT_CUSTOM_PAGE' => $custom_page,
- 'MCHAT_TITLE' => $this->user->lang('MCHAT_TITLE'),
- 'MCHAT_TITLE_HINT' => $this->user->lang('MCHAT_TITLE'),
- 'U_MCHAT' => $this->helper->route('dmzx_mchat_page_custom_controller'),
- );
+ $template_data = [
+ 'MCHAT_TITLE' => $this->lang->lang('MCHAT_TITLE'),
+ 'MCHAT_TITLE_HINT' => $this->lang->lang('MCHAT_TITLE'),
+ 'U_MCHAT_CUSTOM_PAGE' => $custom_page ? $this->helper->route('dmzx_mchat_page_custom_controller') : false,
+ 'U_MCHAT_ARCHIVE' => $archive ? $this->helper->route('dmzx_mchat_page_archive_controller') : false,
+ 'U_MCHAT_RULES' => $rules ? $this->helper->route('dmzx_mchat_page_rules_controller') : false,
+ ];
- if ($navbar_link && $custom_page && $this->settings->cfg('mchat_navbar_link_count'))
+ if ($this->mchat_settings->cfg('mchat_navbar_link_count'))
{
- $active_users = $this->functions->mchat_active_users();
+ $active_users = $this->mchat_functions->mchat_active_users();
$template_data['MCHAT_TITLE'] = $active_users['users_count_title'];
$template_data['MCHAT_TITLE_HINT'] = strip_tags($active_users['users_total']);
}
@@ -770,76 +749,69 @@ class mchat
* @var string page The page that is rendered, one of index|custom|archive
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'page',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.render_page_before', compact($vars)));
// Add lang file
- $this->user->add_lang('posting');
+ $this->lang->add_lang('posting');
- // If the static message is defined in the language file use it, else the entry in the database is used
- $lang_static_message = $this->user->lang('MCHAT_STATIC_MESSAGE');
- $static_message = $lang_static_message ?: $this->settings->cfg('mchat_static_message');
- $whois_refresh = $this->settings->cfg('mchat_whois_index') || ($this->settings->cfg('mchat_custom_page') && $this->settings->cfg('mchat_navbar_link') && $this->settings->cfg('mchat_navbar_link_count'));
+ // If the static message is not empty in the language file, use it, else ise the static message in the database
+ $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');
- $this->template->assign_vars(array(
+ $this->template->assign_vars([
'MCHAT_PAGE' => $page,
- 'MCHAT_ALLOW_SMILES' => $this->settings->cfg('allow_smilies') && $this->auth->acl_get('u_mchat_smilies'),
- 'MCHAT_INPUT_AREA' => $this->settings->cfg('mchat_input_area'),
- 'MCHAT_MESSAGE_TOP' => $this->settings->cfg('mchat_message_top'),
- 'MCHAT_INDEX_HEIGHT' => $this->settings->cfg('mchat_index_height'),
- 'MCHAT_CUSTOM_HEIGHT' => $this->settings->cfg('mchat_custom_height'),
- 'MCHAT_LIVE_UPDATES' => $this->settings->cfg('mchat_live_updates'),
- 'MCHAT_LOCATION' => $this->settings->cfg('mchat_location'),
- 'MCHAT_CHARACTER_COUNT' => $this->settings->cfg('mchat_character_count'),
- 'MCHAT_SOUND' => $this->settings->cfg('mchat_sound'),
- 'MCHAT_SOUND_DISABLED' => !$this->settings->cfg('mchat_sound') && !$this->settings->cfg('mchat_sound', true),
- 'MCHAT_INDEX' => $this->settings->cfg('mchat_index'),
- 'MCHAT_PAUSE_ON_INPUT' => $this->settings->cfg('mchat_pause_on_input'),
- 'MCHAT_MESSAGE_LNGTH' => $this->settings->cfg('mchat_max_message_lngth'),
- 'MCHAT_WHOIS_INDEX' => $this->settings->cfg('mchat_whois_index'),
- 'MCHAT_WHOIS_REFRESH' => $whois_refresh ? $this->settings->cfg('mchat_whois_refresh') * 1000 : 0,
- 'MCHAT_REFRESH_JS' => $this->settings->cfg('mchat_refresh') * 1000,
+ 'MCHAT_ALLOW_SMILES' => $this->mchat_settings->cfg('allow_smilies') && $this->auth->acl_get('u_mchat_smilies'),
+ 'MCHAT_INPUT_AREA' => $this->mchat_settings->cfg('mchat_input_area'),
+ 'MCHAT_MESSAGE_TOP' => $this->mchat_settings->cfg('mchat_message_top'),
+ 'MCHAT_INDEX_HEIGHT' => $this->mchat_settings->cfg('mchat_index_height'),
+ 'MCHAT_CUSTOM_HEIGHT' => $this->mchat_settings->cfg('mchat_custom_height'),
+ 'MCHAT_LIVE_UPDATES' => $this->mchat_settings->cfg('mchat_live_updates'),
+ 'MCHAT_LOCATION' => $this->mchat_settings->cfg('mchat_location'),
+ 'MCHAT_CHARACTER_COUNT' => $this->mchat_settings->cfg('mchat_character_count'),
+ 'MCHAT_SOUND' => $this->mchat_settings->cfg('mchat_sound'),
+ 'MCHAT_SOUND_ENABLED' => $this->mchat_settings->cfg('mchat_sound') || $this->mchat_settings->cfg('mchat_sound', true),
+ 'MCHAT_INDEX' => $this->mchat_settings->cfg('mchat_index'),
+ 'MCHAT_WHOIS_INDEX' => $this->mchat_settings->cfg('mchat_whois_index'),
+ 'MCHAT_WHOIS_REFRESH' => $whois_refresh ? $this->mchat_settings->cfg('mchat_whois_refresh') * 1000 : 0,
+ 'MCHAT_REFRESH_JS' => $this->mchat_settings->cfg('mchat_refresh') * 1000,
'MCHAT_ARCHIVE' => $this->auth->acl_get('u_mchat_archive'),
- 'MCHAT_RULES' => $this->user->lang('MCHAT_RULES_MESSAGE') || $this->settings->cfg('mchat_rules'),
- 'MCHAT_SESSION_TIMELEFT' => $this->user->lang('MCHAT_SESSION_ENDS', gmdate($this->settings->cfg('mchat_timeout') >= 3600 ? 'H:i:s' : 'i:s', $this->settings->cfg('mchat_timeout'))),
- 'MCHAT_LOG_ID' => $this->functions->get_latest_log_id(),
+ 'MCHAT_RULES' => $this->lang->lang('MCHAT_RULES_MESSAGE') ?: $this->mchat_settings->cfg('mchat_rules'),
+ 'MCHAT_LOG_ID' => $this->mchat_log->get_latest_id(),
'MCHAT_STATIC_MESS' => htmlspecialchars_decode($static_message),
- 'MCHAT_MAX_MESSAGE_LENGTH' => $this->settings->cfg('mchat_max_message_lngth'),
- 'MCHAT_REFRESH_RATE' => $this->settings->cfg('mchat_refresh'),
- 'COOKIE_NAME' => $this->settings->cfg('cookie_name', true) . '_',
- 'U_MCHAT_CUSTOM_PAGE' => $this->helper->route('dmzx_mchat_page_custom_controller'),
- 'U_MCHAT_RULES' => $this->helper->route('dmzx_mchat_page_rules_controller'),
- 'U_MCHAT_ARCHIVE_URL' => $this->helper->route('dmzx_mchat_page_archive_controller'),
- ));
+ 'MCHAT_MAX_INPUT_HEIGHT' => $this->mchat_settings->cfg('mchat_max_input_height'),
+ 'MCHAT_MAX_MESSAGE_LENGTH' => $this->mchat_settings->cfg('mchat_max_message_lngth'),
+ 'COOKIE_NAME' => $this->mchat_settings->cfg('cookie_name', true) . '_',
+ ]);
// The template needs some language variables if we display relative time for messages
- if ($this->settings->cfg('mchat_relative_time'))
+ if ($this->mchat_settings->cfg('mchat_relative_time'))
{
$this->template->assign_var('MCHAT_MINUTES_AGO_LIMIT', $this->get_relative_minutes_limit());
}
// Get actions which the user is allowed to perform on the current page
- $actions = array_keys(array_filter(array(
+ $actions = array_keys(array_filter([
'edit' => $this->auth_message('edit', true, time()),
'del' => $this->auth_message('delete', true, time()),
'refresh' => $page !== 'archive' && $this->auth->acl_get('u_mchat_view'),
'add' => $page !== 'archive' && $this->auth->acl_get('u_mchat_use'),
'whois' => $page !== 'archive' && $whois_refresh,
- )));
+ ]));
foreach ($actions as $action)
{
- $this->template->assign_block_vars('mchaturl', array(
+ $this->template->assign_block_vars('mchaturl', [
'ACTION' => $action,
- 'URL' => $this->helper->route('dmzx_mchat_action_' . $action . '_controller', array(), false),
- ));
+ 'URL' => $this->helper->route('dmzx_mchat_action_' . $action . '_controller', [], false),
+ ]);
}
- $limit = $this->settings->cfg('mchat_message_num_' . $page);
+ $limit = $this->mchat_settings->cfg('mchat_message_num_' . $page);
$start = $page === 'archive' ? $this->request->variable('start', 0) : 0;
- $rows = $this->functions->mchat_get_messages(array(), 0, $limit, $start);
+ $rows = $this->mchat_functions->mchat_get_messages([], 0, $limit, $start);
$this->assign_global_template_data();
$this->assign_messages($rows, $page);
@@ -848,7 +820,7 @@ class mchat
if ($page === 'archive')
{
$archive_url = $this->helper->route('dmzx_mchat_page_archive_controller');
- $total_messages = $this->functions->mchat_total_message_count();
+ $total_messages = $this->mchat_functions->mchat_total_message_count();
/**
* Event to modify mChat pagination on the archive page
@@ -860,44 +832,44 @@ class mchat
* @var int start The message which should be considered currently active, used to determine the page we're on
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'archive_url',
'total_messages',
'limit',
'start',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.render_page_pagination_before', compact($vars)));
$this->pagination->generate_template_pagination($archive_url, 'pagination', 'start', $total_messages, $limit, $start);
- $this->template->assign_var('MCHAT_TOTAL_MESSAGES', $this->user->lang('MCHAT_TOTALMESSAGES', $total_messages));
+ $this->template->assign_var('MCHAT_TOTAL_MESSAGES', $this->lang->lang('MCHAT_TOTALMESSAGES', $total_messages));
}
// Render legend
if ($page !== 'index')
{
- $legend = $this->functions->mchat_legend();
- $this->template->assign_var('LEGEND', implode($this->user->lang('COMMA_SEPARATOR'), $legend));
+ $legend = $this->mchat_functions->mchat_legend();
+ $this->template->assign_var('LEGEND', implode($this->lang->lang('COMMA_SEPARATOR'), $legend));
}
// Make mChat collapsible
if ($page === 'index' && $this->cc_operator !== null)
{
$cc_fid = 'mchat';
- $this->template->assign_vars(array(
+ $this->template->assign_vars([
'MCHAT_IS_COLLAPSIBLE' => true,
'S_MCHAT_HIDDEN' => in_array($cc_fid, $this->cc_operator->get_user_categories()),
- 'U_MCHAT_COLLAPSE_URL' => $this->helper->route('phpbb_collapsiblecategories_main_controller', array(
+ 'U_MCHAT_COLLAPSE_URL' => $this->helper->route('phpbb_collapsiblecategories_main_controller', [
'forum_id' => $cc_fid,
'hash' => generate_link_hash('collapsible_' . $cc_fid),
- )),
- ));
+ ]),
+ ]);
}
$this->assign_authors();
if ($this->auth->acl_get('u_mchat_use'))
{
- add_form_key('mchat');
+ add_form_key('mchat', '_DMZX_MCHAT');
}
/**
@@ -908,10 +880,10 @@ class mchat
* @var array actions Array containing URLs to actions the user is allowed to perform
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'page',
'actions',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.render_page_after', compact($vars)));
}
@@ -920,20 +892,20 @@ class mchat
*/
protected function assign_authors()
{
- $md_manager = $this->extension_manager->create_extension_metadata_manager('dmzx/mchat', $this->template);
+ $md_manager = $this->extension_manager->create_extension_metadata_manager('dmzx/mchat');
$meta = $md_manager->get_metadata();
- $author_homepages = array();
+ $author_homepages = [];
- foreach (array_slice($meta['authors'], 0, 2) as $author)
+ foreach (array_slice($meta['authors'], 0, 1) as $author)
{
$author_homepages[] = sprintf('%2$s', $author['homepage'], $author['name']);
}
- $this->template->assign_vars(array(
+ $this->template->assign_vars([
'MCHAT_DISPLAY_NAME' => $meta['extra']['display-name'],
'MCHAT_AUTHOR_HOMEPAGES' => implode(' & ', $author_homepages),
- ));
+ ]);
}
/**
@@ -941,22 +913,22 @@ class mchat
*/
public function assign_global_template_data()
{
- $template_data = array(
- 'S_BBCODE_ALLOWED' => $this->auth->acl_get('u_mchat_bbcode') && $this->settings->cfg('allow_bbcode'),
+ $template_data = [
+ 'S_BBCODE_ALLOWED' => $this->auth->acl_get('u_mchat_bbcode') && $this->mchat_settings->cfg('allow_bbcode'),
'MCHAT_ALLOW_USE' => $this->auth->acl_get('u_mchat_use'),
'MCHAT_ALLOW_IP' => $this->auth->acl_get('u_mchat_ip'),
'MCHAT_ALLOW_PM' => $this->auth->acl_get('u_mchat_pm'),
'MCHAT_ALLOW_LIKE' => $this->auth->acl_get('u_mchat_like'),
'MCHAT_ALLOW_QUOTE' => $this->auth->acl_get('u_mchat_quote'),
'MCHAT_ALLOW_PERMISSIONS' => $this->auth->acl_get('a_authusers'),
- 'MCHAT_EDIT_DELETE_LIMIT' => 1000 * $this->settings->cfg('mchat_edit_delete_limit'),
- 'MCHAT_EDIT_DELETE_IGNORE' => $this->settings->cfg('mchat_edit_delete_limit') && ($this->auth->acl_get('u_mchat_moderator_edit') || $this->auth->acl_get('u_mchat_moderator_delete')),
- 'MCHAT_RELATIVE_TIME' => $this->settings->cfg('mchat_relative_time'),
- 'MCHAT_TIMEOUT' => 1000 * $this->settings->cfg('mchat_timeout'),
+ 'MCHAT_EDIT_DELETE_LIMIT' => 1000 * $this->mchat_settings->cfg('mchat_edit_delete_limit'),
+ 'MCHAT_EDIT_DELETE_IGNORE' => $this->mchat_settings->cfg('mchat_edit_delete_limit') && ($this->auth->acl_get('u_mchat_moderator_edit') || $this->auth->acl_get('u_mchat_moderator_delete')),
+ 'MCHAT_RELATIVE_TIME' => $this->mchat_settings->cfg('mchat_relative_time'),
+ 'MCHAT_TIMEOUT' => 1000 * $this->mchat_settings->cfg('mchat_timeout'),
'S_MCHAT_AVATARS' => $this->display_avatars(),
- 'EXT_URL' => generate_board_url() . '/ext/dmzx/mchat/',
- 'STYLE_PATH' => generate_board_url() . '/styles/' . rawurlencode($this->user->style['style_path']),
- );
+ 'EXT_URL' => $this->mchat_settings->url('ext/dmzx/mchat/', true, false),
+ 'STYLE_PATH' => $this->mchat_settings->url('styles/' . rawurlencode($this->user->style['style_path']), true, false),
+ ];
/**
* Event that allows adding global template data for mChat
@@ -965,9 +937,9 @@ class mchat
* @var array template_data The data that is about to be assigned to the template
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'template_data',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.global_modify_template_data', compact($vars)));
$this->template->assign_vars($template_data);
@@ -980,7 +952,7 @@ class mchat
*/
protected function display_avatars()
{
- return $this->settings->cfg('mchat_avatars') && $this->user->optionget('viewavatars');
+ return $this->mchat_settings->cfg('mchat_avatars') && $this->user->optionget('viewavatars');
}
/**
@@ -991,7 +963,7 @@ class mchat
*/
public function assign_messages($rows, $page = '')
{
- $rows = array_filter($rows, array($this, 'has_read_auth'));
+ $rows = array_filter($rows, [$this, 'has_read_auth']);
if (!$rows)
{
@@ -1001,10 +973,10 @@ class mchat
// At this point the rows are sorted by ID bottom to top.
// We need to reverse the array if they need to be sorted top to bottom.
$reverse = false;
- $mchat_message_top = $this->settings->cfg('mchat_message_top');
+ $mchat_message_top = $this->mchat_settings->cfg('mchat_message_top');
if ($page === 'archive')
{
- $mchat_archive_sort = $this->settings->cfg('mchat_archive_sort');
+ $mchat_archive_sort = $this->mchat_settings->cfg('mchat_archive_sort');
if ($mchat_archive_sort == settings::ARCHIVE_SORT_TOP_BOTTOM || $mchat_archive_sort == settings::ARCHIVE_SORT_USER && !$mchat_message_top)
{
$reverse = true;
@@ -1022,13 +994,13 @@ class mchat
if ($this->foes === null)
{
- $this->foes = $this->functions->mchat_foes();
+ $this->foes = $this->mchat_functions->mchat_foes();
}
// Remove template data from previous render
$this->template->destroy_block_vars('mchatrow');
- $user_avatars = array();
+ $user_avatars = [];
// Cache avatars
$display_avatar = $this->display_avatars();
@@ -1036,22 +1008,22 @@ class mchat
{
if (!isset($user_avatars[$row['user_id']]))
{
- $user_avatars[$row['user_id']] = !$display_avatar || !$row['user_avatar'] ? '' : phpbb_get_user_avatar(array(
+ $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,
- ));
+ ]);
}
}
$board_url = generate_board_url() . '/';
- $this->process_notifications($rows, $board_url);
+ $rows = $this->mchat_notifications->process($rows);
foreach ($rows as $row)
{
- $username_full = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang('GUEST'));
+ $username_full = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->lang->lang('GUEST'));
// Fix profile link root path by replacing relative paths with absolute board URL
if ($this->request->is_ajax())
@@ -1061,49 +1033,42 @@ class mchat
if (in_array($row['user_id'], $this->foes))
{
- $row['message'] = $this->user->lang('MCHAT_FOE', $username_full);
+ $row['message'] = $this->lang->lang('MCHAT_FOE', $username_full);
}
$message_age = time() - $row['message_time'];
$minutes_ago = $this->get_minutes_ago($message_age);
- $absolute_datetime = $this->user->format_date($row['message_time'], $this->settings->cfg('mchat_date'), true);
+ $absolute_datetime = $this->user->format_date($row['message_time'], $this->mchat_settings->cfg('mchat_date'), true);
// If relative time is selected, also display "today" / "yesterday", else display absolute time.
- if ($this->settings->cfg('mchat_relative_time'))
- {
- $datetime = $this->user->format_date($row['message_time'], $this->settings->cfg('mchat_date'), false);
- }
- else
- {
- $datetime = $this->user->format_date($row['message_time'], $this->settings->cfg('mchat_date'), true);
- }
+ $datetime = $this->user->format_date($row['message_time'], $this->mchat_settings->cfg('mchat_date'), !$this->mchat_settings->cfg('mchat_relative_time'));
$is_poster = $row['user_id'] != ANONYMOUS && $this->user->data['user_id'] == $row['user_id'];
$message_for_edit = generate_text_for_edit($row['message'], $row['bbcode_uid'], $row['bbcode_options']);
- $template_data = array(
+ $template_data = [
'MCHAT_ALLOW_EDIT' => $this->auth_message('edit', $row['user_id'], $row['message_time']),
'MCHAT_ALLOW_DEL' => $this->auth_message('delete', $row['user_id'], $row['message_time']),
'MCHAT_USER_AVATAR' => $user_avatars[$row['user_id']],
- 'U_VIEWPROFILE' => $row['user_id'] != ANONYMOUS ? append_sid("{$board_url}memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $row['user_id']) : '',
+ 'U_VIEWPROFILE' => $row['user_id'] != ANONYMOUS ? append_sid($this->mchat_settings->url('memberlist', true), ['mode' => 'viewprofile', 'u' => $row['user_id']]) : '',
'MCHAT_IS_POSTER' => $is_poster,
- 'MCHAT_IS_NOTIFICATION' => (bool) $row['post_id'],
- 'MCHAT_PM' => !$is_poster && $this->settings->cfg('allow_privmsg') && $this->auth->acl_get('u_sendpm') && ($row['user_allow_pm'] || $this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_')) ? append_sid("{$board_url}ucp.{$this->php_ext}", 'i=pm&mode=compose&mchat_pm_quote_message=' . (int) $row['message_id'] . '&u=' . $row['user_id']) : '',
+ 'MCHAT_IS_NOTIFICATION' => $this->mchat_notifications->is_notification($row),
+ 'MCHAT_PM' => !$is_poster && $this->mchat_settings->cfg('allow_privmsg') && $this->auth->acl_get('u_sendpm') && ($row['user_allow_pm'] || $this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_')) ? append_sid($this->mchat_settings->url('ucp', true), ['i' => 'pm', 'mode' => 'compose', 'mchat_pm_quote_message' => $row['message_id'], 'u' => $row['user_id']]) : '',
'MCHAT_MESSAGE_EDIT' => $message_for_edit['text'],
'MCHAT_MESSAGE_ID' => $row['message_id'],
'MCHAT_USERNAME_FULL' => $username_full,
- 'MCHAT_USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang('GUEST')),
- 'MCHAT_USERNAME_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang('GUEST')),
- 'MCHAT_WHOIS_USER' => $this->user->lang('MCHAT_WHOIS_USER', $row['user_ip']),
- 'MCHAT_U_IP' => $this->helper->route('dmzx_mchat_page_whois_controller', array('ip' => $row['user_ip'])),
- 'MCHAT_U_PERMISSIONS' => append_sid("{$board_url}adm/index.{$this->php_ext}", 'i=permissions&mode=setting_user_global&user_id%5B0%5D=' . $row['user_id'], true, $this->user->session_id),
+ 'MCHAT_USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour'], $this->lang->lang('GUEST')),
+ 'MCHAT_USERNAME_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour'], $this->lang->lang('GUEST')),
+ 'MCHAT_WHOIS_USER' => $this->lang->lang('MCHAT_WHOIS_USER', $row['user_ip']),
+ 'MCHAT_U_IP' => $this->helper->route('dmzx_mchat_page_whois_controller', ['ip' => $row['user_ip']]),
+ 'MCHAT_U_PERMISSIONS' => append_sid($this->mchat_settings->url('adm/index', true), ['i' => 'permissions', 'mode' => 'setting_user_global', rawurlencode('user_id[0]') => $row['user_id']], true, $this->user->session_id),
'MCHAT_MESSAGE' => generate_text_for_display($row['message'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']),
- 'MCHAT_TIME' => $minutes_ago === -1 ? $datetime : $this->user->lang('MCHAT_MINUTES_AGO', $minutes_ago),
+ 'MCHAT_TIME' => $minutes_ago === -1 ? $datetime : $this->lang->lang('MCHAT_MINUTES_AGO', $minutes_ago),
'MCHAT_DATETIME' => $absolute_datetime,
'MCHAT_MINUTES_AGO' => $minutes_ago,
'MCHAT_RELATIVE_UPDATE' => 60 - $message_age % 60,
'MCHAT_MESSAGE_TIME' => $row['message_time'],
- );
+ ];
/**
* Event to modify the template data of an mChat message before it is sent to the template
@@ -1111,7 +1076,6 @@ class mchat
* @event dmzx.mchat.message_modify_template_data
* @var array template_data The data that is about to be assigned to the template
* @var string username_full The link to the user profile, e.g. Username
- * @var bool is_notification Whether or not this message is a notification
* @var array row The raw message data as fetched from the database
* @var int message_age The number of seconds that have passed since the message was posted
* @var int minutes_ago The number of minutes that have passed since the message was posted, or -1
@@ -1120,17 +1084,16 @@ class mchat
* @var array message_for_edit The data for editing the message
* @since 2.0.0-RC6
*/
- $vars = array(
+ $vars = [
'template_data',
'username_full',
- 'is_notification',
'row',
'message_age',
'minutes_ago',
'datetime',
'is_poster',
'message_for_edit',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.message_modify_template_data', compact($vars)));
$this->template->assign_block_vars('mchatrow', $template_data);
@@ -1163,111 +1126,6 @@ class mchat
return true;
}
- /**
- * Checks the post rows for notifications and converts their language keys
- *
- * @param array $rows The rows to modify
- * @param string $board_url
- */
- protected function process_notifications(&$rows, $board_url)
- {
- $notification_post_ids = array();
-
- // 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 here.
- $notification_lang = array(
- 'MCHAT_NEW_POST',
- 'MCHAT_NEW_QUOTE',
- 'MCHAT_NEW_EDIT',
- 'MCHAT_NEW_REPLY',
- 'MCHAT_NEW_LOGIN',
- );
-
- foreach ($rows as $i => $row)
- {
- // If post_id is 0 it's not a notification.
- if ($row['post_id'] && in_array($row['message'], $notification_lang))
- {
- if ($row['forum_id'])
- {
- $notification_post_ids[] = $row['post_id'];
- }
- else
- {
- $rows[$i] = $this->process_notification($row, $board_url);
- }
- }
- }
-
- $notification_post_data = $this->functions->mchat_get_post_data($notification_post_ids);
-
- if ($notification_post_data)
- {
- foreach ($rows as $i => $row)
- {
- if (in_array($row['post_id'], $notification_post_ids))
- {
- $rows[$i] = $this->process_notification($row, $board_url, $notification_post_data[$row['post_id']]);
- }
- }
- }
- }
-
- /**
- * Converts the message field of the post row so that it can be passed to generate_text_for_display()
- *
- * @param array $row
- * @param string $board_url
- * @param array $post_data
- * @return array
- */
- protected function process_notification($row, $board_url, $post_data = null)
- {
- $args = array($row['message']);
-
- // If forum_id is 0 it's a login notification.
- // If forum_id is not 0 it's a post notification, we need to fetch forum name and post subject.
- if ($row['forum_id'])
- {
- $viewtopic_url = append_sid($board_url . 'viewtopic.' . $this->php_ext, array(
- 'p' => $row['post_id'],
- '#' => 'p' . $row['post_id'],
- ));
-
- // We prefer $post_data because it was fetched from the forums table just now.
- // $row might contain outdated data if a post was moved to a new forum.
- $forum_id = isset($post_data['forum_id']) ? $post_data['forum_id'] : $row['forum_id'];
-
- $viewforum_url = append_sid($board_url . 'viewforum.' . $this->php_ext, array(
- 'f' => $forum_id,
- ));
-
- if ($post_data)
- {
- $args[] = '[url=' . $viewtopic_url . ']' . $post_data['post_subject'] . '[/url]';
- $args[] = '[url=' . $viewforum_url . ']' . $post_data['forum_name'] . '[/url]';
- }
- else
- {
- $args[0] .= '_DELETED';
- }
- }
- else if ($row['post_id'] == functions::LOGIN_HIDDEN)
- {
- $row['username'] = '' . $row['username'] . '';
- }
-
- $row['message'] = call_user_func_array(array($this->user, 'lang'), $args);
-
- // Quick'n'dirty check if BBCodes are in the message
- if (strpos($row['message'], '[') !== false)
- {
- generate_text_for_storage($row['message'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options'], true, true, true);
- }
-
- return $row;
- }
-
/**
* Calculates the number of minutes that have passed since the message was posted.
* If relative time is disabled or the message is older than 59 minutes, -1 is returned.
@@ -1277,7 +1135,7 @@ class mchat
*/
protected function get_minutes_ago($message_age)
{
- if ($this->settings->cfg('mchat_relative_time'))
+ if ($this->mchat_settings->cfg('mchat_relative_time'))
{
$minutes_ago = floor($message_age / 60);
if ($minutes_ago < $this->get_relative_minutes_limit())
@@ -1298,11 +1156,11 @@ class mchat
*/
protected function get_relative_minutes_limit()
{
- $timeout = $this->settings->cfg('mchat_timeout');
+ $timeout = $this->mchat_settings->cfg('mchat_timeout');
if (!$timeout)
{
- $timeout = $this->settings->cfg('session_length');
+ $timeout = $this->mchat_settings->cfg('session_length');
}
return min(max((int) ceil($timeout / 60), 1), 60);
@@ -1314,51 +1172,48 @@ class mchat
protected function assign_bbcodes_smilies()
{
// Display BBCodes
- if ($this->settings->cfg('allow_bbcode') && $this->auth->acl_get('u_mchat_bbcode'))
+ if ($this->mchat_settings->cfg('allow_bbcode') && $this->auth->acl_get('u_mchat_bbcode'))
{
- $bbcode_template_vars = array(
- 'quote' => array(
+ $bbcode_template_vars = [
+ 'quote' => [
'allow' => true,
'template_var' => 'S_BBCODE_QUOTE',
- ),
- 'img' => array(
+ ],
+ 'img' => [
'allow' => true,
'template_var' => 'S_BBCODE_IMG',
- ),
- 'url' => array(
- 'allow' => $this->settings->cfg('allow_post_links'),
+ ],
+ 'url' => [
+ 'allow' => $this->mchat_settings->cfg('allow_post_links'),
'template_var' => 'S_LINKS_ALLOWED',
- ),
- 'flash' => array(
- 'allow' => $this->settings->cfg('allow_post_flash'),
+ ],
+ 'flash' => [
+ 'allow' => $this->mchat_settings->cfg('allow_post_flash'),
'template_var' => 'S_BBCODE_FLASH',
- ),
- );
+ ],
+ ];
foreach ($bbcode_template_vars as $bbcode => $option)
{
- $is_disallowed = preg_match('#(^|\|)' . $bbcode . '($|\|)#Usi', $this->settings->cfg('mchat_bbcode_disallowed')) || !$option['allow'];
+ $is_disallowed = preg_match('#(^|\|)' . $bbcode . '($|\|)#Usi', $this->mchat_settings->cfg('mchat_bbcode_disallowed')) || !$option['allow'];
$this->template->assign_var($option['template_var'], !$is_disallowed);
}
- $this->template->assign_var('MCHAT_DISALLOWED_BBCODES', $this->settings->cfg('mchat_bbcode_disallowed'));
+ $this->template->assign_var('MCHAT_DISALLOWED_BBCODES', $this->mchat_settings->cfg('mchat_bbcode_disallowed'));
- if (!function_exists('display_custom_bbcodes'))
+ if (!$this->custom_bbcodes_generated)
{
- include($this->root_path . 'includes/functions_display.' . $this->php_ext);
- }
+ $this->mchat_settings->include_functions('display', 'display_custom_bbcodes');
- $this->remove_disallowed_bbcodes = true;
- display_custom_bbcodes();
+ $this->remove_disallowed_bbcodes = true;
+ display_custom_bbcodes();
+ }
}
// Display smilies
- if ($this->settings->cfg('allow_smilies') && $this->auth->acl_get('u_mchat_smilies'))
+ if ($this->mchat_settings->cfg('allow_smilies') && $this->auth->acl_get('u_mchat_smilies') && !$this->smilies_generated)
{
- if (!function_exists('generate_smilies'))
- {
- include($this->root_path . 'includes/functions_posting.' . $this->php_ext);
- }
+ $this->mchat_settings->include_functions('posting', 'generate_smilies');
generate_smilies('inline', 0);
}
@@ -1375,7 +1230,7 @@ class mchat
// Add disallowed BBCodes to the template only if we're rendering for mChat
if ($this->remove_disallowed_bbcodes)
{
- $sql_ary['WHERE'] = $this->functions->mchat_sql_append_forbidden_bbcodes($sql_ary['WHERE']);
+ $sql_ary['WHERE'] = $this->mchat_functions->mchat_sql_append_forbidden_bbcodes($sql_ary['WHERE']);
}
return $sql_ary;
@@ -1389,27 +1244,14 @@ class mchat
*/
public function set_user_default_values($sql_ary)
{
- foreach (array_keys($this->settings->ucp_settings()) as $config_name)
+ foreach (array_keys($this->mchat_settings->ucp_settings()) as $config_name)
{
- $sql_ary['user_' . $config_name] = $this->settings->cfg($config_name, true);
+ $sql_ary['user_' . $config_name] = $this->mchat_settings->cfg($config_name, true);
}
return $sql_ary;
}
- /**
- * Inserts a message with posting information into the database
- *
- * @param string $mode One of post|quote|edit|reply|login
- * @param int $forum_id Can be 0 if mode is login.
- * @param int $post_id Can be 0 if mode is login.
- */
- public function insert_posting($mode, $forum_id = 0, $post_id = 0)
- {
- $is_hidden_login = $this->request->is_set_post('viewonline') || !$this->user->data['user_allow_viewonline'];
- $this->functions->mchat_insert_posting($mode, $forum_id, $post_id, $is_hidden_login);
- }
-
/**
* Fetches the message text of the given ID, quotes it using the current user name and assigns it to the template
*
@@ -1422,7 +1264,7 @@ class mchat
return;
}
- $rows = $this->functions->mchat_get_messages($mchat_message_id);
+ $rows = $this->mchat_functions->mchat_get_messages($mchat_message_id);
$row = reset($rows);
if (!$row || !$this->has_read_auth($row))
@@ -1432,8 +1274,7 @@ class mchat
if ($row['post_id'])
{
- $rows = array($row);
- $this->process_notifications($rows, generate_board_url() . '/');
+ $rows = $this->mchat_notifications->process([$row]);
$row = reset($rows);
}
@@ -1448,7 +1289,7 @@ class mchat
*/
public function session_gc()
{
- $this->functions->mchat_session_gc();
+ $this->mchat_functions->mchat_session_gc();
}
/**
@@ -1456,16 +1297,16 @@ class mchat
*/
protected function assign_whois()
{
- if ($this->settings->cfg('mchat_whois_index') || $this->settings->cfg('mchat_stats_index'))
+ if ($this->mchat_settings->cfg('mchat_whois_index') || $this->mchat_settings->cfg('mchat_stats_index'))
{
- $active_users = $this->functions->mchat_active_users();
+ $active_users = $this->mchat_functions->mchat_active_users();
- $this->template->assign_vars(array(
- 'MCHAT_STATS_INDEX' => $this->settings->cfg('mchat_stats_index'),
+ $this->template->assign_vars([
+ 'MCHAT_STATS_INDEX' => $this->mchat_settings->cfg('mchat_stats_index'),
'MCHAT_USERS_TOTAL' => $active_users['users_total'],
- 'MCHAT_USERS_LIST' => $active_users['online_userlist'] ?: '',
+ 'MCHAT_USERS_LIST' => $active_users['online_userlist'],
'MCHAT_ONLINE_EXPLAIN' => $active_users['refresh_message'],
- ));
+ ]);
}
}
@@ -1489,7 +1330,7 @@ class mchat
return false;
}
- return !$this->settings->cfg('mchat_edit_delete_limit') || $message_time >= time() - $this->settings->cfg('mchat_edit_delete_limit');
+ return !$this->mchat_settings->cfg('mchat_edit_delete_limit') || $message_time >= time() - $this->mchat_settings->cfg('mchat_edit_delete_limit');
}
/**
@@ -1509,36 +1350,35 @@ class mchat
}
// Must not exceed character limit
- if ($this->settings->cfg('mchat_max_message_lngth'))
+ if ($this->mchat_settings->cfg('mchat_max_message_lngth'))
{
$message_without_entities = htmlspecialchars_decode($message, ENT_COMPAT);
- if (utf8_strlen($message_without_entities) > $this->settings->cfg('mchat_max_message_lngth'))
+ if (utf8_strlen($message_without_entities) > $this->mchat_settings->cfg('mchat_max_message_lngth'))
{
- throw new http_exception(400, 'MCHAT_MESS_LONG', array($this->settings->cfg('mchat_max_message_lngth')));
+ throw new http_exception(400, 'MCHAT_MESS_LONG', [$this->mchat_settings->cfg('mchat_max_message_lngth')]);
}
}
- if ($this->settings->cfg('mchat_override_min_post_chars'))
+ if ($this->mchat_settings->cfg('mchat_override_min_post_chars'))
{
- $this->settings->set_cfg('min_post_chars', 0, true);
+ $this->mchat_settings->set_cfg('min_post_chars', 0, true);
}
- if ($this->settings->cfg('mchat_override_smilie_limit'))
+ if ($this->mchat_settings->cfg('mchat_override_smilie_limit'))
{
- $this->settings->set_cfg('max_post_smilies', 0, true);
+ $this->mchat_settings->set_cfg('max_post_smilies', 0, true);
}
- $disallowed_bbcodes = array_filter(explode('|', $this->settings->cfg('mchat_bbcode_disallowed')));
+ $disallowed_bbcodes = array_filter(explode('|', $this->mchat_settings->cfg('mchat_bbcode_disallowed')));
- $mchat_bbcode = $this->settings->cfg('allow_bbcode') && $this->auth->acl_get('u_mchat_bbcode');
- $mchat_magic_urls = $this->settings->cfg('allow_post_links') && $this->auth->acl_get('u_mchat_urls');
- $mchat_smilies = $this->settings->cfg('allow_smilies') && $this->auth->acl_get('u_mchat_smilies');
+ $mchat_bbcode = $this->mchat_settings->cfg('allow_bbcode') && $this->auth->acl_get('u_mchat_bbcode');
+ $mchat_magic_urls = $this->mchat_settings->cfg('allow_post_links') && $this->auth->acl_get('u_mchat_urls');
+ $mchat_smilies = $this->mchat_settings->cfg('allow_smilies') && $this->auth->acl_get('u_mchat_smilies');
- // These arguments for generate_text_for_storage() are ignored in 3.1.x
$mchat_img = $mchat_flash = $mchat_quote = $mchat_url = $mchat_bbcode;
- // Disallowed bbcodes for 3.2.x
- if ($disallowed_bbcodes && $this->parser !== null)
+ // Disallowed bbcodes
+ if ($disallowed_bbcodes)
{
$mchat_img &= !in_array('img', $disallowed_bbcodes);
$mchat_flash &= !in_array('flash', $disallowed_bbcodes);
@@ -1547,30 +1387,35 @@ class mchat
foreach ($disallowed_bbcodes as $bbcode)
{
- $this->parser->disable_bbcode($bbcode);
+ $this->textformatter_parser->disable_bbcode($bbcode);
}
}
$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);
+ generate_text_for_storage($message, $uid, $bitfield, $options, $mchat_bbcode, $mchat_magic_urls, $mchat_smilies, $mchat_img, $mchat_flash, $mchat_quote, $mchat_url, 'mchat');
- // Disallowed bbcodes for 3.1.x
- if ($disallowed_bbcodes && $this->parser === null)
- {
- $bbcode_replace = array(
- '#\[(' . str_replace('*', '\*', $this->settings->cfg('mchat_bbcode_disallowed')) . ')[^\[\]]+\]#Usi',
- '#\[/(' . str_replace('*', '\*', $this->settings->cfg('mchat_bbcode_disallowed')) . ')[^\[\]]+\]#Usi',
- );
-
- $message = preg_replace($bbcode_replace, '', $message);
- }
-
- return array(
+ return [
'message' => str_replace("'", ''', $message),
'bbcode_bitfield' => $bitfield,
'bbcode_uid' => $uid,
'bbcode_options' => $options,
- );
+ ];
+ }
+
+ /**
+ * @param bool $custom_bbcodes_generated
+ */
+ public function set_custom_bbcodes_generated($custom_bbcodes_generated)
+ {
+ $this->custom_bbcodes_generated = $custom_bbcodes_generated;
+ }
+
+ /**
+ * @param bool $smilies_generated
+ */
+ public function set_smilies_generated($smilies_generated)
+ {
+ $this->smilies_generated = $smilies_generated;
}
/**
@@ -1581,7 +1426,7 @@ class mchat
*/
public function render_template($template_file)
{
- $this->template->set_filenames(array('body' => $template_file));
+ $this->template->set_filenames(['body' => $template_file]);
$content = $this->template->assign_display('body', '', true);
return trim($content);
diff --git a/core/notifications.php b/core/notifications.php
new file mode 100644
index 0000000..07d705b
--- /dev/null
+++ b/core/notifications.php
@@ -0,0 +1,399 @@
+mchat_settings = $mchat_settings;
+ $this->user = $user;
+ $this->lang = $lang;
+ $this->auth = $auth;
+ $this->db = $db;
+ $this->dispatcher = $dispatcher;
+ $this->textformatter_parser = $textformatter_parser;
+ }
+
+ /**
+ * Checks whether or not the given message row is a notification
+ *
+ * @param array $row The message row
+ * @return int the notification type, or 0 if the $row is not a notification
+ */
+ public function is_notification($row)
+ {
+ // If post_id is 0 it's not a notification
+ if (isset($row['post_id']) && $row['post_id'])
+ {
+ // If forum_id is 0 it's a login notification
+ if (isset($row['forum_id']) && !$row['forum_id'])
+ {
+ // post_id is either LOGIN_VISIBLE or LOGIN_HIDDEN
+ return $row['post_id'];
+ }
+
+ return self::POST;
+ }
+
+ return 0;
+ }
+
+ /**
+ * Checks the post rows for notifications and converts their language keys
+ *
+ * @param array $rows The rows to modify
+ * @return array
+ */
+ 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.
+ $notification_lang = [
+ 'MCHAT_NEW_POST',
+ 'MCHAT_NEW_QUOTE',
+ 'MCHAT_NEW_EDIT',
+ 'MCHAT_NEW_REPLY',
+ 'MCHAT_NEW_LOGIN',
+ ];
+
+ $notification_langs = array_merge(
+ // Raw notification messages in phpBB < 3.2
+ array_combine($notification_lang, $notification_lang),
+ // XML notification messages in phpBB >= 3.2
+ array_combine(array_map([$this->textformatter_parser, 'parse'], $notification_lang), $notification_lang)
+ );
+
+ $notifications = [];
+ $post_ids = [];
+
+ foreach ($rows as $i => $row)
+ {
+ $type = $this->is_notification($row);
+
+ if ($type && isset($notification_langs[$row['message']]))
+ {
+ $notifications[$i] = $type;
+
+ if ($type == self::POST)
+ {
+ $post_ids[$i] = $row['post_id'];
+ }
+ }
+ }
+
+ $notification_post_data = $this->mchat_get_post_data($post_ids);
+
+ foreach ($notifications as $i => $type)
+ {
+ $lang_key = $notification_langs[$rows[$i]['message']];
+ $post_data = $type == self::POST ? $notification_post_data[$post_ids[$i]] : null;
+ $rows[$i] = $this->process_notification($rows[$i], $type, $lang_key, $post_data);
+ }
+
+ return $rows;
+ }
+
+ /**
+ * Fetches post subjects and their forum names. If a post_id can't be found the value for the post_id is set to null.
+ *
+ * @param array $post_ids
+ * @return array
+ */
+ protected function mchat_get_post_data($post_ids)
+ {
+ if (!$post_ids)
+ {
+ return [];
+ }
+
+ $sql_array = [
+ 'SELECT' => 'p.post_id, p.post_subject, f.forum_id, f.forum_name',
+ 'FROM' => [POSTS_TABLE => 'p', FORUMS_TABLE => 'f'],
+ 'WHERE' => 'p.forum_id = f.forum_id AND ' . $this->db->sql_in_set('p.post_id', $post_ids),
+ ];
+
+ $sql = $this->db->sql_build_query('SELECT', $sql_array);
+ $result = $this->db->sql_query($sql);
+ $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'],
+ ];
+ }
+
+ // Map IDs of missing posts to null
+ $missing_post_subjects = array_fill_keys(array_diff($post_ids, array_keys($post_subjects)), null);
+
+ return $post_subjects + $missing_post_subjects;
+ }
+
+ /**
+ * Converts the message field of the post row so that it can be passed to generate_text_for_display()
+ *
+ * @param array $row
+ * @param int $type
+ * @param string $lang_key
+ * @param array $post_data
+ * @return array
+ */
+ protected function process_notification($row, $type, $lang_key, $post_data = null)
+ {
+ $lang_args = [];
+ $replacements = [];
+
+ $post_subject_placeholder = '%POST_SUBJECT%';
+ $forum_name_placeholder = '%FORUM_NAME%';
+
+ if ($type == self::POST)
+ {
+ if ($post_data)
+ {
+ $viewtopic_url = append_sid($this->mchat_settings->url('viewtopic', true), [
+ 'p' => $row['post_id'],
+ '#' => 'p' . $row['post_id'],
+ ]);
+
+ // We prefer $post_data because it was fetched from the forums table just now.
+ // $row might contain outdated data if a post was moved to a new forum.
+ $forum_id = isset($post_data['forum_id']) ? $post_data['forum_id'] : $row['forum_id'];
+
+ $viewforum_url = append_sid($this->mchat_settings->url('viewforum', true), [
+ 'f' => $forum_id,
+ ]);
+
+ $lang_args[] = '[url=' . $viewtopic_url . ']' . $post_subject_placeholder . '[/url]';
+ $lang_args[] = '[url=' . $viewforum_url . ']' . $forum_name_placeholder . '[/url]';
+
+ $replacements = [
+ $post_subject_placeholder => $post_data['post_subject'],
+ $forum_name_placeholder => $post_data['forum_name'],
+ ];
+ }
+ else
+ {
+ $lang_key .= '_DELETED';
+ }
+ }
+ else if ($type == self::LOGIN_HIDDEN)
+ {
+ $row['username'] = '' . $row['username'] . '';
+ }
+
+ $row['message'] = $this->lang->lang_array($lang_key, $lang_args);
+
+ // Quick'n'dirty check if BBCodes are in the message
+ if (strpos($row['message'], '[') !== false)
+ {
+ generate_text_for_storage($row['message'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options'], true, true, true, true, true, true, true, 'mchat');
+ }
+
+ $row['message'] = strtr($row['message'], $replacements);
+
+ return $row;
+ }
+
+ /**
+ * Inserts a message with posting information into the database
+ *
+ * @param string $mode One of post|quote|edit|reply
+ * @param int $forum_id
+ * @param int $post_id
+ */
+ public function insert_post($mode, $forum_id, $post_id)
+ {
+ $this->insert($mode, $forum_id, $post_id);
+ }
+
+ /**
+ * Inserts a message with login information into the database
+ *
+ * @param bool $is_hidden
+ */
+ public function insert_login($is_hidden)
+ {
+ $this->insert('login', 0, $is_hidden ? self::LOGIN_HIDDEN : self::LOGIN_VISIBLE);
+ }
+
+ /**
+ * Inserts a message with posting or login information into the database
+ *
+ * @param string $mode One of post|quote|edit|reply|login
+ * @param int $forum_id
+ * @param int $post_id Can be 0 if mode is login.
+ */
+ protected function insert($mode, $forum_id, $post_id)
+ {
+ $mode_config = [
+ 'post' => 'mchat_posts_topic',
+ 'quote' => 'mchat_posts_quote',
+ 'edit' => 'mchat_posts_edit',
+ 'reply' => 'mchat_posts_reply',
+ 'login' => 'mchat_posts_login',
+ ];
+
+ $is_mode_enabled = !empty($mode_config[$mode]) && $this->mchat_settings->cfg($mode_config[$mode]) && (!$this->mchat_settings->cfg('mchat_posts_auth_check') || $this->can_use_mchat());
+
+ $sql_array = [
+ 'forum_id' => (int) $forum_id,
+ 'post_id' => (int) $post_id,
+ 'user_id' => (int) $this->user->data['user_id'],
+ 'user_ip' => $this->user->ip,
+ 'message' => $this->textformatter_parser->parse('MCHAT_NEW_' . strtoupper($mode)),
+ 'message_time' => time(),
+ ];
+
+ /**
+ * Event that allows to modify data of a posting or login notification before it is inserted in the database
+ *
+ * @event dmzx.mchat.insert_posting_before
+ * @var string mode The posting mode, one of post|quote|edit|reply|login
+ * @var int forum_id The ID of the forum where the post was made, or 0 if mode is login.
+ * @var int post_id The ID of the post that was made. If mode is login this value is
+ * one of the constants LOGIN_HIDDEN|LOGIN_VISIBLE
+ * @var array is_mode_enabled Whether or not the posting should be added to the database.
+ * @var array sql_array An array containing the data that is about to be inserted into the messages table.
+ * @since 2.0.0-RC6
+ * @changed 2.1.0-RC1 Removed is_hidden_login
+ */
+ $vars = [
+ 'mode',
+ 'forum_id',
+ 'post_id',
+ 'is_mode_enabled',
+ 'sql_array',
+ ];
+ extract($this->dispatcher->trigger_event('dmzx.mchat.insert_posting_before', compact($vars)));
+
+ if ($is_mode_enabled)
+ {
+ $sql = 'INSERT INTO ' . $this->mchat_settings->get_table_mchat() . ' ' . $this->db->sql_build_array('INSERT', $sql_array);
+ $this->db->sql_query($sql);
+ }
+ }
+
+ /**
+ * The user might have just logged in successfully in which case the permissions haven't been updated yet.
+ * Let's do that here so that notifications are recorded correctly.
+ *
+ * @return bool
+ */
+ protected function can_use_mchat()
+ {
+ if ($this->auth->acl_get('u_mchat_use'))
+ {
+ return true;
+ }
+
+ $auth = new auth();
+ $auth->acl($this->user->data);
+ return $auth->acl_get('u_mchat_use');
+ }
+
+ /**
+ * Generates an SQL WHERE condition to include or exlude notifacation
+ * messages based on the current user's settings and permissions
+ *
+ * @return string
+ */
+ public function get_sql_where()
+ {
+ // Exclude all post notifications
+ if (!$this->mchat_settings->cfg('mchat_posts'))
+ {
+ return 'm.post_id = 0';
+ }
+
+ // If the current user doesn't have permission to see hidden users, exclude their login posts
+ if (!$this->auth->acl_get('u_viewonline'))
+ {
+ return implode(' OR ', [
+ 'm.post_id <> ' . self::LOGIN_HIDDEN, // Exclude all notifications that were created by hidden users ...
+ 'm.user_id = ' . (int) $this->user->data['user_id'], // ... but include all login notifications of the current user
+ 'm.forum_id <> 0', // ... and include all post notifications
+ ]);
+ }
+
+ return '';
+ }
+}
diff --git a/core/settings.php b/core/settings.php
index 1ac2eea..d43c91a 100644
--- a/core/settings.php
+++ b/core/settings.php
@@ -15,6 +15,7 @@ use phpbb\auth\auth;
use phpbb\config\config;
use phpbb\config\db_text;
use phpbb\event\dispatcher_interface;
+use phpbb\language\language;
use phpbb\user;
class settings
@@ -22,6 +23,9 @@ class settings
/** @var user */
protected $user;
+ /** @var language */
+ protected $lang;
+
/** @var config */
protected $config;
@@ -34,6 +38,24 @@ class settings
/** @var dispatcher_interface */
protected $dispatcher;
+ /** @var string */
+ protected $root_path;
+
+ /** @var string */
+ protected $php_ext;
+
+ /** @var string */
+ protected $mchat_table;
+
+ /** @var string */
+ protected $mchat_log_table;
+
+ /** @var string */
+ protected $mchat_sessions_table;
+
+ /** @var string */
+ protected $board_url;
+
/**
* Keys for global settings that only the administrator is allowed to modify.
* The values are stored in the phpbb_config table.
@@ -74,18 +96,12 @@ class settings
*
* @var array
*/
- public $prune_modes = array(
+ public $prune_modes = [
0 => 'messages',
1 => 'hours',
24 => 'days',
168 => 'weeks',
- );
-
- /** @var bool */
- public $is_phpbb31;
-
- /** @var bool */
- public $is_phpbb32;
+ ];
/**
* Possible values of the global setting mchat_archive_sort
@@ -98,27 +114,42 @@ class settings
* Constructor
*
* @param user $user
+ * @param language $lang
* @param config $config
* @param db_text $config_text
* @param auth $auth
* @param dispatcher_interface $dispatcher
+ * @param string $root_path
+ * @param string $php_ext
+ * @param string $mchat_table
+ * @param string $mchat_log_table
+ * @param string $mchat_sessions_table
*/
public function __construct(
user $user,
+ language $lang,
config $config,
db_text $config_text,
auth $auth,
- dispatcher_interface $dispatcher
+ dispatcher_interface $dispatcher,
+ $root_path,
+ $php_ext,
+ $mchat_table,
+ $mchat_log_table,
+ $mchat_sessions_table
)
{
- $this->user = $user;
- $this->config = $config;
- $this->config_text = $config_text;
- $this->auth = $auth;
- $this->dispatcher = $dispatcher;
-
- $this->is_phpbb31 = phpbb_version_compare(PHPBB_VERSION, '3.1.0@dev', '>=') && phpbb_version_compare(PHPBB_VERSION, '3.2.0@dev', '<');
- $this->is_phpbb32 = phpbb_version_compare(PHPBB_VERSION, '3.2.0@dev', '>=') && phpbb_version_compare(PHPBB_VERSION, '3.3.0@dev', '<');
+ $this->user = $user;
+ $this->lang = $lang;
+ $this->config = $config;
+ $this->config_text = $config_text;
+ $this->auth = $auth;
+ $this->dispatcher = $dispatcher;
+ $this->root_path = $root_path;
+ $this->php_ext = $php_ext;
+ $this->mchat_table = $mchat_table;
+ $this->mchat_log_table = $mchat_log_table;
+ $this->mchat_sessions_table = $mchat_sessions_table;
}
/**
@@ -126,37 +157,38 @@ class settings
*/
public function initialize_global_settings()
{
- $global_settings = array(
- 'mchat_archive_sort' => array('default' => self::ARCHIVE_SORT_BOTTOM_TOP),
- 'mchat_bbcode_disallowed' => array('default' => '', 'validation' => array('string', false, 0, 255)),
- 'mchat_custom_height' => array('default' => 350, 'validation' => array('num', false, 50, 1000)),
- 'mchat_custom_page' => array('default' => 1),
- 'mchat_edit_delete_limit' => array('default' => 0),
- 'mchat_flood_time' => array('default' => 0, 'validation' => array('num', false, 0, 60)),
- 'mchat_index_height' => array('default' => 250, 'validation' => array('num', false, 50, 1000)),
- 'mchat_live_updates' => array('default' => 1),
- 'mchat_max_message_lngth' => array('default' => 500, 'validation' => array('num', false, 0, 1000)),
- 'mchat_message_num_archive' => array('default' => 25, 'validation' => array('num', false, 10, 100)),
- 'mchat_message_num_custom' => array('default' => 10, 'validation' => array('num', false, 5, 50)),
- 'mchat_message_num_index' => array('default' => 10, 'validation' => array('num', false, 5, 50)),
- 'mchat_navbar_link' => array('default' => 1),
- 'mchat_navbar_link_count' => array('default' => 1),
- 'mchat_override_min_post_chars' => array('default' => 0),
- 'mchat_override_smilie_limit' => array('default' => 0),
- 'mchat_posts_auth_check' => array('default' => 0),
- 'mchat_posts_edit' => array('default' => 0),
- 'mchat_posts_quote' => array('default' => 0),
- 'mchat_posts_reply' => array('default' => 0),
- 'mchat_posts_topic' => array('default' => 0),
- 'mchat_posts_login' => array('default' => 0),
- 'mchat_prune' => array('default' => 0),
- 'mchat_prune_gc' => array('default' => strtotime('1 day', 0)),
- 'mchat_prune_mode' => array('default' => 0),
- 'mchat_prune_num' => array('default' => 0),
- 'mchat_refresh' => array('default' => 10, 'validation' => array('num', false, 5, 60)),
- 'mchat_timeout' => array('default' => 0, 'validation' => array('num', false, 0, (int) $this->cfg('session_length'))),
- 'mchat_whois_refresh' => array('default' => 60, 'validation' => array('num', false, 10, 300)),
- );
+ $global_settings = [
+ 'mchat_archive_sort' => ['default' => self::ARCHIVE_SORT_BOTTOM_TOP],
+ 'mchat_bbcode_disallowed' => ['default' => '', 'validation' => ['string', false, 0, 255]],
+ 'mchat_custom_height' => ['default' => 350, 'validation' => ['num', false, 50, 1000]],
+ 'mchat_custom_page' => ['default' => 1],
+ 'mchat_edit_delete_limit' => ['default' => 0],
+ 'mchat_flood_time' => ['default' => 0, 'validation' => ['num', false, 0, 60]],
+ 'mchat_index_height' => ['default' => 250, 'validation' => ['num', false, 50, 1000]],
+ 'mchat_live_updates' => ['default' => 1],
+ 'mchat_log_enabled' => ['default' => 1],
+ 'mchat_max_input_height' => ['default' => 150, 'validation' => ['num', false, 0, 1000]],
+ 'mchat_max_message_lngth' => ['default' => 500, 'validation' => ['num', false, 0, 1000]],
+ 'mchat_message_num_archive' => ['default' => 25, 'validation' => ['num', false, 10, 100]],
+ 'mchat_message_num_custom' => ['default' => 10, 'validation' => ['num', false, 5, 50]],
+ 'mchat_message_num_index' => ['default' => 10, 'validation' => ['num', false, 5, 50]],
+ 'mchat_navbar_link_count' => ['default' => 1],
+ 'mchat_override_min_post_chars' => ['default' => 0],
+ 'mchat_override_smilie_limit' => ['default' => 0],
+ 'mchat_posts_auth_check' => ['default' => 0],
+ 'mchat_posts_edit' => ['default' => 0],
+ 'mchat_posts_quote' => ['default' => 0],
+ 'mchat_posts_reply' => ['default' => 0],
+ 'mchat_posts_topic' => ['default' => 0],
+ 'mchat_posts_login' => ['default' => 0],
+ 'mchat_prune' => ['default' => 0],
+ 'mchat_prune_gc' => ['default' => strtotime('1 day', 0)],
+ 'mchat_prune_mode' => ['default' => 0],
+ 'mchat_prune_num' => ['default' => 0],
+ 'mchat_refresh' => ['default' => 10, 'validation' => ['num', false, 5, 60]],
+ 'mchat_timeout' => ['default' => 0, 'validation' => ['num', false, 0, (int) $this->cfg('session_length')]],
+ 'mchat_whois_refresh' => ['default' => 60, 'validation' => ['num', false, 10, 300]],
+ ];
/**
* Event to modify global settings data
@@ -165,9 +197,9 @@ class settings
* @var array global_settings Array containing global settings data
* @since 2.0.0-RC7
*/
- $vars = array(
+ $vars = [
'global_settings',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.global_settings_modify', compact($vars)));
return $global_settings;
@@ -178,10 +210,10 @@ class settings
*/
public function initialize_global_text_settings()
{
- $global_text_settings = array(
- 'mchat_rules' => array('default' => ''),
- 'mchat_static_message' => array('default' => ''),
- );
+ $global_text_settings = [
+ 'mchat_rules' => ['default' => ''],
+ 'mchat_static_message' => ['default' => ''],
+ ];
/**
* Event to modify global text settings data
@@ -190,9 +222,9 @@ class settings
* @var array global_text_settings Array containing global text settings data
* @since 2.0.2
*/
- $vars = array(
+ $vars = [
'global_text_settings',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.global_text_settings_modify', compact($vars)));
return $global_text_settings;
@@ -203,22 +235,21 @@ class settings
*/
public function initialize_ucp_settings()
{
- $ucp_settings = array(
- 'mchat_avatars' => array('default' => 1),
- 'mchat_capital_letter' => array('default' => 1),
- 'mchat_character_count' => array('default' => 1),
- 'mchat_date' => array('default' => 'D M d, Y g:i a', 'validation' => array('string', false, 0, 64)),
- 'mchat_index' => array('default' => 1),
- 'mchat_input_area' => array('default' => 1),
- 'mchat_location' => array('default' => 1),
- 'mchat_message_top' => array('default' => 1),
- 'mchat_pause_on_input' => array('default' => 0),
- 'mchat_posts' => array('default' => 1),
- 'mchat_relative_time' => array('default' => 1),
- 'mchat_sound' => array('default' => 1),
- 'mchat_stats_index' => array('default' => 0),
- 'mchat_whois_index' => array('default' => 1),
- );
+ $ucp_settings = [
+ 'mchat_avatars' => ['default' => 1],
+ 'mchat_capital_letter' => ['default' => 1],
+ 'mchat_character_count' => ['default' => 1],
+ 'mchat_date' => ['default' => 'D M d, Y g:i a', 'validation' => ['string', false, 0, 64]],
+ 'mchat_index' => ['default' => 1],
+ 'mchat_input_area' => ['default' => 1],
+ 'mchat_location' => ['default' => 1],
+ 'mchat_message_top' => ['default' => 1],
+ 'mchat_posts' => ['default' => 1],
+ 'mchat_relative_time' => ['default' => 1],
+ 'mchat_sound' => ['default' => 1],
+ 'mchat_stats_index' => ['default' => 0],
+ 'mchat_whois_index' => ['default' => 1],
+ ];
/**
* Event to modify UCP settings data
@@ -227,9 +258,9 @@ class settings
* @var array ucp_settings Array containing UCP settings data
* @since 2.0.0-RC7
*/
- $vars = array(
+ $vars = [
'ucp_settings',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.ucp_settings_modify', compact($vars)));
return $ucp_settings;
@@ -277,9 +308,9 @@ class settings
* @var array global_text_values Array containing global text values
* @since 2.0.2
*/
- $vars = array(
+ $vars = [
'global_text_values',
- );
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.global_text_values_modify', compact($vars)));
$this->global_text_values = $global_text_values;
@@ -372,6 +403,30 @@ class settings
}
}
+ /**
+ * @return string
+ */
+ public function get_table_mchat()
+ {
+ return $this->mchat_table;
+ }
+
+ /**
+ * @return string
+ */
+ public function get_table_mchat_log()
+ {
+ return $this->mchat_log_table;
+ }
+
+ /**
+ * @return string
+ */
+ public function get_table_mchat_sessions()
+ {
+ return $this->mchat_sessions_table;
+ }
+
/**
* @param string $selected
* @return array
@@ -379,31 +434,32 @@ class settings
public function get_date_template_data($selected)
{
$dateformat_options = '';
+ $dateformats = $this->lang->lang_raw('dateformats');
- foreach ($this->user->lang['dateformats'] as $format => $null)
+ foreach (array_keys($dateformats) as $format)
{
$dateformat_options .= '';
}
$s_custom = false;
$dateformat_options .= '';
+ $dateformat_options .= '>' . $this->lang->lang('MCHAT_CUSTOM_DATEFORMAT') . '';
$ucp_settings = $this->ucp_settings();
- return array(
+ return [
'S_MCHAT_DATEFORMAT_OPTIONS' => $dateformat_options,
'MCHAT_DEFAULT_DATEFORMAT' => $ucp_settings['mchat_date']['default'],
'S_MCHAT_CUSTOM_DATEFORMAT' => $s_custom,
- );
+ ];
}
/**
@@ -411,16 +467,51 @@ class settings
*/
public function get_enabled_post_notifications_lang()
{
- $enabled_notifications_lang = array();
+ $enabled_notifications_lang = [];
- foreach (array('topic', 'reply', 'quote', 'edit', 'login') as $notification)
+ foreach (['topic', 'reply', 'quote', 'edit', 'login'] as $notification)
{
if ($this->cfg('mchat_posts_' . $notification))
{
- $enabled_notifications_lang[] = $this->user->lang('MCHAT_POSTS_' . strtoupper($notification));
+ $enabled_notifications_lang[] = $this->lang->lang('MCHAT_POSTS_' . strtoupper($notification));
}
}
- return implode($this->user->lang('COMMA_SEPARATOR'), $enabled_notifications_lang);
+ return implode($this->lang->lang('COMMA_SEPARATOR'), $enabled_notifications_lang);
+ }
+
+ /**
+ * @param string $path
+ * @param bool $absolute_url
+ * @param bool $append_ext
+ * @return string
+ */
+ public function url($path, $absolute_url = false, $append_ext = true)
+ {
+ if ($absolute_url && !$this->board_url)
+ {
+ $this->board_url = generate_board_url() . '/';
+ }
+
+ $url = ($absolute_url ? $this->board_url : $this->root_path) . $path;
+
+ if ($append_ext)
+ {
+ $url .= '.' . $this->php_ext;
+ }
+
+ return $url;
+ }
+
+ /**
+ * @param string $file
+ * @param string $function
+ */
+ public function include_functions($file, $function)
+ {
+ if (!function_exists($function))
+ {
+ include($this->root_path . 'includes/functions_' . $file . '.' . $this->php_ext);
+ }
}
}
diff --git a/cron/mchat_prune.php b/cron/mchat_prune.php
index 11bcc31..c07be7f 100644
--- a/cron/mchat_prune.php
+++ b/cron/mchat_prune.php
@@ -18,35 +18,33 @@ use phpbb\cron\task\base;
class mchat_prune extends base
{
/** @var functions */
- protected $functions;
+ protected $mchat_functions;
/** @var settings */
- protected $settings;
+ protected $mchat_settings;
/**
* Constructor
*
- * @param functions $functions
- * @param settings $settings
+ * @param functions $mchat_functions
+ * @param settings $mchat_settings
*/
public function __construct(
- functions $functions,
- settings $settings
+ functions $mchat_functions,
+ settings $mchat_settings
)
{
- $this->functions = $functions;
- $this->settings = $settings;
+ $this->mchat_functions = $mchat_functions;
+ $this->mchat_settings = $mchat_settings;
}
/**
* Runs this cron task.
- *
- * @return null
*/
public function run()
{
- $this->functions->mchat_prune();
- $this->settings->set_cfg('mchat_prune_last_gc', time());
+ $this->mchat_functions->mchat_prune();
+ $this->mchat_settings->set_cfg('mchat_prune_last_gc', time());
}
/**
@@ -58,7 +56,7 @@ class mchat_prune extends base
*/
public function is_runnable()
{
- return $this->settings->cfg('mchat_prune');
+ return $this->mchat_settings->cfg('mchat_prune');
}
/**
@@ -69,6 +67,6 @@ class mchat_prune extends base
*/
public function should_run()
{
- return $this->settings->cfg('mchat_prune_last_gc') < time() - $this->settings->cfg('mchat_prune_gc');
+ return $this->mchat_settings->cfg('mchat_prune_last_gc') < time() - $this->mchat_settings->cfg('mchat_prune_gc');
}
}
diff --git a/event/acp_listener.php b/event/acp_listener.php
index 416952d..bdcda0f 100644
--- a/event/acp_listener.php
+++ b/event/acp_listener.php
@@ -14,10 +14,10 @@ namespace dmzx\mchat\event;
use dmzx\mchat\core\functions;
use dmzx\mchat\core\settings;
use phpbb\auth\auth;
+use phpbb\event\data;
+use phpbb\language\language;
use phpbb\request\request_interface;
use phpbb\template\template;
-use phpbb\user;
-use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class acp_listener implements EventSubscriberInterface
@@ -28,79 +28,67 @@ class acp_listener implements EventSubscriberInterface
/** @var request_interface */
protected $request;
- /** @var user */
- protected $user;
+ /** @var language */
+ protected $lang;
/** @var settings */
- protected $settings;
+ protected $mchat_settings;
/** @var functions */
- protected $functions;
-
- /** @var string */
- protected $root_path;
-
- /** @var string */
- protected $php_ext;
+ protected $mchat_functions;
/**
* Constructor
*
* @param template $template
* @param request_interface $request
- * @param user $user
- * @param settings $settings
- * @param functions $functions
- * @param string $root_path
- * @param string $php_ext
+ * @param language $lang
+ * @param settings $mchat_settings
+ * @param functions $mchat_functions
*/
public function __construct(
template $template,
request_interface $request,
- user $user,
- settings $settings,
- functions $functions,
- $root_path,
- $php_ext
+ language $lang,
+ settings $mchat_settings,
+ functions $mchat_functions
)
{
- $this->template = $template;
- $this->request = $request;
- $this->user = $user;
- $this->settings = $settings;
- $this->functions = $functions;
- $this->root_path = $root_path;
- $this->php_ext = $php_ext;
+ $this->template = $template;
+ $this->request = $request;
+ $this->lang = $lang;
+ $this->mchat_settings = $mchat_settings;
+ $this->mchat_functions = $mchat_functions;
}
/**
* @return array
*/
- static public function getSubscribedEvents()
+ public static function getSubscribedEvents()
{
- return array(
+ return [
'core.permissions' => 'permissions',
'core.acp_users_prefs_modify_sql' => 'acp_users_prefs_modify_sql',
'core.acp_users_prefs_modify_template_data' => 'acp_users_prefs_modify_template_data',
'core.acp_users_overview_before' => 'acp_users_overview_before',
'core.delete_user_after' => 'delete_user_after',
- );
+ ];
}
/**
- * @param Event $event
+ * @param data $event
*/
- public function permissions($event)
+ public function permissions(data $event)
{
- $ucp_configs = array();
+ $ucp_configs = [];
- foreach (array_keys($this->settings->ucp_settings()) as $config_name)
+ foreach (array_keys($this->mchat_settings->ucp_settings()) as $config_name)
{
$ucp_configs[] = 'u_' . $config_name;
}
- $permission_categories = array(
- 'mchat' => array(
+ $permission_categories = [
+ 'mchat' => [
'u_mchat_use',
'u_mchat_view',
'u_mchat_edit',
@@ -117,38 +105,38 @@ class acp_listener implements EventSubscriberInterface
'u_mchat_smilies',
'u_mchat_urls',
'a_mchat',
- ),
+ ],
'mchat_user_config' => $ucp_configs,
- );
+ ];
- $mchat_permissions = array();
+ $mchat_permissions = [];
foreach ($permission_categories as $cat => $permissions)
{
foreach ($permissions as $permission)
{
- $mchat_permissions[$permission] = array(
+ $mchat_permissions[$permission] = [
'lang' => 'ACL_' . strtoupper($permission),
'cat' => $cat,
- );
+ ];
}
}
$event['permissions'] = array_merge($event['permissions'], $mchat_permissions);
- $event['categories'] = array_merge($event['categories'], array(
+ $event['categories'] = array_merge($event['categories'], [
'mchat' => 'ACP_CAT_MCHAT',
'mchat_user_config' => 'ACP_CAT_MCHAT_USER_CONFIG',
- ));
+ ]);
}
/**
- * @param Event $event
+ * @param data $event
*/
- public function acp_users_prefs_modify_sql($event)
+ public function acp_users_prefs_modify_sql(data $event)
{
- $sql_ary = array();
- $validation = array();
+ $sql_ary = [];
+ $validation = [];
$user_id = $event['user_row']['user_id'];
@@ -156,7 +144,7 @@ class acp_listener implements EventSubscriberInterface
$userdata = $auth->obtain_user_data($user_id);
$auth->acl($userdata);
- foreach ($this->settings->ucp_settings() as $config_name => $config_data)
+ foreach ($this->mchat_settings->ucp_settings() as $config_name => $config_data)
{
if ($auth->acl_get('u_' . $config_name))
{
@@ -171,21 +159,18 @@ class acp_listener implements EventSubscriberInterface
}
}
- if (!function_exists('validate_data'))
- {
- include($this->root_path . 'includes/functions_user.' . $this->php_ext);
- }
+ $this->mchat_settings->include_functions('user', 'validate_data');
$event['error'] = array_merge($event['error'], validate_data($sql_ary, $validation));
$event['sql_ary'] = array_merge($event['sql_ary'], $sql_ary);
}
/**
- * @param Event $event
+ * @param data $event
*/
- public function acp_users_prefs_modify_template_data($event)
+ public function acp_users_prefs_modify_template_data(data $event)
{
- $this->user->add_lang_ext('dmzx/mchat', array('mchat_acp', 'mchat_ucp'));
+ $this->lang->add_lang(['mchat_acp', 'mchat_ucp'], 'dmzx/mchat');
$user_id = (int) $event['user_row']['user_id'];
@@ -193,44 +178,44 @@ class acp_listener implements EventSubscriberInterface
$userdata = $auth->obtain_user_data($user_id);
$auth->acl($userdata);
- $selected = $this->settings->cfg_user('mchat_date', $event['user_row'], $auth);
- $date_template_data = $this->settings->get_date_template_data($selected);
+ $selected = $this->mchat_settings->cfg_user('mchat_date', $event['user_row'], $auth);
+ $date_template_data = $this->mchat_settings->get_date_template_data($selected);
$this->template->assign_vars($date_template_data);
- $notifications_template_data = $this->settings->get_enabled_post_notifications_lang();
+ $notifications_template_data = $this->mchat_settings->get_enabled_post_notifications_lang();
$this->template->assign_var('MCHAT_POSTS_ENABLED_LANG', $notifications_template_data);
- foreach (array_keys($this->settings->ucp_settings()) as $config_name)
+ foreach (array_keys($this->mchat_settings->ucp_settings()) as $config_name)
{
$upper = strtoupper($config_name);
- $this->template->assign_vars(array(
- $upper => $this->settings->cfg_user($config_name, $event['user_row'], $auth),
+ $this->template->assign_vars([
+ $upper => $this->mchat_settings->cfg_user($config_name, $event['user_row'], $auth),
$upper . '_NOAUTH' => !$auth->acl_get('u_' . $config_name, $user_id),
- ));
+ ]);
}
}
/**
- * @param Event $event
+ *
*/
- public function acp_users_overview_before($event)
+ public function acp_users_overview_before()
{
- $this->user->add_lang_ext('dmzx/mchat', 'mchat_acp');
+ $this->lang->add_lang('mchat_acp', 'dmzx/mchat');
- $this->template->assign_vars(array(
- 'L_RETAIN_POSTS' => $this->user->lang('MCHAT_RETAIN_MESSAGES', $this->user->lang('RETAIN_POSTS')),
- 'L_DELETE_POSTS' => $this->user->lang('MCHAT_DELETE_MESSAGES', $this->user->lang('DELETE_POSTS')),
- ));
+ $this->template->assign_vars([
+ 'L_RETAIN_POSTS' => $this->lang->lang('MCHAT_RETAIN_MESSAGES', $this->lang->lang('RETAIN_POSTS')),
+ 'L_DELETE_POSTS' => $this->lang->lang('MCHAT_DELETE_MESSAGES', $this->lang->lang('DELETE_POSTS')),
+ ]);
}
/**
- * @param Event $event
+ * @param data $event
*/
- public function delete_user_after($event)
+ public function delete_user_after(data $event)
{
if ($event['mode'] == 'remove')
{
- $this->functions->mchat_prune($event['user_ids']);
+ $this->mchat_functions->mchat_prune($event['user_ids']);
}
}
}
diff --git a/event/main_listener.php b/event/main_listener.php
index 0cb7a22..1bfb50a 100644
--- a/event/main_listener.php
+++ b/event/main_listener.php
@@ -12,8 +12,10 @@
namespace dmzx\mchat\event;
use dmzx\mchat\core\mchat;
+use dmzx\mchat\core\notifications;
use phpbb\controller\helper;
use phpbb\event\data;
+use phpbb\language\language;
use phpbb\request\request_interface;
use phpbb\user;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -23,12 +25,18 @@ class main_listener implements EventSubscriberInterface
/** @var mchat */
protected $mchat;
+ /** @var notifications */
+ protected $mchat_notifications;
+
/** @var helper */
protected $helper;
/** @var user */
protected $user;
+ /** @var language */
+ protected $lang;
+
/** @var request_interface */
protected $request;
@@ -39,52 +47,59 @@ class main_listener implements EventSubscriberInterface
* Constructor
*
* @param mchat $mchat
+ * @param notifications $mchat_notifications
* @param helper $helper
* @param user $user
+ * @param language $lang
* @param request_interface $request
* @param string $php_ext
*/
public function __construct(
mchat $mchat,
+ notifications $mchat_notifications,
helper $helper,
user $user,
+ language $lang,
request_interface $request,
$php_ext
)
{
- $this->mchat = $mchat;
- $this->helper = $helper;
- $this->user = $user;
- $this->request = $request;
- $this->php_ext = $php_ext;
+ $this->mchat = $mchat;
+ $this->mchat_notifications = $mchat_notifications;
+ $this->helper = $helper;
+ $this->user = $user;
+ $this->lang = $lang;
+ $this->request = $request;
+ $this->php_ext = $php_ext;
}
/**
* @return array
*/
- static public function getSubscribedEvents()
+ public static function getSubscribedEvents()
{
- return array(
+ return [
'core.viewonline_overwrite_location' => 'add_page_viewonline',
'core.user_setup' => 'load_language_on_setup',
'core.page_header' => 'add_page_header_link',
'core.index_modify_page_title' => 'display_mchat_on_index',
'core.submit_post_end' => 'insert_posting',
- 'core.display_custom_bbcodes_modify_sql' => array(array('remove_disallowed_bbcodes'), array('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.user_add_modify_data' => 'user_registration_set_default_values',
'core.login_box_redirect' => 'user_login_success',
'core.session_gc_after' => 'session_gc',
- );
+ ];
}
/**
* @param data $event
*/
- public function add_page_viewonline($event)
+ public function add_page_viewonline(data $event)
{
if (strrpos($event['row']['session_page'], 'app.' . $this->php_ext . '/mchat') === 0)
{
- $event['location'] = $this->user->lang('MCHAT_TITLE');
+ $event['location'] = $this->lang->lang('MCHAT_TITLE');
$event['location_url'] = $this->helper->route('dmzx_mchat_page_custom_controller');
}
}
@@ -92,13 +107,13 @@ class main_listener implements EventSubscriberInterface
/**
* @param data $event
*/
- public function load_language_on_setup($event)
+ public function load_language_on_setup(data $event)
{
$lang_set_ext = $event['lang_set_ext'];
- $lang_set_ext[] = array(
+ $lang_set_ext[] = [
'ext_name' => 'dmzx/mchat',
'lang_set' => 'common',
- );
+ ];
$event['lang_set_ext'] = $lang_set_ext;
}
@@ -121,23 +136,33 @@ class main_listener implements EventSubscriberInterface
/**
* @param data $event
*/
- public function insert_posting($event)
+ public function insert_posting(data $event)
{
- $this->mchat->insert_posting($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 remove_disallowed_bbcodes($event)
+ public function remove_disallowed_bbcodes(data $event)
{
$event['sql_ary'] = $this->mchat->remove_disallowed_bbcodes($event['sql_ary']);
+
+ $this->mchat->set_custom_bbcodes_generated(true);
+ }
+
+ /**
+ *
+ */
+ public function generate_smilies_after()
+ {
+ $this->mchat->set_smilies_generated(true);
}
/**
* @param data $event
*/
- public function user_registration_set_default_values($event)
+ public function user_registration_set_default_values(data $event)
{
$event['sql_ary'] = $this->mchat->set_user_default_values($event['sql_ary']);
}
@@ -145,11 +170,12 @@ class main_listener implements EventSubscriberInterface
/**
* @param data $event
*/
- public function user_login_success($event)
+ public function user_login_success(data $event)
{
if (!$event['admin'])
{
- $this->mchat->insert_posting('login');
+ $is_hidden = $this->request->is_set_post('viewonline') || !$this->user->data['user_allow_viewonline'];
+ $this->mchat_notifications->insert_login($is_hidden);
}
}
diff --git a/ext.php b/ext.php
index b119af6..9b2eb8c 100644
--- a/ext.php
+++ b/ext.php
@@ -11,11 +11,14 @@
namespace dmzx\mchat;
-class ext extends \phpbb\extension\base
+use phpbb\extension\base;
+
+class ext extends base
{
/**
* Requires phpBB 3.1.7-PL1 due to usage of \phpbb\session:update_session_infos()
* Requires phpBB 3.1.8-RC1 due to HTTPS in version check
+ * Requires phpBB 3.2.0 due to EoL of phpBB 3.1
*
* @return bool
* @access public
@@ -37,28 +40,16 @@ class ext extends \phpbb\extension\base
if ($module_ids)
{
- if (phpbb_version_compare(PHPBB_VERSION, '3.2.0-dev', '>='))
- {
- // For phpBB >= 3.2.x
- $lang = $this->container->get('language');
- $lang->add_lang('mchat_acp', 'dmzx/mchat');
- }
- else
- {
- // For phpBB 3.1.x
- $user = $this->container->get('user');
- $user->add_lang_ext('dmzx/mchat', 'mchat_acp');
- $lang = $user;
- }
-
+ $lang = $this->container->get('language');
+ $lang->add_lang('mchat_acp', 'dmzx/mchat');
$php_ext = $this->container->getParameter('core.php_ext');
- $error_msg = $lang->lang('MCHAT_30X_REMNANTS', $table_prefix, implode($lang->lang('COMMA_SEPARATOR'), $module_ids)) . adm_back_link(append_sid('index.' . $php_ext, 'i=acp_extensions&mode=main'));
+ $error_msg = $lang->lang('MCHAT_30X_REMNANTS', $table_prefix, implode($lang->lang('COMMA_SEPARATOR'), $module_ids)) . adm_back_link(append_sid('index.' . $php_ext, ['i' => 'acp_extensions', 'mode' => 'main']));
trigger_error($error_msg, E_USER_WARNING);
}
}
- return phpbb_version_compare(PHPBB_VERSION, '3.1.8-RC1', '>=');
+ return phpbb_version_compare(PHPBB_VERSION, '3.2.0', '>=') && phpbb_version_compare(PHP_VERSION, '5.4.7', '>=');
}
/**
@@ -72,13 +63,13 @@ class ext extends \phpbb\extension\base
{
$db = $this->container->get('dbal.conn');
- $mchat_30x_module_langnames = array(
+ $mchat_30x_module_langnames = [
'ACP_CAT_MCHAT',
'ACP_MCHAT_CONFIG',
'ACP_USER_MCHAT',
'UCP_CAT_MCHAT',
'UCP_MCHAT_CONFIG',
- );
+ ];
$sql = 'SELECT module_id
FROM ' . $table_prefix . 'modules
@@ -87,7 +78,7 @@ class ext extends \phpbb\extension\base
$rows = $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
- $module_ids = array();
+ $module_ids = [];
foreach ($rows as $row)
{
diff --git a/language/en/common.php b/language/en/common.php
index 1367e4d..7056ff1 100644
--- a/language/en/common.php
+++ b/language/en/common.php
@@ -16,7 +16,7 @@ if (!defined('IN_PHPBB'))
if (empty($lang) || !is_array($lang))
{
- $lang = array();
+ $lang = [];
}
// DEVELOPERS PLEASE NOTE
@@ -34,30 +34,40 @@ if (empty($lang) || !is_array($lang))
// Some characters for use
// ’ » “ ” …
-$lang = array_merge($lang, array(
+$lang = array_merge($lang, [
'MCHAT_TITLE' => 'mChat',
- 'MCHAT_TITLE_COUNT' => 'mChat [%1$d]',
+ 'MCHAT_TITLE_COUNT' => [
+ 0 => 'mChat',
+ 1 => 'mChat [%1$d]',
+ ],
+ 'MCHAT_NAVBAR_CUSTOM_PAGE' => 'mChat page',
+ 'MCHAT_NAVBAR_ARCHIVE' => 'Archive',
+ 'MCHAT_NAVBAR_RULES' => 'Rules',
// Who is chatting
'MCHAT_WHO_IS_CHATTING' => 'Who is chatting',
- 'MCHAT_ONLINE_USERS_TOTAL' => array(
+ 'MCHAT_ONLINE_USERS_TOTAL' => [
0 => 'No one is chatting',
1 => '%1$d user is chatting',
2 => '%1$d users are chatting',
- ),
+ ],
'MCHAT_ONLINE_EXPLAIN' => 'based on users active over the past %1$s',
- 'MCHAT_HOURS' => array(
+ 'MCHAT_HOURS' => [
1 => '%1$d hour',
2 => '%1$d hours',
- ),
- 'MCHAT_MINUTES' => array(
+ ],
+ 'MCHAT_MINUTES' => [
1 => '%1$d minute',
2 => '%1$d minutes',
- ),
- 'MCHAT_SECONDS' => array(
+ ],
+ 'MCHAT_SECONDS' => [
1 => '%1$d second',
2 => '%1$d seconds',
- ),
+ ],
+
+ // Custom translations for administrators
+ 'MCHAT_RULES_MESSAGE' => '',
+ 'MCHAT_STATIC_MESSAGE' => '',
// Post notification messages (%1$s is replaced with a link to the new/edited post, %2$s is replaced with a link to the forum)
'MCHAT_NEW_POST' => 'posted a new topic: %1$s in %2$s',
@@ -69,4 +79,4 @@ $lang = array_merge($lang, array(
'MCHAT_NEW_EDIT' => 'edited a post: %1$s in %2$s',
'MCHAT_NEW_EDIT_DELETED' => 'edited a post that was deleted',
'MCHAT_NEW_LOGIN' => 'just logged in',
-));
+]);
diff --git a/language/en/info_acp_mchat.php b/language/en/info_acp_mchat.php
index db0ba43..5012702 100644
--- a/language/en/info_acp_mchat.php
+++ b/language/en/info_acp_mchat.php
@@ -16,7 +16,7 @@ if (!defined('IN_PHPBB'))
if (empty($lang) || !is_array($lang))
{
- $lang = array();
+ $lang = [];
}
// DEVELOPERS PLEASE NOTE
@@ -34,7 +34,7 @@ if (empty($lang) || !is_array($lang))
// Some characters for use
// ’ » “ ” …
-$lang = array_merge($lang, array(
+$lang = array_merge($lang, [
// Module titles
'ACP_CAT_MCHAT' => 'mChat',
'ACP_CAT_MCHAT_USER_CONFIG' => 'mChat in UCP',
@@ -47,4 +47,4 @@ $lang = array_merge($lang, array(
'LOG_MCHAT_TABLE_PURGED' => 'mChat messages purged
» %1$s',
'LOG_DELETED_MCHAT' => 'mChat message deleted
» %1$s',
'LOG_EDITED_MCHAT' => 'mChat message edited
» %1$s',
-));
+]);
diff --git a/language/en/info_ucp_mchat.php b/language/en/info_ucp_mchat.php
index 74477c8..5d2d67a 100644
--- a/language/en/info_ucp_mchat.php
+++ b/language/en/info_ucp_mchat.php
@@ -16,7 +16,7 @@ if (!defined('IN_PHPBB'))
if (empty($lang) || !is_array($lang))
{
- $lang = array();
+ $lang = [];
}
// DEVELOPERS PLEASE NOTE
@@ -34,6 +34,6 @@ if (empty($lang) || !is_array($lang))
// Some characters for use
// ’ » “ ” …
-$lang = array_merge($lang, array(
+$lang = array_merge($lang, [
'UCP_MCHAT_CONFIG' => 'mChat',
-));
+]);
diff --git a/language/en/mchat.php b/language/en/mchat.php
index f5379c3..b306fb9 100644
--- a/language/en/mchat.php
+++ b/language/en/mchat.php
@@ -16,7 +16,7 @@ if (!defined('IN_PHPBB'))
if (empty($lang) || !is_array($lang))
{
- $lang = array();
+ $lang = [];
}
// DEVELOPERS PLEASE NOTE
@@ -34,7 +34,7 @@ if (empty($lang) || !is_array($lang))
// Some characters for use
// ’ » “ ” …
-$lang = array_merge($lang, array(
+$lang = array_merge($lang, [
'MCHAT_ADD' => 'Send',
'MCHAT_ARCHIVE' => 'Archive',
'MCHAT_ARCHIVE_PAGE' => 'mChat Archive',
@@ -53,7 +53,7 @@ $lang = array_merge($lang, array(
'MCHAT_RULES' => 'Rules',
'MCHAT_WHOIS_USER' => 'IP whois for %1$s',
'MCHAT_MESS_LONG' => 'Your message is too long. Please limit it to %1$d characters.',
- 'MCHAT_NO_CUSTOM_PAGE' => 'The mChat custom page is not activated at this time.',
+ 'MCHAT_NO_CUSTOM_PAGE' => 'The mChat page is not activated at this time.',
'MCHAT_NO_RULES' => 'The mChat rules page is not activated at this time.',
'MCHAT_NOACCESS_ARCHIVE' => 'You don’t have permission to view the archive.',
'MCHAT_NOJAVASCRIPT' => 'Please enable JavaScript to use mChat.',
@@ -64,29 +64,25 @@ $lang = array_merge($lang, array(
'MCHAT_PAUSE' => 'Paused',
'MCHAT_PERMISSIONS' => 'Change user’s permissions',
'MCHAT_REFRESHING' => 'Refreshing…',
- 'MCHAT_REFRESH_NO' => 'Update is off',
- 'MCHAT_REFRESH_YES' => 'Updates every %1$d seconds',
'MCHAT_RESPOND' => 'Respond to user',
- 'MCHAT_SESSION_ENDS' => 'Chat session ends in %1$s',
- 'MCHAT_SESSION_OUT' => 'Chat session has expired',
'MCHAT_SMILES' => 'Smilies',
'MCHAT_TOTALMESSAGES' => 'Total messages: %1$d',
'MCHAT_USESOUND' => 'Play sound',
+ 'MCHAT_SOUND_ON' => 'Sound is on',
+ 'MCHAT_SOUND_OFF' => 'Sound is off',
+ 'MCHAT_ENTER' => 'Use Ctrl/Cmd + Enter for the alternative action',
+ 'MCHAT_ENTER_SUBMIT' => 'Enter sends the message',
+ 'MCHAT_ENTER_LINEBREAK' => 'Enter adds a new line',
'MCHAT_COLLAPSE_TITLE' => 'Toggle visibility of mChat',
'MCHAT_WHO_IS_REFRESH_EXPLAIN' => 'Refreshes every %1$d seconds',
- 'MCHAT_MINUTES_AGO' => array(
+ 'MCHAT_MINUTES_AGO' => [
0 => 'just now',
1 => '%1$d minute ago',
2 => '%1$d minutes ago',
- ),
+ ],
// These messages are formatted with JavaScript, hence {} and no %d
'MCHAT_CHARACTER_COUNT' => '{current} characters',
'MCHAT_CHARACTER_COUNT_LIMIT' => '{current} out of {max} characters',
- 'MCHAT_SESSION_ENDS_JS' => 'Chat session ends in {timeleft}',
'MCHAT_MENTION' => ' @{username} ',
-
- // Custom translations for administrators
- 'MCHAT_RULES_MESSAGE' => '',
- 'MCHAT_STATIC_MESSAGE' => '',
-));
+]);
diff --git a/language/en/mchat_acp.php b/language/en/mchat_acp.php
index 46c5794..d997b75 100644
--- a/language/en/mchat_acp.php
+++ b/language/en/mchat_acp.php
@@ -16,7 +16,7 @@ if (!defined('IN_PHPBB'))
if (empty($lang) || !is_array($lang))
{
- $lang = array();
+ $lang = [];
}
// DEVELOPERS PLEASE NOTE
@@ -34,17 +34,18 @@ if (empty($lang) || !is_array($lang))
// Some characters for use
// ’ » “ ” …
-$lang = array_merge($lang, array(
+$lang = array_merge($lang, [
// ACP Configuration sections
'MCHAT_SETTINGS_INDEX' => 'Index page settings',
- 'MCHAT_SETTINGS_CUSTOM' => 'Custom page settings',
+ 'MCHAT_SETTINGS_CUSTOM' => 'mChat page settings',
'MCHAT_SETTINGS_ARCHIVE' => 'Archive page settings',
'MCHAT_SETTINGS_POSTS' => 'New posts settings',
'MCHAT_SETTINGS_MESSAGES' => 'Message settings',
'MCHAT_SETTINGS_PRUNE' => 'Pruning settings (adjustable for founders only)',
+ 'MCHAT_SETTINGS_LOG' => 'Log settings (adjustable for founders only)',
'MCHAT_SETTINGS_STATS' => 'Who is chatting settings',
- 'MCHAT_GLOBALUSERSETTINGS_EXPLAIN' => 'Settings for which a user does not have permission to customise are applied as configured below.
New user accounts will have initial settings as configured below.
Go to the mChat in UCP tab of the user permissions section to adjust customisation permissions.
Go to the Preferences form in the user management section to see the status of each user’s settings.',
+ 'MCHAT_GLOBALUSERSETTINGS_EXPLAIN' => 'Settings for which a user does not have permission to customise are applied as configured below.
New user accounts will have initial settings as configured below.
Go to the mChat in UCP tab of the user permissions section to adjust customisation permissions.
Go to the Preferences form in the user management section to adjust individual user settings.',
'MCHAT_GLOBALUSERSETTINGS_OVERWRITE' => 'Overwrite settings for all users',
'MCHAT_GLOBALUSERSETTINGS_OVERWRITE_EXPLAIN' => 'Applies the settings as defined above to all user accounts.',
'MCHAT_GLOBALUSERSETTINGS_OVERWRITE_CONFIRM' => 'Confirm overwriting mChat settings for all users',
@@ -72,7 +73,7 @@ $lang = array_merge($lang, array(
'MCHAT_TOP_OF_FORUM' => 'Top',
'MCHAT_BOTTOM_OF_FORUM' => 'Bottom',
'MCHAT_REFRESH' => 'Refresh interval',
- 'MCHAT_REFRESH_EXPLAIN' => 'Number of seconds before the chat refreshes.
You are limited from 5 to 60 seconds. Default is 10.',
+ 'MCHAT_REFRESH_EXPLAIN' => 'Number of seconds between refreshing messages.
You are limited from 5 to 60 seconds. Default is 10.',
'MCHAT_LIVE_UPDATES' => 'Live updates of edited and deleted messages',
'MCHAT_LIVE_UPDATES_EXPLAIN' => 'When a user edits or deletes messages, the changes are updated live for all others, without them having to refresh the page. Disable this if you experience performance issues.',
'MCHAT_PRUNE' => 'Enable message pruning',
@@ -83,9 +84,8 @@ $lang = array_merge($lang, array(
'MCHAT_PRUNE_NOW' => 'Prune messages now',
'MCHAT_PRUNE_NOW_CONFIRM' => 'Confirm pruning messages',
'MCHAT_PRUNED' => '%1$d mChat messages have been pruned',
- 'MCHAT_NAVBAR_LINK' => 'Display link to the custom page in the navbar',
- 'MCHAT_NAVBAR_LINK_COUNT' => 'Display number of active chat sessions in navbar link',
- 'MCHAT_MESSAGE_NUM_CUSTOM' => 'Initial number of messages to display on the custom page',
+ 'MCHAT_NAVBAR_LINK_COUNT' => 'Display number of active chat sessions in the navbar link',
+ 'MCHAT_MESSAGE_NUM_CUSTOM' => 'Initial number of messages to display on the mChat page',
'MCHAT_MESSAGE_NUM_CUSTOM_EXPLAIN' => 'You are limited from 5 to 50. Default is 10.',
'MCHAT_MESSAGE_NUM_INDEX' => 'Initial number of messages to display on the index page',
'MCHAT_MESSAGE_NUM_INDEX_EXPLAIN' => 'You are limited from 5 to 50. Default is 10.',
@@ -101,9 +101,11 @@ $lang = array_merge($lang, array(
'MCHAT_EDIT_DELETE_LIMIT_EXPLAIN' => 'Messages older than the specified number of seconds cannot be edited or deleted by the author any more.
Users who have edit/delete permission as well as moderator permission are exempt from this time limit.
Set to 0 to allow unlimited editing and deleting.',
'MCHAT_MAX_MESSAGE_LENGTH' => 'Maximum message length',
'MCHAT_MAX_MESSAGE_LENGTH_EXPLAIN' => 'Maximum number of characters allowed per message posted.
You are limited from 0 to 1000. Default is 500. Set to 0 to disable.',
- 'MCHAT_CUSTOM_PAGE' => 'Enable custom page',
- 'MCHAT_CUSTOM_HEIGHT' => 'Custom page height',
- 'MCHAT_CUSTOM_HEIGHT_EXPLAIN' => 'The height of the chat box in pixels on the custom page.
You are limited from 50 to 1000. Default is 350.',
+ 'MCHAT_MAX_INPUT_HEIGHT' => 'Maximum input field height',
+ 'MCHAT_MAX_INPUT_HEIGHT_EXPLAIN' => 'The input field will not expand beyond this number of pixels.
You are limited from 0 to 1000. Default is 150. Set to 0 to not allow multi-line messages.',
+ 'MCHAT_CUSTOM_PAGE' => 'Enable mChat page',
+ 'MCHAT_CUSTOM_HEIGHT' => 'mChat page height',
+ 'MCHAT_CUSTOM_HEIGHT_EXPLAIN' => 'The height of the chat box in pixels on the mChat page.
You are limited from 50 to 1000. Default is 350.',
'MCHAT_BBCODES_DISALLOWED' => 'Disallowed bbcodes',
'MCHAT_BBCODES_DISALLOWED_EXPLAIN' => 'Here you can input the bbcodes that are not to be used in a message.
Separate bbcodes with a vertical bar, for example:
b|i|u|code|list|list=|flash|quote and/or a %1$scustom bbcode tag name%2$s',
'MCHAT_STATIC_MESSAGE' => 'Static message',
@@ -114,6 +116,8 @@ $lang = array_merge($lang, array(
'MCHAT_OVERRIDE_SMILIE_LIMIT_EXPLAIN' => 'Set to yes to override the forums smilie limit setting for chat messages',
'MCHAT_OVERRIDE_MIN_POST_CHARS' => 'Override minimum characters limit',
'MCHAT_OVERRIDE_MIN_POST_CHARS_EXPLAIN' => 'Set to yes to override the forums minimum characters setting for chat messages',
+ 'MCHAT_LOG_ENABLED' => 'Add entries to the admin log',
+ 'MCHAT_LOG_ENABLED_EXPLAIN' => 'This affects message editing, deleting, pruning and purging.',
'MCHAT_POSTS_AUTH_CHECK' => 'Require user permission',
'MCHAT_POSTS_AUTH_CHECK_EXPLAIN' => 'If set to yes, users who can not use mChat will not generate any post/login notification messages.',
@@ -131,29 +135,27 @@ $lang = array_merge($lang, array(
// Error reporting
'TOO_LONG_MCHAT_BBCODE_DISALLOWED' => 'The disallowed bbcodes value is too long.',
- 'TOO_SMALL_MCHAT_CUSTOM_HEIGHT' => 'The custom height value is too small.',
- 'TOO_LARGE_MCHAT_CUSTOM_HEIGHT' => 'The custom height value is too large.',
+ 'TOO_SMALL_MCHAT_CUSTOM_HEIGHT' => 'The mChat page height value is too small.',
+ 'TOO_LARGE_MCHAT_CUSTOM_HEIGHT' => 'The mChat page height value is too large.',
'TOO_LONG_MCHAT_DATE' => 'The date format you entered is too long.',
'TOO_SHORT_MCHAT_DATE' => 'The date format you entered is too short.',
- 'TOO_SMALL_MCHAT_FLOOD_TIME' => 'The flood time value is too small.',
'TOO_LARGE_MCHAT_FLOOD_TIME' => 'The flood time value is too large.',
'TOO_SMALL_MCHAT_INDEX_HEIGHT' => 'The index height value is too small.',
'TOO_LARGE_MCHAT_INDEX_HEIGHT' => 'The index height value is too large.',
- 'TOO_SMALL_MCHAT_MAX_MESSAGE_LNGTH' => 'The max message length value is too small.',
'TOO_LARGE_MCHAT_MAX_MESSAGE_LNGTH' => 'The max message length value is too large.',
- 'TOO_SMALL_MCHAT_MESSAGE_NUM_CUSTOM' => 'The number of message to display on the custom page is too small.',
- 'TOO_LARGE_MCHAT_MESSAGE_NUM_CUSTOM' => 'The number of message to display on the custom page is too large.',
+ 'TOO_LARGE_MCHAT_MAX_INPUT_HEIGHT' => 'The max input height value is too large.',
+ 'TOO_SMALL_MCHAT_MESSAGE_NUM_CUSTOM' => 'The number of messages to display on the mChat page is too small.',
+ 'TOO_LARGE_MCHAT_MESSAGE_NUM_CUSTOM' => 'The number of messages to display on the mChat page is too large.',
'TOO_SMALL_MCHAT_MESSAGE_NUM_INDEX' => 'The number of messages to display on the index page is too small.',
'TOO_LARGE_MCHAT_MESSAGE_NUM_INDEX' => 'The number of messages to display on the index page is too large.',
- 'TOO_SMALL_MCHAT_MESSAGE_NUM_ARCHIVE' => 'The number of message to display on the archive page is too small.',
- 'TOO_LARGE_MCHAT_MESSAGE_NUM_ARCHIVE' => 'The number of message to display on the archive page is too large.',
+ 'TOO_SMALL_MCHAT_MESSAGE_NUM_ARCHIVE' => 'The number of messages to display on the archive page is too small.',
+ 'TOO_LARGE_MCHAT_MESSAGE_NUM_ARCHIVE' => 'The number of messages to display on the archive page is too large.',
'TOO_SMALL_MCHAT_REFRESH' => 'The refresh value is too small.',
'TOO_LARGE_MCHAT_REFRESH' => 'The refresh value is too large.',
- 'TOO_LONG_MCHAT_STATIC_MESSAGE' => 'The static message value is too long.',
'TOO_SMALL_MCHAT_TIMEOUT' => 'The user timeout value is too small.',
'TOO_LARGE_MCHAT_TIMEOUT' => 'The user timeout value is too large.',
'TOO_SMALL_MCHAT_WHOIS_REFRESH' => 'The whois refresh value is too small.',
'TOO_LARGE_MCHAT_WHOIS_REFRESH' => 'The whois refresh value is too large.',
'MCHAT_30X_REMNANTS' => 'The installation has been aborted.
There are remnant modules from the mChat MOD for phpBB 3.0.x in the database. The mChat extension does not work correctly with these modules present.
You need to entirely uninstall the mChat MOD before being able to install the mChat extension. Specifically, the modules with the following IDs need to be deleted from the %1$smodules table: %2$s',
-));
+]);
diff --git a/language/en/mchat_ucp.php b/language/en/mchat_ucp.php
index 9165668..8a02340 100644
--- a/language/en/mchat_ucp.php
+++ b/language/en/mchat_ucp.php
@@ -16,7 +16,7 @@ if (!defined('IN_PHPBB'))
if (empty($lang) || !is_array($lang))
{
- $lang = array();
+ $lang = [];
}
// DEVELOPERS PLEASE NOTE
@@ -34,7 +34,7 @@ if (empty($lang) || !is_array($lang))
// Some characters for use
// ’ » “ ” …
-$lang = array_merge($lang, array(
+$lang = array_merge($lang, [
'MCHAT_PREFERENCES' => 'mChat preferences',
'MCHAT_NO_SETTINGS' => 'You are not authorised to customise any settings.',
@@ -52,8 +52,6 @@ $lang = array_merge($lang, array(
'MCHAT_DISPLAY_CHARACTER_COUNT' => 'Display number of characters when typing a message',
'MCHAT_RELATIVE_TIME' => 'Display relative time for new messages',
'MCHAT_RELATIVE_TIME_EXPLAIN' => 'Displays “just now”, “1 minute ago” and so on for each message. Set to No to always display the full date.',
- 'MCHAT_PAUSE_ON_INPUT' => 'Pause on input',
- 'MCHAT_PAUSE_ON_INPUT_EXPLAIN' => 'Do not update mChat upon entering a message',
'MCHAT_MESSAGE_TOP' => 'Location of new chat messages',
'MCHAT_MESSAGE_TOP_EXPLAIN' => 'New messages will appear at the top or at the bottom in the chat.',
'MCHAT_LOCATION' => 'Location on the index page',
@@ -69,4 +67,4 @@ $lang = array_merge($lang, array(
'MCHAT_DATE_FORMAT' => 'Date format',
'MCHAT_DATE_FORMAT_EXPLAIN' => 'The syntax used is identical to the PHP date() function.',
'MCHAT_CUSTOM_DATEFORMAT' => 'Custom…',
-));
+]);
diff --git a/language/en/permissions_mchat.php b/language/en/permissions_mchat.php
index 1834312..f89e828 100644
--- a/language/en/permissions_mchat.php
+++ b/language/en/permissions_mchat.php
@@ -16,7 +16,7 @@ if (!defined('IN_PHPBB'))
if (empty($lang) || !is_array($lang))
{
- $lang = array();
+ $lang = [];
}
// DEVELOPERS PLEASE NOTE
@@ -34,7 +34,7 @@ if (empty($lang) || !is_array($lang))
// Some characters for use
// ’ » “ ” …
-$lang = array_merge($lang, array(
+$lang = array_merge($lang, [
'ACL_U_MCHAT_USE' => 'Can use mChat',
'ACL_U_MCHAT_VIEW' => 'Can view mChat',
'ACL_U_MCHAT_EDIT' => 'Can edit own messages',
@@ -43,8 +43,8 @@ $lang = array_merge($lang, array(
'ACL_U_MCHAT_MODERATOR_DELETE' => 'Can delete anyone’s messages',
'ACL_U_MCHAT_IP' => 'Can view IP addresses',
'ACL_U_MCHAT_PM' => 'Can use private message',
- 'ACL_U_MCHAT_LIKE' => 'Can like messages',
- 'ACL_U_MCHAT_QUOTE' => 'Can quote messages',
+ 'ACL_U_MCHAT_LIKE' => 'Can see like icon (requires BBCode permission)',
+ 'ACL_U_MCHAT_QUOTE' => 'Can see quote icon (requires BBCode permission)',
'ACL_U_MCHAT_FLOOD_IGNORE' => 'Can ignore flood limit',
'ACL_U_MCHAT_ARCHIVE' => 'Can view the archive',
'ACL_U_MCHAT_BBCODE' => 'Can use BBCodes',
@@ -59,7 +59,6 @@ $lang = array_merge($lang, array(
'ACL_U_MCHAT_INPUT_AREA' => 'Can customise Input type',
'ACL_U_MCHAT_LOCATION' => 'Can customise Location of mChat on the index page',
'ACL_U_MCHAT_MESSAGE_TOP' => 'Can customise Location of new chat messages',
- 'ACL_U_MCHAT_PAUSE_ON_INPUT' => 'Can customise Pause on input',
'ACL_U_MCHAT_POSTS' => 'Can customise Display new posts',
'ACL_U_MCHAT_RELATIVE_TIME' => 'Can customise Display relative time',
'ACL_U_MCHAT_SOUND' => 'Can customise Play sounds',
@@ -67,4 +66,4 @@ $lang = array_merge($lang, array(
'ACL_U_MCHAT_STATS_INDEX' => 'Can customise Display who is chatting in the stats section',
'ACL_A_MCHAT' => 'Can manage mChat settings',
-));
+]);
diff --git a/migrations/mchat_2_0_3.php b/migrations/mchat_2_0_3.php
new file mode 100644
index 0000000..b6b2aba
--- /dev/null
+++ b/migrations/mchat_2_0_3.php
@@ -0,0 +1,30 @@
+ [
+ $this->table_prefix . 'users' => [
+ 'user_mchat_pause_on_input',
+ ],
+ ],
+ ];
+ }
+
+ public function revert_schema()
+ {
+ return [
+ 'add_columns' => [
+ $this->table_prefix . 'users' => [
+ 'user_mchat_pause_on_input' => ['BOOL', 0],
+ ],
+ ],
+ ];
+ }
+}
diff --git a/styles/360Elite/template/event/dmzx_mchat_messages_define_icons.html b/styles/360Elite/template/event/dmzx_mchat_messages_define_icons.html
deleted file mode 100644
index f633ea4..0000000
--- a/styles/360Elite/template/event/dmzx_mchat_messages_define_icons.html
+++ /dev/null
@@ -1 +0,0 @@
-{% DEFINE MCHAT_USE_WHITE_MESSAGE_ICONS = TRUE %}
diff --git a/styles/Absolution/template/event/overall_footer_after.html b/styles/Absolution/template/event/overall_footer_after.html
new file mode 100644
index 0000000..4c2eaa1
--- /dev/null
+++ b/styles/Absolution/template/event/overall_footer_after.html
@@ -0,0 +1 @@
+{% INCLUDECSS '@dmzx_mchat/mchat_absolution.css' %}
diff --git a/styles/Absolution/theme/mchat_absolution.css b/styles/Absolution/theme/mchat_absolution.css
new file mode 100644
index 0000000..d360950
--- /dev/null
+++ b/styles/Absolution/theme/mchat_absolution.css
@@ -0,0 +1,18 @@
+/**
+ *
+ * mChat CSS for Absolution
+ *
+ * @package phpBB Extension - mChat
+ * @copyright (c) 2018 kasimi - https://kasimi.net
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ *
+ */
+
+.mchat-nav-link-title {
+ color: #082c51;
+ font-weight: bold;
+}
+
+.mchat-nav-link-title i {
+ color: #EE8B0A;
+}
diff --git a/styles/AllanStyle-SUBSILVER/template/event/overall_footer_page_body_after.html b/styles/AllanStyle-SUBSILVER/template/event/overall_footer_page_body_after.html
new file mode 100644
index 0000000..546caf1
--- /dev/null
+++ b/styles/AllanStyle-SUBSILVER/template/event/overall_footer_page_body_after.html
@@ -0,0 +1,5 @@
+{% INCLUDECSS '@dmzx_mchat/mchat_allanstyle.css' %}
+
\ No newline at end of file
diff --git a/styles/AllanStyle-SUBSILVER/theme/mchat_allanstyle.css b/styles/AllanStyle-SUBSILVER/theme/mchat_allanstyle.css
new file mode 100644
index 0000000..6a2e62b
--- /dev/null
+++ b/styles/AllanStyle-SUBSILVER/theme/mchat_allanstyle.css
@@ -0,0 +1,17 @@
+/**
+ *
+ * mChat CSS for AllanStyle SUBSILVER
+ *
+ * @package phpBB Extension - mChat
+ * @copyright (c) 2018 kasimi - https://kasimi.net
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ *
+ */
+
+@media only screen and (min-width: 700px), only screen and (min-device-width: 700px) {
+
+ .mchat-wrapper .list-inner {
+ margin-left: 5px;
+ }
+
+}
diff --git a/styles/Black_Star/template/event/dmzx_mchat_messages_define_icons.html b/styles/Black_Star/template/event/dmzx_mchat_messages_define_icons.html
deleted file mode 100644
index f633ea4..0000000
--- a/styles/Black_Star/template/event/dmzx_mchat_messages_define_icons.html
+++ /dev/null
@@ -1 +0,0 @@
-{% DEFINE MCHAT_USE_WHITE_MESSAGE_ICONS = TRUE %}
diff --git a/styles/Blue-Night/template/event/dmzx_mchat_messages_define_icons.html b/styles/Blue-Night/template/event/dmzx_mchat_messages_define_icons.html
deleted file mode 100644
index f633ea4..0000000
--- a/styles/Blue-Night/template/event/dmzx_mchat_messages_define_icons.html
+++ /dev/null
@@ -1 +0,0 @@
-{% DEFINE MCHAT_USE_WHITE_MESSAGE_ICONS = TRUE %}
diff --git a/styles/Brown/template/event/dmzx_mchat_messages_define_icons.html b/styles/Brown/template/event/dmzx_mchat_messages_define_icons.html
deleted file mode 100644
index f633ea4..0000000
--- a/styles/Brown/template/event/dmzx_mchat_messages_define_icons.html
+++ /dev/null
@@ -1 +0,0 @@
-{% DEFINE MCHAT_USE_WHITE_MESSAGE_ICONS = TRUE %}
diff --git a/styles/Cynthia/template/event/dmzx_mchat_messages_define_icons.html b/styles/Cynthia/template/event/dmzx_mchat_messages_define_icons.html
deleted file mode 100644
index f633ea4..0000000
--- a/styles/Cynthia/template/event/dmzx_mchat_messages_define_icons.html
+++ /dev/null
@@ -1 +0,0 @@
-{% DEFINE MCHAT_USE_WHITE_MESSAGE_ICONS = TRUE %}
diff --git a/styles/DVGFX/template/event/dmzx_mchat_messages_define_icons.html b/styles/DVGFX/template/event/dmzx_mchat_messages_define_icons.html
deleted file mode 100644
index f633ea4..0000000
--- a/styles/DVGFX/template/event/dmzx_mchat_messages_define_icons.html
+++ /dev/null
@@ -1 +0,0 @@
-{% DEFINE MCHAT_USE_WHITE_MESSAGE_ICONS = TRUE %}
diff --git a/styles/Hexagon/template/event/overall_header_head_append.html b/styles/Hexagon/template/event/overall_header_head_append.html
deleted file mode 100644
index c9c10a0..0000000
--- a/styles/Hexagon/template/event/overall_header_head_append.html
+++ /dev/null
@@ -1,2 +0,0 @@
-{% INCLUDECSS '@dmzx_mchat/mchat.css' %}
-{% INCLUDECSS '@dmzx_mchat/mchat_custom.css' %}
diff --git a/styles/Hexagon/theme/images/icon_mchat.png b/styles/Hexagon/theme/images/icon_mchat.png
deleted file mode 100644
index c7cce975e8b4b67e2fa8b74d0b2553710cf84cf4..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001
literal 528
zcmV+r0`L8aP)
')
- .replace(/\n/g, '
')
- .replace(/ {2,}/g, function(space) { return times(' ', space.length -1) + ' '; });
- else
- val = escapeHtml( val );
-
- //if( options.horizontal )
- // val = $.trim( val );
-
- // if( $(this).prop( 'tagName' ).toUpperCase() === 'INPUT' )
- // shadow.text(val).css( "width", "auto" );
- // else
- shadow.html( val ).css( "width", "auto" ); // need to use html here otherwise no way to count spaces (with html we can use )
-
- if( options.horizontal )
- {
- var slopWidth = options.characterSlop * characterWidth + 2;
-
- var newWidth = Math.max( shadow.width() + slopWidth, minWidth );
- var maxWidth = options.maxWidth;
- //if( typeof( maxWidth ) === "undefined" ) maxWidth = $this.parent().width() - 12; // not sure why we were doing this but seems like a bad idea. doesn't work with inline-block parents for one thing, since it is the text area that should be "pushing" them to be wider
- if( maxWidth ) newWidth = Math.min( newWidth, maxWidth );
- // Take scrollbar into account
- if (isTextarea && shadow.get(0).scrollHeight > shadow.height()) {
- newWidth += 20;
- }
- $(this).css( "width", newWidth );
- }
-
- if( options.vertical )
- {
- var shadowWidth = $(this).width();
- if( ! borderBox ) shadowWidth = shadowWidth - parseInt($this.css('paddingLeft'),10) - parseInt($this.css('paddingRight'),10);
- shadow.css( "width", shadowWidth );
- var shadowHeight = borderBox ? shadow.outerHeight() : shadow.height();
-
- $(this).css( "height", "auto" );
- minHeight = borderBox ? $this.outerHeight() : $this.height();
-
- var newHeight = Math.min( Math.max( shadowHeight, minHeight ), maxHeight );
- $(this).css( "height", newHeight );
- $(this).css( "overflow", newHeight == maxHeight ? "auto" : "hidden" );
- }
- };
-
- $(this)
- .change(function(){update.call( this );return true;})
- .keyup(function(){update.call( this );return true;})
- .keypress(function( event ) {
- if( event.ctrlKey || event.metaKey ) return;
-
- var val = this.value;
- var caretInfo = _getCaretInfo( this );
-
- var typedChar = event.which === 13 ? "\n" : String.fromCharCode( event.which );
- var valAfterKeypress = val.slice( 0, caretInfo.start ) + typedChar + val.slice( caretInfo.end );
- update.call( this, valAfterKeypress );
- return true;
- })
- .bind( "update.autogrow", function(){ update.apply(this); } )
- .bind( "remove.autogrow", function() {
- shadow.remove();
- } );
-
- update.apply(this);
-
- });
-
- return this;
- };
-
- // comes from https://github.com/madapaja/jquery.selection/blob/master/src/jquery.selection.js
- var _getCaretInfo = function(element){
- var res = {
- text: '',
- start: 0,
- end: 0
- };
-
- if (!element.value) {
- /* no value or empty string */
- return res;
- }
-
- try {
- if (window.getSelection) {
- /* except IE */
- res.start = element.selectionStart;
- res.end = element.selectionEnd;
- res.text = element.value.slice(res.start, res.end);
- } else if (doc.selection) {
- /* for IE */
- element.focus();
-
- var range = doc.selection.createRange(),
- range2 = doc.body.createTextRange();
-
- res.text = range.text;
-
- try {
- range2.moveToElementText(element);
- range2.setEndPoint('StartToStart', range);
- } catch (e) {
- range2 = element.createTextRange();
- range2.setEndPoint('StartToStart', range);
- }
-
- res.start = element.value.length - range2.text.length;
- res.end = res.start + range.text.length;
- }
- } catch (e) {
- /* give up */
- }
-
- return res;
- };
-
- var entityMap = {
- "&": "&",
- "<": "<",
- ">": ">",
- '"': '"',
- "'": ''',
- "/": '/',
- " ": ' '
- };
-
- function escapeHtml(string) {
- return String(string).replace(/[&<>"'\/\ ]/g, function (s) {
- return entityMap[s];
- } );
- }
-} ) );
diff --git a/styles/elegance/template/javascript/mchat.collapse.js b/styles/all/template/javascript/mchat.collapse.arty.js
similarity index 74%
rename from styles/elegance/template/javascript/mchat.collapse.js
rename to styles/all/template/javascript/mchat.collapse.arty.js
index 640bd05..23fe885 100644
--- a/styles/elegance/template/javascript/mchat.collapse.js
+++ b/styles/all/template/javascript/mchat.collapse.arty.js
@@ -1,4 +1,6 @@
/**
+ *
+ * mchat.collapse.js - Collapse mChat container for styles by Arty
*
* @package phpBB Extension - mChat
* @copyright (c) 2017 kasimi - https://kasimi.net
@@ -10,10 +12,10 @@ jQuery(function($) {
"use strict";
- // Most code below copied from elegance/template/forum_fn.js for phpBB 3.2.1
+ // Most code below copied from elegance/template/forum_fn.js for phpBB 3.2.2
- var $this = $('.mchat-wrapper li.header'),
- forum = $this.parent().next('#mchat-body'),
+ var $this = $('.mchat-wrapper li.header').first(),
+ forum = $this.closest('.topiclist').next(),
id = 'mchat',
toggled = false,
toggle;
@@ -25,22 +27,24 @@ jQuery(function($) {
event.preventDefault();
$(mChat).trigger('mchat_collapse_toggle_before', [{collapsed: !toggle}]);
if (toggled) {
- forum.stop(true, true).slideDown(200);
+ forum.stop(true, true).slideDown(200, function() {
+ $(mChat).trigger('mchat_collapse_toggle_after', [{collapsed: toggle}]);
+ });
toggled = false;
toggle.removeClass('toggled');
phpbb.deleteCookie('toggled-' + id, styleConfig.cookieConfig);
- $(mChat).trigger('mchat_collapse_toggle_after', [{collapsed: toggle}]);
return;
}
- forum.stop(true, true).slideUp(200);
+ forum.stop(true, true).slideUp(200, function() {
+ $(mChat).trigger('mchat_collapse_toggle_after', [{collapsed: toggle}]);
+ });
toggled = true;
toggle.addClass('toggled');
phpbb.setCookie('toggled-' + id, '1', styleConfig.cookieConfig);
- $(mChat).trigger('mchat_collapse_toggle_after', [{collapsed: toggle}]);
});
// Check default state
- if (phpbb.getCookie('toggled-' + id, styleConfig.cookieConfig) == '1') {
+ if (phpbb.getCookie('toggled-' + id, styleConfig.cookieConfig) === '1') {
forum.stop(true, true).slideUp(0);
toggled = true;
toggle.addClass('toggled');
diff --git a/styles/all/template/javascript/mchat.js b/styles/all/template/javascript/mchat.js
index ed075b2..76bdceb 100644
--- a/styles/all/template/javascript/mchat.js
+++ b/styles/all/template/javascript/mchat.js
@@ -112,7 +112,7 @@ jQuery(function($) {
$(mChat).trigger('mchat_send_request_before', [mode, data]);
$.ajax({
url: mChat.actionUrls[mode],
- timeout: Math.min(mChat.refreshTime, 10000),
+ timeout: Math.min(mChat.refreshTime, 10000) - 100,
type: 'POST',
dataType: 'json',
data: data,
@@ -133,7 +133,7 @@ jQuery(function($) {
};
$(mChat).trigger('mchat_ajax_done_before', [data]);
if (data.handle) {
- if (json[this.mode]) {
+ if (json[data.mode]) {
this.deferred.resolve(data.json, data.status, data.xhr);
} else {
this.deferred.reject(data.xhr, data.status, mChat.lang.parserErr);
@@ -144,6 +144,7 @@ jQuery(function($) {
if (mChat.pageIsUnloading) {
return;
}
+ mChat.skipNextRefresh = true;
if (typeof console !== 'undefined' && console.log) {
console.log('AJAX error. status: ' + textStatus + ', message: ' + errorThrown + ' (' + xhr.responseText + ')');
}
@@ -162,24 +163,52 @@ jQuery(function($) {
};
$(mChat).trigger('mchat_ajax_fail_before', [data]);
mChat.sound('error');
- mChat.cached('status-load', 'status-ok', 'status-paused').hide();
- mChat.cached('status-error').show();
+ mChat.status('error');
+ var title = mChat.lang.err;
var responseText;
try {
- responseText = data.xhr.responseJSON.message || data.errorThrown;
+ var json = data.xhr.responseJSON;
+ if (json.S_USER_WARNING || json.S_USER_NOTICE) {
+ title = json.MESSAGE_TITLE;
+ responseText = json.MESSAGE_TEXT;
+ data.xhr.status = 403;
+ } else {
+ responseText = json.message || data.errorThrown;
+ }
} catch (e) {
responseText = data.errorThrown;
}
if (responseText && responseText !== 'timeout') {
- phpbb.alert(mChat.lang.err, responseText);
+ phpbb.alert(title, responseText);
}
data.updateSession();
},
+ registerNavItem: function(id, canEnable, onToggle) {
+ var isEnabled = canEnable && !mChat.storage.get('no_' + id);
+ var classEnabled = 'mchat-nav-item-enabled';
+ var classDisabled = 'mchat-nav-item-disabled';
+ mChat.cached(id).toggleClass(classEnabled, isEnabled).toggleClass(classDisabled, !isEnabled);
+ if (typeof onToggle === 'function') {
+ onToggle(isEnabled);
+ }
+ mChat['toggle_' + id] = function(e) {
+ e.preventDefault();
+ var hasClass = mChat.cached(id).toggleClass(classEnabled + ' ' + classDisabled).hasClass(classEnabled);
+ if (hasClass) {
+ mChat.storage.remove('no_' + id);
+ } else {
+ mChat.storage.set('no_' + id, 'yes');
+ }
+ if (typeof onToggle === 'function') {
+ onToggle(hasClass);
+ }
+ };
+ },
sound: function(file) {
var data = {
audio: mChat.cached('sound-' + file).get(0),
file: file,
- play: !mChat.pageIsUnloading && mChat.cached('user-sound').is(':checked')
+ play: !mChat.pageIsUnloading && mChat.cached('sound').hasClass('mchat-nav-item-enabled')
};
$(mChat).trigger('mchat_sound_before', [data]);
if (data.play && data.audio && data.audio.duration) {
@@ -198,7 +227,8 @@ jQuery(function($) {
$.titleAlert(mChat.lang.newMessageAlert, data);
}
},
- toggle: function(name) {
+ toggle: function() {
+ var name = $(this).data('mchat-element');
var $elem = mChat.cached(name);
$elem.stop().slideToggle(200, function() {
if ($elem.is(':visible')) {
@@ -229,36 +259,35 @@ jQuery(function($) {
});
},
add: function() {
- if (mChat.cached('add').prop('disabled')) {
+ var $add = mChat.cached('add');
+ if ($add.prop('disabled')) {
return;
}
- var messageLength = mChat.cached('input').val().length;
+ var $input = mChat.cached('input');
+ var originalInputValue = mChat.cleanMessage($input.val()).trim();
+ var messageLength = originalInputValue.length;
if (!messageLength) {
- phpbb.alert(mChat.lang.err, mChat.lang.noMessageInput);
return;
}
if (mChat.mssgLngth && messageLength > mChat.mssgLngth) {
phpbb.alert(mChat.lang.err, mChat.lang.mssgLngthLong);
return;
}
- mChat.cached('add').prop('disabled', true);
+ $add.prop('disabled', true);
mChat.pauseSession();
- var originalInputValue = mChat.cached('input').val();
var inputValue = originalInputValue;
var color = mChat.storage.get('color');
if (color && inputValue.indexOf('[color=') === -1) {
inputValue = '[color=#' + color + '] ' + inputValue + ' [/color]';
}
- mChat.cached('input').val('').trigger('update.autogrow').focus();
+ mChat.setText('');
mChat.refresh(inputValue).done(function() {
mChat.resetSession();
}).fail(function() {
- mChat.cached('input').val(originalInputValue).trigger('update.autogrow');
+ mChat.setText(originalInputValue);
}).always(function() {
- mChat.cached('add').prop('disabled', false);
- setTimeout(function() {
- mChat.cached('input').focus();
- }, 1);
+ $add.prop('disabled', false);
+ $input.delay(1).focus();
});
},
edit: function() {
@@ -276,13 +305,14 @@ jQuery(function($) {
message_id: $message.data('mchat-id'),
message: $textarea.val(),
page: mChat.page
- }).done(function(json) {
- mChat.updateMessages($(json.edit));
- mChat.resetSession();
- });
+ }).done(mChat.editDone);
}
});
},
+ editDone: function(json) {
+ mChat.updateMessages($(json.edit));
+ mChat.resetSession();
+ },
del: function() {
var delId = $(this).closest('.mchat-message').data('mchat-id');
mChat.confirm({
@@ -295,60 +325,68 @@ jQuery(function($) {
confirm: function() {
mChat.ajaxRequest('del', true, {
message_id: delId
- }).done(function() {
- mChat.removeMessages([delId]);
- mChat.resetSession();
- });
+ }).done(mChat.delDone);
}
});
},
+ delDone: function(json) {
+ mChat.removeMessages([json.del]);
+ mChat.resetSession();
+ },
refresh: function(message) {
- if (mChat.isPaused && !message) {
- return false;
+ var isAdd = typeof message !== 'undefined';
+ if (!isAdd) {
+ mChat.sessionLength += mChat.refreshTime;
+ if (mChat.timeout && mChat.sessionLength >= mChat.timeout) {
+ mChat.endSession();
+ return;
+ } else if (mChat.skipNextRefresh) {
+ mChat.skipNextRefresh = false;
+ return;
+ }
}
var data = {
- last: mChat.messageIds.length ? mChat.messageIds.max() : 0
+ last: mChat.messageIds.length ? mChat.messageIds.max() : 0,
+ log: mChat.liveUpdates ? mChat.logId : undefined,
+ message: isAdd ? message : undefined
};
- if (message) {
- data.message = message;
+ mChat.status('load');
+ return mChat.ajaxRequest(isAdd ? 'add' : 'refresh', isAdd, data).done(mChat.refreshDone);
+ },
+ refreshDone: function(json) {
+ $(mChat).trigger('mchat_response_handle_data_before', [json]);
+ if (json.add) {
+ mChat.addMessages($(json.add));
}
- if (mChat.liveUpdates) {
- data.log = mChat.logId;
+ if (json.edit) {
+ mChat.updateMessages($(json.edit));
}
- mChat.cached('status-ok', 'status-error', 'status-paused').hide();
- mChat.cached('status-load').show();
- return mChat.ajaxRequest(message ? 'add' : 'refresh', !!message, data).done(function(json) {
- $(mChat).trigger('mchat_response_handle_data_before', [json]);
- if (json.add) {
- mChat.addMessages($(json.add));
- }
- if (json.edit) {
- mChat.updateMessages($(json.edit));
- }
- if (json.del) {
- mChat.removeMessages(json.del);
- }
- if (json.whois) {
- mChat.handleWhoisResponse(json);
- }
- if (json.log) {
- mChat.logId = json.log;
- }
- if (mChat.refreshInterval) {
- mChat.cached('status-load', 'status-error', 'status-paused').hide();
- mChat.cached('status-ok').show();
- }
- $(mChat).trigger('mchat_response_handle_data_after', [json]);
- });
+ if (json.del) {
+ mChat.removeMessages(json.del);
+ }
+ if (json.whois) {
+ mChat.whoisDone(json);
+ }
+ if (json.log) {
+ mChat.logId = json.log;
+ }
+ if (mChat.refreshInterval) {
+ mChat.status('ok');
+ }
+ $(mChat).trigger('mchat_response_handle_data_after', [json]);
+ },
+ rules: function() {
+ $('.mchat-nav-link-title').each(phpbb.toggleDropdown);
+ popup(this.href, 450, 275);
},
whois: function() {
if (mChat.page === 'custom') {
mChat.cached('refresh-pending').show();
mChat.cached('refresh-explain').hide();
}
- mChat.ajaxRequest('whois', false, {}).done(mChat.handleWhoisResponse);
+ mChat.ajaxRequest('whois', false, {}).done(mChat.whoisDone);
},
- handleWhoisResponse: function(json) {
+ whoisDone: function(json) {
var $whois = $(json.container);
var $userlist = $whois.find('#mchat-userlist');
if (mChat.storage.get('show_userlist')) {
@@ -413,12 +451,13 @@ jQuery(function($) {
if (mChat.messageTop) {
container.animate({scrollTop: 0}, animateOptions);
} else {
- (animateOptions.complete = function() {
+ animateOptions.complete = function() {
var scrollHeight = container.get(0).scrollHeight;
if (container.scrollTop() + container.height() < scrollHeight) {
container.animate({scrollTop: scrollHeight}, animateOptions);
}
- })();
+ };
+ animateOptions.complete();
}
} else {
this.message.show();
@@ -515,81 +554,69 @@ jQuery(function($) {
var selector = '.mchat-time[data-mchat-relative-update]';
clearInterval($message.find(selector).addBack(selector).data('mchat-relative-interval'));
},
- timeLeftRegex: /\d\d:(\d\d:\d\d)/,
- timeLeft: function(sessionTime) {
- return (new Date(sessionTime * 1000)).toUTCString().match(mChat.timeLeftRegex)[mChat.timeout >= 3600000 ? 0 : 1];
- },
- countDown: function() {
- mChat.sessionTime -= 1;
- mChat.cached('session').html(mChat.lang.sessEnds.format({timeleft: mChat.timeLeft(mChat.sessionTime)}));
- if (mChat.sessionTime < 1) {
- mChat.endSession();
+ status: function(status) {
+ var data = {
+ status: status,
+ container: mChat.cached('status')
+ };
+ $(mChat).trigger('mchat_status_before', [data]);
+ var $activeStatus = data.container.find('.mchat-status-' + data.status).removeClass('hidden');
+ if ($activeStatus.length) {
+ data.container.find('.mchat-status').not($activeStatus).addClass('hidden');
}
},
pauseSession: function() {
clearInterval(mChat.refreshInterval);
- if (mChat.timeout) {
- clearInterval(mChat.sessionCountdown);
- }
+ mChat.refreshInterval = false;
if (mChat.whoisRefresh) {
clearInterval(mChat.whoisInterval);
+ mChat.whoisInterval = false;
}
},
resetSession: function() {
- if (mChat.page !== 'archive') {
- clearInterval(mChat.refreshInterval);
- mChat.refreshInterval = setInterval(mChat.refresh, mChat.refreshTime);
- if (mChat.timeout) {
- mChat.sessionTime = mChat.timeout / 1000;
- clearInterval(mChat.sessionCountdown);
- mChat.cached('session').html(mChat.lang.sessEnds.format({timeleft: mChat.timeLeft(mChat.sessionTime)}));
- mChat.sessionCountdown = setInterval(mChat.countDown, 1000);
- }
- if (mChat.whoisRefresh) {
- clearInterval(mChat.whoisInterval);
- mChat.whoisInterval = setInterval(mChat.whois, mChat.whoisRefresh);
- }
- mChat.cached('status-ok').show();
- mChat.cached('status-load', 'status-error', 'status-paused').hide();
- mChat.cached('refresh-text').html(mChat.lang.refreshYes);
+ if (mChat.page === 'archive') {
+ return;
}
+ mChat.pauseSession();
+ mChat.sessionLength = 0;
+ mChat.refreshInterval = setInterval(mChat.refresh, mChat.refreshTime);
+ if (mChat.whoisRefresh) {
+ mChat.whoisInterval = setInterval(mChat.whois, mChat.whoisRefresh);
+ }
+ mChat.status('ok');
},
endSession: function(skipUpdateWhois) {
- clearInterval(mChat.refreshInterval);
- mChat.refreshInterval = false;
- if (mChat.timeout) {
- clearInterval(mChat.sessionCountdown);
- mChat.cached('session').html(mChat.lang.sessOut);
+ mChat.pauseSession();
+ if (mChat.whoisRefresh && !skipUpdateWhois) {
+ mChat.whois();
}
- if (mChat.whoisRefresh) {
- clearInterval(mChat.whoisInterval);
- if (!skipUpdateWhois) {
- mChat.whois();
- }
- }
- mChat.cached('status-load', 'status-ok', 'status-error').hide();
- mChat.cached('status-paused').show();
- mChat.cached('refresh-text').html(mChat.lang.refreshNo);
- },
- pauseStart: function() {
- mChat.isPaused = true;
- mChat.cached('refresh-text').html(mChat.lang.refreshNo);
- mChat.cached('status-load', 'status-ok', 'status-error').hide();
- mChat.cached('status-paused').show();
- },
- pauseEnd: function() {
- mChat.cached('refresh-text').html(mChat.lang.refreshYes);
- mChat.cached('status-load', 'status-error', 'status-paused').hide();
- mChat.cached('status-ok').show();
- mChat.isPaused = false;
+ mChat.status('paused');
},
updateCharCount: function() {
- var count = mChat.cached('input').val().length;
- var charCount = mChat.lang.charCount.format({current: count, max: mChat.mssgLngth});
- var $elem = mChat.cached('character-count').html(charCount).toggleClass('invisible', count === 0);
- if (mChat.mssgLngth) {
- $elem.toggleClass('error', count > mChat.mssgLngth);
+ var count = mChat.cleanMessage(mChat.cached('input').val()).length;
+ var exceedCount = Math.max(mChat.mssgLngth - count, -999);
+ if (mChat.showCharCount) {
+ var charCount = mChat.lang.charCount.format({current: count, max: mChat.mssgLngth});
+ var $elem = mChat.cached('character-count').html(charCount).toggleClass('invisible', count === 0);
+ if (mChat.mssgLngth) {
+ $elem.toggleClass('error', count > mChat.mssgLngth);
+ }
}
+ mChat.cached('exceed-character-count').text(exceedCount).toggleClass('hidden', exceedCount >= 0);
+ mChat.cached('input').parent().toggleClass('mchat-input-error', exceedCount < 0);
+ mChat.cached('add').toggleClass('hidden', exceedCount < 0);
+ },
+ cleanMessage: function(message) {
+ if (!mChat.maxInputHeight) {
+ message = message.replace(/\s+/g, ' ');
+ }
+ return message;
+ },
+ smiley: function() {
+ mChat.appendText($(this).data('smiley-code'), true);
+ },
+ smileyPopup: function() {
+ popup(this.href, 300, 350, '_phpbbsmilies');
},
mention: function() {
var $container = $(this).closest('.mchat-message');
@@ -605,38 +632,55 @@ jQuery(function($) {
}
}
}
- insert_text(mChat.lang.mention.format({username: username}));
+ mChat.appendText(mChat.lang.mention.format({username: username}));
},
quote: function() {
var $container = $(this).closest('.mchat-message');
var username = $container.data('mchat-username');
var quote = $container.data('mchat-message');
- insert_text('[quote="' + username + '"] ' + quote + '[/quote]');
- mChat.cached('input').trigger('update.autogrow');
+ mChat.appendText('[quote="' + username + '"] ' + quote + '[/quote]');
},
like: function() {
var $container = $(this).closest('.mchat-message');
var username = $container.data('mchat-username');
var quote = $container.data('mchat-message');
- insert_text('[i]' + mChat.lang.likes + '[/i][quote="' + username + '"] ' + quote + '[/quote]');
- mChat.cached('input').trigger('update.autogrow');
+ mChat.appendText('[i]' + mChat.lang.likes + '[/i][quote="' + username + '"] ' + quote + '[/quote]');
},
ip: function() {
popup(this.href, 750, 500);
},
- cached: function() {
- return $($.map(arguments, function(name) {
- if (!mChat.cache[name]) {
- mChat.cache[name] = $('#mchat-' + name);
- }
- return mChat.cache[name];
- })).map(function() {
- return this.toArray();
- });
+ custom: function() {
+ window.location.href = this.href;
+ },
+ archive: function() {
+ window.location.href = this.href;
+ },
+ setText: function(text) {
+ mChat.cached('input').val('');
+ mChat.appendText(text);
+ },
+ appendText: function(text, spaces, popup) {
+ var $input = mChat.cached('input');
+ if (text) {
+ insert_text(text, spaces, popup);
+ }
+ if (mChat.maxInputHeight) {
+ autosize.update($input);
+ } else {
+ $input.scrollLeft($input[0].scrollWidth - $input[0].clientWidth);
+ }
+ },
+ cached: function(name) {
+ if (!mChat.cache) {
+ mChat.cache = {};
+ }
+ if (!mChat.cache.hasOwnProperty(name)) {
+ mChat.cache[name] = $('#mchat-' + name);
+ }
+ return mChat.cache[name];
}
});
- mChat.cache = {};
mChat.messageIds = mChat.cached('messages').children().map(function() {
return $(this).data('mchat-id');
}).get();
@@ -646,25 +690,13 @@ jQuery(function($) {
mChat.hiddenFields[this.name] = this.value;
});
- mChat.isPaused = false;
-
if (mChat.page !== 'archive') {
mChat.resetSession();
if (!mChat.messageTop) {
- setTimeout(function() {
- mChat.cached('messages').scrollTop(mChat.cached('messages')[0].scrollHeight);
- }, 1);
+ mChat.cached('messages').delay(1).scrollTop(mChat.cached('messages')[0].scrollHeight);
}
- mChat.cached('user-sound').prop('checked', mChat.playSound && !mChat.storage.get('no_sound')).change(function() {
- if (this.checked) {
- mChat.storage.remove('no_sound');
- } else {
- mChat.storage.set('no_sound', 'yes');
- }
- });
-
$.each(mChat.removeBBCodes.split('|'), function(i, bbcode) {
var bbCodeClass = '.bbcode-' + bbcode.replaceMany({
'=': '-',
@@ -673,87 +705,88 @@ jQuery(function($) {
mChat.cached('body').find(bbCodeClass).remove();
});
- var $colourPalette = $('#colour_palette');
+ var $colourPalette = $('#mchat-bbcodes').find('#colour_palette');
$colourPalette.appendTo($colourPalette.parent()).wrap('').show();
- $('#bbpalette,#abbc3_bbpalette,#color_wheel').prop('onclick', null).attr('data-mchat-toggle', 'colour');
+ $('#bbpalette,#abbc3_bbpalette,#color_wheel').prop('onclick', null).attr({
+ 'data-mchat-action': 'toggle',
+ 'data-mchat-element': 'colour'
+ });
$.each(['userlist', 'smilies', 'bbcodes', 'colour'], function(i, elem) {
if (mChat.storage.get('show_' + elem)) {
+ $('.mchat-button-' + elem).addClass('mchat-button-is-down');
mChat.cached(elem).toggle();
}
});
- mChat.isTextarea = mChat.cached('input').is('textarea');
- mChat.cached('form').submit(function(e){
- e.preventDefault();
- }).keypress(function(e) {
- if ((e.which === 10 || e.which === 13) && (!mChat.isTextarea || e.ctrlKey || e.metaKey) && mChat.cached('input').is(e.target)) {
- mChat.add();
+ mChat.cached('colour').find('.colour-palette').on('click', 'a', function(e) {
+ if (e.ctrlKey || e.metaKey) {
+ e.preventDefault();
+ e.stopImmediatePropagation();
+ var $this = $(this);
+ var newColor = $this.data('color');
+ if (mChat.storage.get('color') === newColor) {
+ mChat.storage.remove('color');
+ } else {
+ mChat.storage.set('color', newColor);
+ mChat.cached('colour').find('.colour-palette a').removeClass('remember-color');
+ }
+ $this.toggleClass('remember-color');
}
});
- if (mChat.pause) {
- mChat.cached('form').on('input', function() {
- if (mChat.refreshInterval !== false) {
- var val = mChat.cached('input').val();
- if (mChat.isPaused && val === '') {
- mChat.pauseEnd();
- } else if (!mChat.isPaused && val !== '') {
- mChat.pauseStart();
- }
- }
+ var color = mChat.storage.get('color');
+ if (color) {
+ mChat.cached('colour').find('.colour-palette a[data-color="' + color + '"]').addClass('remember-color');
+ }
+
+ if (mChat.maxInputHeight) {
+ mChat.cached('input').one('focus', function() {
+ autosize(this);
});
}
- if (mChat.showCharCount) {
+ mChat.cached('form').submit(function(e) {
+ e.preventDefault();
+ }).keypress(function(e) {
+ if ((e.which === 10 || e.which === 13) && mChat.cached('input').is(e.target)) {
+ var isCtrl = e.ctrlKey || e.metaKey;
+ if (!mChat.maxInputHeight || !isCtrl === !mChat.storage.get('no_enter')) {
+ e.preventDefault();
+ mChat.add();
+ } else if (mChat.maxInputHeight && isCtrl) {
+ mChat.appendText('\n');
+ }
+ }
+ });
+
+ if (mChat.showCharCount || mChat.mssgLngth) {
mChat.cached('form').on('input', mChat.updateCharCount);
mChat.cached('input').on('focus', function() {
- setTimeout(function() {
- mChat.updateCharCount();
- }, 1);
+ setTimeout(mChat.updateCharCount, 1);
});
}
-
- mChat.cached('input').autogrow({
- vertical: false,
- horizontal: true
- });
}
mChat.startRelativeTimeUpdate(mChat.cached('messages'));
+ mChat.registerNavItem('sound', mChat.playSound);
+ if (mChat.maxInputHeight) {
+ mChat.registerNavItem('enter', true);
+ }
+
$(window).on('beforeunload', function() {
mChat.pageIsUnloading = true;
});
- mChat.cached('colour').find('.colour-palette').on('click', 'a', function(e) {
- if (e.ctrlKey || e.metaKey) {
- e.preventDefault();
- e.stopImmediatePropagation();
- var $this = $(this);
- var newColor = $this.data('color');
- if (mChat.storage.get('color') === newColor) {
- mChat.storage.remove('color');
- } else {
- mChat.storage.set('color', newColor);
- mChat.cached('colour').find('.colour-palette a').removeClass('remember-color');
- }
- $this.toggleClass('remember-color');
- }
- });
-
- var color = mChat.storage.get('color');
- if (color) {
- mChat.cached('colour').find('.colour-palette a[data-color="' + color + '"]').addClass('remember-color');
- }
-
$('#phpbb').on('click', '[data-mchat-action]', function(e) {
e.preventDefault();
var action = $(this).data('mchat-action');
- mChat[action].call(this);
- }).on('click', '[data-mchat-toggle]', function(e) {
- e.preventDefault();
- var elem = $(this).data('mchat-toggle');
- mChat.toggle(elem);
+ mChat[action].call(this, e);
+ }).on('click', '.mchat-panel-buttons button', function() {
+ var $this = $(this).blur();
+ if ($this.hasClass('mchat-button-down')) {
+ $this.toggleClass('mchat-button-is-down');
+ }
});
});
diff --git a/styles/all/template/mchat_script_data.html b/styles/all/template/mchat_script_data.html
index 125e67f..a5ce86a 100644
--- a/styles/all/template/mchat_script_data.html
+++ b/styles/all/template/mchat_script_data.html
@@ -1,13 +1,13 @@
{% if MCHAT_PAGE == 'archive' or not (MCHAT_ALLOW_USE and S_BBCODE_ALLOWED) %}
{% INCLUDEJS T_ASSETS_PATH ~ '/javascript/editor.js' %}
{% endif %}
-
-{% INCLUDEJS '@dmzx_mchat/javascript/jquery.autogrow-textarea.js' %}
+{% if MCHAT_MAX_INPUT_HEIGHT %}
+ {% INCLUDEJS '@dmzx_mchat/javascript/autosize.min.js' %}
+{% endif %}
{% INCLUDEJS '@dmzx_mchat/javascript/jquery.titlealert.min.js' %}
{% INCLUDEJS '@dmzx_mchat/javascript/mchat.js' %}
-
diff --git a/styles/basic/template/event/overall_footer_after.html b/styles/basic/template/event/overall_footer_after.html
new file mode 100644
index 0000000..f9909e1
--- /dev/null
+++ b/styles/basic/template/event/overall_footer_after.html
@@ -0,0 +1,2 @@
+{% INCLUDECSS '@dmzx_mchat/mchat.arty.css' %}
+{% INCLUDEJS '@dmzx_mchat/javascript/mchat.collapse.arty.js' %}
diff --git a/styles/basic/template/event/overall_header_head_append.html b/styles/basic/template/event/overall_header_head_append.html
deleted file mode 100644
index c9c10a0..0000000
--- a/styles/basic/template/event/overall_header_head_append.html
+++ /dev/null
@@ -1,2 +0,0 @@
-{% INCLUDECSS '@dmzx_mchat/mchat.css' %}
-{% INCLUDECSS '@dmzx_mchat/mchat_custom.css' %}
diff --git a/styles/basic/template/mchat_navlink.html b/styles/basic/template/mchat_navlink.html
deleted file mode 100644
index 8b9cbdc..0000000
--- a/styles/basic/template/mchat_navlink.html
+++ /dev/null
@@ -1 +0,0 @@
-
- {% if MCHAT_PAGE == 'archive' %}
- {{ lang('MCHAT_ARCHIVE_PAGE') }}
- {% elseif MCHAT_CUSTOM_PAGE %}
- {{ lang('MCHAT_TITLE') }}
- {% else %}
- {{ lang('MCHAT_TITLE') }}
- {% endif %}
-
-
- {% if MCHAT_PAGE == 'archive' %}
- {{ lang('MCHAT_ARCHIVE_PAGE') }}
- {% elseif MCHAT_CUSTOM_PAGE %}
- {{ lang('MCHAT_TITLE') }}
- {% else %}
- {{ lang('MCHAT_TITLE') }}
- {% endif %}
-
-
{{ MCHAT_USERS_TOTAL }} {{ MCHAT_ONLINE_EXPLAIN }}
{{ MCHAT_USERS_LIST }}
{% endif %}
diff --git a/styles/prosilver/template/event/overall_header_navigation_append.html b/styles/prosilver/template/event/overall_header_navigation_append.html
index c2a66ec..cb93c19 100644
--- a/styles/prosilver/template/event/overall_header_navigation_append.html
+++ b/styles/prosilver/template/event/overall_header_navigation_append.html
@@ -1,3 +1,3 @@
-{% if MCHAT_CUSTOM_PAGE and MCHAT_NAVBAR_LINK %}
+{% if U_MCHAT_CUSTOM_PAGE or MCHAT_PAGE %}
{% INCLUDE '@dmzx_mchat/mchat_navlink.html' %}
{% endif %}
diff --git a/styles/prosilver/template/event/overall_header_stylesheets_after.html b/styles/prosilver/template/event/overall_header_stylesheets_after.html
index 578df19..741739d 100644
--- a/styles/prosilver/template/event/overall_header_stylesheets_after.html
+++ b/styles/prosilver/template/event/overall_header_stylesheets_after.html
@@ -1,7 +1,14 @@
-{% if (MCHAT_CUSTOM_HEIGHT or MCHAT_INDEX_HEIGHT) and MCHAT_PAGE != 'archive' %}
-
+{% if MCHAT_PAGE and MCHAT_PAGE != 'archive' %}
+
{% endif %}
diff --git a/styles/prosilver/template/mchat_body.html b/styles/prosilver/template/mchat_body.html
index 3c896c1..3c2e1e4 100644
--- a/styles/prosilver/template/mchat_body.html
+++ b/styles/prosilver/template/mchat_body.html
@@ -7,7 +7,7 @@
{% EVENT dmzx_mchat_header_before %}
{% if MCHAT_PAGE == 'custom' %}
-