' . $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..3f64511 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,14 +205,14 @@ 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)
{
if (!$row['session_viewonline'])
{
- if (!$can_view_hidden && $row['user_id'] !== $this->user->data['user_id'])
+ if (!$can_view_hidden && $row['user_id'] != $this->user->data['user_id'])
{
continue;
}
@@ -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)]);
}
}
@@ -420,28 +397,36 @@ class functions
/**
* Returns the total number of messages
*
+ * @param string $sql_where
+ * @param string $sql_order_by
* @return int
*/
- public function mchat_total_message_count()
+ public function mchat_total_message_count($sql_where = '', $sql_order_by = '')
{
- $sql_where_ary = $this->get_sql_where_for_notifcation_messages();
+ $sql_where_array = array_filter([$sql_where, $this->mchat_notifications->get_sql_where()]);
- $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' => $sql_where_array ? ('(' . implode(') AND (', $sql_where_array) . ')') : '',
+ 'ORDER_BY' => $sql_order_by,
+ ];
/**
* Event to modifying the SQL query that fetches the total number of mChat messages
*
* @event dmzx.mchat.total_message_count_modify_sql
- * @var array sql_array Array with SQL query data to fetch the total message count
+ * @var array sql_array Array with SQL query data to fetch the total message count
+ * @var string sql_where Additional SQL where condition passed to this method
+ * @var string sql_order_by Additional SQL order by statement passed to this method
* @since 2.0.0-RC6
+ * @changed 2.1.1 Added sql_where, sql_order_by
*/
- $vars = array(
+ $vars = [
'sql_array',
- );
+ 'sql_where',
+ 'sql_order_by',
+ ];
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 +448,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 +461,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_message_id[] = $this->db->sql_in_set('m.message_id', $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
@@ -516,14 +499,15 @@ class functions
* @var int offset SQL offset
* @var array sql_array Array containing the SQL query data
* @since 2.0.0-RC6
+ * @deprecated 2.1.4-RC1, to be removed in 2.1.0.
*/
- $vars = 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);
@@ -540,91 +524,29 @@ class functions
}
}
+ /**
+ * Event to modify message rows before being processed and displayed
+ *
+ * @event dmzx.mchat.get_messages_modify_rowset
+ * @var array message_ids IDs of specific messages to fetch, e.g. for fetching edited messages
+ * @var int last_id The ID of the latest message that the user has, for fetching new messages
+ * @var int total SQL limit
+ * @var int offset SQL offset
+ * @var array rows Array containing message data
+ * @since 2.1.4-RC1
+ */
+ $vars = [
+ 'message_ids',
+ 'last_id',
+ 'total',
+ 'offset',
+ 'rows',
+ ];
+ extract($this->dispatcher->trigger_event('dmzx.mchat.get_messages_modify_rowset', compact($vars)));
+
return $rows;
}
- /**
- * 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 +555,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 +581,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 +606,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 +627,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 +635,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 +645,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 +652,62 @@ 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->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';
- $result = $this->db->sql_query_limit($sql, 1);
- $message_time = (int) $this->db->sql_fetchfield('message_time');
- $this->db->sql_freeresult($result);
+ $sql_queries = [];
- return $message_time && time() - $message_time < $this->settings->cfg('mchat_flood_time');
+ $sql_array = [
+ 'SELECT' => 'm.user_id',
+ 'FROM' => [$this->mchat_settings->get_table_mchat() => 'm'],
+ 'ORDER_BY' => 'm.message_time DESC, m.message_id DESC',
+ ];
+
+ if ($this->mchat_settings->cfg('mchat_flood_time'))
+ {
+ $sql = $this->db->sql_build_query('SELECT', array_merge($sql_array, [
+ 'WHERE' => implode(' AND ', [
+ 'm.user_id = ' . (int) $this->user->data['user_id'],
+ 'message_time > ' . time() . ' - ' . (int) $this->mchat_settings->cfg('mchat_flood_time'),
+ $this->mchat_notifications->get_sql_where('exclude'),
+ ]),
+ ]));
+
+ $sql_queries[$sql] = 1;
+ }
+
+ if ($this->mchat_settings->cfg('mchat_flood_messages'))
+ {
+ $sql = $this->db->sql_build_query('SELECT', array_merge($sql_array, [
+ 'WHERE' => $this->mchat_notifications->get_sql_where('exclude'),
+ ]));
+
+ $sql_queries[$sql] = $this->mchat_settings->cfg('mchat_flood_messages');
+ }
+
+ foreach ($sql_queries as $sql => $limit)
+ {
+ $result = $this->db->sql_query_limit($sql, $limit);
+ $rows = $this->db->sql_fetchrowset($result);
+ $this->db->sql_freeresult($result);
+
+ if ($rows)
+ {
+ foreach ($rows as $row)
+ {
+ if ($row['user_id'] != $this->user->data['user_id'])
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ }
+
+ return false;
}
/**
@@ -861,9 +718,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 +732,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 +790,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 +809,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 +819,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 +831,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..4524470
--- /dev/null
+++ b/core/log.php
@@ -0,0 +1,238 @@
+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 or a custom type
+ * @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, or 0 if no log row was added
+ */
+ public function add_log($log_type, $message_id)
+ {
+ $log_row = [
+ '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(),
+ ];
+
+ $insert_log = true;
+
+ /**
+ * Event that allows adding log types
+ *
+ * @event dmzx.mchat.log_add_before
+ * @var string log_type The log type, one of edit|del or a custom type
+ * @var int message_id ID of the message to which this log entry belongs
+ * @var array log_row Array that is about to be added to the mchat_log table
+ * @var bool insert_log Whether or not to add the log_row
+ * @since 2.1.2
+ */
+ $vars = [
+ 'log_type',
+ 'message_id',
+ 'log_row',
+ 'insert_log',
+ ];
+ extract($this->dispatcher->trigger_event('dmzx.mchat.log_add_before', compact($vars)));
+
+ if (!$insert_log)
+ {
+ return 0;
+ }
+
+ $sql = 'INSERT INTO ' . $this->mchat_settings->get_table_mchat_log() . ' ' . $this->db->sql_build_array('INSERT', $log_row);
+
+ $this->db->sql_query($sql);
+
+ $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 log_row The log data (read only)
+ * @since 2.0.0-RC6
+ * @changed 2.1.2 Removed response
+ */
+ $vars = [
+ '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..58da0ff 100644
--- a/core/mchat.php
+++ b/core/mchat.php
@@ -17,20 +17,28 @@ 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;
use phpbb\textformatter\parser_interface;
use phpbb\user;
+use rmcgirr83\authorizedforurls\event\listener as authorizedforurls;
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 +49,9 @@ class mchat
/** @var user */
protected $user;
+ /** @var language */
+ protected $lang;
+
/** @var auth */
protected $auth;
@@ -56,78 +67,82 @@ 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;
+ /** @var authorizedforurls */
+ protected $authorized_for_urls;
+
/** @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
+ * @param authorizedforurls $authorized_for_urls
*/
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,
- cc_operator $cc_operator = null
+ parser_interface $textformatter_parser,
+ cc_operator $cc_operator = null,
+ authorizedforurls $authorized_for_urls = 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,
- ));
+ $this->authorized_for_urls = $authorized_for_urls;
}
/**
@@ -142,12 +157,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 +186,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 +202,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 +217,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 +232,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 +264,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 +290,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'));
}
/**
@@ -310,13 +321,7 @@ class mchat
throw new http_exception(403, 'NO_AUTH_OPERATION');
}
- // Fix avatars & smilies
- if (!defined('PHPBB_USE_BOARD_URL_PATH'))
- {
- define('PHPBB_USE_BOARD_URL_PATH', true);
- }
-
- $this->user->add_lang_ext('dmzx/mchat', 'mchat');
+ $this->lang->add_lang('mchat', 'dmzx/mchat');
}
/**
@@ -329,25 +334,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 +367,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 +393,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 +422,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 +439,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 +459,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 +488,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 +500,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 +514,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 +536,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 +549,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 +560,22 @@ 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;
+ unset($logs);
+ }
+ else
+ {
+ $log_edit_del_ids = array_fill_keys($this->mchat_log->get_types(), []);
}
$last_id = $this->request->variable('last', 0);
@@ -613,18 +593,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 +652,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 +674,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 +696,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,23 +715,45 @@ 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']);
}
+ else
+ {
+ $active_users = [];
+ }
+
+ /**
+ * Event that is triggered before data for the navigation bar is assigned to the template
+ *
+ * @event dmzx.mchat.header_link_template_data
+ * @var array template_data The data that is abbout to be assigned to the template
+ * @var array active_users Array containing information about active users. Available array keys:
+ * online_userlist, users_count_title, users_total, refresh_message
+ * Note: This array is empty if the number of active chat sessions is not
+ * displayed in the navbar.
+ * @since 2.1.4-RC1
+ */
+ $vars = [
+ 'template_data',
+ 'active_users',
+ ];
+ extract($this->dispatcher->trigger_event('dmzx.mchat.header_link_template_data', compact($vars)));
$this->template->assign_vars($template_data);
}
@@ -770,149 +772,223 @@ 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'));
+ $is_archive = $page == 'archive';
+ $jump_to_id = $is_archive ? $this->request->variable('jumpto', 0) : 0;
- $this->template->assign_vars(array(
+ // If the static message is not empty in the language file, use it, else use 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');
+
+ $total_messages = $this->mchat_functions->mchat_total_message_count();
+
+ $template_data = [
'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_CURRENT_URL' => $this->mchat_settings->get_current_page(),
+ 'MCHAT_ALLOW_SMILES' => $this->mchat_settings->cfg('allow_smilies') && $this->auth->acl_get('u_mchat_smilies'),
+ '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_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'),
+ 'MCHAT_TOTAL_MESSAGES' => $total_messages,
+ 'MCHAT_JUMP_TO' => $jump_to_id,
+ '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());
+ $template_data['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,
- )));
+ 'refresh' => !$is_archive && $this->auth->acl_get('u_mchat_view'),
+ 'add' => !$is_archive && $this->auth->acl_get('u_mchat_use'),
+ 'whois' => !$is_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);
- $start = $page === 'archive' ? $this->request->variable('start', 0) : 0;
- $rows = $this->functions->mchat_get_messages(array(), 0, $limit, $start);
+ $limit = $this->mchat_settings->cfg('mchat_message_num_' . $page);
+
+ if ($is_archive)
+ {
+ if ($jump_to_id)
+ {
+ $sql_where_jump_to_id = 'm.message_id > ' . (int) $jump_to_id;
+ $sql_order_by = 'm.message_id ASC';
+ $num_subsequent_messages = $this->mchat_functions->mchat_total_message_count($sql_where_jump_to_id, $sql_order_by);
+ $start = (int) floor($num_subsequent_messages / $limit) * $limit;
+ }
+ else
+ {
+ $start = $this->request->variable('start', 0);
+ }
+ }
+ else
+ {
+ $start = 0;
+ }
+
+ $message_ids = [];
+ $last_id = 0;
+
+ /**
+ * Event to modify arguments before fetching messages from the database
+ *
+ * @event dmzx.mchat.render_page_get_messages_before
+ * @var string page The page that is rendered, one of index|custom|archive
+ * @var array message_ids IDs of specific messages to fetch, should be an empty array
+ * @var int last_id The ID of the latest message that the user has, should be 0
+ * @var int limit Number of messages to display per page
+ * @var int start The message which should be considered currently active, used to determine the page we're on
+ * @var int jump_to_id The ID of the message that is being jumped to in the archive, usually when a user clicked on a quote reference
+ * @var array actions Array containing URLs to actions the user is allowed to perform (read only)
+ * @var array template_data The data that is about to be assigned to the template
+ * @var int total_messages Total number of messages
+ * @since 2.1.1
+ * @changed 2.1.4-RC1 added total_messages
+ */
+ $vars = [
+ 'page',
+ 'message_ids',
+ 'last_id',
+ 'limit',
+ 'start',
+ 'jump_to_id',
+ 'actions',
+ 'template_data',
+ 'total_messages',
+ ];
+ extract($this->dispatcher->trigger_event('dmzx.mchat.render_page_get_messages_before', compact($vars)));
$this->assign_global_template_data();
- $this->assign_messages($rows, $page);
+
+ // Always fetch at least one message so that we can extract the latest_message_id
+ $soft_limit = max(1, $limit);
+
+ $rows = $this->mchat_functions->mchat_get_messages($message_ids, $last_id, $soft_limit, $start);
+
+ if ($limit)
+ {
+ $this->assign_messages($rows, $page);
+ }
+
+ // Pass the latest_message_id to the template so that we know later where to start looking for new messages
+ $latest_message_id = 0;
+
+ if ($rows)
+ {
+ $latest_message = reset($rows);
+ $latest_message_id = $latest_message['message_id'];
+ }
+
+ $template_data['MCHAT_LATEST_MESSAGE_ID'] = $latest_message_id;
// Render pagination
- if ($page === 'archive')
+ if ($is_archive)
{
$archive_url = $this->helper->route('dmzx_mchat_page_archive_controller');
- $total_messages = $this->functions->mchat_total_message_count();
/**
* Event to modify mChat pagination on the archive page
*
* @event dmzx.mchat.render_page_pagination_before
* @var string archive_url Pagination base URL
- * @var int total_messages Total number of messages
+ * @var int total_messages Total number of messages in the mChat table
* @var int limit Number of messages to display per page
* @var int start The message which should be considered currently active, used to determine the page we're on
+ * @var int jump_to_id The ID of the message that is being jumped to in the archive, usually when a user clicked on a quote reference
+ * @var array template_data The data that is about to be assigned to the template
* @since 2.0.0-RC6
+ * @changed 2.1.1 added jump_to_id, template_data
*/
- $vars = array(
+ $vars = [
'archive_url',
'total_messages',
'limit',
'start',
- );
+ 'jump_to_id',
+ 'template_data',
+ ];
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));
+ $template_data['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();
+ $template_data['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(
+ $template_data = array_merge($template_data, [
'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(
- 'forum_id' => $cc_fid,
- 'hash' => generate_link_hash('collapsible_' . $cc_fid),
- )),
- ));
+ 'S_MCHAT_HIDDEN' => $this->cc_operator->is_collapsed($cc_fid),
+ 'U_MCHAT_COLLAPSE_URL' => $this->cc_operator->get_collapsible_link($cc_fid),
+ ]);
}
$this->assign_authors();
if ($this->auth->acl_get('u_mchat_use'))
{
- add_form_key('mchat');
+ add_form_key('mchat', '_DMZX_MCHAT');
}
/**
* Event that is triggered after mChat was rendered
*
* @event dmzx.mchat.render_page_after
- * @var string page The page that was rendered, one of index|custom|archive
- * @var array actions Array containing URLs to actions the user is allowed to perform
+ * @var string page The page that was rendered, one of index|custom|archive
+ * @var array actions Array containing URLs to actions the user is allowed to perform (read only)
+ * @var array template_data The data that is about to be assigned to the template
* @since 2.0.0-RC6
+ * @changed 2.1.1 Added template_data
*/
- $vars = array(
+ $vars = [
'page',
'actions',
- );
+ 'template_data',
+ ];
extract($this->dispatcher->trigger_event('dmzx.mchat.render_page_after', compact($vars)));
+
+ $this->template->assign_vars($template_data);
}
/**
@@ -920,20 +996,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 +1017,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 +1041,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 +1056,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,44 +1067,27 @@ 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)
{
return;
}
- // 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');
- if ($page === 'archive')
- {
- $mchat_archive_sort = $this->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;
- }
- }
- else if (!$mchat_message_top)
- {
- $reverse = true;
- }
-
- if ($reverse)
+ if ($this->messages_need_reversing($page))
{
$rows = array_reverse($rows);
}
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,74 +1095,60 @@ 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,
- ));
+ 'avatar_width' => $row['user_avatar_width'] >= $row['user_avatar_height'] ? 36 : 0,
+ 'avatar_height' => $row['user_avatar_width'] >= $row['user_avatar_height'] ? 0 : 36,
+ ]);
}
}
- $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'));
-
- // Fix profile link root path by replacing relative paths with absolute board URL
- if ($this->request->is_ajax())
- {
- $username_full = preg_replace('#(?<=href=")[\./]+?/(?=\w)#', $board_url, $username_full);
- }
+ $username_full = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->lang->lang('GUEST'));
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_USER_ID' => $row['user_id'],
'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->auth->acl_get('u_mchat_ip') ? $this->helper->route('dmzx_mchat_page_whois_controller', ['ip' => $row['user_ip']]) : false,
+ '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 +1156,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,23 +1164,50 @@ 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);
}
}
+ /**
+ * By default, rows are fetched by message ID descending. This method returns true if
+ * the user wants them to be displayed ascending, otherwise false.
+ *
+ * @param string $page
+ * @return bool
+ */
+ protected function messages_need_reversing($page)
+ {
+ $mchat_message_top = $this->mchat_settings->cfg('mchat_message_top');
+
+ if ($page === 'archive')
+ {
+ $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)
+ {
+ return true;
+ }
+ }
+ else if (!$mchat_message_top)
+ {
+ return true;
+ }
+
+ return false;
+ }
+
/**
* Returns true if the user is allowed to read the given message row
*
@@ -1163,111 +1234,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 +1243,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 +1264,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);
@@ -1313,52 +1279,67 @@ class mchat
*/
protected function assign_bbcodes_smilies()
{
+ $display_bbcodes = $this->mchat_settings->cfg('allow_bbcode') && $this->auth->acl_get('u_mchat_bbcode');
+
+ $display_smilies = $this->mchat_settings->cfg('allow_smilies') && $this->auth->acl_get('u_mchat_smilies') && !$this->smilies_generated;
+
+ /**
+ * Event to decide whether or to display BBCodes or smilies
+ *
+ * @event dmzx.mchat.assign_bbcodes_smilies_before
+ * @var bool display_bbcodes Whether or not to render BBCodes
+ * @var bool display_smilies Whether or not to render smilies
+ * @since 2.1.4-RC1
+ */
+ $vars = [
+ 'display_bbcodes',
+ 'display_smilies',
+ ];
+ extract($this->dispatcher->trigger_event('dmzx.mchat.assign_bbcodes_smilies_before', compact($vars)));
+
// Display BBCodes
- if ($this->settings->cfg('allow_bbcode') && $this->auth->acl_get('u_mchat_bbcode'))
+ if ($display_bbcodes)
{
- $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 ($display_smilies)
{
- 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 +1356,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 +1370,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 +1390,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 +1400,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 +1415,7 @@ class mchat
*/
public function session_gc()
{
- $this->functions->mchat_session_gc();
+ $this->mchat_functions->mchat_session_gc();
}
/**
@@ -1456,16 +1423,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 +1456,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 +1476,48 @@ 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'))
+ // Compatibility with Authorized for URLs by RMcGirr83 - requires at least 1.0.5
+ // https://www.phpbb.com/customise/db/extension/authorized_for_urls_2/
+ if ($this->authorized_for_urls !== null && is_callable([$this->authorized_for_urls, 'check_text']))
{
- $this->settings->set_cfg('min_post_chars', 0, true);
+ $authorized_for_urls_lang_args = $this->authorized_for_urls->check_text($message, true);
+
+ if ($authorized_for_urls_lang_args)
+ {
+ $authorized_for_urls_lang_key = array_shift($authorized_for_urls_lang_args);
+ throw new http_exception(400, $authorized_for_urls_lang_key, $authorized_for_urls_lang_args);
+ }
}
- if ($this->settings->cfg('mchat_override_smilie_limit'))
+ if ($this->mchat_settings->cfg('mchat_override_min_post_chars'))
{
- $this->settings->set_cfg('max_post_smilies', 0, true);
+ $this->mchat_settings->set_cfg('min_post_chars', 0, true);
}
- $disallowed_bbcodes = array_filter(explode('|', $this->settings->cfg('mchat_bbcode_disallowed')));
+ if ($this->mchat_settings->cfg('mchat_override_smilie_limit'))
+ {
+ $this->mchat_settings->set_cfg('max_post_smilies', 0, true);
+ }
- $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');
+ $disallowed_bbcodes = array_filter(explode('|', $this->mchat_settings->cfg('mchat_bbcode_disallowed')));
+
+ $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 +1526,59 @@ class mchat
foreach ($disallowed_bbcodes as $bbcode)
{
- $this->parser->disable_bbcode($bbcode);
+ $this->textformatter_parser->disable_bbcode($bbcode);
}
}
+ /**
+ * Event to modify the raw mChat message before it is processed
+ *
+ * @event dmzx.mchat.process_message_before
+ * @var string message The raw message as entered by the user
+ * @var string message_without_bbcode The message stripped of all BBCode tags
+ * @var array disallowed_bbcodes The list of disallowed BBCode tags
+ * @var bool mchat_img Whether or not the img BBCode is allowed
+ * @var bool mchat_flash Whether or not the flash BBCode is allowed
+ * @var bool mchat_quote Whether or not the quote BBCode is allowed
+ * @var bool mchat_url Whether or not the url BBCode is allowed
+ * @since 2.1.4-RC1
+ */
+ $vars = [
+ 'message',
+ 'message_without_bbcode',
+ 'disallowed_bbcodes',
+ 'mchat_img',
+ 'mchat_flash',
+ 'mchat_quote',
+ 'mchat_url',
+ ];
+ extract($this->dispatcher->trigger_event('dmzx.mchat.process_message_before', compact($vars)));
+
$uid = $bitfield = $options = '';
- generate_text_for_storage($message, $uid, $bitfield, $options, $mchat_bbcode, $mchat_magic_urls, $mchat_smilies, $mchat_img, $mchat_flash, $mchat_quote, $mchat_url);
+ 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 +1589,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..e0a9894
--- /dev/null
+++ b/core/notifications.php
@@ -0,0 +1,453 @@
+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. 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',
+ ];
+
+ /**
+ * Event that allows to modify rows and language keys before checking for notifications
+ *
+ * @event dmzx.mchat.process_notifications_before
+ * @var array rows Message rows about to be checked for notifications
+ * @var array notification_lang Unprocessed language keys of valid/known notifications
+ * @since 2.1.4-RC1
+ */
+ $vars = [
+ 'rows',
+ 'notification_lang',
+ ];
+ extract($this->dispatcher->trigger_event('dmzx.mchat.process_notifications_before', compact($vars)));
+
+ $notification_langs = array_merge(
+ // Raw notification messages in phpBB < 3.2
+ array_combine($notification_lang, $notification_lang),
+ // 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);
+ }
+
+ /**
+ * Event that allows to modify rows after processing their notifications
+ *
+ * @event dmzx.mchat.process_notifications_after
+ * @var array rows Message rows about to be checked for notifications
+ * @var array notification_lang Unprocessed language keys of valid/known notifications
+ * @var array notification_langs Processed language keys of valid/known notifications
+ * @var array notification_post_data Post data of notifications found in the rows array
+ * @since 2.1.4-RC1
+ */
+ $vars = [
+ 'rows',
+ 'notification_lang',
+ 'notification_langs',
+ 'notification_post_data',
+ ];
+ extract($this->dispatcher->trigger_event('dmzx.mchat.process_notifications_after', compact($vars)));
+
+ return $rows;
+ }
+
+ /**
+ * 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);
+
+ $existing_post_ids = array_column($rows, 'post_id');
+ $existing_posts = array_combine($existing_post_ids, $rows);
+
+ // Map IDs of missing posts to null
+ $missing_posts = array_fill_keys(array_diff($post_ids, $existing_post_ids), null);
+
+ return $existing_posts + $missing_posts;
+ }
+
+ /**
+ * 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
+ *
+ * @param string $mode One of user|exclude. user mode uses the current user's settings to decide which notifications
+ * to exclude. exclude mode always excludes all notifications.
+ * @return string
+ */
+ public function get_sql_where($mode = 'user')
+ {
+ // Exclude all post notifications
+ if ($mode == 'exclude' || !$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 '';
+ }
+
+ /**
+ * Delete post notification messages, for example when disapproving posts
+ *
+ * @param array $post_ids
+ */
+ public function delete_post_notifications($post_ids)
+ {
+ if ($post_ids)
+ {
+ $sql = 'DELETE FROM ' . $this->mchat_settings->get_table_mchat() . '
+ WHERE forum_id <> 0 AND ' . $this->db->sql_in_set('post_id', $post_ids);
+ $this->db->sql_query($sql);
+ }
+ }
+
+ /**
+ * Change the user to which a post notification belongs
+ *
+ * @param int $post_id
+ * @param int $user_id
+ */
+ public function update_post_notification_user($post_id, $user_id)
+ {
+ $sql = 'UPDATE ' . $this->mchat_settings->get_table_mchat() . '
+ SET user_id = ' . (int) $user_id . '
+ WHERE forum_id <> 0 AND post_id = ' . (int) $post_id;
+ $this->db->sql_query($sql);
+ }
+}
diff --git a/core/settings.php b/core/settings.php
index 1ac2eea..494b5a7 100644
--- a/core/settings.php
+++ b/core/settings.php
@@ -15,6 +15,8 @@ use phpbb\auth\auth;
use phpbb\config\config;
use phpbb\config\db_text;
use phpbb\event\dispatcher_interface;
+use phpbb\exception\runtime_exception;
+use phpbb\language\language;
use phpbb\user;
class settings
@@ -22,6 +24,9 @@ class settings
/** @var user */
protected $user;
+ /** @var language */
+ protected $lang;
+
/** @var config */
protected $config;
@@ -34,6 +39,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 +97,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 +115,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 +158,39 @@ 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, 3600]],
+ 'mchat_flood_messages' => ['default' => 0, 'validation' => ['num', false, 0, 100]],
+ '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],
+ 'mchat_message_num_archive' => ['default' => 25, 'validation' => ['num', false, 10, 100]],
+ 'mchat_message_num_custom' => ['default' => 10],
+ 'mchat_message_num_index' => ['default' => 10],
+ '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, 2, 3600]],
+ '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 +199,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 +212,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 +224,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 +237,20 @@ 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_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 +259,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 +309,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;
@@ -330,6 +362,11 @@ class settings
}
}
+ if (isset($this->config[$config]))
+ {
+ return $this->config[$config];
+ }
+
$global_text_settings = $this->global_text_settings();
if (isset($global_text_settings[$config]))
@@ -338,7 +375,7 @@ class settings
return $global_text_values[$config];
}
- return $this->config[$config];
+ throw new runtime_exception();
}
/**
@@ -372,6 +409,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 +440,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 +473,72 @@ 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);
+ }
+
+ /**
+ * @return string
+ */
+ public function get_current_page()
+ {
+ $page = $this->user->page['page_name'];
+
+ // Remove app.php if URL rewriting is enabled in the ACP
+ if ($this->config['enable_mod_rewrite'])
+ {
+ $app_php = 'app.' . $this->php_ext . '/';
+
+ if (($app_position = strpos($page, $app_php)) !== false)
+ {
+ $page = substr($page, $app_position + strlen($app_php));
+ }
+ }
+
+ return generate_board_url() . '/' . $page;
+ }
+
+ /**
+ * @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..99debce 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,61 @@ 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.delete_posts_after' => 'delete_posts_after',
+ '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.mcp_change_poster_after' => 'mcp_change_poster_after',
'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 +109,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 +138,41 @@ 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 delete_posts_after(data $event)
+ {
+ $this->mchat_notifications->delete_post_notifications($event['post_ids']);
+ }
+
+ /**
+ * @param data $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 +180,20 @@ class main_listener implements EventSubscriberInterface
/**
* @param data $event
*/
- public function user_login_success($event)
+ public function mcp_change_poster_after(data $event)
+ {
+ $this->mchat_notifications->update_post_notification_user($event['post_info']['post_id'], $event['userdata']['user_id']);
+ }
+
+ /**
+ * @param data $event
+ */
+ 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..4d6d588 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',
@@ -63,57 +64,62 @@ $lang = array_merge($lang, array(
'MCHAT_VERSION' => 'Version',
'MCHAT_RULES' => 'Rules',
'MCHAT_RULES_EXPLAIN' => 'Enter the rules here. HTML code is allowed. Set to empty to disable the display. This message can be translated: edit the MCHAT_RULES_MESSAGE language key in /ext/dmzx/mchat/language/XX/mchat.php.',
- 'MCHAT_CONFIG_SAVED' => 'mChat configuration has been updated',
+ 'MCHAT_CONFIG_SAVED' => 'mChat configuration has been updated.',
'MCHAT_AVATARS' => 'Display avatars',
- 'MCHAT_AVATARS_EXPLAIN' => 'If set to yes, resized user avatars will be displayed',
+ 'MCHAT_AVATARS_EXPLAIN' => 'If set to yes, resized user avatars will be displayed.',
'MCHAT_INDEX' => 'Display mChat on the index page',
'MCHAT_INDEX_HEIGHT' => 'Index page height',
- 'MCHAT_INDEX_HEIGHT_EXPLAIN' => 'The height of the chat box in pixels on the index page. You are limited from 50 to 1000. Default is 250.',
+ 'MCHAT_INDEX_HEIGHT_EXPLAIN' => 'You are limited from 50 to 1000. Default is 250.',
'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 2 to 3600 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',
'MCHAT_PRUNE_GC' => 'Message prune task interval',
- 'MCHAT_PRUNE_GC_EXPLAIN' => 'The time in seconds that needs to pass before the next message pruning is triggered. Note: this setting controls when messages are checked if they can be deleted. It does not control which messages are deleted. Default is 86400 = 24 hours.',
+ 'MCHAT_PRUNE_GC_EXPLAIN' => 'The time that needs to pass before the next message pruning is triggered. Note: this setting controls when messages are checked if they can be deleted. It does not control which messages are deleted. Default is 86400 seconds = 24 hours.',
'MCHAT_PRUNE_NUM' => 'Messages to retain when pruning',
'MCHAT_PRUNE_NUM_EXPLAIN' => 'When using ’messages’ a fixed number of messages will be kept. When using ’hours’, ’days’ or ’weeks’ all messages older than the specified time period at the time of pruning will be deleted.',
'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_MESSAGE_NUM_CUSTOM_EXPLAIN' => 'You are limited from 5 to 50. Default is 10.',
+ 'MCHAT_NAVBAR_LINK_COUNT' => 'Display number of active chat sessions in the navbar',
+ 'MCHAT_MESSAGE_NUM_CUSTOM' => 'Initial number of messages to display on the mChat page',
+ 'MCHAT_MESSAGE_NUM_CUSTOM_EXPLAIN' => '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.',
+ 'MCHAT_MESSAGE_NUM_INDEX_EXPLAIN' => 'Default is 10.',
'MCHAT_MESSAGE_NUM_ARCHIVE' => 'Number of messages to display on the archive page',
- 'MCHAT_MESSAGE_NUM_ARCHIVE_EXPLAIN' => 'The maximum number of messages to show per page on the archive page. You are limited from 10 to 100. Default is 25.',
+ 'MCHAT_MESSAGE_NUM_ARCHIVE_EXPLAIN' => 'You are limited from 10 to 100. Default is 25.',
'MCHAT_ARCHIVE_SORT' => 'Message sorting',
'MCHAT_ARCHIVE_SORT_TOP_BOTTOM' => 'Always sort messages oldest to newest',
'MCHAT_ARCHIVE_SORT_BOTTOM_TOP' => 'Always sort messages newest to oldest',
'MCHAT_ARCHIVE_SORT_USER' => 'Sort messages depending on the user’s Location of new messages preference',
'MCHAT_FLOOD_TIME' => 'Flood time',
- 'MCHAT_FLOOD_TIME_EXPLAIN' => 'The number of seconds a user must wait before posting another message in the chat. You are limited from 0 to 60 seconds. Default is 0. Set to 0 to disable.',
+ 'MCHAT_FLOOD_TIME_EXPLAIN' => 'The number of seconds a user must wait before posting another message in the chat. You are limited from 0 to 3600 seconds (1 hour). Default is 0. Set to 0 to disable.',
+ 'MCHAT_FLOOD_MESSAGES' => 'Flood messages',
+ 'MCHAT_FLOOD_MESSAGES_EXPLAIN' => 'The number of messages a user can send consecutively before another user is required to post in the chat. You are limited from 0 to 100 messages. Default is 0. Set to 0 to disable.',
'MCHAT_EDIT_DELETE_LIMIT' => 'Time limit for editing and deleting messages',
'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_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_MAX_MESSAGE_LENGTH_EXPLAIN' => 'Maximum number of characters allowed per message posted. Default is 500. Set to 0 to disable.',
+ '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' => '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',
- 'MCHAT_STATIC_MESSAGE_EXPLAIN' => 'Here you can define a static message to display to users of the chat. HTML code is allowed. Set to empty to disable the display. This message can be translated: edit the MCHAT_STATIC_MESSAGE language key in /ext/dmzx/mchat/language/XX/mchat.php.',
+ 'MCHAT_STATIC_MESSAGE_EXPLAIN' => 'Here you can define a static message. HTML code is allowed. Set to empty to disable the display. This message can be translated: edit the MCHAT_STATIC_MESSAGE language key in /ext/dmzx/mchat/language/XX/mchat.php.',
'MCHAT_TIMEOUT' => 'Session timeout',
- 'MCHAT_TIMEOUT_EXPLAIN' => 'Set the number of seconds until a session in the chat ends. Set to 0 for no timeout. Careful, the session of a user reading mChat will never expire! You are limited to the %1$sforum config setting for sessions%2$s which is currently set to %3$d seconds',
+ 'MCHAT_TIMEOUT_EXPLAIN' => 'Set the number of seconds until a session in the chat ends. Set to 0 for no timeout. Careful, the session of a user reading mChat will never expire! You are limited to the %1$sforum config setting for sessions%2$s which is currently set to %3$d seconds.',
'MCHAT_OVERRIDE_SMILIE_LIMIT' => 'Override smilie limit',
- 'MCHAT_OVERRIDE_SMILIE_LIMIT_EXPLAIN' => 'Set to yes to override the forums smilie limit setting for chat messages',
+ '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_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.',
@@ -123,37 +129,35 @@ $lang = array_merge($lang, array(
'MCHAT_SOUND' => 'Play sounds for new, edited and deleted messages',
'MCHAT_PURGE' => 'Delete all messages now',
'MCHAT_PURGE_CONFIRM' => 'Confirm deleting all messages',
- 'MCHAT_PURGED' => 'All mChat messages have been successfully deleted',
+ 'MCHAT_PURGED' => 'All mChat messages have been successfully deleted.',
+
+ 'MCHAT_REPARSER_STATUS' => 'Message reparser status',
+ 'MCHAT_REPARSER_ACTIVE' => 'active',
+ 'MCHAT_REPARSER_FINISHED' => 'finished',
// '%1$s' contains 'Retain posts' and 'Delete posts' respectively
'MCHAT_RETAIN_MESSAGES' => '%1$s and retain mChat messages',
'MCHAT_DELETE_MESSAGES' => '%1$s and delete mChat messages',
// 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_LONG_MCHAT_BBCODE_DISALLOWED' => 'The disallowed BBCodes value is too long.',
+ '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_LARGE_MCHAT_FLOOD_MESSAGES' => 'The flood messages 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_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_LARGE_MCHAT_MAX_INPUT_HEIGHT' => 'The max input height value 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..258ebde 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.',
@@ -45,15 +45,10 @@ $lang = array_merge($lang, array(
'MCHAT_STATS_INDEX_EXPLAIN' => 'Displays who is chatting below the Who is online section on the index page.',
'MCHAT_AVATARS' => 'Display avatars',
'MCHAT_CAPITAL_LETTER' => 'Capital first letter in your messages',
- 'MCHAT_CHAT_AREA' => 'Input type',
- 'MCHAT_INPUT_AREA' => 'Input field',
- 'MCHAT_TEXT_AREA' => 'Text area',
'MCHAT_POSTS' => 'Display new posts (currently all disabled, can be enabled in the mChat Global Settings section in the ACP)',
'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 +64,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..76a27ad 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,9 +43,9 @@ $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_FLOOD_IGNORE' => 'Can ignore flood limit',
+ '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 limits',
'ACL_U_MCHAT_ARCHIVE' => 'Can view the archive',
'ACL_U_MCHAT_BBCODE' => 'Can use BBCodes',
'ACL_U_MCHAT_SMILIES' => 'Can use smilies',
@@ -56,10 +56,8 @@ $lang = array_merge($lang, array(
'ACL_U_MCHAT_CHARACTER_COUNT' => 'Can customise Display number of characters',
'ACL_U_MCHAT_DATE' => 'Can customise Date format',
'ACL_U_MCHAT_INDEX' => 'Can customise Display on index',
- '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 +65,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/migrations/mchat_2_1_1.php b/migrations/mchat_2_1_1.php
new file mode 100644
index 0000000..d353c3b
--- /dev/null
+++ b/migrations/mchat_2_1_1.php
@@ -0,0 +1,55 @@
+ [
+ $this->table_prefix . 'users' => [
+ 'user_mchat_input_area',
+ ],
+ ],
+ ];
+ }
+
+ public function revert_schema()
+ {
+ return [
+ 'add_columns' => [
+ $this->table_prefix . 'users' => [
+ 'user_mchat_input_area' => ['BOOL', 1],
+ ],
+ ],
+ ];
+ }
+}
diff --git a/migrations/mchat_2_1_2.php b/migrations/mchat_2_1_2.php
new file mode 100644
index 0000000..db3ba31
--- /dev/null
+++ b/migrations/mchat_2_1_2.php
@@ -0,0 +1,30 @@
+
+ document.querySelector('#mchat-body').classList.add('topiclist');
+ document.querySelector('#mchat-body').classList.add('forums');
+
\ 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/CleanSilver/template/event/overall_footer_after.html b/styles/CleanSilver/template/event/overall_footer_after.html
new file mode 100644
index 0000000..92842d9
--- /dev/null
+++ b/styles/CleanSilver/template/event/overall_footer_after.html
@@ -0,0 +1 @@
+{% INCLUDECSS '@dmzx_mchat/mchat_cleansilver.css' %}
diff --git a/styles/CleanSilver/theme/mchat_cleansilver.css b/styles/CleanSilver/theme/mchat_cleansilver.css
new file mode 100644
index 0000000..22575ae
--- /dev/null
+++ b/styles/CleanSilver/theme/mchat_cleansilver.css
@@ -0,0 +1,26 @@
+/**
+ *
+ * mChat CSS for CleanSilver
+ *
+ * @package phpBB Extension - mChat
+ * @copyright (c) 2017 MannixMD
+ * @copyright (c) 2018 kasimi - https://kasimi.net
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ *
+ */
+
+.mchat-panel-buttons .icon.fa.fa-smile-o {
+ padding: 3px;
+}
+
+.mchat-wrapper li.header dd {
+ width: 95px;
+}
+
+.mchat-wrapper li.header dd.lastpost {
+ width: 250px;
+}
+
+.mchat-button-is-down {
+ border-style: none;
+}
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 c7cce97..0000000
Binary files a/styles/Hexagon/theme/images/icon_mchat.png and /dev/null differ
diff --git a/styles/Hexagon/theme/images/message_icons_orange.png b/styles/Hexagon/theme/images/message_icons_orange.png
deleted file mode 100644
index 59e827d..0000000
Binary files a/styles/Hexagon/theme/images/message_icons_orange.png and /dev/null differ
diff --git a/styles/Hexagon/theme/mchat_custom.css b/styles/Hexagon/theme/mchat_custom.css
deleted file mode 100644
index 358a873..0000000
--- a/styles/Hexagon/theme/mchat_custom.css
+++ /dev/null
@@ -1,6 +0,0 @@
-.mchat-icon:before {
- background-image: url("./images/message_icons_orange.png") !important;
-}
-.icon-mchat {
- background-image: url("./images/icon_mchat.png");
-}
diff --git a/styles/HexagonReborn/template/event/overall_footer_after.html b/styles/HexagonReborn/template/event/overall_footer_after.html
new file mode 100644
index 0000000..1e4a885
--- /dev/null
+++ b/styles/HexagonReborn/template/event/overall_footer_after.html
@@ -0,0 +1 @@
+{% INCLUDECSS '@dmzx_mchat/mchat_hexagonreborn.css' %}
diff --git a/styles/HexagonReborn/theme/mchat_hexagonreborn.css b/styles/HexagonReborn/theme/mchat_hexagonreborn.css
new file mode 100644
index 0000000..def6ef5
--- /dev/null
+++ b/styles/HexagonReborn/theme/mchat_hexagonreborn.css
@@ -0,0 +1,26 @@
+/**
+ *
+ * mChat CSS for Hexagon Reborn
+ *
+ * @package phpBB Extension - mChat
+ * @copyright (c) 2017 MannixMD
+ * @copyright (c) 2018 kasimi - https://kasimi.net
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ *
+ */
+
+.mchat-button-down {
+ line-height: 1.6;
+}
+
+.mchat-button-down .icon {
+ padding: 2px;
+}
+
+.mchat-button-is-down {
+ border-style: none;
+}
+
+.mchat-input-control button:hover .icon {
+ color: #de7300;
+}
diff --git a/styles/Modern-silver/template/event/overall_header_head_append.html b/styles/Modern-silver/template/event/overall_header_head_append.html
deleted file mode 100644
index c9c10a0..0000000
--- a/styles/Modern-silver/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/Modern-silver/theme/mchat_custom.css b/styles/Modern-silver/theme/mchat_custom.css
deleted file mode 100644
index 318a316..0000000
--- a/styles/Modern-silver/theme/mchat_custom.css
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
- *
- * @package phpBB Extension - mChat
- * @copyright (c) 2016 kasimi - https://kasimi.net
- * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
- *
- */
-
-.mchat-wrapper {
- height: 100%;
-}
diff --git a/styles/MyInvision/template/event/overall_footer_after.html b/styles/MyInvision/template/event/overall_footer_after.html
new file mode 100644
index 0000000..285e993
--- /dev/null
+++ b/styles/MyInvision/template/event/overall_footer_after.html
@@ -0,0 +1 @@
+{% INCLUDECSS '@dmzx_mchat/mchat_myinvision.css' %}
diff --git a/styles/MyInvision/template/event/overall_header_head_append.html b/styles/MyInvision/template/event/overall_header_head_append.html
deleted file mode 100644
index c9c10a0..0000000
--- a/styles/MyInvision/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/MyInvision/theme/mchat_custom.css b/styles/MyInvision/theme/mchat_custom.css
deleted file mode 100644
index 3aff2ee..0000000
--- a/styles/MyInvision/theme/mchat_custom.css
+++ /dev/null
@@ -1,12 +0,0 @@
-.mchat-wrapper .row-item {
- top: -10px;
-}
-.mchat-wrapper .header {
- padding-left: 15px;
- padding-top: 10px;
-}
-#mchat-panel {
- border-bottom: 1px solid #ccc;
- border-left: 1px solid #ccc;
- border-right: 1px solid #ccc;
-}
diff --git a/styles/MyInvision/theme/mchat_myinvision.css b/styles/MyInvision/theme/mchat_myinvision.css
new file mode 100644
index 0000000..66e4961
--- /dev/null
+++ b/styles/MyInvision/theme/mchat_myinvision.css
@@ -0,0 +1,20 @@
+/**
+ *
+ * mChat CSS for MyInvision
+ *
+ * @package phpBB Extension - mChat
+ * @copyright (c) 2017 MannixMD
+ * @copyright (c) 2018 kasimi - https://kasimi.net
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ *
+ */
+
+.mchat-status {
+ padding-bottom: 10px;
+}
+
+#mchat-panel {
+ border-bottom: 1px solid #ccc;
+ border-left: 1px solid #ccc;
+ border-right: 1px solid #ccc;
+}
diff --git a/styles/Project_Durango/template/event/overall_footer_after.html b/styles/Project_Durango/template/event/overall_footer_after.html
new file mode 100644
index 0000000..761d6e9
--- /dev/null
+++ b/styles/Project_Durango/template/event/overall_footer_after.html
@@ -0,0 +1 @@
+{% INCLUDECSS '@dmzx_mchat/mchat_projectdurango.css' %}
diff --git a/styles/Project_Durango/theme/mchat_projectdurango.css b/styles/Project_Durango/theme/mchat_projectdurango.css
new file mode 100644
index 0000000..6cc4453
--- /dev/null
+++ b/styles/Project_Durango/theme/mchat_projectdurango.css
@@ -0,0 +1,78 @@
+/**
+ *
+ * mChat CSS for Project Durango
+ *
+ * @package phpBB Extension - mChat
+ * @copyright (c) 2017 MannixMD
+ * @copyright (c) 2018 kasimi - https://kasimi.net
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ *
+ */
+
+.mchat-panel-buttons .button {
+ border-color: #3a3a3a;
+ background: #3a3a3a;
+}
+
+.mchat-panel-buttons .button:hover {
+ background: #5dc21e;
+ border-color: #5dc21e;
+}
+
+.mchat-panel-button .button .icon {
+ color: #000;
+}
+
+.mchat-panel-buttons .icon {
+ color: #5dc21e;
+}
+
+.mchat-input-control button:hover .icon {
+ color: #5dc21e;
+}
+
+ul#mchat-messages {
+ background: #c2c2c2;
+}
+
+.mchat-messages-top .row {
+ border-bottom-color: #107c10;
+ border-bottom-width: 4px;
+ border-top-width: 0;
+}
+
+.mchat-text {
+ color: #3a3a3a;
+}
+
+ul.mchat-buttons .icon {
+ color: #107c10;
+}
+
+.mchat-wrapper .mchat-buttons li {
+ opacity: .5;
+}
+
+#mchat-main {
+ border-top: 4px solid #107c10;
+}
+
+#mchat-messages li.row:hover {
+ background: #c2c2c2;
+}
+
+.mchat-message-header {
+ color: #3a3a3a;
+}
+
+.mchat-button-add .icon {
+ color: #107c10;
+}
+
+#mchat-confirm textarea {
+ color: #f1f1f1;
+}
+
+#mchat-panel {
+ background-color: #6b6b6b;
+}
diff --git a/styles/Rainbow-AOP/template/event/dmzx_mchat_messages_define_icons.html b/styles/Rainbow-AOP/template/event/dmzx_mchat_messages_define_icons.html
deleted file mode 100644
index f633ea4..0000000
--- a/styles/Rainbow-AOP/template/event/dmzx_mchat_messages_define_icons.html
+++ /dev/null
@@ -1 +0,0 @@
-{% DEFINE MCHAT_USE_WHITE_MESSAGE_ICONS = TRUE %}
diff --git a/styles/SE_Gamer/template/event/overall_footer_after.html b/styles/SE_Gamer/template/event/overall_footer_after.html
new file mode 100644
index 0000000..35a817e
--- /dev/null
+++ b/styles/SE_Gamer/template/event/overall_footer_after.html
@@ -0,0 +1 @@
+{% INCLUDECSS '@dmzx_mchat/mchat_se_gamer.css' %}
diff --git a/styles/SE_Gamer/theme/mchat_se_gamer.css b/styles/SE_Gamer/theme/mchat_se_gamer.css
new file mode 100644
index 0000000..e040767
--- /dev/null
+++ b/styles/SE_Gamer/theme/mchat_se_gamer.css
@@ -0,0 +1,16 @@
+/**
+ *
+ * mChat CSS for SE Gamer
+ *
+ * @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,
+.mchat-nav-link-title:hover,
+.mchat-nav-link,
+.mchat-nav-link:hover {
+ color: #FFFFFF;
+}
diff --git a/styles/Subway/template/event/dmzx_mchat_messages_define_icons.html b/styles/Subway/template/event/dmzx_mchat_messages_define_icons.html
deleted file mode 100644
index 80324e2..0000000
--- a/styles/Subway/template/event/dmzx_mchat_messages_define_icons.html
+++ /dev/null
@@ -1 +0,0 @@
-{% DEFINE MCHAT_USE_WHITE_MESSAGE_ICONS = SOP_SKDARK_SW | default(false) %}
diff --git a/styles/Subway/template/event/overall_header_head_append.html b/styles/Subway/template/event/overall_header_head_append.html
deleted file mode 100644
index c9c10a0..0000000
--- a/styles/Subway/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/Subway/template/mchat_navlink.html b/styles/Subway/template/mchat_navlink.html
deleted file mode 100644
index e0cc977..0000000
--- a/styles/Subway/template/mchat_navlink.html
+++ /dev/null
@@ -1 +0,0 @@
-
{% endif %}
diff --git a/styles/prosilver/template/mchat_messages_icons.html b/styles/prosilver/template/mchat_messages_icons.html
index 96b969f..f4c1c0e 100644
--- a/styles/prosilver/template/mchat_messages_icons.html
+++ b/styles/prosilver/template/mchat_messages_icons.html
@@ -10,16 +10,16 @@
{% DEFINE MCHAT_ALLOW_EDIT = mchatrow.MCHAT_ALLOW_EDIT and not mchatrow.MCHAT_IS_NOTIFICATION %}
{% DEFINE MCHAT_ALLOW_DEL = mchatrow.MCHAT_ALLOW_DEL %}
{% if definition.MCHAT_ALLOW_MENTION or definition.MCHAT_ALLOW_QUOTE or definition.MCHAT_ALLOW_LIKE or definition.MCHAT_ALLOW_PM or MCHAT_ALLOW_IP or MCHAT_ALLOW_PERMISSIONS or definition.MCHAT_ALLOW_EDIT or definition.MCHAT_ALLOW_DEL or definition.MCHAT_ADD_CUSTOM_BUTTON %}
-
+
{% EVENT dmzx_mchat_messages_icons_add_before %}
- {% if definition.MCHAT_ALLOW_MENTION %}