From 7f503c2f35c3bd81e2cc609415ab16a4162eb8af Mon Sep 17 00:00:00 2001 From: kasimi Date: Sat, 19 Dec 2015 22:45:42 +0100 Subject: [PATCH] Removed unused dependencies & code cleanup --- adm/style/acp_users_mchat.html | 2 +- config/services.yml | 8 +- controller/admin_controller.php | 41 +- controller/mchat.php | 14 +- core/functions_mchat.php | 297 +++--- core/render_helper.php | 856 ++++++++---------- event/listener.php | 69 +- .../event/overall_header_content_before.html | 6 +- styles/prosilver/template/mchat_body.html | 2 +- 9 files changed, 574 insertions(+), 721 deletions(-) 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 = '
' . $mchat_stats['mchat_users_count'] . ' ' . $mchat_stats['refresh_message'] . '
'; } else { - $message = '
' . $this->user->lang['MCHAT_NO_CHATTERS'] . ' (' . $mchat_stats['refresh_message'] . ')
'; + $message = '
' . $this->user->lang['MCHAT_NO_CHATTERS'] . ' (' . $mchat_stats['refresh_message'] . ')
'; } if ($this->request->is_ajax()) { - // Return for: \Symfony\Component\HttpFoundation\JsonResponse + // Return for \Symfony\Component\HttpFoundation\JsonResponse return array( 'json' => true, 'message' => $message, ); } - else - { - throw new \phpbb\exception\http_exception(501, 'MCHAT_ERROR_NOT_IMPLEMENTED'); - } + + throw new \phpbb\exception\http_exception(501, 'MCHAT_ERROR_NOT_IMPLEMENTED'); break; - // Add function... case 'add': - - // If mChat disabled if (!$this->config['mchat_enable'] || !$mchat_add_mess || !check_form_key('mchat_posting', -1)) { // Forbidden (for jQ AJAX request) - if ($this->request->is_ajax()) - { - throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN'); - } + throw new \phpbb\exception\http_exception(403, 'MCHAT_NOACCESS'); } - // Reguest... $message = utf8_ucfirst($this->request->variable('message', '', true)); - // must have something other than bbcode in the message - if (empty($mchatregex)) - { - //let's strip all the bbcode - $mchatregex = '#\[/?[^\[\]]+\]#mi'; - } - $message_chars = preg_replace($mchatregex, '', $message); - $message_chars = (utf8_strlen(trim($message_chars)) > 0) ? true : false; - - if (!$message || !$message_chars) + // Must have something other than bbcode in the message + $message_chars = trim(preg_replace('#\[/?[^\[\]]+\]#mi', '', $message)); + if (!$message || !utf8_strlen($message_chars)) { // Not Implemented (for jQ AJAX request) throw new \phpbb\exception\http_exception(501, 'MCHAT_ERROR_NOT_IMPLEMENTED'); } // Flood control - if (!$mchat_no_flood && $this->config_mchat['flood_time']) + if (!$mchat_no_flood && $config_mchat['flood_time']) { $mchat_flood_current_time = time(); + $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); - $row = $this->db->sql_fetchrow($result); + $message_time = (int) $this->db->sql_fetchfield('message_time'); $this->db->sql_freeresult($result); - if($row['message_time'] > 0 && ($mchat_flood_current_time - $row['message_time']) < (int) $this->config_mchat['flood_time']) + + if ($message_time && time() - $message_time < $config_mchat['flood_time']) { // Locked (for jQ AJAX request) throw new \phpbb\exception\http_exception(400, 'MCHAT_BAD_REQUEST'); } } - // insert user into the mChat sessions table + + // Insert user into the mChat sessions table $this->functions_mchat->mchat_sessions($mchat_session_time, true); - // we override the $this->config['min_post_chars'] entry? - if ($this->config_mchat['override_min_post_chars']) + + // We override the $this->config['min_post_chars'] entry? + if ($config_mchat['override_min_post_chars']) { $old_cfg['min_post_chars'] = $this->config['min_post_chars']; $this->config['min_post_chars'] = 0; } - //we do the same for the max number of smilies? - if ($this->config_mchat['override_smilie_limit']) + + // We do the same for the max number of smilies? + if ($config_mchat['override_smilie_limit']) { $old_cfg['max_post_smilies'] = $this->config['max_post_smilies']; $this->config['max_post_smilies'] = 0; } // Add function part code from http://wiki.phpbb.com/Parsing_text - $uid = $bitfield = $options = ''; // will be modified by generate_text_for_storage + $uid = $bitfield = $options = ''; generate_text_for_storage($message, $uid, $bitfield, $options, $mchat_allow_bbcode, $mchat_urls, $mchat_smilies); + // Not allowed bbcodes - if (!$mchat_allow_bbcode || $this->config_mchat['bbcode_disallowed']) + if (!$mchat_allow_bbcode) { - if (!$mchat_allow_bbcode) - { - $bbcode_remove = '#\[/?[^\[\]]+\]#Usi'; - $message = preg_replace($bbcode_remove, '', $message); - } - // disallowed bbcodes - else if ($this->config_mchat['bbcode_disallowed']) - { - if (empty($bbcode_replace)) - { - $bbcode_replace = array('#\[(' . $this->config_mchat['bbcode_disallowed'] . ')[^\[\]]+\]#Usi', '#\[/(' . $this->config_mchat['bbcode_disallowed'] . ')[^\[\]]+\]#Usi', - ); - } - $message = preg_replace($bbcode_replace, '', $message); - } + $bbcode_remove = '#\[/?[^\[\]]+\]#Usi'; + $message = preg_replace($bbcode_remove, '', $message); + } + + // Disallowed bbcodes + if ($config_mchat['bbcode_disallowed']) + { + $bbcode_replace = array( + '#\[(' . $config_mchat['bbcode_disallowed'] . ')[^\[\]]+\]#Usi', + '#\[/(' . $config_mchat['bbcode_disallowed'] . ')[^\[\]]+\]#Usi', + ); + $message = preg_replace($bbcode_replace, '', $message); } $sql_ary = array( @@ -628,132 +569,130 @@ class render_helper 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid, 'bbcode_options' => $options, - 'message_time' => time() + 'message_time' => time(), ); + $sql = 'INSERT INTO ' . $this->mchat_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); - // reset the config settings - if(isset($old_cfg['min_post_chars'])) + // Reset the config settings + if (isset($old_cfg['min_post_chars'])) { $this->config['min_post_chars'] = $old_cfg['min_post_chars']; unset($old_cfg['min_post_chars']); } - if(isset($old_cfg['max_post_smilies'])) + + if (isset($old_cfg['max_post_smilies'])) { $this->config['max_post_smilies'] = $old_cfg['max_post_smilies']; unset($old_cfg['max_post_smilies']); } - // Stop run code! if ($this->request->is_ajax()) { - // Return for: \Symfony\Component\HttpFoundation\JsonResponse + // Return for \Symfony\Component\HttpFoundation\JsonResponse return array( 'json' => true, 'success' => true, ); } - else - { - exit_handler(); - } + + exit_handler(); + break; - // Edit function... case 'edit': - $message_id = $this->request->variable('message_id', 0); - // If mChat disabled and not edit if (!$this->config['mchat_enable'] || !$message_id) { // Forbidden (for jQ AJAX request) - throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN'); + throw new \phpbb\exception\http_exception(403, 'MCHAT_NOACCESS'); } - // check for the correct user - $sql = 'SELECT * - FROM ' . $this->mchat_table . ' - WHERE message_id = ' . (int) $message_id; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - // edit and delete auths - $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; + // Check for the correct user + if ($this->auth->acl_get('m_')) + { + // Always allow users with 'm_' auth to edit and delete + $user_id = $this->user->data['user_id']; + } + else + { + $sql = 'SELECT user_id + FROM ' . $this->mchat_table . ' + WHERE message_id = ' . (int) $message_id; + $result = $this->db->sql_query($sql); + $user_id = (int) $this->db->sql_fetchfield('user_id'); + $this->db->sql_freeresult($result); + } + + // Edit and delete auths + $mchat_edit = $this->auth->acl_get('u_mchat_edit') && $this->user->data['user_id'] == $user_id; + $mchat_del = $this->auth->acl_get('u_mchat_delete') && $this->user->data['user_id'] == $user_id; + // If mChat disabled and not edit if (!$mchat_edit) { // Forbidden (for jQ AJAX request) - throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN'); + throw new \phpbb\exception\http_exception(403, 'MCHAT_NOACCESS'); } - // Reguest... + $message = $this->request->variable('message', '', true); - // must have something other than bbcode in the message - if (empty($mchatregex)) - { - //let's strip all the bbcode - $mchatregex = '#\[/?[^\[\]]+\]#mi'; - } - $message_chars = preg_replace($mchatregex, '', $message); - $message_chars = (utf8_strlen(trim($message_chars)) > 0) ? true : false; - if (!$message || !$message_chars) + // Must have something other than bbcode in the message + $message_chars = trim(preg_replace('#\[/?[^\[\]]+\]#mi', '', $message)); + if (!$message || !utf8_strlen($message_chars)) { // Not Implemented (for jQ AJAX request) throw new \phpbb\exception\http_exception(501, 'MCHAT_ERROR_NOT_IMPLEMENTED'); } // Message limit - $message = ($this->config_mchat['max_message_lngth'] != 0 && utf8_strlen($message) >= $this->config_mchat['max_message_lngth'] + 3) ? utf8_substr($message, 0, $this->config_mchat['max_message_lngth']).'...' : $message; + $message = $config_mchat['max_message_lngth'] && utf8_strlen($message) >= $config_mchat['max_message_lngth'] + 3 ? utf8_substr($message, 0, $config_mchat['max_message_lngth']) . '...' : $message; - // we override the $this->config['min_post_chars'] entry? - if ($this->config_mchat['override_min_post_chars']) + // We override the $this->config['min_post_chars'] entry? + if ($config_mchat['override_min_post_chars']) { $old_cfg['min_post_chars'] = $this->config['min_post_chars']; $this->config['min_post_chars'] = 0; } - //we do the same for the max number of smilies? - if ($this->config_mchat['override_smilie_limit']) + + // We do the same for the max number of smilies? + if ($config_mchat['override_smilie_limit']) { $old_cfg['max_post_smilies'] = $this->config['max_post_smilies']; $this->config['max_post_smilies'] = 0; } // Edit function part code from http://wiki.phpbb.com/Parsing_text - $uid = $bitfield = $options = ''; // will be modified by generate_text_for_storage + $uid = $bitfield = $options = ''; generate_text_for_storage($message, $uid, $bitfield, $options, $mchat_allow_bbcode, $mchat_urls, $mchat_smilies); // Not allowed bbcodes - if (!$mchat_allow_bbcode || $this->config_mchat['bbcode_disallowed']) + if (!$mchat_allow_bbcode) { - if (!$mchat_allow_bbcode) - { - $bbcode_remove = '#\[/?[^\[\]]+\]#Usi'; - $message = preg_replace($bbcode_remove, '', $message); - } - // disallowed bbcodes - else if ($this->config_mchat['bbcode_disallowed']) - { - if (empty($bbcode_replace)) - { - $bbcode_replace = array('#\[(' . $this->config_mchat['bbcode_disallowed'] . ')[^\[\]]+\]#Usi', - '#\[/(' . $this->config_mchat['bbcode_disallowed'] . ')[^\[\]]+\]#Usi', - ); - } - $message = preg_replace($bbcode_replace, '', $message); - } + $bbcode_remove = '#\[/?[^\[\]]+\]#Usi'; + $message = preg_replace($bbcode_remove, '', $message); + } + + // Disallowed bbcodes + if ($config_mchat['bbcode_disallowed']) + { + $bbcode_replace = array( + '#\[(' . $config_mchat['bbcode_disallowed'] . ')[^\[\]]+\]#Usi', + '#\[/(' . $config_mchat['bbcode_disallowed'] . ')[^\[\]]+\]#Usi', + ); + $message = preg_replace($bbcode_replace, '', $message); } $sql_ary = array( 'message' => str_replace('\'', '’', $message), 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid, - 'bbcode_options' => $options + 'bbcode_options' => $options, ); - $sql = 'UPDATE ' . $this->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); @@ -770,19 +709,19 @@ class render_helper $message_edit = $row['message']; decode_message($message_edit, $row['bbcode_uid']); - $message_edit = str_replace('"', '"', $message_edit); // Edit Fix ;) - $message_edit = mb_ereg_replace("'", "’", $message_edit); // Edit Fix ;) - $mchat_ban = ($this->auth->acl_get('a_authusers') && $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 = str_replace('"', '"', $message_edit); + $message_edit = mb_ereg_replace("'", "’", $message_edit); + $mchat_ban = $this->auth->acl_get('a_authusers') && $this->user->data['user_id'] != $row['user_id']; + $this->template->assign_block_vars('mchatrow', array( 'MCHAT_ALLOW_BAN' => $mchat_ban, 'MCHAT_ALLOW_EDIT' => $mchat_edit, 'MCHAT_ALLOW_DEL' => $mchat_del, 'MCHAT_MESSAGE_EDIT' => $message_edit, - '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_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']), @@ -791,119 +730,113 @@ 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' => censor_text(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 )); - // reset the config settings - if(isset($old_cfg['min_post_chars'])) + + // Reset the config settings + if (isset($old_cfg['min_post_chars'])) { $this->config['min_post_chars'] = $old_cfg['min_post_chars']; unset($old_cfg['min_post_chars']); } - if(isset($old_cfg['max_post_smilies'])) + + if (isset($old_cfg['max_post_smilies'])) { $this->config['max_post_smilies'] = $old_cfg['max_post_smilies']; unset($old_cfg['max_post_smilies']); } - //adds a log + // Add a log $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EDITED_MCHAT', false, array($row['username'])); - // insert user into the mChat sessions table + $this->functions_mchat->mchat_sessions($mchat_session_time, true); - // If read mode request set true $mchat_read_mode = true; break; - // Delete function... case 'delete': - $message_id = $this->request->variable('message_id', 0); - // If mChat disabled + if (!$this->config['mchat_enable'] || !$message_id) { // Forbidden (for jQ AJAX request) - throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN'); + throw new \phpbb\exception\http_exception(403, 'MCHAT_NOACCESS'); } - // check for the correct user - $sql = 'SELECT m.*, u.username, u.user_colour + + // Check for the correct user + $sql = 'SELECT u.user_id, u.username 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); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); - // edit and delete auths - $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; - // If mChat disabled + // Edit and delete auths + $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']); + if (!$mchat_del) { // Forbidden (for jQ AJAX request) - throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN'); + throw new \phpbb\exception\http_exception(403, 'MCHAT_NOACCESS'); } - // Run delete! + // Run delete $sql = 'DELETE FROM ' . $this->mchat_table . ' WHERE message_id = ' . (int) $message_id; $this->db->sql_query($sql); - //adds a log + // Add a log $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DELETED_MCHAT', false, array($row['username'])); - // insert user into the mChat sessions table + $this->functions_mchat->mchat_sessions($mchat_session_time, true); - // Stop running code if ($this->request->is_ajax()) { - // Return for: \Symfony\Component\HttpFoundation\JsonResponse + // Return for \Symfony\Component\HttpFoundation\JsonResponse return array( 'json' => true, 'success' => true, ); } - else - { - exit_handler(); - } + + exit_handler(); + break; - // Default function... default: // If not include in index.php set mchat.php page true if (!$include_on_index) { - // Yes its custom page... $mchat_custom_page = true; // If custom page false mchat.php page redirect to index... - if (!$this->config_mchat['custom_page'] && $mchat_custom_page) + if (!$config_mchat['custom_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_NO_CUSTOM_PAGE']. '

