Version 2.0.0-RC6

This commit is contained in:
dmzx
2016-09-20 22:38:19 +02:00
parent aac8ce6f58
commit 233dc89a8a
73 changed files with 2722 additions and 1336 deletions

View File

@@ -13,11 +13,6 @@ namespace dmzx\mchat\core;
class settings
{
const VALIDATE_TYPE = 0;
const VALIDATE_IS_OPTIONAL = 1;
const VALIDATE_MIN_VALUE = 2;
const VALIDATE_MAX_VALUE = 3;
/** @var \phpbb\user */
protected $user;
@@ -27,10 +22,23 @@ class settings
/** @var \phpbb\auth\auth */
protected $auth;
/** @var array */
/**
* Keys for global settings that only the administrator is allowed to modify.
* The values are stored in the phpbb_config table.
*
* @var array
*/
public $global;
/** @var array */
/**
* Keys for user-specific settings for which the administrator can set default
* values as well as adjust permissions to allow users to customize them.
* The values are stored in the phpbb_users table as well as the phpbb_config table.
* If a user has permission to customize a setting, the value in the phpbb_users
* table is used, otherwise the value in the phpbb_config table is used.
*
* @var array
*/
public $ucp;
/** @var bool */
@@ -45,30 +53,62 @@ class settings
* @param \phpbb\user $user
* @param \phpbb\config\config $config
* @param \phpbb\auth\auth $auth
* @param array $global
* @param array $ucp
*/
public function __construct(\phpbb\user $user, \phpbb\config\config $config, \phpbb\auth\auth $auth, $global, $ucp)
public function __construct(\phpbb\user $user, \phpbb\config\config $config, \phpbb\auth\auth $auth)
{
$this->user = $user;
$this->config = $config;
$this->auth = $auth;
$this->global = $global;
$this->ucp = $ucp;
$this->is_phpbb31 = phpbb_version_compare($config['version'], '3.1.0@dev', '>=') && phpbb_version_compare($config['version'], '3.2.0@dev', '<');
$this->is_phpbb32 = phpbb_version_compare($config['version'], '3.2.0@dev', '>=') && phpbb_version_compare($config['version'], '3.3.0@dev', '<');
$this->global = 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),
'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_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_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)),
);
$this->inject_core_config_values();
}
$this->ucp = 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),
);
/**
* Writes phpBB config values into the mChat config for validating input data
*/
protected function inject_core_config_values()
{
// Limit mChat session timeout to phpBB session length
$this->global['mchat_timeout']['validation'][self::VALIDATE_MAX_VALUE] = (int) $this->cfg('session_length');
$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', '<');
}
/**
@@ -101,10 +141,18 @@ class settings
/**
* @param $config
* @param $value
* @param bool $volatile
*/
public function set_cfg($config, $value)
public function set_cfg($config, $value, $volatile = false)
{
$this->config->set($config, $value);
if ($volatile)
{
$this->config[$config] = $value;
}
else
{
$this->config->set($config, $value);
}
}
/**
@@ -146,7 +194,7 @@ class settings
{
$enabled_notifications_lang = array();
foreach (array('topic', 'reply', 'quote', 'edit') as $notification)
foreach (array('topic', 'reply', 'quote', 'edit', 'login') as $notification)
{
if ($this->cfg('mchat_posts_' . $notification))
{