forked from featherbb/featherbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforums.php
More file actions
187 lines (154 loc) · 8.51 KB
/
Copy pathforums.php
File metadata and controls
187 lines (154 loc) · 8.51 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/**
* Copyright (C) 2015 FeatherBB
* based on code by (C) 2008-2012 FluxBB
* and Rickard Andersson (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
namespace controller\admin;
class forums
{
public function __construct()
{
$this->feather = \Slim\Slim::getInstance();
$this->start = $this->feather->start;
$this->config = $this->feather->config;
$this->user = $this->feather->user;
$this->request = $this->feather->request;
$this->model = new \model\admin\forums();
load_textdomain('featherbb', $this->feather->forum_env['FEATHER_ROOT'].'lang/'.$this->user->language.'/admin/forums.mo');
}
public function __autoload($class_name)
{
require $this->feather->forum_env['FEATHER_ROOT'] . $class_name . '.php';
}
//
// CRUD
//
public function add_forum()
{
$cat_id = (int) $this->request->post('cat');
if ($cat_id < 1) {
redirect($this->feather->url->get('admin/forums/'), __('Must be valid category'));
}
if ($fid = $this->model->add_forum($cat_id, __('New forum'))) {
// Regenerate the quick jump cache
$this->feather->cache->store('quickjump', \model\cache::get_quickjump());
redirect($this->feather->url->get('admin/forums/edit/'.$fid.'/'), __('Forum added redirect'));
} else {
redirect($this->feather->url->get('admin/forums/'), __('Unable to add forum'));
}
}
public function edit_forum($forum_id)
{
if($this->request->isPost()) {
if ($this->request->post('save') && $this->request->post('read_forum_old')) {
// Forums parameters / TODO : better handling of wrong parameters
$forum_data = array('forum_name' => $this->feather->utils->escape($this->request->post('forum_name')),
'forum_desc' => $this->request->post('forum_desc') ? $this->feather->utils->linebreaks($this->feather->utils->trim($this->request->post('forum_desc'))) : NULL,
'cat_id' => (int) $this->request->post('cat_id'),
'sort_by' => (int) $this->request->post('sort_by'),
'redirect_url' => $this->feather->url->is_valid($this->request->post('redirect_url')) ? $this->feather->utils->escape($this->request->post('redirect_url')) : NULL);
if ($forum_data['forum_name'] == '') {
redirect($this->feather->url->get('admin/forums/edit/'.$forum_id.'/'), __('Must enter name message'));
}
if ($forum_data['cat_id'] < 1) {
redirect($this->feather->url->get('admin/forums/edit/'.$forum_id.'/'), __('Must be valid category'));
}
$this->model->update_forum($forum_id, $forum_data);
// Permissions
$permissions = $this->model->get_default_group_permissions(false);
foreach($permissions as $perm_group) {
$permissions_data = array('group_id' => $perm_group['g_id'],
'forum_id' => $forum_id);
if ($perm_group['g_read_board'] == '1' && isset($this->request->post('read_forum_new')[$perm_group['g_id']]) && $this->request->post('read_forum_new')[$perm_group['g_id']] == '1') {
$permissions_data['read_forum'] = '1';
}
else {
$permissions_data['read_forum'] = '0';
}
$permissions_data['post_replies'] = (isset($this->request->post('post_replies_new')[$perm_group['g_id']])) ? '1' : '0';
$permissions_data['post_topics'] = (isset($this->request->post('post_topics_new')[$perm_group['g_id']])) ? '1' : '0';
// Check if the new settings differ from the old
if ($permissions_data['read_forum'] != $this->request->post('read_forum_old')[$perm_group['g_id']] ||
$permissions_data['post_replies'] != $this->request->post('post_replies_old')[$perm_group['g_id']] ||
$permissions_data['post_topics'] != $this->request->post('post_topics_old')[$perm_group['g_id']]) {
// If there is no group permissions override for this forum
if ($permissions_data['read_forum'] == '1' && $permissions_data['post_replies'] == $perm_group['g_post_replies'] && $permissions_data['post_topics'] == $perm_group['g_post_topics']) {
$this->model->delete_permissions($forum_id, $perm_group['g_id']);
} else {
// Run an UPDATE and see if it affected a row, if not, INSERT
$this->model->update_permissions($permissions_data);
}
}
}
// Regenerate the quick jump cache
$this->feather->cache->store('quickjump', \model\cache::get_quickjump());
redirect($this->feather->url->get('admin/forums/edit/'.$forum_id.'/'), __('Forum updated redirect'));
} elseif ($this->request->post('revert_perms')) {
$this->model->delete_permissions($forum_id);
// Regenerate the quick jump cache
$this->feather->cache->store('quickjump', \model\cache::get_quickjump());
redirect($this->feather->url->get('admin/forums/edit/'.$forum_id.'/'), __('Perms reverted redirect'));
}
} else {
\FeatherBB\AdminUtils::generateAdminMenu('forums');
$this->feather->view2->setPageInfo(array(
'title' => array($this->feather->utils->escape($this->config['o_board_title']), __('Admin'), __('Forums')),
'active_page' => 'admin',
'admin_console' => true,
'perm_data' => $this->model->get_permissions($forum_id),
'cur_index' => 7,
'cur_forum' => $this->model->get_forum_info($forum_id),
'forum_data' => $this->model->get_forums(),
)
)->addTemplate('admin/forums/permissions.php')->display();
}
}
public function delete_forum($forum_id)
{
if($this->request->isPost()) {
$this->model->delete_forum($forum_id);
// Regenerate the quick jump cache
$this->feather->cache->store('quickjump', \model\cache::get_quickjump());
redirect($this->feather->url->get('admin/forums/'), __('Forum deleted redirect'));
} else { // If the user hasn't confirmed
\FeatherBB\AdminUtils::generateAdminMenu('forums');
$this->feather->view2->setPageInfo(array(
'title' => array($this->feather->utils->escape($this->config['o_board_title']), __('Admin'), __('Forums')),
'active_page' => 'admin',
'admin_console' => true,
'cur_forum' => $this->model->get_forum_info($forum_id),
)
)->addTemplate('admin/forums/delete_forum.php')->display();
}
}
// -- //
public function edit_positions()
{
foreach ($this->request->post('position') as $forum_id => $position) {
$position = (int) $this->feather->utils->trim($position);
$this->model->update_positions($forum_id, $position);
}
// Regenerate the quick jump cache
$this->feather->cache->store('quickjump', \model\cache::get_quickjump());
redirect($this->feather->url->get('admin/forums/'), __('Forums updated redirect'));
}
public function display()
{
if ($this->request->post('update_positions')) {
$this->edit_positions();
}
\FeatherBB\AdminUtils::generateAdminMenu('forums');
$categories_model = new \model\admin\categories();
$this->feather->view2->setPageInfo(array(
'title' => array($this->feather->utils->escape($this->config['o_board_title']), __('Admin'), __('Forums')),
'active_page' => 'admin',
'admin_console' => true,
'cat_list' => $categories_model->get_cat_list(),
'forum_data' => $this->model->get_forums(),
'cur_index' => 4,
)
)->addTemplate('admin/forums/admin_forums.php')->display();
}
}