From 0addbac5c0c5ad60aaa96ffc5a03049c23361db9 Mon Sep 17 00:00:00 2001
From: dmzx {MCHAT_ERROR} {{ MCHAT_ERROR }} {MCHAT_ERROR} {{ MCHAT_ERROR }}{L_MCHAT_TITLE}
+{{ lang('MCHAT_TITLE') }}
-{L_MCHAT_VERSION}{L_COLON} {MCHAT_VERSION}
+{{ lang('MCHAT_VERSION') ~ lang('COLON') }} {{ MCHAT_VERSION }}
-
+{% if MCHAT_ERROR %}
{L_WARNING}
- {{ lang('WARNING') }}
+ {L_MCHAT_TITLE}
+{{ lang('MCHAT_TITLE') }}
-{L_MCHAT_VERSION}{L_COLON} {MCHAT_VERSION}
+{{ lang('MCHAT_VERSION') ~ lang('COLON') }} {{ MCHAT_VERSION }}
-{L_WARNING}
- {{ lang('WARNING') }}
+
-
+
-
+
-
{L_MCHAT_STATS_INDEX_EXPLAIN}
{{ lang('MCHAT_STATS_INDEX_EXPLAIN') }}
-
+
-
+{% EVENT dmzx_mchat_acp_location_after %}
-
+{% EVENT dmzx_mchat_acp_message_top_before %}
-
{L_MCHAT_MESSAGE_TOP_EXPLAIN}
{{ lang('MCHAT_MESSAGE_TOP_EXPLAIN') }}
-
+
-
+
-
+
-
+
-
+
-
{L_MCHAT_PAUSE_ON_INPUT_EXPLAIN}
{{ lang('MCHAT_PAUSE_ON_INPUT_EXPLAIN') }}
-
{L_MCHAT_DATE_FORMAT_EXPLAIN}
{{ lang('MCHAT_DATE_FORMAT_EXPLAIN') }}
-
-
+{% EVENT dmzx_mchat_acp_relative_time_after %}
{L_MCHAT_RELATIVE_TIME_EXPLAIN}
{{ lang('MCHAT_RELATIVE_TIME_EXPLAIN') }}
-
+{% EVENT dmzx_mchat_acp_posts_before %}
-
+
-
+{% EVENT dmzx_mchat_acp_posts_after %}
diff --git a/adm/style/event/acp_users_prefs_append.html b/adm/style/event/acp_users_prefs_append.html
index 42b4a32..e094e7d 100644
--- a/adm/style/event/acp_users_prefs_append.html
+++ b/adm/style/event/acp_users_prefs_append.html
@@ -1,5 +1,5 @@
diff --git a/config/services.yml b/config/services.yml
index 33dd677..34fdf6c 100644
--- a/config/services.yml
+++ b/config/services.yml
@@ -67,6 +67,7 @@ services:
arguments:
- '@user'
- '@config'
+ - '@config_text'
- '@auth'
- '@dispatcher'
dmzx.mchat.acp.listener:
diff --git a/controller/acp_controller.php b/controller/acp_controller.php
index 2541600..b71ae12 100644
--- a/controller/acp_controller.php
+++ b/controller/acp_controller.php
@@ -123,11 +123,13 @@ class acp_controller
$is_founder = $this->user->data['user_type'] == USER_FOUNDER;
+ $settings = array_merge($this->settings->global_settings(), $this->settings->global_text_settings());
+
if ($this->request->is_set_post('submit'))
{
$mchat_new_config = array();
$validation = array();
- foreach ($this->settings->global_settings() as $config_name => $config_data)
+ foreach ($settings as $config_name => $config_data)
{
$default = $this->settings->cfg($config_name);
settype($default, gettype($config_data['default']));
@@ -221,7 +223,7 @@ class acp_controller
'U_ACTION' => $u_action,
);
- foreach (array_keys($this->settings->global_settings()) as $key)
+ foreach (array_keys($settings) as $key)
{
$template_data[strtoupper($key)] = $this->settings->cfg($key);
}
@@ -364,8 +366,8 @@ class acp_controller
}
/**
- * @param $selected
- * @return array
+ * @param int $selected
+ * @return string
*/
protected function get_prune_mode_options($selected)
{
diff --git a/controller/ucp_controller.php b/controller/ucp_controller.php
index eaf07f5..f1bd12c 100644
--- a/controller/ucp_controller.php
+++ b/controller/ucp_controller.php
@@ -176,6 +176,7 @@ 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,
diff --git a/core/functions.php b/core/functions.php
index c10d4c1..5995ad2 100644
--- a/core/functions.php
+++ b/core/functions.php
@@ -56,6 +56,9 @@ class functions
/** @var string */
protected $mchat_sessions_table;
+ /** @var array */
+ protected $active_users;
+
/** @var array */
public $log_types = array(
1 => 'edit',
@@ -177,10 +180,16 @@ class functions
/**
* Returns data about users who are currently chatting
*
+ * @param bool $cached Whether to return possibly cached data
* @return array
*/
- public function mchat_active_users()
+ public function mchat_active_users($cached = true)
{
+ if ($cached && $this->active_users)
+ {
+ return $this->active_users;
+ }
+
$check_time = time() - $this->mchat_session_time();
$sql_array = array(
@@ -258,6 +267,8 @@ class functions
);
extract($this->dispatcher->trigger_event('dmzx.mchat.active_users_after', compact($vars)));
+ $this->active_users = $active_users;
+
return $active_users;
}
@@ -284,7 +295,7 @@ class functions
{
$sql = 'INSERT INTO ' . $this->mchat_sessions_table . ' ' . $this->db->sql_build_array('INSERT', array(
'user_id' => (int) $this->user->data['user_id'],
- 'user_ip' => $this->user->data['user_ip'],
+ 'user_ip' => $this->user->ip,
'user_lastupdate' => time(),
));
$this->db->sql_query($sql);
@@ -349,9 +360,23 @@ class functions
$offset = 0;
}
+ /**
+ * Allow modifying SQL query before message ids to be pruned are retrieved.
+ *
+ * @event dmzx.mchat.prune_sql_before
+ * @var array user_ids Array of user IDs that are being pruned, empty when pruning via cron
+ * @var array sql_array SQL query data
+ * @since 2.0.2
+ */
+ $vars = array(
+ '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);
$result = $this->db->sql_query_limit($sql, 0, $offset);
- $rows = $this->db->sql_fetchrowset();
+ $rows = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result);
$prune_ids = array();
@@ -366,7 +391,7 @@ class functions
*
* @event dmzx.mchat.prune_before
* @var array prune_ids Array of message IDs that are about to be pruned
- * @var array user_ids Array of user IDs that are being pruned
+ * @var array user_ids Array of user IDs that are being pruned, empty when pruning via cron
* @since 2.0.0-RC6
* @changed 2.0.1 Added user_ids
*/
@@ -395,7 +420,7 @@ class functions
/**
* Returns the total number of messages
*
- * @return string
+ * @return int
*/
public function mchat_total_message_count()
{
@@ -757,7 +782,7 @@ class functions
'login' => 'mchat_posts_login',
);
- $is_mode_enabled = !empty($mode_config[$mode]) && $this->settings->cfg($mode_config[$mode]);
+ $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')
@@ -770,7 +795,7 @@ class functions
'forum_id' => (int) $forum_id,
'post_id' => (int) $post_id,
'user_id' => (int) $this->user->data['user_id'],
- 'user_ip' => $this->user->data['session_ip'],
+ 'user_ip' => $this->user->ip,
'message' => 'MCHAT_NEW_' . strtoupper($mode),
'message_time' => time(),
);
diff --git a/core/mchat.php b/core/mchat.php
index c227b70..115686f 100644
--- a/core/mchat.php
+++ b/core/mchat.php
@@ -71,9 +71,6 @@ class mchat
/** @var boolean */
protected $remove_disallowed_bbcodes = false;
- /** @var array */
- protected $active_users = null;
-
/** @var array */
protected $foes = null;
@@ -155,8 +152,6 @@ class mchat
$this->assign_bbcodes_smilies();
$this->render_page('index');
-
- $this->template->assign_var('MCHAT_IS_INDEX', true);
}
/**
@@ -189,8 +184,6 @@ class mchat
$this->assign_bbcodes_smilies();
- $this->template->assign_var('MCHAT_IS_CUSTOM_PAGE', true);
-
$this->render_page('custom');
// Add to navlinks
@@ -221,8 +214,6 @@ class mchat
throw new http_exception(403, 'MCHAT_NOACCESS_ARCHIVE');
}
- $this->template->assign_var('MCHAT_IS_ARCHIVE_PAGE', true);
-
$this->render_page('archive');
// Add to navlinks
@@ -291,7 +282,7 @@ class mchat
$lang_rules = $this->user->lang('MCHAT_RULES_MESSAGE');
- if (!$this->settings->cfg('mchat_rules') && !$lang_rules)
+ if (!$lang_rules && !$this->settings->cfg('mchat_rules'))
{
throw new http_exception(404, 'MCHAT_NO_RULES');
}
@@ -332,7 +323,7 @@ class mchat
* User submits a message
*
* @param bool $return_raw
- * @return array data sent to client as JSON
+ * @return array|JsonResponse data sent to client as JSON
*/
public function action_add($return_raw = false)
{
@@ -354,7 +345,7 @@ class mchat
$message_data = array_merge($message_data, array(
'user_id' => $this->user->data['user_id'],
- 'user_ip' => $this->user->data['session_ip'],
+ 'user_ip' => $this->user->ip,
'message_time' => time(),
));
@@ -408,7 +399,7 @@ class mchat
* User edits a message
*
* @param bool $return_raw
- * @return array data sent to client as JSON
+ * @return array|JsonResponse data sent to client as JSON
*/
public function action_edit($return_raw = false)
{
@@ -434,7 +425,7 @@ class mchat
throw new http_exception(403, 'NO_AUTH_OPERATION');
}
- $this->template->assign_var('MCHAT_IS_ARCHIVE_PAGE', $this->request->variable('archive', false));
+ $this->template->assign_var('MCHAT_PAGE', $this->request->variable('page', ''));
$message = $this->request->variable('message', '', true);
$sql_ary = $this->process_message($message);
@@ -474,7 +465,7 @@ class mchat
* User deletes a message
*
* @param bool $return_raw
- * @return array data sent to client as JSON
+ * @return array|JsonResponse data sent to client as JSON
*/
public function action_del($return_raw = false)
{
@@ -528,7 +519,7 @@ class mchat
* User checks for new messages
*
* @param bool $return_raw
- * @return array sent to client as JSON
+ * @return array|JsonResponse sent to client as JSON
*/
public function action_refresh($return_raw = false)
{
@@ -693,7 +684,7 @@ class mchat
* User requests who is chatting
*
* @param bool $return_raw
- * @return array data sent to client as JSON
+ * @return array|JsonResponse data sent to client as JSON
*/
public function action_whois($return_raw = false)
{
@@ -701,12 +692,18 @@ class mchat
$this->assign_whois();
- $response = array('whois' => $this->render_template('mchat_whois.html'));
+ $response = array('whois' => true);
- if ($this->settings->cfg('mchat_navbar_link_count') && $this->settings->cfg('mchat_navbar_link') && $this->settings->cfg('mchat_custom_page') && $this->active_users)
+ if ($this->settings->cfg('mchat_whois_index'))
{
- $response['navlink'] = $this->active_users['users_count_title'];
- $response['navlink_title'] = strip_tags($this->active_users['users_total']);
+ $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'))
+ {
+ $active_users = $this->functions->mchat_active_users();
+ $response['navlink'] = $active_users['users_count_title'];
+ $response['navlink_title'] = strip_tags($active_users['users_total']);
}
/**
@@ -749,13 +746,9 @@ class mchat
if ($navbar_link && $custom_page && $this->settings->cfg('mchat_navbar_link_count'))
{
- if ($this->active_users === null)
- {
- $this->active_users = $this->functions->mchat_active_users();
- }
-
- $template_data['MCHAT_TITLE'] = $this->active_users['users_count_title'];
- $template_data['MCHAT_TITLE_HINT'] = strip_tags($this->active_users['users_total']);
+ $active_users = $this->functions->mchat_active_users();
+ $template_data['MCHAT_TITLE'] = $active_users['users_count_title'];
+ $template_data['MCHAT_TITLE_HINT'] = strip_tags($active_users['users_total']);
}
$this->template->assign_vars($template_data);
@@ -786,6 +779,7 @@ class mchat
// 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'));
$this->template->assign_vars(array(
'MCHAT_PAGE' => $page,
@@ -803,17 +797,16 @@ class mchat
'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' => $this->settings->cfg('mchat_whois_index') || $this->settings->cfg('mchat_stats_index') ? $this->settings->cfg('mchat_whois_refresh') * 1000 : 0,
+ 'MCHAT_WHOIS_REFRESH' => $whois_refresh ? $this->settings->cfg('mchat_whois_refresh') * 1000 : 0,
'MCHAT_REFRESH_JS' => $this->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_WHOIS_REFRESH_EXPLAIN' => $this->user->lang('MCHAT_WHO_IS_REFRESH_EXPLAIN', $this->settings->cfg('mchat_whois_refresh')),
'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_STATIC_MESS' => htmlspecialchars_decode($static_message),
- 'A_MCHAT_MESS_LONG' => addslashes($this->user->lang('MCHAT_MESS_LONG', $this->settings->cfg('mchat_max_message_lngth'))),
- 'A_MCHAT_REFRESH_YES' => addslashes($this->user->lang('MCHAT_REFRESH_YES', $this->settings->cfg('mchat_refresh'))),
- 'A_COOKIE_NAME' => addslashes($this->settings->cfg('cookie_name', true) . '_'),
+ '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'),
@@ -822,15 +815,7 @@ class mchat
// The template needs some language variables if we display relative time for messages
if ($this->settings->cfg('mchat_relative_time'))
{
- $minutes_limit = $this->get_relative_minutes_limit();
- for ($i = 0; $i < $minutes_limit; $i++)
- {
- $this->template->assign_block_vars('mchattime', array(
- 'KEY' => $i,
- 'A_LANG' => addslashes($this->user->lang('MCHAT_MINUTES_AGO', $i)),
- 'IS_LAST' => $i + 1 === $minutes_limit,
- ));
- }
+ $this->template->assign_var('MCHAT_MINUTES_AGO_LIMIT', $this->get_relative_minutes_limit());
}
// Get actions which the user is allowed to perform on the current page
@@ -839,15 +824,14 @@ class mchat
'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' && ($this->settings->cfg('mchat_whois_index') || $this->settings->cfg('mchat_stats_index')),
+ 'whois' => $page !== 'archive' && $whois_refresh,
)));
- foreach ($actions as $i => $action)
+ foreach ($actions as $action)
{
$this->template->assign_block_vars('mchaturl', array(
'ACTION' => $action,
'URL' => $this->helper->route('dmzx_mchat_action_' . $action . '_controller', array(), false),
- 'IS_LAST' => $i + 1 === count($actions),
));
}
@@ -994,7 +978,7 @@ class mchat
*/
protected function display_avatars()
{
- return $this->settings->cfg('mchat_avatars') && $this->user->optionget('viewavatars') && $this->settings->cfg('mchat_avatars');
+ return $this->settings->cfg('mchat_avatars') && $this->user->optionget('viewavatars');
}
/**
@@ -1099,10 +1083,10 @@ class mchat
'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}{$this->root_path}memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $row['user_id']) : '',
+ 'U_VIEWPROFILE' => $row['user_id'] != ANONYMOUS ? append_sid("{$board_url}memberlist.{$this->php_ext}", '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}{$this->root_path}ucp.{$this->php_ext}", 'i=pm&mode=compose&mchat_pm_quote_message=' . (int) $row['message_id'] . '&u=' . $row['user_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_MESSAGE_EDIT' => $message_for_edit['text'],
'MCHAT_MESSAGE_ID' => $row['message_id'],
'MCHAT_USERNAME_FULL' => $username_full,
@@ -1110,7 +1094,7 @@ class mchat
'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}{$this->root_path}adm/index.{$this->php_ext}", 'i=permissions&mode=setting_user_global&user_id%5B0%5D=' . $row['user_id'], true, $this->user->session_id),
+ '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_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_DATETIME' => $absolute_datetime,
@@ -1152,7 +1136,7 @@ class mchat
}
/**
- * Returns true of the user is allowed to read the given message row
+ * Returns true if the user is allowed to read the given message row
*
* @param array $row
* @return bool
@@ -1355,7 +1339,7 @@ class mchat
$this->template->assign_var($option['template_var'], !$is_disallowed);
}
- $this->template->assign_var('A_MCHAT_DISALLOWED_BBCODES', addslashes($this->settings->cfg('mchat_bbcode_disallowed')));
+ $this->template->assign_var('MCHAT_DISALLOWED_BBCODES', $this->settings->cfg('mchat_bbcode_disallowed'));
if (!function_exists('display_custom_bbcodes'))
{
@@ -1472,22 +1456,19 @@ class mchat
{
if ($this->settings->cfg('mchat_whois_index') || $this->settings->cfg('mchat_stats_index'))
{
- if ($this->active_users === null)
- {
- $this->active_users = $this->functions->mchat_active_users();
- }
+ $active_users = $this->functions->mchat_active_users();
$this->template->assign_vars(array(
'MCHAT_STATS_INDEX' => $this->settings->cfg('mchat_stats_index'),
- 'MCHAT_USERS_TOTAL' => $this->active_users['users_total'],
- 'MCHAT_USERS_LIST' => $this->active_users['online_userlist'] ?: '',
- 'MCHAT_ONLINE_EXPLAIN' => $this->active_users['refresh_message'],
+ 'MCHAT_USERS_TOTAL' => $active_users['users_total'],
+ 'MCHAT_USERS_LIST' => $active_users['online_userlist'] ?: '',
+ 'MCHAT_ONLINE_EXPLAIN' => $active_users['refresh_message'],
));
}
}
/**
- * Checks whether an author has edit or delete permissions for a message
+ * Checks whether the current user has edit or delete permissions for a message written by $author_id
*
* @param string $mode One of edit|delete
* @param int $author_id The user id of the message
diff --git a/core/settings.php b/core/settings.php
index 6bfe327..1ac2eea 100644
--- a/core/settings.php
+++ b/core/settings.php
@@ -13,6 +13,7 @@ namespace dmzx\mchat\core;
use phpbb\auth\auth;
use phpbb\config\config;
+use phpbb\config\db_text;
use phpbb\event\dispatcher_interface;
use phpbb\user;
@@ -24,6 +25,9 @@ class settings
/** @var config */
protected $config;
+ /** @var db_text */
+ protected $config_text;
+
/** @var auth */
protected $auth;
@@ -38,6 +42,21 @@ class settings
*/
protected $global_settings;
+ /**
+ * Keys for global text settings that only the administrator is allowed to modify.
+ * The values are stored in the phpbb_config_text table.
+ *
+ * @var array
+ */
+ protected $global_text_settings;
+
+ /**
+ * Values for global text settings.
+ *
+ * @var array
+ */
+ protected $global_text_values;
+
/**
* Keys for user-specific settings for which the administrator can set default
* values as well as adjust permissions to allow users to customize them.
@@ -80,18 +99,21 @@ class settings
*
* @param user $user
* @param config $config
+ * @param db_text $config_text
* @param auth $auth
* @param dispatcher_interface $dispatcher
*/
public function __construct(
user $user,
config $config,
+ db_text $config_text,
auth $auth,
dispatcher_interface $dispatcher
)
{
$this->user = $user;
$this->config = $config;
+ $this->config_text = $config_text;
$this->auth = $auth;
$this->dispatcher = $dispatcher;
@@ -121,6 +143,7 @@ class settings
'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),
@@ -131,8 +154,6 @@ class settings
'mchat_prune_mode' => array('default' => 0),
'mchat_prune_num' => array('default' => 0),
'mchat_refresh' => array('default' => 10, 'validation' => array('num', false, 5, 60)),
- 'mchat_rules' => array('default' => '', 'validation' => array('string', false, 0, 255)),
- 'mchat_static_message' => array('default' => '', 'validation' => array('string', false, 0, 255)),
'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)),
);
@@ -152,6 +173,31 @@ class settings
return $global_settings;
}
+ /**
+ * @return array
+ */
+ public function initialize_global_text_settings()
+ {
+ $global_text_settings = array(
+ 'mchat_rules' => array('default' => ''),
+ 'mchat_static_message' => array('default' => ''),
+ );
+
+ /**
+ * Event to modify global text settings data
+ *
+ * @event dmzx.mchat.global_text_settings_modify
+ * @var array global_text_settings Array containing global text settings data
+ * @since 2.0.2
+ */
+ $vars = array(
+ 'global_text_settings',
+ );
+ extract($this->dispatcher->trigger_event('dmzx.mchat.global_text_settings_modify', compact($vars)));
+
+ return $global_text_settings;
+ }
+
/**
* @return array
*/
@@ -202,6 +248,46 @@ class settings
return $this->global_settings;
}
+ /**
+ * @return array
+ */
+ public function global_text_settings()
+ {
+ if (empty($this->global_text_settings))
+ {
+ $this->global_text_settings = $this->initialize_global_text_settings();
+ }
+
+ return $this->global_text_settings;
+ }
+
+ /**
+ * @return array
+ */
+ public function global_text_values()
+ {
+ if (empty($this->global_text_values))
+ {
+ $global_text_values = $this->config_text->get_array(array_keys($this->global_text_settings()));
+
+ /**
+ * Event to modify global text values
+ *
+ * @event dmzx.mchat.global_text_values_modify
+ * @var array global_text_values Array containing global text values
+ * @since 2.0.2
+ */
+ $vars = array(
+ 'global_text_values',
+ );
+ extract($this->dispatcher->trigger_event('dmzx.mchat.global_text_values_modify', compact($vars)));
+
+ $this->global_text_values = $global_text_values;
+ }
+
+ return $this->global_text_values;
+ }
+
/**
* @return array
*/
@@ -234,23 +320,48 @@ class settings
*/
public function cfg_user($config, $user_data, $auth, $force_global = false)
{
- $ucp_settings = $this->ucp_settings();
-
- if (!$force_global && isset($ucp_settings[$config]) && $auth->acl_get('u_' . $config))
+ if (!$force_global)
{
- return $user_data['user_' . $config];
+ $ucp_settings = $this->ucp_settings();
+
+ if (isset($ucp_settings[$config]) && $auth->acl_get('u_' . $config))
+ {
+ return $user_data['user_' . $config];
+ }
+ }
+
+ $global_text_settings = $this->global_text_settings();
+
+ if (isset($global_text_settings[$config]))
+ {
+ $global_text_values = $this->global_text_values();
+ return $global_text_values[$config];
}
return $this->config[$config];
}
/**
- * @param $config
- * @param $value
+ * @param string $config
+ * @param mixed $value
* @param bool $volatile
*/
public function set_cfg($config, $value, $volatile = false)
{
+ $global_text_settings = $this->global_text_settings();
+
+ if (isset($global_text_settings[$config]))
+ {
+ $this->global_text_values[$config] = $value;
+
+ if (!$volatile)
+ {
+ $this->config_text->set($config, $value);
+ }
+
+ return;
+ }
+
if ($volatile)
{
$this->config[$config] = $value;
@@ -290,7 +401,7 @@ class settings
return array(
'S_MCHAT_DATEFORMAT_OPTIONS' => $dateformat_options,
- 'A_MCHAT_DEFAULT_DATEFORMAT' => addslashes($ucp_settings['mchat_date']['default']),
+ 'MCHAT_DEFAULT_DATEFORMAT' => $ucp_settings['mchat_date']['default'],
'S_MCHAT_CUSTOM_DATEFORMAT' => $s_custom,
);
}
diff --git a/event/acp_listener.php b/event/acp_listener.php
index 2872906..416952d 100644
--- a/event/acp_listener.php
+++ b/event/acp_listener.php
@@ -187,7 +187,7 @@ class acp_listener implements EventSubscriberInterface
{
$this->user->add_lang_ext('dmzx/mchat', array('mchat_acp', 'mchat_ucp'));
- $user_id = $event['user_row']['user_id'];
+ $user_id = (int) $event['user_row']['user_id'];
$auth = new auth();
$userdata = $auth->obtain_user_data($user_id);
diff --git a/event/main_listener.php b/event/main_listener.php
index 7b912b0..0cb7a22 100644
--- a/event/main_listener.php
+++ b/event/main_listener.php
@@ -13,9 +13,9 @@ namespace dmzx\mchat\event;
use dmzx\mchat\core\mchat;
use phpbb\controller\helper;
+use phpbb\event\data;
use phpbb\request\request_interface;
use phpbb\user;
-use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class main_listener implements EventSubscriberInterface
@@ -78,7 +78,7 @@ class main_listener implements EventSubscriberInterface
}
/**
- * @param Event $event
+ * @param data $event
*/
public function add_page_viewonline($event)
{
@@ -90,7 +90,7 @@ class main_listener implements EventSubscriberInterface
}
/**
- * @param Event $event
+ * @param data $event
*/
public function load_language_on_setup($event)
{
@@ -104,26 +104,22 @@ class main_listener implements EventSubscriberInterface
/**
* Create a URL to the mchat controller file for the header linklist
- *
- * @param Event $event
*/
- public function add_page_header_link($event)
+ public function add_page_header_link()
{
$this->mchat->render_page_header_link();
}
/**
* Check if mchat should be displayed on index.
- *
- * @param Event $event
*/
- public function display_mchat_on_index($event)
+ public function display_mchat_on_index()
{
$this->mchat->page_index();
}
/**
- * @param Event $event
+ * @param data $event
*/
public function insert_posting($event)
{
@@ -131,7 +127,7 @@ class main_listener implements EventSubscriberInterface
}
/**
- * @param Event $event
+ * @param data $event
*/
public function remove_disallowed_bbcodes($event)
{
@@ -139,7 +135,7 @@ class main_listener implements EventSubscriberInterface
}
/**
- * @param Event $event
+ * @param data $event
*/
public function user_registration_set_default_values($event)
{
@@ -147,7 +143,7 @@ class main_listener implements EventSubscriberInterface
}
/**
- * @param Event $event
+ * @param data $event
*/
public function user_login_success($event)
{
@@ -158,9 +154,9 @@ class main_listener implements EventSubscriberInterface
}
/**
- * @param Event $event
+ *
*/
- public function pm_compose_add_quote($event)
+ public function pm_compose_add_quote()
{
$mchat_message_id = $this->request->variable('mchat_pm_quote_message', 0);
@@ -171,9 +167,9 @@ class main_listener implements EventSubscriberInterface
}
/**
- * @param Event $event
+ *
*/
- public function session_gc($event)
+ public function session_gc()
{
$this->mchat->session_gc();
}
diff --git a/ext.php b/ext.php
index 99c1f06..b119af6 100644
--- a/ext.php
+++ b/ext.php
@@ -52,7 +52,7 @@ class ext extends \phpbb\extension\base
}
$php_ext = $this->container->getParameter('core.php_ext');
- $error_msg = $lang->lang('MCHAT_30X_REMNANTS', $table_prefix, implode(', ', $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);
}
@@ -65,7 +65,7 @@ class ext extends \phpbb\extension\base
* This method checks whether the phpbb_modules table contains remnants of the 3.0 MOD.
* It returns an array of the modules' IDs, or an empty array if no old modules are found.
*
- * @var string $table_prefix
+ * @param string $table_prefix
* @return array
*/
protected function get_old_module_ids($table_prefix)
@@ -84,7 +84,7 @@ class ext extends \phpbb\extension\base
FROM ' . $table_prefix . 'modules
WHERE ' . $db->sql_in_set('module_langname', $mchat_30x_module_langnames);
$result = $db->sql_query($sql);
- $rows = $db->sql_fetchrowset();
+ $rows = $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
$module_ids = array();
diff --git a/language/en/info_acp_mchat.php b/language/en/info_acp_mchat.php
index 8a4d407..2a6da30 100644
--- a/language/en/info_acp_mchat.php
+++ b/language/en/info_acp_mchat.php
@@ -43,7 +43,7 @@ $lang = array_merge($lang, array(
// Log entries (%1$s is replaced with the user name who triggered the event)
'LOG_MCHAT_CONFIG_UPDATE' => 'mChat configuration updated
» %1$s',
- 'LOG_MCHAT_TABLE_PRUNED' => 'mChat messages pruned: %2$d
» %1$s',
+ 'LOG_MCHAT_TABLE_PRUNED' => 'mChat messages pruned: %2$d',
'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/mchat_acp.php b/language/en/mchat_acp.php
index f718135..7fb5514 100644
--- a/language/en/mchat_acp.php
+++ b/language/en/mchat_acp.php
@@ -92,8 +92,8 @@ $lang = array_merge($lang, array(
'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_ARCHIVE_SORT' => 'Message sorting',
- 'MCHAT_ARCHIVE_SORT_TOP_BOTTOM' => 'Always sort messages top to bottom',
- 'MCHAT_ARCHIVE_SORT_BOTTOM_TOP' => 'Always sort messages bottom to top',
+ '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.',
@@ -115,6 +115,9 @@ $lang = array_merge($lang, array(
'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_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.',
+
'MCHAT_WHOIS_REFRESH' => 'Who is chatting refresh interval',
'MCHAT_WHOIS_REFRESH_EXPLAIN' => 'Number of seconds before who is chatting refreshes.
You are limited from 10 to 300 seconds. Default is 60.',
'MCHAT_SOUND' => 'Play sounds for new, edited and deleted messages',
diff --git a/migrations/mchat_2_0_2.php b/migrations/mchat_2_0_2.php
new file mode 100644
index 0000000..467733a
--- /dev/null
+++ b/migrations/mchat_2_0_2.php
@@ -0,0 +1,39 @@
+config['mchat_rules'])),
+ array('config_text.add', array('mchat_static_message', $this->config['mchat_static_message'])),
+
+ array('config.remove', array('mchat_rules')),
+ array('config.remove', array('mchat_static_message')),
+ );
+ }
+}
diff --git a/styles/360Elite/template/event/dmzx_mchat_messages_define_icons.html b/styles/360Elite/template/event/dmzx_mchat_messages_define_icons.html
index 4be4b10..f633ea4 100644
--- a/styles/360Elite/template/event/dmzx_mchat_messages_define_icons.html
+++ b/styles/360Elite/template/event/dmzx_mchat_messages_define_icons.html
@@ -1 +1 @@
-
+{% DEFINE MCHAT_USE_WHITE_MESSAGE_ICONS = TRUE %}
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
index 4be4b10..f633ea4 100644
--- a/styles/Black_Star/template/event/dmzx_mchat_messages_define_icons.html
+++ b/styles/Black_Star/template/event/dmzx_mchat_messages_define_icons.html
@@ -1 +1 @@
-
+{% 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
index 4be4b10..f633ea4 100644
--- a/styles/Blue-Night/template/event/dmzx_mchat_messages_define_icons.html
+++ b/styles/Blue-Night/template/event/dmzx_mchat_messages_define_icons.html
@@ -1 +1 @@
-
+{% 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
index 4be4b10..f633ea4 100644
--- a/styles/Brown/template/event/dmzx_mchat_messages_define_icons.html
+++ b/styles/Brown/template/event/dmzx_mchat_messages_define_icons.html
@@ -1 +1 @@
-
+{% DEFINE MCHAT_USE_WHITE_MESSAGE_ICONS = TRUE %}
diff --git a/styles/Cynthia/template/event/dmzx_mchat_messages_define_icons.html b/styles/Cynthia/template/event/dmzx_mchat_messages_define_icons.html
index 4be4b10..f633ea4 100644
--- a/styles/Cynthia/template/event/dmzx_mchat_messages_define_icons.html
+++ b/styles/Cynthia/template/event/dmzx_mchat_messages_define_icons.html
@@ -1 +1 @@
-
+{% 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
index 4be4b10..f633ea4 100644
--- a/styles/DVGFX/template/event/dmzx_mchat_messages_define_icons.html
+++ b/styles/DVGFX/template/event/dmzx_mchat_messages_define_icons.html
@@ -1 +1 @@
-
+{% 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
new file mode 100644
index 0000000..c9c10a0
--- /dev/null
+++ b/styles/Hexagon/template/event/overall_header_head_append.html
@@ -0,0 +1,2 @@
+{% 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
new file mode 100644
index 0000000000000000000000000000000000000000..c7cce975e8b4b67e2fa8b74d0b2553710cf84cf4
GIT binary patch
literal 528
zcmV+r0`L8aP){L_MCHAT_ARCHIVE_PAGE}{L_MCHAT_TITLE}{L_MCHAT_TITLE}
+
+ {% if MCHAT_PAGE == 'archive' %}
+ {{ lang('MCHAT_ARCHIVE_PAGE') }}
+ {% elseif MCHAT_CUSTOM_PAGE %}
+ {{ lang('MCHAT_TITLE') }}
+ {% else %}
+ {{ lang('MCHAT_TITLE') }}
+ {% endif %}
+
{L_MCHAT_ARCHIVE_PAGE}{L_MCHAT_TITLE}{L_MCHAT_TITLE}
+
+ {% if MCHAT_PAGE == 'archive' %}
+ {{ lang('MCHAT_ARCHIVE_PAGE') }}
+ {% elseif MCHAT_CUSTOM_PAGE %}
+ {{ lang('MCHAT_TITLE') }}
+ {% else %}
+ {{ lang('MCHAT_TITLE') }}
+ {% endif %}
+
{MCHAT_USERS_TOTAL} {MCHAT_ONLINE_EXPLAIN}
{MCHAT_USERS_LIST}
-
+
{{ MCHAT_USERS_TOTAL }} {{ MCHAT_ONLINE_EXPLAIN }}
{{ MCHAT_USERS_LIST }}
+{% endif %}
diff --git a/styles/prosilver/template/event/index_body_forumlist_body_after.html b/styles/prosilver/template/event/index_body_forumlist_body_after.html
index 09b7e33..9385188 100644
--- a/styles/prosilver/template/event/index_body_forumlist_body_after.html
+++ b/styles/prosilver/template/event/index_body_forumlist_body_after.html
@@ -1,3 +1,3 @@
-
-
-
+{% if MCHAT_INDEX and not MCHAT_LOCATION %}
+ {% INCLUDE '@dmzx_mchat/mchat_body.html' %}
+{% endif %}
diff --git a/styles/prosilver/template/event/index_body_markforums_before.html b/styles/prosilver/template/event/index_body_markforums_before.html
index 90d820d..4c94f7b 100644
--- a/styles/prosilver/template/event/index_body_markforums_before.html
+++ b/styles/prosilver/template/event/index_body_markforums_before.html
@@ -1,3 +1,3 @@
-
-
-
+{% if MCHAT_INDEX and MCHAT_LOCATION %}
+ {% INCLUDE '@dmzx_mchat/mchat_body.html' %}
+{% endif %}
diff --git a/styles/prosilver/template/event/overall_footer_copyright_append.html b/styles/prosilver/template/event/overall_footer_copyright_append.html
index a91abfc..278d9be 100644
--- a/styles/prosilver/template/event/overall_footer_copyright_append.html
+++ b/styles/prosilver/template/event/overall_footer_copyright_append.html
@@ -1,4 +1,4 @@
-
+{% if MCHAT_PAGE %}
- {MCHAT_DISPLAY_NAME} © {L_POST_BY_AUTHOR} {MCHAT_AUTHOR_HOMEPAGES}
-
+ {{ MCHAT_DISPLAY_NAME }} © {{ lang('POST_BY_AUTHOR') }} {{ MCHAT_AUTHOR_HOMEPAGES }}
+{% endif %}
diff --git a/styles/prosilver/template/event/overall_header_head_append.html b/styles/prosilver/template/event/overall_header_head_append.html
index 5615e3c..4698c71 100644
--- a/styles/prosilver/template/event/overall_header_head_append.html
+++ b/styles/prosilver/template/event/overall_header_head_append.html
@@ -1 +1 @@
-
+{% INCLUDECSS '@dmzx_mchat/mchat.css' %}
diff --git a/styles/prosilver/template/event/overall_header_navigation_append.html b/styles/prosilver/template/event/overall_header_navigation_append.html
index 555b165..c2a66ec 100644
--- a/styles/prosilver/template/event/overall_header_navigation_append.html
+++ b/styles/prosilver/template/event/overall_header_navigation_append.html
@@ -1,3 +1,3 @@
-
-
-
+{% if MCHAT_CUSTOM_PAGE and MCHAT_NAVBAR_LINK %}
+ {% INCLUDE '@dmzx_mchat/mchat_navlink.html' %}
+{% endif %}
diff --git a/styles/prosilver/template/event/overall_header_stylesheets_after.html b/styles/prosilver/template/event/overall_header_stylesheets_after.html
index fc6000b..578df19 100644
--- a/styles/prosilver/template/event/overall_header_stylesheets_after.html
+++ b/styles/prosilver/template/event/overall_header_stylesheets_after.html
@@ -1,7 +1,7 @@
-
+{% if (MCHAT_CUSTOM_HEIGHT or MCHAT_INDEX_HEIGHT) and MCHAT_PAGE != 'archive' %}
-
+{% endif %}
diff --git a/styles/prosilver/template/mchat_body.html b/styles/prosilver/template/mchat_body.html
index e850ffe..267e567 100644
--- a/styles/prosilver/template/mchat_body.html
+++ b/styles/prosilver/template/mchat_body.html
@@ -1,142 +1,142 @@
-
-
-
+{% if MCHAT_PAGE in ['custom', 'archive'] %}
+ {% INCLUDE 'overall_header.html' %}
+{% endif %}
-
+{% EVENT dmzx_mchat_overall_header_after %}
-
+{% EVENT dmzx_mchat_header_before %}
-
-