Version 2.1.0
This commit is contained in:
@@ -16,6 +16,7 @@ use dmzx\mchat\core\settings;
|
||||
use phpbb\cache\driver\driver_interface as cache_interface;
|
||||
use phpbb\db\driver\driver_interface as db_interface;
|
||||
use phpbb\event\dispatcher_interface;
|
||||
use phpbb\language\language;
|
||||
use phpbb\log\log_interface;
|
||||
use phpbb\request\request_interface;
|
||||
use phpbb\template\template;
|
||||
@@ -24,7 +25,7 @@ use phpbb\user;
|
||||
class acp_controller
|
||||
{
|
||||
/** @var functions */
|
||||
protected $functions;
|
||||
protected $mchat_functions;
|
||||
|
||||
/** @var template */
|
||||
protected $template;
|
||||
@@ -35,6 +36,9 @@ class acp_controller
|
||||
/** @var user */
|
||||
protected $user;
|
||||
|
||||
/** @var language */
|
||||
protected $lang;
|
||||
|
||||
/** @var db_interface */
|
||||
protected $db;
|
||||
|
||||
@@ -50,64 +54,43 @@ class acp_controller
|
||||
/** @var settings */
|
||||
protected $settings;
|
||||
|
||||
/** @var string */
|
||||
protected $mchat_table;
|
||||
|
||||
/** @var string */
|
||||
protected $mchat_log_table;
|
||||
|
||||
/** @var string */
|
||||
protected $root_path;
|
||||
|
||||
/** @var string */
|
||||
protected $php_ext;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param functions $functions
|
||||
* @param functions $mchat_functions
|
||||
* @param template $template
|
||||
* @param log_interface $log
|
||||
* @param user $user
|
||||
* @param language $lang
|
||||
* @param db_interface $db
|
||||
* @param cache_interface $cache
|
||||
* @param request_interface $request
|
||||
* @param dispatcher_interface $dispatcher
|
||||
* @param settings $settings
|
||||
* @param string $mchat_table
|
||||
* @param string $mchat_log_table
|
||||
* @param string $root_path
|
||||
* @param string $php_ext
|
||||
*/
|
||||
public function __construct(
|
||||
functions $functions,
|
||||
functions $mchat_functions,
|
||||
template $template,
|
||||
log_interface $log,
|
||||
user $user,
|
||||
language $lang,
|
||||
db_interface $db,
|
||||
cache_interface $cache,
|
||||
request_interface $request,
|
||||
dispatcher_interface $dispatcher,
|
||||
settings $settings,
|
||||
$mchat_table,
|
||||
$mchat_log_table,
|
||||
$root_path,
|
||||
$php_ext
|
||||
settings $settings
|
||||
)
|
||||
{
|
||||
$this->functions = $functions;
|
||||
$this->mchat_functions = $mchat_functions;
|
||||
$this->template = $template;
|
||||
$this->log = $log;
|
||||
$this->user = $user;
|
||||
$this->lang = $lang;
|
||||
$this->db = $db;
|
||||
$this->cache = $cache;
|
||||
$this->request = $request;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->settings = $settings;
|
||||
$this->mchat_table = $mchat_table;
|
||||
$this->mchat_log_table = $mchat_log_table;
|
||||
$this->root_path = $root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +102,7 @@ class acp_controller
|
||||
{
|
||||
add_form_key('acp_mchat');
|
||||
|
||||
$error = array();
|
||||
$error = [];
|
||||
|
||||
$is_founder = $this->user->data['user_type'] == USER_FOUNDER;
|
||||
|
||||
@@ -127,8 +110,8 @@ class acp_controller
|
||||
|
||||
if ($this->request->is_set_post('submit'))
|
||||
{
|
||||
$mchat_new_config = array();
|
||||
$validation = array();
|
||||
$mchat_new_config = [];
|
||||
$validation = [];
|
||||
foreach ($settings as $config_name => $config_data)
|
||||
{
|
||||
$default = $this->settings->cfg($config_name);
|
||||
@@ -143,19 +126,19 @@ class acp_controller
|
||||
// Remove leading & trailing | characters to not break allowed BBCodes
|
||||
$mchat_new_config['mchat_bbcode_disallowed'] = trim($mchat_new_config['mchat_bbcode_disallowed'], '|');
|
||||
|
||||
// Don't allow changing pruning settings for non founders
|
||||
if (!$is_founder)
|
||||
{
|
||||
// Don't allow changing pruning settings for non founders
|
||||
unset($mchat_new_config['mchat_prune']);
|
||||
unset($mchat_new_config['mchat_prune_gc']);
|
||||
unset($mchat_new_config['mchat_prune_mode']);
|
||||
unset($mchat_new_config['mchat_prune_num']);
|
||||
|
||||
// Don't allow changing log settings for non founders
|
||||
unset($mchat_new_config['mchat_log_enabled']);
|
||||
}
|
||||
|
||||
if (!function_exists('validate_data'))
|
||||
{
|
||||
include($this->root_path . 'includes/functions_user.' . $this->php_ext);
|
||||
}
|
||||
$this->settings->include_functions('user', 'validate_data');
|
||||
|
||||
$error = array_merge($error, validate_data($mchat_new_config, $validation));
|
||||
|
||||
@@ -172,10 +155,10 @@ class acp_controller
|
||||
* @var array error Array with error lang keys
|
||||
* @since 2.0.0-RC7
|
||||
*/
|
||||
$vars = array(
|
||||
$vars = [
|
||||
'mchat_new_config',
|
||||
'error',
|
||||
);
|
||||
];
|
||||
extract($this->dispatcher->trigger_event('dmzx.mchat.acp_globalsettings_update_data', compact($vars)));
|
||||
|
||||
if (!$error)
|
||||
@@ -187,41 +170,50 @@ class acp_controller
|
||||
}
|
||||
|
||||
// Add an entry into the log table
|
||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_CONFIG_UPDATE', false, array($this->user->data['username']));
|
||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_CONFIG_UPDATE', false, [$this->user->data['username']]);
|
||||
|
||||
trigger_error($this->user->lang('MCHAT_CONFIG_SAVED') . adm_back_link($u_action));
|
||||
trigger_error($this->lang->lang('MCHAT_CONFIG_SAVED') . adm_back_link($u_action));
|
||||
}
|
||||
|
||||
// Replace "error" strings with their real, localised form
|
||||
$error = array_map(array($this->user, 'lang'), $error);
|
||||
$error = array_map([$this->lang, 'lang'], $error);
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if ($is_founder && $this->request->is_set_post('mchat_purge') && $this->request->variable('mchat_purge_confirm', false) && check_form_key('acp_mchat'))
|
||||
{
|
||||
$this->db->sql_query('DELETE FROM ' . $this->mchat_table);
|
||||
$this->db->sql_query('DELETE FROM ' . $this->mchat_log_table);
|
||||
$this->cache->destroy('sql', $this->mchat_log_table);
|
||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PURGED', false, array($this->user->data['username']));
|
||||
trigger_error($this->user->lang('MCHAT_PURGED') . adm_back_link($u_action));
|
||||
/**
|
||||
* Event that is triggered right before all mChat messages are
|
||||
* deleted when using the Delete all messages button in the ACP
|
||||
*
|
||||
* @event dmzx.mchat.purge_before
|
||||
* @since 2.1.0-RC1
|
||||
*/
|
||||
$this->dispatcher->dispatch('dmzx.mchat.purge_before');
|
||||
|
||||
$this->db->sql_query('DELETE FROM ' . $this->settings->get_table_mchat());
|
||||
$this->db->sql_query('DELETE FROM ' . $this->settings->get_table_mchat_log());
|
||||
$this->cache->destroy('sql', $this->settings->get_table_mchat_log());
|
||||
$this->mchat_functions->phpbb_log('LOG_MCHAT_TABLE_PURGED');
|
||||
trigger_error($this->lang->lang('MCHAT_PURGED') . adm_back_link($u_action));
|
||||
}
|
||||
else if ($is_founder && $this->request->is_set_post('mchat_prune_now') && $this->request->variable('mchat_prune_now_confirm', false) && check_form_key('acp_mchat'))
|
||||
{
|
||||
$num_pruned_messages = count($this->functions->mchat_prune());
|
||||
trigger_error($this->user->lang('MCHAT_PRUNED', $num_pruned_messages) . adm_back_link($u_action));
|
||||
$num_pruned_messages = count($this->mchat_functions->mchat_prune());
|
||||
trigger_error($this->lang->lang('MCHAT_PRUNED', $num_pruned_messages) . adm_back_link($u_action));
|
||||
}
|
||||
}
|
||||
|
||||
$template_data = array(
|
||||
$template_data = [
|
||||
'MCHAT_ERROR' => implode('<br>', $error),
|
||||
'MCHAT_VERSION' => $this->settings->cfg('mchat_version'),
|
||||
'MCHAT_FOUNDER' => $is_founder,
|
||||
'S_MCHAT_PRUNE_MODE_OPTIONS' => $this->get_prune_mode_options($this->settings->cfg('mchat_prune_mode')),
|
||||
'L_MCHAT_BBCODES_DISALLOWED_EXPLAIN' => $this->user->lang('MCHAT_BBCODES_DISALLOWED_EXPLAIN', '<a href="' . append_sid("{$this->root_path}adm/index.$this->php_ext", 'i=bbcodes', true, $this->user->session_id) . '">', '</a>'),
|
||||
'L_MCHAT_TIMEOUT_EXPLAIN' => $this->user->lang('MCHAT_TIMEOUT_EXPLAIN','<a href="' . append_sid("{$this->root_path}adm/index.$this->php_ext", 'i=board&mode=load', true, $this->user->session_id) . '">', '</a>', $this->settings->cfg('session_length')),
|
||||
'L_MCHAT_BBCODES_DISALLOWED_EXPLAIN' => $this->lang->lang('MCHAT_BBCODES_DISALLOWED_EXPLAIN', '<a href="' . append_sid($this->settings->url('adm/index'), ['i' => 'bbcodes']) . '">', '</a>'),
|
||||
'L_MCHAT_TIMEOUT_EXPLAIN' => $this->lang->lang('MCHAT_TIMEOUT_EXPLAIN','<a href="' . append_sid($this->settings->url('adm/index'), ['i' => 'board', 'mode' => 'load']) . '">', '</a>', $this->settings->cfg('session_length')),
|
||||
'U_ACTION' => $u_action,
|
||||
);
|
||||
];
|
||||
|
||||
foreach (array_keys($settings) as $key)
|
||||
{
|
||||
@@ -236,10 +228,10 @@ class acp_controller
|
||||
* @var array error Array with error lang keys
|
||||
* @since 2.0.0-RC7
|
||||
*/
|
||||
$vars = array(
|
||||
$vars = [
|
||||
'template_data',
|
||||
'error',
|
||||
);
|
||||
];
|
||||
extract($this->dispatcher->trigger_event('dmzx.mchat.acp_globalsettings_modify_template_data', compact($vars)));
|
||||
|
||||
$this->template->assign_vars($template_data);
|
||||
@@ -252,12 +244,12 @@ class acp_controller
|
||||
{
|
||||
add_form_key('acp_mchat');
|
||||
|
||||
$error = array();
|
||||
$error = [];
|
||||
|
||||
if ($this->request->is_set_post('submit'))
|
||||
{
|
||||
$mchat_new_config = array();
|
||||
$validation = array();
|
||||
$mchat_new_config = [];
|
||||
$validation = [];
|
||||
foreach ($this->settings->ucp_settings() as $config_name => $config_data)
|
||||
{
|
||||
$default = $this->settings->cfg($config_name, true);
|
||||
@@ -270,10 +262,7 @@ class acp_controller
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('validate_data'))
|
||||
{
|
||||
include($this->root_path . 'includes/functions_user.' . $this->php_ext);
|
||||
}
|
||||
$this->settings->include_functions('user', 'validate_data');
|
||||
|
||||
$error = array_merge($error, validate_data($mchat_new_config, $validation));
|
||||
|
||||
@@ -282,7 +271,7 @@ class acp_controller
|
||||
$error[] = 'FORM_INVALID';
|
||||
}
|
||||
|
||||
$mchat_new_user_config = array();
|
||||
$mchat_new_user_config = [];
|
||||
|
||||
if ($this->request->variable('mchat_overwrite', 0) && $this->request->variable('mchat_overwrite_confirm', 0))
|
||||
{
|
||||
@@ -301,11 +290,11 @@ class acp_controller
|
||||
* @var array error Array with error lang keys
|
||||
* @since 2.0.0-RC7
|
||||
*/
|
||||
$vars = array(
|
||||
$vars = [
|
||||
'mchat_new_config',
|
||||
'mchat_new_user_config',
|
||||
'error',
|
||||
);
|
||||
];
|
||||
extract($this->dispatcher->trigger_event('dmzx.mchat.acp_globalusersettings_update_data', compact($vars)));
|
||||
|
||||
if (!$error)
|
||||
@@ -323,13 +312,13 @@ class acp_controller
|
||||
}
|
||||
|
||||
// Add an entry into the log table
|
||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_CONFIG_UPDATE', false, array($this->user->data['username']));
|
||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_CONFIG_UPDATE', false, [$this->user->data['username']]);
|
||||
|
||||
trigger_error($this->user->lang('MCHAT_CONFIG_SAVED') . adm_back_link($u_action));
|
||||
trigger_error($this->lang->lang('MCHAT_CONFIG_SAVED') . adm_back_link($u_action));
|
||||
}
|
||||
|
||||
// Replace "error" strings with their real, localised form
|
||||
$error = array_map(array($this->user, 'lang'), $error);
|
||||
$error = array_map([$this->lang, 'lang'], $error);
|
||||
}
|
||||
|
||||
// Force global date format for $selected_date value, not user-specific
|
||||
@@ -341,12 +330,12 @@ class acp_controller
|
||||
$template_data[strtoupper($key)] = $this->settings->cfg($key, true);
|
||||
}
|
||||
|
||||
$template_data = array_merge($template_data, array(
|
||||
$template_data = array_merge($template_data, [
|
||||
'MCHAT_POSTS_ENABLED_LANG' => $this->settings->get_enabled_post_notifications_lang(),
|
||||
'MCHAT_ERROR' => implode('<br>', $error),
|
||||
'MCHAT_VERSION' => $this->settings->cfg('mchat_version'),
|
||||
'U_ACTION' => $u_action,
|
||||
));
|
||||
]);
|
||||
|
||||
/**
|
||||
* Event to modify ACP global user settings template data
|
||||
@@ -356,10 +345,10 @@ class acp_controller
|
||||
* @var array error Array with error lang keys
|
||||
* @since 2.0.0-RC7
|
||||
*/
|
||||
$vars = array(
|
||||
$vars = [
|
||||
'template_data',
|
||||
'error',
|
||||
);
|
||||
];
|
||||
extract($this->dispatcher->trigger_event('dmzx.mchat.acp_globalusersettings_modify_template_data', compact($vars)));
|
||||
|
||||
$this->template->assign_vars($template_data);
|
||||
@@ -381,7 +370,7 @@ class acp_controller
|
||||
foreach ($this->settings->prune_modes as $i => $prune_mode)
|
||||
{
|
||||
$prune_mode_options .= '<option value="' . $i . '"' . (($i == $selected) ? ' selected="selected"' : '') . '>';
|
||||
$prune_mode_options .= $this->user->lang('MCHAT_ACP_' . strtoupper($prune_mode));
|
||||
$prune_mode_options .= $this->lang->lang('MCHAT_ACP_' . strtoupper($prune_mode));
|
||||
$prune_mode_options .= '</option>';
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ use dmzx\mchat\core\settings;
|
||||
use phpbb\auth\auth;
|
||||
use phpbb\db\driver\driver_interface as db_interface;
|
||||
use phpbb\event\dispatcher_interface;
|
||||
use phpbb\language\language;
|
||||
use phpbb\request\request_interface;
|
||||
use phpbb\template\template;
|
||||
use phpbb\user;
|
||||
@@ -27,6 +28,9 @@ class ucp_controller
|
||||
/** @var user */
|
||||
protected $user;
|
||||
|
||||
/** @var language */
|
||||
protected $lang;
|
||||
|
||||
/** @var auth */
|
||||
protected $auth;
|
||||
|
||||
@@ -37,51 +41,42 @@ class ucp_controller
|
||||
protected $request;
|
||||
|
||||
/** @var settings */
|
||||
protected $settings;
|
||||
protected $mchat_settings;
|
||||
|
||||
/** @var dispatcher_interface */
|
||||
protected $dispatcher;
|
||||
|
||||
/** @var string */
|
||||
protected $root_path;
|
||||
|
||||
/** @var string */
|
||||
protected $php_ext;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param template $template
|
||||
* @param user $user
|
||||
* @param language $lang
|
||||
* @param auth $auth
|
||||
* @param db_interface $db
|
||||
* @param request_interface $request
|
||||
* @param settings $settings
|
||||
* @param settings $mchat_settings
|
||||
* @param dispatcher_interface $dispatcher
|
||||
* @param string $root_path
|
||||
* @param string $php_ext
|
||||
*/
|
||||
public function __construct(
|
||||
template $template,
|
||||
user $user,
|
||||
language $lang,
|
||||
auth $auth,
|
||||
db_interface $db,
|
||||
request_interface $request,
|
||||
settings $settings,
|
||||
dispatcher_interface $dispatcher,
|
||||
$root_path,
|
||||
$php_ext
|
||||
settings $mchat_settings,
|
||||
dispatcher_interface $dispatcher
|
||||
)
|
||||
{
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
$this->auth = $auth;
|
||||
$this->db = $db;
|
||||
$this->request = $request;
|
||||
$this->settings = $settings;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->root_path = $root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
$this->lang = $lang;
|
||||
$this->auth = $auth;
|
||||
$this->db = $db;
|
||||
$this->request = $request;
|
||||
$this->mchat_settings = $mchat_settings;
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,13 +88,13 @@ class ucp_controller
|
||||
{
|
||||
add_form_key('ucp_mchat');
|
||||
|
||||
$error = array();
|
||||
$error = [];
|
||||
|
||||
if ($this->request->is_set_post('submit'))
|
||||
{
|
||||
$mchat_new_config = array();
|
||||
$validation = array();
|
||||
foreach ($this->settings->ucp_settings() as $config_name => $config_data)
|
||||
$mchat_new_config = [];
|
||||
$validation = [];
|
||||
foreach ($this->mchat_settings->ucp_settings() as $config_name => $config_data)
|
||||
{
|
||||
if ($this->auth->acl_get('u_' . $config_name))
|
||||
{
|
||||
@@ -114,10 +109,7 @@ class ucp_controller
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('validate_data'))
|
||||
{
|
||||
include($this->root_path . 'includes/functions_user.' . $this->php_ext);
|
||||
}
|
||||
$this->mchat_settings->include_functions('user', 'validate_data');
|
||||
|
||||
$error = array_merge($error, validate_data($mchat_new_config, $validation));
|
||||
|
||||
@@ -134,10 +126,10 @@ class ucp_controller
|
||||
* @var array error Array with error lang keys
|
||||
* @since 2.0.0-RC7
|
||||
*/
|
||||
$vars = array(
|
||||
$vars = [
|
||||
'mchat_new_config',
|
||||
'error',
|
||||
);
|
||||
];
|
||||
extract($this->dispatcher->trigger_event('dmzx.mchat.ucp_update_data', compact($vars)));
|
||||
|
||||
if (!$error)
|
||||
@@ -148,25 +140,25 @@ class ucp_controller
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
meta_refresh(3, $u_action);
|
||||
$message = $this->user->lang('PROFILE_UPDATED') . '<br><br>' . $this->user->lang('RETURN_UCP', '<a href="' . $u_action . '">', '</a>');
|
||||
$message = $this->lang->lang('PROFILE_UPDATED') . '<br><br>' . $this->lang->lang('RETURN_UCP', '<a href="' . $u_action . '">', '</a>');
|
||||
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('<br>', $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('<br>', $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);
|
||||
|
||||
Reference in New Issue
Block a user