forked from phpbb-extensions/phpbb-ext-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmcp_controller.php.twig
More file actions
94 lines (80 loc) · 2.54 KB
/
mcp_controller.php.twig
File metadata and controls
94 lines (80 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
*
* {{ EXTENSION.extension_display_name }}. An extension for the phpBB Forum Software package.
*
* @copyright (c) {{ "now"|date("Y") ~ (AUTHORS.0.author_name ? ', ' ~ AUTHORS.0.author_name) ~ (AUTHORS.0.author_homepage ? ', ' ~ AUTHORS.0.author_homepage) }}
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace {{ EXTENSION.vendor_name }}\{{ EXTENSION.extension_name }}\controller;
/**
* {{ EXTENSION.extension_display_name }} MCP controller.
*/
class mcp_controller
{
/** @var {{ LANGUAGE.class }} */
protected ${{ LANGUAGE.object }};
/** @var \phpbb\request\request */
protected $request;
/** @var \phpbb\template\template */
protected $template;
/** @var string Custom form action */
protected $u_action;
/**
* Constructor.
*
* @param {{ LANGUAGE.class ~ LANGUAGE.indent.class }} ${{ LANGUAGE.object ~ LANGUAGE.indent.object}} {{ LANGUAGE.object|capitalize }} object
* @param \phpbb\request\request $request Request object
* @param \phpbb\template\template $template Template object
*/
public function __construct({{ LANGUAGE.class }} ${{ LANGUAGE.object }}, \phpbb\request\request $request, \phpbb\template\template $template)
{
$this->{{ LANGUAGE.object ~ LANGUAGE.indent.object }} = ${{ LANGUAGE.object }};
$this->request = $request;
$this->template = $template;
}
/**
* Display the options a moderator can take for this extension.
*
* @return void
*/
public function display_options()
{
// Create a form key for preventing CSRF attacks
add_form_key('{{ EXTENSION.vendor_name|lower }}_{{ EXTENSION.extension_name|lower }}_mcp');
// Create an array to collect errors that will be output to the user
$errors = [];
// Is the form being submitted to us?
if ($this->request->is_set_post('submit'))
{
// Test if the submitted form is valid
if (!check_form_key('{{ EXTENSION.vendor_name|lower }}_{{ EXTENSION.extension_name|lower }}_mcp'))
{
$errors[] = $this->{{ LANGUAGE.object }}->lang('FORM_INVALID');
}
// If no errors, process the form data
if (empty($errors))
{
// Do your awesome moderator stuff here!
}
}
$s_errors = !empty($errors);
// Set output variables for display in the template
$this->template->assign_vars([
'S_ERROR' => $s_errors,
'ERROR_MSG' => $s_errors ? implode('<br>', $errors) : '',
'U_MCP_ACTION' => $this->u_action,
]);
}
/**
* Set custom form action.
*
* @param string $u_action Custom form action
* @return void
*/
public function set_page_url($u_action)
{
$this->u_action = $u_action;
}
}