diff --git a/adm/style/acp_mchat_globalsettings.html b/adm/style/acp_mchat_globalsettings.html index 6ba3c16..0e83c81 100644 --- a/adm/style/acp_mchat_globalsettings.html +++ b/adm/style/acp_mchat_globalsettings.html @@ -12,189 +12,182 @@
diff --git a/adm/style/acp_mchat_globalusersettings.html b/adm/style/acp_mchat_globalusersettings.html index ac1295e..332b413 100644 --- a/adm/style/acp_mchat_globalusersettings.html +++ b/adm/style/acp_mchat_globalusersettings.html @@ -15,12 +15,29 @@ diff --git a/composer.json b/composer.json index 5838f23..627e175 100644 --- a/composer.json +++ b/composer.json @@ -3,8 +3,8 @@ "type": "phpbb-extension", "description": "mChat Extension", "homepage": "http://www.dmzx-web.net", - "version": "2.0.0-RC3", - "time": "2016-03-24", + "version": "2.0.0-RC4", + "time": "2016-03-31", "keywords": ["phpbb", "extension", "mchat"], "license": "GPL-2.0", "authors": [ diff --git a/config/services.yml b/config/services.yml index a47a3cf..a9e5731 100644 --- a/config/services.yml +++ b/config/services.yml @@ -49,6 +49,7 @@ services: - '@ext.manager' - '%core.root_path%' - '%core.php_ext%' + - '@?phpbb.collapsiblecategories.operator' dmzx.mchat.functions: class: dmzx\mchat\core\functions arguments: diff --git a/controller/acp_controller.php b/controller/acp_controller.php index 2c85d7d..47bad30 100644 --- a/controller/acp_controller.php +++ b/controller/acp_controller.php @@ -87,20 +87,13 @@ class acp_controller $error = array(); - if ($this->request->is_set_post('mchat_purge')) + if ($this->request->is_set_post('mchat_purge') && $this->request->variable('mchat_purge_confirm', false) && check_form_key('acp_mchat') && $this->user->data['user_type'] == USER_FOUNDER) { - $this->template->assign_var('MCHAT_PURGE', true); - } - else if ($this->request->is_set_post('mchat_purge_confirm')) - { - if (check_form_key('acp_mchat') && $this->user->data['user_type'] == USER_FOUNDER) - { - $this->db->sql_query('TRUNCATE TABLE ' . $this->mchat_table); - $this->db->sql_query('TRUNCATE TABLE ' . $this->mchat_deleted_messages_table); - $this->cache->destroy('sql', $this->mchat_deleted_messages_table); - $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PURGED', false, array($this->user->data['username'])); - trigger_error($this->user->lang('MCHAT_PURGED') . adm_back_link($u_action)); - } + $this->db->sql_query('TRUNCATE TABLE ' . $this->mchat_table); + $this->db->sql_query('TRUNCATE TABLE ' . $this->mchat_deleted_messages_table); + $this->cache->destroy('sql', $this->mchat_deleted_messages_table); + $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PURGED', false, array($this->user->data['username'])); + trigger_error($this->user->lang('MCHAT_PURGED') . adm_back_link($u_action)); } else if ($this->request->is_set_post('submit')) { @@ -203,6 +196,18 @@ class acp_controller if (!$error) { + if ($this->request->variable('mchat_overwrite', 0) && $this->request->variable('mchat_overwrite_confirm', 0)) + { + $mchat_new_user_config = array(); + foreach ($mchat_new_config as $config_name => $config_value) + { + $mchat_new_user_config['user_' . $config_name] = $config_value; + } + + $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $mchat_new_user_config); + $this->db->sql_query($sql); + } + // Set the options the user configured foreach ($mchat_new_config as $config_name => $config_value) { diff --git a/controller/main_controller.php b/controller/main_controller.php index 7caec63..ed9349e 100644 --- a/controller/main_controller.php +++ b/controller/main_controller.php @@ -54,7 +54,7 @@ class main_controller * Controller for mChat actions called with Ajax requests * * @param string $action The action to perform, one of add|edit|del|refresh|whois - * @return A Symfony JsonResponse object + * @return \Symfony\Component\HttpFoundation\JsonResponse A Symfony JsonResponse object */ public function action($action) { diff --git a/core/mchat.php b/core/mchat.php index ea76981..06432e0 100644 --- a/core/mchat.php +++ b/core/mchat.php @@ -49,26 +49,30 @@ class mchat /** @var string */ protected $php_ext; + /** @var \phpbb\collapsiblecategories\operator\operator */ + protected $cc_operator; + /** @var boolean */ protected $remove_disallowed_bbcodes = false; /** * Constructor * - * @param \dmzx\mchat\core\functions $functions - * @param \dmzx\mchat\core\settings $settings - * @param \phpbb\controller\helper $helper - * @param \phpbb\template\template $template - * @param \phpbb\user $user - * @param \phpbb\auth\auth $auth - * @param \phpbb\pagination $pagination - * @param \phpbb\request\request $request - * @param \phpbb\event\dispatcher_interface $dispatcher - * @param \phpbb\extension\manager $extension_manager - * @param string $root_path - * @param string $php_ext + * @param \dmzx\mchat\core\functions $functions + * @param \dmzx\mchat\core\settings $settings + * @param \phpbb\controller\helper $helper + * @param \phpbb\template\template $template + * @param \phpbb\user $user + * @param \phpbb\auth\auth $auth + * @param \phpbb\pagination $pagination + * @param \phpbb\request\request $request + * @param \phpbb\event\dispatcher_interface $dispatcher + * @param \phpbb\extension\manager $extension_manager + * @param string $root_path + * @param string $php_ext + * @param \phpbb\collapsiblecategories\operator\operator $cc_operator */ - public function __construct(\dmzx\mchat\core\functions $functions, \dmzx\mchat\core\settings $settings, \phpbb\controller\helper $helper, \phpbb\template\template $template, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\pagination $pagination, \phpbb\request\request $request, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\extension\manager $extension_manager, $root_path, $php_ext) + public function __construct(\dmzx\mchat\core\functions $functions, \dmzx\mchat\core\settings $settings, \phpbb\controller\helper $helper, \phpbb\template\template $template, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\pagination $pagination, \phpbb\request\request $request, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\extension\manager $extension_manager, $root_path, $php_ext, \phpbb\collapsiblecategories\operator\operator $cc_operator = null) { $this->functions = $functions; $this->settings = $settings; @@ -82,6 +86,7 @@ class mchat $this->extension_manager = $extension_manager; $this->root_path = $root_path; $this->php_ext = $php_ext; + $this->cc_operator = $cc_operator; $this->template->assign_vars(array( 'IS_PHPBB31' => $this->settings->is_phpbb31, @@ -307,8 +312,7 @@ class mchat throw new \phpbb\exception\http_exception(403, 'MCHAT_NOACCESS'); } - $is_archive = $this->request->variable('archive', 0); - $this->template->assign_var('MCHAT_IS_ARCHIVE_PAGE', $is_archive); + $this->template->assign_var('MCHAT_IS_ARCHIVE_PAGE', $this->request->variable('archive', false)); $message = $this->request->variable('message', '', true); @@ -330,7 +334,7 @@ class mchat $rows = $this->functions->mchat_get_messages($sql_where, 1); $this->assign_global_template_data(); - $this->assign_messages($rows, $is_archive ? 'archive' : ''); + $this->assign_messages($rows); return array('edit' => $this->render_template('mchat_messages.html')); } @@ -520,22 +524,22 @@ class mchat 'MCHAT_WHOIS_REFRESH_EXPLAIN' => $this->user->lang('MCHAT_WHO_IS_REFRESH_EXPLAIN', $this->settings->cfg('mchat_whois_refresh')), 'MCHAT_SESSION_TIMELEFT' => $this->user->lang('MCHAT_SESSION_ENDS', gmdate('H:i:s', (int) $this->settings->cfg('mchat_timeout'))), 'MCHAT_STATIC_MESS' => htmlspecialchars_decode($static_message), - 'MCHAT_MESS_LONG' => addslashes($this->user->lang('MCHAT_MESS_LONG', $this->settings->cfg('mchat_max_message_lngth'))), - 'MCHAT_REFRESH_YES' => addslashes($this->user->lang('MCHAT_REFRESH_YES', $this->settings->cfg('mchat_refresh'))), + 'A_MCHAT_MESS_LONG' => addslashes($this->user->lang('MCHAT_MESS_LONG', $this->settings->cfg('mchat_max_message_lngth'))), + 'A_MCHAT_REFRESH_YES' => addslashes($this->user->lang('MCHAT_REFRESH_YES', $this->settings->cfg('mchat_refresh'))), 'U_MCHAT_CUSTOM_PAGE' => $this->helper->route('dmzx_mchat_controller'), 'U_MCHAT_RULES' => $this->helper->route('dmzx_mchat_page_controller', array('page' => 'rules')), 'U_MCHAT_ARCHIVE_URL' => $this->helper->route('dmzx_mchat_page_controller', array('page' => 'archive')), )); // The template needs some language variables if we display relative time for messages - if ($this->settings->cfg('mchat_relative_time') && $page != 'archive') + if ($this->settings->cfg('mchat_relative_time')) { $minutes_limit = $this->get_relative_minutes_limit(); for ($i = 0; $i < $minutes_limit; $i++) { $this->template->assign_block_vars('mchattime', array( 'KEY' => $i, - 'LANG' => addslashes($this->user->lang('MCHAT_MINUTES_AGO', $i)), + 'A_LANG' => addslashes($this->user->lang('MCHAT_MINUTES_AGO', $i)), 'IS_LAST' => $i + 1 === $minutes_limit, )); } @@ -545,9 +549,9 @@ class mchat $actions = array_keys(array_filter(array( 'edit' => $this->auth_message('u_mchat_edit', true, time()), 'del' => $this->auth_message('u_mchat_delete', true, time()), - 'refresh' => $page != 'archive' && $this->auth->acl_get('u_mchat_view'), - 'add' => $page != 'archive' && $u_mchat_use, - 'whois' => $page != 'archive' && $this->settings->cfg('mchat_whois'), + 'refresh' => $page !== 'archive' && $this->auth->acl_get('u_mchat_view'), + 'add' => $page !== 'archive' && $u_mchat_use, + 'whois' => $page !== 'archive' && $this->settings->cfg('mchat_whois'), ))); foreach ($actions as $i => $action) @@ -560,14 +564,14 @@ class mchat } $limit = $this->settings->cfg('mchat_message_num_' . $page); - $start = $page == 'archive' ? $this->request->variable('start', 0) : 0; + $start = $page === 'archive' ? $this->request->variable('start', 0) : 0; $rows = $this->functions->mchat_get_messages('', $limit, $start); $this->assign_global_template_data(); - $this->assign_messages($rows, $page); + $this->assign_messages($rows); // Render pagination - if ($page == 'archive') + if ($page === 'archive') { $archive_url = $this->helper->route('dmzx_mchat_page_controller', array('page' => 'archive')); $total_messages = $this->functions->mchat_total_message_count(); @@ -576,12 +580,26 @@ class mchat } // Render legend - if ($page != 'index' && $this->settings->cfg('mchat_whois')) + if ($page !== 'index' && $this->settings->cfg('mchat_whois')) { $legend = $this->functions->mchat_legend(); $this->template->assign_var('LEGEND', implode($this->user->lang('COMMA_SEPARATOR'), $legend)); } + // Make mChat collapsible + if ($page === 'index' && $this->cc_operator !== null) + { + $cc_fid = 'mchat'; + $this->template->assign_vars(array( + 'MCHAT_IS_COLLAPSIBLE' => true, + 'S_MCHAT_HIDDEN' => in_array($cc_fid, $this->cc_operator->get_user_categories()), + 'U_MCHAT_COLLAPSE_URL' => $this->helper->route('phpbb_collapsiblecategories_main_controller', array( + 'forum_id' => $cc_fid, + 'hash' => generate_link_hash('collapsible_' . $cc_fid), + )), + )); + } + $this->assign_authors(); if ($u_mchat_use) @@ -657,9 +675,8 @@ class mchat * Assigns all message rows to the template * * @param array $rows - * @param string $page */ - protected function assign_messages($rows, $page = '') + protected function assign_messages($rows) { if (!$rows) { @@ -718,7 +735,7 @@ class mchat } $message_age = time() - $row['message_time']; - $minutes_ago = $this->get_minutes_ago($message_age, $page); + $minutes_ago = $this->get_minutes_ago($message_age); $datetime = $this->user->format_date($row['message_time'], $this->settings->cfg('mchat_date')); $is_poster = $row['user_id'] != ANONYMOUS && $this->user->data['user_id'] == $row['user_id']; @@ -754,12 +771,11 @@ class mchat * or the message is older than 59 minutes or we render for the archive, -1 is returned. * * @param int $message_age - * @param string $page * @return int */ - protected function get_minutes_ago($message_age, $page) + protected function get_minutes_ago($message_age) { - if ($this->settings->cfg('mchat_relative_time') && $page != 'archive') + if ($this->settings->cfg('mchat_relative_time')) { $minutes_ago = floor($message_age / 60); if ($minutes_ago < $this->get_relative_minutes_limit()) @@ -780,11 +796,11 @@ class mchat */ protected function get_relative_minutes_limit() { - $timeout = $this->settings->cfg('session_length'); + $timeout = $this->settings->cfg('mchat_timeout'); - if ($this->settings->cfg('mchat_timeout')) + if (!$timeout) { - $timeout = $this->settings->cfg('mchat_timeout'); + $timeout = $this->settings->cfg('session_length'); } return min(max((int) ceil($timeout / 60), 1), 60); @@ -823,7 +839,7 @@ class mchat $this->template->assign_var($option['template_var'], !$is_disallowed); } - $this->template->assign_var('MCHAT_DISALLOWED_BBCODES', addslashes(str_replace('=', '-', $this->settings->cfg('mchat_bbcode_disallowed')))); + $this->template->assign_var('A_MCHAT_DISALLOWED_BBCODES', addslashes(str_replace('=', '-', $this->settings->cfg('mchat_bbcode_disallowed')))); if (!function_exists('display_custom_bbcodes')) { @@ -863,6 +879,22 @@ class mchat return $sql_ary; } + /** + * Sets the default values when a user registers a new account as configured in the global user settings + * + * @param array $sql_ary + * @return array + */ + public function set_user_default_values($sql_ary) + { + foreach (array_keys($this->settings->ucp) as $config_name) + { + $sql_ary['user_' . $config_name] = $this->settings->cfg($config_name, true); + } + + return $sql_ary; + } + /** Inserts a message with posting information into the database * * @param string $mode One of post|quote|edit|reply @@ -910,7 +942,7 @@ class mchat return true; } - $can_edit_delete = $this->settings->cfg('mchat_edit_delete_limit') == 0 || $message_time >= time() - $this->settings->cfg('mchat_edit_delete_limit'); + $can_edit_delete = !$this->settings->cfg('mchat_edit_delete_limit') || $message_time >= time() - $this->settings->cfg('mchat_edit_delete_limit'); return $can_edit_delete && $this->user->data['user_id'] == $author_id && $this->user->data['is_registered']; } diff --git a/event/acp_listener.php b/event/acp_listener.php index 070f631..2c73b4c 100644 --- a/event/acp_listener.php +++ b/event/acp_listener.php @@ -154,7 +154,7 @@ class acp_listener implements EventSubscriberInterface */ public function acp_users_prefs_modify_template_data($event) { - $this->user->add_lang_ext('dmzx/mchat', 'mchat_ucp'); + $this->user->add_lang_ext('dmzx/mchat', array('mchat_acp', 'mchat_ucp')); $user_id = $event['user_row']['user_id']; diff --git a/event/main_listener.php b/event/main_listener.php index 8709f10..2b25236 100644 --- a/event/main_listener.php +++ b/event/main_listener.php @@ -55,6 +55,7 @@ class main_listener implements EventSubscriberInterface 'core.index_modify_page_title' => 'display_mchat_on_index', 'core.posting_modify_submit_post_after' => 'posting_modify_submit_post_after', 'core.display_custom_bbcodes_modify_sql' => 'display_custom_bbcodes_modify_sql', + 'core.user_add_modify_data' => 'user_registration_set_default_values', ); } @@ -123,4 +124,12 @@ class main_listener implements EventSubscriberInterface { $event['sql_ary'] = $this->mchat->remove_disallowed_bbcodes($event['sql_ary']); } + + /** + * @param object $event The event object + */ + public function user_registration_set_default_values($event) + { + $event['sql_ary'] = $this->mchat->set_user_default_values($event['sql_ary']); + } } diff --git a/language/en/info_acp_mchat.php b/language/en/info_acp_mchat.php index 3a35931..1b42daa 100644 --- a/language/en/info_acp_mchat.php +++ b/language/en/info_acp_mchat.php @@ -36,17 +36,15 @@ if (empty($lang) || !is_array($lang)) $lang = array_merge($lang, array( // Module titles - 'ACP_CAT_MCHAT' => 'mChat', - 'ACP_CAT_MCHAT_USER_CONFIG' => 'mChat in UCP', - 'ACP_MCHAT_GLOBALSETTINGS' => 'Global settings', - 'ACP_MCHAT_GLOBALUSERSETTINGS' => 'Global user settings', - - 'MCHAT_ACP_USER_PREFS_EXPLAIN' => 'Below are listed all mChat preferences of the selected user. Settings for which the selected user does not have permission to customise are disabled. These settings can be changed in the Global user settings mChat configuration section.', + 'ACP_CAT_MCHAT' => 'mChat', + 'ACP_CAT_MCHAT_USER_CONFIG' => 'mChat in UCP', + 'ACP_MCHAT_GLOBALSETTINGS' => 'Global settings', + 'ACP_MCHAT_GLOBALUSERSETTINGS' => 'Global user settings', // Log entries (%1$s is replaced with the user name who triggered the event) - 'LOG_MCHAT_CONFIG_UPDATE' => 'mChat configuration updated