Version 2.0.0-RC3
This commit is contained in:
@@ -13,8 +13,8 @@ namespace dmzx\mchat\core;
|
||||
|
||||
class functions
|
||||
{
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
/** @var \dmzx\mchat\core\settings */
|
||||
protected $settings;
|
||||
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
@@ -52,7 +52,7 @@ class functions
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\config\config $config
|
||||
* @param \dmzx\mchat\core\settings $settings
|
||||
* @param \phpbb\user $user
|
||||
* @param \phpbb\auth\auth $auth
|
||||
* @param \phpbb\log\log_interface $log
|
||||
@@ -64,9 +64,9 @@ class functions
|
||||
* @param string $mchat_deleted_messages_table
|
||||
* @param string $mchat_sessions_table
|
||||
*/
|
||||
function __construct(\phpbb\config\config $config, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\log\log_interface $log, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache, $root_path, $php_ext, $mchat_table, $mchat_deleted_messages_table, $mchat_sessions_table)
|
||||
function __construct(\dmzx\mchat\core\settings $settings, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\log\log_interface $log, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache, $root_path, $php_ext, $mchat_table, $mchat_deleted_messages_table, $mchat_sessions_table)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->settings = $settings;
|
||||
$this->user = $user;
|
||||
$this->auth = $auth;
|
||||
$this->log = $log;
|
||||
@@ -119,7 +119,19 @@ class functions
|
||||
*/
|
||||
protected function mchat_session_time()
|
||||
{
|
||||
return !empty($this->config['mchat_timeout']) ? $this->config['mchat_timeout'] : (!empty($this->config['load_online_time']) ? $this->config['load_online_time'] * 60 : $this->config['session_length']);
|
||||
$mchat_timeout = $this->settings->cfg('mchat_timeout');
|
||||
if ($mchat_timeout)
|
||||
{
|
||||
return $mchat_timeout;
|
||||
}
|
||||
|
||||
$load_online_time = $this->settings->cfg('load_online_time');
|
||||
if ($load_online_time)
|
||||
{
|
||||
return $load_online_time * 60;
|
||||
}
|
||||
|
||||
return $this->settings->cfg('session_length');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,11 +228,11 @@ class functions
|
||||
*/
|
||||
public function mchat_prune()
|
||||
{
|
||||
if ($this->config['mchat_prune'])
|
||||
if ($this->settings->cfg('mchat_prune'))
|
||||
{
|
||||
$mchat_total_messages = $this->mchat_total_message_count();
|
||||
|
||||
if ($mchat_total_messages > $this->config['mchat_prune_num'])
|
||||
if ($mchat_total_messages > $this->settings->cfg('mchat_prune_num'))
|
||||
{
|
||||
$sql = 'SELECT message_id
|
||||
FROM '. $this->mchat_table . '
|
||||
@@ -230,10 +242,10 @@ class functions
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
// Compute new oldest message id
|
||||
$delete_id = $mchat_total_messages - $this->config['mchat_prune_num'] + $first_id;
|
||||
$delete_id = $mchat_total_messages - $this->settings->cfg('mchat_prune_num') + $first_id;
|
||||
|
||||
// Delete older messages
|
||||
$this->mchat_action('prune', null, $delete_id, $this->user->data['username']);
|
||||
$this->mchat_action('prune', null, $delete_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -258,6 +270,16 @@ class functions
|
||||
*/
|
||||
public function mchat_get_messages($sql_where, $total = 0, $offset = 0)
|
||||
{
|
||||
// Exclude post notifications
|
||||
if (!$this->settings->cfg('mchat_posts'))
|
||||
{
|
||||
if (!empty($sql_where))
|
||||
{
|
||||
$sql_where = '(' . $sql_where . ') AND ';
|
||||
}
|
||||
$sql_where .= 'm.forum_id = 0';
|
||||
}
|
||||
|
||||
$sql_array = array(
|
||||
'SELECT' => 'm.*, u.username, u.user_colour, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, u.user_allow_pm',
|
||||
'FROM' => array($this->mchat_table => 'm'),
|
||||
@@ -276,6 +298,15 @@ class functions
|
||||
$rows = $this->db->sql_fetchrowset($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
// Set deleted users to ANONYMOUS
|
||||
foreach ($rows as $i => $row)
|
||||
{
|
||||
if (!isset($row['username']))
|
||||
{
|
||||
$rows[$i]['user_id'] = ANONYMOUS;
|
||||
}
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
@@ -287,7 +318,7 @@ class functions
|
||||
public function mchat_legend()
|
||||
{
|
||||
// Grab group details for legend display for who is online on the custom page
|
||||
$order_legend = $this->config['legend_sort_groupname'] ? 'group_name' : 'group_legend';
|
||||
$order_legend = $this->settings->cfg('legend_sort_groupname') ? 'group_name' : 'group_legend';
|
||||
if ($this->auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
|
||||
{
|
||||
$sql = 'SELECT group_id, group_name, group_colour, group_type
|
||||
@@ -361,7 +392,7 @@ class functions
|
||||
*/
|
||||
public function mchat_sql_append_forbidden_bbcodes($sql_where)
|
||||
{
|
||||
$disallowed_bbcodes = explode('|', $this->config['mchat_bbcode_disallowed']);
|
||||
$disallowed_bbcodes = explode('|', $this->settings->cfg('mchat_bbcode_disallowed'));
|
||||
|
||||
if (!empty($disallowed_bbcodes))
|
||||
{
|
||||
@@ -380,13 +411,13 @@ class functions
|
||||
public function mchat_insert_posting($mode, $data)
|
||||
{
|
||||
$mode_config = array(
|
||||
'post' => $this->config['mchat_new_posts_topic'],
|
||||
'quote' => $this->config['mchat_new_posts_quote'],
|
||||
'edit' => $this->config['mchat_new_posts_edit'],
|
||||
'reply' => $this->config['mchat_new_posts_reply'],
|
||||
'post' => 'mchat_posts_topic',
|
||||
'quote' => 'mchat_posts_quote',
|
||||
'edit' => 'mchat_posts_edit',
|
||||
'reply' => 'mchat_posts_reply',
|
||||
);
|
||||
|
||||
if (empty($mode_config[$mode]))
|
||||
if (empty($mode_config[$mode]) || !$this->settings->cfg($mode_config[$mode]))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -420,7 +451,7 @@ class functions
|
||||
*/
|
||||
public function mchat_is_user_flooding()
|
||||
{
|
||||
if (!$this->config['mchat_flood_time'] || $this->auth->acl_get('u_mchat_flood_ignore'))
|
||||
if (!$this->settings->cfg('mchat_flood_time') || $this->auth->acl_get('u_mchat_flood_ignore'))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -433,7 +464,7 @@ class functions
|
||||
$message_time = (int) $this->db->sql_fetchfield('message_time');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
return $message_time && time() - $message_time < $this->config['mchat_flood_time'];
|
||||
return $message_time && time() - $message_time < $this->settings->cfg('mchat_flood_time');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -486,10 +517,9 @@ class functions
|
||||
* @param string $action One of add|edit|del|prune
|
||||
* @param array $sql_ary
|
||||
* @param int $message_id
|
||||
* @param string $log_username
|
||||
* @return bool
|
||||
*/
|
||||
public function mchat_action($action, $sql_ary = null, $message_id = 0, $log_username = '')
|
||||
public function mchat_action($action, $sql_ary = null, $message_id = 0)
|
||||
{
|
||||
$is_new_session = false;
|
||||
|
||||
@@ -507,7 +537,7 @@ class functions
|
||||
$this->user->update_session_infos();
|
||||
$is_new_session = $this->mchat_add_user_session();
|
||||
$this->db->sql_query('UPDATE ' . $this->mchat_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE message_id = ' . (int) $message_id);
|
||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EDITED_MCHAT', false, array($log_username));
|
||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EDITED_MCHAT', false, array($this->user->data['username']));
|
||||
break;
|
||||
|
||||
// User deletes a message
|
||||
@@ -517,7 +547,7 @@ class functions
|
||||
$this->db->sql_query('DELETE FROM ' . $this->mchat_table . ' WHERE message_id = ' . (int) $message_id);
|
||||
$this->db->sql_query('INSERT INTO ' . $this->mchat_deleted_messages_table . ' ' . $this->db->sql_build_array('INSERT', array('message_id' => (int) $message_id)));
|
||||
$this->cache->destroy('sql', $this->mchat_deleted_messages_table);
|
||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DELETED_MCHAT', false, array($log_username));
|
||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DELETED_MCHAT', false, array($this->user->data['username']));
|
||||
break;
|
||||
|
||||
// User triggers messages to be pruned
|
||||
@@ -539,7 +569,6 @@ class functions
|
||||
$this->db->sql_query('DELETE FROM ' . $this->mchat_table . ' WHERE ' .$this->db->sql_in_set('message_id', $prune_ids));
|
||||
$this->db->sql_multi_insert($this->mchat_deleted_messages_table, $rows);
|
||||
$this->cache->destroy('sql', $this->mchat_deleted_messages_table);
|
||||
// $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED', false, array($log_username));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user