From 5ba5026c44696ed74978652a2f47dd799fea3d57 Mon Sep 17 00:00:00 2001 From: dmzx Date: Sat, 22 Aug 2015 21:32:33 +0200 Subject: [PATCH] Version 0.1.2 --- composer.json | 7 +- config/services.yml | 3 + controller/admin_controller.php | 9 ++- core/functions_mchat.php | 58 ++++++++++----- core/render_helper.php | 73 ++++++++++++------- event/listener.php | 54 +++++++------- ...{mchat_module.php => mchat_module_acp.php} | 2 +- ...chat_schema_6.php => mchat_module_cat.php} | 30 ++++---- ...mchat_module1.php => mchat_module_ucp.php} | 2 +- migrations/mchat_schema.php | 52 ++++++++++++- migrations/mchat_schema_2.php | 52 ------------- migrations/mchat_schema_4.php | 53 -------------- migrations/mchat_schema_5.php | 46 ------------ ...ema_3.php => mchat_schema_sample_data.php} | 4 +- styles/prosilver/template/mchat_body.html | 2 + ucp/ucp_mchat_info.php | 4 +- ucp/ucp_mchat_module.php | 16 ++-- 17 files changed, 214 insertions(+), 253 deletions(-) rename migrations/{mchat_module.php => mchat_module_acp.php} (90%) rename migrations/{mchat_schema_6.php => mchat_module_cat.php} (52%) rename migrations/{mchat_module1.php => mchat_module_ucp.php} (90%) delete mode 100644 migrations/mchat_schema_2.php delete mode 100644 migrations/mchat_schema_4.php delete mode 100644 migrations/mchat_schema_5.php rename migrations/{mchat_schema_3.php => mchat_schema_sample_data.php} (95%) diff --git a/composer.json b/composer.json index 439e94e..1085535 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "phpbb-extension", "description": "mChat Extension for phpbb 3.1.x", "homepage": "http://www.dmzx-web.net", - "version": "0.1.1", + "version": "0.1.2", "time": "2015-03-10", "keywords": ["phpbb", "extension", "mchat"], "license": "GPL-2.0", @@ -27,6 +27,11 @@ "display-name": "mChat Extension", "soft-require": { "phpbb/phpbb": "3.1.*" + }, + "version-check": { + "host": "www.dmzx-web.net", + "directory": "/versions", + "filename": "mchat_version.json" } } } \ No newline at end of file diff --git a/config/services.yml b/config/services.yml index 794a9d3..556305d 100644 --- a/config/services.yml +++ b/config/services.yml @@ -40,6 +40,7 @@ services: - @cache - @pagination - @request + - @dispatcher - %core.root_path% - %core.php_ext% - %core.table_prefix% @@ -53,6 +54,7 @@ services: - @log - @dbal.conn - @cache + - @service_container - %core.table_prefix% - %dmzx.mchat.table.mchat% - %dmzx.mchat.table.mchat_config% @@ -67,6 +69,7 @@ services: - @template - @user - @dbal.conn + - @service_container - %core.root_path% - %core.php_ext% - %core.table_prefix% diff --git a/controller/admin_controller.php b/controller/admin_controller.php index 40a245f..3281c09 100644 --- a/controller/admin_controller.php +++ b/controller/admin_controller.php @@ -94,17 +94,17 @@ class admin_controller 'date' => $this->request->variable('mchat_date', '', true), 'whois' => $this->request->variable('mchat_whois', 0), 'whois_refresh' => $this->request->variable('mchat_whois_refresh', 0), - 'bbcode_disallowed' => utf8_normalize_nfc($this->request->variable('mchat_bbcode_disallowed', '', true)), + 'bbcode_disallowed' => $this->request->variable('mchat_bbcode_disallowed', '', true), 'prune_enable' => $this->request->variable('mchat_prune_enable', 0), 'prune_num' => $this->request->variable('mchat_prune_num', 0), 'index_height' => $this->request->variable('mchat_index_height', 0), 'custom_height' => $this->request->variable('mchat_custom_height', 0), - 'static_message' => utf8_normalize_nfc($this->request->variable('mchat_static_message', '', true)), + 'static_message' => $this->request->variable('mchat_static_message', '', true), 'override_min_post_chars' => $this->request->variable('mchat_override_min_post_chars', 0), 'override_smilie_limit' => $this->request->variable('mchat_override_smilie_limit', 0), 'timeout' => $this->request->variable('mchat_timeout', 0), 'pause_on_input' => $this->request->variable('mchat_pause_on_input', 0), - 'rules' => utf8_normalize_nfc($this->request->variable('mchat_rules', '', true)), + 'rules' => $this->request->variable('mchat_rules', '', true), 'avatars' => $this->request->variable('mchat_avatars', 0), ); @@ -169,7 +169,8 @@ class admin_controller } // let's get it on - $sql = 'SELECT * FROM ' . $this->mchat_config_table; + $sql = 'SELECT * + FROM ' . $this->mchat_config_table; $result = $this->db->sql_query($sql); $mchat_config = array(); while ($row = $this->db->sql_fetchrow($result)) diff --git a/core/functions_mchat.php b/core/functions_mchat.php index ee15399..e622517 100644 --- a/core/functions_mchat.php +++ b/core/functions_mchat.php @@ -27,6 +27,9 @@ class functions_mchat /** @var \phpbb\cache\service */ protected $cache; + /** @var \phpbb\event\dispatcher_interface */ + protected $dispatcher; + protected $table_prefix; /** @@ -50,13 +53,14 @@ class functions_mchat * @param \phpbb\cache\service $cache * @param $table_prefix */ - public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\log\log_interface $log, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, $table_prefix, $mchat_table, $mchat_config_table, $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, $dispatcher, $table_prefix, $mchat_table, $mchat_config_table, $mchat_sessions_table) { $this->template = $template; $this->user = $user; $this->auth = $auth; $this->db = $db; $this->cache = $cache; + $this->dispatcher = $dispatcher; $this->phpbb_log = $log; $this->table_prefix = $table_prefix; $this->mchat_table = $mchat_table; @@ -73,7 +77,8 @@ class functions_mchat // Grab the config entries in the ACP...and cache em :P if (($config_mchat = $this->cache->get('_mchat_config')) === false) { - $sql = 'SELECT * FROM ' . $this->mchat_config_table; + $sql = 'SELECT * + FROM ' . $this->mchat_config_table; $result = $this->db->sql_query($sql); $config_mchat = array(); while ($row = $this->db->sql_fetchrow($result)) @@ -94,8 +99,8 @@ class functions_mchat function mchat_user_fix($user_id) { $sql = 'UPDATE ' . $this->mchat_table . ' - SET user_id = ' . ANONYMOUS . ' - WHERE user_id = ' . (int) $user_id; + SET user_id = ' . ANONYMOUS . ' + WHERE user_id = ' . (int) $user_id; $this->db->sql_query($sql); return; @@ -144,7 +149,8 @@ class functions_mchat { $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); // add the user into the sessions upon first visit @@ -157,10 +163,10 @@ class functions_mchat $mchat_user_list = ''; $sql = 'SELECT m.user_id, u.username, u.user_type, u.user_allow_viewonline, u.user_colour - FROM ' . $this->mchat_sessions_table . ' m - LEFT JOIN ' . USERS_TABLE . ' u ON m.user_id = u.user_id - WHERE m.user_lastupdate > ' . $check_time . ' - ORDER BY u.username ASC'; + FROM ' . $this->mchat_sessions_table . ' m + LEFT JOIN ' . USERS_TABLE . ' u ON m.user_id = u.user_id + WHERE m.user_lastupdate > ' . $check_time . ' + ORDER BY u.username ASC'; $result = $this->db->sql_query($sql); $can_view_hidden = $this->auth->acl_get('u_viewonline'); while ($row = $this->db->sql_fetchrow($result)) @@ -214,7 +220,9 @@ class functions_mchat // insert user into the mChat sessions table if ($this->user->data['user_type'] == USER_FOUNDER || $this->user->data['user_type'] == USER_NORMAL) { - $sql = 'SELECT * FROM ' . $this->mchat_sessions_table . ' WHERE user_id =' . (int) $this->user->data['user_id']; + $sql = 'SELECT * + FROM ' . $this->mchat_sessions_table . ' + WHERE user_id =' . (int) $this->user->data['user_id']; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); @@ -251,7 +259,8 @@ class functions_mchat return; } - $sql = 'DELETE FROM ' . $this->mchat_table . ' WHERE post_id = ' . (int) $post_id; + $sql = 'DELETE FROM ' . $this->mchat_table . ' + WHERE post_id = ' . (int) $post_id; $this->db->sql_query($sql); return; @@ -265,7 +274,8 @@ class functions_mchat function mchat_prune($mchat_prune_amount) { // Run query to get the total message rows... - $sql = 'SELECT COUNT(message_id) AS total_messages FROM ' . $this->mchat_table; + $sql = 'SELECT COUNT(message_id) AS total_messages + FROM ' . $this->mchat_table; $result = $this->db->sql_query($sql); $mchat_total_messages = (int) $this->db->sql_fetchfield('total_messages'); $this->db->sql_freeresult($result); @@ -281,7 +291,9 @@ class functions_mchat if ($prune) { - $result = $this->db->sql_query_limit('SELECT * FROM '. $this->mchat_table . ' ORDER BY message_id ASC', 1); + $result = $this->db->sql_query_limit('SELECT * + FROM '. $this->mchat_table . ' + ORDER BY message_id ASC', 1); $row = $this->db->sql_fetchrow($result); $first_id = (int) $row['message_id']; @@ -292,7 +304,7 @@ class functions_mchat // 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; + 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'); @@ -340,9 +352,9 @@ class functions_mchat $num_predefined_bbcodes = 22; $sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline - FROM ' . BBCODES_TABLE . ' - WHERE display_on_posting = 1 - ORDER BY bbcode_tag'; + FROM ' . BBCODES_TABLE . ' + WHERE display_on_posting = 1 + ORDER BY bbcode_tag'; $result = $this->db->sql_query($sql); $i = 0; @@ -374,4 +386,16 @@ class functions_mchat } $this->db->sql_freeresult($result); } + + function functions_mchat_aft() + { + /** + * Event functions_mchat_aft + * + * @event dmzx.mchat.core.functions_mchat_aft + * @since 0.1.2 + */ + $this->dispatcher->trigger_event('dmzx.mchat.core.functions_mchat_aft'); + } + } \ No newline at end of file diff --git a/core/render_helper.php b/core/render_helper.php index 16bb230..fd2cadd 100644 --- a/core/render_helper.php +++ b/core/render_helper.php @@ -38,6 +38,9 @@ class render_helper /** @var \phpbb\request\request */ protected $request; + /** @var \phpbb\event\dispatcher_interface */ + protected $dispatcher; + protected $phpbb_root_path; protected $phpEx; @@ -66,7 +69,7 @@ class render_helper * @param $phpEx * @param $table_prefix */ - public function __construct(\dmzx\mchat\core\functions_mchat $functions_mchat, \phpbb\config\config $config, \phpbb\controller\helper $helper, \phpbb\template\template $template, \phpbb\log\log_interface $log, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, \phpbb\pagination $pagination, \phpbb\request\request $request, $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\cache\service $cache, \phpbb\pagination $pagination, \phpbb\request\request $request, \phpbb\event\dispatcher_interface $dispatcher, $phpbb_root_path, $phpEx, $table_prefix, $mchat_table) { $this->functions_mchat = $functions_mchat; $this->config = $config; @@ -78,6 +81,7 @@ class render_helper $this->cache = $cache; $this->pagination = $pagination; $this->request = $request; + $this->dispatcher = $dispatcher; $this->phpbb_root_path = $phpbb_root_path; $this->phpEx = $phpEx; $this->phpbb_log = $log; @@ -141,8 +145,10 @@ class render_helper // grab fools..uhmmm, foes the user has $foes_array = array(); - $sql = 'SELECT * FROM ' . ZEBRA_TABLE . ' - WHERE user_id = ' . $this->user->data['user_id'] . ' AND foe = 1'; + $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)) { @@ -273,7 +279,8 @@ 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; + $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); @@ -289,7 +296,7 @@ class render_helper // 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 m.message_id DESC'; $result = $this->db->sql_query_limit($sql, (int) $this->config_mchat['archive_limit'], $mchat_archive_start); @@ -327,14 +334,14 @@ class render_helper 'U_VIEWPROFILE' => ($row['user_id'] != ANONYMOUS) ? append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&u=' . $row['user_id']) : '', 'U_USER_IDS' => ($row['user_id'] != ANONYMOUS && $this->user->data['user_id'] != $row['user_id']) ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&mode=compose&u=' . $row['user_id']) : '', 'BOT_USER_ID' => $row['user_id'] != '1', - 'U_USER_ID' => ($row['user_id'] != ANONYMOUS && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && $this->user->data['user_id'] != $row['user_id'] && $row['user_id'] != '1' && ($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']) : '', + 'U_USER_ID' => ($row['user_id'] != ANONYMOUS && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && $this->user->data['user_id'] != $row['user_id'] && $row['user_id'] != '1' && ($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']), @@ -350,7 +357,8 @@ class render_helper } // Run query again to get the total message rows... - $sql = 'SELECT COUNT(message_id) AS mess_id FROM ' . $this->mchat_table; + $sql = 'SELECT COUNT(message_id) AS mess_id + FROM ' . $this->mchat_table; $result = $this->db->sql_query($sql); $mchat_total_message = $this->db->sql_fetchfield('mess_id'); $this->db->sql_freeresult($result); @@ -368,7 +376,7 @@ class render_helper //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')), + 'U_VIEW_FORUM' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'archive')), )); // If archive mode request set true $mchat_archive_mode = true; @@ -433,7 +441,7 @@ class render_helper $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 ;) + $message_edit = mb_ereg_replace("'", "’", $message_edit);// Edit Fix ;) if (sizeof($foes_array)) { if (in_array($row['user_id'], $foes_array)) @@ -450,7 +458,7 @@ class render_helper 'U_VIEWPROFILE' => ($row['user_id'] != ANONYMOUS) ? append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&u=' . $row['user_id']) : '', 'U_USER_IDS' => ($row['user_id'] != ANONYMOUS && $this->user->data['user_id'] != $row['user_id']) ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&mode=compose&u=' . $row['user_id']) : '', 'BOT_USER_ID' => $row['user_id'] != '1', - 'U_USER_ID' => ($row['user_id'] != ANONYMOUS && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && $this->user->data['user_id'] != $row['user_id'] && $row['user_id'] != '1' && ($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']) : '', + 'U_USER_ID' => ($row['user_id'] != ANONYMOUS && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && $this->user->data['user_id'] != $row['user_id'] && $row['user_id'] != '1' && ($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']), @@ -524,7 +532,7 @@ class render_helper } // Reguest... - $message = utf8_ucfirst(utf8_normalize_nfc($this->request->variable('message', '', true))); + $message = utf8_ucfirst($this->request->variable('message', '', true)); // must have something other than bbcode in the message if (empty($mchatregex)) @@ -545,7 +553,8 @@ class render_helper if (!$mchat_no_flood && $this->config_mchat['flood_time']) { $mchat_flood_current_time = time(); - $sql = 'SELECT message_time FROM ' . $this->mchat_table . ' + $sql = 'SELECT message_time + FROM ' . $this->mchat_table . ' WHERE user_id = ' . (int) $this->user->data['user_id'] . ' ORDER BY message_time DESC'; $result = $this->db->sql_query_limit($sql, 1); @@ -588,13 +597,19 @@ class render_helper { if (empty($bbcode_replace)) { - $bbcode_replace = array('#\[(' . $this->config_mchat['bbcode_disallowed'] . ')[^\[\]]+\]#Usi', - '#\[/(' . $this->config_mchat['bbcode_disallowed'] . ')[^\[\]]+\]#Usi', - ); + $bbcode_replace = array('#\[(' . $this->config_mchat['bbcode_disallowed'] . ')[^\[\]]+\]#Usi', '#\[/(' . $this->config_mchat['bbcode_disallowed'] . ')[^\[\]]+\]#Usi', + ); } $message = preg_replace($bbcode_replace, '', $message); } } + /** + * Event render_helper_add + * + * @event dmzx.mchat.core.render_helper_add + * @since 0.1.2 + */ + $this->dispatcher->trigger_event('dmzx.mchat.core.render_helper_add'); $sql_ary = array( 'forum_id' => 0, @@ -760,7 +775,7 @@ class render_helper 'U_VIEWPROFILE' => ($row['user_id'] != ANONYMOUS) ? append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&u=' . $row['user_id']) : '', 'U_USER_IDS' => ($row['user_id'] != ANONYMOUS && $this->user->data['user_id'] != $row['user_id']) ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&mode=compose&u=' . $row['user_id']) : '', 'BOT_USER_ID' => $row['user_id'] != '1', - 'U_USER_ID' => ($row['user_id'] != ANONYMOUS && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && $this->user->data['user_id'] != $row['user_id'] && $row['user_id'] != '1' && ($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']) : '', + 'U_USER_ID' => ($row['user_id'] != ANONYMOUS && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && $this->user->data['user_id'] != $row['user_id'] && $row['user_id'] != '1' && ($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']), @@ -783,9 +798,8 @@ class render_helper $this->config['max_post_smilies'] = $old_cfg['max_post_smilies']; unset($old_cfg['max_post_smilies']); } + //adds a log - // $message_author = get_username_string('no_profile', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']); - // add_log('admin', 'LOG_EDITED_MCHAT', $message_author); $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); @@ -879,16 +893,18 @@ class render_helper $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 + $sql = 'SELECT group_id, group_name, group_colour, group_type + FROM ' . GROUPS_TABLE . ' + WHERE group_legend <> 0 ORDER BY ' . $order_legend . ' ASC'; } else { - $sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type FROM ' . GROUPS_TABLE . ' g - LEFT JOIN ' . USER_GROUP_TABLE . ' ug ON (g.group_id = ug.group_id AND ug.user_id = ' . $this->user->data['user_id'] . ' AND ug.user_pending = 0) - WHERE g.group_legend <> 0 - AND (g.group_type <> ' . GROUP_HIDDEN . ' + $sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type + FROM ' . GROUPS_TABLE . ' g + LEFT JOIN ' . USER_GROUP_TABLE . ' ug ON (g.group_id = ug.group_id AND ug.user_id = ' . $this->user->data['user_id'] . ' AND ug.user_pending = 0) + WHERE g.group_legend <> 0 + AND (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . (int) $this->user->data['user_id'] . ') ORDER BY g.' . $order_legend . ' ASC'; } @@ -1052,6 +1068,13 @@ class render_helper } break; } + /** + * Event render_helper_aft + * + * @event dmzx.mchat.core.render_helper_aft + * @since 0.1.2 + */ + $this->dispatcher->trigger_event('dmzx.mchat.core.render_helper_aft'); // show index stats if (!empty($this->config['mchat_stats_index']) && !empty($this->user->data['user_mchat_stats_index'])) diff --git a/event/listener.php b/event/listener.php index e7a7410..2d9276b 100644 --- a/event/listener.php +++ b/event/listener.php @@ -31,6 +31,9 @@ class listener implements EventSubscriberInterface /** @var \phpbb\db\driver\driver_interface */ protected $db; + /** @var ContainerInterface */ + protected $phpbb_container; + protected $phpbb_root_path; protected $phpEx; @@ -47,7 +50,7 @@ class listener implements EventSubscriberInterface */ protected $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, $root_path, $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, $phpbb_container, $root_path, $phpEx, $table_prefix,$mchat_table) { $this->render_helper = $render_helper; $this->auth = $auth; @@ -56,6 +59,7 @@ class listener implements EventSubscriberInterface $this->controller_helper = $controller_helper; $this->user = $user; $this->db = $db; + $this->phpbb_container = $phpbb_container; $this->root_path = $root_path; $this->phpEx = $phpEx; $this->table_prefix = $table_prefix; @@ -65,22 +69,20 @@ class listener implements EventSubscriberInterface 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.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', ); } public function add_page_viewonline($event) { - global $user, $phpbb_container, $phpEx; - - if (strrpos($event['row']['session_page'], 'app.' . $phpEx . '/chat') === 0) + if (strrpos($event['row']['session_page'], 'app.' . $this->phpEx . '/chat') === 0) { - $event['location'] = $user->lang('MCHAT_TITLE'); - $event['location_url'] = $phpbb_container->get('controller.helper')->route('dmzx_mchat_controller'); + $event['location'] = $this->user->lang('MCHAT_TITLE'); + $event['location_url'] = $this->phpbb_container->get('controller.helper')->route('dmzx_mchat_controller'); } } @@ -147,7 +149,7 @@ class listener implements EventSubscriberInterface { $mchat_new_data = $this->user->lang['MCHAT_NEW_EDIT']; } - else if ($event['mode'] == 'reply'&& (isset($this->config['mchat_new_posts_reply']) && $this->config['mchat_new_posts_reply'])) + else if ($event['mode'] == 'reply' && (isset($this->config['mchat_new_posts_reply']) && $this->config['mchat_new_posts_reply'])) { $mchat_new_data = $this->user->lang['MCHAT_NEW_REPLY']; } @@ -156,21 +158,21 @@ class listener implements EventSubscriberInterface return; } - // Data... - $message = utf8_normalize_nfc($mchat_new_data . ': [url=' . generate_board_url() . '/viewtopic.' . $this->phpEx . '?p=' . $event['data']['post_id'] . '#p' . $event['data']['post_id'] . ']' . $event['post_data']['post_subject'] . '[/url] '. $this->user->lang['MCHAT_IN'] .' [url=' . generate_board_url() . '/viewforum.' . $this->phpEx . '?f=' . $event['forum_id'] . ']' . $event['post_data']['forum_name'] . ' [/url] ' . $this->user->lang['MCHAT_IN_SECTION']); + // Data... + $message = utf8_normalize_nfc($mchat_new_data . ': [url=' . generate_board_url() . '/viewtopic.' . $this->phpEx . '?p=' . $event['data']['post_id'] . '#p' . $event['data']['post_id'] . ']' . $event['post_data']['post_subject'] . '[/url] '. $this->user->lang['MCHAT_IN'] .' [url=' . generate_board_url() . '/viewforum.' . $this->phpEx . '?f=' . $event['forum_id'] . ']' . $event['post_data']['forum_name'] . ' [/url] ' . $this->user->lang['MCHAT_IN_SECTION']); - $uid = $bitfield = $options = ''; // will be modified by generate_text_for_storage - generate_text_for_storage($message, $uid, $bitfield, $options, true, false, false); - $sql_ary = array( - 'forum_id' => $event['forum_id'], - 'post_id' => $event['post_id'], - 'user_id' => $this->user->data['user_id'], - 'user_ip' => $this->user->data['session_ip'], - 'message' => $message, - 'bbcode_bitfield' => $bitfield, - 'bbcode_uid' => $uid, - 'bbcode_options' => $options, - 'message_time' => time() + $uid = $bitfield = $options = ''; // will be modified by generate_text_for_storage + generate_text_for_storage($message, $uid, $bitfield, $options, true, false, false); + $sql_ary = array( + 'forum_id' => $event['forum_id'], + 'post_id' => $event['post_id'], + 'user_id' => $this->user->data['user_id'], + 'user_ip' => $this->user->data['session_ip'], + 'message' => $message, + 'bbcode_bitfield' => $bitfield, + 'bbcode_uid' => $uid, + 'bbcode_options' => $options, + 'message_time' => time() ); $sql = 'INSERT INTO ' . $this->mchat_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); diff --git a/migrations/mchat_module.php b/migrations/mchat_module_acp.php similarity index 90% rename from migrations/mchat_module.php rename to migrations/mchat_module_acp.php index 51ae9bc..29c37e7 100644 --- a/migrations/mchat_module.php +++ b/migrations/mchat_module_acp.php @@ -9,7 +9,7 @@ namespace dmzx\mchat\migrations; -class mchat_module extends \phpbb\db\migration\migration +class mchat_module_acp extends \phpbb\db\migration\migration { public function update_data() diff --git a/migrations/mchat_schema_6.php b/migrations/mchat_module_cat.php similarity index 52% rename from migrations/mchat_schema_6.php rename to migrations/mchat_module_cat.php index 232981d..48b03c8 100644 --- a/migrations/mchat_schema_6.php +++ b/migrations/mchat_module_cat.php @@ -9,13 +9,13 @@ namespace dmzx\mchat\migrations; -class mchat_schema_6 extends \phpbb\db\migration\migration +class mchat_module_cat extends \phpbb\db\migration\migration { static public function depends_on() { return array( - '\dmzx\mchat\migrations\mchat_schema_5', + '\dmzx\mchat\migrations\mchat_schema', ); } @@ -23,26 +23,26 @@ class mchat_schema_6 extends \phpbb\db\migration\migration { return array( array('module.add', array('acp', 'ACP_CAT_USERS', array( - 'module_basename' => 'users', - 'module_enabled' => 1, - 'module_display' => 0, - 'module_langname' => 'ACP_USER_MCHAT', - 'module_mode' => 'mchat', - 'module_auth' => 'acl_a_user', + 'module_basename' => 'users', + 'module_enabled' => 1, + 'module_display' => 0, + 'module_langname' => 'ACP_USER_MCHAT', + 'module_mode' => 'mchat', + 'module_auth' => 'acl_a_user', + ), ), - ), - // First, lets add a new category named UCP_CAT_MCHAT - array('ucp', false, 'UCP_CAT_MCHAT'), + // First, lets add a new category named UCP_CAT_MCHAT + array('ucp', false, 'UCP_CAT_MCHAT'), - // next let's add our module - array('ucp', 'UCP_CAT_MCHAT', array( + // next let's add our module + array('ucp', 'UCP_CAT_MCHAT', array( 'module_basename' => 'mchat', 'modes' => array('configuration'), 'module_auth' => 'u_mchat_use', + ), ), - ), - ), + ), ); } } \ No newline at end of file diff --git a/migrations/mchat_module1.php b/migrations/mchat_module_ucp.php similarity index 90% rename from migrations/mchat_module1.php rename to migrations/mchat_module_ucp.php index c54df35..faa8bbb 100644 --- a/migrations/mchat_module1.php +++ b/migrations/mchat_module_ucp.php @@ -9,7 +9,7 @@ namespace dmzx\mchat\migrations; -class mchat_module1 extends \phpbb\db\migration\migration +class mchat_module_ucp extends \phpbb\db\migration\migration { public function update_data() diff --git a/migrations/mchat_schema.php b/migrations/mchat_schema.php index b370411..1c66d8b 100644 --- a/migrations/mchat_schema.php +++ b/migrations/mchat_schema.php @@ -11,6 +11,7 @@ namespace dmzx\mchat\migrations; class mchat_schema extends \phpbb\db\migration\migration { + var $ext_version = '0.1.2'; public function update_data() { @@ -25,7 +26,7 @@ class mchat_schema extends \phpbb\db\migration\migration array('config.add', array('mchat_new_posts_quote', false)), array('config.add', array('mchat_message_top', true)), array('config.add', array('mchat_stats_index', false)), - array('config.add', array('mchat_version','0.1.1')), + array('config.add', array('mchat_version', $this->ext_version)), // Add permissions array('permission.add', array('u_mchat_use')), @@ -78,6 +79,42 @@ class mchat_schema extends \phpbb\db\migration\migration ), 'PRIMARY_KEY' => 'config_name', ), + + $this->table_prefix . 'mchat' => array( + 'COLUMNS' => array( + 'message_id' => array('UINT', NULL, 'auto_increment'), + 'user_id' => array('UINT', 0), + 'user_ip' => array('VCHAR:40', ''), + 'message' => array('MTEXT_UNI', ''), + 'bbcode_bitfield' => array('VCHAR', ''), + 'bbcode_uid' => array('VCHAR:8', ''), + 'bbcode_options' => array('BOOL', '7'), + 'message_time' => array('INT:11', 0), + 'forum_id' => array('UINT', 0), + 'post_id' => array('UINT', 0), + ), + 'PRIMARY_KEY' => 'message_id', + ), + + $this->table_prefix . 'mchat_sessions' => array( + 'COLUMNS' => array( + 'user_id' => array('UINT', 0), + 'user_lastupdate' => array('TIMESTAMP', 0), + 'user_ip' => array('VCHAR:40', ''), + ), + 'PRIMARY_KEY' => 'user_id', + ), + ), + + 'add_columns' => array( + $this->table_prefix . 'users' => array( + 'user_mchat_index' => array('BOOL', '1'), + 'user_mchat_sound' => array('BOOL', '1'), + 'user_mchat_stats_index' => array('BOOL', '1'), + 'user_mchat_topics' => array('BOOL', '1'), + 'user_mchat_avatars' => array('BOOL', '1'), + 'user_mchat_input_area' => array('BOOL', '1'), + ), ), ); } @@ -86,8 +123,21 @@ class mchat_schema extends \phpbb\db\migration\migration { return array( 'drop_tables' => array( + $this->table_prefix . 'mchat', + $this->table_prefix . 'mchat_sessions', $this->table_prefix . 'mchat_config', ), + + 'drop_columns' => array( + $this->table_prefix . 'users' => array( + 'user_mchat_index', + 'user_mchat_sound', + 'user_mchat_stats_index', + 'user_mchat_topics', + 'user_mchat_avatars', + 'user_mchat_input_area', + ), + ), ); } } \ No newline at end of file diff --git a/migrations/mchat_schema_2.php b/migrations/mchat_schema_2.php deleted file mode 100644 index b6740d0..0000000 --- a/migrations/mchat_schema_2.php +++ /dev/null @@ -1,52 +0,0 @@ - array( - $this->table_prefix . 'mchat' => array( - 'COLUMNS' => array( - 'message_id' => array('UINT', NULL, 'auto_increment'), - 'user_id' => array('UINT', 0), - 'user_ip' => array('VCHAR:40', ''), - 'message' => array('MTEXT_UNI', ''), - 'bbcode_bitfield' => array('VCHAR', ''), - 'bbcode_uid' => array('VCHAR:8', ''), - 'bbcode_options' => array('BOOL', '7'), - 'message_time' => array('INT:11', 0), - 'forum_id' => array('UINT', 0), - 'post_id' => array('UINT', 0), - ), - 'PRIMARY_KEY' => 'message_id', - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_tables' => array( - $this->table_prefix . 'mchat', - ), - ); - } -} \ No newline at end of file diff --git a/migrations/mchat_schema_4.php b/migrations/mchat_schema_4.php deleted file mode 100644 index 30a6271..0000000 --- a/migrations/mchat_schema_4.php +++ /dev/null @@ -1,53 +0,0 @@ - array( - $this->table_prefix . 'users' => array( - 'user_mchat_index' => array('BOOL', '1'), - 'user_mchat_sound' => array('BOOL', '1'), - 'user_mchat_stats_index' => array('BOOL', '1'), - 'user_mchat_topics' => array('BOOL', '1'), - 'user_mchat_avatars' => array('BOOL', '1'), - 'user_mchat_input_area' => array('BOOL', '1'), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'users' => array( - 'user_mchat_index', - 'user_mchat_sound', - 'user_mchat_stats_index', - 'user_mchat_topics', - 'user_mchat_avatars', - 'user_mchat_input_area', - ), - ), - ); - } -} \ No newline at end of file diff --git a/migrations/mchat_schema_5.php b/migrations/mchat_schema_5.php deleted file mode 100644 index b35be41..0000000 --- a/migrations/mchat_schema_5.php +++ /dev/null @@ -1,46 +0,0 @@ - array( - $this->table_prefix . 'mchat_sessions' => array( - 'COLUMNS' => array( - 'user_id' => array('UINT', 0), - 'user_lastupdate' => array('TIMESTAMP', 0), - 'user_ip' => array('VCHAR:40', ''), - ), - 'PRIMARY_KEY' => 'user_id', - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_tables' => array( - $this->table_prefix . 'mchat_sessions', - ), - ); - } -} \ No newline at end of file diff --git a/migrations/mchat_schema_3.php b/migrations/mchat_schema_sample_data.php similarity index 95% rename from migrations/mchat_schema_3.php rename to migrations/mchat_schema_sample_data.php index 3bdc50c..7eca1ec 100644 --- a/migrations/mchat_schema_3.php +++ b/migrations/mchat_schema_sample_data.php @@ -9,13 +9,13 @@ namespace dmzx\mchat\migrations; -class mchat_schema_3 extends \phpbb\db\migration\migration +class mchat_schema_sample_data extends \phpbb\db\migration\migration { static public function depends_on() { return array( - '\dmzx\mchat\migrations\mchat_schema_2', + '\dmzx\mchat\migrations\mchat_schema', ); } diff --git a/styles/prosilver/template/mchat_body.html b/styles/prosilver/template/mchat_body.html index 1c7ab9e..c0afa7a 100644 --- a/styles/prosilver/template/mchat_body.html +++ b/styles/prosilver/template/mchat_body.html @@ -182,6 +182,7 @@ + @@ -192,6 +193,7 @@ + diff --git a/ucp/ucp_mchat_info.php b/ucp/ucp_mchat_info.php index b390109..34cf30b 100644 --- a/ucp/ucp_mchat_info.php +++ b/ucp/ucp_mchat_info.php @@ -13,10 +13,12 @@ class ucp_mchat_info { function module() { + global $config; + return array( 'filename' => '\dmzx\mchat\ucp\ucp_mchat_module', 'title' => 'UCP_MCHAT_CONFIG', - 'version' => '1.3.8', + 'version' => $config['mchat_version'], 'modes' => array( 'configuration' => array( 'title' => 'UCP_MCHAT_CONFIG', diff --git a/ucp/ucp_mchat_module.php b/ucp/ucp_mchat_module.php index 46eff7d..ccb9758 100644 --- a/ucp/ucp_mchat_module.php +++ b/ucp/ucp_mchat_module.php @@ -29,12 +29,12 @@ class ucp_mchat_module case 'configuration': $data = array( - 'user_mchat_index' => $request->variable('user_mchat_index', (bool) $user->data['user_mchat_index']), - 'user_mchat_sound' => $request->variable('user_mchat_sound', (bool) $user->data['user_mchat_sound']), + 'user_mchat_index' => $request->variable('user_mchat_index', (bool) $user->data['user_mchat_index']), + 'user_mchat_sound' => $request->variable('user_mchat_sound', (bool) $user->data['user_mchat_sound']), 'user_mchat_stats_index' => $request->variable('user_mchat_stats_index', (bool) $user->data['user_mchat_stats_index']), - 'user_mchat_topics' => $request->variable('user_mchat_topics', (bool) $user->data['user_mchat_topics']), - 'user_mchat_avatars' => $request->variable('user_mchat_avatars', (bool) $user->data['user_mchat_avatars']), - 'user_mchat_input_area' => $request->variable('user_mchat_input_area', (bool) $user->data['user_mchat_input_area']), + 'user_mchat_topics' => $request->variable('user_mchat_topics', (bool) $user->data['user_mchat_topics']), + 'user_mchat_avatars' => $request->variable('user_mchat_avatars', (bool) $user->data['user_mchat_avatars']), + 'user_mchat_input_area' => $request->variable('user_mchat_input_area', (bool) $user->data['user_mchat_input_area']), ); add_form_key('ucp_mchat'); @@ -49,10 +49,10 @@ class ucp_mchat_module if (!sizeof($error)) { $sql_ary = array( - 'user_mchat_index' => $data['user_mchat_index'], - 'user_mchat_sound' => $data['user_mchat_sound'], + 'user_mchat_index' => $data['user_mchat_index'], + 'user_mchat_sound' => $data['user_mchat_sound'], 'user_mchat_stats_index' => $data['user_mchat_stats_index'], - 'user_mchat_topics' => $data['user_mchat_topics'], + 'user_mchat_topics' => $data['user_mchat_topics'], 'user_mchat_avatars' => $data['user_mchat_avatars'], 'user_mchat_input_area' => $data['user_mchat_input_area'], );