-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathBans.php
More file actions
115 lines (93 loc) · 3.7 KB
/
Bans.php
File metadata and controls
115 lines (93 loc) · 3.7 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* Copyright (C) 2015-2019 FeatherBB
* based on code by (C) 2008-2015 FluxBB
* and Rickard Andersson (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
namespace FeatherBB\Controller\Admin;
use FeatherBB\Core\AdminUtils;
use FeatherBB\Core\Error;
use FeatherBB\Core\Interfaces\ForumSettings;
use FeatherBB\Core\Interfaces\Hooks;
use FeatherBB\Core\Interfaces\Input;
use FeatherBB\Core\Interfaces\Lang;
use FeatherBB\Core\Interfaces\User;
use FeatherBB\Core\Interfaces\View;
use FeatherBB\Core\Url;
use FeatherBB\Core\Utils;
class Bans
{
public function __construct()
{
$this->model = new \FeatherBB\Model\Admin\Bans();
Lang::load('admin/bans');
Lang::load('admin/common');
if (!User::can('mod.ban_users')) {
throw new Error(__('No permission'), '403');
}
}
public function display($req, $res, $args)
{
Hooks::fire('controller.admin.bans.display');
// Display bans
if (Input::query('find_ban')) {
$banInfo = $this->model->findBan();
// Determine the ban offset (based on $_GET['p'])
$numPages = ceil($banInfo['num_bans'] / 50);
$p = (!Input::query('p') || Input::query('p') <= 1 || Input::query('p') > $numPages) ? 1 : intval(Input::query('p'));
$startFrom = 50 * ($p - 1);
$banData = $this->model->findBan($startFrom);
View::setPageInfo([
'admin_console' => true,
'page' => $p,
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Bans'), __('Results head')],
'paging_links' => '<span class="pages-label">' . __('Pages') . ' </span>' . Url::paginateOld($numPages, $p, '?find_ban=&' . implode('&', $banInfo['query_str'])),
'ban_data' => $banData['data'],
]
)->addTemplate('@forum/admin/bans/search_ban')->display();
} else {
AdminUtils::generateAdminMenu('bans');
View::setPageInfo([
'admin_console' => true,
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Bans')],
]
)->addTemplate('@forum/admin/bans/admin_bans')->display();
}
}
public function add($req, $res, $args)
{
Hooks::fire('controller.admin.bans.add');
if (Input::post('add_edit_ban')) {
return $this->model->insertBan();
}
AdminUtils::generateAdminMenu('bans');
$banId = (isset($args['id'])) ? $args['id'] : null;
View::setPageInfo([
'admin_console' => true,
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Bans')],
'ban' => $this->model->addBanInfo($banId),
]
)->addTemplate('@forum/admin/bans/add_ban')->display();
}
public function delete($req, $res, $args)
{
Hooks::fire('controller.admin.bans.delete');
// Remove the ban
return $this->model->removeBan($args['id']);
}
public function edit($req, $res, $args)
{
Hooks::fire('controller.admin.bans.edit');
if (Input::post('add_edit_ban')) {
return $this->model->insertBan();
}
AdminUtils::generateAdminMenu('bans');
View::setPageInfo([
'admin_console' => true,
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Bans')],
'ban' => $this->model->editBanInfo($args['id']),
]
)->addTemplate('@forum/admin/bans/add_ban')->display();
}
}