' . sprintf($this->user->lang['RETURN_PAGE'], '', '')); } - // user has permissions to view the custom chat? - if (!$mchat_view && $mchat_custom_page) + // User has permissions to view the custom chat? + if (!$mchat_view) { trigger_error('NOT_AUTHORISED', E_USER_NOTICE); } - // if whois true - if ($this->config_mchat['whois']) + if ($config_mchat['whois']) { - // 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'; + // 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'; + ORDER BY ' . $order_legend . ' ASC'; } else { @@ -913,100 +846,101 @@ class render_helper 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'; + ORDER BY g.' . $order_legend . ' ASC'; } $result = $this->db->sql_query($sql); - $legend = array(); + $rows = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); - while ($row = $this->db->sql_fetchrow($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'))) + $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[] = ''.$group_name.''; + $legend[] = '' . $group_name . ''; } else { - $legend[] = 'phpbb_root_path}memberlist.{$this->phpEx}", 'mode=group&g='.$row['group_id']).'">'.$group_name.''; + $legend[] = 'phpbb_root_path}memberlist.{$this->phpEx}", 'mode=group&g='.$row['group_id']) . '">' . $group_name . ''; } } - $this->db->sql_freeresult($result); - $legend = implode(', ', $legend); - // Assign index specific vars $this->template->assign_vars(array( - 'LEGEND' => $legend, + 'LEGEND' => implode(', ', $legend), )); } + $this->template->assign_block_vars('navlinks', array( - 'FORUM_NAME' => $this->user->lang['MCHAT_TITLE'], - 'U_VIEW_FORUM' => $this->helper->route('dmzx_mchat_controller'), + 'FORUM_NAME' => $this->user->lang['MCHAT_TITLE'], + 'U_VIEW_FORUM' => $this->helper->route('dmzx_mchat_controller'), )); } - // Run code... if ($mchat_view) { - $message_number = $mchat_custom_page ? $this->config_mchat['message_limit'] : $this->config_mchat['message_num']; + $message_number = $config_mchat[$mchat_custom_page ? 'message_limit' : 'message_num']; $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->mchat_table . ' m - LEFT JOIN ' . USERS_TABLE . ' u ON m.user_id = u.user_id + LEFT JOIN ' . USERS_TABLE . ' u ON m.user_id = u.user_id ' . $sql_where . ' ORDER BY message_id DESC'; $result = $this->db->sql_query_limit($sql, $message_number); $rows = $this->db->sql_fetchrowset($result); $this->db->sql_freeresult($result); - 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, true); } - foreach($rows as $row) + foreach ($rows as $row) { - // auth check - if ($row['forum_id'] != 0 && !$this->auth->acl_get('f_read', $row['forum_id'])) + // Auth checks + 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; - // 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']; } - $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); // Edit Fix ;) + $message_edit = str_replace('"', '"', $message_edit); $message_edit = mb_ereg_replace("'", "’", $message_edit); - if (sizeof($foes_array)) + + 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']); $message = str_replace('\'', '’', $row['message']); + $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']), @@ -1016,10 +950,9 @@ 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($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, )); - } // Write no message @@ -1027,11 +960,13 @@ class render_helper { $mchat_no_message = true; } - // display custom bbcodes - if($mchat_allow_bbcode && $this->config['allow_bbcode']) + + // Display custom bbcodes + if ($mchat_allow_bbcode && $this->config['allow_bbcode']) { $this->functions_mchat->display_mchat_bbcodes(); } + // Smile row if ($mchat_smilies) { @@ -1041,39 +976,37 @@ class render_helper } generate_smilies('inline', 0); } + // If the static message is defined in the language file use it, else just use the entry in the database - if (isset($this->user->lang[strtoupper('static_message')]) || !empty($this->config_mchat['static_message'])) + if (isset($this->user->lang[strtoupper('static_message')]) || !empty($config_mchat['static_message'])) { - $this->config_mchat['static_message'] = $this->config_mchat['static_message']; - if(isset($this->user->lang[strtoupper('static_message')])) + $config_mchat['static_message'] = $config_mchat['static_message']; + if (isset($this->user->lang[strtoupper('static_message')])) { - $this->config_mchat['static_message'] = $this->user->lang[strtoupper('static_message')]; + $config_mchat['static_message'] = $this->user->lang[strtoupper('static_message')]; } } + // If the static message is defined in the language file use it, else just use the entry in the database - if (isset($this->user->lang[strtoupper('mchat_rules')]) || !empty($this->config_mchat['rules'])) + if (isset($this->user->lang[strtoupper('mchat_rules')]) || !empty($config_mchat['rules'])) { - if(isset($this->user->lang[strtoupper('mchat_rules')])) + if (isset($this->user->lang[strtoupper('mchat_rules')])) { - $this->config_mchat['rules'] = $this->user->lang[strtoupper('mchat_rules')]; + $config_mchat['rules'] = $this->user->lang[strtoupper('mchat_rules')]; } } - // a list of users using the chat - if ($mchat_custom_page) - { - $mchat_users = $this->functions_mchat->mchat_users($mchat_session_time, true); - } - else - { - $mchat_users = $this->functions_mchat->mchat_users($mchat_session_time); - } + + // A list of users using the chat + $mchat_users = $this->functions_mchat->mchat_users($mchat_session_time, $mchat_custom_page); $this->template->assign_vars(array( 'MCHAT_USERS_COUNT' => $mchat_users['mchat_users_count'], 'MCHAT_USERS_LIST' => $mchat_users['online_userlist'], )); } + break; } + /** * Event render_helper_aft * @@ -1082,14 +1015,13 @@ class render_helper */ $this->dispatcher->trigger_event('dmzx.mchat.core.render_helper_aft'); - // show index stats + // Show index stats if (!empty($this->config['mchat_stats_index']) && !empty($this->user->data['user_mchat_stats_index'])) { - // stats display - $mchat_session_time = !empty($this->config_mchat['timeout']) ? $this->config_mchat['timeout'] : $this->config['session_length']; - $mchat_stats = $this->functions_mchat->mchat_users($mchat_session_time); + $mchat_session_time = !empty($config_mchat['timeout']) ? $config_mchat['timeout'] : $this->config['session_length']; + $mchat_stats = $this->functions_mchat->mchat_users($mchat_session_time, false); $this->template->assign_vars(array( - 'MCHAT_INDEX_STATS' => true, + 'MCHAT_INDEX_STATS' => true, 'MCHAT_INDEX_USERS_COUNT' => $mchat_stats['mchat_users_count'], 'MCHAT_INDEX_USERS_LIST' => !empty($mchat_stats['online_userlist']) ? $mchat_stats['online_userlist'] : '', 'L_MCHAT_ONLINE_EXPLAIN' => $mchat_stats['refresh_message'], @@ -1098,57 +1030,63 @@ class render_helper $copyright = base64_decode('PGEgaHJlZj0iaHR0cDovL3JtY2dpcnI4My5vcmciPlJNY0dpcnI4MzwvYT4gJmNvcHk7IDxhIGhyZWY9Imh0dHA6Ly93d3cuZG16eC13ZWIubmV0IiB0aXRsZT0id3d3LmRtengtd2ViLm5ldCI+ZG16eDwvYT4='); add_form_key('mchat_posting'); + // Template function... $this->template->assign_vars(array( - 'MCHAT_FILE_NAME' => $this->helper->route('dmzx_mchat_controller'), - 'MCHAT_REFRESH_JS' => 1000 * $this->config_mchat['refresh'], - 'MCHAT_ADD_MESSAGE' => $mchat_add_mess, - 'MCHAT_READ_MODE' => $mchat_read_mode, - 'MCHAT_ARCHIVE_MODE' => $mchat_archive_mode, - 'MCHAT_INPUT_TYPE' => $this->user->data['user_mchat_input_area'], - 'MCHAT_RULES' => $mchat_rules, - 'MCHAT_ALLOW_SMILES' => $mchat_smilies, - 'MCHAT_ALLOW_IP' => $mchat_ip, - 'MCHAT_ALLOW_PM' => $mchat_pm, - 'MCHAT_ALLOW_LIKE' => $mchat_like, - 'MCHAT_ALLOW_QUOTE' => $mchat_quote, - 'MCHAT_NOMESSAGE_MODE' => $mchat_no_message, - 'MCHAT_ALLOW_BBCODES' => ($mchat_allow_bbcode && $this->config['allow_bbcode']) ? true : false, - 'MCHAT_MESSAGE_TOP' => $this->config['mchat_message_top'] ? true : false, - 'MCHAT_ENABLE' => $this->config['mchat_enable'], - 'MCHAT_ARCHIVE_URL' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'archive')), - 'MCHAT_CUSTOM_PAGE' => $mchat_custom_page, - 'MCHAT_INDEX_HEIGHT' => $this->config_mchat['index_height'], - 'MCHAT_CUSTOM_HEIGHT' => $this->config_mchat['custom_height'], + 'MCHAT_FILE_NAME' => $this->helper->route('dmzx_mchat_controller'), + 'MCHAT_REFRESH_JS' => 1000 * $config_mchat['refresh'], + 'MCHAT_ADD_MESSAGE' => $mchat_add_mess, + 'MCHAT_READ_MODE' => $mchat_read_mode, + 'MCHAT_ARCHIVE_MODE' => $mchat_archive_mode, + 'MCHAT_INPUT_TYPE' => $this->user->data['user_mchat_input_area'], + 'MCHAT_RULES' => $mchat_rules, + 'MCHAT_ALLOW_SMILES' => $mchat_smilies, + 'MCHAT_ALLOW_IP' => $mchat_ip, + 'MCHAT_ALLOW_PM' => $mchat_pm, + 'MCHAT_ALLOW_LIKE' => $mchat_like, + 'MCHAT_ALLOW_QUOTE' => $mchat_quote, + 'MCHAT_NOMESSAGE_MODE' => $mchat_no_message, + 'MCHAT_ALLOW_BBCODES' => $mchat_allow_bbcode && $this->config['allow_bbcode'], + 'MCHAT_MESSAGE_TOP' => $this->config['mchat_message_top'], + 'MCHAT_ENABLE' => $this->config['mchat_enable'], + 'MCHAT_ARCHIVE_URL' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'archive')), + 'MCHAT_CUSTOM_PAGE' => $mchat_custom_page, + 'MCHAT_INDEX_HEIGHT' => $config_mchat['index_height'], + 'MCHAT_CUSTOM_HEIGHT' => $config_mchat['custom_height'], 'MCHAT_READ_ARCHIVE_BUTTON' => $mchat_read_archive, - 'MCHAT_FOUNDER' => $mchat_founder, - 'MCHAT_CLEAN_URL' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'clean', 'redirect' => $on_page)), - 'MCHAT_STATIC_MESS' => !empty($this->config_mchat['static_message']) ? htmlspecialchars_decode($this->config_mchat['static_message']) : '', - 'L_MCHAT_COPYRIGHT' => $copyright, - 'MCHAT_WHOIS' => $this->config_mchat['whois'], - 'MCHAT_MESSAGE_LNGTH' => $this->config_mchat['max_message_lngth'], - 'L_MCHAT_MESSAGE_LNGTH_EXPLAIN' => (intval($this->config_mchat['max_message_lngth'])) ? sprintf($this->user->lang['MCHAT_MESSAGE_LNGTH_EXPLAIN'], intval($this->config_mchat['max_message_lngth'])) : '', - 'MCHAT_MESS_LONG' => sprintf($this->user->lang['MCHAT_MESS_LONG'], $this->config_mchat['max_message_lngth']), - 'MCHAT_USER_TIMEOUT' => 1000 * $this->config_mchat['timeout'], - 'MCHAT_WHOIS_REFRESH' => 1000 * $this->config_mchat['whois_refresh'], - 'MCHAT_PAUSE_ON_INPUT' => $this->config_mchat['pause_on_input'] ? true : false, - 'L_MCHAT_ONLINE_EXPLAIN' => $this->functions_mchat->mchat_session_time($mchat_session_time), - 'MCHAT_REFRESH_YES' => sprintf($this->user->lang['MCHAT_REFRESH_YES'], $this->config_mchat['refresh']), - 'L_MCHAT_WHOIS_REFRESH_EXPLAIN' => sprintf($this->user->lang['WHO_IS_REFRESH_EXPLAIN'], $this->config_mchat['whois_refresh']), - 'S_MCHAT_AVATARS' => $mchat_avatars, - 'S_MCHAT_LOCATION' => $this->config_mchat['location'], - 'S_MCHAT_SOUND_YES' => $this->user->data['user_mchat_sound'], - 'S_MCHAT_INDEX_STATS' => $this->user->data['user_mchat_stats_index'], - 'U_MORE_SMILIES' => append_sid("{$this->phpbb_root_path}posting.{$this->phpEx}", 'mode=smilies'), - 'U_MCHAT_RULES' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'rules')), - 'S_MCHAT_ON_INDEX' => ($this->config['mchat_on_index'] && !empty($this->user->data['user_mchat_index'])) ? true : false, - 'EXT_URL' => generate_board_url() . '/ext/dmzx/mchat/', + 'MCHAT_FOUNDER' => $mchat_founder, + 'MCHAT_CLEAN_URL' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'clean', 'redirect' => $include_on_index ? 'index' : 'mchat')), + 'MCHAT_STATIC_MESS' => !empty($config_mchat['static_message']) ? htmlspecialchars_decode($config_mchat['static_message']) : '', + 'L_MCHAT_COPYRIGHT' => $copyright, + 'MCHAT_WHOIS' => $config_mchat['whois'], + 'MCHAT_MESSAGE_LNGTH' => $config_mchat['max_message_lngth'], + //'MCHAT_MESSAGE_LNGTH_EXPLAIN' => $config_mchat['max_message_lngth']) ? sprintf($this->user->lang['MCHAT_MESSAGE_LNGTH_EXPLAIN'], $config_mchat['max_message_lngth']) : '', + 'MCHAT_MESS_LONG' => sprintf($this->user->lang['MCHAT_MESS_LONG'], $config_mchat['max_message_lngth']), + 'MCHAT_USER_TIMEOUT' => 1000 * $config_mchat['timeout'], + 'MCHAT_WHOIS_REFRESH' => 1000 * $config_mchat['whois_refresh'], + 'MCHAT_PAUSE_ON_INPUT' => $config_mchat['pause_on_input'], + 'L_MCHAT_ONLINE_EXPLAIN' => $this->functions_mchat->mchat_session_time($mchat_session_time), + 'MCHAT_REFRESH_YES' => sprintf($this->user->lang['MCHAT_REFRESH_YES'], $config_mchat['refresh']), + 'L_MCHAT_WHOIS_REFRESH_EXPLAIN' => sprintf($this->user->lang['WHO_IS_REFRESH_EXPLAIN'], $config_mchat['whois_refresh']), + 'S_MCHAT_AVATARS' => $mchat_avatars, + 'S_MCHAT_LOCATION' => $config_mchat['location'], + 'S_MCHAT_SOUND_YES' => $this->user->data['user_mchat_sound'], + 'S_MCHAT_INDEX_STATS' => $this->user->data['user_mchat_stats_index'], + 'U_MORE_SMILIES' => append_sid("{$this->phpbb_root_path}posting.{$this->phpEx}", 'mode=smilies'), + 'U_MCHAT_RULES' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'rules')), + 'S_MCHAT_ON_INDEX' => $this->config['mchat_on_index'] && !empty($this->user->data['user_mchat_index']), + 'EXT_URL' => generate_board_url() . '/ext/dmzx/mchat/', )); - // Return for: \$this->helper->render(filename, lang_title); + // Return for $this->helper->render(filename, lang_title); return array( 'filename' => 'mchat_body.html', 'lang_title' => $this->user->lang['MCHAT_TITLE'], ); } + + public function get_disallowed_bbcodes() + { + return $this->functions_mchat->get_disallowed_bbcodes(); + } } diff --git a/event/listener.php b/event/listener.php index f792900..fcdf09b 100644 --- a/event/listener.php +++ b/event/listener.php @@ -34,40 +34,27 @@ class listener implements EventSubscriberInterface /** @var \phpbb\db\driver\driver_interface */ protected $db; - /** @var ContainerInterface */ - protected $phpbb_container; - /** @var string */ protected $phpEx; /** @var string */ - protected $table_prefix; - - /** - * The database tables - * - * @var string - */ protected $mchat_table; /** * Constructor * - * @param \dmzx\mchat\core\render_helper $render_helper + * @param \dmzx\mchat\core\render_helper $render_helper * @param \phpbb\auth\auth $auth * @param \phpbb\config\config $config * @param \phpbb\controller\helper $controller_helper * @param \phpbb\template\template $template * @param \phpbb\user $user * @param \phpbb\db\driver\driver_interface $db - * @param ContainerInterface $phpbb_container - * @param $phpEx - * @param $table_prefix - * @param $mchat_table + * @param string $phpEx + * @param string $mchat_table * */ - - public function __construct(\dmzx\mchat\core\render_helper $render_helper, \phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\controller\helper $controller_helper, \phpbb\template\template $template, \phpbb\user $user, \phpbb\db\driver\driver_interface $db, $phpbb_container, $phpEx, $table_prefix, $mchat_table) + public function __construct(\dmzx\mchat\core\render_helper $render_helper, \phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\controller\helper $controller_helper, \phpbb\template\template $template, \phpbb\user $user, \phpbb\db\driver\driver_interface $db, $phpEx, $mchat_table) { $this->render_helper = $render_helper; $this->auth = $auth; @@ -76,21 +63,20 @@ class listener implements EventSubscriberInterface $this->controller_helper = $controller_helper; $this->user = $user; $this->db = $db; - $this->phpbb_container = $phpbb_container; $this->phpEx = $phpEx; - $this->table_prefix = $table_prefix; $this->mchat_table = $mchat_table; } static public function getSubscribedEvents() { return array( - 'core.viewonline_overwrite_location' => 'add_page_viewonline', - 'core.user_setup' => 'load_language_on_setup', - 'core.page_header' => 'add_page_header_link', - 'core.index_modify_page_title' => 'display_mchat_on_index', - 'core.posting_modify_submit_post_after' => 'posting_modify_submit_post_after', - 'core.permissions' => 'permissions', + 'core.viewonline_overwrite_location' => 'add_page_viewonline', + 'core.user_setup' => 'load_language_on_setup', + 'core.page_header' => 'add_page_header_link', + 'core.index_modify_page_title' => 'display_mchat_on_index', + 'core.posting_modify_submit_post_after' => 'posting_modify_submit_post_after', + 'core.permissions' => 'permissions', + 'core.display_custom_bbcodes_modify_sql' => 'display_custom_bbcodes_modify_sql', ); } @@ -99,7 +85,7 @@ class listener implements EventSubscriberInterface if (strrpos($event['row']['session_page'], 'app.' . $this->phpEx . '/chat') === 0) { $event['location'] = $this->user->lang('MCHAT_TITLE'); - $event['location_url'] = $this->phpbb_container->get('controller.helper')->route('dmzx_mchat_controller'); + $event['location_url'] = $this->controller_helper->route('dmzx_mchat_controller'); } } @@ -189,7 +175,7 @@ class listener implements EventSubscriberInterface 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid, 'bbcode_options' => $options, - 'message_time' => time() + 'message_time' => time(), ); $sql = 'INSERT INTO ' . $this->mchat_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); @@ -198,8 +184,7 @@ class listener implements EventSubscriberInterface public function permissions($event) { - $permissions = $event['permissions']; - $permissions += array( + $event['permissions'] = array_merge($event['permissions'], array( 'u_mchat_use' => array( 'lang' => 'ACL_U_MCHAT_USE', 'cat' => 'mChat' @@ -256,9 +241,27 @@ class listener implements EventSubscriberInterface 'lang' => 'ACL_A_MCHAT', 'cat' => 'mChat' ), - ); - $event['permissions'] = $permissions; - $categories['mChat'] = 'ACP_CAT_MCHAT'; - $event['categories'] = array_merge($event['categories'], $categories); + )); + + $event['categories'] = array_merge($event['categories'], array( + 'mChat' => 'ACP_CAT_MCHAT', + )); + } + + public function display_custom_bbcodes_modify_sql($event) + { + // Prevent disallowed BBCodes from being added to the template only if we're rendering for mChat + if ($this->render_helper->initialized) + { + $disallowed_bbcode_array = $this->render_helper->get_disallowed_bbcodes(); + + if (!empty($disallowed_bbcode_array)) + { + $disallowed_bbcode_array = array_map('strtoupper', $disallowed_bbcode_array); + $sql_ary = $event['sql_ary']; + $sql_ary['WHERE'] .= " AND UPPER(b.bbcode_tag) NOT IN ('" . implode("','", $disallowed_bbcode_array) . "')"; + $event['sql_ary'] = $sql_ary; + } + } } } diff --git a/styles/prosilver/template/event/overall_header_content_before.html b/styles/prosilver/template/event/overall_header_content_before.html index 4368384..4c0bf8d 100644 --- a/styles/prosilver/template/event/overall_header_content_before.html +++ b/styles/prosilver/template/event/overall_header_content_before.html @@ -1,7 +1,7 @@ - +
- {L_INFORMATION}{L_COLON} {L_MCHAT_DISABLE} + {L_INFORMATION}{L_COLON} {L_MCHAT_ENABLE}
- \ No newline at end of file + diff --git a/styles/prosilver/template/mchat_body.html b/styles/prosilver/template/mchat_body.html index ddba59d..a530c15 100644 --- a/styles/prosilver/template/mchat_body.html +++ b/styles/prosilver/template/mchat_body.html @@ -177,7 +177,7 @@ - +

{L_WHO_IS_CHATTING}

{MCHAT_USERS_COUNT}{MCHAT_USERS_COUNT} {L_MCHAT_ONLINE_EXPLAIN}
{MCHAT_USERS_LIST}
{L_MCHAT_WHOIS_REFRESH_EXPLAIN}