Version 2.0.0-RC3

This commit is contained in:
dmzx
2016-03-26 09:15:07 +01:00
parent e6c96ec8f0
commit 5f8c5d3f09
84 changed files with 2046 additions and 1300 deletions

View File

@@ -13,9 +13,6 @@ namespace dmzx\mchat\controller;
class acp_controller
{
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\template\template */
protected $template;
@@ -34,6 +31,9 @@ class acp_controller
/** @var \phpbb\request\request */
protected $request;
/** @var \dmzx\mchat\core\settings */
protected $settings;
/** @var string */
protected $mchat_table;
@@ -49,27 +49,27 @@ class acp_controller
/**
* Constructor
*
* @param \phpbb\config\config $config
* @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_deleted_messages_table
* @param string $root_path
* @param string $php_ext
*/
public function __construct(\phpbb\config\config $config, \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, $mchat_table, $mchat_deleted_messages_table, $root_path, $php_ext)
public function __construct(\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_deleted_messages_table, $root_path, $php_ext)
{
$this->config = $config;
$this->template = $template;
$this->log = $log;
$this->user = $user;
$this->db = $db;
$this->cache = $cache;
$this->request = $request;
$this->settings = $settings;
$this->mchat_table = $mchat_table;
$this->mchat_deleted_messages_table = $mchat_deleted_messages_table;
$this->root_path = $root_path;
@@ -79,48 +79,13 @@ class acp_controller
/**
* Display the options the admin can configure for this extension
*
* @param $u_action
* @param string $u_action
*/
public function display_options($u_action)
public function globalsettings($u_action)
{
add_form_key('acp_mchat');
$mchat_config = array(
'mchat_archive_limit' => array('default' => 25, 'validation' => array('num', false, 25, 50)),
'mchat_avatars' => array('default' => 1, 'validation' => array()),
'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, 'validation' => array()),
'mchat_relative_time' => array('default' => 1, 'validation' => array()),
'mchat_date' => array('default' => 'D M d, Y g:i a', 'validation' => array('string', false, 0, 255)),
'mchat_edit_delete_limit' => array('default' => 0, 'validation' => array()),
'mchat_flood_time' => array('default' => 0, 'validation' => array('num', false, 0, 30)),
'mchat_index_height' => array('default' => 250, 'validation' => array('num', false, 50, 1000)),
'mchat_live_updates' => array('default' => 1, 'validation' => array()),
'mchat_location' => array('default' => 0, 'validation' => array()),
'mchat_max_message_lngth' => array('default' => 500, 'validation' => array('num', false, 0, 500)),
'mchat_message_limit' => array('default' => 10, 'validation' => array('num', false, 10, 30)),
'mchat_message_num' => array('default' => 10, 'validation' => array('num', false, 10, 50)),
'mchat_message_top' => array('default' => 1, 'validation' => array()),
'mchat_navbar_link' => array('default' => 1, 'validation' => array()),
'mchat_new_posts_edit' => array('default' => 0, 'validation' => array()),
'mchat_new_posts_quote' => array('default' => 0, 'validation' => array()),
'mchat_new_posts_reply' => array('default' => 0, 'validation' => array()),
'mchat_new_posts_topic' => array('default' => 0, 'validation' => array()),
'mchat_on_index' => array('default' => 1, 'validation' => array()),
'mchat_override_min_post_chars' => array('default' => 0, 'validation' => array()),
'mchat_override_smilie_limit' => array('default' => 0, 'validation' => array()),
'mchat_pause_on_input' => array('default' => 0, 'validation' => array()),
'mchat_prune' => array('default' => 0, 'validation' => array()),
'mchat_prune_num' => array('default' => 0, 'validation' => array()),
'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_stats_index' => array('default' => 0, 'validation' => array()),
'mchat_timeout' => array('default' => 0, 'validation' => array('num', false, 0, (int) $this->config['session_length'])),
'mchat_whois' => array('default' => 1, 'validation' => array()),
'mchat_whois_refresh' => array('default' => 60, 'validation' => array('num', false, 30, 300)),
);
$error = array();
if ($this->request->is_set_post('mchat_purge'))
{
@@ -139,35 +104,37 @@ class acp_controller
}
else if ($this->request->is_set_post('submit'))
{
$mchat_new_config = array();
$validation = array();
foreach ($this->settings->global as $config_name => $config_data)
{
$default = $this->settings->cfg($config_name);
settype($default, gettype($config_data['default']));
$mchat_new_config[$config_name] = $this->request->variable($config_name, $default, is_string($default));
if (isset($config_data['validation']))
{
$validation[$config_name] = $config_data['validation'];
}
}
if (!function_exists('validate_data'))
{
include($this->root_path . 'includes/functions_user.' . $this->php_ext);
}
$mchat_new_config = array();
$validation = array();
foreach ($mchat_config as $key => $value)
{
$mchat_new_config[$key] = $this->request->variable($key, $value['default'], is_string($value['default']));
if (!empty($value['validation']))
{
$validation[$key] = $value['validation'];
}
}
$error = validate_data($mchat_new_config, $validation);
$error = array_merge($error, validate_data($mchat_new_config, $validation));
if (!check_form_key('acp_mchat'))
{
$error[] = 'FORM_INVALID';
}
if (empty($error))
if (!$error)
{
// Set the options the user configured
foreach ($mchat_new_config as $config_name => $config_value)
{
$this->config->set($config_name, $config_value);
$this->settings->set_cfg($config_name, $config_value);
}
// Add an entry into the log table
@@ -180,36 +147,94 @@ class acp_controller
$error = array_map(array($this->user, 'lang'), $error);
}
$dateformat_options = '';
foreach ($this->user->lang['dateformats'] as $format => $null)
foreach (array_keys($this->settings->global) as $key)
{
$dateformat_options .= '<option value="' . $format . '"' . (($format == $this->config['mchat_date']) ? ' selected="selected"' : '') . '>';
$dateformat_options .= $this->user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $this->user->lang('VARIANT_DATE_SEPARATOR') . $this->user->format_date(time(), $format, true) : '');
$dateformat_options .= '</option>';
}
$s_custom = false;
$dateformat_options .= '<option value="custom"';
if (!isset($this->user->lang['dateformats'][$this->config['mchat_date']]))
{
$dateformat_options .= ' selected="selected"';
$s_custom = true;
}
$dateformat_options .= '>' . $this->user->lang('MCHAT_CUSTOM_DATEFORMAT') . '</option>';
foreach (array_keys($mchat_config) as $key)
{
$this->template->assign_var(strtoupper($key), $this->config[$key]);
$this->template->assign_var(strtoupper($key), $this->settings->cfg($key));
}
$this->template->assign_vars(array(
'MCHAT_ERROR' => !empty($error) ? implode('<br />', $error) : '',
'MCHAT_VERSION' => $this->config['mchat_version'],
'MCHAT_ERROR' => $error ? implode('<br />', $error) : '',
'MCHAT_VERSION' => $this->settings->cfg('mchat_version'),
'MCHAT_FOUNDER' => $this->user->data['user_type'] == USER_FOUNDER,
'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_USER_TIMEOUT_EXPLAIN','<a href="' . append_sid("{$this->root_path}adm/index.$this->php_ext", 'i=board&amp;mode=load', true, $this->user->session_id) . '">', '</a>', $this->config['session_length']),
'S_MCHAT_DATEFORMAT_OPTIONS' => $dateformat_options,
'S_CUSTOM_DATEFORMAT' => $s_custom,
'L_MCHAT_TIMEOUT_EXPLAIN' => $this->user->lang('MCHAT_USER_TIMEOUT_EXPLAIN','<a href="' . append_sid("{$this->root_path}adm/index.$this->php_ext", 'i=board&amp;mode=load', true, $this->user->session_id) . '">', '</a>', $this->settings->cfg('session_length')),
'U_ACTION' => $u_action,
));
}
/**
* @param string $u_action
*/
public function globalusersettings($u_action)
{
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)
{
$default = $this->settings->cfg($config_name, true);
settype($default, gettype($config_data['default']));
$mchat_new_config[$config_name] = $this->request->variable('user_' . $config_name, $default, is_string($default));
if (isset($config_data['validation']))
{
$validation[$config_name] = $config_data['validation'];
}
}
if (!function_exists('validate_data'))
{
include($this->root_path . 'includes/functions_user.' . $this->php_ext);
}
$error = array_merge($error, validate_data($mchat_new_config, $validation));
if (!check_form_key('acp_mchat'))
{
$error[] = 'FORM_INVALID';
}
if (!$error)
{
// Set the options the user configured
foreach ($mchat_new_config as $config_name => $config_value)
{
$this->settings->set_cfg($config_name, $config_value);
}
// 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']));
trigger_error($this->user->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);
}
foreach (array_keys($this->settings->ucp) as $key)
{
$this->template->assign_var(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' => $error ? implode('<br />', $error) : '',
'MCHAT_VERSION' => $this->settings->cfg('mchat_version'),
'U_ACTION' => $u_action,
));
}

