config = $phpbb_container->get('config'); $this->request = $phpbb_container->get('request'); $this->template = $phpbb_container->get('template'); $this->user = $phpbb_container->get('user'); $this->language = $phpbb_container->get('language'); $this->tag_helper = $phpbb_container->get('pedodev.tagging.tag_helper'); $this->page_title = $this->language->lang('ACP_TAGGING_TITLE'); $this->tpl_name = 'acp_tagging_body'; $this->tag_list = $this->tag_helper->get_tag_list(); $this->tag_search_available = ($this->config['search_type'] == '\phpbb\search\fulltext_native' or $this->config['search_type'] == '\phpbb\search\fulltext_mysql'); $action = $this->request->variable('action', '', $super_global = request_interface::GET); switch($action) { case 'edit': $this->load_edit_page(); break; case 'delete': $this->load_delete_page(); break; case 'add': $this->load_add_page(); break; default: $this->load_main_page(); break; } } private function get_tag_data(): array { return array( 'title' => $this->request->variable('tagging_tagtitle', ''), 'color' => ltrim($this->request->variable('tagging_tagcolor', ''), '#'), 'active' => $this->request->variable('tagging_tagactive', false), 'searchable' => $this->request->variable('tagging_tagsearchable', false), ); } private function load_edit_page(): void { $form_key = 'pedodev_tagging_edit_tag'; add_form_key($form_key); $tag_id = $this->request->variable('tag', -1, request_interface::GET); if (!isset($this->tag_list[$tag_id])) { trigger_error($this->language->lang('ACP_TAGGING_INVALID_TAG') . adm_back_link($this->u_action)); } if ($this->request->is_set_post('submit')) { $this->check_form_key($form_key); $tag_data = $this->get_tag_data(); if (!$this->tag_helper->validate_tag($tag_data)) { trigger_error($this->language->lang('ACP_TAGGING_TAG_INVALID') . adm_back_link($this->u_action)); } $this->tag_list[$tag_id] = $tag_data; $this->tag_helper->update_tag_list($this->tag_list); trigger_error($this->language->lang('ACP_TAGGING_TAG_EDITED', $tag_data['title']) . adm_back_link($this->u_action)); } $tag = $this->tag_list[$tag_id]; $this->template->assign_vars([ 'EDIT' => 1, 'TAGGING_PAGE_TITLE' => $this->language->lang('ACP_TAGGING_SETTINGS_EDIT'), 'EDIT_TAG_NAME' => $tag['title'], 'TAG_COLOR' => $tag['color'], 'TAG_ACTIVE' => $tag['active'], 'TAG_SEARCHABLE' => $tag['searchable'], ]); } private function load_add_page(): void { $form_key = 'pedodev_tagging_add_tag'; add_form_key($form_key); if ($this->request->is_set_post('submit')) { $this->check_form_key($form_key); $tag_data = $this->get_tag_data(); if (!$this->tag_helper->validate_tag($tag_data)) { trigger_error($this->language->lang('ACP_TAGGING_TAG_INVALID') . adm_back_link($this->u_action)); } $this->tag_list[] = $tag_data; $this->tag_helper->update_tag_list($this->tag_list); trigger_error($this->language->lang('ACP_TAGGING_TAG_ADDED', $tag_data['title']) . adm_back_link($this->u_action)); } $random_color = substr(md5(rand()), 0, 6); $this->template->assign_vars([ 'EDIT' => 1, 'TAGGING_PAGE_TITLE' => $this->language->lang('ACP_TAGGING_SETTINGS_ADD'), 'TAG_COLOR' => $random_color, 'TAG_ACTIVE' => true, 'TAG_SEARCHABLE' => true, ]); } private function load_delete_page(): void { $form_key = 'pedodev_tagging_delete_tag'; add_form_key($form_key); $tag_id = $this->request->variable('tag', -1, request_interface::GET); if (!isset($this->tag_list[$tag_id])) { trigger_error($this->language->lang('ACP_TAGGING_INVALID_TAG') . adm_back_link($this->u_action)); } $tag = $this->tag_list[$tag_id]; if ($this->request->is_set_post('submit')) { $this->check_form_key($form_key); unset($this->tag_list[$tag_id]); $this->tag_helper->update_tag_list($this->tag_list); trigger_error($this->language->lang('ACP_TAGGING_TAG_DELETED', $tag['title']) . adm_back_link($this->u_action)); } $this->template->assign_vars([ 'DELETE' => 1, 'TAGGING_PAGE_TITLE' => $this->language->lang('ACP_TAGGING_SETTINGS_DELETE'), 'DELETE_CONFIRMATION' => $this->language->lang('ACP_TAGGING_DELETE_CONFIRMATION', $tag['title']), ]); } private function load_main_page(): void { $form_key = 'pedodev_tagging_main'; add_form_key($form_key); $id = 0; if ($this->request->is_set_post('submit')) { $this->check_form_key($form_key); $this->config->set('pedodev_tagging_tagthreads', $this->request->variable('tagging_tagthreads', false)); $this->config->set('pedodev_tagging_tagposts', $this->request->variable('tagging_tagposts', false)); $this->config->set('pedodev_tagging_maxtags', $this->request->variable('tagging_maxtags', 0)); $this->config->set('pedodev_tagging_tagsearch', ($this->request->variable('tagging_tagsearch', false) and $this->tag_search_available)); $this->config->set('pedodev_tagging_viewtopic', $this->request->variable('tagging_viewtopic', false)); $this->config->set('pedodev_tagging_viewforum', $this->request->variable('tagging_viewforum', false)); $this->config->set('pedodev_tagging_results', $this->request->variable('tagging_results', false)); trigger_error($this->language->lang('ACP_TAGGING_SETTING_SAVED') . adm_back_link($this->u_action)); } foreach ($this->tag_list as $id => $tag) { $id = (int)$id; $this->template->assign_block_vars('tag_list', [ 'TITLE' => $tag['title'], 'COLOR' => $tag['color'], 'ACTIVE' => $tag['active'], 'SEARCHABLE' => $tag['searchable'], 'EDIT_LINK' => $this->u_action . "&tag={$id}&action=edit", 'DELETE_LINK' => $this->u_action . "&tag={$id}&action=delete", ]); } $this->template->assign_vars([ 'TAGGING_PAGE_TITLE' => $this->language->lang('ACP_TAGGING_SETTINGS'), 'U_ACTION' => $this->u_action, 'TAGGING_ADD_TAG' => $this->u_action . "&action=add", 'TAG_THREADS' => $this->config['pedodev_tagging_tagthreads'], 'TAG_POSTS' => $this->config['pedodev_tagging_tagposts'], 'MAX_TAGS' => (int)$this->config['pedodev_tagging_maxtags'], 'TAG_SEARCH' => $this->config['pedodev_tagging_tagsearch'], 'TAG_VIEWTOPIC' => $this->config['pedodev_tagging_viewtopic'], 'TAG_VIEWFORUM' => $this->config['pedodev_tagging_viewforum'], 'TAG_RESULTS' => $this->config['pedodev_tagging_results'], 'TAG_SEARCH_UNAVAILABLE' => !$this->tag_search_available, ]); } private function check_form_key($form_key): void { if (!check_form_key($form_key)) { trigger_error('FORM_INVALID'); } } }