1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package Breizh Smilies Categories Extension |
5
|
|
|
* @copyright (c) 2020 Sylver35 https://breizhcode.com |
6
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace sylver35\smiliescat\core; |
11
|
|
|
|
12
|
|
|
use phpbb\cache\driver\driver_interface as cache; |
13
|
|
|
use phpbb\db\driver\driver_interface as db; |
14
|
|
|
use phpbb\config\config; |
15
|
|
|
use phpbb\user; |
16
|
|
|
use phpbb\language\language; |
17
|
|
|
use phpbb\template\template; |
18
|
|
|
use phpbb\request\request; |
19
|
|
|
use phpbb\extension\manager; |
20
|
|
|
|
21
|
|
|
class category |
22
|
|
|
{ |
23
|
|
|
/** @var \phpbb\cache\driver\driver_interface */ |
24
|
|
|
protected $cache; |
25
|
|
|
|
26
|
|
|
/** @var \phpbb\db\driver\driver_interface */ |
27
|
|
|
protected $db; |
28
|
|
|
|
29
|
|
|
/** @var \phpbb\config\config */ |
30
|
|
|
protected $config; |
31
|
|
|
|
32
|
|
|
/** @var \phpbb\user */ |
33
|
|
|
protected $user; |
34
|
|
|
|
35
|
|
|
/** @var \phpbb\language\language */ |
36
|
|
|
protected $language; |
37
|
|
|
|
38
|
|
|
/** @var \phpbb\template\template */ |
39
|
|
|
protected $template; |
40
|
|
|
|
41
|
|
|
/** @var \phpbb\request\request */ |
42
|
|
|
protected $request; |
43
|
|
|
|
44
|
|
|
/** @var \phpbb\extension\manager "Extension Manager" */ |
45
|
|
|
protected $ext_manager; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* The database tables |
49
|
|
|
* |
50
|
|
|
* @var string */ |
51
|
|
|
protected $smilies_category_table; |
52
|
|
|
|
53
|
|
|
/** @var string phpBB root path */ |
54
|
|
|
protected $root_path; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Constructor |
58
|
|
|
*/ |
59
|
|
|
public function __construct(cache $cache, db $db, config $config, user $user, language $language, template $template, request $request, manager $ext_manager, $smilies_category_table, $root_path) |
60
|
|
|
{ |
61
|
|
|
$this->cache = $cache; |
62
|
|
|
$this->db = $db; |
63
|
|
|
$this->config = $config; |
64
|
|
|
$this->user = $user; |
65
|
|
|
$this->language = $language; |
66
|
|
|
$this->template = $template; |
67
|
|
|
$this->request = $request; |
68
|
|
|
$this->ext_manager = $ext_manager; |
69
|
|
|
$this->smilies_category_table = $smilies_category_table; |
70
|
|
|
$this->root_path = $root_path; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function get_version() |
74
|
|
|
{ |
75
|
|
|
if (($data = $this->cache->get('_smiliescat_version')) === false) |
76
|
|
|
{ |
77
|
|
|
$md_manager = $this->ext_manager->create_extension_metadata_manager('sylver35/smiliescat'); |
78
|
|
|
$meta = $md_manager->get_metadata(); |
79
|
|
|
|
80
|
|
|
$data = array( |
81
|
|
|
'version' => $meta['version'], |
82
|
|
|
'homepage' => $meta['homepage'], |
83
|
|
|
); |
84
|
|
|
// cache for 7 days |
85
|
|
|
$this->cache->put('_smiliescat_version', $data, 604800); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $data; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function smilies_count($cat) |
92
|
|
|
{ |
93
|
|
|
$sql_where = ($cat == -1) ? "code <> ''" : "category = $cat"; |
94
|
|
|
$sql = $this->db->sql_build_query('SELECT', array( |
95
|
|
|
'SELECT' => 'COUNT(DISTINCT smiley_url) AS smilies_count', |
96
|
|
|
'FROM' => array(SMILIES_TABLE => ''), |
97
|
|
|
'WHERE' => $sql_where, |
98
|
|
|
)); |
99
|
|
|
$result = $this->db->sql_query($sql); |
100
|
|
|
$smilies_count = (int) $this->db->sql_fetchfield('smilies_count'); |
101
|
|
|
$this->db->sql_freeresult($result); |
102
|
|
|
|
103
|
|
|
return $smilies_count; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function select_categories($cat, $modify = false) |
107
|
|
|
{ |
108
|
|
|
$lang = $this->user->lang_name; |
109
|
|
|
$select = '<option>' . $this->language->lang('SC_CATEGORY_SELECT') . '</option>'; |
110
|
|
|
if (!$modify) |
111
|
|
|
{ |
112
|
|
|
$sel = ($cat == -1) ? ' selected="selected"' : ''; |
113
|
|
|
$select .= '<option value="-1"' . $sel . '>' . $this->language->lang('SC_CATEGORY_ANY') . '</option>'; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$sql = 'SELECT * |
117
|
|
|
FROM ' . $this->smilies_category_table . " |
118
|
|
|
WHERE cat_lang = '$lang' |
119
|
|
|
ORDER BY cat_order ASC"; |
120
|
|
|
$result = $this->db->sql_query($sql); |
121
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
122
|
|
|
{ |
123
|
|
|
$selected = ($cat == $row['cat_id']) ? ' selected="selected"' : ''; |
124
|
|
|
$select .= '<option title="' . $row['cat_name'] . '" value="' . $row['cat_id'] . '"' . $selected . '> ' . $row['cat_name'] . '</option>'; |
125
|
|
|
} |
126
|
|
|
$this->db->sql_freeresult($result); |
127
|
|
|
|
128
|
|
|
$selected_defaut = ($cat == 0) ? ' selected="selected"' : ''; |
129
|
|
|
$select .= '<option title="' . $this->language->lang('SC_CATEGORY_DEFAUT') . '" value="0"' . $selected_defaut . '> ' . $this->language->lang('SC_CATEGORY_DEFAUT') . '</option>'; |
130
|
|
|
|
131
|
|
|
return $select; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function capitalize($var) |
135
|
|
|
{ |
136
|
|
|
return $this->db->sql_escape(ucfirst(strtolower(trim($var)))); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function get_max_order() |
140
|
|
|
{ |
141
|
|
|
// Get max order id... |
142
|
|
|
$sql = 'SELECT MAX(cat_order) AS maxi |
143
|
|
|
FROM ' . $this->smilies_category_table; |
144
|
|
|
$result = $this->db->sql_query($sql); |
145
|
|
|
$max = (int) $this->db->sql_fetchfield('maxi', $result); |
146
|
|
|
$this->db->sql_freeresult($result); |
147
|
|
|
|
148
|
|
|
return $max; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function get_max_id() |
152
|
|
|
{ |
153
|
|
|
// Get max id... |
154
|
|
|
$sql = 'SELECT MAX(cat_id) AS id_max |
155
|
|
|
FROM ' . $this->smilies_category_table; |
156
|
|
|
$result = $this->db->sql_query($sql); |
157
|
|
|
$id_max = (int) $this->db->sql_fetchfield('id_max', $result); |
158
|
|
|
$this->db->sql_freeresult($result); |
159
|
|
|
|
160
|
|
|
return $id_max; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function get_first_order() |
164
|
|
|
{ |
165
|
|
|
// Get first order id... |
166
|
|
|
$sql = 'SELECT cat_order, cat_id |
167
|
|
|
FROM ' . $this->smilies_category_table . ' |
168
|
|
|
ORDER BY cat_order ASC'; |
169
|
|
|
$result = $this->db->sql_query_limit($sql, 1); |
170
|
|
|
$row = $this->db->sql_fetchrow($result); |
171
|
|
|
$mini = $row['cat_id']; |
172
|
|
|
$this->db->sql_freeresult($result); |
173
|
|
|
|
174
|
|
|
return $mini; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function shoutbox_smilies($event) |
178
|
|
|
{ |
179
|
|
|
$i = $cat_order = $cat_id = 0; |
180
|
|
|
$list_cat = []; |
181
|
|
|
$lang = $this->user->lang_name; |
182
|
|
|
|
183
|
|
|
$sql = $this->db->sql_build_query('SELECT', array( |
184
|
|
|
'SELECT' => '*', |
185
|
|
|
'FROM' => array($this->smilies_category_table => ''), |
186
|
|
|
'WHERE' => "cat_lang = '$lang'", |
187
|
|
|
'ORDER_BY' => 'cat_order ASC', |
188
|
|
|
)); |
189
|
|
|
$result = $this->db->sql_query($sql, 3600); |
190
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
191
|
|
|
{ |
192
|
|
|
$list_cat[$i] = array( |
193
|
|
|
'cat_id' => $row['cat_id'], |
194
|
|
|
'cat_order' => $row['cat_order'], |
195
|
|
|
'cat_name' => $row['cat_name'], |
196
|
|
|
'cat_nb' => $row['cat_nb'], |
197
|
|
|
); |
198
|
|
|
$i++; |
199
|
|
|
$cat_order = $row['cat_order']; |
200
|
|
|
} |
201
|
|
|
$this->db->sql_freeresult($result); |
202
|
|
|
|
203
|
|
|
if ($i > 0) |
204
|
|
|
{ |
205
|
|
|
// Add the Unclassified category |
206
|
|
|
$list_cat[$i] = array( |
207
|
|
|
'cat_id' => $cat_id, |
208
|
|
|
'cat_order' => $cat_order + 1, |
209
|
|
|
'cat_name' => $this->language->lang('SC_CATEGORY_DEFAUT'), |
210
|
|
|
'cat_nb' => $this->smilies_count($cat_id), |
211
|
|
|
); |
212
|
|
|
|
213
|
|
|
$event['content'] = array_merge($event['content'], array( |
214
|
|
|
'title_cat' => $this->language->lang('ACP_SC_SMILIES'), |
215
|
|
|
'categories' => $list_cat, |
216
|
|
|
)); |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public function shoutbox_smilies_popup($event) |
221
|
|
|
{ |
222
|
|
|
$cat = $event['cat']; |
223
|
|
|
if ($cat > -1) |
224
|
|
|
{ |
225
|
|
|
$i = 0; |
226
|
|
|
$smilies = array(); |
227
|
|
|
$lang = $this->user->lang_name; |
228
|
|
|
|
229
|
|
|
if ($cat > 0) |
230
|
|
|
{ |
231
|
|
|
$sql = 'SELECT cat_name |
232
|
|
|
FROM ' . $this->smilies_category_table . " |
233
|
|
|
WHERE cat_lang = '$lang' |
234
|
|
|
AND cat_id = $cat"; |
235
|
|
|
$result = $this->db->sql_query_limit($sql, 1); |
236
|
|
|
$row = $this->db->sql_fetchrow($result); |
237
|
|
|
$cat_name = $row['cat_name']; |
238
|
|
|
$this->db->sql_freeresult($result); |
239
|
|
|
} |
240
|
|
|
else |
241
|
|
|
{ |
242
|
|
|
$cat_name = $this->language->lang('SC_CATEGORY_DEFAUT'); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
$sql = $this->db->sql_build_query('SELECT', array( |
246
|
|
|
'SELECT' => 'smiley_url, MIN(smiley_id) AS smiley_id, MIN(code) AS code, MIN(smiley_order) AS min_smiley_order, MIN(smiley_width) AS smiley_width, MIN(smiley_height) AS smiley_height, MIN(emotion) AS emotion, MIN(display_on_shout) AS display_on_shout', |
247
|
|
|
'FROM' => array(SMILIES_TABLE => ''), |
248
|
|
|
'WHERE' => "category = $cat", |
249
|
|
|
'GROUP_BY' => 'smiley_url', |
250
|
|
|
'ORDER_BY' => 'min_smiley_order ASC', |
251
|
|
|
)); |
252
|
|
|
$result = $this->db->sql_query($sql); |
253
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
254
|
|
|
{ |
255
|
|
|
$smilies[$i] = array( |
256
|
|
|
'nb' => $i, |
257
|
|
|
'code' => $row['code'], |
258
|
|
|
'emotion' => $row['emotion'], |
259
|
|
|
'width' => $row['smiley_width'], |
260
|
|
|
'height' => $row['smiley_height'], |
261
|
|
|
'image' => $row['smiley_url'], |
262
|
|
|
); |
263
|
|
|
$i++; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
$empty_row = ($i == 0) ? $this->language->lang('SC_SMILIES_EMPTY_CATEGORY') : false; |
267
|
|
|
|
268
|
|
|
$event['content'] = array_merge($event['content'], array( |
269
|
|
|
'in_cat' => true, |
270
|
|
|
'cat' => $cat, |
271
|
|
|
'total' => $i, |
272
|
|
|
'smilies' => $smilies, |
273
|
|
|
'emptyRow' => $empty_row, |
274
|
|
|
'title' => $this->language->lang('SC_CATEGORY_IN', $cat_name), |
275
|
|
|
)); |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
public function adm_add_cat() |
280
|
|
|
{ |
281
|
|
|
$max = $this->get_max_order(); |
282
|
|
|
$sql = 'SELECT lang_local_name, lang_iso |
283
|
|
|
FROM ' . LANG_TABLE . " |
284
|
|
|
ORDER BY lang_id ASC"; |
285
|
|
|
$result = $this->db->sql_query($sql); |
286
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
287
|
|
|
{ |
288
|
|
|
$this->template->assign_block_vars('categories', array( |
289
|
|
|
'CAT_LANG' => $row['lang_local_name'], |
290
|
|
|
'CAT_ISO' => $row['lang_iso'], |
291
|
|
|
'CAT_ORDER' => $max + 1, |
292
|
|
|
)); |
293
|
|
|
} |
294
|
|
|
$this->db->sql_freeresult($result); |
295
|
|
|
|
296
|
|
|
$this->template->assign_vars(array( |
297
|
|
|
'CAT_ORDER' => $max + 1, |
298
|
|
|
)); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
public function adm_edit_cat($id) |
302
|
|
|
{ |
303
|
|
|
// Get total lang id... |
304
|
|
|
$sql = 'SELECT COUNT(lang_id) as total |
305
|
|
|
FROM ' . LANG_TABLE; |
306
|
|
|
$result = $this->db->sql_query($sql); |
307
|
|
|
$total = (int) $this->db->sql_fetchfield('total', $result); |
308
|
|
|
$this->db->sql_freeresult($result); |
309
|
|
|
|
310
|
|
|
$title = ''; |
311
|
|
|
$i = $cat_order = $cat_id = 0; |
312
|
|
|
$list_id = []; |
313
|
|
|
$sql = $this->db->sql_build_query('SELECT', array( |
314
|
|
|
'SELECT' => 'l.*, c.*', |
315
|
|
|
'FROM' => array(LANG_TABLE => 'l'), |
316
|
|
|
'LEFT_JOIN' => array( |
317
|
|
|
array( |
318
|
|
|
'FROM' => array($this->smilies_category_table => 'c'), |
319
|
|
|
'ON' => 'c.cat_lang = l.lang_iso', |
320
|
|
|
), |
321
|
|
|
), |
322
|
|
|
'WHERE' => "cat_id = $id", |
323
|
|
|
'ORDER_BY' => 'lang_id ASC', |
324
|
|
|
)); |
325
|
|
|
$result = $this->db->sql_query($sql); |
326
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
327
|
|
|
{ |
328
|
|
|
$this->template->assign_block_vars('category_lang', array( |
329
|
|
|
'CAT_LANG' => $row['lang_local_name'], |
330
|
|
|
'CAT_ISO' => $row['lang_iso'], |
331
|
|
|
'CAT_ORDER' => $row['cat_order'], |
332
|
|
|
'CAT_ID' => $row['cat_id'], |
333
|
|
|
'CAT_TRADUCT' => $row['cat_name'], |
334
|
|
|
'CAT_SORT' => 'edit', |
335
|
|
|
)); |
336
|
|
|
$i++; |
337
|
|
|
$list_id[$i] = $row['lang_id']; |
338
|
|
|
$cat_id = $row['cat_id']; |
339
|
|
|
$cat_order = $row['cat_order']; |
340
|
|
|
$title = $row['cat_title']; |
341
|
|
|
} |
342
|
|
|
$this->db->sql_freeresult($result); |
343
|
|
|
|
344
|
|
|
// Add rows for empty langs in this category |
345
|
|
|
if ($i !== $total) |
346
|
|
|
{ |
347
|
|
|
$sql = $this->db->sql_build_query('SELECT', array( |
348
|
|
|
'SELECT' => '*', |
349
|
|
|
'FROM' => array(LANG_TABLE => 'l'), |
350
|
|
|
'WHERE' => $this->db->sql_in_set('lang_id', $list_id, true, true), |
351
|
|
|
)); |
352
|
|
|
$result = $this->db->sql_query($sql); |
353
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
354
|
|
|
{ |
355
|
|
|
$this->template->assign_block_vars('category_lang', array( |
356
|
|
|
'CAT_LANG' => $row['lang_local_name'], |
357
|
|
|
'CAT_ISO' => $row['lang_iso'], |
358
|
|
|
'CAT_ORDER' => $cat_order, |
359
|
|
|
'CAT_ID' => $cat_id, |
360
|
|
|
'CAT_TRADUCT' => '', |
361
|
|
|
'CAT_SORT' => 'create', |
362
|
|
|
)); |
363
|
|
|
} |
364
|
|
|
$this->db->sql_freeresult($result); |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
$this->template->assign_vars(array( |
368
|
|
|
'CAT_ORDER' => $cat_order, |
369
|
|
|
'CAT_TITLE' => $title, |
370
|
|
|
)); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
public function adm_list_cat($u_action) |
374
|
|
|
{ |
375
|
|
|
$i = 1; |
376
|
|
|
$cat = 0; |
377
|
|
|
$empty_row = false; |
378
|
|
|
$max = $this->get_max_order(); |
379
|
|
|
$sql = $this->db->sql_build_query('SELECT', array( |
380
|
|
|
'SELECT' => 'l.lang_iso, l.lang_local_name, c.*', |
381
|
|
|
'FROM' => array(LANG_TABLE => 'l'), |
382
|
|
|
'LEFT_JOIN' => array( |
383
|
|
|
array( |
384
|
|
|
'FROM' => array($this->smilies_category_table => 'c'), |
385
|
|
|
'ON' => 'c.cat_lang = l.lang_iso', |
386
|
|
|
), |
387
|
|
|
), |
388
|
|
|
'ORDER_BY' => 'cat_order ASC, c.cat_lang_id ASC', |
389
|
|
|
)); |
390
|
|
|
$result = $this->db->sql_query($sql); |
391
|
|
|
if ($row = $this->db->sql_fetchrow($result)) |
392
|
|
|
{ |
393
|
|
|
do |
394
|
|
|
{ |
395
|
|
|
$this->template->assign_block_vars('categories', array( |
396
|
|
|
'CAT_NR' => $i, |
397
|
|
|
'CAT_LANG' => $row['lang_local_name'], |
398
|
|
|
'CAT_ISO' => $row['lang_iso'], |
399
|
|
|
'CAT_ID' => $row['cat_id'], |
400
|
|
|
'CAT_ORDER' => $row['cat_order'], |
401
|
|
|
'CAT_TRADUCT' => $row['cat_name'], |
402
|
|
|
'CAT_NB' => $row['cat_nb'], |
403
|
|
|
'ROW' => ($cat !== $row['cat_id']) ? true : false, |
404
|
|
|
'ROW_MAX' => ($row['cat_order'] == $max) ? true : false, |
405
|
|
|
'SPACER_CAT' => $this->language->lang('SC_CATEGORY_IN', $row['cat_title']), |
406
|
|
|
'U_EDIT' => $u_action . '&action=edit&id=' . $row['cat_id'], |
407
|
|
|
'U_DELETE' => $u_action . '&action=delete&id=' . $row['cat_id'], |
408
|
|
|
'U_MOVE_UP' => $u_action . '&action=move_up&id=' . $row['cat_id'] . '&hash=' . generate_link_hash('acp-main_module'), |
409
|
|
|
'U_MOVE_DOWN' => $u_action . '&action=move_down&id=' . $row['cat_id'] . '&hash=' . generate_link_hash('acp-main_module'), |
410
|
|
|
)); |
411
|
|
|
$i++; |
412
|
|
|
$cat = $row['cat_id']; |
413
|
|
|
$empty_row = (!$cat) ? true : false; |
414
|
|
|
} while ($row = $this->db->sql_fetchrow($result)); |
415
|
|
|
} |
416
|
|
|
$this->db->sql_freeresult($result); |
417
|
|
|
|
418
|
|
|
$this->template->assign_vars(array( |
419
|
|
|
'EMPTY_ROW' => $empty_row, |
420
|
|
|
)); |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
public function adm_edit_smiley($id, $u_action, $start) |
424
|
|
|
{ |
425
|
|
|
$lang = $this->user->lang_name; |
426
|
|
|
$sql = $this->db->sql_build_query('SELECT', array( |
427
|
|
|
'SELECT' => 's.*, c.*', |
428
|
|
|
'FROM' => array(SMILIES_TABLE => 's'), |
429
|
|
|
'LEFT_JOIN' => array( |
430
|
|
|
array( |
431
|
|
|
'FROM' => array($this->smilies_category_table => 'c'), |
432
|
|
|
'ON' => "c.cat_id = s.category AND c.cat_lang = '$lang'", |
433
|
|
|
), |
434
|
|
|
), |
435
|
|
|
'WHERE' => "smiley_id = $id", |
436
|
|
|
)); |
437
|
|
|
$result = $this->db->sql_query($sql); |
438
|
|
|
$row = $this->db->sql_fetchrow($result); |
439
|
|
|
|
440
|
|
|
$this->template->assign_vars(array( |
441
|
|
|
'WIDTH' => $row['smiley_width'], |
442
|
|
|
'HEIGHT' => $row['smiley_height'], |
443
|
|
|
'CODE' => $row['code'], |
444
|
|
|
'EMOTION' => $row['emotion'], |
445
|
|
|
'CATEGORY' => $row['cat_name'], |
446
|
|
|
'EX_CAT' => ($row['cat_id']) ? $row['cat_id'] : 0, |
447
|
|
|
'SELECT_CATEGORY' => $this->select_categories($row['cat_id'], true), |
448
|
|
|
'IMG_SRC' => $this->root_path . $this->config['smilies_path'] . '/' . $row['smiley_url'], |
449
|
|
|
'U_MODIFY' => $u_action . '&action=modify&id=' . $row['smiley_id'] . '&start=' . $start, |
450
|
|
|
'U_BACK' => $u_action, |
451
|
|
|
)); |
452
|
|
|
$this->db->sql_freeresult($result); |
453
|
|
|
} |
454
|
|
|
} |
455
|
|
|
|