acp = $acp; $this->auth = $auth; $this->config = $config; $this->functions = $functions; $this->helper = $helper; $this->language = $language; $this->log = $log; $this->log_aps = $log_aps; $this->request = $request; $this->template = $template; $this->user = $user; } /** * Assign functions defined in this class to event listeners in the core. * * @static * @return array * @access public */ static public function getSubscribedEvents() { return [ 'core.acp_language_after_delete' => 'delete_name', 'core.acp_users_display_overview' => 'display_user', 'core.acp_manage_forums_display_form' => 'display_data', 'core.acp_manage_forums_update_data_after' => 'request_data', ]; } /** * Delete a localised points name upon language deletion. * * @event core.acp_language_after_delete * @param \phpbb\event\data $event The event object * @return void * @access public */ public function delete_name(\phpbb\event\data $event) { $this->config->delete('aps_points_name_' . $event['lang_iso'], true); } /** * Display a user's points when managing a specific user. * * @event core.acp_users_display_overview * @param \phpbb\event\data $event The event object * @return void * @access public */ public function display_user(\phpbb\event\data $event) { $this->template->assign_var('APS_POINTS', $event['user_row']['user_points']); } /** * Display a points list when adding/creating a forum. * * @event core.acp_manage_forums_display_form * @param \phpbb\event\data $event The event object * @return void * @access public */ public function display_data(\phpbb\event\data $event) { $this->log_aps->load_lang(); // Only display a points list if the administrator is authorised to edit the points if ($s_auth = $this->auth->acl_get('a_aps_points')) { // Build a points list for this forum $this->acp->build((int) $event['forum_id']); // Request any action (ajax) $action = $this->request->variable('aps_action', ''); // Ajaxify the copy points action if (!empty($action) && $this->request->is_ajax()) { $json_response = new \phpbb\json_response; $forum_id = $this->request->variable('f', 0); switch ($action) { case 'copy': $copy = $this->request->variable('aps_points_copy', 0); if (empty($copy)) { $json_response->send([ 'MESSAGE_TITLE' => $this->language->lang('ERROR'), 'MESSAGE_TEXT' => $this->language->lang('ACP_APS_POINTS_COPY_EMPTY_FROM'), ]); } $fields = $this->acp->get_fields(); $fields = array_flip($fields[0]); $this->acp->copy_points($copy, $forum_id, $fields); $json_response->send([ 'MESSAGE_TITLE' => $this->language->lang('INFORMATION'), 'MESSAGE_TEXT' => $this->language->lang('ACP_APS_POINTS_COPY_SUCCESS', $this->functions->get_name()), 'APS_VALUES' => $this->acp->assign_values($forum_id), ]); break; case 'reset': if (confirm_box(true)) { $this->acp->delete_points($forum_id); $json_response->send([ 'MESSAGE_TITLE' => $this->language->lang('INFORMATION'), 'MESSAGE_TEXT' => $this->language->lang('ACP_APS_POINTS_RESET_SUCCESS', $this->functions->get_name()), ]); } else { confirm_box(false, $this->language->lang('ACP_APS_POINTS_RESET_CONFIRM', $this->functions->get_name()), build_hidden_fields([ 'aps_action' => $action, 'forum_id' => $forum_id, ])); } break; } } } $this->template->assign_vars([ 'S_APS_POINTS' => (bool) $s_auth, 'U_APS_RESET' => $this->helper->get_current_url() . '&aps_action=reset', ]); } /** * Request and set the points when adding/editing a forum. * * @event core.acp_manage_forums_update_data_after * @param \phpbb\event\data $event The event object * @return void * @access public */ public function request_data(\phpbb\event\data $event) { $this->log_aps->load_lang(); // Only set the points when the administrator is authorised to edit the points if (!$this->auth->acl_get('a_aps_points')) { return; } $forum_id = !empty($event['forum_data']['forum_id']) ? (int) $event['forum_data']['forum_id'] : 0; $copy = $this->request->variable('aps_points_copy', 0); $reset = $this->request->variable('aps_points_reset', 0); $values = $this->request->variable('aps_values', ['' => 0.00]); if (!empty($reset) && !empty($forum_id)) { $this->acp->delete_points($forum_id); $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_ACP_APS_POINTS_RESET', time(), [$event['forum_data']['forum_name'], $this->functions->get_name()]); } else if (!empty($copy) && $copy != $forum_id) { $this->acp->copy_points($copy, $forum_id, $values); $forum_name = $this->functions->forum_name($copy); $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_ACP_APS_POINTS_COPIED', time(), [$forum_name, $event['forum_data']['forum_name'], $this->functions->get_name()]); } else { $this->acp->set_points($values, $forum_id); } } }