Version 0.3.2
This commit is contained in:
@@ -11,6 +11,9 @@ namespace dmzx\mchat\core;
|
||||
|
||||
class functions_mchat
|
||||
{
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
|
||||
/** @var \phpbb\template\template */
|
||||
protected $template;
|
||||
|
||||
@@ -29,6 +32,12 @@ class functions_mchat
|
||||
/** @var \phpbb\cache\service */
|
||||
protected $cache;
|
||||
|
||||
/** @var string */
|
||||
protected $phpbb_root_path;
|
||||
|
||||
/** @var string */
|
||||
protected $phpEx;
|
||||
|
||||
/** @var string */
|
||||
protected $mchat_table;
|
||||
|
||||
@@ -41,26 +50,32 @@ class functions_mchat
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\config\config $config
|
||||
* @param \phpbb\template\template $template
|
||||
* @param \phpbb\user $user
|
||||
* @param \phpbb\auth\auth $auth
|
||||
* @param \phpbb\log\log_interface $log
|
||||
* @param \phpbb\db\driver\driver_interface $db
|
||||
* @param \phpbb\cache\service $cache
|
||||
* @param string $phpbb_root_path
|
||||
* @param string $phpEx
|
||||
* @param string $mchat_table
|
||||
* @param string $mchat_config_table
|
||||
* @param string $mchat_sessions_table
|
||||
*/
|
||||
function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\log\log_interface $log, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, $mchat_table, $mchat_config_table, $mchat_sessions_table)
|
||||
function __construct(\phpbb\config\config $config, \phpbb\template\template $template, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\log\log_interface $log, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, $phpbb_root_path, $phpEx, $mchat_table, $mchat_config_table, $mchat_sessions_table)
|
||||
{
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
$this->auth = $auth;
|
||||
$this->log = $log;
|
||||
$this->db = $db;
|
||||
$this->cache = $cache;
|
||||
$this->mchat_table = $mchat_table;
|
||||
$this->mchat_config_table = $mchat_config_table;
|
||||
$this->config = $config;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
$this->auth = $auth;
|
||||
$this->log = $log;
|
||||
$this->db = $db;
|
||||
$this->cache = $cache;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->phpEx = $phpEx;
|
||||
$this->mchat_table = $mchat_table;
|
||||
$this->mchat_config_table = $mchat_config_table;
|
||||
$this->mchat_sessions_table = $mchat_sessions_table;
|
||||
}
|
||||
|
||||
@@ -106,13 +121,13 @@ class functions_mchat
|
||||
{
|
||||
$hours = floor($chat_timeout / 3600);
|
||||
$chat_timeout = $chat_timeout - ($hours * 3600);
|
||||
$chat_session .= $hours > 1 ? ($hours . ' ' . $this->user->lang['MCHAT_HOURS']) : ($hours . ' ' . $this->user->lang['MCHAT_HOUR']);
|
||||
$chat_session .= $hours > 1 ? ($hours . ' ' . $this->user->lang('MCHAT_HOURS')) : ($hours . ' ' . $this->user->lang('MCHAT_HOUR'));
|
||||
}
|
||||
|
||||
$minutes = floor($chat_timeout / 60);
|
||||
if ($minutes)
|
||||
{
|
||||
$minutes = $minutes > 1 ? ($minutes . ' ' . $this->user->lang['MCHAT_MINUTES']) : ($minutes . ' ' . $this->user->lang['MCHAT_MINUTE']);
|
||||
$minutes = $minutes > 1 ? ($minutes . ' ' . $this->user->lang('MCHAT_MINUTES')) : ($minutes . ' ' . $this->user->lang('MCHAT_MINUTE'));
|
||||
$chat_timeout = $chat_timeout - ($minutes * 60);
|
||||
$chat_session .= $minutes;
|
||||
}
|
||||
@@ -120,17 +135,17 @@ class functions_mchat
|
||||
$seconds = ceil($chat_timeout);
|
||||
if ($seconds)
|
||||
{
|
||||
$seconds = $seconds > 1 ? ($seconds . ' ' . $this->user->lang['MCHAT_SECONDS']) : ($seconds . ' ' . $this->user->lang['MCHAT_SECOND']);
|
||||
$seconds = $seconds > 1 ? ($seconds . ' ' . $this->user->lang('MCHAT_SECONDS')) : ($seconds . ' ' . $this->user->lang('MCHAT_SECOND'));
|
||||
$chat_session .= $seconds;
|
||||
}
|
||||
|
||||
return sprintf($this->user->lang['MCHAT_ONLINE_EXPLAIN'], $chat_session);
|
||||
return sprintf($this->user->lang('MCHAT_ONLINE_EXPLAIN'), $chat_session);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $session_time amount of time before a users session times out
|
||||
*/
|
||||
function mchat_users($session_time, $on_page)
|
||||
function mchat_users($session_time)
|
||||
{
|
||||
$check_time = time() - (int) $session_time;
|
||||
|
||||
@@ -138,12 +153,6 @@ class functions_mchat
|
||||
WHERE user_lastupdate < ' . $check_time;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
// Add the user into the sessions upon first visit
|
||||
if ($on_page && ($this->user->data['user_id'] != ANONYMOUS && !$this->user->data['is_bot']))
|
||||
{
|
||||
$this->mchat_sessions($session_time);
|
||||
}
|
||||
|
||||
$mchat_user_count = 0;
|
||||
$mchat_user_list = '';
|
||||
|
||||
@@ -172,8 +181,8 @@ class functions_mchat
|
||||
}
|
||||
|
||||
$mchat_user_count++;
|
||||
$mchat_user_online_link = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']);
|
||||
$mchat_user_list .= ($mchat_user_list != '') ? $this->user->lang['COMMA_SEPARATOR'] . $mchat_user_online_link : $mchat_user_online_link;
|
||||
$mchat_user_online_link = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang('GUEST'));
|
||||
$mchat_user_list .= ($mchat_user_list != '') ? $this->user->lang('COMMA_SEPARATOR') . $mchat_user_online_link : $mchat_user_online_link;
|
||||
}
|
||||
|
||||
$refresh_message = $this->mchat_session_time($session_time);
|
||||
@@ -182,7 +191,7 @@ class functions_mchat
|
||||
{
|
||||
return array(
|
||||
'online_userlist' => '',
|
||||
'mchat_users_count' => $this->user->lang['MCHAT_NO_CHATTERS'],
|
||||
'mchat_users_count' => $this->user->lang('MCHAT_NO_CHATTERS'),
|
||||
'refresh_message' => $refresh_message,
|
||||
);
|
||||
}
|
||||
@@ -190,7 +199,7 @@ class functions_mchat
|
||||
{
|
||||
return array(
|
||||
'online_userlist' => $mchat_user_list,
|
||||
'mchat_users_count' => $mchat_user_count > 1 ? sprintf($this->user->lang['MCHAT_ONLINE_USERS_TOTAL'], $mchat_user_count) : sprintf($this->user->lang['MCHAT_ONLINE_USER_TOTAL'], $mchat_user_count),
|
||||
'mchat_users_count' => sprintf($this->user->lang($mchat_user_count > 1 ? 'MCHAT_ONLINE_USERS_TOTAL' : 'MCHAT_ONLINE_USER_TOTAL'), $mchat_user_count),
|
||||
'refresh_message' => $refresh_message,
|
||||
);
|
||||
}
|
||||
@@ -203,31 +212,34 @@ class functions_mchat
|
||||
{
|
||||
$check_time = time() - (int) $session_time;
|
||||
$sql = 'DELETE FROM ' . $this->mchat_sessions_table . '
|
||||
WHERE user_lastupdate <' . $check_time;
|
||||
WHERE user_lastupdate < ' . $check_time;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
// Insert user into the mChat sessions table
|
||||
if ($this->user->data['user_type'] == USER_FOUNDER || $this->user->data['user_type'] == USER_NORMAL)
|
||||
if ($this->user->data['user_type'] == USER_FOUNDER || $this->user->data['user_type'] == USER_NORMAL && $this->user->data['user_id'] != ANONYMOUS && !$this->user->data['is_bot'])
|
||||
{
|
||||
$sql = 'SELECT *
|
||||
FROM ' . $this->mchat_sessions_table . '
|
||||
WHERE user_id =' . (int) $this->user->data['user_id'];
|
||||
WHERE user_id = ' . (int) $this->user->data['user_id'];
|
||||
$result = $this->db->sql_query($sql);
|
||||
$row = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$sql_ary = array('user_lastupdate' => time());
|
||||
$user_lastupdate = time();
|
||||
|
||||
if ($row)
|
||||
{
|
||||
$sql = 'UPDATE ' . $this->mchat_sessions_table . '
|
||||
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
|
||||
WHERE user_id =' . (int) $this->user->data['user_id'];
|
||||
SET user_lastupdate = ' . $user_lastupdate . '
|
||||
WHERE user_id = ' . (int) $this->user->data['user_id'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql_ary['user_id'] = $this->user->data['user_id'];
|
||||
$sql = 'INSERT INTO ' . $this->mchat_sessions_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
|
||||
$sql = 'INSERT INTO ' . $this->mchat_sessions_table . ' ' . $this->db->sql_build_array('INSERT', array(
|
||||
'user_id' => $this->user->data['user_id'],
|
||||
'user_ip' => $this->user->data['user_ip'],
|
||||
'user_lastupdate' => $user_lastupdate,
|
||||
));
|
||||
}
|
||||
|
||||
$this->db->sql_query($sql);
|
||||
@@ -307,7 +319,6 @@ class functions_mchat
|
||||
}
|
||||
}
|
||||
|
||||
// From /includes/functions_display.php
|
||||
display_custom_bbcodes();
|
||||
}
|
||||
|
||||
@@ -328,4 +339,144 @@ class functions_mchat
|
||||
'avatar_height' => $row['user_avatar_height'] > $row['user_avatar_width'] ? 40 : (40 / $row['user_avatar_width']) * $row['user_avatar_height'],
|
||||
));
|
||||
}
|
||||
|
||||
function mchat_messages($sql_where, $total, $offset = 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'),
|
||||
'LEFT_JOIN' => array(
|
||||
array(
|
||||
'FROM' => array(USERS_TABLE => 'u'),
|
||||
'ON' => 'm.user_id = u.user_id',
|
||||
)
|
||||
),
|
||||
'WHERE' => $sql_where,
|
||||
'ORDER_BY' => 'm.message_id DESC',
|
||||
);
|
||||
|
||||
$sql = $this->db->sql_build_query('SELECT', $sql_array);
|
||||
$result = $this->db->sql_query_limit($sql, $total, $offset);
|
||||
$rows = $this->db->sql_fetchrowset($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
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';
|
||||
if ($this->auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
|
||||
{
|
||||
$sql = 'SELECT group_id, group_name, group_colour, group_type
|
||||
FROM ' . GROUPS_TABLE . '
|
||||
WHERE group_legend <> 0
|
||||
ORDER BY ' . $order_legend . ' ASC';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type
|
||||
FROM ' . GROUPS_TABLE . ' g
|
||||
LEFT JOIN ' . USER_GROUP_TABLE . ' ug ON (g.group_id = ug.group_id AND ug.user_id = ' . $this->user->data['user_id'] . ' AND ug.user_pending = 0)
|
||||
WHERE g.group_legend <> 0
|
||||
AND (g.group_type <> ' . GROUP_HIDDEN . '
|
||||
OR ug.user_id = ' . (int) $this->user->data['user_id'] . ')
|
||||
ORDER BY g.' . $order_legend . ' ASC';
|
||||
}
|
||||
$result = $this->db->sql_query($sql);
|
||||
$rows = $this->db->sql_fetchrowset($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$legend = array();
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
$colour_text = $row['group_colour'] ? ' style="color:#' . $row['group_colour'] . '"' : '';
|
||||
$group_name = $row['group_type'] == GROUP_SPECIAL ? $this->user->lang('G_' . $row['group_name']) : $row['group_name'];
|
||||
if ($row['group_name'] == 'BOTS' || $this->user->data['user_id'] != ANONYMOUS && !$this->auth->acl_get('u_viewprofile'))
|
||||
{
|
||||
$legend[] = '<span' . $colour_text . '>' . $group_name . '</span>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$legend[] = '<a' . $colour_text . ' href="' . append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=group&g='.$row['group_id']) . '">' . $group_name . '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
return $legend;
|
||||
}
|
||||
|
||||
function mchat_truncate_messages()
|
||||
{
|
||||
$sql = 'TRUNCATE TABLE ' . $this->mchat_table;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED');
|
||||
}
|
||||
|
||||
function mchat_foes()
|
||||
{
|
||||
$sql = 'SELECT *
|
||||
FROM ' . ZEBRA_TABLE . '
|
||||
WHERE user_id = ' . (int) $this->user->data['user_id'] . '
|
||||
AND foe = 1';
|
||||
$result = $this->db->sql_query($sql);
|
||||
$rows = $this->db->sql_fetchrowset($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$foes = array();
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
$foes[] = $row['zebra_id'];
|
||||
}
|
||||
|
||||
return $foes;
|
||||
}
|
||||
|
||||
function mchat_insert_posting($mode, $data)
|
||||
{
|
||||
if (empty($this->config['mchat_enable']) || empty($this->config['mchat_new_posts']))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ($mode == 'post' && !empty($this->config['mchat_new_posts_topic']))
|
||||
{
|
||||
$mchat_new_data = $this->user->lang('MCHAT_NEW_TOPIC');
|
||||
}
|
||||
else if ($mode == 'quote' && !empty($this->config['mchat_new_posts_quote']))
|
||||
{
|
||||
$mchat_new_data = $this->user->lang('MCHAT_NEW_QUOTE');
|
||||
}
|
||||
else if ($mode == 'edit' && !empty($this->config['mchat_new_posts_edit']))
|
||||
{
|
||||
$mchat_new_data = $this->user->lang('MCHAT_NEW_EDIT');
|
||||
}
|
||||
else if ($mode == 'reply' && !empty($this->config['mchat_new_posts_reply']))
|
||||
{
|
||||
$mchat_new_data = $this->user->lang('MCHAT_NEW_REPLY');
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$message = utf8_normalize_nfc($mchat_new_data . ': [url=' . generate_board_url() . '/viewtopic.' . $this->phpEx . '?p=' . $data['post_id'] . '#p' . $data['post_id'] . ']' . $data['post_subject'] . '[/url] '. $this->user->lang('MCHAT_IN') . ' [url=' . generate_board_url() . '/viewforum.' . $this->phpEx . '?f=' . $data['forum_id'] . ']' . $data['forum_name'] . ' [/url] ' . $this->user->lang('MCHAT_IN_SECTION'));
|
||||
|
||||
$uid = $bitfield = $options = ''; // will be modified by generate_text_for_storage
|
||||
generate_text_for_storage($message, $uid, $bitfield, $options, true, false, false);
|
||||
$sql_ary = array(
|
||||
'forum_id' => $data['forum_id'],
|
||||
'post_id' => $data['post_id'],
|
||||
'user_id' => $this->user->data['user_id'],
|
||||
'user_ip' => $this->user->data['session_ip'],
|
||||
'message' => $message,
|
||||
'bbcode_bitfield' => $bitfield,
|
||||
'bbcode_uid' => $uid,
|
||||
'bbcode_options' => $options,
|
||||
'message_time' => time(),
|
||||
);
|
||||
$sql = 'INSERT INTO ' . $this->mchat_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user