Ajout d'une extension
This commit is contained in:
266
ext/phpbbstudio/aps/event/acp.php
Normal file
266
ext/phpbbstudio/aps/event/acp.php
Normal file
@@ -0,0 +1,266 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\event;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System Event listener: ACP.
|
||||
*/
|
||||
class acp implements EventSubscriberInterface
|
||||
{
|
||||
/** @var \phpbbstudio\aps\core\acp */
|
||||
protected $acp;
|
||||
|
||||
/** @var \phpbb\auth\auth */
|
||||
protected $auth;
|
||||
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
|
||||
/** @var \phpbbstudio\aps\core\functions */
|
||||
protected $functions;
|
||||
|
||||
/** @var \phpbb\controller\helper */
|
||||
protected $helper;
|
||||
|
||||
/** @var \phpbb\language\language */
|
||||
protected $language;
|
||||
|
||||
/** @var \phpbb\log\log */
|
||||
protected $log;
|
||||
|
||||
/** @var \phpbbstudio\aps\core\log */
|
||||
protected $log_aps;
|
||||
|
||||
/** @var \phpbb\request\request */
|
||||
protected $request;
|
||||
|
||||
/** @var \phpbb\template\template */
|
||||
protected $template;
|
||||
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbbstudio\aps\core\acp $acp APS ACP functions
|
||||
* @param \phpbb\auth\auth $auth Authentication object
|
||||
* @param \phpbb\config\config $config Configuration object
|
||||
* @param \phpbbstudio\aps\core\functions $functions APS Core functions
|
||||
* @param \phpbb\controller\helper $helper Controller helper object
|
||||
* @param \phpbb\language\language $language Language object
|
||||
* @param \phpbb\log\log $log phpBB Log object
|
||||
* @param \phpbbstudio\aps\core\log $log_aps APS Log object
|
||||
* @param \phpbb\request\request $request Request object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param \phpbb\user $user User object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(
|
||||
\phpbbstudio\aps\core\acp $acp,
|
||||
\phpbb\auth\auth $auth,
|
||||
\phpbb\config\config $config,
|
||||
\phpbbstudio\aps\core\functions $functions,
|
||||
\phpbb\controller\helper $helper,
|
||||
\phpbb\language\language $language,
|
||||
\phpbb\log\log $log,
|
||||
\phpbbstudio\aps\core\log $log_aps,
|
||||
\phpbb\request\request $request,
|
||||
\phpbb\template\template $template,
|
||||
\phpbb\user $user
|
||||
)
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
528
ext/phpbbstudio/aps/event/actions.php
Normal file
528
ext/phpbbstudio/aps/event/actions.php
Normal file
@@ -0,0 +1,528 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\event;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System Event listener: Actions.
|
||||
*/
|
||||
class actions implements EventSubscriberInterface
|
||||
{
|
||||
/** @var \phpbb\auth\auth */
|
||||
protected $auth;
|
||||
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
|
||||
/** @var \phpbbstudio\aps\core\functions */
|
||||
protected $functions;
|
||||
|
||||
/** @var \phpbbstudio\aps\actions\manager */
|
||||
protected $manager;
|
||||
|
||||
/** @var \phpbb\request\request */
|
||||
protected $request;
|
||||
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/** @var string phpBB root path */
|
||||
protected $root_path;
|
||||
|
||||
/** @var string PHP file extension */
|
||||
protected $php_ext;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\auth\auth $auth Authentication object
|
||||
* @param \phpbb\config\config $config Configuration object
|
||||
* @param \phpbbstudio\aps\core\functions $functions APS Core functions
|
||||
* @param \phpbbstudio\aps\actions\manager $manager APS Manager object
|
||||
* @param \phpbb\request\request $request Request object
|
||||
* @param \phpbb\user $user User object
|
||||
* @param string $root_path phpBB root path
|
||||
* @param string $php_ext php File extension
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(
|
||||
\phpbb\auth\auth $auth,
|
||||
\phpbb\config\config $config,
|
||||
\phpbbstudio\aps\core\functions $functions,
|
||||
\phpbbstudio\aps\actions\manager $manager,
|
||||
\phpbb\request\request $request,
|
||||
\phpbb\user $user,
|
||||
$root_path,
|
||||
$php_ext
|
||||
)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->config = $config;
|
||||
$this->functions = $functions;
|
||||
$this->manager = $manager;
|
||||
$this->request = $request;
|
||||
$this->user = $user;
|
||||
|
||||
$this->root_path = $root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign functions defined in this class to event listeners in the core.
|
||||
*
|
||||
* @static
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
static public function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
/* User actions */
|
||||
'core.modify_posting_auth' => 'bump',
|
||||
'core.submit_post_end' => 'post',
|
||||
'core.delete_post_after' => 'post_delete',
|
||||
'core.viewtopic_modify_poll_ajax_data' => 'vote',
|
||||
|
||||
/* Moderator actions */
|
||||
'core.mcp_main_modify_fork_sql' => 'copy',
|
||||
'core.mcp_change_poster_after' => 'change',
|
||||
'core.delete_topics_before_query' => 'delete',
|
||||
'core.posting_modify_submit_post_before' => 'lock_and_type',
|
||||
'core.mcp_lock_unlock_after' => 'lock',
|
||||
'core.move_posts_before' => 'move_posts',
|
||||
'core.move_topics_before_query' => 'move_topics',
|
||||
'core.approve_posts_after' => 'queue',
|
||||
'core.approve_topics_after' => 'queue',
|
||||
'core.disapprove_posts_after' => 'queue',
|
||||
'core.mcp_forum_merge_topics_after' => 'merge',
|
||||
|
||||
/* Global actions */
|
||||
'core.ucp_register_register_after' => 'register',
|
||||
'core.mcp_warn_post_after' => 'warn',
|
||||
'core.mcp_warn_user_after' => 'warn',
|
||||
'core.submit_pm_after' => 'pm',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger Advanced Points System action: “bump”!
|
||||
*
|
||||
* @event core.modify_posting_auth
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function bump(\phpbb\event\data $event)
|
||||
{
|
||||
if (
|
||||
($event['mode'] !== 'bump')
|
||||
||
|
||||
(!$event['is_authed'] || !empty($event['error']) || $event['post_data']['forum_type'] != FORUM_POST)
|
||||
||
|
||||
(($event['post_data']['forum_status'] == ITEM_LOCKED || (isset($event['post_data']['topic_status']) && $event['post_data']['topic_status'] == ITEM_LOCKED)) && !$this->auth->acl_get('m_edit', $event['forum_id']))
|
||||
)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ($bump_time = bump_topic_allowed($event['forum_id'], $event['post_data']['topic_bumped'], $event['post_data']['topic_last_post_time'], $event['post_data']['topic_poster'], $event['post_data']['topic_last_poster_id'])
|
||||
&& check_link_hash($this->request->variable('hash', ''), "topic_{$event['post_data']['topic_id']}"))
|
||||
{
|
||||
$this->manager->trigger('topic', $this->user->data['user_id'], $event, $event['forum_id']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger Advanced Points System action: “post” or “topic”!
|
||||
*
|
||||
* @event core.submit_post_end
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function post(\phpbb\event\data $event)
|
||||
{
|
||||
if ($event['mode'] === 'edit' && $event['data']['poster_id'] != $this->user->data['user_id'])
|
||||
{
|
||||
$this->manager->trigger('edit', $event['data']['poster_id'], $event, $event['data']['forum_id']);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($event['mode'])
|
||||
{
|
||||
case 'edit':
|
||||
$action = $event['data']['topic_first_post_id'] == $event['data']['post_id'] ? 'topic' : 'post';
|
||||
break;
|
||||
|
||||
case 'post':
|
||||
$action = 'topic';
|
||||
break;
|
||||
|
||||
case 'reply':
|
||||
case 'quote':
|
||||
$action = 'post';
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
$this->manager->trigger($action, $this->user->data['user_id'], $event, $event['data']['forum_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger Advanced Points System action: “delete” or “post”!
|
||||
*
|
||||
* @event core.delete_post_after
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function post_delete(\phpbb\event\data $event)
|
||||
{
|
||||
if ($this->user->data['user_id'] == $event['data']['poster_id'])
|
||||
{
|
||||
$data = array_merge($this->manager->clean_event($event), [
|
||||
'mode' => ($event['is_soft'] ? 'soft_' : '') . 'delete',
|
||||
'post_data' => ['topic_type' => POST_NORMAL],
|
||||
]);
|
||||
|
||||
$this->manager->trigger('post', $event['data']['poster_id'], $data, $event['forum_id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = [
|
||||
'action' => 'post',
|
||||
'is_soft' => $event['is_soft'],
|
||||
'posts' => [
|
||||
0 => [
|
||||
'forum_id' => $event['forum_id'],
|
||||
'topic_id' => $event['topic_id'],
|
||||
'post_id' => $event['post_id'],
|
||||
'poster_id' => $event['data']['poster_id'],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->manager->trigger('delete', $event['data']['poster_id'], $data, $event['forum_id']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger Advanced Points System action: “vote”!
|
||||
*
|
||||
* @event core.viewtopic_modify_poll_ajax_data
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function vote(\phpbb\event\data $event)
|
||||
{
|
||||
$this->manager->trigger('vote', $this->user->data['user_id'], $event, $event['forum_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger Advanced Points System action: “copy”!
|
||||
*
|
||||
* @event core.mcp_main_modify_fork_sql
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function copy(\phpbb\event\data $event)
|
||||
{
|
||||
$this->manager->trigger('copy', $event['topic_row']['topic_poster'], $event, [(int) $event['topic_row']['forum_id'], (int) $event['sql_ary']['forum_id']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger Advanced Points System action: “change”!
|
||||
*
|
||||
* @event core.mcp_change_poster_after
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function change(\phpbb\event\data $event)
|
||||
{
|
||||
$this->manager->trigger('change', [$event['userdata']['user_id'], $event['post_info']['poster_id']], $event, $event['post_info']['forum_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger Advanced Points System action: “delete”!
|
||||
*
|
||||
* @event core.delete_topics_before_query
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function delete(\phpbb\event\data $event)
|
||||
{
|
||||
// Check for chain triggering events
|
||||
if (!$this->config['aps_chain_merge_delete'] && $this->request->variable('action', '', true) === 'merge_topics')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!function_exists('phpbb_get_topic_data'))
|
||||
{
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
include $this->root_path . 'includes/functions_mcp.' . $this->php_ext;
|
||||
}
|
||||
|
||||
$topics = phpbb_get_topic_data($event['topic_ids']);
|
||||
|
||||
$forum_ids = $this->manager->get_identifiers($topics, 'forum_id');
|
||||
$user_ids = $this->manager->get_identifiers($topics, 'topic_poster');
|
||||
|
||||
$data = array_merge($this->manager->clean_event($event), [
|
||||
'action' => 'topic',
|
||||
'topics' => $topics,
|
||||
]);
|
||||
|
||||
$this->manager->trigger('delete', $user_ids, $data, $forum_ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger Advanced Points System action: “lock” and/or “type”!
|
||||
*
|
||||
* @event core.posting_modify_submit_post_before
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function lock_and_type(\phpbb\event\data $event)
|
||||
{
|
||||
if ($event['mode'] === 'edit')
|
||||
{
|
||||
if ($this->user->data['user_id'] != $event['data']['poster_id'])
|
||||
{
|
||||
$row = $this->functions->topic_post_locked($event['data']['post_id']);
|
||||
|
||||
if ($row['post_edit_locked'] != $event['data']['post_edit_locked'])
|
||||
{
|
||||
$data = array_merge($this->manager->clean_event($event), [
|
||||
'action' => $event['data']['post_edit_locked'] ? 'lock_post' : 'unlock_post',
|
||||
'data' => [$event['data']],
|
||||
]);
|
||||
|
||||
$this->manager->trigger('lock', $event['data']['poster_id'], $data, $event['data']['forum_id']);
|
||||
}
|
||||
|
||||
if ($row['topic_status'] != $event['data']['topic_status'])
|
||||
{
|
||||
$data = array_merge($this->manager->clean_event($event), [
|
||||
'action' => $event['data']['topic_status'] ? 'unlock' : 'lock',
|
||||
'data' => [$event['data'] + ['topic_poster' => (int) $row['topic_poster']]],
|
||||
]);
|
||||
|
||||
$this->manager->trigger('lock', $row['topic_poster'], $data, $event['data']['forum_id']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($event['post_data']['orig_topic_type'] != $event['post_data']['topic_type'])
|
||||
{
|
||||
$data = array_merge($this->manager->clean_event($event), [
|
||||
'type_from' => $event['post_data']['orig_topic_type'],
|
||||
'type_to' => $event['post_data']['topic_type'],
|
||||
]);
|
||||
|
||||
$this->manager->trigger('topic_type', $event['post_data']['topic_poster'], $data, $event['data']['forum_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger Advanced Points System action: “lock”!
|
||||
*
|
||||
* @event core.mcp_lock_unlock_after
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function lock(\phpbb\event\data $event)
|
||||
{
|
||||
$s_user = in_array($event['action'], ['lock', 'unlock']) ? 'topic_poster' : 'poster_id';
|
||||
|
||||
$forum_ids = $this->manager->get_identifiers($event['data'], 'forum_id');
|
||||
$user_ids = $this->manager->get_identifiers($event['data'] , $s_user);
|
||||
|
||||
$this->manager->trigger('lock', $user_ids, $event, $forum_ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger Advanced Points System action: “move”!
|
||||
*
|
||||
* @event core.move_posts_before
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function move_posts(\phpbb\event\data $event)
|
||||
{
|
||||
// Check for chain triggering events
|
||||
if (!$this->config['aps_chain_merge_move'] && $this->request->variable('action', '', true) === 'merge_topics')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!function_exists('phpbb_get_topic_data'))
|
||||
{
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
include $this->root_path . 'includes/functions_mcp.' . $this->php_ext;
|
||||
}
|
||||
|
||||
$posts = phpbb_get_post_data($event['post_ids']);
|
||||
|
||||
$forum_ids = $this->manager->get_identifiers($posts, 'forum_id');
|
||||
$user_ids = $this->manager->get_identifiers($posts, 'poster_id');
|
||||
|
||||
$data = array_merge($this->manager->clean_event($event), [
|
||||
'action' => 'post',
|
||||
'posts' => $posts,
|
||||
]);
|
||||
|
||||
$this->manager->trigger('move', $user_ids, $data, $forum_ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger Advanced Points System action: “move”!
|
||||
*
|
||||
* @event core.move_topics_before_query
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function move_topics(\phpbb\event\data $event)
|
||||
{
|
||||
if (!function_exists('phpbb_get_topic_data'))
|
||||
{
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
include $this->root_path . 'includes/functions_mcp.' . $this->php_ext;
|
||||
}
|
||||
|
||||
$topics = phpbb_get_topic_data($event['topic_ids']);
|
||||
|
||||
$forum_ids = $this->manager->get_identifiers($topics, 'forum_id');
|
||||
$user_ids = $this->manager->get_identifiers($topics, 'topic_poster');
|
||||
|
||||
$data = array_merge($this->manager->clean_event($event), [
|
||||
'action' => 'topic',
|
||||
'topics' => $topics,
|
||||
]);
|
||||
|
||||
$this->manager->trigger('move', $user_ids, $data, $forum_ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger Advanced Points System action: “queue”!
|
||||
*
|
||||
* @event core.approve_posts_after
|
||||
* @event core.approve_topics_after
|
||||
* @event core.disapprove_posts_after
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function queue(\phpbb\event\data $event)
|
||||
{
|
||||
$data = array_merge($this->manager->clean_event($event), [
|
||||
'mode' => isset($event['action']) ? $event['action'] : 'disapprove',
|
||||
]);
|
||||
|
||||
$posts = isset($event['post_info']) ? $event['post_info'] : $event['topic_info'];
|
||||
|
||||
$forum_ids = $this->manager->get_identifiers($posts, 'forum_id');
|
||||
$user_ids = $this->manager->get_identifiers($posts, 'poster_id');
|
||||
|
||||
$this->manager->trigger('queue', $user_ids, $data, $forum_ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger Advanced Points System action: “merge”!
|
||||
*
|
||||
* @event core.mcp_forum_merge_topics_after
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function merge(\phpbb\event\data $event)
|
||||
{
|
||||
$user_ids = $this->manager->get_identifiers($event['all_topic_data'], 'topic_poster');
|
||||
|
||||
$this->manager->trigger('merge', $user_ids, $event, $event['all_topic_data'][$event['to_topic_id']]['forum_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger Advanced Points System action: “register”!
|
||||
*
|
||||
* @event core.ucp_register_register_after
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function register(\phpbb\event\data $event)
|
||||
{
|
||||
$this->manager->trigger('register', $event['user_id'], $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger Advanced Points System action: “warn”!
|
||||
*
|
||||
* @event core.mcp_warn_post_after
|
||||
* @event core.mcp_warn_user_after
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function warn(\phpbb\event\data $event)
|
||||
{
|
||||
$this->manager->trigger('warn', $event['user_row']['user_id'], $event, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger Advanced Points System action: “pm”!
|
||||
*
|
||||
* @event core.submit_pm_after
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function pm(\phpbb\event\data $event)
|
||||
{
|
||||
// Check for chain triggering events
|
||||
if (!$this->config['aps_chain_warn_pm'] && $this->request->variable('mode', '', true) === 'warn_user')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->manager->trigger('pm', [], $event, 0);
|
||||
}
|
||||
}
|
||||
275
ext/phpbbstudio/aps/event/check.php
Normal file
275
ext/phpbbstudio/aps/event/check.php
Normal file
@@ -0,0 +1,275 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\event;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System Event listener: Check.
|
||||
*/
|
||||
class check implements EventSubscriberInterface
|
||||
{
|
||||
/** @var \phpbbstudio\aps\core\functions */
|
||||
protected $functions;
|
||||
|
||||
/** @var \phpbb\language\language */
|
||||
protected $language;
|
||||
|
||||
/** @var \phpbb\template\template */
|
||||
protected $template;
|
||||
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/** @var \phpbbstudio\aps\points\valuator */
|
||||
protected $valuator;
|
||||
|
||||
/** @var double|false The minimum point value */
|
||||
protected $min;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\config\config $config Configuration object
|
||||
* @param \phpbbstudio\aps\core\functions $functions APS Core functions
|
||||
* @param \phpbb\language\language $language Language object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param \phpbb\user $user User object
|
||||
* @param \phpbbstudio\aps\points\valuator $valuator APS Valuator object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(
|
||||
\phpbb\config\config $config,
|
||||
\phpbbstudio\aps\core\functions $functions,
|
||||
\phpbb\language\language $language,
|
||||
\phpbb\template\template $template,
|
||||
\phpbb\user $user,
|
||||
\phpbbstudio\aps\points\valuator $valuator
|
||||
)
|
||||
{
|
||||
$this->functions = $functions;
|
||||
$this->language = $language;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
$this->valuator = $valuator;
|
||||
|
||||
$this->min = $config['aps_points_min'] !== '' ? (double) $config['aps_points_min'] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign functions defined in this class to event listeners in the core.
|
||||
*
|
||||
* @static
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
static public function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
'core.viewtopic_modify_page_title' => 'check_bump',
|
||||
'core.handle_post_delete_conditions' => 'check_delete',
|
||||
'core.modify_posting_auth' => 'check_post',
|
||||
'core.viewtopic_modify_poll_data' => 'check_vote',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the action: "Bump".
|
||||
*
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function check_bump(\phpbb\event\data $event)
|
||||
{
|
||||
if ($this->min === false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If there already is no bump link, return
|
||||
if ($this->template->retrieve_var('U_BUMP_TOPIC') === '')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the value
|
||||
$value = $this->get_value('aps_bump', $event['forum_id']);
|
||||
|
||||
// Check if the value is negative
|
||||
if ($value >= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->below_min($value))
|
||||
{
|
||||
$this->template->assign_var('U_BUMP_TOPIC', '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the action: "Delete".
|
||||
*
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function check_delete(\phpbb\event\data $event)
|
||||
{
|
||||
if ($this->min === false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (confirm_box(true))
|
||||
{
|
||||
$data = $this->functions->post_data($event['post_id']);
|
||||
|
||||
if ($this->user->data['user_id'] != $data['poster_id'])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$field = 'aps_post_delete' . ($event['is_soft'] ? '_soft' : '');
|
||||
|
||||
if ($value = $this->check_value($field, $event['forum_id']))
|
||||
{
|
||||
$event['error'] = array_merge($event['error'], [
|
||||
$this->language->lang('APS_POINTS_TOO_LOW', $this->functions->get_name()) . '<br>' .
|
||||
$this->language->lang('APS_POINTS_ACTION_COST', $this->functions->display_points($value))
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the action: "Post" and "Topic".
|
||||
*
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function check_post(\phpbb\event\data $event)
|
||||
{
|
||||
if ($this->min === false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($event['mode'])
|
||||
{
|
||||
default:
|
||||
return;
|
||||
break;
|
||||
|
||||
case 'post':
|
||||
$field = 'aps_topic_base';
|
||||
break;
|
||||
|
||||
case 'reply':
|
||||
case 'quote':
|
||||
$field = 'aps_post_base';
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
$data = $this->functions->post_data($event['post_id']);
|
||||
|
||||
if ($this->user->data['user_id'] != $data['poster_id'])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$type = $data['topic_first_post_id'] == $event['post_id'] ? 'topic' : 'post';
|
||||
$field = 'aps_' . $type . '_edit';
|
||||
break;
|
||||
}
|
||||
|
||||
if ($value = $this->check_value($field, $event['forum_id']))
|
||||
{
|
||||
$event['error'] = array_merge($event['error'], [
|
||||
$this->language->lang('APS_POINTS_TOO_LOW', $this->functions->get_name()) . '<br>' .
|
||||
$this->language->lang('APS_POINTS_ACTION_COST', $this->functions->display_points($value))
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the action: "Vote".
|
||||
*
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function check_vote(\phpbb\event\data $event)
|
||||
{
|
||||
if ($this->min === false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->check_value('aps_vote', $event['forum_id']))
|
||||
{
|
||||
$event['s_can_vote'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the user has enough points to perform an action.
|
||||
*
|
||||
* @param int $field The points field
|
||||
* @param int $forum_id The forum identifier
|
||||
* @return double|false The points value
|
||||
* @access protected
|
||||
*/
|
||||
protected function check_value($field, $forum_id)
|
||||
{
|
||||
$value = $this->get_value($field, $forum_id);
|
||||
|
||||
$check = $value < 0 && $this->below_min($value) ? $value : false;
|
||||
|
||||
return $check;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base value for a points action.
|
||||
*
|
||||
* @param int $field The points field
|
||||
* @param int $forum_id The forum identifier
|
||||
* @return double The points value
|
||||
* @access protected
|
||||
*/
|
||||
protected function get_value($field, $forum_id)
|
||||
{
|
||||
$fields = [0 => [$field]];
|
||||
|
||||
$values = $this->valuator->get_points($fields, $forum_id, false);
|
||||
|
||||
$value = isset($values[$forum_id][$field]) ? $values[$forum_id][$field] : 0.00;
|
||||
|
||||
return (double) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not the value is below the points minimum.
|
||||
*
|
||||
* @param double $value The points value
|
||||
* @return bool Whether or not the value is below the minimum
|
||||
* @access protected
|
||||
*/
|
||||
protected function below_min($value)
|
||||
{
|
||||
$points = $this->functions->equate_points($this->user->data['user_points'], $value);
|
||||
|
||||
return (bool) ($points < $this->min);
|
||||
}
|
||||
}
|
||||
200
ext/phpbbstudio/aps/event/display.php
Normal file
200
ext/phpbbstudio/aps/event/display.php
Normal file
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\event;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System Event listener: Display.
|
||||
*/
|
||||
class display implements EventSubscriberInterface
|
||||
{
|
||||
/** @var \phpbbstudio\aps\core\functions */
|
||||
protected $functions;
|
||||
|
||||
/** @var \phpbb\controller\helper */
|
||||
protected $helper;
|
||||
|
||||
/** @var \phpbb\language\language */
|
||||
protected $language;
|
||||
|
||||
/** @var \phpbb\template\template */
|
||||
protected $template;
|
||||
|
||||
/** @var string php File extension */
|
||||
protected $php_ext;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbbstudio\aps\core\functions $functions APS Core functions
|
||||
* @param \phpbb\controller\helper $helper Controller helper object
|
||||
* @param \phpbb\language\language $language Language object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param string $php_ext php File extension
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(
|
||||
\phpbbstudio\aps\core\functions $functions,
|
||||
\phpbb\controller\helper $helper,
|
||||
\phpbb\language\language $language,
|
||||
\phpbb\template\template $template,
|
||||
$php_ext
|
||||
)
|
||||
{
|
||||
$this->functions = $functions;
|
||||
$this->helper = $helper;
|
||||
$this->language = $language;
|
||||
$this->template = $template;
|
||||
|
||||
$this->php_ext = $php_ext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign functions defined in this class to event listeners in the core.
|
||||
*
|
||||
* @static
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
static public function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
'core.user_setup' => 'load_lang',
|
||||
'core.page_header_after' => 'display_links',
|
||||
|
||||
'core.viewonline_overwrite_location' => 'view_online',
|
||||
|
||||
'core.ucp_pm_view_message' => 'display_pm',
|
||||
'core.viewtopic_post_rowset_data' => 'set_post',
|
||||
'core.viewtopic_cache_user_data' => 'cache_post',
|
||||
'core.viewtopic_modify_post_row' => 'display_post',
|
||||
'core.memberlist_prepare_profile_data' => 'display_profile',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Load language during user set up.
|
||||
*
|
||||
* @event core.user_setup
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function load_lang()
|
||||
{
|
||||
$this->language->add_lang('aps_common', 'phpbbstudio/aps');
|
||||
}
|
||||
|
||||
public function display_links()
|
||||
{
|
||||
$locations = array_filter($this->functions->get_link_locations());
|
||||
|
||||
if ($locations)
|
||||
{
|
||||
$this->template->assign_vars(array_combine(array_map(function($key) {
|
||||
return 'S_APS_' . strtoupper($key);
|
||||
}, array_keys($locations)), $locations));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the points page when viewing the Who is Online page.
|
||||
*
|
||||
* @event core.viewonline_overwrite_location
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function view_online(\phpbb\event\data $event)
|
||||
{
|
||||
if ($event['on_page'][1] === 'app' && strrpos($event['row']['session_page'], 'app.' . $this->php_ext . '/points') === 0)
|
||||
{
|
||||
$event['location'] = $this->language->lang('APS_VIEWING_POINTS_PAGE', $this->functions->get_name());
|
||||
$event['location_url'] = $this->helper->route('phpbbstudio_aps_display');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the user points when viewing a Private Message.
|
||||
*
|
||||
* @event core.ucp_pm_view_message
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function display_pm(\phpbb\event\data $event)
|
||||
{
|
||||
$event['msg_data'] = array_merge($event['msg_data'], [
|
||||
'AUTHOR_POINTS' => $event['user_info']['user_points'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user points after being retrieved from the database.
|
||||
*
|
||||
* @event core.viewtopic_post_rowset_data
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function set_post(\phpbb\event\data $event)
|
||||
{
|
||||
$event['rowset_data'] = array_merge($event['rowset_data'], [
|
||||
'user_points' => $event['row']['user_points'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache the user points when displaying a post.
|
||||
*
|
||||
* @event core.viewtopic_cache_user_data
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function cache_post(\phpbb\event\data $event)
|
||||
{
|
||||
$event['user_cache_data'] = array_merge($event['user_cache_data'], [
|
||||
'user_points' => $event['row']['user_points'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the user points when displaying a post.
|
||||
*
|
||||
* @event core.viewtopic_modify_post_row
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function display_post(\phpbb\event\data $event)
|
||||
{
|
||||
$event['post_row'] = array_merge($event['post_row'], [
|
||||
'POSTER_POINTS' => $event['user_cache'][$event['poster_id']]['user_points'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the user points when display a profile.
|
||||
*
|
||||
* @event core.memberlist_prepare_profile_data
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function display_profile(\phpbb\event\data $event)
|
||||
{
|
||||
$event['template_data'] = array_merge($event['template_data'], [
|
||||
'USER_POINTS' => $event['data']['user_points'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
83
ext/phpbbstudio/aps/event/modules.php
Normal file
83
ext/phpbbstudio/aps/event/modules.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\event;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System Event listener: Modules.
|
||||
*/
|
||||
class modules implements EventSubscriberInterface
|
||||
{
|
||||
/** @var \phpbbstudio\aps\core\functions */
|
||||
protected $functions;
|
||||
|
||||
/** @var \phpbb\language\language */
|
||||
protected $language;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbbstudio\aps\core\functions $functions APS Core functions
|
||||
* @param \phpbb\language\language $language Language object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function __construct(\phpbbstudio\aps\core\functions $functions, \phpbb\language\language $language)
|
||||
{
|
||||
$this->functions = $functions;
|
||||
$this->language = $language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign functions defined in this class to event listeners in the core.
|
||||
*
|
||||
* @static
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
static public function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
'core.modify_module_row' => 'module_names',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Localise the APS module titles.
|
||||
*
|
||||
* @event core.modify_module_row
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function module_names(\phpbb\event\data $event)
|
||||
{
|
||||
$module = $event['module_row'];
|
||||
|
||||
$langname = $module['langname'];
|
||||
|
||||
switch ($langname)
|
||||
{
|
||||
case 'ACP_APS_MODE_POINTS':
|
||||
case 'MCP_APS_POINTS':
|
||||
case 'UCP_APS_POINTS':
|
||||
$module['lang'] = $this->language->lang($langname, ucfirst($this->functions->get_name()));
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
$event['module_row'] = $module;
|
||||
}
|
||||
}
|
||||
67
ext/phpbbstudio/aps/event/permissions.php
Normal file
67
ext/phpbbstudio/aps/event/permissions.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* phpBB Studio - Advanced Points System. An extension for the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) 2019, phpBB Studio, https://www.phpbbstudio.com
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbbstudio\aps\event;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System Event listener: Permissions.
|
||||
*/
|
||||
class permissions implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* Assign functions defined in this class to event listeners in the core.
|
||||
*
|
||||
* @static
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
static public function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
'core.permissions' => 'permissions',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Advanced Points System permissions
|
||||
*
|
||||
* @event core.permissions
|
||||
* @param \phpbb\event\data $event The event object
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function permissions(\phpbb\event\data $event)
|
||||
{
|
||||
$categories = $event['categories'];
|
||||
$permissions = $event['permissions'];
|
||||
|
||||
if (empty($categories['phpbb_studio']))
|
||||
{
|
||||
$categories['phpbb_studio'] = 'ACL_CAT_PHPBB_STUDIO';
|
||||
|
||||
$event['categories'] = $categories;
|
||||
}
|
||||
|
||||
$perms = [
|
||||
'a_aps_logs', 'a_aps_points', 'a_aps_reasons', 'a_aps_display', 'a_aps_settings',
|
||||
'm_aps_adjust_custom', 'm_aps_adjust_reason',
|
||||
'u_aps_view_build', 'u_aps_view_build_other', 'u_aps_view_logs', 'u_aps_view_logs_other', 'u_aps_view_mod',
|
||||
];
|
||||
|
||||
foreach ($perms as $permission)
|
||||
{
|
||||
$permissions[$permission] = ['lang' => 'ACL_' . utf8_strtoupper($permission), 'cat' => 'phpbb_studio'];
|
||||
}
|
||||
|
||||
$event['permissions'] = $permissions;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user