View File

@@ -54,7 +54,7 @@ class main_controller
* Controller for mChat actions called with Ajax requests
*
* @param string $action The action to perform, one of add|edit|del|refresh|whois
* @return A Symfony JsonResponse object
* @return \Symfony\Component\HttpFoundation\JsonResponse A Symfony JsonResponse object
*/
public function action($action)
{

View File

@@ -13,42 +13,52 @@ namespace dmzx\mchat\controller;
class ucp_controller
{
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\template\template */
protected $template;
/** @var \phpbb\user */
protected $user;
/** @var \phpbb\auth\auth */
protected $auth;
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\request\request */
protected $request;
/** @var array */
protected $user_config_keys;
/** @var \dmzx\mchat\core\settings */
protected $settings;
/** @var string */
protected $root_path;
/** @var string */
protected $php_ext;
/**
* Constructor
*
* @param \phpbb\config\config $config
* @param \phpbb\template\template $template
* @param \phpbb\user $user
* @param \phpbb\auth\auth $auth
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\request\request $request
* @param array $user_config_keys
* @param \dmzx\mchat\core\settings $settings
* @param string $root_path
* @param string $php_ext
*/
public function __construct(\phpbb\config\config $config, \phpbb\template\template $template, \phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\request\request $request, $user_config_keys)
public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\request\request $request, \dmzx\mchat\core\settings $settings, $root_path, $php_ext)
{
$this->config = $config;
$this->template = $template;
$this->user = $user;
$this->db = $db;
$this->request = $request;
$this->user_config_keys = $user_config_keys;
$this->template = $template;
$this->user = $user;
$this->auth = $auth;
$this->db = $db;
$this->request = $request;
$this->settings = $settings;
$this->root_path = $root_path;
$this->php_ext = $php_ext;
}
/**
@@ -56,7 +66,7 @@ class ucp_controller
*
* @param $u_action
*/
public function display_options($u_action)
public function configuration($u_action)
{
add_form_key('ucp_mchat');
@@ -64,21 +74,39 @@ class ucp_controller
if ($this->request->is_set_post('submit'))
{
$mchat_new_config = array();
$validation = array();
foreach ($this->settings->ucp as $config_name => $config_data)
{
if ($this->auth->acl_get('u_' . $config_name))
{
$default = $this->user->data['user_' . $config_name];
settype($default, gettype($config_data['default']));
$mchat_new_config['user_' . $config_name] = $this->request->variable('user_' . $config_name, $default, is_string($default));
if (isset($config_data['validation']))
{
$validation['user_' . $config_name] = $config_data['validation'];
}
}
}
if (!function_exists('validate_data'))
{
include($this->root_path . 'includes/functions_user.' . $this->php_ext);
}
$error = array_merge($error, validate_data($mchat_new_config, $validation));
if (!check_form_key('ucp_mchat'))
{
$error[] = 'FORM_INVALID';
}
if (empty($error))
if (!$error)
{
$data = array();
foreach ($this->user_config_keys as $config_key)
{
$data[$config_key] = $this->request->variable($config_key, (int) $this->user->data[$config_key]);
}
$sql = 'UPDATE ' . USERS_TABLE . '
SET ' . $this->db->sql_build_array('UPDATE', $data) . '
SET ' . $this->db->sql_build_array('UPDATE', $mchat_new_config) . '
WHERE user_id = ' . (int) $this->user->data['user_id'];
$this->db->sql_query($sql);
@@ -91,19 +119,35 @@ class ucp_controller
$error = array_map(array($this->user, 'lang'), $error);
}
foreach ($this->user_config_keys as $config_key)
$auth_count = 0;
foreach (array_keys($this->settings->ucp) as $config_name)
{
$this->template->assign_var(strtoupper($config_key), $this->user->data[$config_key]);
$upper = strtoupper($config_name);
$auth = $this->auth->acl_get('u_' . $config_name);
$this->template->assign_vars(array(
$upper => $this->settings->cfg($config_name),
$upper . '_AUTH' => $auth,
));
if ($auth)
{
$auth_count++;
}
}
$this->template->assign_vars(array(
'ERROR' => sizeof($error) ? implode('<br />', $error) : '',
'S_UCP_ACTION' => $u_action,
$selected = $this->settings->cfg('mchat_date');
$date_template_data = $this->settings->get_date_template_data($selected);
$this->template->assign_vars($date_template_data);
'S_MCHAT_TOPICS' => $this->config['mchat_new_posts_edit'] || $this->config['mchat_new_posts_quote'] || $this->config['mchat_new_posts_reply'] || $this->config['mchat_new_posts_topic'],
'S_MCHAT_INDEX' => $this->config['mchat_on_index'],
'S_MCHAT_INDEX_STATS' => $this->config['mchat_stats_index'],
'S_MCHAT_AVATARS' => $this->config['mchat_avatars'],
$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(
'ERROR' => sizeof($error) ? implode('<br />', $error) : '',
'MCHAT_AUTH_COUNT' => $auth_count,
'S_UCP_ACTION' => $u_action,
));
}
}