Alpha update

This commit is contained in:
ebassi -
parent 3a568602da
commit a06cdba30e
28 changed files with 615 additions and 589 deletions

View file

@ -4,18 +4,18 @@ namespace pedodev\tagging\acp;
class main_info
{
public function module()
{
return [
'filename' => '\pedodev\tagging\acp\main_module',
'title' => 'ACP_TAGGING_TITLE',
'modes' => [
'settings' => [
'title' => 'ACP_TAGGING_SETTINGS',
'auth' => 'ext_pedodev/tagging && acl_a_board',
'cat' => ['ACP_TAGGING_TITLE'],
],
],
];
}
public function module()
{
return [
'filename' => '\pedodev\tagging\acp\main_module',
'title' => 'ACP_TAGGING_TITLE',
'modes' => [
'settings' => [
'title' => 'ACP_TAGGING_SETTINGS',
'auth' => 'ext_pedodev/tagging && acl_a_board',
'cat' => ['ACP_TAGGING_TITLE'],
],
],
];
}
}

View file

@ -6,13 +6,14 @@ use phpbb\request\request_interface;
class main_module
{
public $u_action, $tpl_name, $page_title;
private $config, $request, $template, $user, $language, $tag_helper;
private array $tag_list;
private string $tag_list_filepath;
public $u_action, $tpl_name, $page_title;
private $config, $request, $template, $user, $language, $tag_helper;
private array $tag_list;
private string $tag_list_filepath;
private bool $tag_search_available;
public function main(string $id, string $mode): void
{
public function main(string $id, string $mode): void
{
global $phpbb_container;
$this->config = $phpbb_container->get('config');
@ -23,8 +24,9 @@ class main_module
$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->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);
@ -43,12 +45,21 @@ class main_module
$this->load_main_page();
break;
}
}
private function load_edit_page()
{
$form_key = 'pedodev_tagging_edit_tag';
}
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);
@ -59,43 +70,70 @@ class main_module
}
if ($this->request->is_set_post('submit'))
{
$this->check_form_key($form_key);
{
$this->check_form_key($form_key);
$tag_data = array(
'title' => $this->request->variable('tagging_tagtitle', ''),
'color' => $this->request->variable('tagging_tagcolor', ''),
'active' => $this->request->variable('tagging_tagactive', false),
'searchable' => $this->request->variable('tagging_tagsearchable', false),
);
if (empty($tag_data['title']) || empty($tag_data['color']))
{
trigger_error($this->language->lang('ACP_TAGGING_TAG_EMPTY') . adm_back_link($this->u_action));
}
$tag_data = $this->get_tag_data();
$this->tag_list[$tag_id] = $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));
}
trigger_error($this->language->lang('ACP_TAGGING_TAG_EDITED', $tag_data['title']) . adm_back_link($this->u_action));
}
$tag = $this->tag_list[$tag_id];
$tag = $this->tag_list[$tag_id];
$this->template->assign_vars([
'EDIT' => 1,
'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'],
'EDIT_TAG_NAME' => $tag['title'],
'TAG_COLOR' => $tag['color'],
'TAG_ACTIVE' => $tag['active'],
'TAG_SEARCHABLE' => $tag['searchable'],
]);
}
}
private function load_delete_page()
{
$form_key = 'pedodev_tagging_delete_tag';
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);
@ -108,14 +146,14 @@ class main_module
$tag = $this->tag_list[$tag_id];
if ($this->request->is_set_post('submit'))
{
$this->check_form_key($form_key);
{
$this->check_form_key($form_key);
unset($this->tag_list[$tag_id]);
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));
}
trigger_error($this->language->lang('ACP_TAGGING_TAG_DELETED', $tag['title']) . adm_back_link($this->u_action));
}
$this->template->assign_vars([
'DELETE' => 1,
@ -123,53 +161,13 @@ class main_module
'DELETE_CONFIRMATION' => $this->language->lang('ACP_TAGGING_DELETE_CONFIRMATION', $tag['title']),
]);
}
private function load_add_page()
{
$form_key = 'pedodev_tagging_add_tag';
add_form_key($form_key);
if ($this->request->is_set_post('submit'))
{
$this->check_form_key($form_key);
$new_tag = $this->request->variable('tagging_tagtitle', '');
if (empty($new_tag))
{
trigger_error($this->language->lang('ACP_TAGGING_TAG_EMPTY') . adm_back_link($this->u_action));
}
$this->tag_list[] = array(
'title' => $new_tag,
'color' => $this->request->variable('tagging_tagcolor', ''),
'active' => $this->request->variable('tagging_tagactive', false),
'searchable' => $this->request->variable('tagging_tagsearchable', false),
);
$this->tag_helper->update_tag_list($this->tag_list);
trigger_error($this->language->lang('ACP_TAGGING_TAG_ADDED', $new_tag) . adm_back_link($this->u_action));
}
private function load_main_page(): void
{
$form_key = 'pedodev_tagging_main';
add_form_key($form_key);
$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_main_page()
{
$form_key = 'pedodev_tagging_main';
add_form_key($form_key);
$id = 0;
$id = 0;
if ($this->request->is_set_post('submit'))
{
@ -177,7 +175,7 @@ class main_module
$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));
$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));
@ -187,37 +185,38 @@ class main_module
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'],
'TITLE' => $tag['title'],
'COLOR' => $tag['color'],
'ACTIVE' => $tag['active'],
'SEARCHABLE' => $tag['searchable'],
'EDIT_LINK' => $this->u_action . "&tag={$id}&action=edit",
'EDIT_LINK' => $this->u_action . "&tag={$id}&action=edit",
'DELETE_LINK' => $this->u_action . "&tag={$id}&action=delete",
]);
}
$id++;
$this->template->assign_vars([
'TAGGING_PAGE_TITLE' => $this->language->lang('ACP_TAGGING_SETTINGS'),
'U_ACTION' => $this->u_action,
'TAGGING_ADD_TAG' => $this->u_action . "&tag={$id}&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'],
]);
}
'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)
{
private function check_form_key($form_key): void
{
if (!check_form_key($form_key))
{
trigger_error('FORM_INVALID');
}
}
}
}