Version 2.0.0-RC7
This commit is contained in:
@@ -4,37 +4,50 @@
|
||||
*
|
||||
* @package phpBB Extension - mChat
|
||||
* @copyright (c) 2016 dmzx - http://www.dmzx-web.net
|
||||
* @copyright (c) 2016 kasimi
|
||||
* @copyright (c) 2016 kasimi - https://kasimi.net
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
namespace dmzx\mchat\controller;
|
||||
|
||||
use dmzx\mchat\core\functions;
|
||||
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\log\log_interface;
|
||||
use phpbb\request\request_interface;
|
||||
use phpbb\template\template;
|
||||
use phpbb\user;
|
||||
|
||||
class acp_controller
|
||||
{
|
||||
/** @var \dmzx\mchat\core\functions */
|
||||
/** @var functions */
|
||||
protected $functions;
|
||||
|
||||
/** @var \phpbb\template\template */
|
||||
/** @var template */
|
||||
protected $template;
|
||||
|
||||
/** @var \phpbb\log\log_interface */
|
||||
/** @var log_interface */
|
||||
protected $log;
|
||||
|
||||
/** @var \phpbb\user */
|
||||
/** @var user */
|
||||
protected $user;
|
||||
|
||||
/** @var \phpbb\db\driver\driver_interface */
|
||||
/** @var db_interface */
|
||||
protected $db;
|
||||
|
||||
/** @var \phpbb\cache\service */
|
||||
/** @var cache_interface */
|
||||
protected $cache;
|
||||
|
||||
/** @var \phpbb\request\request */
|
||||
/** @var request_interface */
|
||||
protected $request;
|
||||
|
||||
/** @var \dmzx\mchat\core\settings */
|
||||
/** @var dispatcher_interface */
|
||||
protected $dispatcher;
|
||||
|
||||
/** @var settings */
|
||||
protected $settings;
|
||||
|
||||
/** @var string */
|
||||
@@ -52,20 +65,34 @@ class acp_controller
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \dmzx\mchat\core\functions $functions
|
||||
* @param \phpbb\template\template $template
|
||||
* @param \phpbb\log\log_interface $log
|
||||
* @param \phpbb\user $user
|
||||
* @param \phpbb\db\driver\driver_interface $db
|
||||
* @param \phpbb\cache\service $cache
|
||||
* @param \phpbb\request\request $request
|
||||
* @param \dmzx\mchat\core\settings $settings
|
||||
* @param string $mchat_table
|
||||
* @param string $mchat_log_table
|
||||
* @param string $root_path
|
||||
* @param string $php_ext
|
||||
* @param functions $functions
|
||||
* @param template $template
|
||||
* @param log_interface $log
|
||||
* @param user $user
|
||||
* @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(\dmzx\mchat\core\functions $functions, \phpbb\template\template $template, \phpbb\log\log_interface $log, \phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, \phpbb\request\request $request, \dmzx\mchat\core\settings $settings, $mchat_table, $mchat_log_table, $root_path, $php_ext)
|
||||
public function __construct(
|
||||
functions $functions,
|
||||
template $template,
|
||||
log_interface $log,
|
||||
user $user,
|
||||
db_interface $db,
|
||||
cache_interface $cache,
|
||||
request_interface $request,
|
||||
dispatcher_interface $dispatcher,
|
||||
settings $settings,
|
||||
$mchat_table,
|
||||
$mchat_log_table,
|
||||
$root_path, $php_ext
|
||||
)
|
||||
{
|
||||
$this->functions = $functions;
|
||||
$this->template = $template;
|
||||
@@ -74,6 +101,7 @@ class acp_controller
|
||||
$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;
|
||||
@@ -98,7 +126,7 @@ class acp_controller
|
||||
{
|
||||
$mchat_new_config = array();
|
||||
$validation = array();
|
||||
foreach ($this->settings->global as $config_name => $config_data)
|
||||
foreach ($this->settings->global_settings() as $config_name => $config_data)
|
||||
{
|
||||
$default = $this->settings->cfg($config_name);
|
||||
settype($default, gettype($config_data['default']));
|
||||
@@ -113,6 +141,8 @@ class acp_controller
|
||||
if (!$is_founder)
|
||||
{
|
||||
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']);
|
||||
}
|
||||
|
||||
@@ -128,6 +158,20 @@ class acp_controller
|
||||
$error[] = 'FORM_INVALID';
|
||||
}
|
||||
|
||||
/**
|
||||
* Event to modify ACP global settings data before they are updated
|
||||
*
|
||||
* @event dmzx.mchat.acp_globalsettings_update_data
|
||||
* @var array mchat_new_config Array containing the ACP settings data that is about to be sent to the database
|
||||
* @var array error Array with error lang keys
|
||||
* @since 2.0.0-RC7
|
||||
*/
|
||||
$vars = array(
|
||||
'mchat_new_config',
|
||||
'error',
|
||||
);
|
||||
extract($this->dispatcher->trigger_event('dmzx.mchat.acp_globalsettings_update_data', compact($vars)));
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
// Set the options the user configured
|
||||
@@ -163,19 +207,36 @@ class acp_controller
|
||||
}
|
||||
}
|
||||
|
||||
foreach (array_keys($this->settings->global) as $key)
|
||||
{
|
||||
$this->template->assign_var(strtoupper($key), $this->settings->cfg($key));
|
||||
}
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
$template_data = array(
|
||||
'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')),
|
||||
'U_ACTION' => $u_action,
|
||||
));
|
||||
);
|
||||
|
||||
foreach (array_keys($this->settings->global_settings()) as $key)
|
||||
{
|
||||
$template_data[strtoupper($key)] = $this->settings->cfg($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event to modify ACP global settings template data
|
||||
*
|
||||
* @event dmzx.mchat.acp_globalsettings_modify_template_data
|
||||
* @var array template_data Array containing the template data for the ACP settings
|
||||
* @var array error Array with error lang keys
|
||||
* @since 2.0.0-RC7
|
||||
*/
|
||||
$vars = array(
|
||||
'template_data',
|
||||
'error',
|
||||
);
|
||||
extract($this->dispatcher->trigger_event('dmzx.mchat.acp_globalsettings_modify_template_data', compact($vars)));
|
||||
|
||||
$this->template->assign_vars($template_data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,15 +246,13 @@ class acp_controller
|
||||
{
|
||||
add_form_key('acp_mchat');
|
||||
|
||||
$this->user->add_lang_ext('dmzx/mchat', 'mchat_ucp');
|
||||
|
||||
$error = array();
|
||||
|
||||
if ($this->request->is_set_post('submit'))
|
||||
{
|
||||
$mchat_new_config = array();
|
||||
$validation = array();
|
||||
foreach ($this->settings->ucp as $config_name => $config_data)
|
||||
foreach ($this->settings->ucp_settings() as $config_name => $config_data)
|
||||
{
|
||||
$default = $this->settings->cfg($config_name, true);
|
||||
settype($default, gettype($config_data['default']));
|
||||
@@ -217,16 +276,36 @@ class acp_controller
|
||||
$error[] = 'FORM_INVALID';
|
||||
}
|
||||
|
||||
$mchat_new_user_config = array();
|
||||
|
||||
if ($this->request->variable('mchat_overwrite', 0) && $this->request->variable('mchat_overwrite_confirm', 0))
|
||||
{
|
||||
foreach ($mchat_new_config as $config_name => $config_value)
|
||||
{
|
||||
$mchat_new_user_config['user_' . $config_name] = $config_value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event to modify ACP global user settings data before they are updated
|
||||
*
|
||||
* @event dmzx.mchat.acp_globalusersettings_update_data
|
||||
* @var array mchat_new_config Array containing the ACP global user settings data that is about to be sent to the database
|
||||
* @var array mchat_new_user_config Array containing the user settings data when overwriting all user settings
|
||||
* @var array error Array with error lang keys
|
||||
* @since 2.0.0-RC7
|
||||
*/
|
||||
$vars = array(
|
||||
'mchat_new_config',
|
||||
'mchat_new_user_config',
|
||||
'error',
|
||||
);
|
||||
extract($this->dispatcher->trigger_event('dmzx.mchat.acp_globalusersettings_update_data', compact($vars)));
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if ($this->request->variable('mchat_overwrite', 0) && $this->request->variable('mchat_overwrite_confirm', 0))
|
||||
if ($mchat_new_user_config)
|
||||
{
|
||||
$mchat_new_user_config = array();
|
||||
foreach ($mchat_new_config as $config_name => $config_value)
|
||||
{
|
||||
$mchat_new_user_config['user_' . $config_name] = $config_value;
|
||||
}
|
||||
|
||||
$sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $mchat_new_user_config);
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
@@ -247,23 +326,59 @@ class acp_controller
|
||||
$error = array_map(array($this->user, 'lang'), $error);
|
||||
}
|
||||
|
||||
foreach (array_keys($this->settings->ucp) as $key)
|
||||
// Force global date format for $selected_date value, not user-specific
|
||||
$selected_date = $this->settings->cfg('mchat_date', true);
|
||||
$template_data = $this->settings->get_date_template_data($selected_date);
|
||||
|
||||
foreach (array_keys($this->settings->ucp_settings()) as $key)
|
||||
{
|
||||
$this->template->assign_var(strtoupper($key), $this->settings->cfg($key, true));
|
||||
$template_data[strtoupper($key)] = $this->settings->cfg($key, true);
|
||||
}
|
||||
|
||||
// Force global date format for $selected value, not user-specific
|
||||
$selected = $this->settings->cfg('mchat_date', true);
|
||||
$date_template_data = $this->settings->get_date_template_data($selected);
|
||||
$this->template->assign_vars($date_template_data);
|
||||
|
||||
$notifications_template_data = $this->settings->get_enabled_post_notifications_lang();
|
||||
$this->template->assign_var('MCHAT_POSTS_ENABLED_LANG', $notifications_template_data);
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
'MCHAT_ERROR' => implode('<br />', $error),
|
||||
'MCHAT_VERSION' => $this->settings->cfg('mchat_version'),
|
||||
'U_ACTION' => $u_action,
|
||||
$template_data = array_merge($template_data, array(
|
||||
'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
|
||||
*
|
||||
* @event dmzx.mchat.acp_globalusersettings_modify_template_data
|
||||
* @var array template_data Array containing the template data for the ACP user settings
|
||||
* @var array error Array with error lang keys
|
||||
* @since 2.0.0-RC7
|
||||
*/
|
||||
$vars = array(
|
||||
'template_data',
|
||||
'error',
|
||||
);
|
||||
extract($this->dispatcher->trigger_event('dmzx.mchat.acp_globalusersettings_modify_template_data', compact($vars)));
|
||||
|
||||
$this->template->assign_vars($template_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $selected
|
||||
* @return array
|
||||
*/
|
||||
protected function get_prune_mode_options($selected)
|
||||
{
|
||||
if (empty($this->settings->prune_modes[$selected]))
|
||||
{
|
||||
$selected = 0;
|
||||
}
|
||||
|
||||
$prune_mode_options = '';
|
||||
|
||||
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 .= '</option>';
|
||||
}
|
||||
|
||||
return $prune_mode_options;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user