-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCategories.php
More file actions
111 lines (91 loc) · 3.72 KB
/
Categories.php
File metadata and controls
111 lines (91 loc) · 3.72 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
<?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\Container;
use FeatherBB\Core\Interfaces\Cache as CacheInterface;
use FeatherBB\Core\Interfaces\ForumSettings;
use FeatherBB\Core\Interfaces\Hooks;
use FeatherBB\Core\Interfaces\Input;
use FeatherBB\Core\Interfaces\Lang;
use FeatherBB\Core\Interfaces\Router;
use FeatherBB\Core\Interfaces\User;
use FeatherBB\Core\Interfaces\View;
use FeatherBB\Core\Utils;
use FeatherBB\Model\Cache;
class Categories
{
public function __construct()
{
$this->model = new \FeatherBB\Model\Admin\Categories();
Lang::load('admin/categories');
if (!User::isAdmin()) {
throw new Error(__('No permission'), '403');
}
}
public function add($req, $res, $args)
{
Hooks::fire('controller.admin.categories.add');
$catName = Utils::trim(Input::post('cat_name'));
if ($catName == '') {
return Router::redirect(Router::pathFor('adminCategories'), __('Must enter name message'));
}
if ($this->model->addCategory($catName)) {
return Router::redirect(Router::pathFor('adminCategories'), __('Category added redirect'));
} else { //TODO, add error message
return Router::redirect(Router::pathFor('adminCategories'), __('Category added redirect'));
}
}
public function edit($req, $res, $args)
{
Hooks::fire('controller.admin.categories.edit');
if (empty(Input::post('cat'))) {
throw new Error(__('Bad request'), '400');
}
foreach (Input::post('cat') as $catId => $properties) {
$category = ['id' => (int) $catId,
'name' => Utils::escape($properties['name']),
'order' => (int) $properties['order'],];
if ($category['name'] == '') {
return Router::redirect(Router::pathFor('adminCategories'), __('Must enter name message'));
}
$this->model->updateCategory($category);
}
// Regenerate the quick jump cache
CacheInterface::store('quickjump', Cache::quickjump());
return Router::redirect(Router::pathFor('adminCategories'), __('Categories updated redirect'));
}
public function delete($req, $res, $args)
{
Hooks::fire('controller.admin.categories.delete');
$catToDelete = (int) Input::post('cat_to_delete');
if ($catToDelete < 1) {
throw new Error(__('Bad request'), '400');
}
if (intval(Input::post('disclaimer')) != 1) {
return Router::redirect(Router::pathFor('adminCategories'), __('Delete category not validated'));
}
if ($this->model->deleteCategory($catToDelete)) {
return Router::redirect(Router::pathFor('adminCategories'), __('Category deleted redirect'));
} else {
return Router::redirect(Router::pathFor('adminCategories'), __('Unable to delete category'));
}
}
public function display($req, $res, $args)
{
Hooks::fire('controller.admin.categories.display');
AdminUtils::generateAdminMenu('categories');
View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Categories')],
'active_page' => 'admin',
'admin_console' => true,
'cat_list' => $this->model->categoryList(),
])->addTemplate('@forum/admin/categories')->display();
}
}