Ajout d'une extension
This commit is contained in:
940
ext/phpbbstudio/aps/controller/acp_controller.php
Normal file
940
ext/phpbbstudio/aps/controller/acp_controller.php
Normal file
@@ -0,0 +1,940 @@
|
||||
<?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\controller;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System ACP controller.
|
||||
*/
|
||||
class acp_controller
|
||||
{
|
||||
/** @var \phpbbstudio\aps\core\acp */
|
||||
protected $acp;
|
||||
|
||||
/** @var \phpbb\auth\auth */
|
||||
protected $auth;
|
||||
|
||||
/** @var \phpbbstudio\aps\points\blockader */
|
||||
protected $blockader;
|
||||
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
|
||||
/** @var array Clone of phpBB config */
|
||||
protected $config_new;
|
||||
|
||||
/** @var \phpbbstudio\aps\controller\main_controller */
|
||||
protected $controller;
|
||||
|
||||
/** @var \phpbb\db\driver\driver_interface */
|
||||
protected $db;
|
||||
|
||||
/** @var \phpbb\event\dispatcher */
|
||||
protected $dispatcher;
|
||||
|
||||
/** @var \phpbbstudio\aps\core\functions */
|
||||
protected $functions;
|
||||
|
||||
/** @var \phpbb\language\language */
|
||||
protected $language;
|
||||
|
||||
/** @var \phpbb\log\log */
|
||||
protected $log_phpbb;
|
||||
|
||||
/** @var \phpbbstudio\aps\core\log */
|
||||
protected $log;
|
||||
|
||||
/** @var \phpbb\pagination */
|
||||
protected $pagination;
|
||||
|
||||
/** @var \phpbbstudio\aps\points\reasoner */
|
||||
protected $reasoner;
|
||||
|
||||
/** @var \phpbb\request\request */
|
||||
protected $request;
|
||||
|
||||
/** @var \phpbb\template\template */
|
||||
protected $template;
|
||||
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/** @var string Custom form action */
|
||||
protected $u_action;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbbstudio\aps\core\acp $acp APS ACP functions
|
||||
* @param \phpbb\auth\auth $auth Authentication object
|
||||
* @param \phpbbstudio\aps\points\blockader $blockader APS Blockader object
|
||||
* @param \phpbb\config\config $config Configuration object
|
||||
* @param \phpbbstudio\aps\controller\main_controller $controller APS Main controller
|
||||
* @param \phpbb\db\driver\driver_interface $db Database object
|
||||
* @param \phpbb\event\dispatcher $dispatcher Event dispatcher
|
||||
* @param \phpbbstudio\aps\core\functions $functions APS Core functions
|
||||
* @param \phpbb\language\language $language phpBB Language object
|
||||
* @param \phpbb\log\log $log_phpbb phpBB Log object
|
||||
* @param \phpbbstudio\aps\core\log $log APS Log object
|
||||
* @param \phpbb\pagination $pagination Pagination object
|
||||
* @param \phpbbstudio\aps\points\reasoner $reasoner APS Reasoner 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,
|
||||
\phpbbstudio\aps\points\blockader $blockader,
|
||||
\phpbb\config\config $config,
|
||||
main_controller $controller,
|
||||
\phpbb\db\driver\driver_interface $db,
|
||||
\phpbb\event\dispatcher $dispatcher,
|
||||
\phpbbstudio\aps\core\functions $functions,
|
||||
\phpbb\language\language $language,
|
||||
\phpbb\log\log $log_phpbb,
|
||||
\phpbbstudio\aps\core\log $log,
|
||||
\phpbb\pagination $pagination,
|
||||
\phpbbstudio\aps\points\reasoner $reasoner,
|
||||
\phpbb\request\request $request,
|
||||
\phpbb\template\template $template,
|
||||
\phpbb\user $user
|
||||
)
|
||||
{
|
||||
$this->acp = $acp;
|
||||
$this->auth = $auth;
|
||||
$this->blockader = $blockader;
|
||||
$this->config = $config;
|
||||
$this->controller = $controller;
|
||||
$this->db = $db;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->functions = $functions;
|
||||
$this->language = $language;
|
||||
$this->log_phpbb = $log_phpbb;
|
||||
$this->log = $log;
|
||||
$this->pagination = $pagination;
|
||||
$this->reasoner = $reasoner;
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ACP settings.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function settings()
|
||||
{
|
||||
$this->log->load_lang();
|
||||
$this->language->add_lang('aps_acp_common', 'phpbbstudio/aps');
|
||||
|
||||
$errors = [];
|
||||
$submit = $this->request->is_set_post('submit');
|
||||
$form_key = 'aps_settings';
|
||||
add_form_key($form_key);
|
||||
|
||||
if ($action = $this->request->variable('action', '', true))
|
||||
{
|
||||
switch ($action)
|
||||
{
|
||||
case 'copy':
|
||||
$errors = $this->copy_points();
|
||||
break;
|
||||
|
||||
case 'clean':
|
||||
$this->clean_points();
|
||||
break;
|
||||
|
||||
case 'locations':
|
||||
$this->link_locations();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$settings = [
|
||||
'legend1' => 'GENERAL_OPTIONS',
|
||||
'aps_points_copy' => ['lang' => 'ACP_APS_POINTS_COPY_TITLE', 'type' => 'custom', 'method' => 'set_action', 'params' => ['copy']],
|
||||
'aps_points_clean' => ['lang' => 'ACP_APS_POINTS_CLEAN', 'type' => 'custom', 'method' => 'set_action', 'params' => ['clean']],
|
||||
'aps_points_safe_mode' => ['lang' => 'ACP_APS_POINTS_SAFE_MODE', 'type' => 'radio:enabled_disabled', 'validate' => 'bool', 'explain' => true],
|
||||
'legend2' => 'ACP_APS_POINTS_NAMES',
|
||||
// Later inserted
|
||||
'legend3' => 'ACP_APS_FORMATTING',
|
||||
'aps_points_icon' => ['lang' => 'ACP_APS_POINTS_ICON', 'type' => 'text:0:100', 'append' => '<i class="icon fa-fw" aria-hidden="true"></i>'],
|
||||
'aps_points_icon_img' => ['lang' => 'ACP_APS_POINTS_ICON_IMG', 'validate' => 'string:0:255', 'type' => 'custom', 'method' => 'build_icon_image_select', 'explain' => true],
|
||||
'aps_points_icon_position' => ['lang' => 'ACP_APS_POINTS_ICON_POSITION', 'validate' => 'bool', 'type' => 'custom', 'method' => 'build_position_radio'],
|
||||
'aps_points_decimals' => ['lang' => 'ACP_APS_POINTS_DECIMALS', 'validate' => 'string', 'type' => 'select', 'method' => 'build_decimal_select'],
|
||||
'aps_points_separator_dec' => ['lang' => 'ACP_APS_SEPARATOR_DEC', 'validate' => 'string', 'type' => 'select', 'method' => 'build_separator_select', 'params' => ['{CONFIG_VALUE}']],
|
||||
'aps_points_separator_thou' => ['lang' => 'ACP_APS_SEPARATOR_THOU', 'validate' => 'string', 'type' => 'select', 'method' => 'build_separator_select'],
|
||||
'legend4' => 'GENERAL_SETTINGS',
|
||||
'aps_link_locations' => ['lang' => 'ACP_APS_LOCATIONS', 'type' => 'custom', 'method' => 'set_action', 'params' => ['locations', false], 'explain' => true],
|
||||
'aps_points_display_profile' => ['lang' => 'ACP_APS_POINTS_DISPLAY_PROFILE', 'type' => 'radio:yes_no', 'validate' => 'bool', 'explain' => true],
|
||||
'aps_points_display_post' => ['lang' => 'ACP_APS_POINTS_DISPLAY_POST', 'type' => 'radio:yes_no', 'validate' => 'bool', 'explain' => true],
|
||||
'aps_points_display_pm' => ['lang' => 'ACP_APS_POINTS_DISPLAY_PM', 'type' => 'radio:yes_no', 'validate' => 'bool', 'explain' => true],
|
||||
'aps_points_min' => ['lang' => 'ACP_APS_POINTS_MIN', 'type' => 'number', 'validate' => 'string', 'explain' => true], // Validate as string to make sure it does not default to 0
|
||||
'aps_points_max' => ['lang' => 'ACP_APS_POINTS_MAX', 'type' => 'number', 'validate' => 'string', 'explain' => true],
|
||||
'aps_actions_per_page' => ['lang' => 'ACP_APS_POINTS_PER_PAGE', 'type' => 'number:10:100', 'validate' => 'number:10:100', 'explain' => true],
|
||||
'aps_points_exclude_words' => ['lang' => 'ACP_APS_POINTS_EXCLUDE_WORDS', 'type' => 'number:0:10', 'validate' => 'number:0:10', 'explain' => true, 'append' => ' ' . $this->language->lang('ACP_APS_CHARACTERS')],
|
||||
'aps_points_exclude_chars' => ['lang' => 'ACP_APS_POINTS_EXCLUDE_CHARS', 'type' => 'radio:yes_no', 'validate' => 'bool', 'explain' => true],
|
||||
'legend5' => 'ACP_APS_IGNORE_SETTINGS',
|
||||
'aps_ignore_criteria' => ['lang' => 'ACP_APS_IGNORE_CRITERIA', 'validate' => 'int:0:4', 'type' => 'custom', 'method' => 'build_ignore_criteria_radio', 'explain' => true],
|
||||
'aps_ignore_min_words' => ['lang' => 'ACP_APS_IGNORE_MIN_WORDS', 'type' => 'number:0:100', 'validate' => 'number:0:100', 'explain' => true],
|
||||
'aps_ignore_min_chars' => ['lang' => 'ACP_APS_IGNORE_MIN_CHARS', 'type' => 'number:0:200', 'validate' => 'number:0:200', 'explain' => true],
|
||||
'aps_ignore_excluded_words' => ['lang' => 'ACP_APS_IGNORE_EXCLUDED_WORDS', 'type' => 'radio:yes_no', 'validate' => 'bool', 'explain' => true],
|
||||
'aps_ignore_excluded_chars' => ['lang' => 'ACP_APS_IGNORE_EXCLUDED_CHARS', 'type' => 'radio:yes_no', 'validate' => 'bool', 'explain' => true],
|
||||
'legend6' => 'ACP_APS_CHAIN_SETTINGS',
|
||||
'aps_chain_merge_delete' => ['lang' => 'ACP_APS_CHAIN_MERGE_DELETE', 'type' => 'radio:enabled_disabled', 'validate' => 'bool', 'explain' => true],
|
||||
'aps_chain_merge_move' => ['lang' => 'ACP_APS_CHAIN_MERGE_MOVE', 'type' => 'radio:enabled_disabled', 'validate' => 'bool', 'explain' => true],
|
||||
'aps_chain_warn_pm' => ['lang' => 'ACP_APS_CHAIN_WARN_PM', 'type' => 'radio:enabled_disabled', 'validate' => 'bool', 'explain' => true],
|
||||
];
|
||||
|
||||
$settings = phpbb_insert_config_array($settings, $this->build_point_names(), ['after' => 'legend2']);
|
||||
|
||||
/**
|
||||
* Event to add additional settings to the APS ACP settings page.
|
||||
*
|
||||
* @event phpbbstudio.aps.acp_settings
|
||||
* @var array settings Available settings
|
||||
* @since 1.0.0
|
||||
*/
|
||||
$vars = ['settings'];
|
||||
extract($this->dispatcher->trigger_event('phpbbstudio.aps.acp_settings', compact($vars)));
|
||||
|
||||
$this->config_new = clone $this->config;
|
||||
$settings_array = $submit ? $this->request->variable('config', ['' => '']) : $this->config_new;
|
||||
|
||||
validate_config_vars($settings, $settings_array, $errors);
|
||||
|
||||
if ($submit && !check_form_key($form_key))
|
||||
{
|
||||
$errors[] = $this->language->lang('FORM_INVALID');
|
||||
}
|
||||
|
||||
if (!empty($errors))
|
||||
{
|
||||
$submit = false;
|
||||
}
|
||||
|
||||
foreach ($settings as $config_name => $data)
|
||||
{
|
||||
if (!isset($settings_array[$config_name]) || strpos($config_name, 'legend') !== false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->config_new[$config_name] = $config_value = $settings_array[$config_name];
|
||||
|
||||
if ($submit)
|
||||
{
|
||||
$this->config->set($config_name, $config_value);
|
||||
}
|
||||
}
|
||||
|
||||
if ($submit)
|
||||
{
|
||||
// Log the action
|
||||
$this->log_phpbb->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_ACP_APS_SETTINGS');
|
||||
|
||||
// Show success message
|
||||
trigger_error($this->language->lang('ACP_APS_SETTINGS_SUCCESS') . adm_back_link($this->u_action));
|
||||
}
|
||||
|
||||
foreach ($settings as $config_key => $setting)
|
||||
{
|
||||
if (!is_array($setting) && strpos($config_key, 'legend') === false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strpos($config_key, 'legend') !== false)
|
||||
{
|
||||
$this->template->assign_block_vars('settings', [
|
||||
'CLASS' => str_replace(['acp_', '_'], ['', '-'], utf8_strtolower($setting)),
|
||||
'LEGEND' => $setting,
|
||||
'S_LEGEND' => true,
|
||||
]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = explode(':', $setting['type']);
|
||||
$content = build_cfg_template($type, $config_key, $this->config_new, $config_key, $setting);
|
||||
|
||||
if (empty($content))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$booleans = ['yes_no', 'no_yes', 'enabled_disabled', 'disabled_enabled'];
|
||||
if ($type[0] === 'radio' && !empty($type[1]) && in_array($type[1], $booleans))
|
||||
{
|
||||
$yes = [$this->language->lang('YES'), $this->language->lang('ENABLED')];
|
||||
$no = [$this->language->lang('NO'), $this->language->lang('DISABLED')];
|
||||
$content = preg_replace(
|
||||
['/(' . implode('|', $yes) . ')/', '/(' . implode('|', $no) . ')/', '/class="radio"/'],
|
||||
['<span class="aps-button-green">$1</span>', '<span class="aps-button-red">$1</span>', 'class="radio aps-bool"'],
|
||||
$content
|
||||
);
|
||||
}
|
||||
|
||||
$this->template->assign_block_vars('settings', [
|
||||
'KEY' => $config_key,
|
||||
'CONTENT' => $content,
|
||||
'TITLE' => $setting['lang'],
|
||||
'S_EXPLAIN' => isset($setting['explain']) ? $setting['explain'] : false,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->template->assign_vars([
|
||||
'S_ERROR' => !empty($errors),
|
||||
'ERROR_MSG' => !empty($errors) ? implode('<br>', $errors) : '',
|
||||
|
||||
'U_ACTION' => $this->u_action,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ACP display.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function display()
|
||||
{
|
||||
$this->log->load_lang();
|
||||
$this->language->add_lang(['aps_acp_common', 'aps_display'], 'phpbbstudio/aps');
|
||||
|
||||
$errors = [];
|
||||
|
||||
add_form_key('aps_display');
|
||||
|
||||
$blocks = $this->controller->get_page_blocks();
|
||||
$admin_blocks = $this->blockader->row($this->blockader->get_admin_id());
|
||||
$insert = empty($admin_blocks);
|
||||
|
||||
if ($insert)
|
||||
{
|
||||
foreach ($blocks as $slug => $data)
|
||||
{
|
||||
$admin_blocks[$slug] = array_keys($data['blocks']);
|
||||
}
|
||||
}
|
||||
|
||||
$admin_pages = array_keys($admin_blocks);
|
||||
|
||||
foreach ($admin_pages as $slug)
|
||||
{
|
||||
if (empty($blocks[$slug]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$data = $blocks[$slug];
|
||||
|
||||
$this->template->assign_block_vars('aps_pages', [
|
||||
'ID' => $slug,
|
||||
'TITLE' => $data['title'],
|
||||
'S_ACTIVE' => in_array($slug, $admin_pages),
|
||||
]);
|
||||
|
||||
foreach ($data['blocks'] as $block_id => $block)
|
||||
{
|
||||
$this->template->assign_block_vars('aps_pages.blocks', [
|
||||
'ID' => $block_id,
|
||||
'TITLE' => $block['title'],
|
||||
'S_ACTIVE' => isset($admin_blocks[$slug]) && in_array($block_id, $admin_blocks[$slug]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$submit = $this->request->is_set_post('submit');
|
||||
|
||||
$settings = [
|
||||
'aps_display_top_change' => $this->request->variable('aps_display_top_change', (int) $this->config['aps_display_top_change']),
|
||||
'aps_display_top_count' => $this->request->variable('aps_display_top_count', (int) $this->config['aps_display_top_count']),
|
||||
'aps_display_adjustments' => $this->request->variable('aps_display_adjustments', (int) $this->config['aps_display_adjustments']),
|
||||
'aps_display_graph_time' => $this->request->variable('aps_display_graph_time', (int) $this->config['aps_display_graph_time']),
|
||||
];
|
||||
|
||||
/**
|
||||
* Event to handle additional settings for the APS ACP display page.
|
||||
*
|
||||
* @event phpbbstudio.aps.acp_display
|
||||
* @var array settings Available settings
|
||||
* @var array errors Any errors that may have occurred
|
||||
* @var bool submit Whether or not the form was submitted
|
||||
* @since 1.0.2
|
||||
*/
|
||||
$vars = ['settings', 'errors', 'submit'];
|
||||
extract($this->dispatcher->trigger_event('phpbbstudio.aps.acp_display', compact($vars)));
|
||||
|
||||
if ($submit)
|
||||
{
|
||||
if (!check_form_key('aps_display'))
|
||||
{
|
||||
$errors[] = $this->language->lang('FORM_INVALID');
|
||||
}
|
||||
|
||||
$display_blocks = $this->request->variable('aps_blocks', ['' => ['']]);
|
||||
|
||||
if (empty($errors))
|
||||
{
|
||||
// Set the settings
|
||||
foreach ($settings as $name => $value)
|
||||
{
|
||||
if ($this->config[$name] != $value)
|
||||
{
|
||||
$this->config->set($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($display_blocks as $key => $array)
|
||||
{
|
||||
$display_blocks[$key] = array_filter($array);
|
||||
}
|
||||
|
||||
// Set the blocks
|
||||
$this->blockader->set_blocks($this->blockader->get_admin_id(), $display_blocks, $insert);
|
||||
|
||||
// Log the action
|
||||
$this->log_phpbb->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_ACP_APS_DISPLAY');
|
||||
|
||||
// Show success message
|
||||
trigger_error($this->language->lang('ACP_APS_DISPLAY_SUCCESS') . adm_back_link($this->u_action));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($settings as $name => $value)
|
||||
{
|
||||
$this->template->assign_var(utf8_strtoupper($name), $value);
|
||||
}
|
||||
|
||||
$this->template->assign_vars([
|
||||
'S_ERROR' => !empty($errors),
|
||||
'ERROR_MSG' => !empty($errors) ? implode('<br>', $errors) : '',
|
||||
|
||||
'U_ACTION' => $this->u_action,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ACP points and reasons.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function points()
|
||||
{
|
||||
$this->log->load_lang();
|
||||
$this->language->add_lang('aps_acp_common', 'phpbbstudio/aps');
|
||||
|
||||
$errors = [];
|
||||
$action = $this->request->variable('action', '');
|
||||
$submit = $this->request->is_set_post('submit');
|
||||
|
||||
$form_name = 'acp_aps_points';
|
||||
add_form_key($form_name);
|
||||
|
||||
if (
|
||||
(!$this->auth->acl_get('a_aps_points') && !$this->auth->acl_get('a_aps_reasons'))
|
||||
|| (!empty($action) && !$this->auth->acl_get('a_aps_reasons'))
|
||||
)
|
||||
{
|
||||
trigger_error('NOT_AUTHORISED', E_USER_WARNING);
|
||||
}
|
||||
|
||||
switch ($action)
|
||||
{
|
||||
case 'add':
|
||||
case 'edit':
|
||||
$reason_id = (int) $this->request->variable('r', 0);
|
||||
|
||||
$reason = $this->reasoner->row($reason_id);
|
||||
$reason = $this->reasoner->fill($reason);
|
||||
|
||||
$reason['reason_title'] = $this->request->variable('title', (string) $reason['reason_title'] , true);
|
||||
$reason['reason_desc'] = $this->request->variable('description', (string) $reason['reason_desc'], true);
|
||||
$reason['reason_points'] = $this->request->variable('points', (double) $reason['reason_points']);
|
||||
|
||||
if ($submit)
|
||||
{
|
||||
if (!check_form_key($form_name))
|
||||
{
|
||||
$errors[] = $this->language->lang('FORM_INVALID');
|
||||
}
|
||||
|
||||
if (empty($reason['reason_title']) || strlen($reason['reason_title']) > 255)
|
||||
{
|
||||
$errors[] = $this->language->lang('ACP_APS_REASON_EMPTY_SUBJECT');
|
||||
}
|
||||
|
||||
$reason_points_to_check = round($reason['reason_points'], 2);
|
||||
|
||||
if (empty($reason_points_to_check))
|
||||
{
|
||||
$errors[] = $this->language->lang('ACP_APS_REASON_EMPTY_POINTS', $this->functions->get_name());
|
||||
}
|
||||
|
||||
if (empty($errors))
|
||||
{
|
||||
if ($action === 'add')
|
||||
{
|
||||
$this->reasoner->insert($reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->reasoner->update($reason, $reason_id);
|
||||
}
|
||||
|
||||
$this->log_phpbb->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_ACP_APS_REASON_' . utf8_strtoupper($action));
|
||||
|
||||
trigger_error($this->language->lang('ACP_APS_REASON_SAVED') . adm_back_link($this->u_action));
|
||||
}
|
||||
}
|
||||
|
||||
$this->template->assign_vars([
|
||||
'REASON_TITLE' => $reason['reason_title'],
|
||||
'REASON_DESC' => $reason['reason_desc'],
|
||||
'REASON_POINTS' => $reason['reason_points'],
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$reason_id = (int) $this->request->variable('r', 0);
|
||||
|
||||
if (confirm_box(true))
|
||||
{
|
||||
$this->reasoner->delete($reason_id);
|
||||
|
||||
$json_response = new \phpbb\json_response;
|
||||
$json_response->send([
|
||||
'SUCCESS' => true,
|
||||
'MESSAGE_TITLE' => $this->language->lang('INFORMATION'),
|
||||
'MESSAGE_TEXT' => $this->language->lang('ACP_APS_REASON_DELETE_SUCCESS'),
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
confirm_box(false, 'ACP_APS_REASON_DELETE', build_hidden_fields([
|
||||
'submit' => $submit,
|
||||
'action' => $action,
|
||||
]));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'move':
|
||||
$reason_id = $this->request->variable('r', 0);
|
||||
$dir = $this->request->variable('dir', '');
|
||||
|
||||
$this->reasoner->order($reason_id, $dir);
|
||||
|
||||
$json_response = new \phpbb\json_response;
|
||||
$json_response->send([
|
||||
'success' => true,
|
||||
]);
|
||||
break;
|
||||
|
||||
default:
|
||||
if ($this->auth->acl_get('a_aps_points'))
|
||||
{
|
||||
$this->acp->build();
|
||||
|
||||
if ($submit)
|
||||
{
|
||||
if (!check_form_key($form_name))
|
||||
{
|
||||
$errors[] = $this->language->lang('FORM_INVALID');
|
||||
}
|
||||
|
||||
if (empty($errors))
|
||||
{
|
||||
$values = $this->request->variable('aps_values', ['' => 0.00]);
|
||||
|
||||
$this->acp->set_points($values);
|
||||
|
||||
$this->log_phpbb->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_ACP_APS_POINTS', time(), [$this->functions->get_name()]);
|
||||
|
||||
trigger_error($this->language->lang('ACP_APS_POINTS_SUCCESS', $this->functions->get_name()) . adm_back_link($this->u_action));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->auth->acl_get('a_aps_points'))
|
||||
{
|
||||
$rowset = $this->reasoner->rowset();
|
||||
|
||||
foreach ($rowset as $row)
|
||||
{
|
||||
$this->template->assign_block_vars('aps_reasons', [
|
||||
'ID' => (int) $row['reason_id'],
|
||||
'TITLE' => (string) $row['reason_title'],
|
||||
'DESC' => (string) $row['reason_desc'],
|
||||
'POINTS' => (double) $row['reason_points'],
|
||||
|
||||
'U_DELETE' => $this->u_action . '&action=delete&r=' . (int) $row['reason_id'],
|
||||
'U_EDIT' => $this->u_action . '&action=edit&r=' . (int) $row['reason_id'],
|
||||
'U_MOVE_UP' => $this->u_action . '&action=move&dir=up&r=' . (int) $row['reason_id'],
|
||||
'U_MOVE_DOWN' => $this->u_action . '&action=move&dir=down&r=' . (int) $row['reason_id'],
|
||||
]);
|
||||
}
|
||||
|
||||
$this->template->assign_vars([
|
||||
'U_APS_REASON_ADD' => $this->u_action . '&action=add',
|
||||
]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$s_errors = (bool) count($errors);
|
||||
|
||||
$this->template->assign_vars([
|
||||
'S_ERRORS' => $s_errors,
|
||||
'ERROR_MSG' => $s_errors ? implode('<br />', $errors) : '',
|
||||
|
||||
'APS_TITLE' => $action ? $this->language->lang('ACP_APS_REASON_' . utf8_strtoupper($action)) : $this->functions->get_name(),
|
||||
|
||||
'S_APS_ACTION' => $action,
|
||||
'S_APS_POINTS' => $this->auth->acl_get('a_aps_points'),
|
||||
'S_APS_REASONS' => $this->auth->acl_get('a_aps_reasons'),
|
||||
|
||||
'U_APS_ACTION' => $this->u_action . ($action ? "&action={$action}" : '') . (!empty($reason_id) ? "&r={$reason_id}" : ''),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ACP logs.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function logs()
|
||||
{
|
||||
$this->log->load_lang();
|
||||
$this->language->add_lang('aps_acp_common', 'phpbbstudio/aps');
|
||||
|
||||
// Set up general vars
|
||||
$start = $this->request->variable('start', 0);
|
||||
$forum_id = $this->request->variable('f', '');
|
||||
$topic_id = $this->request->variable('t', 0);
|
||||
$post_id = $this->request->variable('p', 0);
|
||||
$user_id = $this->request->variable('u', 0);
|
||||
$reportee_id = $this->request->variable('r', 0);
|
||||
|
||||
$delete_mark = $this->request->variable('del_marked', false, false, \phpbb\request\request_interface::POST);
|
||||
$delete_all = $this->request->variable('del_all', false, false, \phpbb\request\request_interface::POST);
|
||||
$marked = $this->request->variable('mark', [0]);
|
||||
|
||||
// Sort keys
|
||||
$sort_days = $this->request->variable('st', 0);
|
||||
$sort_key = $this->request->variable('sk', 't');
|
||||
$sort_dir = $this->request->variable('sd', 'd');
|
||||
|
||||
// Keywords
|
||||
$keywords = $this->request->variable('keywords', '', true);
|
||||
$keywords_param = !empty($keywords) ? '&keywords=' . urlencode(htmlspecialchars_decode($keywords)) : '';
|
||||
|
||||
if (($delete_mark || $delete_all))
|
||||
{
|
||||
if (confirm_box(true))
|
||||
{
|
||||
$conditions = [];
|
||||
|
||||
if ($delete_mark && count($marked))
|
||||
{
|
||||
$conditions['log_id'] = ['IN' => $marked];
|
||||
}
|
||||
|
||||
if ($delete_all)
|
||||
{
|
||||
if ($sort_days)
|
||||
{
|
||||
$conditions['log_time'] = ['>=', time() - ($sort_days * 86400)];
|
||||
}
|
||||
|
||||
$conditions['keywords'] = $keywords;
|
||||
}
|
||||
|
||||
$this->log->delete($conditions);
|
||||
|
||||
$plural = $delete_all ? 2 : count($marked);
|
||||
$log_action = 'LOG_ACP_APS_LOGS_' . $delete_all ? 'CLEARED' : 'DELETED';
|
||||
$this->log_phpbb->add('admin', $this->user->data['user_id'], $this->user->ip, $log_action, time(), [$this->functions->get_name()]);
|
||||
|
||||
trigger_error($this->language->lang('ACP_APS_LOGS_DELETED', $plural) . adm_back_link($this->u_action));
|
||||
}
|
||||
else
|
||||
{
|
||||
confirm_box(false, $this->language->lang('CONFIRM_OPERATION'), build_hidden_fields([
|
||||
'f' => $forum_id,
|
||||
'start' => $start,
|
||||
'del_marked' => $delete_mark,
|
||||
'del_all' => $delete_all,
|
||||
'mark' => $marked,
|
||||
'st' => $sort_days,
|
||||
'sk' => $sort_key,
|
||||
'sd' => $sort_dir,
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
$name = $this->functions->get_name();
|
||||
$limit = $this->config['aps_actions_per_page'];
|
||||
|
||||
// Sorting
|
||||
$limit_days = [
|
||||
0 => $this->language->lang('ALL_ENTRIES'),
|
||||
1 => $this->language->lang('1_DAY'),
|
||||
7 => $this->language->lang('7_DAYS'),
|
||||
14 => $this->language->lang('2_WEEKS'),
|
||||
30 => $this->language->lang('1_MONTH'),
|
||||
90 => $this->language->lang('3_MONTHS'),
|
||||
180 => $this->language->lang('6_MONTHS'),
|
||||
365 => $this->language->lang('1_YEAR'),
|
||||
];
|
||||
$sort_by_text = [
|
||||
'a' => $this->language->lang('SORT_ACTION'),
|
||||
'ps' => $name,
|
||||
'pn' => $this->language->lang('APS_POINTS_NEW', $name),
|
||||
'po' => $this->language->lang('APS_POINTS_OLD', $name),
|
||||
'uu' => $this->language->lang('SORT_USERNAME'),
|
||||
'ru' => ucfirst($this->language->lang('FROM')),
|
||||
't' => $this->language->lang('SORT_DATE'),
|
||||
];
|
||||
$sort_by_sql = [
|
||||
'a' => 'l.log_action',
|
||||
'ps' => 'l.points_sum',
|
||||
'pn' => 'l.points_new',
|
||||
'po' => 'l.points_old',
|
||||
'uu' => 'u.username',
|
||||
'ru' => 'r.username',
|
||||
't' => 'l.log_time',
|
||||
];
|
||||
|
||||
$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
|
||||
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
|
||||
|
||||
// Define where and sort sql for use in displaying logs
|
||||
$sql_time = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
|
||||
$sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
|
||||
|
||||
$rowset = $this->log->get(true, $limit, $start, $forum_id, $topic_id, $post_id, $user_id, $reportee_id, $sql_time, $sql_sort, $keywords);
|
||||
$start = $this->log->get_valid_offset();
|
||||
$total = $this->log->get_log_count();
|
||||
|
||||
$base_url = $this->u_action . "&$u_sort_param$keywords_param";
|
||||
$this->pagination->generate_template_pagination($base_url, 'pagination', 'start', $total, $limit, $start);
|
||||
|
||||
foreach ($rowset as $row)
|
||||
{
|
||||
$this->template->assign_block_vars('logs', array_change_key_case($row, CASE_UPPER));
|
||||
}
|
||||
|
||||
$this->template->assign_vars([
|
||||
'U_ACTION' => $this->u_action . "&$u_sort_param$keywords_param&start=$start",
|
||||
|
||||
'S_LIMIT_DAYS' => $s_limit_days,
|
||||
'S_SORT_KEY' => $s_sort_key,
|
||||
'S_SORT_DIR' => $s_sort_dir,
|
||||
'S_KEYWORDS' => $keywords,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set custom form action.
|
||||
*
|
||||
* @param string $u_action Custom form action
|
||||
* @return acp_controller $this This controller for chaining calls
|
||||
* @access public
|
||||
*/
|
||||
public function set_page_url($u_action)
|
||||
{
|
||||
$this->u_action = $u_action;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a settings array for point names for all installed languages.
|
||||
*
|
||||
* @return array $names Array of localised point name settings
|
||||
* @access protected
|
||||
*/
|
||||
protected function build_point_names()
|
||||
{
|
||||
$names = [];
|
||||
|
||||
$sql = 'SELECT * FROM ' . LANG_TABLE . ' ORDER BY lang_english_name';
|
||||
$result = $this->db->sql_query($sql);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$name['aps_points_name_' . $row['lang_iso']] = ['lang' =>$row['lang_english_name'], 'validate' => 'string:0:100', 'type' => 'text:0:100'];
|
||||
|
||||
$names = $row['lang_iso'] === $this->config['default_lang'] ? $name + $names : array_merge($names, $name);
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
// Only add the 'expand view' if there are multiple language installed
|
||||
if (count($names) > 1)
|
||||
{
|
||||
// Get the first array key
|
||||
$key = array_keys($names)[0];
|
||||
|
||||
// The 'expand view' HTML string
|
||||
$expand = '<a class="aps-names-toggle" data-text="' . $this->language->lang('COLLAPSE_VIEW') . '">' . $this->language->lang('EXPAND_VIEW') . '</a>';
|
||||
|
||||
$names[$key]['append'] = $expand;
|
||||
}
|
||||
|
||||
return $names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the copy action from the settings page.
|
||||
*
|
||||
* @return array Array filled with errors
|
||||
* @access protected
|
||||
*/
|
||||
protected function copy_points()
|
||||
{
|
||||
$json_response = new \phpbb\json_response;
|
||||
|
||||
add_form_key('aps_points_copy');
|
||||
|
||||
if ($this->request->is_set_post('submit_copy'))
|
||||
{
|
||||
$errors = [];
|
||||
|
||||
$from = $this->request->variable('aps_forums_from', 0);
|
||||
$to = $this->request->variable('aps_forums_to', [0]);
|
||||
|
||||
if (empty($from) || empty($to))
|
||||
{
|
||||
$errors[] = $this->language->lang('ACP_APS_POINTS_COPY_EMPTY');
|
||||
}
|
||||
|
||||
if (!check_form_key('aps_points_copy'))
|
||||
{
|
||||
$errors[] = $this->language->lang('FORM_INVALID');
|
||||
}
|
||||
|
||||
if ($errors)
|
||||
{
|
||||
if ($this->request->is_ajax())
|
||||
{
|
||||
$json_response->send([
|
||||
'MESSAGE_TITLE' => $this->language->lang('ERROR'),
|
||||
'MESSAGE_TEXT' => implode('<br />', $errors),
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->acp->copy_multiple($from, $to);
|
||||
|
||||
$this->log_phpbb->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_ACP_APS_COPIED', time(), [$this->functions->get_name()]);
|
||||
|
||||
$json_response->send([
|
||||
'MESSAGE_TITLE' => $this->language->lang('INFORMATION'),
|
||||
'MESSAGE_TEXT' => $this->language->lang('ACP_APS_POINTS_COPY_SUCCESS', $this->functions->get_name()),
|
||||
]);
|
||||
|
||||
trigger_error($this->language->lang('ACP_APS_POINTS_COPY_SUCCESS', $this->functions->get_name()) . adm_back_link($this->u_action));
|
||||
}
|
||||
}
|
||||
|
||||
$this->template->set_filenames(['copy' => '@phpbbstudio_aps/aps_points_copy.html']);
|
||||
|
||||
$this->template->assign_vars([
|
||||
'S_APS_COPY' => true,
|
||||
'S_APS_FORUMS' => make_forum_select(),
|
||||
'U_APS_ACTION_COPY' => $this->u_action . '&action=copy',
|
||||
]);
|
||||
|
||||
if ($this->request->is_ajax())
|
||||
{
|
||||
$json_response->send([
|
||||
'MESSAGE_TITLE' => $this->language->lang('ACP_APS_POINTS_COPY_TITLE', $this->functions->get_name()),
|
||||
'MESSAGE_TEXT' => $this->template->assign_display('copy'),
|
||||
]);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the clean action from the settings page.
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function clean_points()
|
||||
{
|
||||
if (confirm_box(true))
|
||||
{
|
||||
$this->acp->clean_points();
|
||||
|
||||
$this->log_phpbb->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_ACP_APS_CLEANED', time(), [$this->functions->get_name()]);
|
||||
|
||||
$json_response = new \phpbb\json_response;
|
||||
$json_response->send([
|
||||
'MESSAGE_TITLE' => $this->language->lang('INFORMATION'),
|
||||
'MESSAGE_TEXT' => $this->language->lang('ACP_APS_POINTS_CLEAN_SUCCESS', $this->functions->get_name()),
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
confirm_box(false, $this->language->lang('ACP_APS_POINTS_CLEAN_CONFIRM', $this->functions->get_name()), build_hidden_fields([
|
||||
'action' => 'clean',
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the link locations from the settings page.
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function link_locations()
|
||||
{
|
||||
$locations = $this->functions->get_link_locations();
|
||||
$variables = ['S_APS_LOCATIONS' => true];
|
||||
|
||||
foreach ($locations as $location => $status)
|
||||
{
|
||||
$variables[$location] = (bool) $status;
|
||||
}
|
||||
|
||||
$this->template->assign_vars($variables);
|
||||
|
||||
if ($this->request->is_set_post('submit_locations'))
|
||||
{
|
||||
$links = [];
|
||||
|
||||
foreach (array_keys($locations) as $location)
|
||||
{
|
||||
$links[$location] = $this->request->variable((string) $location, false);
|
||||
}
|
||||
|
||||
$this->functions->set_link_locations($links);
|
||||
|
||||
$this->log_phpbb->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_ACP_APS_LOCATIONS');
|
||||
|
||||
trigger_error($this->language->lang('ACP_APS_LOCATIONS_SUCCESS') . adm_back_link($this->u_action));
|
||||
}
|
||||
}
|
||||
}
|
||||
578
ext/phpbbstudio/aps/controller/main_controller.php
Normal file
578
ext/phpbbstudio/aps/controller/main_controller.php
Normal file
@@ -0,0 +1,578 @@
|
||||
<?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\controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System main controller.
|
||||
*/
|
||||
class main_controller
|
||||
{
|
||||
/** @var \phpbb\auth\auth */
|
||||
protected $auth;
|
||||
|
||||
/** @var \phpbbstudio\aps\points\blockader */
|
||||
protected $blockader;
|
||||
|
||||
/** @var \phpbbstudio\aps\core\blocks */
|
||||
protected $blocks;
|
||||
|
||||
/** @var \phpbb\event\dispatcher */
|
||||
protected $dispatcher;
|
||||
|
||||
/** @var \phpbbstudio\aps\core\functions */
|
||||
protected $functions;
|
||||
|
||||
/** @var \phpbb\controller\helper */
|
||||
protected $helper;
|
||||
|
||||
/** @var \phpbb\language\language */
|
||||
protected $language;
|
||||
|
||||
/** @var \phpbb\request\request */
|
||||
protected $request;
|
||||
|
||||
/** @var \phpbb\template\template */
|
||||
protected $template;
|
||||
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/** @var string phpBB root path */
|
||||
protected $root_path;
|
||||
|
||||
/** @var string php File extension */
|
||||
protected $php_ext;
|
||||
|
||||
/** @var string APS Points name */
|
||||
protected $name;
|
||||
|
||||
/** @var string Current page */
|
||||
protected $page;
|
||||
|
||||
/** @var array Available page blocks */
|
||||
protected $page_blocks;
|
||||
|
||||
/** @var array User desired page blocks */
|
||||
protected $user_blocks;
|
||||
|
||||
/** @var array Admin desired page blocks */
|
||||
protected $admin_blocks;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\auth\auth $auth Authentication object
|
||||
* @param \phpbbstudio\aps\points\blockader $blockader APS Blockader
|
||||
* @param \phpbbstudio\aps\core\blocks $blocks APS Blocks functions
|
||||
* @param \phpbb\event\dispatcher $dispatcher Event dispatcher
|
||||
* @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\request\request $request Request object
|
||||
* @param \phpbb\template\template $template Template 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,
|
||||
\phpbbstudio\aps\points\blockader $blockader,
|
||||
\phpbbstudio\aps\core\blocks $blocks,
|
||||
\phpbb\event\dispatcher $dispatcher,
|
||||
\phpbbstudio\aps\core\functions $functions,
|
||||
\phpbb\controller\helper $helper,
|
||||
\phpbb\language\language $language,
|
||||
\phpbb\request\request $request,
|
||||
\phpbb\template\template $template,
|
||||
\phpbb\user $user,
|
||||
$root_path,
|
||||
$php_ext
|
||||
)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->blockader = $blockader;
|
||||
$this->blocks = $blocks;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->functions = $functions;
|
||||
$this->helper = $helper;
|
||||
$this->language = $language;
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
$this->root_path = $root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
|
||||
$this->name = $functions->get_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the points page.
|
||||
*
|
||||
* @param string $page The page slug
|
||||
* @param int $pagination The page number for pagination
|
||||
* @return Response
|
||||
* @access public
|
||||
*/
|
||||
public function display($page, $pagination)
|
||||
{
|
||||
$this->language->add_lang('aps_display', 'phpbbstudio/aps');
|
||||
|
||||
$this->page = $page;
|
||||
|
||||
// Load page blocks
|
||||
$this->get_page_blocks($pagination);
|
||||
|
||||
// Load admin and user blocks
|
||||
$this->get_admin_user_blocks();
|
||||
|
||||
// Check existance
|
||||
if ($msg = $this->check_existance())
|
||||
{
|
||||
return $msg;
|
||||
}
|
||||
|
||||
// Check authorisation
|
||||
if ($msg = $this->check_auth())
|
||||
{
|
||||
return $msg;
|
||||
}
|
||||
|
||||
// Handle any action
|
||||
$this->handle_action();
|
||||
|
||||
foreach ($this->admin_blocks as $slug => $admin_blocks)
|
||||
{
|
||||
if (empty($admin_blocks))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$data = $this->page_blocks[$slug];
|
||||
|
||||
// Only list pages that the user is authorised to see
|
||||
if (!isset($data['auth']) || $data['auth'])
|
||||
{
|
||||
$this->template->assign_block_vars('aps_navbar', [
|
||||
'TITLE' => $data['title'],
|
||||
'S_ACTIVE' => $this->page === $slug,
|
||||
'U_VIEW' => $this->helper->route('phpbbstudio_aps_display', ['page' => $slug]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$called_functions = [];
|
||||
|
||||
$blocks = array_keys($this->page_blocks[$this->page]['blocks']);
|
||||
$blocks = empty($this->user_blocks[$this->page]) ? $blocks : array_unique(array_merge($this->user_blocks[$this->page], $blocks));
|
||||
|
||||
foreach ($blocks as $block_id)
|
||||
{
|
||||
// If the block is no longer available, remove it from the user blocks
|
||||
if (empty($this->page_blocks[$this->page]['blocks'][$block_id]))
|
||||
{
|
||||
$this->delete_block($block_id);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// If it's disabled by the admin, do not display it
|
||||
if (!in_array($block_id, $this->admin_blocks[$this->page]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$block = $this->page_blocks[$this->page]['blocks'][$block_id];
|
||||
|
||||
// Only show blocks that the user is authorised to see
|
||||
if (!isset($block['auth']) || $block['auth'])
|
||||
{
|
||||
if (empty($this->user_blocks[$this->page]) || in_array($block_id, $this->user_blocks[$this->page]))
|
||||
{
|
||||
if (!empty($block['function']) && !in_array($block['function'], $called_functions))
|
||||
{
|
||||
$called_functions[] = $this->call_function($block_id, $block);
|
||||
}
|
||||
|
||||
$this->template->assign_block_vars('aps_blocks', $this->build_display($block_id, $block));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->template->assign_block_vars('aps_blocks_add', ['item' => $this->build_list($block_id, $block)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Purge temporary variable
|
||||
unset($called_functions);
|
||||
|
||||
// Output template variables for display
|
||||
$this->template->assign_vars([
|
||||
'S_APS_DAE_ENABLED' => $this->functions->is_dae_enabled(),
|
||||
'S_APS_OVERVIEW' => true,
|
||||
'U_APS_ACTION_SORT' => $this->helper->route('phpbbstudio_aps_display', ['page' => $page, 'aps_action' => 'move']),
|
||||
'U_MCP' => ($this->auth->acl_get('m_') || $this->auth->acl_getf_global('m_')) ? append_sid("{$this->root_path}mcp.{$this->php_ext}", 'i=-phpbbstudio-aps-mcp-main_module&mode=front', true, $this->user->session_id) : '',
|
||||
]);
|
||||
|
||||
// Breadcrumbs
|
||||
$this->template->assign_block_vars_array('navlinks', [
|
||||
[
|
||||
'FORUM_NAME' => $this->name,
|
||||
'U_VIEW_FORUM' => $this->helper->route('phpbbstudio_aps_display'),
|
||||
],
|
||||
[
|
||||
'FORUM_NAME' => $this->language->lang('APS_OVERVIEW'),
|
||||
'U_VIEW_FORUM' => $this->helper->route('phpbbstudio_aps_display'),
|
||||
],
|
||||
]);
|
||||
|
||||
// Output the page!
|
||||
return $this->helper->render('@phpbbstudio_aps/aps_display.html', $this->page_blocks[$this->page]['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build template variables array for a given block.
|
||||
*
|
||||
* @param string $block_id The block identifier
|
||||
* @param array $block The block data
|
||||
* @return array The block template variables
|
||||
* @access protected
|
||||
*/
|
||||
protected function build_display($block_id, array $block)
|
||||
{
|
||||
return [
|
||||
'ID' => $block_id,
|
||||
'TITLE' => $block['title'],
|
||||
'TEMPLATE' => $block['template'],
|
||||
'S_REQUIRED' => !empty($block['required']),
|
||||
'U_DELETE' => $this->helper->route('phpbbstudio_aps_display', ['page' => $this->page, 'aps_action' => 'delete', 'id' => $block_id]),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Build template list item for a given block.
|
||||
*
|
||||
* @param string $block_id The block identifier
|
||||
* @param array $block The block data
|
||||
* @return string The block template list item
|
||||
* @access protected
|
||||
*/
|
||||
protected function build_list($block_id, array $block)
|
||||
{
|
||||
$u_add = $this->helper->route('phpbbstudio_aps_display', ['page' => $this->page, 'aps_action' => 'add', 'id' => $block_id]);
|
||||
|
||||
return '<li><a class="aps-button-green" href="' . $u_add . '" data-ajax="aps_add">' . $block['title'] . '</a></li>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a function defined in the block data.
|
||||
*
|
||||
* @param string $block_id The block identifier
|
||||
* @param array $block The block data
|
||||
* @return mixed The block function declaration
|
||||
* @access protected
|
||||
*/
|
||||
protected function call_function($block_id, array $block)
|
||||
{
|
||||
// Set up function parameters and append the block id
|
||||
$params = !empty($block['params']) ? $block['params'] : [];
|
||||
$params = array_merge($params, [
|
||||
'block_id' => $block_id
|
||||
]);
|
||||
|
||||
// Call the function
|
||||
call_user_func_array($block['function'], $params);
|
||||
|
||||
return $block['function'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current user is authorised to see this display page.
|
||||
*
|
||||
* @return string|Response
|
||||
* @access protected
|
||||
*/
|
||||
protected function check_auth()
|
||||
{
|
||||
if (isset($this->page_blocks[$this->page]['auth']) && !$this->page_blocks[$this->page]['auth'])
|
||||
{
|
||||
$message = $this->language->lang('NOT_AUTHORISED');
|
||||
$back_link = '<a href="' . $this->helper->route('phpbbstudio_aps_display', ['page' => 'overview']) . '">' . $this->language->lang('APS_OVERVIEW') . '</a>';
|
||||
$back_msg = $this->language->lang('RETURN_TO', $back_link);
|
||||
|
||||
return $this->helper->message($message . '<br /><br />' . $back_msg, [], 'INFORMATION', 401);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current page is available.
|
||||
*
|
||||
* @return string|Response
|
||||
* @access protected
|
||||
*/
|
||||
protected function check_existance()
|
||||
{
|
||||
if (empty($this->page_blocks[$this->page]))
|
||||
{
|
||||
$message = $this->language->lang('PAGE_NOT_FOUND');
|
||||
$back_link = '<a href="' . $this->helper->route('phpbbstudio_aps_display', ['page' => 'overview']) . '">' . $this->language->lang('APS_OVERVIEW') . '</a>';
|
||||
$back_msg = $this->language->lang('RETURN_TO', $back_link);;
|
||||
|
||||
return $this->helper->message($message . '<br /><br />' . $back_msg, [], 'INFORMATION', 404);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle actions for the display blocks.
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function handle_action()
|
||||
{
|
||||
// Request the action
|
||||
$action = $this->request->variable('aps_action', '', true);
|
||||
|
||||
// Only these actions are available
|
||||
if (!in_array($action, ['add', 'delete', 'move']))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Request the block identifier
|
||||
$block_id = $this->request->variable('id', '', true);
|
||||
|
||||
// Call the action's function
|
||||
$response = $this->{$action . '_block'}($block_id);
|
||||
|
||||
// If the request is AJAX, send a response
|
||||
if ($this->request->is_ajax())
|
||||
{
|
||||
$json_response = new \phpbb\json_response;
|
||||
$json_response->send([
|
||||
'success' => $response,
|
||||
'APS_TITLE' => $this->language->lang('APS_SUCCESS'),
|
||||
'APS_TEXT' => $this->language->lang('APS_POINTS_BLOCK_' . utf8_strtoupper($action), $this->name),
|
||||
]);
|
||||
}
|
||||
|
||||
// Otherwise assign a meta refresh
|
||||
$this->helper->assign_meta_refresh_var(0, $this->helper->route('phpbbstudio_aps_display', ['page' => $this->page]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the admin and user desired page blocks.
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function get_admin_user_blocks()
|
||||
{
|
||||
$rowset = $this->blockader->rowset($this->user->data['user_id']);
|
||||
|
||||
foreach ($rowset as $user_id => $blocks)
|
||||
{
|
||||
if ($user_id == $this->blockader->get_admin_id())
|
||||
{
|
||||
$this->admin_blocks = $blocks;
|
||||
}
|
||||
|
||||
if ($user_id == $this->user->data['user_id'])
|
||||
{
|
||||
$this->user_blocks = $blocks;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($this->admin_blocks))
|
||||
{
|
||||
foreach ($this->page_blocks as $page => $data)
|
||||
{
|
||||
$this->admin_blocks[$page] = array_keys($data['blocks']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available display blocks.
|
||||
*
|
||||
* @param int $pagination Pagination page number
|
||||
* @return array The display blocks
|
||||
* @access public
|
||||
*/
|
||||
public function get_page_blocks($pagination = 1)
|
||||
{
|
||||
$page_blocks = [
|
||||
'overview' => [
|
||||
'title' => $this->language->lang('APS_OVERVIEW'),
|
||||
'blocks' => [
|
||||
'points_top' => [
|
||||
'title' => $this->language->lang('APS_TOP_USERS'),
|
||||
'function' => [$this->blocks, 'user_top_search'],
|
||||
'template' => '@phpbbstudio_aps/blocks/points_top.html',
|
||||
],
|
||||
'points_search' => [
|
||||
'title' => $this->language->lang('FIND_USERNAME'),
|
||||
'function' => [$this->blocks, 'user_top_search'],
|
||||
'template' => '@phpbbstudio_aps/blocks/points_search.html',
|
||||
],
|
||||
'points_settings' => [
|
||||
'title' => $this->language->lang('SETTINGS'),
|
||||
'template' => '@phpbbstudio_aps/blocks/points_settings.html',
|
||||
],
|
||||
'points_random' => [
|
||||
'title' => $this->language->lang('APS_RANDOM_USER'),
|
||||
'function' => [$this->blocks, 'user_random'],
|
||||
'template' => '@phpbbstudio_aps/blocks/points_random.html',
|
||||
],
|
||||
'points_forums' => [
|
||||
'title' => $this->language->lang('APS_POINTS_PER_FORUM', $this->name),
|
||||
'function' => [$this->blocks, 'charts_forum'],
|
||||
'template' => '@phpbbstudio_aps/blocks/points_forums.html',
|
||||
],
|
||||
'points_groups' => [
|
||||
'title' => $this->language->lang('APS_POINTS_PER_GROUP', $this->name),
|
||||
'function' => [$this->blocks, 'charts_group'],
|
||||
'template' => '@phpbbstudio_aps/blocks/points_groups.html',
|
||||
],
|
||||
'points_growth' => [
|
||||
'title' => $this->language->lang('APS_POINTS_GROWTH', $this->name),
|
||||
'function' => [$this->blocks, 'charts_period'],
|
||||
'template' => '@phpbbstudio_aps/blocks/points_growth.html',
|
||||
],
|
||||
'points_trade_off' => [
|
||||
'title' => $this->language->lang('APS_POINTS_TRADE_OFF', $this->name),
|
||||
'function' => [$this->blocks, 'charts_period'],
|
||||
'template' => '@phpbbstudio_aps/blocks/points_trade_off.html',
|
||||
],
|
||||
],
|
||||
],
|
||||
'actions' => [
|
||||
'title' => $this->language->lang('APS_POINTS_ACTIONS', $this->name),
|
||||
'auth' => $this->auth->acl_get('u_aps_view_logs'),
|
||||
'blocks' => [
|
||||
'points_actions' => [
|
||||
'auth' => $this->auth->acl_get('u_aps_view_logs'),
|
||||
'title' => $this->language->lang('APS_POINTS_ACTIONS', $this->name),
|
||||
'required' => true,
|
||||
'function' => [$this->blocks, 'display_actions'],
|
||||
'params' => ['pagination' => $pagination],
|
||||
'template' => '@phpbbstudio_aps/blocks/points_actions.html',
|
||||
],
|
||||
'points_registration' => [
|
||||
'auth' => $this->auth->acl_get('u_aps_view_logs'),
|
||||
'title' => $this->language->lang('APS_RECENT_ADJUSTMENTS'),
|
||||
'function' => [$this->blocks, 'recent_adjustments'],
|
||||
'template' => '@phpbbstudio_aps/blocks/points_adjustments.html',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Event to add additional page blocks to the APS display page.
|
||||
*
|
||||
* @event phpbbstudio.aps.display_blocks
|
||||
* @var array page_blocks Available page blocks
|
||||
* @var int pagination Pagination's page number
|
||||
* @since 1.0.0
|
||||
*/
|
||||
$vars = ['page_blocks', 'pagination'];
|
||||
extract($this->dispatcher->trigger_event('phpbbstudio.aps.display_blocks', compact($vars)));
|
||||
|
||||
$this->page_blocks = $page_blocks;
|
||||
|
||||
return $this->page_blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a block to the user desired blocks.
|
||||
*
|
||||
* @param string $block_id The block identifier
|
||||
* @return string The rendered block for display
|
||||
* @access protected
|
||||
*/
|
||||
protected function add_block($block_id)
|
||||
{
|
||||
$insert = empty($this->user_blocks);
|
||||
|
||||
$this->user_blocks[$this->page] = !$insert ? array_merge($this->user_blocks[$this->page], [$block_id]) : [$block_id];
|
||||
|
||||
$this->blockader->set_blocks($this->user->data['user_id'], $this->user_blocks, $insert);
|
||||
|
||||
$this->template->set_filenames(['block' => '@phpbbstudio_aps/blocks/base.html']);
|
||||
|
||||
if (!empty($this->page_blocks[$this->page]['blocks'][$block_id]['function']))
|
||||
{
|
||||
$this->call_function($block_id, $this->page_blocks[$this->page]['blocks'][$block_id]);
|
||||
}
|
||||
|
||||
$this->template->assign_vars([
|
||||
'block' => $this->build_display($block_id, $this->page_blocks[$this->page]['blocks'][$block_id]),
|
||||
'S_USER_LOGGED_IN' => $this->user->data['user_id'] != ANONYMOUS,
|
||||
'S_IS_BOT' => $this->user->data['is_bot'],
|
||||
]);
|
||||
|
||||
return $this->template->assign_display('block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a block from the user desired blocks.
|
||||
*
|
||||
* @param string $block_id The block identifier
|
||||
* @return string HTML list item
|
||||
* @access protected
|
||||
*/
|
||||
protected function delete_block($block_id)
|
||||
{
|
||||
$insert = empty($this->user_blocks);
|
||||
|
||||
if ($insert)
|
||||
{
|
||||
foreach ($this->page_blocks as $page => $data)
|
||||
{
|
||||
$this->user_blocks[$page] = array_keys($data['blocks']);
|
||||
}
|
||||
}
|
||||
|
||||
if (($key = array_search($block_id, $this->user_blocks[$this->page])) !== false) {
|
||||
unset($this->user_blocks[$this->page][$key]);
|
||||
}
|
||||
|
||||
$this->blockader->set_blocks($this->user->data['user_id'], $this->user_blocks, $insert);
|
||||
|
||||
return $this->build_list($block_id, $this->page_blocks[$this->page]['blocks'][$block_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move (order) the user desired blocks.
|
||||
*
|
||||
* @return bool|int Boolean on update or integer on insert.
|
||||
* @access protected
|
||||
*/
|
||||
protected function move_block()
|
||||
{
|
||||
$insert = empty($this->user_blocks);
|
||||
|
||||
$order = $this->request->variable('order', ['']);
|
||||
|
||||
// Filter out empty block identifiers
|
||||
$this->user_blocks[$this->page] = array_filter($order);
|
||||
|
||||
return $this->blockader->set_blocks($this->user->data['user_id'], $this->user_blocks, $insert);
|
||||
}
|
||||
}
|
||||
617
ext/phpbbstudio/aps/controller/mcp_controller.php
Normal file
617
ext/phpbbstudio/aps/controller/mcp_controller.php
Normal file
@@ -0,0 +1,617 @@
|
||||
<?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\controller;
|
||||
|
||||
/**
|
||||
* phpBB Studio - Advanced Points System MCP controller.
|
||||
*/
|
||||
class mcp_controller
|
||||
{
|
||||
/** @var \phpbb\auth\auth */
|
||||
protected $auth;
|
||||
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
|
||||
/** @var \phpbb\db\driver\driver_interface */
|
||||
protected $db;
|
||||
|
||||
/** @var \phpbb\event\dispatcher */
|
||||
protected $dispatcher;
|
||||
|
||||
/** @var \phpbbstudio\aps\points\distributor */
|
||||
protected $distributor;
|
||||
|
||||
/** @var \phpbbstudio\aps\core\functions */
|
||||
protected $functions;
|
||||
|
||||
/** @var \phpbb\group\helper */
|
||||
protected $group_helper;
|
||||
|
||||
/** @var \phpbb\language\language */
|
||||
protected $language;
|
||||
|
||||
/** @var \phpbbstudio\aps\core\log */
|
||||
protected $log;
|
||||
|
||||
/** @var \phpbb\notification\manager */
|
||||
protected $notification;
|
||||
|
||||
/** @var \phpbb\pagination */
|
||||
protected $pagination;
|
||||
|
||||
/** @var \phpbbstudio\aps\points\reasoner */
|
||||
protected $reasoner;
|
||||
|
||||
/** @var \phpbb\request\request */
|
||||
protected $request;
|
||||
|
||||
/** @var \phpbb\template\template */
|
||||
protected $template;
|
||||
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/** @var \phpbbstudio\aps\points\valuator */
|
||||
protected $valuator;
|
||||
|
||||
/** @var string phpBB root path */
|
||||
protected $root_path;
|
||||
|
||||
/** @var string PHP file extension */
|
||||
protected $php_ext;
|
||||
|
||||
/** @var string Points name */
|
||||
protected $name;
|
||||
|
||||
/** @var string Custom form action */
|
||||
protected $u_action;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\auth\auth $auth Authentication object
|
||||
* @param \phpbb\config\config $config Configuration object
|
||||
* @param \phpbb\db\driver\driver_interface $db Database object
|
||||
* @param \phpbb\event\dispatcher $dispatcher Event dispatcher
|
||||
* @param \phpbbstudio\aps\points\distributor $distributor APS Distributor object
|
||||
* @param \phpbbstudio\aps\core\functions $functions APS Core functions
|
||||
* @param \phpbb\group\helper $group_helper Group helper object
|
||||
* @param \phpbb\language\language $language Language object
|
||||
* @param \phpbbstudio\aps\core\log $log APS Log object
|
||||
* @param \phpbb\notification\manager $notification Notification manager object
|
||||
* @param \phpbb\pagination $pagination Pagination object
|
||||
* @param \phpbbstudio\aps\points\reasoner $reasoner APS Reasoner object
|
||||
* @param \phpbb\request\request $request Request object
|
||||
* @param \phpbb\template\template $template Template object
|
||||
* @param \phpbb\user $user User object
|
||||
* @param \phpbbstudio\aps\points\valuator $valuator APS Valuator 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,
|
||||
\phpbb\db\driver\driver_interface $db,
|
||||
\phpbb\event\dispatcher $dispatcher,
|
||||
\phpbbstudio\aps\points\distributor $distributor,
|
||||
\phpbbstudio\aps\core\functions $functions,
|
||||
\phpbb\group\helper $group_helper,
|
||||
\phpbb\language\language $language,
|
||||
\phpbbstudio\aps\core\log $log,
|
||||
\phpbb\notification\manager $notification,
|
||||
\phpbb\pagination $pagination,
|
||||
\phpbbstudio\aps\points\reasoner $reasoner,
|
||||
\phpbb\request\request $request,
|
||||
\phpbb\template\template $template,
|
||||
\phpbb\user $user,
|
||||
\phpbbstudio\aps\points\valuator $valuator,
|
||||
$root_path,
|
||||
$php_ext
|
||||
)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->config = $config;
|
||||
$this->db = $db;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->distributor = $distributor;
|
||||
$this->functions = $functions;
|
||||
$this->group_helper = $group_helper;
|
||||
$this->language = $language;
|
||||
$this->log = $log;
|
||||
$this->notification = $notification;
|
||||
$this->pagination = $pagination;
|
||||
$this->reasoner = $reasoner;
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
$this->valuator = $valuator;
|
||||
|
||||
$this->root_path = $root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
|
||||
$this->name = $functions->get_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle MCP front page.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function front()
|
||||
{
|
||||
if ($this->auth->acl_get('u_aps_view_logs'))
|
||||
{
|
||||
$this->log->load_lang();
|
||||
|
||||
// Latest 5 logs
|
||||
$logs = $this->log->get(false, 5);
|
||||
foreach ($logs as $row)
|
||||
{
|
||||
$this->template->assign_block_vars('logs', array_change_key_case($row, CASE_UPPER));
|
||||
}
|
||||
|
||||
// Latest 5 adjustments
|
||||
$moderated = $this->log->get(false, 5, 0, '', 0, 0, 0, 0, 0, 'l.log_time DESC', 'APS_POINTS_USER_ADJUSTED');
|
||||
foreach ($moderated as $row)
|
||||
{
|
||||
$this->template->assign_block_vars('moderated', array_change_key_case($row, CASE_UPPER));
|
||||
}
|
||||
}
|
||||
|
||||
// Top 5 users
|
||||
$sql = 'SELECT user_id, username, user_colour, user_points
|
||||
FROM ' . $this->functions->table('users') . '
|
||||
WHERE user_type <> ' . USER_IGNORE . '
|
||||
ORDER BY user_points DESC, username_clean ASC';
|
||||
$result = $this->db->sql_query_limit($sql, 5);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$this->template->assign_block_vars('aps_users_top', [
|
||||
'NAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
|
||||
'POINTS' => $row['user_points'],
|
||||
]);
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
// Bottom 5 user
|
||||
$sql = 'SELECT user_id, username, user_colour, user_points
|
||||
FROM ' . $this->functions->table('users') . '
|
||||
WHERE user_type <> ' . USER_IGNORE . '
|
||||
ORDER BY user_points ASC, username_clean DESC';
|
||||
$result = $this->db->sql_query_limit($sql, 5);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$this->template->assign_block_vars('aps_users_bottom', [
|
||||
'NAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
|
||||
'POINTS' => $row['user_points'],
|
||||
]);
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
/**
|
||||
* Event to assign additional variables for the APS MCP front page.
|
||||
*
|
||||
* @event phpbbstudio.aps.mcp_front
|
||||
* @since 1.0.0
|
||||
*/
|
||||
$this->dispatcher->dispatch('phpbbstudio.aps.mcp_front');
|
||||
|
||||
$this->template->assign_vars([
|
||||
'S_APS_LOGS' => $this->auth->acl_get('u_aps_view_logs'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle MCP logs.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function logs()
|
||||
{
|
||||
$this->log->load_lang();
|
||||
|
||||
// Set up general vars
|
||||
$start = $this->request->variable('start', 0);
|
||||
$forum_id = $this->request->variable('f', '');
|
||||
$topic_id = $this->request->variable('t', 0);
|
||||
$post_id = $this->request->variable('p', 0);
|
||||
$user_id = $this->request->variable('u', 0);
|
||||
$reportee_id = $this->request->variable('r', 0);
|
||||
|
||||
// Sort keys
|
||||
$sort_days = $this->request->variable('st', 0);
|
||||
$sort_key = $this->request->variable('sk', 't');
|
||||
$sort_dir = $this->request->variable('sd', 'd');
|
||||
|
||||
// Keywords
|
||||
$keywords = $this->request->variable('keywords', '', true);
|
||||
$keywords_param = !empty($keywords) ? '&keywords=' . urlencode(htmlspecialchars_decode($keywords)) : '';
|
||||
|
||||
$name = $this->functions->get_name();
|
||||
$limit = $this->config['aps_actions_per_page'];
|
||||
|
||||
// Sorting
|
||||
$limit_days = [
|
||||
0 => $this->language->lang('ALL_ENTRIES'),
|
||||
1 => $this->language->lang('1_DAY'),
|
||||
7 => $this->language->lang('7_DAYS'),
|
||||
14 => $this->language->lang('2_WEEKS'),
|
||||
30 => $this->language->lang('1_MONTH'),
|
||||
90 => $this->language->lang('3_MONTHS'),
|
||||
180 => $this->language->lang('6_MONTHS'),
|
||||
365 => $this->language->lang('1_YEAR'),
|
||||
];
|
||||
$sort_by_text = [
|
||||
'a' => $this->language->lang('SORT_ACTION'),
|
||||
'ps' => $name,
|
||||
'pn' => $this->language->lang('APS_POINTS_NEW', $name),
|
||||
'po' => $this->language->lang('APS_POINTS_OLD', $name),
|
||||
'uu' => $this->language->lang('SORT_USERNAME'),
|
||||
'ru' => $this->language->lang('FROM'),
|
||||
't' => $this->language->lang('SORT_DATE'),
|
||||
];
|
||||
$sort_by_sql = [
|
||||
'a' => 'l.log_action',
|
||||
'ps' => 'l.points_sum',
|
||||
'pn' => 'l.points_new',
|
||||
'po' => 'l.points_old',
|
||||
'uu' => 'u.username',
|
||||
'ru' => 'r.username',
|
||||
't' => 'l.log_time',
|
||||
];
|
||||
|
||||
$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
|
||||
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
|
||||
|
||||
// Define where and sort sql for use in displaying logs
|
||||
$sql_time = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
|
||||
$sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
|
||||
|
||||
$rowset = $this->log->get(true, $limit, $start, $forum_id, $topic_id, $post_id, $user_id, $reportee_id, $sql_time, $sql_sort, $keywords);
|
||||
$start = $this->log->get_valid_offset();
|
||||
$total = $this->log->get_log_count();
|
||||
|
||||
$base_url = $this->u_action . "&$u_sort_param$keywords_param";
|
||||
$this->pagination->generate_template_pagination($base_url, 'pagination', 'start', $total, $limit, $start);
|
||||
|
||||
foreach ($rowset as $row)
|
||||
{
|
||||
$this->template->assign_block_vars('logs', array_change_key_case($row, CASE_UPPER));
|
||||
}
|
||||
|
||||
$this->template->assign_vars([
|
||||
'U_ACTION' => $this->u_action . "&$u_sort_param$keywords_param&start=$start",
|
||||
|
||||
'S_LIMIT_DAYS' => $s_limit_days,
|
||||
'S_SORT_KEY' => $s_sort_key,
|
||||
'S_SORT_DIR' => $s_sort_dir,
|
||||
'S_KEYWORDS' => $keywords,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle MCP user adjustment.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$this->log->load_lang();
|
||||
|
||||
$group_id = $this->request->variable('g', 0);
|
||||
$user_id = $this->request->variable('u', 0);
|
||||
|
||||
if (empty($group_id) && empty($user_id))
|
||||
{
|
||||
$this->find_user();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->language->add_lang('acp/common');
|
||||
|
||||
$action = $this->request->variable('action', '');
|
||||
|
||||
switch ($action)
|
||||
{
|
||||
case 'add':
|
||||
case 'sub':
|
||||
case 'set':
|
||||
if (!$this->auth->acl_get('m_aps_adjust_custom'))
|
||||
{
|
||||
trigger_error($this->language->lang('NOT_AUTHORISED'), E_USER_WARNING);
|
||||
}
|
||||
break;
|
||||
|
||||
case '':
|
||||
// do nothing
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!$this->auth->acl_get('m_aps_adjust_reason'))
|
||||
{
|
||||
trigger_error($this->language->lang('NOT_AUTHORISED'), E_USER_WARNING);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($user_id))
|
||||
{
|
||||
$sql = 'SELECT user_id, username, user_colour
|
||||
FROM ' . $this->functions->table('users') . '
|
||||
WHERE user_type <> ' . USER_IGNORE . '
|
||||
AND user_id = ' . (int) $user_id;
|
||||
$result = $this->db->sql_query_limit($sql, 1);
|
||||
$user = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if ($user === false)
|
||||
{
|
||||
trigger_error($this->language->lang('NO_USER') . $this->back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$user_ids = [$user_id];
|
||||
|
||||
$u_action = '&u=' . (int) $user_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'SELECT user_id
|
||||
FROM ' . $this->functions->table('user_group') . '
|
||||
WHERE group_id = ' . (int) $group_id;
|
||||
$result = $this->db->sql_query($sql);
|
||||
$rowset = $this->db->sql_fetchrowset($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if (empty($rowset))
|
||||
{
|
||||
$this->language->add_lang('acp/groups');
|
||||
|
||||
trigger_error($this->language->lang('GROUPS_NO_MEMBERS') . $this->back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$user_ids = array_column($rowset, 'user_id');
|
||||
|
||||
$u_action = '&g=' . (int) $group_id;
|
||||
}
|
||||
|
||||
|
||||
// Actions
|
||||
$reasons = $this->reasoner->rowset();
|
||||
$actions = [
|
||||
'add' => $this->language->lang('ADD'),
|
||||
'sub' => $this->language->lang('REMOVE'),
|
||||
'set' => $this->language->lang('CHANGE'),
|
||||
];
|
||||
|
||||
$users = $this->valuator->users($user_ids);
|
||||
|
||||
$submit = $this->request->is_set_post('submit');
|
||||
$points = $this->request->variable('points', 0.00);
|
||||
$reason = $this->request->variable('reason', '', true);
|
||||
|
||||
if ($submit)
|
||||
{
|
||||
if ($action === '')
|
||||
{
|
||||
trigger_error($this->language->lang('NO_ACTION'), E_USER_WARNING);
|
||||
}
|
||||
|
||||
if (confirm_box(true))
|
||||
{
|
||||
foreach ($users as $uid => $user_points)
|
||||
{
|
||||
switch ($action)
|
||||
{
|
||||
case 'add':
|
||||
$sum_points = $points;
|
||||
break;
|
||||
case 'sub':
|
||||
$sum_points = $this->functions->equate_points(0, $points, '-');
|
||||
break;
|
||||
case 'set':
|
||||
$sum_points = $this->functions->equate_points($points, $user_points, '-');
|
||||
break;
|
||||
|
||||
default:
|
||||
if (empty($reasons[$action]))
|
||||
{
|
||||
trigger_error($this->language->lang('NO_ACTION') . $this->back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$sum_points = $reasons[$action]['reason_points'];
|
||||
$reason = $reasons[$action]['reason_title'] . '<br />' . $reasons[$action]['reason_desc'];
|
||||
break;
|
||||
}
|
||||
|
||||
$log_entry = [];
|
||||
|
||||
$log_entry[] = [
|
||||
'action' => 'APS_POINTS_USER_ADJUSTED',
|
||||
'actions' => !empty($reason) ? [$reason => $sum_points] : ['APS_POINTS_USER_ADJUSTED' => $sum_points],
|
||||
'user_id' => (int) $uid,
|
||||
'reportee_id' => (int) $this->user->data['user_id'],
|
||||
'reportee_ip' => (string) $this->user->ip,
|
||||
'points_old' => $user_points,
|
||||
'points_sum' => $sum_points,
|
||||
];
|
||||
|
||||
$this->distributor->distribute($uid, $sum_points, $log_entry, $user_points);
|
||||
}
|
||||
|
||||
$this->config->increment('aps_notification_id', 1);
|
||||
|
||||
$this->notification->add_notifications('phpbbstudio.aps.notification.type.adjust', [
|
||||
'name' => $this->functions->get_name(),
|
||||
'reason' => $reason,
|
||||
'user_ids' => array_keys($users),
|
||||
'moderator' => get_username_string('no_profile', $this->user->data['user_id'], $this->user->data['username'], $this->user->data['user_colour']),
|
||||
'moderator_id' => (int) $this->user->data['user_id'],
|
||||
'notification_id' => (int) $this->config['aps_notification_id'],
|
||||
]);
|
||||
|
||||
trigger_error($this->language->lang('MCP_APS_POINTS_USER_CHANGE_SUCCESS', $this->name) . $this->back_link($this->u_action));
|
||||
}
|
||||
else
|
||||
{
|
||||
confirm_box(false, $this->language->lang('MCP_APS_POINTS_USER_CHANGE', $this->name), build_hidden_fields([
|
||||
'submit' => $submit,
|
||||
'action' => $action,
|
||||
'points' => $points,
|
||||
'reason' => $reason,
|
||||
]));
|
||||
|
||||
redirect($this->u_action);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($user_id) && $this->auth->acl_get('u_aps_view_logs'))
|
||||
{
|
||||
$logs = $this->log->get(false, 5, 0, '', 0, 0, (int) $user_id);
|
||||
|
||||
foreach ($logs as $row)
|
||||
{
|
||||
$this->template->assign_block_vars('logs', array_change_key_case($row, CASE_UPPER));
|
||||
}
|
||||
|
||||
$this->template->assign_var('S_APS_LOGS', true);
|
||||
}
|
||||
|
||||
if (!empty($group_id))
|
||||
{
|
||||
$sql = 'SELECT group_id, group_name, group_colour
|
||||
FROM ' . $this->functions->table('groups') . '
|
||||
WHERE group_id = ' . (int) $group_id;
|
||||
$result = $this->db->sql_query_limit($sql, 1);
|
||||
$group = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$group_name = $this->group_helper->get_name_string('full', $group['group_id'], $group['group_name'], $group['group_colour']);
|
||||
}
|
||||
|
||||
$this->template->assign_vars([
|
||||
'APS_ACTIONS' => $actions,
|
||||
'APS_REASONS' => $reasons,
|
||||
'APS_POINTS' => $user_id ? $this->functions->display_points($users[$user_id]) : '',
|
||||
'APS_USERNAME' => !empty($user) ? get_username_string('full', $user['user_id'], $user['username'], $user['user_colour']) : '',
|
||||
'APS_GROUP' => !empty($group_name) ? $group_name : '',
|
||||
|
||||
'S_APS_CUSTOM' => $this->auth->acl_get('m_aps_adjust_custom'),
|
||||
'S_APS_REASON' => $this->auth->acl_get('m_aps_adjust_reason'),
|
||||
'S_APS_POINTS' => true,
|
||||
|
||||
'U_APS_ACTION' => $this->u_action . $u_action,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a user for the MCP adjustment page.
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
protected function find_user()
|
||||
{
|
||||
$this->language->add_lang('acp/groups');
|
||||
|
||||
$form_name = 'mcp_aps_change';
|
||||
add_form_key($form_name);
|
||||
|
||||
$submit_group = $this->request->is_set_post('submit_group');
|
||||
$submit_user = $this->request->is_set_post('submit_user');
|
||||
$submit = $submit_group || $submit_user;
|
||||
|
||||
$group_id = $this->request->variable('group_id', 0);
|
||||
|
||||
if ($submit && !check_form_key($form_name))
|
||||
{
|
||||
$error = 'FORM_INVALID';
|
||||
}
|
||||
else if ($submit)
|
||||
{
|
||||
if ($submit_group)
|
||||
{
|
||||
redirect($this->u_action . '&g=' . (int) $group_id);
|
||||
}
|
||||
|
||||
if ($submit_user)
|
||||
{
|
||||
if (!function_exists('user_get_id_name'))
|
||||
{
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
include $this->root_path . 'includes/functions_user.' . $this->php_ext;
|
||||
}
|
||||
|
||||
$username[] = $this->request->variable('username', '', true);
|
||||
|
||||
$error = user_get_id_name($user_ids, $username);
|
||||
|
||||
if (empty($error))
|
||||
{
|
||||
$user_id = $user_ids[0];
|
||||
|
||||
redirect($this->u_action . '&u=' . (int) $user_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('group_select_options'))
|
||||
{
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
include $this->root_path . 'includes/functions_admin.' . $this->php_ext;
|
||||
}
|
||||
|
||||
$this->template->assign_vars([
|
||||
'S_ERROR' => !empty($error),
|
||||
'ERROR_MSG' => !empty($error) ? $this->language->lang($error) : '',
|
||||
|
||||
'APS_USERNAME' => !empty($username[0]) ? $username[0] : '',
|
||||
'APS_GROUPS' => group_select_options($group_id),
|
||||
|
||||
'S_APS_SEARCH' => true,
|
||||
|
||||
'U_APS_ACTION' => $this->u_action,
|
||||
'U_APS_SEARCH' => append_sid("{$this->root_path}memberlist.{$this->php_ext}", 'mode=searchuser&form=mcp_aps_change&field=username'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a back link for this MCP controller.
|
||||
*
|
||||
* @param string $action The action to return to
|
||||
* @return string A HTML formatted URL to the action
|
||||
* @access protected
|
||||
*/
|
||||
protected function back_link($action)
|
||||
{
|
||||
return '<br /><br /><a href="' . $action . '">« ' . $this->language->lang('BACK_TO_PREV') . '</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set custom form action.
|
||||
*
|
||||
* @param string $u_action Custom form action
|
||||
* @return mcp_controller $this This controller for chaining calls
|
||||
* @access public
|
||||
*/
|
||||
public function set_page_url($u_action)
|
||||
{
|
||||
$this->u_action = $u_action;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user