diff --git a/adm/style/acp_users_mchat.html b/adm/style/acp_users_mchat.html
index b6421ce..869376f 100644
--- a/adm/style/acp_users_mchat.html
+++ b/adm/style/acp_users_mchat.html
@@ -48,4 +48,4 @@
{S_FORM_TOKEN}
-
\ No newline at end of file
+
diff --git a/config/services.yml b/config/services.yml
index 7318c94..9dea54b 100644
--- a/config/services.yml
+++ b/config/services.yml
@@ -8,15 +8,14 @@ services:
- @dmzx.mchat.functions_mchat
- @config
- @template
+ - @log
- @user
- - @service_container
- @dbal.conn
- @cache
- @request
- @ext.manager
- %core.root_path%
- %core.php_ext%
- - %core.table_prefix%
- %dmzx.mchat.table.mchat_config%
dmzx.mchat.controller:
class: dmzx\mchat\controller\mchat
@@ -35,13 +34,11 @@ services:
- @user
- @auth
- @dbal.conn
- - @cache
- @pagination
- @request
- @dispatcher
- %core.root_path%
- %core.php_ext%
- - %core.table_prefix%
- %dmzx.mchat.table.mchat%
dmzx.mchat.functions_mchat:
class: dmzx\mchat\core\functions_mchat
@@ -52,7 +49,6 @@ services:
- @log
- @dbal.conn
- @cache
- - %core.table_prefix%
- %dmzx.mchat.table.mchat%
- %dmzx.mchat.table.mchat_config%
- %dmzx.mchat.table.mchat_sessions%
@@ -66,9 +62,7 @@ services:
- @template
- @user
- @dbal.conn
- - @service_container
- %core.php_ext%
- - %core.table_prefix%
- %dmzx.mchat.table.mchat%
tags:
- { name: event.listener }
\ No newline at end of file
diff --git a/controller/admin_controller.php b/controller/admin_controller.php
index 655a616..439eeb8 100644
--- a/controller/admin_controller.php
+++ b/controller/admin_controller.php
@@ -20,12 +20,12 @@ class admin_controller
/** @var \phpbb\template\template */
protected $template;
+ /** @var \phpbb\log\log_interface */
+ protected $log;
+
/** @var \phpbb\user */
protected $user;
- /** @var ContainerInterface */
- protected $container;
-
/** @var \phpbb\db\driver\driver_interface */
protected $db;
@@ -45,57 +45,41 @@ class admin_controller
protected $phpEx;
/** @var string */
- protected $table_prefix;
+ protected $mchat_config_table;
/** @var string */
public $u_action;
- /**
- * The database table
- *
- * @var string
- */
- protected $mchat_config_table;
-
- /** @var \phpbb\config\db_text */
- protected $config_text;
-
/**
* Constructor
*
* @param \dmzx\mchat\core\functions_mchat $functions_mchat
* @param \phpbb\config\config $config
* @param \phpbb\template\template $template
+ * @param \phpbb\log\log_interface $log
* @param \phpbb\user $user
- * @param ContainerInterface $container
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\cache\service $cache
* @param \phpbb\request\request $request
* @param \phpbb\extension\manager $phpbb_extension_manager
- * @param $phpbb_root_path
- * @param $phpEx
- * @param $table_prefix
- * @param $mchat_config_table
- * @param \phpbb\config\db_text $config_text
- *
+ * @param string $phpbb_root_path
+ * @param string $phpEx
+ * @param string $mchat_config_table
*/
-
- public function __construct(\dmzx\mchat\core\functions_mchat $functions_mchat, \phpbb\config\config $config, \phpbb\template\template $template, \phpbb\user $user, $container, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, \phpbb\request\request $request, \phpbb\extension\manager $phpbb_extension_manager, $phpbb_root_path, $phpEx, $table_prefix, $mchat_config_table)
+ public function __construct(\dmzx\mchat\core\functions_mchat $functions_mchat, \phpbb\config\config $config, \phpbb\template\template $template, \phpbb\log\log_interface $log, \phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, \phpbb\request\request $request, \phpbb\extension\manager $phpbb_extension_manager, $phpbb_root_path, $phpEx, $mchat_config_table)
{
- $this->functions_mchat = $container->get('dmzx.mchat.functions_mchat');
+ $this->functions_mchat = $functions_mchat;
$this->config = $config;
$this->template = $template;
+ $this->log = $log;
$this->user = $user;
- $this->container = $container;
$this->db = $db;
$this->cache = $cache;
$this->request = $request;
$this->phpbb_extension_manager = $phpbb_extension_manager;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
- $this->table_prefix = $container->getParameter('core.table_prefix');
$this->mchat_config_table = $mchat_config_table;
- $this->config_text = $container->get('config_text');
}
/**
@@ -181,8 +165,7 @@ class admin_controller
$this->set_options();
// and an entry into the log table
- $log = $this->container->get('log');
- $log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_CONFIG_UPDATE');
+ $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_CONFIG_UPDATE');
// purge the cache
$this->cache->destroy('_mchat_config');
diff --git a/controller/mchat.php b/controller/mchat.php
index f39232c..c725687 100644
--- a/controller/mchat.php
+++ b/controller/mchat.php
@@ -11,24 +11,22 @@ namespace dmzx\mchat\controller;
class mchat
{
- /** @var \dmzx\mchat\core\render_helper */
+ /** @var \dmzx\mchat\core\render_helper*/
protected $render_helper;
- /** @var \phpbb\controller\helper */
+ /** @var \phpbb\controller\helper*/
protected $helper;
- /** @var \phpbb\request\request */
+ /** @var \phpbb\request\request*/
protected $request;
/**
* Constructor
*
- * @param \dmzx\mchat\core\render_helper $render_helper
+ * @param \dmzx\mchat\core\render_helper $render_helper
* @param \phpbb\controller\helper $helper
- * @param \phpbb\request\request $request
- *
+ * @param \phpbb\request\request $request
*/
-
public function __construct(\dmzx\mchat\core\render_helper $render_helper, \phpbb\controller\helper $helper, \phpbb\request\request $request)
{
$this->render_helper = $render_helper;
@@ -43,7 +41,7 @@ class mchat
*/
public function handle()
{
- $ret = $this->render_helper->render_data_for_page();
+ $ret = $this->render_helper->render_data_for_page(false);
// If this was an ajax request, we just create an json_response and return that. It's not ours to handle here.
if ($this->request->is_ajax() && is_array($ret) && isset($ret['json']) && $ret['json'] === true)
diff --git a/core/functions_mchat.php b/core/functions_mchat.php
index d7719cf..502a811 100644
--- a/core/functions_mchat.php
+++ b/core/functions_mchat.php
@@ -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'] = '' . $row['username'] . '';
}
}
+
$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('&', '"', "'", '<', '>'), 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'],
+ ));
}
}
diff --git a/core/render_helper.php b/core/render_helper.php
index 7abf84e..5ca2b00 100644
--- a/core/render_helper.php
+++ b/core/render_helper.php
@@ -35,30 +35,22 @@ class render_helper
/** @var \phpbb\db\driver\driver_interface */
protected $db;
- /** @var \phpbb\cache\service */
- protected $cache;
-
/** @var \phpbb\request\request */
protected $request;
/** @var \phpbb\event\dispatcher_interface */
protected $dispatcher;
- /** @var string phpBB root path */
+ /** @var string */
protected $phpbb_root_path;
/** @var string */
protected $phpEx;
/** @var string */
- protected $table_prefix;
-
- /**
- * The database tables
- *
- * @var string
- */
protected $mchat_table;
+
+ public $initialized = false;
/**
* Constructor
@@ -71,17 +63,13 @@ class render_helper
* @param \phpbb\user $user
* @param \phpbb\auth\auth $auth
* @param \phpbb\db\driver\driver_interface $db
- * @param \phpbb\cache\service $cache
* @param \phpbb\request\request $request
* @param \phpbb\event\dispatcher_interface $dispatcher
- * @param $phpbb_root_path
- * @param $phpEx
- * @param $table_prefix
- * @param $mchat_table
- *
+ * @param string $phpbb_root_path
+ * @param string $phpEx
+ * @param string $mchat_table
*/
-
- 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\event\dispatcher_interface $dispatcher, $phpbb_root_path, $phpEx, $table_prefix, $mchat_table)
+ 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\pagination $pagination, \phpbb\request\request $request, \phpbb\event\dispatcher_interface $dispatcher, $phpbb_root_path, $phpEx, $mchat_table)
{
$this->functions_mchat = $functions_mchat;
$this->config = $config;
@@ -91,103 +79,92 @@ class render_helper
$this->user = $user;
$this->auth = $auth;
$this->db = $db;
- $this->cache = $cache;
$this->pagination = $pagination;
$this->request = $request;
$this->dispatcher = $dispatcher;
$this->phpbb_root_path = $phpbb_root_path;
$this->phpEx = $phpEx;
- $this->table_prefix = $table_prefix;
$this->mchat_table = $mchat_table;
}
/**
- * Method to render the page data
- *
- * @var bool Bool if the rendering is only for index
- * @return array Data for page rendering
- */
- public function render_data_for_page($only_for_index = false)
+ * Method to render the page data
+ *
+ * @var bool Bool if the rendering is only for index
+ * @return array Data for page rendering
+ */
+ public function render_data_for_page($include_on_index)
{
- $include_on_index = ($only_for_index === true);
-
// Add lang file
$this->user->add_lang('posting');
- //chat enabled
+ $this->initialized = true;
+
if (!$this->config['mchat_enable'])
{
$this->template->assign_vars(array(
- 'L_MCHAT_DISABLE' => $this->user->lang['MCHAT_ENABLE'],
- 'S_MCHAT_MESSAGE' => (!$this->config['mchat_enable']) ? true : false,
+ 'S_MCHAT_DISABLED' => true,
));
}
- // avatars
- if (!function_exists('get_user_avatar'))
+ // Avatars & BBCodes
+ if (!function_exists('display_custom_bbcodes'))
{
include($this->phpbb_root_path . 'includes/functions_display.' . $this->phpEx);
}
- if (($this->config_mchat = $this->cache->get('_mchat_config')) === false)
- {
- $this->functions_mchat->mchat_cache();
- }
- $this->config_mchat = $this->cache->get('_mchat_config');
- // Access rights
- $mchat_allow_bbcode = ($this->config['allow_bbcode'] && $this->auth->acl_get('u_mchat_bbcode')) ? true : false;
- $mchat_smilies = ($this->config['allow_smilies'] && $this->auth->acl_get('u_mchat_smilies')) ? true : false;
- $mchat_urls = ($this->config['allow_post_links'] && $this->auth->acl_get('u_mchat_urls')) ? true : false;
- $mchat_ip = ($this->auth->acl_get('u_mchat_ip')) ? true : false;
- $mchat_pm = ($this->auth->acl_get('u_mchat_pm')) ? true : false;
- $mchat_like = ($this->auth->acl_get('u_mchat_like')) ? true : false;
- $mchat_quote = ($this->auth->acl_get('u_mchat_quote')) ? true : false;
- $mchat_add_mess = ($this->auth->acl_get('u_mchat_use')) ? true : false;
- $mchat_view = ($this->auth->acl_get('u_mchat_view')) ? true : false;
- $mchat_no_flood = ($this->auth->acl_get('u_mchat_flood_ignore')) ? true : false;
- $mchat_read_archive = ($this->auth->acl_get('u_mchat_archive')) ? true : false;
- $mchat_founder = ($this->user->data['user_type'] == USER_FOUNDER) ? true : false;
- $mchat_session_time = !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_rules = (!empty($this->config_mchat['rules']) || isset($this->user->lang[strtoupper('mchat_rules')])) ? true : false;
- $mchat_avatars = (!empty($this->config_mchat['avatars']) && $this->user->optionget('viewavatars') && $this->user->data['user_mchat_avatars']) ? true : false;
+ $config_mchat = $this->functions_mchat->mchat_cache();
- // needed variables
- // Request options.
+ // Access rights
+ $mchat_allow_bbcode = $this->config['allow_bbcode'] && $this->auth->acl_get('u_mchat_bbcode');
+ $mchat_smilies = $this->config['allow_smilies'] && $this->auth->acl_get('u_mchat_smilies');
+ $mchat_urls = $this->config['allow_post_links'] && $this->auth->acl_get('u_mchat_urls');
+ $mchat_ip = $this->auth->acl_get('u_mchat_ip');
+ $mchat_pm = $this->auth->acl_get('u_mchat_pm');
+ $mchat_like = $this->auth->acl_get('u_mchat_like');
+ $mchat_quote = $this->auth->acl_get('u_mchat_quote');
+ $mchat_add_mess = $this->auth->acl_get('u_mchat_use');
+ $mchat_view = $this->auth->acl_get('u_mchat_view');
+ $mchat_no_flood = $this->auth->acl_get('u_mchat_flood_ignore');
+ $mchat_read_archive = $this->auth->acl_get('u_mchat_archive');
+ $mchat_founder = $this->user->data['user_type'] == USER_FOUNDER;
+ $mchat_session_time = !empty($config_mchat['timeout']) ? $config_mchat['timeout'] : (!empty($this->config['load_online_time']) ? $this->config['load_online_time'] * 60 : $this->config['session_length']);
+ $mchat_rules = !empty($config_mchat['rules']) || isset($this->user->lang[strtoupper('mchat_rules')]);
+ $mchat_avatars = !empty($config_mchat['avatars']) && $this->user->optionget('viewavatars') && $this->user->data['user_mchat_avatars'];
+
+ // Request variables
$mchat_mode = $this->request->variable('mode', '');
$mchat_read_mode = $mchat_archive_mode = $mchat_custom_page = $mchat_no_message = false;
- // set redirect if on index or custom page
- $on_page = $include_on_index ? 'index' : 'mchat';
- // grab fools..uhmmm, foes the user has
- $foes_array = array();
+ // Grab fools..uhmmm, foes the user has
$sql = 'SELECT *
FROM ' . ZEBRA_TABLE . '
WHERE user_id = ' . $this->user->data['user_id'] . '
AND foe = 1';
$result = $this->db->sql_query($sql);
- while ($row = $this->db->sql_fetchrow($result))
+ $rows = $this->db->sql_fetchrowset($result);
+ $this->db->sql_freeresult($result);
+
+ $foes_array = array();
+ foreach ($rows as $row)
{
$foes_array[] = $row['zebra_id'];
}
- $this->db->sql_freeresult($result);
- // Request mode...
+ // Request mode
switch ($mchat_mode)
{
- // rules popup..
case 'rules':
// If the rules are defined in the language file use them, else just use the entry in the database
if ($mchat_rules || isset($this->user->lang[strtoupper('mchat_rules')]))
{
- if(isset($this->user->lang[strtoupper('mchat_rules')]))
+ if (isset($this->user->lang[strtoupper('mchat_rules')]))
{
$this->template->assign_var('MCHAT_RULES', $this->user->lang[strtoupper('mchat_rules')]);
}
else
{
- $mchat_rules = $this->config_mchat['rules'];
- $mchat_rules = explode("\n", $mchat_rules);
-
+ $mchat_rules = explode("\n", $config_mchat['rules']);
foreach ($mchat_rules as $mchat_rule)
{
$mchat_rule = utf8_htmlspecialchars($mchat_rule);
@@ -197,71 +174,59 @@ class render_helper
}
}
- // Output the page
- // Return for: \$this->helper->render(filename, lang_title);
+ // Return for $this->helper->render(filename, lang_title);
return array(
'filename' => 'mchat_rules.html',
'lang_title' => $this->user->lang['MCHAT_HELP'],
);
}
- else
- {
- // Show no rules
- trigger_error('MCHAT_NO_RULES', E_USER_NOTICE);
- }
+
+ // Show no rules
+ trigger_error('MCHAT_NO_RULES', E_USER_NOTICE);
break;
- // whois function..
- case 'whois':
- // Must have auths
- if ($mchat_mode == 'whois' && $mchat_ip)
+ case 'whois':
+ if ($mchat_mode === 'whois' && $mchat_ip)
{
- // function already exists..
if (!function_exists('user_ipwhois'))
{
include($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx);
}
- $this->user_ip = $this->request->variable('ip', '');
-
- $this->template->assign_var('WHOIS', user_ipwhois($this->user_ip));
+ $user_ip = $this->request->variable('ip', '');
+ $this->template->assign_var('WHOIS', user_ipwhois($user_ip));
// Output the page
- // Return for: \$this->helper->render(filename, lang_title);
+ // Return for $this->helper->render(filename, lang_title);
return array(
'filename' => 'viewonline_whois.html',
'lang_title' => $this->user->lang['WHO_IS_ONLINE'],
);
}
- else
+
+ // Show not authorized
+ trigger_error('NO_AUTH_OPERATION', E_USER_NOTICE);
+
+ break;
+
+ case 'clean':
+ if (!$this->user->data['is_registered'])
+ {
+ // Login box
+ login_box('', $this->user->lang['LOGIN']);
+ }
+
+ if (!$mchat_founder)
{
// Show not authorized
trigger_error('NO_AUTH_OPERATION', E_USER_NOTICE);
}
- break;
- // Clean function...
- case 'clean':
-
- // User logged in?
- if(!$this->user->data['is_registered'] || !$mchat_founder)
- {
- if(!$this->user->data['is_registered'])
- {
- // Login box...
- login_box('', $this->user->lang['LOGIN']);
- }
- else if (!$mchat_founder)
- {
- // Show not authorized
- trigger_error('NO_AUTH_OPERATION', E_USER_NOTICE);
- }
- }
-
+
$mchat_redirect = $this->request->variable('redirect', '');
$mchat_redirect = ($mchat_redirect == 'index') ? append_sid("{$this->phpbb_root_path}index.{$this->phpEx}") : $this->helper->route('dmzx_mchat_controller', array('#mChat'));
- if(confirm_box(true))
+ if (confirm_box(true))
{
// Run cleaner
$sql = 'TRUNCATE TABLE ' . $this->mchat_table;
@@ -275,17 +240,19 @@ class render_helper
// Display confirm box
confirm_box(false, $this->user->lang['MCHAT_DELALLMESS']);
}
+
$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED');
redirect($mchat_redirect);
+
break;
- // Archive function...
- case 'archive':
+ case 'archive':
if (!$mchat_read_archive || !$mchat_view)
{
- // redirect to correct page
+ // Redirect to correct page
$mchat_redirect = append_sid("{$this->phpbb_root_path}index.{$this->phpEx}");
+
// Redirect to previous page
meta_refresh(3, $mchat_redirect);
trigger_error($this->user->lang['MCHAT_NOACCESS_ARCHIVE']. '
' . sprintf($this->user->lang['RETURN_PAGE'], '', ''));
@@ -293,73 +260,67 @@ 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->mchat_table;
- $result = $this->db->sql_query($sql);
- $mchat_total_messages = $this->db->sql_fetchfield('messages');
- $this->db->sql_freeresult($result);
- // prune the chats if necessary and amount in ACP not empty
- if ($this->config_mchat['prune_enable'] && ($mchat_total_messages > $this->config_mchat['prune_num'] && $this->config_mchat['prune_num'] > 0))
+ // Prune the chats
+ if ($config_mchat['prune_enable'] && $config_mchat['prune_num'] > 0)
{
- $this->functions_mchat->mchat_prune((int) $this->config_mchat['prune_num']);
+ $this->functions_mchat->mchat_prune($config_mchat['prune_num']);
}
- // Reguest...
$mchat_archive_start = $this->request->variable('start', 0);
$sql_where = $this->user->data['user_mchat_topics'] ? '' : 'WHERE m.forum_id = 0';
- // Message row
+
+ // Fetch message rows
$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->mchat_table . ' m
LEFT JOIN ' . USERS_TABLE . ' u ON m.user_id = u.user_id
' . $sql_where . '
ORDER BY m.message_id DESC';
- $result = $this->db->sql_query_limit($sql, (int) $this->config_mchat['archive_limit'], $mchat_archive_start);
+ $result = $this->db->sql_query_limit($sql, (int) $config_mchat['archive_limit'], $mchat_archive_start);
$rows = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result);
- foreach($rows as $row)
+ foreach ($rows as $row)
{
- // auth check
- if ($row['forum_id'] != 0 && !$this->auth->acl_get('f_read', $row['forum_id']))
+ if ($row['forum_id'] && !$this->auth->acl_get('f_read', $row['forum_id']))
{
continue;
}
- // edit, delete and permission auths
- $mchat_ban = ($this->auth->acl_get('a_authusers') && $this->user->data['user_id'] != $row['user_id']) ? true : false;
- $mchat_edit = ($this->auth->acl_get('u_mchat_edit') && ($this->auth->acl_get('m_') || $this->user->data['user_id'] == $row['user_id'])) ? true : false;
- $mchat_del = ($this->auth->acl_get('u_mchat_delete') && ($this->auth->acl_get('m_') || $this->user->data['user_id'] == $row['user_id'])) ? true : false;
- $mchat_avatar = $row['user_avatar'] ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], ($row['user_avatar_width'] > $row['user_avatar_height']) ? 40 : (40 / $row['user_avatar_height']) * $row['user_avatar_width'], ($row['user_avatar_height'] > $row['user_avatar_width']) ? 40 : (40 / $row['user_avatar_width']) * $row['user_avatar_height']) : '';
- $message_edit = $row['message'];
+
+ // Edit, delete and permission auths
+ $mchat_ban = $this->auth->acl_get('a_authusers') && $this->user->data['user_id'] != $row['user_id'];
+ $mchat_edit = $this->auth->acl_get('u_mchat_edit') && ($this->auth->acl_get('m_') || $this->user->data['user_id'] == $row['user_id']);
+ $mchat_del = $this->auth->acl_get('u_mchat_delete') && ($this->auth->acl_get('m_') || $this->user->data['user_id'] == $row['user_id']);
+ $message_edit = $row['message'];
+
decode_message($message_edit, $row['bbcode_uid']);
- $message_edit = str_replace('"', '"', $message_edit); // Edit Fix ;)
- if (sizeof($foes_array))
+ $message_edit = str_replace('"', '"', $message_edit);
+
+ if (!empty($foes_array) && in_array($row['user_id'], $foes_array))
{
- if (in_array($row['user_id'], $foes_array))
- {
- $row['message'] = sprintf($this->user->lang['MCHAT_FOE'], get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']));
- }
+ $row['message'] = sprintf($this->user->lang['MCHAT_FOE'], get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']));
}
+
$row['username'] = mb_ereg_replace("'", "", $row['username']);
+
$this->template->assign_block_vars('mchatrow', array(
'MCHAT_ALLOW_BAN' => $mchat_ban,
'MCHAT_ALLOW_EDIT' => $mchat_edit,
'MCHAT_ALLOW_DEL' => $mchat_del,
- 'MCHAT_USER_AVATAR' => $mchat_avatar,
- 'U_VIEWPROFILE' => ($row['user_id'] != ANONYMOUS) ? append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&u=' . $row['user_id']) : '',
- 'MCHAT_IS_POSTER' => ($row['user_id'] != ANONYMOUS && $this->user->data['user_id'] == $row['user_id']) ? true : false,
- 'MCHAT_PM' => ($row['user_id'] != ANONYMOUS && $this->user->data['user_id'] != $row['user_id'] && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && ($row['user_allow_pm'] || $this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_'))) ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&mode=compose&u=' . $row['user_id']) : '',
+ 'MCHAT_USER_AVATAR' => $row['user_avatar'] ? $this->functions_mchat->mchat_avatar($row) : '',
+ 'U_VIEWPROFILE' => $row['user_id'] != ANONYMOUS ? append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&u=' . $row['user_id']) : '',
+ 'MCHAT_IS_POSTER' => $row['user_id'] != ANONYMOUS && $this->user->data['user_id'] == $row['user_id'],
+ 'MCHAT_PM' => $row['user_id'] != ANONYMOUS && $this->user->data['user_id'] != $row['user_id'] && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && ($row['user_allow_pm'] || $this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_')) ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&mode=compose&u=' . $row['user_id']) : '',
'MCHAT_MESSAGE_EDIT' => $message_edit,
'MCHAT_MESSAGE_ID' => $row['message_id'],
'MCHAT_USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']),
'MCHAT_USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']),
'MCHAT_USERNAME_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']),
'MCHAT_USER_IP' => $row['user_ip'],
- 'MCHAT_U_WHOIS' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'whois', 'ip' => $row['user_ip'])),
+ 'MCHAT_U_WHOIS' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'whois', 'ip' => $row['user_ip'])),
'MCHAT_U_BAN' => append_sid("{$this->phpbb_root_path}adm/index.{$this->phpEx}" ,'i=permissions&mode=setting_user_global&user_id[0]=' . $row['user_id'], true, $this->user->session_id),
'MCHAT_MESSAGE' => generate_text_for_display($row['message'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']),
- 'MCHAT_TIME' => $this->user->format_date($row['message_time'], $this->config_mchat['date']),
- 'MCHAT_CLASS' => ($row['message_id'] % 2) ? 1 : 2
+ 'MCHAT_TIME' => $this->user->format_date($row['message_time'], $config_mchat['date']),
+ 'MCHAT_CLASS' => $row['message_id'] % 2 ? 1 : 2,
));
}
@@ -370,49 +331,45 @@ class render_helper
}
}
- // Run query again to get the total message rows...
+ // Run query again to get the total message rows
$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');
+ $mchat_total_message = (int) $this->db->sql_fetchfield('mess_id');
$this->db->sql_freeresult($result);
- // Page list function...
+ // 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->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $mchat_total_message, (int) $config_mchat['archive_limit'], $mchat_archive_start);
$this->template->assign_vars(array(
- 'MCHAT_TOTAL_MESSAGES' => sprintf($this->user->lang['MCHAT_TOTALMESSAGES'], $mchat_total_message),
+ 'MCHAT_TOTAL_MESSAGES' => sprintf($this->user->lang['MCHAT_TOTALMESSAGES'], $mchat_total_message),
));
- //add to navlinks
+ // Add to navlinks
$this->template->assign_block_vars('navlinks', array(
- 'FORUM_NAME' => $this->user->lang['MCHAT_ARCHIVE_PAGE'],
- 'U_VIEW_FORUM' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'archive')),
+ 'FORUM_NAME' => $this->user->lang['MCHAT_ARCHIVE_PAGE'],
+ 'U_VIEW_FORUM' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'archive')),
));
- // If archive mode request set true
+
$mchat_archive_mode = true;
- $old_mode = 'archive';
break;
- // Read function...
case 'read':
-
- // If mChat disabled or user can't view the chat
if (!$this->config['mchat_enable'] || !$mchat_view)
{
// Forbidden (for jQ AJAX request)
- throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN');
+ throw new \phpbb\exception\http_exception(403, 'MCHAT_NOACCESS');
}
- // if we're reading on the custom page, then we are chatting
+
+ // If we're reading on the custom page, then we are chatting
if ($mchat_custom_page)
{
- // insert user into the mChat sessions table
$this->functions_mchat->mchat_sessions($mchat_session_time, true);
}
+
// Request
$mchat_message_last_id = $this->request->variable('message_last_id', 0);
$sql_and = $this->user->data['user_mchat_topics'] ? '' : 'AND m.forum_id = 0';
@@ -422,56 +379,57 @@ class render_helper
AND m.message_id > ' . (int) $mchat_message_last_id . '
' . $sql_and . '
ORDER BY m.message_id DESC';
- $result = $this->db->sql_query_limit($sql, (int) $this->config_mchat['message_limit']);
+ $result = $this->db->sql_query_limit($sql, (int) $config_mchat['message_limit']);
$rows = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result);
- // Reverse the array wanting messages appear in reverse
- if(!$this->config['mchat_message_top'])
+
+ // Reverse the array if messages appear at the bottom
+ if (!$this->config['mchat_message_top'])
{
$rows = array_reverse($rows);
}
- foreach($rows as $row_num => $row)
+ foreach ($rows as $row)
{
- // auth check
+ // Auth checks
if ($row['forum_id'] != 0 && !$this->auth->acl_get('f_read', $row['forum_id']))
{
continue;
}
- // edit auths
+
if ($this->user->data['user_id'] == ANONYMOUS && $this->user->data['user_id'] == $row['user_id'])
{
- $chat_auths = $this->user->data['session_ip'] == $row['user_ip'] ? true : false;
+ $chat_auths = $this->user->data['session_ip'] == $row['user_ip'];
}
else
{
- $chat_auths = $this->user->data['user_id'] == $row['user_id'] ? true : false;
+ $chat_auths = $this->user->data['user_id'] == $row['user_id'];
}
- // edit, delete and permission auths
- $mchat_ban = ($this->auth->acl_get('a_authusers') && $this->user->data['user_id'] != $row['user_id']) ? true : false;
- $mchat_edit = ($this->auth->acl_get('u_mchat_edit') && ($this->auth->acl_get('m_') || $chat_auths)) ? true : false;
- $mchat_del = ($this->auth->acl_get('u_mchat_delete') && ($this->auth->acl_get('m_') || $chat_auths)) ? true : false;
- $mchat_avatar = $row['user_avatar'] ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], ($row['user_avatar_width'] > $row['user_avatar_height']) ? 40 : (40 / $row['user_avatar_height']) * $row['user_avatar_width'], ($row['user_avatar_height'] > $row['user_avatar_width']) ? 40 : (40 / $row['user_avatar_width']) * $row['user_avatar_height']) : '';
- $message_edit = $row['message'];
+
+ $mchat_ban = $this->auth->acl_get('a_authusers') && $this->user->data['user_id'] != $row['user_id'];
+ $mchat_edit = $this->auth->acl_get('u_mchat_edit') && ($this->auth->acl_get('m_') || $chat_auths);
+ $mchat_del = $this->auth->acl_get('u_mchat_delete') && ($this->auth->acl_get('m_') || $chat_auths);
+ $message_edit = $row['message'];
+
decode_message($message_edit, $row['bbcode_uid']);
$message_edit = str_replace('"', '"', $message_edit);
- $message_edit = mb_ereg_replace("'", "", $message_edit);// Edit Fix ;)
- if (sizeof($foes_array))
+ $message_edit = mb_ereg_replace("'", "", $message_edit);
+
+ if (!empty($foes_array) && in_array($row['user_id'], $foes_array))
{
- if (in_array($row['user_id'], $foes_array))
- {
- $row['message'] = sprintf($this->user->lang['MCHAT_FOE'], get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']));
- }
+ $row['message'] = sprintf($this->user->lang['MCHAT_FOE'], get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']));
}
+
$row['username'] = mb_ereg_replace("'", "", $row['username']);
+
$this->template->assign_block_vars('mchatrow', array(
'MCHAT_ALLOW_BAN' => $mchat_ban,
'MCHAT_ALLOW_EDIT' => $mchat_edit,
'MCHAT_ALLOW_DEL' => $mchat_del,
- 'MCHAT_USER_AVATAR' => $mchat_avatar,
- 'U_VIEWPROFILE' => ($row['user_id'] != ANONYMOUS) ? append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&u=' . $row['user_id']) : '',
- 'MCHAT_IS_POSTER' => ($row['user_id'] != ANONYMOUS && $this->user->data['user_id'] == $row['user_id']) ? true : false,
- 'MCHAT_PM' => ($row['user_id'] != ANONYMOUS && $this->user->data['user_id'] != $row['user_id'] && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && ($row['user_allow_pm'] || $this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_'))) ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&mode=compose&u=' . $row['user_id']) : '',
+ 'MCHAT_USER_AVATAR' => $row['user_avatar'] ? $this->functions_mchat->mchat_avatar($row) : '',
+ 'U_VIEWPROFILE' => $row['user_id'] != ANONYMOUS ? append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&u=' . $row['user_id']) : '',
+ 'MCHAT_IS_POSTER' => $row['user_id'] != ANONYMOUS && $this->user->data['user_id'] == $row['user_id'],
+ 'MCHAT_PM' => $row['user_id'] != ANONYMOUS && $this->user->data['user_id'] != $row['user_id'] && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && ($row['user_allow_pm'] || $this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_')) ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&mode=compose&u=' . $row['user_id']) : '',
'MCHAT_MESSAGE_EDIT' => $message_edit,
'MCHAT_MESSAGE_ID' => $row['message_id'],
'MCHAT_USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']),
@@ -481,8 +439,8 @@ class render_helper
'MCHAT_U_WHOIS' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'whois', 'ip' => $row['user_ip'])),
'MCHAT_U_BAN' => append_sid("{$this->phpbb_root_path}adm/index.{$this->phpEx}" ,'i=permissions&mode=setting_user_global&user_id[0]=' . $row['user_id'], true, $this->user->session_id),
'MCHAT_MESSAGE' => generate_text_for_display($row['message'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']),
- 'MCHAT_TIME' => $this->user->format_date($row['message_time'], $this->config_mchat['date']),
- 'MCHAT_CLASS' => ($row['message_id'] % 2) ? 1 : 2
+ 'MCHAT_TIME' => $this->user->format_date($row['message_time'], $config_mchat['date']),
+ 'MCHAT_CLASS' => $row['message_id'] % 2 ? 1 : 2
));
}
@@ -492,131 +450,114 @@ class render_helper
$mchat_no_message = true;
}
- // If read mode request set true
$mchat_read_mode = true;
break;
- // Stats function...
case 'stats':
-
- // If mChat disabled or user can't view the chat
- if (!$this->config['mchat_enable'] || !$mchat_view || !$this->config_mchat['whois'])
+ if (!$this->config['mchat_enable'] || !$mchat_view || !$config_mchat['whois'])
{
// Forbidden (for jQ AJAX request)
- throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN');
+ throw new \phpbb\exception\http_exception(403, 'MCHAT_NOACCESS');
}
- $mchat_stats = $this->functions_mchat->mchat_users($mchat_session_time);
+ $mchat_stats = $this->functions_mchat->mchat_users($mchat_session_time, false);
- if(!empty($mchat_stats['online_userlist']))
+ if (!empty($mchat_stats['online_userlist']))
{
$message = '