|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* @package Breizh Smilies Categories Extension |
|
5
|
|
|
* @copyright (c) 2020-2024 Sylver35 https://breizhcode.com |
|
6
|
|
|
* @license https://opensource.org/licenses/gpl-license.php GNU Public License |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace sylver35\smiliescat\controller; |
|
11
|
|
|
|
|
12
|
|
|
use sylver35\smiliescat\core\category; |
|
13
|
|
|
use sylver35\smiliescat\core\smiley; |
|
14
|
|
|
use sylver35\smiliescat\core\work; |
|
15
|
|
|
use phpbb\config\config; |
|
16
|
|
|
use phpbb\db\driver\driver_interface as db; |
|
17
|
|
|
use phpbb\pagination; |
|
18
|
|
|
use phpbb\request\request; |
|
19
|
|
|
use phpbb\template\template; |
|
20
|
|
|
use phpbb\user; |
|
21
|
|
|
use phpbb\language\language; |
|
22
|
|
|
use phpbb\log\log; |
|
23
|
|
|
|
|
24
|
|
|
class admin_controller |
|
25
|
|
|
{ |
|
26
|
|
|
private const DEFAULT_CAT = 9998; |
|
27
|
|
|
private const NOT_DISPLAY = 9999; |
|
28
|
|
|
|
|
29
|
|
|
/* @var \sylver35\smiliescat\core\category */ |
|
30
|
|
|
protected $category; |
|
31
|
|
|
|
|
32
|
|
|
/* @var \sylver35\smiliescat\core\smiley */ |
|
33
|
|
|
protected $smiley; |
|
34
|
|
|
|
|
35
|
|
|
/* @var \sylver35\smiliescat\core\work */ |
|
36
|
|
|
protected $work; |
|
37
|
|
|
|
|
38
|
|
|
/** @var \phpbb\config\config */ |
|
39
|
|
|
protected $config; |
|
40
|
|
|
|
|
41
|
|
|
/** @var \phpbb\db\driver\driver_interface */ |
|
42
|
|
|
protected $db; |
|
43
|
|
|
|
|
44
|
|
|
/** @var \phpbb\pagination */ |
|
45
|
|
|
protected $pagination; |
|
46
|
|
|
|
|
47
|
|
|
/** @var \phpbb\request\request */ |
|
48
|
|
|
protected $request; |
|
49
|
|
|
|
|
50
|
|
|
/** @var \phpbb\template\template */ |
|
51
|
|
|
protected $template; |
|
52
|
|
|
|
|
53
|
|
|
/** @var \phpbb\user */ |
|
54
|
|
|
protected $user; |
|
55
|
|
|
|
|
56
|
|
|
/** @var \phpbb\language\language */ |
|
57
|
|
|
protected $language; |
|
58
|
|
|
|
|
59
|
|
|
/** @var \phpbb\log\log */ |
|
60
|
|
|
protected $log; |
|
61
|
|
|
|
|
62
|
|
|
/** @var string phpBB root path */ |
|
63
|
|
|
protected $root_path; |
|
64
|
|
|
|
|
65
|
|
|
/** @var string Custom form action */ |
|
66
|
|
|
protected $u_action; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* The database tables |
|
70
|
|
|
* |
|
71
|
|
|
* @var string */ |
|
72
|
|
|
protected $smilies_category_table; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Constructor |
|
76
|
|
|
*/ |
|
77
|
|
|
public function __construct(category $category, smiley $smiley, work $work, config $config, db $db, pagination $pagination, request $request, template $template, user $user, language $language, log $log, $root_path, $smilies_category_table) |
|
78
|
|
|
{ |
|
79
|
|
|
$this->category = $category; |
|
80
|
|
|
$this->smiley = $smiley; |
|
81
|
|
|
$this->work = $work; |
|
82
|
|
|
$this->config = $config; |
|
83
|
|
|
$this->db = $db; |
|
84
|
|
|
$this->pagination = $pagination; |
|
85
|
|
|
$this->request = $request; |
|
86
|
|
|
$this->template = $template; |
|
87
|
|
|
$this->user = $user; |
|
88
|
|
|
$this->language = $language; |
|
89
|
|
|
$this->log = $log; |
|
90
|
|
|
$this->root_path = $root_path; |
|
91
|
|
|
$this->smilies_category_table = $smilies_category_table; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function acp_smilies_category($id, $action) |
|
95
|
|
|
{ |
|
96
|
|
|
$this->language->add_lang('acp/posting'); |
|
97
|
|
|
$start = (int) $this->request->variable('start', 0); |
|
98
|
|
|
$select = (int) $this->request->variable('select', 0); |
|
99
|
|
|
$cat_id = (int) $this->request->variable('cat_id', 0); |
|
100
|
|
|
$ex_cat = (int) $this->request->variable('ex_cat', 0); |
|
101
|
|
|
$list = $this->request->variable('list', [0]); |
|
102
|
|
|
$form_key = 'sylver35/smiliescat'; |
|
103
|
|
|
add_form_key($form_key); |
|
104
|
|
|
|
|
105
|
|
|
if ($action) |
|
106
|
|
|
{ |
|
107
|
|
|
switch ($action) |
|
108
|
|
|
{ |
|
109
|
|
|
case 'edit': |
|
110
|
|
|
$this->smiley->edit_smiley($id, $start, $ex_cat, $this->u_action); |
|
111
|
|
|
break; |
|
112
|
|
|
|
|
113
|
|
|
case 'edit_multi': |
|
114
|
|
|
$list = $this->request->variable('mark', [0]); |
|
115
|
|
|
if (empty($list)) |
|
116
|
|
|
{ |
|
117
|
|
|
trigger_error($this->language->lang('SC_SMILIES_EMPTY') . adm_back_link($this->u_action . '&start=' . $start . '#acp_smilies_category'), E_USER_WARNING); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
$this->smiley->edit_multi_smiley($list, $start, $this->u_action); |
|
121
|
|
|
break; |
|
122
|
|
|
|
|
123
|
|
|
case 'modify': |
|
124
|
|
|
if (!check_form_key($form_key)) |
|
125
|
|
|
{ |
|
126
|
|
|
trigger_error($this->language->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
$this->smiley->modify_smiley($id, $cat_id, $ex_cat); |
|
130
|
|
|
trigger_error($this->language->lang('SMILIES_EDITED', 1) . adm_back_link($this->u_action . '&start=' . $start . '#acp_smilies_category')); |
|
131
|
|
|
break; |
|
132
|
|
|
|
|
133
|
|
|
case 'modify_list': |
|
134
|
|
|
foreach ($list as $smiley) |
|
135
|
|
|
{ |
|
136
|
|
|
$this->smiley->modify_smiley($smiley, $cat_id); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
trigger_error($this->language->lang('SMILIES_EDITED', count($list)) . adm_back_link($this->u_action . '&start=' . $start . '#acp_smilies_category')); |
|
140
|
|
|
break; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
$this->template->assign_vars([ |
|
144
|
|
|
'IN_ACTION' => true, |
|
145
|
|
|
]); |
|
146
|
|
|
} |
|
147
|
|
|
else |
|
148
|
|
|
{ |
|
149
|
|
|
$this->smiley->extract_list_smilies($select, $start, $this->u_action); |
|
150
|
|
|
|
|
151
|
|
|
$this->template->assign_vars([ |
|
152
|
|
|
'LIST_CATEGORY' => $this->smiley->select_categories($select, true, true), |
|
153
|
|
|
'U_SELECT_CAT' => $this->u_action . '&select=' . $select, |
|
154
|
|
|
'U_MODIFY_LIST' => $this->u_action . '&action=edit_multi&start=' . $start, |
|
155
|
|
|
'U_BACK' => $this->u_action, |
|
156
|
|
|
]); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
$this->template->assign_vars([ |
|
160
|
|
|
'CATEGORIE_SMILIES' => true, |
|
161
|
|
|
]); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
public function acp_categories_config($id, $action, $mode) |
|
165
|
|
|
{ |
|
166
|
|
|
$this->language->add_lang('acp/language'); |
|
167
|
|
|
$form_key = 'sylver35/smiliescat'; |
|
168
|
|
|
add_form_key($form_key); |
|
169
|
|
|
|
|
170
|
|
|
if ($action) |
|
171
|
|
|
{ |
|
172
|
|
|
if (in_array($action, ['config_cat', 'add_cat', 'edit_cat']) && !check_form_key($form_key)) |
|
173
|
|
|
{ |
|
174
|
|
|
trigger_error($this->language->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
switch ($action) |
|
178
|
|
|
{ |
|
179
|
|
|
case 'config_cat': |
|
180
|
|
|
$this->config->set('smilies_per_page_cat', (int) $this->request->variable('smilies_per_page_cat', 15)); |
|
181
|
|
|
$this->config->set('smilies_per_page_acp', (int) $this->request->variable('smilies_per_page_acp', 15)); |
|
182
|
|
|
|
|
183
|
|
|
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SC_CONFIG', time()); |
|
184
|
|
|
trigger_error($this->language->lang('CONFIG_UPDATED') . adm_back_link($this->u_action)); |
|
185
|
|
|
break; |
|
186
|
|
|
|
|
187
|
|
|
case 'add': |
|
188
|
|
|
$this->work->add_cat($this->u_action); |
|
189
|
|
|
break; |
|
190
|
|
|
|
|
191
|
|
|
case 'add_cat': |
|
192
|
|
|
$this->work->add_category($this->u_action); |
|
193
|
|
|
break; |
|
194
|
|
|
|
|
195
|
|
|
case 'edit': |
|
196
|
|
|
$this->work->edit_cat((int) $id, $this->u_action); |
|
197
|
|
|
break; |
|
198
|
|
|
|
|
199
|
|
|
case 'edit_cat': |
|
200
|
|
|
$this->work->edit_category((int) $id, $this->u_action); |
|
201
|
|
|
break; |
|
202
|
|
|
|
|
203
|
|
|
case 'delete': |
|
204
|
|
|
if (confirm_box(true)) |
|
205
|
|
|
{ |
|
206
|
|
|
$this->work->delete_cat((int) $id, $this->u_action); |
|
207
|
|
|
} |
|
208
|
|
|
else |
|
209
|
|
|
{ |
|
210
|
|
|
confirm_box(false, $this->language->lang('CONFIRM_OPERATION'), build_hidden_fields([ |
|
211
|
|
|
'mode' => $mode, |
|
212
|
|
|
'id' => $id, |
|
213
|
|
|
'action' => $action, |
|
214
|
|
|
])); |
|
215
|
|
|
} |
|
216
|
|
|
break; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
$this->template->assign_vars([ |
|
220
|
|
|
'IN_ACTION' => true, |
|
221
|
|
|
]); |
|
222
|
|
|
} |
|
223
|
|
|
else |
|
224
|
|
|
{ |
|
225
|
|
|
$this->work->adm_list_cat($this->u_action); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
$this->template->assign_vars([ |
|
229
|
|
|
'CATEGORIE_CONFIG' => true, |
|
230
|
|
|
'SMILIES_PER_PAGE_CAT' => $this->config['smilies_per_page_cat'], |
|
231
|
|
|
'SMILIES_PER_PAGE_ACP' => $this->config['smilies_per_page_acp'], |
|
232
|
|
|
'U_ACTION_CONFIG' => $this->u_action . '&action=config_cat', |
|
233
|
|
|
'U_ADD' => $this->u_action . '&action=add', |
|
234
|
|
|
]); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* Set page url |
|
239
|
|
|
* |
|
240
|
|
|
* @param string $u_action Custom form action |
|
241
|
|
|
* @return void |
|
242
|
|
|
* @access public |
|
243
|
|
|
*/ |
|
244
|
|
|
public function set_page_url($u_action) |
|
245
|
|
|
{ |
|
246
|
|
|
$this->u_action = $u_action; |
|
247
|
|
|
} |
|
248
|
|
|
} |
|
249
|
|
|
|