Removed unused dependencies & code cleanup

This commit is contained in:
kasimi
2015-12-19 22:45:42 +01:00
parent 90ef1c717e
commit 7f503c2f35
9 changed files with 574 additions and 721 deletions

View File

@@ -30,17 +30,12 @@ class functions_mchat
protected $cache;
/** @var string */
protected $table_prefix;
/**
* The database tables
*
* @var string
*/
protected $mchat_table;
/** @var string */
protected $mchat_config_table;
/** @var string */
protected $mchat_sessions_table;
/**
@@ -52,74 +47,57 @@ class functions_mchat
* @param \phpbb\log\log_interface $log
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\cache\service $cache
* @param $table_prefix
* @param $mchat_table
* @param $mchat_config_table
* @param $mchat_sessions_table
*
* @param string $mchat_table
* @param string $mchat_config_table
* @param string $mchat_sessions_table
*/
public 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, $table_prefix, $mchat_table, $mchat_config_table, $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)
{
$this->template = $template;
$this->user = $user;
$this->auth = $auth;
$this->phpbb_log = $log;
$this->log = $log;
$this->db = $db;
$this->cache = $cache;
$this->table_prefix = $table_prefix;
$this->mchat_table = $mchat_table;
$this->mchat_config_table = $mchat_config_table;
$this->mchat_sessions_table = $mchat_sessions_table;
}
// mchat_cache
/**
* builds the cache if it doesn't exist
*/
* Builds the cache if it doesn't exist
*/
function mchat_cache()
{
// Grab the config entries in the ACP...and cache em :P
if (($config_mchat = $this->cache->get('_mchat_config')) === false)
$config_mchat = $this->cache->get('_mchat_config');
if ($config_mchat === false)
{
$sql = 'SELECT *
FROM ' . $this->mchat_config_table;
$result = $this->db->sql_query($sql);
$rows = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result);
$config_mchat = array();
while ($row = $this->db->sql_fetchrow($result))
foreach ($rows as $row)
{
$config_mchat[$row['config_name']] = $row['config_value'];
}
$this->db->sql_freeresult($result);
$this->cache->put('_mchat_config', $config_mchat);
}
return $config_mchat;
}
// mchat_user_fix
/**
* @param $user_id the id of the user being deleted from the forum
*
*/
function mchat_user_fix($user_id)
{
$sql = 'UPDATE ' . $this->mchat_table . '
SET user_id = ' . ANONYMOUS . '
WHERE user_id = ' . (int) $user_id;
$this->db->sql_query($sql);
return;
}
// mchat_session_time
/**
* @param $time the amount of time to display
*
*/
* @param $time the amount of time to display
*/
function mchat_session_time($time)
{
// fix the display of the time limit
// hours, minutes, seconds
// Fix the display of the time limit
$chat_session = '';
$chat_timeout = (int) $time;
$hours = $minutes = $seconds = 0;
@@ -130,6 +108,7 @@ class functions_mchat
$chat_timeout = $chat_timeout - ($hours * 3600);
$chat_session .= $hours > 1 ? ($hours . ' ' . $this->user->lang['MCHAT_HOURS']) : ($hours . ' ' . $this->user->lang['MCHAT_HOUR']);
}
$minutes = floor($chat_timeout / 60);
if ($minutes)
{
@@ -137,20 +116,21 @@ class functions_mchat
$chat_timeout = $chat_timeout - ($minutes * 60);
$chat_session .= $minutes;
}
$seconds = ceil($chat_timeout);
if ($seconds)
{
$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);
}
// mchat_users
/**
* @param $session_time amount of time before a users session times out
*/
function mchat_users($session_time, $on_page = false)
* @param $session_time amount of time before a users session times out
*/
function mchat_users($session_time, $on_page)
{
$check_time = time() - (int) $session_time;
@@ -158,8 +138,8 @@ 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']))
// 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);
}
@@ -173,8 +153,11 @@ class functions_mchat
WHERE m.user_lastupdate > ' . $check_time . '
ORDER BY u.username ASC';
$result = $this->db->sql_query($sql);
$rows = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result);
$can_view_hidden = $this->auth->acl_get('u_viewonline');
while ($row = $this->db->sql_fetchrow($result))
foreach ($rows as $row)
{
if (!$row['user_allow_viewonline'])
{
@@ -187,13 +170,14 @@ class functions_mchat
$row['username'] = '<em>' . $row['username'] . '</em>';
}
}
$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;
}
$this->db->sql_freeresult($result);
$refresh_message = $this->mchat_session_time($session_time);
if (!$mchat_user_count)
{
return array(
@@ -212,17 +196,17 @@ class functions_mchat
}
}
// mchat_sessions
/**
* @param mixed $session_time amount of time before a user is not shown as being in the chat
*/
* @param mixed $session_time amount of time before a user is not shown as being in the chat
*/
function mchat_sessions($session_time)
{
$check_time = time() - (int) $session_time;
$sql = 'DELETE FROM ' . $this->mchat_sessions_table . ' WHERE user_lastupdate <' . $check_time;
$sql = 'DELETE FROM ' . $this->mchat_sessions_table . '
WHERE user_lastupdate <' . $check_time;
$this->db->sql_query($sql);
// insert user into the mChat sessions table
// Insert user into the mChat sessions table
if ($this->user->data['user_type'] == USER_FOUNDER || $this->user->data['user_type'] == USER_NORMAL)
{
$sql = 'SELECT *
@@ -232,163 +216,116 @@ class functions_mchat
$row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (!$row)
$sql_ary = array('user_lastupdate' => time());
if ($row)
{
$sql_ary = array(
'user_id' => $this->user->data['user_id'],
'user_lastupdate' => time(),
);
$sql = 'INSERT INTO ' . $this->mchat_sessions_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
$this->db->sql_query($sql);
$sql = 'UPDATE ' . $this->mchat_sessions_table . '
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
WHERE user_id =' . (int) $this->user->data['user_id'];
}
else
{
$sql_ary = array(
'user_lastupdate' => time(),
);
$sql = 'UPDATE ' . $this->mchat_sessions_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id =' . (int) $this->user->data['user_id'];
$this->db->sql_query($sql);
$sql_ary['user_id'] = $this->user->data['user_id'];
$sql = 'INSERT INTO ' . $this->mchat_sessions_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
}
$this->db->sql_query($sql);
}
return;
}
// mChat add-on Topic Notification
/**
* @param mixed $post_id limits deletion to a post_id in the forum
*/
* mChat add-on Topic Notification
*
* @param mixed $post_id limits deletion to a post_id in the forum
*/
function mchat_delete_topic($post_id)
{
if (!isset($post_id) || empty($post_id))
if ($post_id)
{
$sql = 'DELETE FROM ' . $this->mchat_table . '
WHERE post_id = ' . (int) $post_id;
$this->db->sql_query($sql);
}
}
/**
* AutoPrune Chats
*
* @param mixed $mchat_prune_amount set from mchat config entry
*/
function mchat_prune($mchat_prune_amount)
{
// How many chats do we have?
$sql = 'SELECT COUNT(message_id) AS messages
FROM ' . $this->mchat_table;
$result = $this->db->sql_query($sql);
$mchat_total_messages = (int) $this->db->sql_fetchfield('messages');
$this->db->sql_freeresult($result);
if ($mchat_total_messages <= $mchat_prune_amount)
{
return;
}
$sql = 'DELETE FROM ' . $this->mchat_table . '
WHERE post_id = ' . (int) $post_id;
$this->db->sql_query($sql);
return;
}
// mchat_prune
// AutoPrune Chats
/**
* @param mixed $mchat_prune_amount set from mchat config entry
*/
function mchat_prune($mchat_prune_amount)
{
// Run query to get the total message rows...
$sql = 'SELECT COUNT(message_id) AS total_messages
FROM ' . $this->mchat_table;
$result = $this->db->sql_query($sql);
$mchat_total_messages = (int) $this->db->sql_fetchfield('total_messages');
$result = $this->db->sql_query_limit('SELECT message_id
FROM '. $this->mchat_table . '
ORDER BY message_id ASC', 1);
$first_id = (int) $this->db->sql_fetchfield('message_id');
$this->db->sql_freeresult($result);
// count is below prune amount?
// do nothing
$prune = true;
if ($mchat_total_messages <= $mchat_prune_amount)
{
$prune = false;
}
// Compute the delete id
$delete_id = $mchat_total_messages - $mchat_prune_amount + $first_id;
if ($prune)
{
$result = $this->db->sql_query_limit('SELECT *
FROM '. $this->mchat_table . '
ORDER BY message_id ASC', 1);
$row = $this->db->sql_fetchrow($result);
$first_id = (int) $row['message_id'];
$this->db->sql_freeresult($result);
// compute the delete id
$delete_id = $mchat_total_messages - $mchat_prune_amount + $first_id;
// let's go delete them...if the message id is less than the delete id
$sql = 'DELETE FROM ' . $this->mchat_table . '
WHERE message_id < ' . (int) $delete_id;
$this->db->sql_query($sql);
$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED');
}
// free up some memory...variable(s) are no longer needed.
unset($mchat_total_messages);
// return to what we were doing
return;
$sql = 'DELETE FROM ' . $this->mchat_table . '
WHERE message_id < ' . (int) $delete_id;
$this->db->sql_query($sql);
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED');
}
// display_mchat_bbcodes
// can't use the default phpBB one but
// most of code is from similar function
/**
* @param mixed $mchat_prune_amount set from mchat config entry
*/
* @param mixed $mchat_prune_amount set from mchat config entry
*/
function display_mchat_bbcodes()
{
// grab the bbcodes that aren't allowed
$config_mchat = $this->cache->get('_mchat_config');
$disallowed_bbcode_array = explode('|', strtoupper($config_mchat['bbcode_disallowed']));
preg_replace('#^(.*?)=#si','$1',$disallowed_bbcode_array);
$default_bbcodes = array('b','i','u','quote','code','list','img','url','size','color','email','flash');
// let's remove the default bbcodes
if (sizeof($disallowed_bbcode_array))
$default_bbcodes = array('B', 'I', 'U', 'QUOTE', 'CODE', 'LIST', 'IMG', 'URL', 'SIZE', 'COLOR', 'EMAIL', 'FLASH');
$disallowed_bbcode_array = $this->get_disallowed_bbcodes();
// Let's remove the default bbcodes
if (!empty($disallowed_bbcode_array))
{
$disallowed_bbcode_array = array_map('strtoupper', $disallowed_bbcode_array);
foreach ($default_bbcodes as $default_bbcode)
{
$default_bbcode = strtoupper($default_bbcode);
if (!in_array($default_bbcode, $disallowed_bbcode_array))
{
$this->template->assign_vars(array(
'S_MCHAT_BBCODE_'.$default_bbcode => true,
'S_MCHAT_BBCODE_' . $default_bbcode => true,
));
}
}
}
// now for the custom bbcodes
// Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
$num_predefined_bbcodes = 22;
$sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline
FROM ' . BBCODES_TABLE . '
WHERE display_on_posting = 1
ORDER BY bbcode_tag';
$result = $this->db->sql_query($sql);
$i = 0;
while ($row = $this->db->sql_fetchrow($result))
{
$bbcode_tag_name = strtoupper($row['bbcode_tag']);
if (sizeof($disallowed_bbcode_array))
{
if (in_array($bbcode_tag_name, $disallowed_bbcode_array))
{
continue;
}
}
// If the helpline is defined within the language file, we will use the localised version, else just use the database entry...
if (isset($this->user->lang[strtoupper($row['bbcode_helpline'])]))
{
$row['bbcode_helpline'] = $this->user->lang[strtoupper($row['bbcode_helpline'])];
}
$this->template->assign_block_vars('custom_tags', array(
'BBCODE_NAME' => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
'BBCODE_ID' => $num_predefined_bbcodes + ($i * 2),
'BBCODE_TAG' => $row['bbcode_tag'],
'BBCODE_HELPLINE' => $row['bbcode_helpline'],
'A_BBCODE_HELPLINE' => str_replace(array('&amp;', '&quot;', "'", '&lt;', '&gt;'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']),
));
$i++;
}
$this->db->sql_freeresult($result);
// From /includes/functions_display.php
display_custom_bbcodes();
}
public function get_disallowed_bbcodes()
{
$config_mchat = $this->mchat_cache();
$disallowed_bbcode = $config_mchat['bbcode_disallowed'];
$disallowed_bbcode_array = explode('|', $disallowed_bbcode);
return $disallowed_bbcode_array;
}
function mchat_avatar($row)
{
return phpbb_get_user_avatar(array(
'avatar' => $row['user_avatar'],
'avatar_type' => $row['user_avatar_type'],
'avatar_width' => $row['user_avatar_width'] > $row['user_avatar_height'] ? 40 : (40 / $row['user_avatar_height']) * $row['user_avatar_width'],
'avatar_height' => $row['user_avatar_height'] > $row['user_avatar_width'] ? 40 : (40 / $row['user_avatar_width']) * $row['user_avatar_height'],
));
}
}

File diff suppressed because it is too large Load Diff