Version 2.1.3

This commit is contained in:
dmzx
2019-08-29 08:41:42 +02:00
parent 940161da23
commit 4d7253f0f0
11 changed files with 149 additions and 69 deletions

View File

@@ -631,24 +631,62 @@ class functions
*/
public function mchat_is_user_flooding()
{
if (!$this->mchat_settings->cfg('mchat_flood_time') || $this->auth->acl_get('u_mchat_flood_ignore'))
if ($this->auth->acl_get('u_mchat_flood_ignore'))
{
return false;
}
$sql_queries = [];
$sql_array = [
'SELECT' => 'm.message_time',
'SELECT' => 'm.user_id',
'FROM' => [$this->mchat_settings->get_table_mchat() => 'm'],
'WHERE' => 'm.user_id = ' . (int) $this->user->data['user_id'],
'ORDER_BY' => 'm.message_time DESC',
'ORDER_BY' => 'm.message_time DESC, m.message_id DESC',
];
$sql = $this->db->sql_build_query('SELECT', $sql_array);
$result = $this->db->sql_query_limit($sql, 1);
$message_time = (int) $this->db->sql_fetchfield('message_time');
$this->db->sql_freeresult($result);
if ($this->mchat_settings->cfg('mchat_flood_time'))
{
$sql = $this->db->sql_build_query('SELECT', array_merge($sql_array, [
'WHERE' => implode(' AND ', [
'm.user_id = ' . (int) $this->user->data['user_id'],
'message_time > ' . time() . ' - ' . (int) $this->mchat_settings->cfg('mchat_flood_time'),
$this->mchat_notifications->get_sql_where('exclude'),
]),
]));
return $message_time && time() - $message_time < $this->mchat_settings->cfg('mchat_flood_time');
$sql_queries[$sql] = 1;
}
if ($this->mchat_settings->cfg('mchat_flood_messages'))
{
$sql = $this->db->sql_build_query('SELECT', array_merge($sql_array, [
'WHERE' => $this->mchat_notifications->get_sql_where('exclude'),
]));
$sql_queries[$sql] = $this->mchat_settings->cfg('mchat_flood_messages');
}
foreach ($sql_queries as $sql => $limit)
{
$result = $this->db->sql_query_limit($sql, $limit);
$rows = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result);
if ($rows)
{
foreach ($rows as $row)
{
if ($row['user_id'] != $this->user->data['user_id'])
{
return false;
}
}
return true;
}
}
return false;
}
/**

View File

@@ -208,6 +208,7 @@ class notifications
return $post_subjects + $missing_post_subjects;
}
/**
* Converts the message field of the post row so that it can be passed to generate_text_for_display()
*
@@ -374,12 +375,14 @@ class notifications
* Generates an SQL WHERE condition to include or exlude notifacation
* messages based on the current user's settings and permissions
*
* @param string $mode One of user|exclude. user mode uses the current user's settings to decide which notifications
* to exclude. exclude mode always excludes all notifications.
* @return string
*/
public function get_sql_where()
public function get_sql_where($mode = 'user')
{
// Exclude all post notifications
if (!$this->mchat_settings->cfg('mchat_posts'))
if ($mode == 'exclude' || !$this->mchat_settings->cfg('mchat_posts'))
{
return 'm.post_id = 0';
}

View File

@@ -163,7 +163,8 @@ class settings
'mchat_custom_height' => ['default' => 350, 'validation' => ['num', false, 50, 1000]],
'mchat_custom_page' => ['default' => 1],
'mchat_edit_delete_limit' => ['default' => 0],
'mchat_flood_time' => ['default' => 0, 'validation' => ['num', false, 0, 60]],
'mchat_flood_time' => ['default' => 0, 'validation' => ['num', false, 0, 3600]],
'mchat_flood_messages' => ['default' => 0, 'validation' => ['num', false, 0, 100]],
'mchat_index_height' => ['default' => 250, 'validation' => ['num', false, 50, 1000]],
'mchat_live_updates' => ['default' => 1],
'mchat_log_enabled' => ['default' => 1],