Update Version 0.1.0

Update Version 0.1.0
This commit is contained in:
dmzx
2015-05-02 10:58:11 +02:00
parent bdd08b5d61
commit 5f77698758
13 changed files with 753 additions and 299 deletions

View File

@@ -11,18 +11,6 @@ namespace dmzx\mchat\core;
class functions_mchat
{
/**
* CONSTANTS SECTION
*
* To access them, you need to use the class.
*
*/
const MCHAT_CONFIG_TABLE = 'mchat_config';
const MCHAT_TABLE = 'mchat';
const MCHAT_SESSIONS_TABLE = 'mchat_sessions';
/**
* End of constants
*/
/** @var \phpbb\template\template */
protected $template;
@@ -41,6 +29,17 @@ class functions_mchat
protected $table_prefix;
/**
* The database tables
*
* @var string
*/
protected $mchat_table;
protected $mchat_config_table;
protected $mchat_sessions_table;
/**
* Constructor
*
@@ -51,7 +50,7 @@ class functions_mchat
* @param \phpbb\cache\service $cache
* @param $table_prefix
*/
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)
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)
{
$this->template = $template;
$this->user = $user;
@@ -60,6 +59,9 @@ class functions_mchat
$this->cache = $cache;
$this->phpbb_log = $log;
$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
@@ -71,7 +73,7 @@ class functions_mchat
// Grab the config entries in teh ACP...and cache em :P
if (($config_mchat = $this->cache->get('_mchat_config')) === false)
{
$sql = 'SELECT * FROM ' . $this->table_prefix . self::MCHAT_CONFIG_TABLE;
$sql = 'SELECT * FROM ' . $this->mchat_config_table;
$result = $this->db->sql_query($sql);
$config_mchat = array();
while ($row = $this->db->sql_fetchrow($result))
@@ -91,7 +93,7 @@ class functions_mchat
*/
function mchat_user_fix($user_id)
{
$sql = 'UPDATE ' . $this->table_prefix . self::MCHAT_TABLE . '
$sql = 'UPDATE ' . $this->mchat_table . '
SET user_id = ' . ANONYMOUS . '
WHERE user_id = ' . (int) $user_id;
$this->db->sql_query($sql);
@@ -142,7 +144,7 @@ class functions_mchat
{
$check_time = time() - (int) $session_time;
$sql = 'DELETE FROM ' . $this->table_prefix . self::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);
// add the user into the sessions upon first visit
@@ -155,7 +157,7 @@ class functions_mchat
$mchat_user_list = '';
$sql = 'SELECT m.user_id, u.username, u.user_type, u.user_allow_viewonline, u.user_colour
FROM ' . $this->table_prefix . self::MCHAT_SESSIONS_TABLE . ' m
FROM ' . $this->mchat_sessions_table . ' m
LEFT JOIN ' . USERS_TABLE . ' u ON m.user_id = u.user_id
WHERE m.user_lastupdate > ' . $check_time . '
ORDER BY u.username ASC';
@@ -206,13 +208,13 @@ class functions_mchat
function mchat_sessions($session_time)
{
$check_time = time() - (int) $session_time;
$sql = 'DELETE FROM ' . $this->table_prefix . self::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
if ($this->user->data['user_type'] == USER_FOUNDER || $this->user->data['user_type'] == USER_NORMAL)
{
$sql = 'SELECT * FROM ' . $this->table_prefix . self::MCHAT_SESSIONS_TABLE . ' WHERE user_id =' . (int) $this->user->data['user_id'];
$sql = 'SELECT * FROM ' . $this->mchat_sessions_table . ' 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);
@@ -223,7 +225,7 @@ class functions_mchat
'user_id' => $this->user->data['user_id'],
'user_lastupdate' => time(),
);
$sql = 'INSERT INTO ' . $this->table_prefix . self::MCHAT_SESSIONS_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
$sql = 'INSERT INTO ' . $this->mchat_sessions_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
$this->db->sql_query($sql);
}
else
@@ -231,7 +233,7 @@ class functions_mchat
$sql_ary = array(
'user_lastupdate' => time(),
);
$sql = 'UPDATE ' . $this->table_prefix . self::MCHAT_SESSIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id =' . (int) $this->user->data['user_id'];
$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);
}
}
@@ -249,7 +251,7 @@ class functions_mchat
return;
}
$sql = 'DELETE FROM ' . $this->table_prefix . self::MCHAT_TABLE . ' WHERE post_id = ' . (int) $post_id;
$sql = 'DELETE FROM ' . $this->mchat_table . ' WHERE post_id = ' . (int) $post_id;
$this->db->sql_query($sql);
return;
@@ -263,7 +265,7 @@ class functions_mchat
function mchat_prune($mchat_prune_amount)
{
// Run query to get the total message rows...
$sql = 'SELECT COUNT(message_id) AS total_messages FROM ' . $this->table_prefix . self::MCHAT_TABLE;
$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');
$this->db->sql_freeresult($result);
@@ -279,7 +281,7 @@ class functions_mchat
if ($prune)
{
$result = $this->db->sql_query_limit('SELECT * FROM '. $this->table_prefix . self::MCHAT_TABLE . ' ORDER BY message_id ASC', 1);
$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'];
@@ -289,7 +291,7 @@ class functions_mchat
$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->table_prefix . self::MCHAT_TABLE . '
$sql = 'DELETE FROM ' . $this->mchat_table . '
WHERE message_id < ' . (int) $delete_id;
$this->db->sql_query($sql);

View File

@@ -41,6 +41,12 @@ class render_helper
protected $phpbb_root_path;
protected $phpEx;
protected $table_prefix;
/**
* The database tables
*
* @var string
*/
protected $mchat_table;
/**
* Constructor
@@ -58,7 +64,7 @@ class render_helper
* @param $phpEx
* @param $table_prefix
*/
public function __construct(\dmzx\mchat\core\functions_mchat $functions_mchat, \phpbb\config\config $config, \phpbb\controller\helper $helper, \phpbb\template\template $template, \phpbb\log\log_interface $log, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, \phpbb\request\request $request, $phpbb_root_path, $phpEx, $table_prefix)
public function __construct(\dmzx\mchat\core\functions_mchat $functions_mchat, \phpbb\config\config $config, \phpbb\controller\helper $helper, \phpbb\template\template $template, \phpbb\log\log_interface $log, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, \phpbb\pagination $pagination, \phpbb\request\request $request, $phpbb_root_path, $phpEx, $table_prefix, $mchat_table)
{
$this->functions_mchat = $functions_mchat;
$this->config = $config;
@@ -68,11 +74,13 @@ class render_helper
$this->auth = $auth;
$this->db = $db;
$this->cache = $cache;
$this->pagination = $pagination;
$this->request = $request;
$this->phpbb_root_path = $phpbb_root_path;
$this->phpEx = $phpEx;
$this->phpbb_log = $log;
$this->table_prefix = $table_prefix;
$this->mchat_table = $mchat_table;
}
/**
@@ -160,7 +168,7 @@ class render_helper
foreach ($mchat_rules as $mchat_rule)
{
$mchat_rule = htmlspecialchars($mchat_rule);
$mchat_rule = utf8_htmlspecialchars($mchat_rule);
$this->template->assign_block_vars('rule', array(
'MCHAT_RULE' => $mchat_rule,
));
@@ -234,7 +242,7 @@ class render_helper
if(confirm_box(true))
{
// Run cleaner
$sql = 'TRUNCATE TABLE ' . $this->table_prefix . \dmzx\mchat\core\functions_mchat::MCHAT_TABLE;
$sql = 'TRUNCATE TABLE ' . $this->mchat_table;
$this->db->sql_query($sql);
meta_refresh(3, $mchat_redirect);
@@ -264,7 +272,7 @@ class render_helper
if ($this->config['mchat_enable'] && $mchat_read_archive && $mchat_view)
{
// how many chats do we have?
$sql = 'SELECT COUNT(message_id) AS messages FROM ' . $this->table_prefix . \dmzx\mchat\core\functions_mchat::MCHAT_TABLE;
$sql = 'SELECT COUNT(message_id) AS messages FROM ' . $this->mchat_table;
$result = $this->db->sql_query($sql);
$mchat_total_messages = $this->db->sql_fetchfield('messages');
$this->db->sql_freeresult($result);
@@ -279,7 +287,7 @@ class render_helper
$sql_where = $this->user->data['user_mchat_topics'] ? '' : 'WHERE m.forum_id = 0';
// Message row
$sql = '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 ' . $this->table_prefix . \dmzx\mchat\core\functions_mchat::MCHAT_TABLE . ' m
FROM ' . $this->mchat_table . ' m
LEFT JOIN ' . USERS_TABLE . ' u ON m.user_id = u.user_id
' . $sql_where . '
ORDER BY m.message_id DESC';
@@ -341,15 +349,19 @@ class render_helper
}
// Run query again to get the total message rows...
$sql = 'SELECT COUNT(message_id) AS mess_id FROM ' . $this->table_prefix . \dmzx\mchat\core\functions_mchat::MCHAT_TABLE;
$sql = 'SELECT COUNT(message_id) AS mess_id FROM ' . $this->mchat_table;
$result = $this->db->sql_query($sql);
$mchat_total_message = $this->db->sql_fetchfield('mess_id');
$this->db->sql_freeresult($result);
// Page list function...
$pagination_url = $this->helper->route('dmzx_mchat_controller', array('mode' => 'archive'));
$start = $this->request->variable('start', 0);
$this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $mchat_total_message, (int) $this->config_mchat['archive_limit'], $mchat_archive_start);
$this->template->assign_vars(array(
// 'MCHAT_PAGE_NUMBER' => $pagination->get_on_page($mchat_total_message, (int) $this->config_mchat['archive_limit'], $mchat_archive_start),
'MCHAT_TOTAL_MESSAGES' => sprintf($this->user->lang['MCHAT_TOTALMESSAGES'], $mchat_total_message),
//\\ 'MCHAT_PAGINATION' => generate_pagination(append_sid("{$this->phpbb_root_path}mchat.{$this->phpEx}", 'mode=archive'), $mchat_total_message, (int) $this->config_mchat['archive_limit'], $mchat_archive_start, true)
));
//add to navlinks
@@ -382,7 +394,7 @@ class render_helper
$mchat_message_last_id = $this->request->variable('message_last_id', 0);
$sql_and = $this->user->data['user_mchat_topics'] ? '' : 'AND m.forum_id = 0';
$sql = '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 ' . $this->table_prefix . \dmzx\mchat\core\functions_mchat::MCHAT_TABLE . ' m, ' . USERS_TABLE . ' u
FROM ' . $this->mchat_table . ' m, ' . USERS_TABLE . ' u
WHERE m.user_id = u.user_id
AND m.message_id > ' . (int) $mchat_message_last_id . '
' . $sql_and . '
@@ -532,7 +544,7 @@ class render_helper
if (!$mchat_no_flood && $this->config_mchat['flood_time'])
{
$mchat_flood_current_time = time();
$sql = 'SELECT message_time FROM ' . $this->table_prefix . \dmzx\mchat\core\functions_mchat::MCHAT_TABLE . '
$sql = 'SELECT message_time FROM ' . $this->mchat_table . '
WHERE user_id = ' . (int) $this->user->data['user_id'] . '
ORDER BY message_time DESC';
$result = $this->db->sql_query_limit($sql, 1);
@@ -594,7 +606,7 @@ class render_helper
'bbcode_options' => $options,
'message_time' => time()
);
$sql = 'INSERT INTO ' . $this->table_prefix . \dmzx\mchat\core\functions_mchat::MCHAT_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
$sql = 'INSERT INTO ' . $this->mchat_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
$this->db->sql_query($sql);
// reset the config settings
@@ -638,7 +650,7 @@ class render_helper
// check for the correct user
$sql = 'SELECT *
FROM ' . $this->table_prefix . \dmzx\mchat\core\functions_mchat::MCHAT_TABLE . '
FROM ' . $this->mchat_table . '
WHERE message_id = ' . (int) $message_id;
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
@@ -717,13 +729,13 @@ class render_helper
'bbcode_options' => $options
);
$sql = 'UPDATE ' . $this->table_prefix . \dmzx\mchat\core\functions_mchat::MCHAT_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary).'
$sql = 'UPDATE ' . $this->mchat_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary).'
WHERE message_id = ' . (int) $message_id;
$this->db->sql_query($sql);
// Message edited...now read it
$sql = '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 ' . $this->table_prefix . \dmzx\mchat\core\functions_mchat::MCHAT_TABLE . ' m, ' . USERS_TABLE . ' u
FROM ' . $this->mchat_table . ' m, ' . USERS_TABLE . ' u
WHERE m.user_id = u.user_id
AND m.message_id = ' . (int) $message_id . '
ORDER BY m.message_id DESC';
@@ -793,7 +805,7 @@ class render_helper
}
// check for the correct user
$sql = 'SELECT m.*, u.username, u.user_colour
FROM ' . $this->table_prefix . \dmzx\mchat\core\functions_mchat::MCHAT_TABLE . ' m
FROM ' . $this->mchat_table . ' m
LEFT JOIN ' . USERS_TABLE . ' u ON m.user_id = u.user_id
WHERE m.message_id = ' . (int) $message_id;
$result = $this->db->sql_query($sql);
@@ -811,7 +823,7 @@ class render_helper
}
// Run delete!
$sql = 'DELETE FROM ' . $this->table_prefix . \dmzx\mchat\core\functions_mchat::MCHAT_TABLE . '
$sql = 'DELETE FROM ' . $this->mchat_table . '
WHERE message_id = ' . (int) $message_id;
$this->db->sql_query($sql);
//adds a log
@@ -857,7 +869,7 @@ class render_helper
// user has permissions to view the custom chat?
if (!$mchat_view && $mchat_custom_page)
{
trigger_error($user->lang['NOT_AUTHORISED'], E_USER_NOTICE);
trigger_error('NOT_AUTHORISED', E_USER_NOTICE);
}
// if whois true
@@ -917,7 +929,7 @@ class render_helper
$sql_where = $this->user->data['user_mchat_topics'] ? '' : 'WHERE m.forum_id = 0';
// Message row
$sql = '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 ' . $this->table_prefix . \dmzx\mchat\core\functions_mchat::MCHAT_TABLE . ' m
FROM ' . $this->mchat_table . ' m
LEFT JOIN ' . USERS_TABLE . ' u ON m.user_id = u.user_id
' . $sql_where . '
ORDER BY message_id DESC';