1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* phpBB Gallery - Core Extension |
4
|
|
|
* |
5
|
|
|
* @package phpbbgallery/core |
6
|
|
|
* @author nickvergessen |
7
|
|
|
* @author satanasov |
8
|
|
|
* @author Leinad4Mind |
9
|
|
|
* @copyright 2014 nickvergessen, 2014- satanasov, 2018- Leinad4Mind |
10
|
|
|
* @license GPL-2.0-only |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace phpbbgallery\core\image; |
14
|
|
|
|
15
|
|
|
class image |
16
|
|
|
{ |
17
|
|
|
/** @var \phpbb\db\driver\driver_interface */ |
|
|
|
|
18
|
|
|
protected $db; |
19
|
|
|
|
20
|
|
|
/** @var \phpbb\user */ |
|
|
|
|
21
|
|
|
protected $user; |
22
|
|
|
|
23
|
|
|
/** @var \phpbb\language\language */ |
|
|
|
|
24
|
|
|
protected $language; |
25
|
|
|
|
26
|
|
|
/** @var \phpbb\template\template */ |
|
|
|
|
27
|
|
|
protected $template; |
28
|
|
|
|
29
|
|
|
/** @var \phpbb\event\dispatcher_interface */ |
|
|
|
|
30
|
|
|
protected $phpbb_dispatcher; |
31
|
|
|
|
32
|
|
|
/** @var \phpbbgallery\core\auth\auth */ |
33
|
|
|
protected $gallery_auth; |
34
|
|
|
|
35
|
|
|
/** @var \phpbbgallery\core\album\album */ |
36
|
|
|
protected $album; |
37
|
|
|
|
38
|
|
|
/** @var \phpbbgallery\core\config */ |
39
|
|
|
protected $gallery_config; |
40
|
|
|
|
41
|
|
|
/** @var \phpbb\controller\helper */ |
|
|
|
|
42
|
|
|
protected $helper; |
43
|
|
|
|
44
|
|
|
/** @var \phpbbgallery\core\url */ |
45
|
|
|
protected $url; |
46
|
|
|
|
47
|
|
|
/** @var \phpbbgallery\core\log */ |
48
|
|
|
protected $gallery_log; |
49
|
|
|
|
50
|
|
|
/** @var \phpbbgallery\core\notification\helper */ |
51
|
|
|
protected $notification_helper; |
52
|
|
|
|
53
|
|
|
/** @var \phpbbgallery\core\cache */ |
54
|
|
|
protected $gallery_cache; |
55
|
|
|
|
56
|
|
|
/** @var \phpbbgallery\core\report */ |
57
|
|
|
protected $gallery_report; |
58
|
|
|
|
59
|
|
|
/** @var \phpbbgallery\core\user */ |
60
|
|
|
protected $gallery_user; |
61
|
|
|
|
62
|
|
|
/** @var \phpbbgallery\core\contest */ |
63
|
|
|
protected $contest; |
64
|
|
|
|
65
|
|
|
/** @var \phpbbgallery\core\file\file */ |
66
|
|
|
protected $file; |
67
|
|
|
|
68
|
|
|
/** @var */ |
69
|
|
|
protected $table_images; |
70
|
|
|
|
71
|
|
|
const IMAGE_SHOW_IP = 128; |
72
|
|
|
const IMAGE_SHOW_RATINGS = 64; |
73
|
|
|
const IMAGE_SHOW_USERNAME = 32; |
74
|
|
|
const IMAGE_SHOW_VIEWS = 16; |
75
|
|
|
const IMAGE_SHOW_TIME = 8; |
76
|
|
|
const IMAGE_SHOW_IMAGENAME = 4; |
77
|
|
|
const IMAGE_SHOW_COMMENTS = 2; |
78
|
|
|
const IMAGE_SHOW_ALBUM = 1; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* construct |
82
|
|
|
* |
83
|
|
|
* @param \phpbb\db\driver\driver_interface $db |
84
|
|
|
* @param \phpbb\user $user |
85
|
|
|
* @param \phpbb\language\language $language |
86
|
|
|
* @param \phpbb\template\template $template |
87
|
|
|
* @param \phpbb\event\dispatcher_interface $phpbb_dispatcher |
88
|
|
|
* @param \phpbbgallery\core\auth\auth $gallery_auth |
89
|
|
|
* @param \phpbbgallery\core\album\album $album |
90
|
|
|
* @param \phpbbgallery\core\config $gallery_config |
91
|
|
|
* @param \phpbb\controller\helper $helper |
92
|
|
|
* @param \phpbbgallery\core\url $url |
93
|
|
|
* @param \phpbbgallery\core\log $gallery_log |
94
|
|
|
* @param \phpbbgallery\core\notification\helper $notification_helper |
95
|
|
|
* @param \phpbbgallery\core\report $report |
96
|
|
|
* @param \phpbbgallery\core\cache $gallery_cache |
97
|
|
|
* @param \phpbbgallery\core\user $gallery_user |
98
|
|
|
* @param \phpbbgallery\core\contest $contest |
99
|
|
|
* @param \phpbbgallery\core\file\file $file |
100
|
|
|
* @param $table_images |
101
|
|
|
*/ |
102
|
96 |
|
public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, \phpbb\language\language $language, |
103
|
|
|
\phpbb\template\template $template, \phpbb\event\dispatcher_interface $phpbb_dispatcher, \phpbbgallery\core\auth\auth $gallery_auth, |
104
|
|
|
\phpbbgallery\core\album\album $album, \phpbbgallery\core\config $gallery_config, \phpbb\controller\helper $helper, |
105
|
|
|
\phpbbgallery\core\url $url, \phpbbgallery\core\log $gallery_log, \phpbbgallery\core\notification\helper $notification_helper, |
106
|
|
|
\phpbbgallery\core\report $report, \phpbbgallery\core\cache $gallery_cache, \phpbbgallery\core\user $gallery_user, |
107
|
|
|
\phpbbgallery\core\contest $contest, \phpbbgallery\core\file\file $file, |
108
|
|
|
$table_images) |
109
|
|
|
{ |
110
|
96 |
|
$this->db = $db; |
111
|
96 |
|
$this->user = $user; |
112
|
96 |
|
$this->language = $language; |
113
|
96 |
|
$this->template = $template; |
114
|
96 |
|
$this->phpbb_dispatcher = $phpbb_dispatcher; |
115
|
96 |
|
$this->gallery_auth = $gallery_auth; |
116
|
96 |
|
$this->album = $album; |
117
|
96 |
|
$this->gallery_config = $gallery_config; |
118
|
96 |
|
$this->helper = $helper; |
119
|
96 |
|
$this->url = $url; |
120
|
96 |
|
$this->gallery_log = $gallery_log; |
121
|
96 |
|
$this->notification_helper = $notification_helper; |
122
|
96 |
|
$this->gallery_cache = $gallery_cache; |
123
|
96 |
|
$this->gallery_report = $report; |
124
|
96 |
|
$this->gallery_user = $gallery_user; |
125
|
96 |
|
$this->contest = $contest; |
126
|
96 |
|
$this->file = $file; |
127
|
96 |
|
$this->table_images = $table_images; |
128
|
96 |
|
} |
129
|
|
|
|
130
|
2 |
|
public function get_new_author_info($username) |
131
|
|
|
{ |
132
|
|
|
// Who is the new uploader? |
133
|
2 |
|
if (!$username) |
134
|
|
|
{ |
135
|
|
|
return false; |
136
|
|
|
} |
137
|
2 |
|
$user_id = 0; |
138
|
2 |
|
if ($username) |
139
|
|
|
{ |
140
|
2 |
|
if (!function_exists('user_get_id_name')) |
141
|
|
|
{ |
142
|
1 |
|
$this->url->_include('functions_user', 'phpbb'); |
143
|
|
|
} |
144
|
2 |
|
user_get_id_name($user_id, $username); |
145
|
|
|
} |
146
|
|
|
|
147
|
2 |
|
if (empty($user_id)) |
|
|
|
|
148
|
|
|
{ |
149
|
1 |
|
return false; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
$sql = 'SELECT username, user_colour, user_id |
153
|
1 |
|
FROM ' . USERS_TABLE . ' |
|
|
|
|
154
|
1 |
|
WHERE user_id = ' . (int) $user_id[0]; |
155
|
1 |
|
$result = $this->db->sql_query($sql); |
156
|
1 |
|
$row = $this->db->sql_fetchrow($result); |
157
|
1 |
|
$this->db->sql_freeresult($result); |
158
|
|
|
|
159
|
1 |
|
return $row; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Delete an image completely. |
164
|
|
|
* |
165
|
|
|
* @param array $images Array with the image_id(s) |
166
|
|
|
* @param array $filenames Array with filenames for the image_ids. If a filename is missing it's queried from the database. |
167
|
|
|
* Format: $image_id => $filename |
168
|
|
|
* @param bool $resync_albums |
169
|
|
|
* @param bool $skip_files If set to true, we won't try to delete the source files. |
170
|
|
|
* @return bool |
171
|
|
|
*/ |
172
|
|
|
public function delete_images($images, $filenames = array(), $resync_albums = true, $skip_files = false) |
173
|
|
|
{ |
174
|
|
|
$phpbb_gallery_contest = $this->contest; |
175
|
|
|
if (empty($images)) |
176
|
|
|
{ |
177
|
|
|
return; |
178
|
|
|
} |
179
|
|
|
if (!$skip_files) |
180
|
|
|
{ |
181
|
|
|
// Delete the files from the disc... |
182
|
|
|
$need_filenames = array(); |
183
|
|
|
foreach ($images as $image) |
184
|
|
|
{ |
185
|
|
|
if (!isset($filenames[$image])) |
186
|
|
|
{ |
187
|
|
|
$need_filenames[] = $image; |
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
$filenames = array_merge($filenames, self::get_filenames($need_filenames)); |
|
|
|
|
191
|
|
|
$this->file->delete($filenames); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Event delete images |
196
|
|
|
* |
197
|
|
|
* @event phpbbgallery.core.image.delete_images |
198
|
|
|
* @var array images array of the image ids we are deleting |
199
|
|
|
* @var array filenames array of the image filenames |
200
|
|
|
* @since 1.2.0 |
201
|
|
|
*/ |
202
|
|
|
$vars = array('images', 'filenames'); |
203
|
|
|
extract($this->phpbb_dispatcher->trigger_event('phpbbgallery.core.image.delete_images', compact($vars))); |
204
|
|
|
|
205
|
|
|
$sql = 'SELECT * |
206
|
|
|
FROM ' . $this->table_images . ' |
207
|
|
|
WHERE ' . $this->db->sql_in_set('image_id', $images); |
208
|
|
|
$result = $this->db->sql_query($sql); |
209
|
|
|
$resync_album_ids = $resync_contests = $targets = array(); |
210
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
211
|
|
|
{ |
212
|
|
|
if ($row['image_contest_rank']) |
213
|
|
|
{ |
214
|
|
|
$resync_contests[] = (int) $row['image_album_id']; |
215
|
|
|
} |
216
|
|
|
$resync_album_ids[] = (int) $row['image_album_id']; |
217
|
|
|
if ($row['image_status'] == (int) \phpbbgallery\core\block::STATUS_UNAPPROVED) |
218
|
|
|
{ |
219
|
|
|
$targets[$row['image_album_id']][$row['image_id']] = $row['image_user_id']; |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
// Let's prepare notifications |
224
|
|
|
if (!empty($targets)) |
225
|
|
|
{ |
226
|
|
|
foreach ($targets as $album => $target) |
227
|
|
|
{ |
228
|
|
|
|
229
|
|
|
$data = array( |
230
|
|
|
'targets' => array((int) current($target)), |
231
|
|
|
'album_id' => $album, |
232
|
|
|
'last_image' => key($target), |
233
|
|
|
); |
234
|
|
|
$this->notification_helper->notify('not_approved', $data); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
$this->db->sql_freeresult($result); |
240
|
|
|
$resync_contests = array_unique($resync_contests); |
241
|
|
|
$resync_album_ids = array_unique($resync_album_ids); |
242
|
|
|
|
243
|
|
|
$sql = 'DELETE FROM ' . $this->table_images . ' |
244
|
|
|
WHERE ' . $this->db->sql_in_set('image_id', $images); |
245
|
|
|
$this->db->sql_query($sql); |
246
|
|
|
|
247
|
|
|
// The images need to be deleted, before we grab the new winners. |
248
|
|
|
$phpbb_gallery_contest->resync_albums($resync_contests); |
249
|
|
|
if ($resync_albums) |
250
|
|
|
{ |
251
|
|
|
foreach ($resync_album_ids as $album_id) |
252
|
|
|
{ |
253
|
|
|
$this->album->update_info($album_id); |
254
|
|
|
} |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
return true; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Get the real filenames, so we can load/delete/edit the image-file. |
262
|
|
|
* |
263
|
|
|
* @param mixed $images Array or integer with the image_id(s) |
264
|
|
|
* @return array Format: $image_id => $filename |
265
|
|
|
*/ |
266
|
4 |
|
public function get_filenames($images) |
267
|
|
|
{ |
268
|
4 |
|
if (empty($images)) |
269
|
|
|
{ |
270
|
|
|
return array(); |
271
|
|
|
} |
272
|
|
|
|
273
|
4 |
|
$filenames = array(); |
274
|
|
|
$sql = 'SELECT image_id, image_filename |
275
|
4 |
|
FROM ' . $this->table_images . ' |
276
|
4 |
|
WHERE ' . $this->db->sql_in_set('image_id', $images); |
277
|
4 |
|
$result = $this->db->sql_query($sql); |
278
|
4 |
|
while ($row = $this->db->sql_fetchrow($result)) |
279
|
|
|
{ |
280
|
3 |
|
$filenames[(int) $row['image_id']] = $row['image_filename']; |
281
|
|
|
} |
282
|
4 |
|
$this->db->sql_freeresult($result); |
283
|
|
|
|
284
|
4 |
|
return $filenames; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Generate link to image |
289
|
|
|
* |
290
|
|
|
* @param string $content what's in the link: image_name, thumbnail, fake_thumbnail, medium or lastimage_icon |
291
|
|
|
* @param string $mode where does the link lead to: highslide, lytebox, lytebox_slide_show, image_page, image, none |
292
|
|
|
* @param int $image_id |
293
|
|
|
* @param string $image_name |
294
|
|
|
* @param int $album_id |
295
|
|
|
* @param bool $is_gif we need to know whether we display a gif, so we can use a better medium-image |
296
|
|
|
* @param bool $count shall the image-link be counted as view? (Set to false from image_page.php to deny double increment) |
297
|
|
|
* @param string $additional_parameters additional parameters for the url, (starting with &) |
298
|
|
|
* @param int $next_image |
299
|
|
|
* @return mixed |
300
|
|
|
*/ |
301
|
6 |
|
public function generate_link($content, $mode, $image_id, $image_name, $album_id, $is_gif = false, $count = true, $additional_parameters = '', $next_image = 0) |
302
|
|
|
{ |
303
|
6 |
|
$image_page_url = $this->helper->route('phpbbgallery_core_image', array('image_id' => (int) $image_id)); |
304
|
|
|
//$image_page_url = $phpbb_ext_gallery_url->append_sid('image_page', "album_id=$album_id&image_id=$image_id{$additional_parameters}"); |
305
|
|
|
//$image_url = $phpbb_ext_gallery_url->append_sid('image', "album_id=$album_id&image_id=$image_id{$additional_parameters}" . ((!$count) ? '&view=no_count' : '')); |
306
|
6 |
|
$image_url = $this->url->show_image($image_id, 'medium'); |
307
|
6 |
|
$thumb_url = $this->url->show_image($image_id, 'mini'); |
308
|
6 |
|
$medium_url = $this->url->show_image($image_id, 'medium'); |
309
|
|
|
//$medium_url = $phpbb_ext_gallery_url->append_sid('image', "mode=medium&album_id=$album_id&image_id=$image_id{$additional_parameters}"); |
310
|
6 |
|
switch ($content) |
311
|
|
|
{ |
312
|
6 |
|
case 'image_name': |
313
|
|
|
$shorten_image_name = $image_name; |
314
|
|
|
$content = '<span style="font-weight: bold; display: inline;">' . $shorten_image_name . '</span>'; |
315
|
|
|
break; |
316
|
6 |
|
case 'image_name_unbold': |
317
|
|
|
$shorten_image_name = $image_name; |
318
|
|
|
$content = $shorten_image_name; |
319
|
|
|
break; |
320
|
6 |
|
case 'thumbnail': |
321
|
6 |
|
$content = '<img src="{U_THUMBNAIL}" alt="{IMAGE_NAME}" title="{IMAGE_NAME}" style="max-width: 100%; max-height: 100%"/>'; |
322
|
6 |
|
$content = str_replace(array('{U_THUMBNAIL}', '{IMAGE_NAME}'), array($thumb_url, $image_name), $content); |
323
|
6 |
|
break; |
324
|
|
|
case 'fake_thumbnail': |
325
|
|
|
$content = '<img src="{U_THUMBNAIL}" alt="{IMAGE_NAME}" title="{IMAGE_NAME}" style="max-width: {FAKE_THUMB_SIZE}px; max-height: {FAKE_THUMB_SIZE}px;" />'; |
326
|
|
|
$content = str_replace(array('{U_THUMBNAIL}', '{IMAGE_NAME}', '{FAKE_THUMB_SIZE}'), array($thumb_url, $image_name, $this->gallery_config->get('mini_thumbnail_size')), $content); |
327
|
|
|
break; |
328
|
|
|
case 'medium': |
329
|
|
|
$content = '<img src="{U_MEDIUM}" alt="{IMAGE_NAME}" title="{IMAGE_NAME}" class="postimage" />'; |
330
|
|
|
$content = str_replace(array('{U_MEDIUM}', '{IMAGE_NAME}'), array($medium_url, $image_name), $content); |
331
|
|
|
//cheat for animated/transparent gif |
332
|
|
|
if ($is_gif) |
333
|
|
|
{ |
334
|
|
|
$content = '<img src="{U_MEDIUM}" alt="{IMAGE_NAME}" title="{IMAGE_NAME}" style="max-width: {MEDIUM_WIDTH_SIZE}px; max-height: {MEDIUM_HEIGHT_SIZE}px;" />'; |
335
|
|
|
$content = str_replace(array('{U_MEDIUM}', '{IMAGE_NAME}', '{MEDIUM_HEIGHT_SIZE}', '{MEDIUM_WIDTH_SIZE}'), array($image_url, $image_name, $this->gallery_config->get('medium_height'), $this->gallery_config->get('medium_width')), $content); |
336
|
|
|
} |
337
|
|
|
break; |
338
|
|
|
case 'lastimage_icon': |
339
|
|
|
$content = $this->user->img('icon_topic_latest', 'VIEW_LATEST_IMAGE'); |
340
|
|
|
break; |
341
|
|
|
} |
342
|
|
|
|
343
|
6 |
|
$url = $image_page_url; |
344
|
|
|
|
345
|
6 |
|
switch ($mode) |
346
|
|
|
{ |
347
|
6 |
|
case 'image_page': |
348
|
6 |
|
$tpl = '<a href="{IMAGE_URL}" title="{IMAGE_NAME}" style="display: inline;">{CONTENT}</a>'; |
349
|
6 |
|
break; |
350
|
|
|
case 'image_page_next': |
351
|
|
|
$tpl = '<a href="{IMAGE_URL}" title="{IMAGE_NAME}" class="right-box right">{CONTENT}</a>'; |
352
|
|
|
break; |
353
|
|
|
case 'image_page_prev': |
354
|
|
|
$tpl = '<a href="{IMAGE_URL}" title="{IMAGE_NAME}" class="left-box left">{CONTENT}</a>'; |
355
|
|
|
break; |
356
|
|
|
case 'image': |
357
|
|
|
$url = $image_url; |
358
|
|
|
$tpl = '<a href="{IMAGE_URL}" title="{IMAGE_NAME}">{CONTENT}</a>'; |
359
|
|
|
break; |
360
|
|
|
case 'none': |
361
|
|
|
$tpl = '{CONTENT}'; |
362
|
|
|
break; |
363
|
|
|
case 'next': |
364
|
|
|
if ($next_image) |
365
|
|
|
{ |
366
|
|
|
$url = $this->url->append_sid('image_page', "album_id=$album_id&image_id=$next_image{$additional_parameters}"); |
367
|
|
|
$tpl = '<a href="{IMAGE_URL}" title="{IMAGE_NAME}">{CONTENT}</a>'; |
368
|
|
|
} |
369
|
|
|
else |
370
|
|
|
{ |
371
|
|
|
$tpl = '{CONTENT}'; |
372
|
|
|
} |
373
|
|
|
break; |
374
|
|
|
default: |
375
|
|
|
$url = $image_url; |
376
|
|
|
|
377
|
|
|
$tpl = '{CONTENT}'; |
378
|
|
|
|
379
|
|
|
/** |
380
|
|
|
* Event generate link |
381
|
|
|
* |
382
|
|
|
* @event phpbbgallery.core.image.generate_link |
383
|
|
|
* @var string mode type of link |
384
|
|
|
* @var string tpl html to be outputted |
385
|
|
|
* @since 1.2.0 |
386
|
|
|
*/ |
387
|
|
|
$vars = array('mode', 'tpl'); |
388
|
|
|
extract($this->phpbb_dispatcher->trigger_event('phpbbgallery.core.image.generate_link', compact($vars)));//@todo: Correctly identify the event |
389
|
|
|
break; |
390
|
|
|
} |
391
|
|
|
|
392
|
6 |
|
return str_replace(array('{IMAGE_URL}', '{IMAGE_NAME}', '{CONTENT}'), array($url, $image_name, $content), $tpl); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* Handle user- & total image_counter |
397
|
|
|
* |
398
|
|
|
* @param array $image_id_ary array with the image_ids which changed their status |
399
|
|
|
* @param bool $add are we adding or removing the images |
400
|
|
|
* @param bool $readd is it possible that there are images which aren't really changed |
401
|
|
|
*/ |
402
|
|
|
public function handle_counter($image_id_ary, $add, $readd = false) |
403
|
|
|
{ |
404
|
|
|
if (empty($image_id_ary)) |
405
|
|
|
{ |
406
|
|
|
return; |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
$num_images = $num_comments = 0; |
|
|
|
|
410
|
|
|
$sql = 'SELECT SUM(image_comments) as comments |
411
|
|
|
FROM ' . $this->table_images .' |
412
|
|
|
WHERE image_status ' . (($readd) ? '=' : '<>') . ' ' . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . ' |
413
|
|
|
AND ' . $this->db->sql_in_set('image_id', $image_id_ary) . ' |
414
|
|
|
GROUP BY image_user_id'; |
415
|
|
|
$result = $this->db->sql_query($sql); |
416
|
|
|
$num_comments = $this->db->sql_fetchfield('comments'); |
417
|
|
|
$this->db->sql_freeresult($result); |
418
|
|
|
|
419
|
|
|
$sql = 'SELECT COUNT(image_id) images, image_user_id |
420
|
|
|
FROM ' . $this->table_images .' |
421
|
|
|
WHERE image_status ' . (($readd) ? '=' : '<>') . ' ' . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . ' |
422
|
|
|
AND ' . $this->db->sql_in_set('image_id', $image_id_ary) . ' |
423
|
|
|
GROUP BY image_user_id'; |
424
|
|
|
$result = $this->db->sql_query($sql); |
425
|
|
|
|
426
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
427
|
|
|
{ |
428
|
|
|
$sql_ary = array( |
|
|
|
|
429
|
|
|
'user_id' => (int) $row['image_user_id'], |
430
|
|
|
'user_images' => (int) $row['images'], |
431
|
|
|
); |
432
|
|
|
//@todo: phpbb_gallery_hookup::add_image($row['image_user_id'], (($add) ? $row['images'] : 0 - $row['images'])); |
433
|
|
|
|
434
|
|
|
$num_images = $num_images + $row['images']; |
435
|
|
|
|
436
|
|
|
$this->gallery_user->set_user_id((int) $row['image_user_id'], false); |
437
|
|
|
$this->gallery_user->update_images((($add) ? $row['images'] : 0 - $row['images'])); |
438
|
|
|
} |
439
|
|
|
$this->db->sql_freeresult($result); |
440
|
|
|
|
441
|
|
|
if ($add) |
442
|
|
|
{ |
443
|
|
|
$this->gallery_config->inc('num_images', (int) $num_images); |
444
|
|
|
$this->gallery_config->inc('num_comments', (int) $num_comments); |
445
|
|
|
} |
446
|
|
|
else |
447
|
|
|
{ |
448
|
|
|
$this->gallery_config->dec('num_images', (int) $num_images); |
449
|
|
|
$this->gallery_config->dec('num_comments', (int) $num_comments); |
450
|
|
|
} |
451
|
|
|
} |
452
|
|
|
|
453
|
2 |
|
public function get_image_data($image_id) |
454
|
|
|
{ |
455
|
2 |
|
if (empty($image_id)) |
456
|
|
|
{ |
457
|
|
|
return; |
458
|
|
|
} |
459
|
|
|
|
460
|
2 |
|
$sql = 'SELECT * FROM ' . $this->table_images .' WHERE image_id = ' . (int) $image_id; |
461
|
2 |
|
$result = $this->db->sql_query($sql); |
462
|
2 |
|
$row = $this->db->sql_fetchrow($result); |
463
|
2 |
|
$this->db->sql_freeresult($result); |
464
|
|
|
|
465
|
2 |
|
if ($row) |
466
|
|
|
{ |
467
|
2 |
|
return $row; |
468
|
|
|
} |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
/** |
472
|
|
|
* Approve image |
473
|
|
|
* @param (array) $image_id_ary The image ID array to be approved |
474
|
|
|
* @param (int) $album_id The album image is approved to (just save some queries for log) |
475
|
|
|
* return 0 on success |
476
|
|
|
*/ |
477
|
|
|
public function approve_images($image_id_ary, $album_id) |
478
|
|
|
{ |
479
|
|
|
$sql = 'SELECT image_id, image_name, image_user_id |
480
|
|
|
FROM ' . $this->table_images . ' |
481
|
|
|
WHERE image_status = 0 |
482
|
|
|
AND ' . $this->db->sql_in_set('image_id', $image_id_ary); |
483
|
|
|
$result = $this->db->sql_query($sql); |
484
|
|
|
$targets = array(); |
485
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
486
|
|
|
{ |
487
|
|
|
$this->gallery_log->add_log('moderator', 'approve', $album_id, $row['image_id'], array('LOG_GALLERY_APPROVED', $row['image_name'])); |
488
|
|
|
$targets[] = $row['image_user_id']; |
489
|
|
|
$last_img = $row['image_id']; |
490
|
|
|
} |
491
|
|
|
$this->db->sql_freeresult($result); |
492
|
|
|
if (!empty($targets)) |
493
|
|
|
{ |
494
|
|
|
$data = array( |
495
|
|
|
'targets' => $targets, |
496
|
|
|
'album_id' => $album_id, |
497
|
|
|
'last_image' => $last_img, |
|
|
|
|
498
|
|
|
); |
499
|
|
|
$this->notification_helper->notify('approved', $data); |
500
|
|
|
$this->notification_helper->new_image($data); |
501
|
|
|
} |
502
|
|
|
$this->handle_counter($image_id_ary, true, true); |
503
|
|
|
|
504
|
|
|
$sql = 'UPDATE ' . $this->table_images . ' |
505
|
|
|
SET image_status = ' . (int) \phpbbgallery\core\block::STATUS_APPROVED . ' |
506
|
|
|
WHERE image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN . ' |
507
|
|
|
AND ' . $this->db->sql_in_set('image_id', $image_id_ary); |
508
|
|
|
$this->db->sql_query($sql); |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
/** |
512
|
|
|
* UnApprove image |
513
|
|
|
* @param (array) $image_id_ary The image ID array to be unapproved |
514
|
|
|
* @param (int) $album_id The album image is approved to (just save some queries for log) |
515
|
|
|
*/ |
516
|
|
|
public function unapprove_images($image_id_ary, $album_id) |
517
|
|
|
{ |
518
|
|
|
self::handle_counter($image_id_ary, false); |
|
|
|
|
519
|
|
|
|
520
|
|
|
$sql = 'UPDATE ' . $this->table_images .' |
521
|
|
|
SET image_status = ' . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . ' |
522
|
|
|
WHERE image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN . ' |
523
|
|
|
AND ' . $this->db->sql_in_set('image_id', $image_id_ary); |
524
|
|
|
$this->db->sql_query($sql); |
525
|
|
|
|
526
|
|
|
$sql = 'SELECT image_id, image_name |
527
|
|
|
FROM ' . $this->table_images .' |
528
|
|
|
WHERE image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN . ' |
529
|
|
|
AND ' . $this->db->sql_in_set('image_id', $image_id_ary); |
530
|
|
|
$result = $this->db->sql_query($sql); |
531
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
532
|
|
|
{ |
533
|
|
|
$this->gallery_log->add_log('moderator', 'unapprove', $album_id, $row['image_id'], array('LOG_GALLERY_UNAPPROVED', $row['image_name'])); |
534
|
|
|
} |
535
|
|
|
$this->db->sql_freeresult($result); |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
/** |
539
|
|
|
* Move image |
540
|
|
|
* @param (int) $image_id The image that we want to move_uploaded_file |
541
|
|
|
* @param $image_id_ary |
542
|
|
|
* @param $album_id |
543
|
|
|
* @internal param $ (int) $album_id The album we want to move image to |
544
|
|
|
*/ |
545
|
|
|
public function move_image($image_id_ary, $album_id) |
546
|
|
|
{ |
547
|
|
|
$target_data = $this->album->get_info($album_id); |
548
|
|
|
|
549
|
|
|
// Store images to cache (so we can log them) |
550
|
|
|
$image_cache = $this->gallery_cache->get_images($image_id_ary); |
551
|
|
|
//TO DO - Contests |
552
|
|
|
$sql = 'UPDATE ' . $this->table_images . ' |
553
|
|
|
SET image_album_id = ' . (int) $album_id . ' |
554
|
|
|
WHERE ' . $this->db->sql_in_set('image_id', $image_id_ary); |
555
|
|
|
$this->db->sql_query($sql); |
556
|
|
|
|
557
|
|
|
$this->gallery_report->move_images($image_id_ary, $album_id); |
558
|
|
|
|
559
|
|
|
foreach ($image_id_ary as $image) |
560
|
|
|
{ |
561
|
|
|
$this->gallery_log->add_log('moderator', 'move', 0, $image, array('LOG_GALLERY_MOVED', $image_cache[$image]['image_name'], $target_data['album_name'])); |
562
|
|
|
} |
563
|
|
|
$this->gallery_cache->destroy_images(); |
564
|
|
|
//You will need to take care for album sync for the target and source |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
/** |
568
|
|
|
* Lock images |
569
|
|
|
* @param (array) $image_id_ary Array of images we want to lock |
570
|
|
|
* @param (int) $album_id Album id, so we can log the action |
571
|
|
|
*/ |
572
|
|
|
public function lock_images($image_id_ary, $album_id) |
573
|
|
|
{ |
574
|
|
|
self::handle_counter($image_id_ary, false); |
|
|
|
|
575
|
|
|
|
576
|
|
|
$sql = 'UPDATE ' . $this->table_images . ' |
577
|
|
|
SET image_status = ' . (int) \phpbbgallery\core\block::STATUS_LOCKED . ' |
578
|
|
|
WHERE image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN . ' |
579
|
|
|
AND ' . $this->db->sql_in_set('image_id', $image_id_ary); |
580
|
|
|
$this->db->sql_query($sql); |
581
|
|
|
|
582
|
|
|
$sql = 'SELECT image_id, image_name |
583
|
|
|
FROM ' . $this->table_images . ' |
584
|
|
|
WHERE image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN . ' |
585
|
|
|
AND ' . $this->db->sql_in_set('image_id', $image_id_ary); |
586
|
|
|
$result = $this->db->sql_query($sql); |
587
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
588
|
|
|
{ |
589
|
|
|
$this->gallery_log->add_log('moderator', 'lock', $album_id, $row['image_id'], array('LOG_GALLERY_LOCKED', $row['image_name'])); |
590
|
|
|
} |
591
|
|
|
$this->db->sql_freeresult($result); |
592
|
|
|
} |
593
|
|
|
|
594
|
|
|
/** |
595
|
|
|
* Get last image id |
596
|
|
|
* Return (int) image_id |
597
|
|
|
**/ |
598
|
3 |
|
public function get_last_image() |
599
|
|
|
{ |
600
|
3 |
|
$this->gallery_auth->load_user_permissions($this->user->data['user_id']); |
601
|
3 |
|
$public = $this->album->get_public_albums(); |
602
|
3 |
|
$sql_order = 'image_id DESC'; |
603
|
3 |
|
$sql_limit = 1; |
604
|
|
|
$sql = 'SELECT * |
605
|
3 |
|
FROM ' . $this->table_images . ' |
606
|
3 |
|
WHERE image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN . ' |
607
|
|
|
AND ( |
608
|
|
|
( |
609
|
3 |
|
' . $this->db->sql_in_set('image_album_id', $this->gallery_auth->acl_album_ids('i_view'), false, true) . ' |
610
|
|
|
AND ( |
611
|
3 |
|
image_status <> ' . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . ' |
612
|
3 |
|
OR image_user_id = ' . (int) $this->user->data['user_id'] . ' |
613
|
|
|
) |
614
|
|
|
) |
615
|
3 |
|
OR ' . $this->db->sql_in_set('image_album_id', $this->gallery_auth->acl_album_ids('m_status'), false, true) . ' |
616
|
|
|
) |
617
|
3 |
|
AND ' . $this->db->sql_in_set('image_album_id', $public, true, true) . ' |
618
|
3 |
|
ORDER BY ' . $sql_order; |
619
|
3 |
|
$result = $this->db->sql_query_limit($sql, $sql_limit); |
620
|
|
|
|
621
|
3 |
|
$row = $this->db->sql_fetchrow($result); |
622
|
|
|
|
623
|
3 |
|
$this->db->sql_freeresult($result); |
624
|
|
|
|
625
|
3 |
|
return $row; |
626
|
|
|
} |
627
|
67 |
|
public function assign_block($image_block_name, $image_data, $display_option = 0, $thumbnail_link = 'image_page', $imagename_link = 'image_page') |
628
|
|
|
{ |
629
|
|
|
// Now let's get display options |
630
|
67 |
|
$show_ip = ($display_option & self::IMAGE_SHOW_IP) !== 0; |
631
|
67 |
|
$show_ratings = ($display_option & self::IMAGE_SHOW_RATINGS) !== 0; |
632
|
67 |
|
$show_username = ($display_option & self::IMAGE_SHOW_USERNAME) !== 0; |
633
|
67 |
|
$show_views = ($display_option & self::IMAGE_SHOW_VIEWS) !== 0; |
634
|
67 |
|
$show_time = ($display_option & self::IMAGE_SHOW_TIME) !== 0; |
635
|
67 |
|
$show_imagename = ($display_option & self::IMAGE_SHOW_IMAGENAME) !== 0; |
636
|
67 |
|
$show_comments = ($display_option & self::IMAGE_SHOW_COMMENTS) !== 0; |
637
|
67 |
|
$show_album = ($display_option & self::IMAGE_SHOW_ALBUM) !== 0; |
638
|
|
|
|
639
|
67 |
|
switch ($thumbnail_link) |
640
|
|
|
{ |
641
|
67 |
|
case 'image_page': |
642
|
63 |
|
$action = $this->helper->route('phpbbgallery_core_image', array('image_id' => (int) $image_data['image_id'])); |
643
|
63 |
|
break; |
644
|
4 |
|
case 'image': |
645
|
2 |
|
$action = $this->helper->route('phpbbgallery_core_image_file_source', array('image_id' => (int) $image_data['image_id'])); |
646
|
2 |
|
break; |
647
|
|
|
default: |
648
|
2 |
|
$action = false; |
649
|
2 |
|
break; |
650
|
|
|
} |
651
|
|
|
|
652
|
67 |
|
switch ($imagename_link) |
653
|
|
|
{ |
654
|
67 |
|
case 'image_page': |
655
|
63 |
|
$action_image = $this->helper->route('phpbbgallery_core_image', array('image_id' => (int) $image_data['image_id'])); |
656
|
63 |
|
break; |
657
|
4 |
|
case 'image': |
658
|
2 |
|
$action_image = $this->helper->route('phpbbgallery_core_image_file_source', array('image_id' => (int) $image_data['image_id'])); |
659
|
2 |
|
break; |
660
|
|
|
default: |
661
|
2 |
|
$action_image = false; |
662
|
2 |
|
break; |
663
|
|
|
} |
664
|
|
|
|
665
|
67 |
|
$this->template->assign_block_vars($image_block_name, array( |
666
|
67 |
|
'IMAGE_ID' => $image_data['image_id'], |
667
|
67 |
|
'U_IMAGE' => $show_imagename ? $action_image : false, |
668
|
67 |
|
'UC_IMAGE_NAME' => $show_imagename ? $image_data['image_name'] : false, |
669
|
67 |
|
'U_ALBUM' => $show_album ? $this->helper->route('phpbbgallery_core_album', array('album_id' => (int) $image_data['album_id'])) : false, |
670
|
67 |
|
'ALBUM_NAME' => $show_album ? $image_data['album_name'] : false, |
671
|
67 |
|
'IMAGE_VIEWS' => $show_views ? $image_data['image_view_count'] : -1, |
672
|
|
|
//'UC_THUMBNAIL' => 'self::generate_link('thumbnail', $phpbb_ext_gallery->config->get('link_thumbnail'), $image_data['image_id'], $image_data['image_name'], $image_data['image_album_id']), |
673
|
67 |
|
'UC_THUMBNAIL' => $this->helper->route('phpbbgallery_core_image_file_mini', array('image_id' => (int) $image_data['image_id'])), |
674
|
67 |
|
'UC_THUMBNAIL_ACTION' => $action, |
675
|
67 |
|
'S_UNAPPROVED' => ($this->gallery_auth->acl_check('m_status', $image_data['image_album_id'], $image_data['album_user_id']) && ($image_data['image_status'] == (int) \phpbbgallery\core\block::STATUS_UNAPPROVED)) ? true : false, |
676
|
67 |
|
'S_LOCKED' => ($image_data['image_status'] == (int) \phpbbgallery\core\block::STATUS_LOCKED) ? true : false, |
677
|
67 |
|
'S_REPORTED' => ($this->gallery_auth->acl_check('m_report', $image_data['image_album_id'], $image_data['album_user_id']) && $image_data['image_reported']) ? true : false, |
678
|
67 |
|
'POSTER' => $show_username ? get_username_string('full', $image_data['image_user_id'], $image_data['image_username'], $image_data['image_user_colour']) : false, |
|
|
|
|
679
|
67 |
|
'TIME' => $show_time ? $this->user->format_date($image_data['image_time']) : false, |
680
|
|
|
|
681
|
67 |
|
'S_RATINGS' => ($this->gallery_config->get('allow_rates') == 1 && $show_ratings) ? ($image_data['image_rates'] > 0 ? $image_data['image_rate_avg'] / 100 : $this->language->lang('NOT_RATED')) : false, |
682
|
67 |
|
'U_RATINGS' => $this->helper->route('phpbbgallery_core_image', array('image_id' => (int) $image_data['image_id'])) . '#rating', |
683
|
67 |
|
'L_COMMENTS' => ($image_data['image_comments'] == 1) ? $this->language->lang('COMMENT') : $this->language->lang('COMMENTS'), |
684
|
67 |
|
'S_COMMENTS' => $show_comments ? (($this->gallery_config->get('allow_comments') && $this->gallery_auth->acl_check('c_read', $image_data['image_album_id'], $image_data['album_user_id'])) ? (($image_data['image_comments']) ? $image_data['image_comments'] : $this->language->lang('NO_COMMENTS')) : '') : false, |
685
|
67 |
|
'U_COMMENTS' => $this->helper->route('phpbbgallery_core_image', array('image_id' => (int) $image_data['image_id'])) . '#comments', |
686
|
67 |
|
'U_USER_IP' => $show_ip && $this->gallery_auth->acl_check('m_status', $image_data['image_album_id'], $image_data['album_user_id']) ? $image_data['image_user_ip'] : false, |
687
|
|
|
|
688
|
67 |
|
'S_IMAGE_REPORTED' => $image_data['image_reported'], |
689
|
67 |
|
'U_IMAGE_REPORTED' => '',//($image_data['image_reported']) ? $phpbb_ext_gallery->url->append_sid('mcp', "mode=report_details&album_id={$image_data['image_album_id']}&option_id=" . $image_data['image_reported']) : '', |
690
|
67 |
|
'S_STATUS_APPROVED' => ($image_data['image_status'] == (int) \phpbbgallery\core\block::STATUS_APPROVED) ? true : false, |
691
|
67 |
|
'S_STATUS_UNAPPROVED' => ($image_data['image_status'] == (int) \phpbbgallery\core\block::STATUS_UNAPPROVED) ? true : false, |
692
|
67 |
|
'S_STATUS_UNAPPROVED_ACTION' => ($this->gallery_auth->acl_check('m_status', $image_data['image_album_id'], $image_data['album_user_id']) && $image_data['image_status'] == (int) \phpbbgallery\core\block::STATUS_UNAPPROVED) ? $this->helper->route('phpbbgallery_core_moderate_image_approve', array('image_id' => (int) $image_data['image_id'])) : '', |
693
|
67 |
|
'S_STATUS_LOCKED' => ($image_data['image_status'] == (int) \phpbbgallery\core\block::STATUS_LOCKED) ? true : false, |
694
|
|
|
|
695
|
67 |
|
'U_REPORT' => ($this->gallery_auth->acl_check('m_report', $image_data['image_album_id'], $image_data['album_user_id']) && $image_data['image_reported']) ? '123'/*$this->url->append_sid('mcp', "mode=report_details&album_id={$image_data['image_album_id']}&option_id=" . $image_data['image_reported'])*/ : '', |
696
|
67 |
|
'U_STATUS' => '',//($this->auth->acl_check('m_status', $image_data['image_album_id'], $album_user_id)) ? $phpbb_ext_gallery->url->append_sid('mcp', "mode=queue_details&album_id={$image_data['image_album_id']}&option_id=" . $image_data['image_id']) : '', |
697
|
67 |
|
'L_STATUS' => ($image_data['image_status'] == (int) \phpbbgallery\core\block::STATUS_UNAPPROVED) ? $this->language->lang('APPROVE_IMAGE') : (($image_data['image_status'] == (int) \phpbbgallery\core\block::STATUS_APPROVED) ? $this->language->lang('CHANGE_IMAGE_STATUS') : $this->language->lang('UNLOCK_IMAGE')), |
698
|
|
|
)); |
699
|
67 |
|
} |
700
|
|
|
} |
701
|
|
|
|
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