1 | <?php |
||
21 | class admin_controller implements admin_controller_interface |
||
22 | { |
||
23 | /** @var manager */ |
||
24 | protected $manager; |
||
25 | |||
26 | /** @var request */ |
||
27 | protected $request; |
||
28 | |||
29 | /** @var template */ |
||
30 | protected $template; |
||
31 | |||
32 | /** @var user */ |
||
33 | protected $user; |
||
34 | |||
35 | /** @var string */ |
||
36 | protected $form_key; |
||
37 | |||
38 | /** @var int */ |
||
39 | protected $forum_id; |
||
40 | |||
41 | /** @var string */ |
||
42 | protected $u_action; |
||
43 | |||
44 | /** |
||
45 | * Constructor |
||
46 | * |
||
47 | * @param manager $manager |
||
48 | * @param request $request |
||
49 | * @param template $template |
||
50 | * @param user $user |
||
51 | */ |
||
52 | public function __construct(manager $manager, request $request, template $template, user $user) |
||
59 | |||
60 | public function main() |
||
89 | |||
90 | /** |
||
91 | * @inheritdoc |
||
92 | */ |
||
93 | public function display_settings() |
||
113 | |||
114 | /** |
||
115 | * @inheritdoc |
||
116 | */ |
||
117 | public function add_prefix() |
||
130 | |||
131 | /** |
||
132 | * @inheritdoc |
||
133 | */ |
||
134 | public function edit_prefix($prefix_id) |
||
135 | { |
||
136 | if (!$this->check_hash('edit' . $prefix_id)) |
||
137 | { |
||
138 | trigger_error($this->get_error_message('FORM_INVALID'), E_USER_WARNING); |
||
139 | } |
||
140 | |||
141 | try |
||
142 | { |
||
143 | $prefix = $this->manager->get_prefix($prefix_id); |
||
144 | $this->manager->update_prefix($prefix['prefix_id'], ['prefix_enabled' => !$prefix['prefix_enabled']]); |
||
145 | } |
||
146 | catch (\OutOfBoundsException $e) |
||
147 | { |
||
148 | trigger_error($e->getMessage() . $this->get_error_message(), E_USER_WARNING); |
||
149 | } |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * @inheritdoc |
||
154 | */ |
||
155 | public function delete_prefix($prefix_id) |
||
178 | |||
179 | /** |
||
180 | * @inheritdoc |
||
181 | */ |
||
182 | public function move_prefix($prefix_id, $direction, $amount = 1) |
||
183 | { |
||
184 | if (!$this->check_hash($direction . $prefix_id)) |
||
185 | { |
||
186 | trigger_error($this->get_error_message('FORM_INVALID'), E_USER_WARNING); |
||
187 | } |
||
188 | |||
189 | try |
||
190 | { |
||
191 | $this->manager->move_prefix($prefix_id, $direction, $amount); |
||
192 | } |
||
193 | catch (\OutOfBoundsException $e) |
||
194 | { |
||
195 | trigger_error($e->getMessage() . $this->get_error_message(), E_USER_WARNING); |
||
196 | } |
||
197 | |||
198 | if ($this->request->is_ajax()) |
||
199 | { |
||
200 | $json_response = new \phpbb\json_response; |
||
201 | $json_response->send(['success' => true]); |
||
202 | } |
||
203 | } |
||
204 | |||
205 | /** |
||
206 | * @inheritdoc |
||
207 | */ |
||
208 | public function set_u_action($u_action) |
||
213 | |||
214 | /** |
||
215 | * @param int $forum_id |
||
216 | */ |
||
217 | public function set_forum_id($forum_id) |
||
221 | |||
222 | /** |
||
223 | * Check link hash helper |
||
224 | * |
||
225 | * @param string $hash A hashed string |
||
226 | * @return bool True if hash matches, false if not |
||
227 | */ |
||
228 | protected function check_hash($hash) |
||
232 | |||
233 | /** |
||
234 | * Return a common message and back link for trigger error dialogs |
||
235 | * |
||
236 | * @param string $message A language key |
||
237 | * @return string |
||
238 | */ |
||
239 | protected function get_error_message($message = '') |
||
243 | } |
||
244 |