1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* phpBB Gallery - Core Extension |
4
|
|
|
* |
5
|
|
|
* @package phpbbgallery/core |
6
|
|
|
* @author nickvergessen |
7
|
|
|
* @author satanasov |
8
|
|
|
* @author Leinad4Mind |
9
|
|
|
* @copyright 2007-2012 nickvergessen, 2014- satanasov, 2018- Leinad4Mind |
10
|
|
|
* @license GPL-2.0-only |
11
|
|
|
* |
12
|
|
|
* mostly borrowed from phpBB3 |
13
|
|
|
* @author: phpBB Group |
14
|
|
|
* @location: includes/acp/acp_forums.php |
15
|
|
|
* |
16
|
|
|
* Note: There are several code parts commented out, for example the album/forum_password. |
17
|
|
|
* I didn't remove them, to have it easier when I implement this feature one day. I hope it's okay. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @ignore |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace phpbbgallery\core\album; |
25
|
|
|
|
26
|
|
|
class manage |
27
|
|
|
{ |
28
|
|
|
public $user_id = 0; |
29
|
|
|
|
30
|
|
|
public $parent_id = 0; |
31
|
|
|
|
32
|
|
|
private $u_action = ''; |
33
|
|
|
|
34
|
|
|
/** @var \phpbb\user */ |
|
|
|
|
35
|
|
|
protected $user; |
36
|
|
|
|
37
|
|
|
/** @var \phpbb\language\language */ |
|
|
|
|
38
|
|
|
protected $language; |
39
|
|
|
|
40
|
|
|
/** @var \phpbb\request\request */ |
|
|
|
|
41
|
|
|
protected $request; |
42
|
|
|
|
43
|
|
|
/** @var \phpbb\db\driver\driver_interface */ |
|
|
|
|
44
|
|
|
protected $db; |
45
|
|
|
|
46
|
|
|
/** @var \phpbb\event\dispatcher */ |
|
|
|
|
47
|
|
|
protected $dispatcher; |
48
|
|
|
|
49
|
|
|
/** @var \phpbbgallery\core\auth\auth */ |
50
|
|
|
protected $gallery_auth; |
51
|
|
|
|
52
|
|
|
/** @var \phpbbgallery\core\album\album */ |
53
|
|
|
protected $gallery_album; |
54
|
|
|
|
55
|
|
|
/** @var \phpbbgallery\core\album\display */ |
56
|
|
|
protected $gallery_display; |
57
|
|
|
|
58
|
|
|
/** @var \phpbbgallery\core\image\image */ |
59
|
|
|
protected $gallery_image; |
60
|
|
|
|
61
|
|
|
/** @var \phpbbgallery\core\cache */ |
62
|
|
|
protected $gallery_cache; |
63
|
|
|
|
64
|
|
|
/** @var \phpbbgallery\core\user */ |
65
|
|
|
protected $gallery_user; |
66
|
|
|
|
67
|
|
|
/** @var \phpbbgallery\core\config */ |
68
|
|
|
protected $gallery_config; |
69
|
|
|
|
70
|
|
|
/** @var \phpbbgallery\core\contest */ |
71
|
|
|
protected $gallery_contest; |
72
|
|
|
|
73
|
|
|
/** @var \phpbbgallery\core\report */ |
74
|
|
|
protected $gallery_report; |
75
|
|
|
|
76
|
|
|
/** @var \phpbbgallery\core\log */ |
77
|
|
|
protected $gallery_log; |
78
|
|
|
|
79
|
|
|
/** @var \phpbbgallery\core\notification */ |
80
|
|
|
protected $gallery_notification; |
81
|
|
|
|
82
|
|
|
/** @var string */ |
83
|
|
|
protected $albums_table; |
84
|
|
|
|
85
|
|
|
/** @var string */ |
86
|
|
|
protected $images_table; |
87
|
|
|
|
88
|
|
|
/** @var string */ |
89
|
|
|
protected $comments_table; |
90
|
|
|
|
91
|
|
|
/** @var string */ |
92
|
|
|
protected $permissions_table; |
93
|
|
|
|
94
|
|
|
/** @var string */ |
95
|
|
|
protected $moderators_table; |
96
|
|
|
|
97
|
|
|
/** @var string */ |
98
|
|
|
protected $contests_table; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* manage constructor. |
102
|
|
|
* @param \phpbb\user $user |
103
|
|
|
* @param \phpbb\request\request $request |
104
|
|
|
* @param \phpbb\db\driver\driver_interface $db |
105
|
|
|
* @param \phpbb\event\dispatcher $dispatcher |
106
|
|
|
* @param \phpbbgallery\core\auth\auth $gallery_auth |
107
|
|
|
* @param album $gallery_album |
108
|
|
|
* @param display $gallery_display |
109
|
|
|
* @param \phpbbgallery\core\image\image $gallery_image |
110
|
|
|
* @param \phpbbgallery\core\cache $gallery_cache |
111
|
|
|
* @param \phpbbgallery\core\user $gallery_user |
112
|
|
|
* @param \phpbbgallery\core\config $gallery_config |
113
|
|
|
* @param \phpbbgallery\core\contest $gallery_contest |
114
|
|
|
* @param \phpbbgallery\core\report $gallery_report |
115
|
|
|
* @param \phpbbgallery\core\log $gallery_log |
116
|
|
|
* @param \phpbbgallery\core\notification $gallery_notification |
117
|
|
|
* @param $albums_table |
118
|
|
|
* @param $images_table |
119
|
|
|
* @param $comments_table |
120
|
|
|
* @param $permissions_table |
121
|
|
|
* @param $moderators_table |
122
|
|
|
* @param $contests_table |
123
|
|
|
*/ |
124
|
|
|
public function __construct(\phpbb\user $user, \phpbb\language\language $language, |
125
|
|
|
\phpbb\request\request $request, \phpbb\db\driver\driver_interface $db, |
126
|
|
|
\phpbb\event\dispatcher $dispatcher, |
127
|
|
|
\phpbbgallery\core\auth\auth $gallery_auth, \phpbbgallery\core\album\album $gallery_album, |
128
|
|
|
\phpbbgallery\core\album\display $gallery_display, \phpbbgallery\core\image\image $gallery_image, |
129
|
|
|
\phpbbgallery\core\cache $gallery_cache, \phpbbgallery\core\user $gallery_user, |
130
|
|
|
\phpbbgallery\core\config $gallery_config, |
131
|
|
|
\phpbbgallery\core\contest $gallery_contest, \phpbbgallery\core\report $gallery_report, |
132
|
|
|
\phpbbgallery\core\log $gallery_log, \phpbbgallery\core\notification $gallery_notification, |
133
|
|
|
$albums_table, $images_table, $comments_table, $permissions_table, $moderators_table, $contests_table) |
134
|
|
|
{ |
135
|
|
|
$this->user = $user; |
136
|
|
|
$this->language = $language; |
137
|
|
|
$this->request = $request; |
138
|
|
|
$this->db = $db; |
139
|
|
|
$this->dispatcher = $dispatcher; |
140
|
|
|
$this->gallery_auth = $gallery_auth; |
141
|
|
|
$this->gallery_album = $gallery_album; |
142
|
|
|
$this->gallery_display = $gallery_display; |
143
|
|
|
$this->gallery_image = $gallery_image; |
144
|
|
|
$this->gallery_cache = $gallery_cache; |
145
|
|
|
$this->gallery_user = $gallery_user; |
146
|
|
|
$this->gallery_config = $gallery_config; |
147
|
|
|
$this->gallery_contest = $gallery_contest; |
148
|
|
|
$this->gallery_report = $gallery_report; |
149
|
|
|
$this->gallery_log = $gallery_log; |
150
|
|
|
$this->gallery_notification = $gallery_notification; |
151
|
|
|
$this->albums_table = $albums_table; |
152
|
|
|
$this->images_table = $images_table; |
153
|
|
|
$this->comments_table = $comments_table; |
154
|
|
|
$this->permissions_table = $permissions_table; |
155
|
|
|
$this->moderators_table = $moderators_table; |
156
|
|
|
$this->contests_table = $contests_table; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function set_user($user_id) |
160
|
|
|
{ |
161
|
|
|
$this->user_id = (int) $user_id; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
public function set_parent($parent_id) |
165
|
|
|
{ |
166
|
|
|
$this->parent_id = (int) $parent_id; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function set_u_action($action) |
170
|
|
|
{ |
171
|
|
|
$this->u_action = $action; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Generate back link for acp pages |
176
|
|
|
* @param $u_action |
177
|
|
|
* @return string |
178
|
|
|
*/ |
179
|
|
|
public function back_link($u_action) |
180
|
|
|
{ |
181
|
|
|
return '<br /><br /><a href="' . $u_action . '">« ' . $this->language->lang('BACK_TO_PREV') . '</a>'; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Update album data |
186
|
|
|
* |
187
|
|
|
* borrowed from phpBB3 |
188
|
|
|
* @author: phpBB Group |
189
|
|
|
* @function: update_forum_data |
190
|
|
|
* @param $album_data |
191
|
|
|
* @param $contest_data |
192
|
|
|
* @return array |
193
|
|
|
*/ |
194
|
|
|
public function update_album_data(&$album_data, &$contest_data) |
195
|
|
|
{ |
196
|
|
|
$errors = array(); |
197
|
|
|
|
198
|
|
|
if (!$album_data['album_name']) |
199
|
|
|
{ |
200
|
|
|
$errors[] = $this->language->lang('ALBUM_NAME_EMPTY'); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
if (utf8_strlen($album_data['album_desc']) > 4000) |
|
|
|
|
204
|
|
|
{ |
205
|
|
|
$errors[] = $this->language->lang('ALBUM_DESC_TOO_LONG'); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/*if ($album_data['album_password'] || $album_data['album_password_confirm']) |
209
|
|
|
{ |
210
|
|
|
if ($album_data['album_password'] != $album_data['album_password_confirm']) |
211
|
|
|
{ |
212
|
|
|
$album_data['album_password'] = $album_data['album_password_confirm'] = ''; |
213
|
|
|
$errors[] = $user->lang['ALBUM_PASSWORD_MISMATCH']; |
214
|
|
|
} |
215
|
|
|
}*/ |
216
|
|
|
// Validate the contest timestamps: |
217
|
|
|
if ($album_data['album_type'] == (int) \phpbbgallery\core\block::TYPE_CONTEST) |
218
|
|
|
{ |
219
|
|
|
if ($this->user->data['user_timezone'] == '') |
220
|
|
|
{ |
221
|
|
|
$timezone = 'UTC'; |
|
|
|
|
222
|
|
|
} |
223
|
|
|
else |
224
|
|
|
{ |
225
|
|
|
$timezone = $this->user->data['user_timezone']; |
226
|
|
|
} |
227
|
|
|
//$timezone = ($this->user->data['user_timezone'] == '' ? $this->user->data['user_timezone'] : 'UTC'); |
228
|
|
|
$time = $this->user->create_datetime(); |
229
|
|
|
|
230
|
|
|
$start_date_error = $date_error = false; |
231
|
|
|
if (!preg_match('#(\\d{4})-(\\d{1,2})-(\\d{1,2}) (\\d{1,2}):(\\d{2})#', $contest_data['contest_start'], $m)) |
232
|
|
|
{ |
233
|
|
|
$errors[] = sprintf($this->language->lang('CONTEST_START_INVALID'), $contest_data['contest_start']); |
234
|
|
|
$start_date_error = true; |
235
|
|
|
} |
236
|
|
|
else |
237
|
|
|
{ |
238
|
|
|
$contest_data['contest_start'] = gmmktime((int) $m[4], (int) $m[5], 0, (int) $m[2], (int) $m[3], (int) $m[1]) - $time->getOffset();// - $offset; |
239
|
|
|
} |
240
|
|
|
if (!preg_match('#(\\d{4})-(\\d{1,2})-(\\d{1,2}) (\\d{1,2}):(\\d{2})#', $contest_data['contest_rating'], $m)) |
241
|
|
|
{ |
242
|
|
|
$errors[] = sprintf($this->language->lang('CONTEST_RATING_INVALID'), $contest_data['contest_rating']); |
243
|
|
|
$date_error = true; |
244
|
|
|
} |
245
|
|
|
else if (!$start_date_error) |
246
|
|
|
{ |
247
|
|
|
$contest_data['contest_rating'] = gmmktime($m[4], $m[5], 0, $m[2], $m[3], $m[1]) - $contest_data['contest_start'] - $time->getOffset();//- $offset; |
248
|
|
|
} |
249
|
|
|
if (!preg_match('#(\\d{4})-(\\d{1,2})-(\\d{1,2}) (\\d{1,2}):(\\d{2})#', $contest_data['contest_end'], $m)) |
250
|
|
|
{ |
251
|
|
|
$errors[] = sprintf($this->language->lang('CONTEST_END_INVALID'), $contest_data['contest_end']); |
252
|
|
|
$date_error = true; |
253
|
|
|
} |
254
|
|
|
else if (!$start_date_error) |
255
|
|
|
{ |
256
|
|
|
$contest_data['contest_end'] = gmmktime($m[4], $m[5], 0, $m[2], $m[3], $m[1]) - $contest_data['contest_start'] - $time->getOffset();//- $offset; |
257
|
|
|
} |
258
|
|
|
if (!$start_date_error && !$date_error) |
259
|
|
|
{ |
260
|
|
|
if ($contest_data['contest_end'] < $contest_data['contest_rating']) |
261
|
|
|
{ |
262
|
|
|
$errors[] = $this->language->lang('CONTEST_END_BEFORE_RATING'); |
263
|
|
|
} |
264
|
|
|
if ($contest_data['contest_rating'] < 0) |
265
|
|
|
{ |
266
|
|
|
$errors[] = $this->language->lang('CONTEST_RATING_BEFORE_START'); |
267
|
|
|
} |
268
|
|
|
if ($contest_data['contest_end'] < 0) |
269
|
|
|
{ |
270
|
|
|
$errors[] = $this->language->lang('CONTEST_END_BEFORE_START'); |
271
|
|
|
} |
272
|
|
|
} |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
// Unset data that are not database fields |
276
|
|
|
$album_data_sql = $album_data; |
277
|
|
|
/* |
278
|
|
|
unset($album_data_sql['album_password_confirm']); |
279
|
|
|
*/ |
280
|
|
|
|
281
|
|
|
// What are we going to do tonight Brain? The same thing we do every night, |
282
|
|
|
// try to take over the world ... or decide whether to continue update |
283
|
|
|
// and if so, whether it's a new album/cat/contest or an existing one |
284
|
|
|
if (sizeof($errors)) |
285
|
|
|
{ |
286
|
|
|
return $errors; |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/* |
290
|
|
|
// As we don't know the old password, it's kinda tricky to detect changes |
291
|
|
|
if ($album_data_sql['album_password_unset']) |
292
|
|
|
{ |
293
|
|
|
$albumdata_sql['album_password'] = ''; |
294
|
|
|
} |
295
|
|
|
else if (empty($album_data_sql['album_password'])) |
296
|
|
|
{ |
297
|
|
|
unset($album_data_sql['album_password']); |
298
|
|
|
} |
299
|
|
|
else |
300
|
|
|
{ |
301
|
|
|
$album_data_sql['album_password'] = phpbb_hash($album_data_sql['album_password']); |
302
|
|
|
} |
303
|
|
|
unset($album_data_sql['album_password_unset']); |
304
|
|
|
*/ |
305
|
|
|
|
306
|
|
|
if (!isset($album_data_sql['album_id'])) |
307
|
|
|
{ |
308
|
|
|
// no album_id means we're creating a new album |
309
|
|
|
unset($album_data_sql['type_action']); |
310
|
|
|
$add_on_top = $this->request->variable('add_on_top', 0); |
311
|
|
|
|
312
|
|
|
if ($album_data_sql['parent_id']) |
313
|
|
|
{ |
314
|
|
|
$sql = 'SELECT left_id, right_id, album_type |
315
|
|
|
FROM ' . $this->albums_table . ' |
316
|
|
|
WHERE album_id = ' . (int) $album_data_sql['parent_id']; |
317
|
|
|
$result = $this->db->sql_query($sql); |
318
|
|
|
$row = $this->db->sql_fetchrow($result); |
319
|
|
|
$this->db->sql_freeresult($result); |
320
|
|
|
|
321
|
|
|
if (!$row) |
322
|
|
|
{ |
323
|
|
|
trigger_error($this->language->lang('PARENT_NOT_EXIST') . $this->back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
if (!$add_on_top) |
327
|
|
|
{ |
328
|
|
|
$sql = 'UPDATE ' . $this->albums_table . ' |
329
|
|
|
SET left_id = left_id + 2, right_id = right_id + 2 |
330
|
|
|
WHERE album_user_id = 0 |
331
|
|
|
AND left_id > ' . (int) $row['right_id']; |
332
|
|
|
$this->db->sql_query($sql); |
333
|
|
|
|
334
|
|
|
$sql = 'UPDATE ' . $this->albums_table . ' |
335
|
|
|
SET right_id = right_id + 2 |
336
|
|
|
WHERE album_user_id = 0 |
337
|
|
|
AND ' . (int) $row['left_id'] . ' BETWEEN left_id AND right_id'; |
338
|
|
|
$this->db->sql_query($sql); |
339
|
|
|
|
340
|
|
|
$album_data_sql['left_id'] = $row['right_id']; |
341
|
|
|
$album_data_sql['right_id'] = $row['right_id'] + 1; |
342
|
|
|
} |
343
|
|
|
else |
344
|
|
|
{ |
345
|
|
|
$sql = 'UPDATE ' . $this->albums_table . ' |
346
|
|
|
SET left_id = left_id + 2, right_id = right_id + 2 |
347
|
|
|
WHERE album_user_id = 0 |
348
|
|
|
AND left_id > ' . (int) $row['left_id']; |
349
|
|
|
$this->db->sql_query($sql); |
350
|
|
|
|
351
|
|
|
$sql = 'UPDATE ' . $this->albums_table . ' |
352
|
|
|
SET right_id = right_id + 2 |
353
|
|
|
WHERE album_user_id = 0 |
354
|
|
|
AND ' . (int) $row['left_id'] . ' BETWEEN left_id AND right_id'; |
355
|
|
|
$this->db->sql_query($sql); |
356
|
|
|
|
357
|
|
|
$album_data_sql['left_id'] = $row['left_id'] + 1; |
358
|
|
|
$album_data_sql['right_id'] = $row['left_id'] + 2; |
359
|
|
|
} |
360
|
|
|
} |
361
|
|
|
else |
362
|
|
|
{ |
363
|
|
|
if (!$add_on_top) |
364
|
|
|
{ |
365
|
|
|
$sql = 'SELECT MAX(right_id) AS right_id |
366
|
|
|
FROM ' . $this->albums_table . ' |
367
|
|
|
WHERE album_user_id = 0'; |
368
|
|
|
$result = $this->db->sql_query($sql); |
369
|
|
|
$row = $this->db->sql_fetchrow($result); |
370
|
|
|
$this->db->sql_freeresult($result); |
371
|
|
|
|
372
|
|
|
$album_data_sql['left_id'] = $row['right_id'] + 1; |
373
|
|
|
$album_data_sql['right_id'] = $row['right_id'] + 2; |
374
|
|
|
} |
375
|
|
|
else |
376
|
|
|
{ |
377
|
|
|
$sql = 'UPDATE ' . $this->albums_table . ' |
378
|
|
|
SET left_id = left_id + 2, right_id = right_id + 2 |
379
|
|
|
WHERE album_user_id = 0'; |
380
|
|
|
$this->db->sql_query($sql); |
381
|
|
|
|
382
|
|
|
$album_data_sql['left_id'] = 1; |
383
|
|
|
$album_data_sql['right_id'] = 2; |
384
|
|
|
} |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
$sql = 'INSERT INTO ' . $this->albums_table . ' ' . $this->db->sql_build_array('INSERT', $album_data_sql); |
388
|
|
|
$this->db->sql_query($sql); |
389
|
|
|
$album_data['album_id'] = (int) $this->db->sql_nextid(); |
390
|
|
|
|
391
|
|
|
// Type is contest, so create it... |
392
|
|
|
if ($album_data['album_type'] == (int) \phpbbgallery\core\block::TYPE_CONTEST) |
393
|
|
|
{ |
394
|
|
|
$contest_data_sql = $contest_data; |
395
|
|
|
$contest_data_sql['contest_album_id'] = $album_data['album_id']; |
396
|
|
|
$contest_data_sql['contest_marked'] = (int) \phpbbgallery\core\block::IN_CONTEST; |
397
|
|
|
|
398
|
|
|
$sql = 'INSERT INTO ' . $this->contests_table . ' ' . $this->db->sql_build_array('INSERT', $contest_data_sql); |
399
|
|
|
$this->db->sql_query($sql); |
400
|
|
|
$album_data['album_contest'] = (int) $this->db->sql_nextid(); |
401
|
|
|
|
402
|
|
|
$sql = 'UPDATE ' . $this->albums_table . ' |
403
|
|
|
SET album_contest = ' . $album_data['album_contest'] . ' |
404
|
|
|
WHERE album_id = ' . (int) $album_data['album_id']; |
405
|
|
|
$this->db->sql_query($sql); |
406
|
|
|
} |
407
|
|
|
$this->gallery_log->add_log('admin', 'add', $album_data['album_id'], 0, array('LOG_ALBUM_ADD', $album_data['album_name'])); |
408
|
|
|
} |
409
|
|
|
else |
410
|
|
|
{ |
411
|
|
|
$row = $this->gallery_album->get_info($album_data_sql['album_id']); |
412
|
|
|
$reset_marked_images = false; |
|
|
|
|
413
|
|
|
|
414
|
|
|
if ($row['album_type'] == (int) \phpbbgallery\core\block::TYPE_CONTEST && $album_data_sql['album_type'] != (int) \phpbbgallery\core\block::TYPE_CONTEST) |
415
|
|
|
{ |
416
|
|
|
// Changing a contest to album? No! |
417
|
|
|
// Changing a contest to category? No! |
418
|
|
|
$errors[] = $this->language->lang('ALBUM_WITH_CONTEST_NO_TYPE_CHANGE'); |
419
|
|
|
return $errors; |
420
|
|
|
} |
421
|
|
|
else if ($row['album_type'] != (int) \phpbbgallery\core\block::TYPE_CONTEST && $album_data_sql['album_type'] == (int) \phpbbgallery\core\block::TYPE_CONTEST) |
422
|
|
|
{ |
423
|
|
|
// Changing a album to contest? No! |
424
|
|
|
// Changing a category to contest? No! |
425
|
|
|
$errors[] = $this->language->lang('ALBUM_NO_TYPE_CHANGE_TO_CONTEST'); |
426
|
|
|
return $errors; |
427
|
|
|
} |
428
|
|
|
else if ($row['album_type'] == (int) \phpbbgallery\core\block::TYPE_CAT && $album_data_sql['album_type'] == (int) \phpbbgallery\core\block::TYPE_UPLOAD) |
429
|
|
|
{ |
430
|
|
|
// Changing a category to a album? Yes! |
431
|
|
|
// Reset the data (you couldn't upload directly in a cat, you must use a album) |
432
|
|
|
$album_data_sql['album_images'] = $album_data_sql['album_images_real'] = $album_data_sql['album_last_image_id'] = $album_data_sql['album_last_user_id'] = $album_data_sql['album_last_image_time'] = $album_data_sql['album_contest'] = 0; |
433
|
|
|
$album_data_sql['album_last_username'] = $album_data_sql['album_last_user_colour'] = $album_data_sql['album_last_image_name'] = ''; |
434
|
|
|
} |
435
|
|
|
else if ($row['album_type'] == (int) \phpbbgallery\core\block::TYPE_UPLOAD && $album_data_sql['album_type'] == (int) \phpbbgallery\core\block::TYPE_CAT) |
436
|
|
|
{ |
437
|
|
|
// Changing a album to a category? Yes! |
438
|
|
|
// we're turning a uploadable album into a non-uploadable album |
439
|
|
|
if ($album_data_sql['type_action'] == 'move') |
440
|
|
|
{ |
441
|
|
|
$to_album_id = $this->request->variable('to_album_id', 0); |
442
|
|
|
|
443
|
|
|
if ($to_album_id) |
444
|
|
|
{ |
445
|
|
|
$errors = $this->move_album_content($album_data_sql['album_id'], $to_album_id); |
446
|
|
|
} |
447
|
|
|
else |
448
|
|
|
{ |
449
|
|
|
return array($this->language->lang('NO_DESTINATION_ALBUM')); |
450
|
|
|
} |
451
|
|
|
} |
452
|
|
|
else if ($album_data_sql['type_action'] == 'delete') |
453
|
|
|
{ |
454
|
|
|
$errors = $this->delete_album_content($album_data_sql['album_id']); |
455
|
|
|
} |
456
|
|
|
else |
457
|
|
|
{ |
458
|
|
|
return array($this->language->lang('NO_ALBUM_ACTION')); |
459
|
|
|
} |
460
|
|
|
} |
461
|
|
|
else if ($row['album_type'] == (int) \phpbbgallery\core\block::TYPE_CONTEST && $album_data_sql['album_type'] == (int) \phpbbgallery\core\block::TYPE_CONTEST) |
462
|
|
|
{ |
463
|
|
|
// Changing a contest to contest? Yes! |
464
|
|
|
// We need to check for the contest_data |
465
|
|
|
$row_contest = $this->gallery_contest->get_contest($album_data['album_id'], 'album'); |
466
|
|
|
$contest_data['contest_id'] = $row_contest['contest_id']; |
467
|
|
|
if ($row_contest['contest_marked'] == (int) \phpbbgallery\core\block::NO_CONTEST) |
468
|
|
|
{ |
469
|
|
|
// If the old contest is finished, but the new one isn't, we need to remark the images! |
470
|
|
|
// If we change it the other way round, the album.php will do the end on the first visit! |
471
|
|
|
if (($row_contest['contest_start'] + $row_contest['contest_end']) > time()) |
472
|
|
|
{ |
473
|
|
|
$contest_data['contest_marked'] = (int) \phpbbgallery\core\block::IN_CONTEST; |
474
|
|
|
$reset_marked_images = true; |
475
|
|
|
} |
476
|
|
|
} |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
if (sizeof($errors)) |
480
|
|
|
{ |
481
|
|
|
return $errors; |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
if ($row['parent_id'] != $album_data_sql['parent_id']) |
485
|
|
|
{ |
486
|
|
|
if ($row['album_id'] != $album_data_sql['parent_id']) |
487
|
|
|
{ |
488
|
|
|
$errors = $this->move_album($album_data_sql['album_id'], $album_data_sql['parent_id']); |
489
|
|
|
} |
490
|
|
|
else |
491
|
|
|
{ |
492
|
|
|
$album_data_sql['parent_id'] = $row['parent_id']; |
493
|
|
|
} |
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
if (sizeof($errors)) |
497
|
|
|
{ |
498
|
|
|
return $errors; |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
unset($album_data_sql['type_action']); |
502
|
|
|
|
503
|
|
|
if ($row['album_name'] != $album_data_sql['album_name']) |
504
|
|
|
{ |
505
|
|
|
// The album name has changed, clear the parents list of all albums (for safety) |
506
|
|
|
$sql = 'UPDATE ' . $this->albums_table . " |
507
|
|
|
SET album_parents = ''"; |
508
|
|
|
$this->db->sql_query($sql); |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
// Setting the album id to the album id is not really received well by some dbs. ;) |
512
|
|
|
$album_id = $album_data_sql['album_id']; |
513
|
|
|
unset($album_data_sql['album_id']); |
514
|
|
|
|
515
|
|
|
$sql = 'UPDATE ' . $this->albums_table . ' |
516
|
|
|
SET ' . $this->db->sql_build_array('UPDATE', $album_data_sql) . ' |
517
|
|
|
WHERE album_id = ' . (int) $album_id; |
518
|
|
|
$this->db->sql_query($sql); |
519
|
|
|
|
520
|
|
|
/* if ($album_data_sql['album_type'] == $phpbb_ext_gallery_core_album::TYPE_CONTEST) |
521
|
|
|
{ |
522
|
|
|
// Setting the contest id to the contest id is not really received well by some dbs. ;) |
523
|
|
|
$contest_id = $contest_data['contest_id']; |
524
|
|
|
unset($contest_data['contest_id']); |
525
|
|
|
|
526
|
|
|
$sql = 'UPDATE ' . $this->contests_table . ' |
527
|
|
|
SET ' . $db->sql_build_array('UPDATE', $contest_data) . ' |
528
|
|
|
WHERE contest_id = ' . (int) $contest_id; |
529
|
|
|
$db->sql_query($sql); |
530
|
|
|
if ($reset_marked_images) |
531
|
|
|
{ |
532
|
|
|
// If the old contest is finished, but the new one isn't, we need to remark the images! |
533
|
|
|
$sql = 'UPDATE ' . $this->images_table . ' |
534
|
|
|
SET image_contest_rank = 0, |
535
|
|
|
image_contest_end = 0, |
536
|
|
|
image_contest = ' . phpbb_ext_gallery_core_image::IN_CONTEST . ' |
537
|
|
|
WHERE image_album_id = ' . (int) $album_id; |
538
|
|
|
$db->sql_query($sql); |
539
|
|
|
} |
540
|
|
|
|
541
|
|
|
// Add it back |
542
|
|
|
$contest_data['contest_id'] = $contest_id; |
543
|
|
|
} |
544
|
|
|
*/ |
545
|
|
|
// Add it back |
546
|
|
|
$album_data['album_id'] = $album_id; |
547
|
|
|
|
548
|
|
|
$this->gallery_log->add_log('admin', 'edit', $album_id, 0, array('LOG_ALBUM_EDIT', $album_data['album_name'])); |
549
|
|
|
} |
550
|
|
|
|
551
|
|
|
return $errors; |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
/** |
555
|
|
|
* Move album |
556
|
|
|
* |
557
|
|
|
* borrowed from phpBB3 |
558
|
|
|
* @author: phpBB Group |
559
|
|
|
* @function: move_forum |
560
|
|
|
* @param $from_id |
561
|
|
|
* @param $to_id |
562
|
|
|
* @return array |
563
|
|
|
*/ |
564
|
|
|
public function move_album($from_id, $to_id) |
565
|
|
|
{ |
566
|
|
|
$to_data = $moved_ids = $errors = array(); |
|
|
|
|
567
|
|
|
|
568
|
|
|
// Get the parent data |
569
|
|
|
if ($to_id > 0) |
570
|
|
|
{ |
571
|
|
|
$to_data = $this->gallery_album->get_info($to_id); |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
$moved_albums = $this->gallery_display->get_branch($this->user_id, $from_id, 'children', 'descending'); |
575
|
|
|
// var_dump($moved_albums); |
576
|
|
|
$from_data = $moved_albums[0]; |
577
|
|
|
|
578
|
|
|
$diff = sizeof($moved_albums) * 2; |
579
|
|
|
|
580
|
|
|
$moved_ids = array(); |
581
|
|
|
for ($i = 0, $end = sizeof($moved_albums); $i < $end; ++$i) |
582
|
|
|
{ |
583
|
|
|
// Can not select child as parent |
584
|
|
|
if ($moved_albums[$i]['album_id'] == $to_id) |
585
|
|
|
{ |
586
|
|
|
return array($this->language->lang('ALBUM_PARENT_INVALID')); |
587
|
|
|
} |
588
|
|
|
$moved_ids[] = $moved_albums[$i]['album_id']; |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
// Resync parents |
592
|
|
|
$sql = 'UPDATE ' . $this->albums_table . " |
593
|
|
|
SET right_id = right_id - $diff, album_parents = '' |
594
|
|
|
WHERE album_user_id = " . (int) $this->user_id . ' |
595
|
|
|
AND left_id < ' . (int) $from_data['right_id'] . " |
596
|
|
|
AND right_id > " . (int) $from_data['right_id']; |
597
|
|
|
$this->db->sql_query($sql); |
598
|
|
|
|
599
|
|
|
// Resync right-hand side of tree |
600
|
|
|
$sql = 'UPDATE ' . $this->albums_table . " |
601
|
|
|
SET left_id = left_id - $diff, right_id = right_id - $diff, album_parents = '' |
602
|
|
|
WHERE album_user_id = " . (int) $this->user_id . ' |
603
|
|
|
AND left_id > ' . (int) $from_data['right_id']; |
604
|
|
|
$this->db->sql_query($sql); |
605
|
|
|
|
606
|
|
|
if ($to_id > 0) |
607
|
|
|
{ |
608
|
|
|
// Retrieve $to_data again, it may have been changed... |
609
|
|
|
$to_data = $this->gallery_album->get_info($to_id); |
610
|
|
|
|
611
|
|
|
// Resync new parents |
612
|
|
|
$sql = 'UPDATE ' . $this->albums_table . " |
613
|
|
|
SET right_id = right_id + $diff, album_parents = '' |
614
|
|
|
WHERE album_user_id = " . (int) $this->user_id . ' |
615
|
|
|
AND ' . (int) $to_data['right_id'] . ' BETWEEN left_id AND right_id |
616
|
|
|
AND ' . $this->db->sql_in_set('album_id', $moved_ids, true); |
617
|
|
|
$this->db->sql_query($sql); |
618
|
|
|
|
619
|
|
|
// Resync the right-hand side of the tree |
620
|
|
|
$sql = 'UPDATE ' . $this->albums_table . ' |
621
|
|
|
SET left_id = left_id + ' . (int) $diff . ', right_id = right_id + ' . (int) $diff . ', album_parents = \'\' |
622
|
|
|
WHERE album_user_id = ' . (int) $this->user_id . ' |
623
|
|
|
AND left_id > ' . (int) $to_data['right_id'] . ' |
624
|
|
|
AND ' . $this->db->sql_in_set('album_id', $moved_ids, true); |
625
|
|
|
$this->db->sql_query($sql); |
626
|
|
|
|
627
|
|
|
// Resync moved branch |
628
|
|
|
$to_data['right_id'] += $diff; |
629
|
|
|
|
630
|
|
|
if ($to_data['right_id'] > $from_data['right_id']) |
631
|
|
|
{ |
632
|
|
|
$diff = '+ ' . ($to_data['right_id'] - $from_data['right_id'] - 1); |
633
|
|
|
} |
634
|
|
|
else |
635
|
|
|
{ |
636
|
|
|
$diff = '- ' . abs($to_data['right_id'] - $from_data['right_id'] - 1); |
637
|
|
|
} |
638
|
|
|
} |
639
|
|
|
else |
640
|
|
|
{ |
641
|
|
|
$sql = 'SELECT MAX(right_id) AS right_id |
642
|
|
|
FROM ' . $this->albums_table . ' |
643
|
|
|
WHERE album_user_id = ' . (int) $this->user_id . ' |
644
|
|
|
AND ' . $this->db->sql_in_set('album_id', $moved_ids, true); |
645
|
|
|
$result = $this->db->sql_query($sql); |
646
|
|
|
$row = $this->db->sql_fetchrow($result); |
647
|
|
|
$this->db->sql_freeresult($result); |
648
|
|
|
|
649
|
|
|
$diff = '+ ' . ($row['right_id'] - $from_data['left_id'] + 1); |
650
|
|
|
} |
651
|
|
|
|
652
|
|
|
$sql = 'UPDATE ' . $this->albums_table . " |
653
|
|
|
SET left_id = left_id $diff, right_id = right_id $diff, album_parents = '' |
654
|
|
|
WHERE album_user_id = " . (int) $this->user_id . ' |
655
|
|
|
AND ' . $this->db->sql_in_set('album_id', $moved_ids); |
656
|
|
|
$this->db->sql_query($sql); |
657
|
|
|
|
658
|
|
|
return $errors; |
659
|
|
|
} |
660
|
|
|
|
661
|
|
|
/** |
662
|
|
|
* Remove complete album |
663
|
|
|
* |
664
|
|
|
* borrowed from phpBB3 |
665
|
|
|
* @author: phpBB Group |
666
|
|
|
* @function: delete_forum |
667
|
|
|
* @param $album_id |
668
|
|
|
* @param string $action_images |
669
|
|
|
* @param string $action_subalbums |
670
|
|
|
* @param int $images_to_id |
671
|
|
|
* @param int $subalbums_to_id |
672
|
|
|
* @return array |
673
|
|
|
*/ |
674
|
|
|
public function delete_album($album_id, $action_images = 'delete', $action_subalbums = 'delete', $images_to_id = 0, $subalbums_to_id = 0) |
675
|
|
|
{ |
676
|
|
|
$album_data = $this->gallery_album->get_info($album_id); |
677
|
|
|
$errors = array(); |
678
|
|
|
$log_action_images = $log_action_albums = $images_to_name = $subalbums_to_name = ''; |
679
|
|
|
$album_ids = array($album_id); |
680
|
|
|
|
681
|
|
|
if ($action_images == 'delete') |
682
|
|
|
{ |
683
|
|
|
$log_action_images = 'IMAGES'; |
684
|
|
|
$errors = array_merge($errors, $this->delete_album_content($album_id)); |
685
|
|
|
} |
686
|
|
|
else if ($action_images == 'move') |
687
|
|
|
{ |
688
|
|
|
if (!$images_to_id) |
689
|
|
|
{ |
690
|
|
|
$errors[] = $this->language->lang('NO_DESTINATION_ALBUM'); |
691
|
|
|
} |
692
|
|
|
else |
693
|
|
|
{ |
694
|
|
|
$log_action_images = 'MOVE_IMAGES'; |
695
|
|
|
|
696
|
|
|
$sql = 'SELECT album_name |
697
|
|
|
FROM ' . $this->albums_table . ' |
698
|
|
|
WHERE album_id = ' . (int) $images_to_id; |
699
|
|
|
$result = $this->db->sql_query($sql); |
700
|
|
|
$row = $this->db->sql_fetchrow($result); |
701
|
|
|
$this->db->sql_freeresult($result); |
702
|
|
|
|
703
|
|
|
if (!$row) |
704
|
|
|
{ |
705
|
|
|
$errors[] = $this->language->lang('NO_ALBUM'); |
706
|
|
|
} |
707
|
|
|
else |
708
|
|
|
{ |
709
|
|
|
$images_to_name = $row['album_name']; |
710
|
|
|
$errors = array_merge($errors, $this->move_album_content($album_id, $images_to_id)); |
711
|
|
|
} |
712
|
|
|
} |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
if (sizeof($errors)) |
716
|
|
|
{ |
717
|
|
|
return $errors; |
718
|
|
|
} |
719
|
|
|
|
720
|
|
|
if ($action_subalbums == 'delete') |
721
|
|
|
{ |
722
|
|
|
$log_action_albums = 'ALBUMS'; |
723
|
|
|
$rows = $this->gallery_display->get_branch($this->user_id, $album_id, 'children', 'descending', false); |
724
|
|
|
|
725
|
|
|
foreach ($rows as $row) |
726
|
|
|
{ |
727
|
|
|
$album_ids[] = $row['album_id']; |
728
|
|
|
$errors = array_merge($errors, $this->delete_album_content($row['album_id'])); |
729
|
|
|
} |
730
|
|
|
|
731
|
|
|
if (sizeof($errors)) |
732
|
|
|
{ |
733
|
|
|
return $errors; |
734
|
|
|
} |
735
|
|
|
|
736
|
|
|
$diff = sizeof($album_ids) * 2; |
737
|
|
|
|
738
|
|
|
$sql = 'DELETE FROM ' . $this->albums_table . ' |
739
|
|
|
WHERE ' . $this->db->sql_in_set('album_id', $album_ids); |
740
|
|
|
$this->db->sql_query($sql); |
741
|
|
|
} |
742
|
|
|
else if ($action_subalbums == 'move') |
743
|
|
|
{ |
744
|
|
|
if (!$subalbums_to_id) |
745
|
|
|
{ |
746
|
|
|
$errors[] = $this->language->lang('NO_DESTINATION_ALBUM'); |
747
|
|
|
} |
748
|
|
|
else |
749
|
|
|
{ |
750
|
|
|
$log_action_albums = 'MOVE_ALBUMS'; |
751
|
|
|
|
752
|
|
|
$sql = 'SELECT album_name |
753
|
|
|
FROM ' . $this->albums_table . ' |
754
|
|
|
WHERE album_id = ' . (int) $subalbums_to_id; |
755
|
|
|
$result = $this->db->sql_query($sql); |
756
|
|
|
$row = $this->db->sql_fetchrow($result); |
757
|
|
|
$this->db->sql_freeresult($result); |
758
|
|
|
|
759
|
|
|
if (!$row) |
760
|
|
|
{ |
761
|
|
|
$errors[] = $this->language->lang('NO_ALBUM'); |
762
|
|
|
} |
763
|
|
|
else |
764
|
|
|
{ |
765
|
|
|
$subalbums_to_name = $row['album_name']; |
766
|
|
|
|
767
|
|
|
$sql = 'SELECT album_id |
768
|
|
|
FROM ' . $this->albums_table . ' |
769
|
|
|
WHERE parent_id = ' . (int) $album_id; |
770
|
|
|
$result = $this->db->sql_query($sql); |
771
|
|
|
|
772
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
773
|
|
|
{ |
774
|
|
|
$this->move_album($row['album_id'], $subalbums_to_id); |
775
|
|
|
} |
776
|
|
|
$this->db->sql_freeresult($result); |
777
|
|
|
|
778
|
|
|
// Grab new album data for correct tree updating later |
779
|
|
|
$album_data = $this->gallery_album->get_info($album_id); |
780
|
|
|
|
781
|
|
|
$sql = 'UPDATE ' . $this->albums_table . ' |
782
|
|
|
SET parent_id = ' . (int) $subalbums_to_id .' |
783
|
|
|
WHERE parent_id = ' . (int) $album_id . ' |
784
|
|
|
AND album_user_id = ' . (int) $this->user_id; |
785
|
|
|
$this->db->sql_query($sql); |
786
|
|
|
|
787
|
|
|
$diff = 2; |
788
|
|
|
$sql = 'DELETE FROM ' . $this->albums_table . ' |
789
|
|
|
WHERE album_id = ' . (int) $album_id; |
790
|
|
|
$this->db->sql_query($sql); |
791
|
|
|
} |
792
|
|
|
} |
793
|
|
|
|
794
|
|
|
if (sizeof($errors)) |
795
|
|
|
{ |
796
|
|
|
return $errors; |
797
|
|
|
} |
798
|
|
|
} |
799
|
|
|
else |
800
|
|
|
{ |
801
|
|
|
$diff = 2; |
802
|
|
|
$sql = 'DELETE FROM ' . $this->albums_table . ' |
803
|
|
|
WHERE album_id = ' . (int) $album_id; |
804
|
|
|
$this->db->sql_query($sql); |
805
|
|
|
} |
806
|
|
|
|
807
|
|
|
// Resync tree |
808
|
|
|
$sql = 'UPDATE ' . $this->albums_table . ' |
809
|
|
|
SET right_id = right_id - ' . (int) $diff . ' |
810
|
|
|
WHERE left_id < ' . (int) $album_data['right_id'] . ' AND right_id > ' . (int) $album_data['right_id']. ' |
811
|
|
|
AND album_user_id = ' . (int) $this->user_id; |
812
|
|
|
$this->db->sql_query($sql); |
813
|
|
|
|
814
|
|
|
$sql = 'UPDATE ' . $this->albums_table . ' |
815
|
|
|
SET left_id = left_id - ' . (int) $diff . ', right_id = right_id - ' . (int) $diff . ' |
816
|
|
|
WHERE left_id > ' . (int) $album_data['right_id']. ' |
817
|
|
|
AND album_user_id = ' . (int) $this->user_id; |
818
|
|
|
$this->db->sql_query($sql); |
819
|
|
|
|
820
|
|
|
$log_action = implode('_', array($log_action_images, $log_action_albums)); |
821
|
|
|
|
822
|
|
|
/** |
823
|
|
|
* Log what we did |
824
|
|
|
*/ |
825
|
|
|
switch ($log_action) |
826
|
|
|
{ |
827
|
|
|
case 'MOVE_IMAGES_MOVE_ALBUMS': |
828
|
|
|
$this->gallery_log->add_log('admin', 'del', 0, 0, array('LOG_ALBUM_DEL_MOVE_IMAGES_MOVE_ALBUMS', $images_to_name, $subalbums_to_name, $album_data['album_name'])); |
829
|
|
|
break; |
830
|
|
|
|
831
|
|
|
case 'MOVE_IMAGES_ALBUMS': |
832
|
|
|
$this->gallery_log->add_log('admin', 'del', $images_to_id, 0, array('LOG_ALBUM_DEL_MOVE_IMAGES_ALBUMS', $images_to_name, $album_data['album_name'])); |
833
|
|
|
break; |
834
|
|
|
|
835
|
|
|
case 'IMAGES_MOVE_ALBUMS': |
836
|
|
|
$this->gallery_log->add_log('admin', 'del', $subalbums_to_id, 0, array('LOG_ALBUM_DEL_IMAGES_MOVE_ALBUMS', $subalbums_to_name, $album_data['album_name'])); |
837
|
|
|
break; |
838
|
|
|
|
839
|
|
|
case '_MOVE_ALBUMS': |
840
|
|
|
$this->gallery_log->add_log('admin', 'del', $subalbums_to_id, 0, array('LOG_ALBUM_DEL_MOVE_ALBUMS', $subalbums_to_name, $album_data['album_name'])); |
841
|
|
|
break; |
842
|
|
|
|
843
|
|
|
case 'MOVE_IMAGES_': |
844
|
|
|
$this->gallery_log->add_log('admin', 'del', $images_to_id, 0, array('LOG_ALBUM_DEL_MOVE_IMAGES', $images_to_name, $album_data['album_name'])); |
845
|
|
|
break; |
846
|
|
|
|
847
|
|
|
case 'IMAGES_ALBUMS': |
848
|
|
|
$this->gallery_log->add_log('admin', 'del', 0, 0, array('LOG_ALBUM_DEL_IMAGES_ALBUMS', $album_data['album_name'])); |
849
|
|
|
break; |
850
|
|
|
|
851
|
|
|
case '_ALBUMS': |
852
|
|
|
$this->gallery_log->add_log('admin', 'del', 0, 0, array('LOG_ALBUM_DEL_ALBUMS', $album_data['album_name'])); |
853
|
|
|
break; |
854
|
|
|
|
855
|
|
|
case 'IMAGES_': |
856
|
|
|
$this->gallery_log->add_log('admin', 'del', 0, 0, array('LOG_ALBUM_DEL_IMAGES', $album_data['album_name'])); |
857
|
|
|
break; |
858
|
|
|
|
859
|
|
|
default: |
860
|
|
|
$this->gallery_log->add_log('admin', 'del', 0, 0, array('LOG_ALBUM_DEL_ALBUM', $album_data['album_name'])); |
861
|
|
|
break; |
862
|
|
|
} |
863
|
|
|
|
864
|
|
|
$this->gallery_auth->set_user_permissions('all', ''); |
|
|
|
|
865
|
|
|
return $errors; |
866
|
|
|
} |
867
|
|
|
|
868
|
|
|
/** |
869
|
|
|
* Move album content from one to another album |
870
|
|
|
* |
871
|
|
|
* borrowed from phpBB3 |
872
|
|
|
* @author: phpBB Group |
873
|
|
|
* @function: move_forum_content |
874
|
|
|
* @param $from_id |
875
|
|
|
* @param $to_id |
876
|
|
|
* @param bool $sync |
877
|
|
|
* @return array |
878
|
|
|
*/ |
879
|
|
|
public function move_album_content($from_id, $to_id, $sync = true) |
880
|
|
|
{ |
881
|
|
|
// Lucifer TODO - Log to gallery log |
882
|
|
|
//$sql = 'UPDATE ' . LOG_TABLE . " |
883
|
|
|
// SET album_id = $to_id |
884
|
|
|
// WHERE album_id = $from_id |
885
|
|
|
// AND log_type = " . LOG_GALLERY; |
886
|
|
|
//$db->sql_query($sql); |
887
|
|
|
|
888
|
|
|
// Reset contest-information for safety. |
889
|
|
|
$sql = 'UPDATE ' . $this->images_table . ' |
890
|
|
|
SET image_album_id = ' . (int) $to_id . ', |
891
|
|
|
image_contest_rank = 0, |
892
|
|
|
image_contest_end = 0, |
893
|
|
|
image_contest = ' . (int) \phpbbgallery\core\block::NO_CONTEST . ' |
894
|
|
|
WHERE image_album_id = ' . (int) $from_id; |
895
|
|
|
$this->db->sql_query($sql); |
896
|
|
|
|
897
|
|
|
$this->gallery_report->move_album_content($from_id, $to_id); |
898
|
|
|
|
899
|
|
|
$sql = 'DELETE FROM ' . $this->contests_table . ' |
900
|
|
|
WHERE contest_album_id = ' . (int) $from_id; |
901
|
|
|
$this->db->sql_query($sql); |
902
|
|
|
|
903
|
|
|
$sql = 'DELETE FROM ' . $this->permissions_table . ' |
904
|
|
|
WHERE perm_album_id = ' . (int) $from_id; |
905
|
|
|
$this->db->sql_query($sql); |
906
|
|
|
|
907
|
|
|
$sql = 'DELETE FROM ' . $this->moderators_table . ' |
908
|
|
|
WHERE album_id = ' . (int) $from_id; |
909
|
|
|
$this->db->sql_query($sql); |
910
|
|
|
|
911
|
|
|
$this->gallery_notification->delete_albums($from_id); |
912
|
|
|
|
913
|
|
|
/** |
914
|
|
|
* Event related to moving album content |
915
|
|
|
* |
916
|
|
|
* @event phpbbgallery.core.album.manage.move_album_content |
917
|
|
|
* @var int from_id Album we are moving from |
918
|
|
|
* @var int to_id Album we are moving to |
919
|
|
|
* @var bool sync Should we sync the albums data |
920
|
|
|
* @since 1.2.0 |
921
|
|
|
*/ |
922
|
|
|
$vars = array('from_id', 'to_id', 'sync'); |
923
|
|
|
extract($this->dispatcher->trigger_event('phpbbgallery.core.album.manage.move_album_content', compact($vars))); |
924
|
|
|
|
925
|
|
|
$this->gallery_cache->destroy_albums(); |
926
|
|
|
|
927
|
|
|
if ($sync) |
928
|
|
|
{ |
929
|
|
|
// Resync counters |
930
|
|
|
$this->gallery_album->update_info($from_id); |
931
|
|
|
$this->gallery_album->update_info($to_id); |
932
|
|
|
} |
933
|
|
|
|
934
|
|
|
return array(); |
935
|
|
|
} |
936
|
|
|
|
937
|
|
|
/** |
938
|
|
|
* Delete album content: |
939
|
|
|
* Deletes all images, comments, rates, image-files, etc. |
940
|
|
|
* @param $album_id |
941
|
|
|
* @return array |
942
|
|
|
*/ |
943
|
|
|
public function delete_album_content($album_id) |
944
|
|
|
{ |
945
|
|
|
$album_id = (int) $album_id; |
946
|
|
|
|
947
|
|
|
// Before we remove anything we make sure we are able to adjust the image counts later. ;) |
948
|
|
|
$sql = 'SELECT image_user_id |
949
|
|
|
FROM ' . $this->images_table . ' |
950
|
|
|
WHERE image_album_id = ' . (int) $album_id . ' |
951
|
|
|
AND image_status <> ' . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . ' |
952
|
|
|
AND image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN; |
953
|
|
|
$result = $this->db->sql_query($sql); |
954
|
|
|
|
955
|
|
|
$image_counts = array(); |
956
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
957
|
|
|
{ |
958
|
|
|
$image_counts[$row['image_user_id']] = (!empty($image_counts[$row['image_user_id']])) ? $image_counts[$row['image_user_id']] + 1 : 1; |
959
|
|
|
} |
960
|
|
|
$this->db->sql_freeresult($result); |
961
|
|
|
|
962
|
|
|
$sql = 'SELECT image_id, image_filename, image_album_id |
963
|
|
|
FROM ' . $this->images_table . ' |
964
|
|
|
WHERE image_album_id = ' . (int) $album_id; |
965
|
|
|
$result = $this->db->sql_query($sql); |
966
|
|
|
|
967
|
|
|
$filenames = $deleted_images = array(); |
968
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
969
|
|
|
{ |
970
|
|
|
$deleted_images[] = $row['image_id']; |
971
|
|
|
$filenames[(int) $row['image_id']] = $row['image_filename']; |
972
|
|
|
} |
973
|
|
|
$this->db->sql_freeresult($result); |
974
|
|
|
|
975
|
|
|
if (!empty($deleted_images)) |
976
|
|
|
{ |
977
|
|
|
$this->gallery_image->delete_images($deleted_images, $filenames); |
978
|
|
|
} |
979
|
|
|
|
980
|
|
|
// Lucifer TODO: Log Gallery deletion from log |
981
|
|
|
//$sql = 'DELETE FROM ' . LOG_TABLE . " |
982
|
|
|
// WHERE album_id = $album_id |
983
|
|
|
// AND log_type = " . LOG_GALLERY; |
984
|
|
|
//$db->sql_query($sql); |
985
|
|
|
|
986
|
|
|
//@todo: merge queries into loop |
987
|
|
|
$sql = 'DELETE FROM ' . $this->permissions_table . ' |
988
|
|
|
WHERE perm_album_id = ' . (int) $album_id; |
989
|
|
|
$this->db->sql_query($sql); |
990
|
|
|
$sql = 'DELETE FROM ' . $this->contests_table . ' |
991
|
|
|
WHERE contest_album_id = ' . (int) $album_id; |
992
|
|
|
$this->db->sql_query($sql); |
993
|
|
|
|
994
|
|
|
$sql = 'DELETE FROM ' . $this->moderators_table . ' |
995
|
|
|
WHERE album_id = ' . (int) $album_id; |
996
|
|
|
$this->db->sql_query($sql); |
997
|
|
|
|
998
|
|
|
$this->gallery_notification->delete_albums($album_id); |
999
|
|
|
|
1000
|
|
|
// Adjust users image counts |
1001
|
|
|
if (!empty($image_counts)) |
1002
|
|
|
{ |
1003
|
|
|
foreach ($image_counts as $image_user_id => $subtract) |
1004
|
|
|
{ |
1005
|
|
|
$this->gallery_user->set_user_id($image_user_id); |
1006
|
|
|
$this->gallery_user->update_images((0 - $subtract)); |
1007
|
|
|
} |
1008
|
|
|
} |
1009
|
|
|
|
1010
|
|
|
// Make sure the overall image & comment count is correct... |
1011
|
|
|
$sql = 'SELECT COUNT(image_id) AS num_images, SUM(image_comments) AS num_comments |
1012
|
|
|
FROM ' . $this->images_table . ' |
1013
|
|
|
WHERE image_status <> ' . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . ' |
1014
|
|
|
AND image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN; |
1015
|
|
|
$result = $this->db->sql_query($sql); |
1016
|
|
|
$row = $this->db->sql_fetchrow($result); |
1017
|
|
|
$this->db->sql_freeresult($result); |
1018
|
|
|
|
1019
|
|
|
$this->gallery_config->set('num_images', $row['num_images']); |
1020
|
|
|
$this->gallery_config->set('num_comments', (int) $row['num_comments']); |
1021
|
|
|
|
1022
|
|
|
/** |
1023
|
|
|
* Event delete album content |
1024
|
|
|
* |
1025
|
|
|
* @event phpbbgallery.core.album.manage.delete_album_content |
1026
|
|
|
* @var int album_id Album we are deleting |
1027
|
|
|
* @since 1.2.0 |
1028
|
|
|
*/ |
1029
|
|
|
$vars = array('album_id'); |
1030
|
|
|
extract($this->dispatcher->trigger_event('phpbbgallery.core.album.manage.delete_album_content', compact($vars))); |
1031
|
|
|
|
1032
|
|
|
$this->gallery_cache->destroy_albums(); |
1033
|
|
|
|
1034
|
|
|
return array(); |
1035
|
|
|
} |
1036
|
|
|
|
1037
|
|
|
/** |
1038
|
|
|
* Move album position by $steps up/down |
1039
|
|
|
* |
1040
|
|
|
* borrowed from phpBB3 |
1041
|
|
|
* @author: phpBB Group |
1042
|
|
|
* @function: move_forum_by |
1043
|
|
|
* @param $album_row |
1044
|
|
|
* @param string $action |
1045
|
|
|
* @param int $steps |
1046
|
|
|
* @return mixed |
1047
|
|
|
*/ |
1048
|
|
|
public function move_album_by($album_row, $action = 'move_up', $steps = 1) |
1049
|
|
|
{ |
1050
|
|
|
/** |
1051
|
|
|
* Fetch all the siblings between the module's current spot |
1052
|
|
|
* and where we want to move it to. If there are less than $steps |
1053
|
|
|
* siblings between the current spot and the target then the |
1054
|
|
|
* module will move as far as possible |
1055
|
|
|
*/ |
1056
|
|
|
$sql = 'SELECT album_id, album_name, left_id, right_id |
1057
|
|
|
FROM ' . $this->albums_table . ' |
1058
|
|
|
WHERE parent_id = ' . (int) $album_row['parent_id'] . ' |
1059
|
|
|
AND album_user_id = ' . (int) $this->user_id . ' |
1060
|
|
|
AND ' . (($action == 'move_up') ? 'right_id < ' . $album_row['right_id'] . ' ORDER BY right_id DESC' : 'left_id > ' . $album_row['left_id'] . ' ORDER BY left_id ASC'); |
1061
|
|
|
$result = $this->db->sql_query_limit($sql, $steps); |
1062
|
|
|
|
1063
|
|
|
$target = array(); |
1064
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
1065
|
|
|
{ |
1066
|
|
|
$target = $row; |
1067
|
|
|
} |
1068
|
|
|
$this->db->sql_freeresult($result); |
1069
|
|
|
|
1070
|
|
|
if (!sizeof($target)) |
1071
|
|
|
{ |
1072
|
|
|
// The album is already on top or bottom |
1073
|
|
|
return false; |
1074
|
|
|
} |
1075
|
|
|
|
1076
|
|
|
/** |
1077
|
|
|
* $left_id and $right_id define the scope of the nodes that are affected by the move. |
1078
|
|
|
* $diff_up and $diff_down are the values to subtract or add to each node's left_id |
1079
|
|
|
* and right_id in order to move them up or down. |
1080
|
|
|
* $move_up_left and $move_up_right define the scope of the nodes that are moving |
1081
|
|
|
* up. Other nodes in the scope of ($left_id, $right_id) are considered to move down. |
1082
|
|
|
*/ |
1083
|
|
|
if ($action == 'move_up') |
1084
|
|
|
{ |
1085
|
|
|
$left_id = $target['left_id']; |
1086
|
|
|
$right_id = $album_row['right_id']; |
1087
|
|
|
|
1088
|
|
|
$diff_up = $album_row['left_id'] - $target['left_id']; |
1089
|
|
|
$diff_down = $album_row['right_id'] + 1 - $album_row['left_id']; |
1090
|
|
|
|
1091
|
|
|
$move_up_left = $album_row['left_id']; |
1092
|
|
|
$move_up_right = $album_row['right_id']; |
1093
|
|
|
} |
1094
|
|
|
else |
1095
|
|
|
{ |
1096
|
|
|
$left_id = $album_row['left_id']; |
1097
|
|
|
$right_id = $target['right_id']; |
1098
|
|
|
|
1099
|
|
|
$diff_up = $album_row['right_id'] + 1 - $album_row['left_id']; |
1100
|
|
|
$diff_down = $target['right_id'] - $album_row['right_id']; |
1101
|
|
|
|
1102
|
|
|
$move_up_left = $album_row['right_id'] + 1; |
1103
|
|
|
$move_up_right = $target['right_id']; |
1104
|
|
|
} |
1105
|
|
|
|
1106
|
|
|
// Now do the dirty job |
1107
|
|
|
$sql = 'UPDATE ' . $this->albums_table . ' |
1108
|
|
|
SET left_id = left_id + CASE |
1109
|
|
|
WHEN left_id BETWEEN ' . (int) $move_up_left . ' AND ' . (int) $move_up_right . ' THEN -' .(int) $diff_up . ' |
1110
|
|
|
ELSE ' .(int) $diff_down . ' |
1111
|
|
|
END, |
1112
|
|
|
right_id = right_id + CASE |
1113
|
|
|
WHEN right_id BETWEEN ' . (int) $move_up_left . ' AND ' . (int) $move_up_right . ' THEN -' . (int) $diff_up . ' |
1114
|
|
|
ELSE ' . (int) $diff_down . ' |
1115
|
|
|
END, |
1116
|
|
|
album_parents = \'\' |
1117
|
|
|
WHERE |
1118
|
|
|
left_id BETWEEN ' . (int) $left_id . ' AND ' . (int) $right_id . ' |
1119
|
|
|
AND right_id BETWEEN ' . (int) $left_id . ' AND ' . (int) $right_id . ' |
1120
|
|
|
AND album_user_id = ' . (int) $this->user_id; |
1121
|
|
|
$this->db->sql_query($sql); |
1122
|
|
|
|
1123
|
|
|
return $target['album_name']; |
1124
|
|
|
} |
1125
|
|
|
} |
1126
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths