First commit
This commit is contained in:
commit
3a568602da
36 changed files with 1584 additions and 0 deletions
24
event/permissions.php
Executable file
24
event/permissions.php
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Adds permissions to the Permissions page in the Admin CP
|
||||
*/
|
||||
|
||||
namespace pedodev\tagging\event;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
class permissions implements EventSubscriberInterface
|
||||
{
|
||||
static public function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
'core.permissions' => 'load_permissions',
|
||||
];
|
||||
}
|
||||
|
||||
public function load_permissions(object $event): void
|
||||
{
|
||||
$event->update_subarray('permissions', 'u_pedodev_tagging_cantagposts', ['lang' => 'ACL_U_PEDODEV_TAGGING_CANTAGPOSTS', 'cat' => 'post']);
|
||||
}
|
||||
}
|
||||
190
event/posting_listener.php
Executable file
190
event/posting_listener.php
Executable file
|
|
@ -0,0 +1,190 @@
|
|||
<?php
|
||||
|
||||
namespace pedodev\tagging\event;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
use phpbb\config\config;
|
||||
use phpbb\template\template;
|
||||
use phpbb\db\driver\factory;
|
||||
use phpbb\language\language;
|
||||
use phpbb\auth\auth;
|
||||
|
||||
use pedodev\tagging\core\tag_helper;
|
||||
use pedodev\tagging\core\search_helper;
|
||||
use pedodev\tagging\core\request_helper;
|
||||
|
||||
class posting_listener implements EventSubscriberInterface
|
||||
{
|
||||
private string $error;
|
||||
private array $selected_tag_list;
|
||||
|
||||
public function __construct(
|
||||
private config $config,
|
||||
private template $template,
|
||||
private factory $db,
|
||||
private language $language,
|
||||
private auth $auth,
|
||||
|
||||
private tag_helper $tag_helper,
|
||||
private search_helper $search_helper,
|
||||
private request_helper $request_helper,
|
||||
) {}
|
||||
|
||||
static public function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
'core.modify_posting_parameters' => 'load_language',
|
||||
'core.posting_modify_template_vars' => 'template_add_tags',
|
||||
'core.posting_modify_submission_errors' => 'check_errors',
|
||||
'core.submit_post_end' => 'posting_add_tags',
|
||||
];
|
||||
}
|
||||
|
||||
public function load_language(object $event): void
|
||||
{
|
||||
$this->language->add_lang('tagging_post', 'pedodev/tagging');
|
||||
}
|
||||
|
||||
public function check_errors(object $event): void
|
||||
{
|
||||
$error = $event['error'];
|
||||
|
||||
$this->selected_tag_list = $this->request_helper->get_selected_tags();
|
||||
$tag_count = count($this->selected_tag_list);
|
||||
|
||||
if (!isset($event['post_data']['topic_first_post_id']) || $event['post_id'] == $event['post_data']['topic_first_post_id'])
|
||||
{
|
||||
$allowed = $this->config['pedodev_tagging_tagthreads'];
|
||||
$error_msg = $this->language->lang('TAGGING_THREAD_ERROR');
|
||||
}
|
||||
else
|
||||
{
|
||||
$allowed = $this->config['pedodev_tagging_tagposts'];
|
||||
$error_msg = $this->language->lang('TAGGING_POST_ERROR');
|
||||
}
|
||||
|
||||
if (!$this->auth->acl_get('u_pedodev_tagging_cantagposts') && $tag_count > 0)
|
||||
{
|
||||
$error[] = $this->language->lang('TAGGING_PERMISSION_ERROR');
|
||||
}
|
||||
else if (!$allowed && $tag_count > 0)
|
||||
{
|
||||
$error[] = $error_msg;
|
||||
}
|
||||
else if ($tag_count > $this->config['pedodev_tagging_maxtags'])
|
||||
{
|
||||
$error[] = $this->language->lang('TAGGING_LIMIT_ERROR', $this->config['pedodev_tagging_maxtags'], count($this->selected_tag_list));
|
||||
}
|
||||
|
||||
$event['error'] = $error;
|
||||
}
|
||||
|
||||
public function template_add_tags(object $event): void
|
||||
{
|
||||
if (!isset($event['post_data']['topic_first_post_id']) || $event['post_id'] == $event['post_data']['topic_first_post_id'])
|
||||
{
|
||||
$allowed = $this->config['pedodev_tagging_tagthreads'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$allowed = $this->config['pedodev_tagging_tagposts'];
|
||||
}
|
||||
|
||||
if (!$allowed || !$this->auth->acl_get('u_pedodev_tagging_cantagposts'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$post_id = (int)$event['post_id'];
|
||||
|
||||
if (isset($this->selected_tag_list))
|
||||
{
|
||||
$post_tags = $this->selected_tag_list;
|
||||
}
|
||||
else if ($post_id != 0)
|
||||
{
|
||||
$post_tags = $this->search_helper->search_post_tags(array($post_id));
|
||||
$post_tags = empty($post_tags) ? array() : current($post_tags);
|
||||
}
|
||||
else
|
||||
{
|
||||
$post_tags = array();
|
||||
}
|
||||
|
||||
$active_tag_list = $this->tag_helper->get_active_tag_list();
|
||||
|
||||
$this->template->assign_var('TAGGING_ALLOWED', 1);
|
||||
|
||||
if ($event['preview'])
|
||||
{
|
||||
$this->template->assign_var('POST_TAGS', implode(' ', array_map([$this->tag_helper, 'get_colored_title'], $post_tags)));
|
||||
}
|
||||
|
||||
foreach ($active_tag_list as $id => $tag)
|
||||
{
|
||||
$this->template->assign_block_vars('tags', [
|
||||
'ID' => $id,
|
||||
'TITLE' => $tag['title'],
|
||||
'COLOR' => $tag['color'],
|
||||
'SELECTED' => in_array($id, $post_tags),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function posting_add_tags(object $event): void
|
||||
{
|
||||
$post_id = $event['data']['post_id'];
|
||||
|
||||
switch ($event['mode'])
|
||||
{
|
||||
case 'post':
|
||||
$this->insert_post_tags($post_id);
|
||||
break;
|
||||
case 'reply':
|
||||
$this->insert_post_tags($post_id);
|
||||
break;
|
||||
case 'edit':
|
||||
$this->delete_post_tags($post_id);
|
||||
$this->insert_post_tags($post_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function insert_post_tags(int $post_id): void
|
||||
{
|
||||
if ($post_id <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$sql_ary = array();
|
||||
$active_tag_list = $this->tag_helper->get_active_tag_list();
|
||||
|
||||
foreach ($active_tag_list as $id => $tag)
|
||||
{
|
||||
if (in_array($id, $this->selected_tag_list))
|
||||
{
|
||||
$sql_ary[] = [
|
||||
'post_id' => (int)$post_id,
|
||||
'tag_id' => (int)$id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->sql_multi_insert($this->tag_helper->get_tag_table(), $sql_ary);
|
||||
}
|
||||
|
||||
private function delete_post_tags(int $post_id): void
|
||||
{
|
||||
if ($post_id <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = 'DELETE FROM ' . $this->tag_helper->get_tag_table() . '
|
||||
WHERE post_id = ' . (int)$post_id;
|
||||
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
}
|
||||
166
event/search_tag_listener.php
Executable file
166
event/search_tag_listener.php
Executable file
|
|
@ -0,0 +1,166 @@
|
|||
<?php
|
||||
|
||||
namespace pedodev\tagging\event;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
use phpbb\config\config;
|
||||
use phpbb\template\template;
|
||||
use phpbb\language\language;
|
||||
|
||||
use pedodev\tagging\core\tag_helper;
|
||||
use pedodev\tagging\core\search_helper;
|
||||
use pedodev\tagging\core\request_helper;
|
||||
|
||||
class search_tag_listener implements EventSubscriberInterface
|
||||
{
|
||||
private array $post_tags;
|
||||
private string $mode;
|
||||
|
||||
public function __construct(
|
||||
private config $config,
|
||||
private template $template,
|
||||
private language $language,
|
||||
|
||||
private tag_helper $tag_helper,
|
||||
private search_helper $search_helper,
|
||||
private request_helper $request_helper,
|
||||
) {}
|
||||
|
||||
static public function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
'core.search_modify_forum_select_list' => 'assign_presearch_tags',
|
||||
// 'core.search_backend_search_after' => [['fetch_results_tags', 0], ['search_by_tag', 1]],
|
||||
'core.search_modify_url_parameters' => 'add_tags_url',
|
||||
// 'core.search_modify_tpl_ary' => 'assign_results_tags',
|
||||
'core.search_modify_submit_parameters' => 'load_language',
|
||||
'core.search_native_keywords_count_query_before' => 'test_func',
|
||||
];
|
||||
}
|
||||
|
||||
public function load_language(object $event): void
|
||||
{
|
||||
$this->language->add_lang('tagging_search', 'pedodev/tagging');
|
||||
}
|
||||
|
||||
public function assign_presearch_tags(object $event): void
|
||||
{
|
||||
if (!$this->config['pedodev_tagging_tagsearch'])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$active_tag_list = $this->tag_helper->get_searchable_tag_list();
|
||||
|
||||
$this->template->assign_var('TAGGING_ALLOWED', 1);
|
||||
|
||||
foreach ($active_tag_list as $id => $tag)
|
||||
{
|
||||
$this->template->assign_block_vars('tags', [
|
||||
'ID' => $id,
|
||||
'TITLE' => $tag['title'],
|
||||
'COLOR' => $tag['color'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function fetch_results_tags(object $event): void
|
||||
{
|
||||
if (!$this->config['pedodev_tagging_results'])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->mode = $event['show_results'];
|
||||
|
||||
if ($this->mode === 'posts')
|
||||
{
|
||||
$this->post_tags = $this->search_helper->search_post_tags($event['id_ary']);
|
||||
}
|
||||
else if ($this->mode === 'topics')
|
||||
{
|
||||
$this->post_tags = $this->search_helper->search_topic_tags($event['id_ary']);
|
||||
}
|
||||
}
|
||||
|
||||
public function add_tags_url(object $event): void
|
||||
{
|
||||
$tag_ids = $this->request_helper->get_selected_tags();
|
||||
|
||||
if (empty($tag_ids))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$u_search = $event['u_search'];
|
||||
$u_search .= '&tag_' . implode('=1&tag_', $tag_ids) . '=1';
|
||||
$u_search .= '&tag_filter=' . $this->request_helper->get_tag_filter();
|
||||
$event['u_search'] = $u_search;
|
||||
}
|
||||
|
||||
public function assign_results_tags(object $event): void
|
||||
{
|
||||
if (!$this->config['pedodev_tagging_results'])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$post_row = $event['tpl_ary'];
|
||||
$post_id = $post_row['POST_ID'] ? (int)$post_row['POST_ID'] : (int)$post_row['TOPIC_ID'];
|
||||
|
||||
if (array_key_exists($post_id, $this->post_tags))
|
||||
{
|
||||
$post_tags = $this->post_tags[$post_id];
|
||||
$tags = implode(' ', array_map([$this->tag_helper, 'get_colored_title'], $post_tags));
|
||||
$post_row['POST_TAGS'] = $tags;
|
||||
}
|
||||
|
||||
$event['tpl_ary'] = $post_row;
|
||||
}
|
||||
|
||||
public function search_by_tag(object $event): void
|
||||
{
|
||||
if (!$this->config['pedodev_tagging_tagsearch'])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$id_ary = $event['id_ary'];
|
||||
|
||||
if (empty($id_ary) && $this->request_helper->is_keyword_search())
|
||||
{
|
||||
var_dump("Empty search");
|
||||
return;
|
||||
}
|
||||
|
||||
$tag_ids = $this->request_helper->get_selected_tags();
|
||||
|
||||
if (empty($tag_ids))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$mode = $event['show_results'];
|
||||
$tag_filter = $this->request_helper->get_tag_filter();
|
||||
|
||||
$post_ary = $this->search_helper->search_posts_by_tag($tag_ids, $tag_filter, $mode);
|
||||
|
||||
if (empty($id_ary))
|
||||
{
|
||||
$id_ary = $post_ary;
|
||||
}
|
||||
else
|
||||
{
|
||||
$id_ary = array_intersect($id_ary, $post_ary);
|
||||
}
|
||||
|
||||
$event['id_ary'] = $id_ary;
|
||||
$event['total_match_count'] = count($id_ary);
|
||||
}
|
||||
|
||||
public function test_func(object $event): void
|
||||
{
|
||||
// var_dump($event);
|
||||
}
|
||||
}
|
||||
59
event/viewforum_listener.php
Executable file
59
event/viewforum_listener.php
Executable file
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace pedodev\tagging\event;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
use phpbb\config\config;
|
||||
|
||||
use pedodev\tagging\core\tag_helper;
|
||||
use pedodev\tagging\core\search_helper;
|
||||
|
||||
class viewforum_listener implements EventSubscriberInterface
|
||||
{
|
||||
private array $topic_tags;
|
||||
|
||||
public function __construct(
|
||||
private config $config,
|
||||
private tag_helper $tag_helper,
|
||||
private search_helper $search_helper,
|
||||
) {}
|
||||
|
||||
static public function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
'core.viewforum_modify_topics_data' => 'fetch_topic_tags',
|
||||
'core.viewforum_modify_topicrow' => 'assign_topic_tags',
|
||||
];
|
||||
}
|
||||
|
||||
public function fetch_topic_tags(object $event): void
|
||||
{
|
||||
if (!$this->config['pedodev_tagging_viewforum'])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->topic_tags = $this->search_helper->search_topic_tags($event['topic_list']);
|
||||
}
|
||||
|
||||
public function assign_topic_tags(object $event): void
|
||||
{
|
||||
if (!$this->config['pedodev_tagging_viewforum'])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$topic_row = $event['topic_row'];
|
||||
$topic_id = (int)$topic_row['TOPIC_ID'];
|
||||
|
||||
if (array_key_exists($topic_id, $this->topic_tags))
|
||||
{
|
||||
$topic_tags = $this->topic_tags[$topic_id];
|
||||
$tags = implode(' ', array_map([$this->tag_helper, 'get_colored_title'], $topic_tags));
|
||||
$topic_row['TOPIC_TAGS'] = $tags;
|
||||
}
|
||||
|
||||
$event['topic_row'] = $topic_row;
|
||||
}
|
||||
}
|
||||
59
event/viewtopic_listener.php
Executable file
59
event/viewtopic_listener.php
Executable file
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace pedodev\tagging\event;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
use phpbb\config\config;
|
||||
|
||||
use pedodev\tagging\core\tag_helper;
|
||||
use pedodev\tagging\core\search_helper;
|
||||
|
||||
class viewtopic_listener implements EventSubscriberInterface
|
||||
{
|
||||
private array $post_tags;
|
||||
|
||||
public function __construct(
|
||||
private config $config,
|
||||
private tag_helper $tag_helper,
|
||||
private search_helper $search_helper,
|
||||
) {}
|
||||
|
||||
static public function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
'core.viewtopic_get_post_data' => 'fetch_post_tags',
|
||||
'core.viewtopic_modify_post_row' => 'assign_post_tags',
|
||||
];
|
||||
}
|
||||
|
||||
public function fetch_post_tags(object $event): void
|
||||
{
|
||||
if (!$this->config['pedodev_tagging_viewtopic'])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->post_tags = $this->search_helper->search_post_tags($event['post_list']);
|
||||
}
|
||||
|
||||
public function assign_post_tags(object $event): void
|
||||
{
|
||||
if (!$this->config['pedodev_tagging_viewtopic'])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$post_row = $event['post_row'];
|
||||
$post_id = (int)$post_row['POST_ID'];
|
||||
|
||||
if (array_key_exists($post_id, $this->post_tags))
|
||||
{
|
||||
$post_tags = $this->post_tags[$post_id];
|
||||
$tags = implode(' ', array_map([$this->tag_helper, 'get_colored_title'], $post_tags));
|
||||
$post_row['POST_TAGS'] = $tags;
|
||||
}
|
||||
|
||||
$event['post_row'] = $post_row;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue