|
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
|
|
|
|
|
13
|
|
|
namespace phpbbgallery\core\acp; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @package acp |
|
17
|
|
|
*/ |
|
18
|
|
|
class main_module |
|
19
|
|
|
{ |
|
20
|
|
|
var $u_action; |
|
21
|
|
|
|
|
22
|
|
|
function main($id, $mode) |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
global $user, $language; |
|
25
|
|
|
global $request, $phpbb_container, $gallery_url; |
|
26
|
|
|
|
|
27
|
|
|
$this->language = $phpbb_container->get('language'); |
|
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
$gallery_url = $phpbb_container->get('phpbbgallery.core.url'); |
|
30
|
|
|
|
|
31
|
|
|
$this->language->add_lang(array('gallery_acp', 'gallery'), 'phpbbgallery/core'); |
|
32
|
|
|
$this->tpl_name = 'gallery_main'; |
|
|
|
|
|
|
33
|
|
|
add_form_key('acp_gallery'); |
|
|
|
|
|
|
34
|
|
|
$submode = $request->variable('submode', ''); |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
switch ($mode) |
|
37
|
|
|
{ |
|
38
|
|
|
case 'overview': |
|
39
|
|
|
$title = 'ACP_GALLERY_OVERVIEW'; |
|
40
|
|
|
$this->page_title = $this->language->lang($title); |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
$this->overview(); |
|
43
|
|
|
break; |
|
44
|
|
|
|
|
45
|
|
|
default: |
|
46
|
|
|
trigger_error('NO_MODE', E_USER_ERROR); |
|
47
|
|
|
break; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
function overview() |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
global $auth, $config, $db, $template, $user, $table_prefix, $phpbb_root_path; |
|
54
|
|
|
global $phpbb_container, $request, $gallery_url; |
|
55
|
|
|
|
|
56
|
|
|
$this->language = $phpbb_container->get('language'); |
|
|
|
|
|
|
57
|
|
|
$phpbbgallery_core_file = $phpbb_root_path . 'files/phpbbgallery/core'; |
|
58
|
|
|
$phpbbgallery_core_file_medium = $phpbb_root_path . 'files/phpbbgallery/core/medium'; |
|
59
|
|
|
$phpbbgallery_core_file_mini = $phpbb_root_path . 'files/phpbbgallery/core/mini'; |
|
60
|
|
|
$phpbbgallery_core_file_source = $phpbb_root_path . 'files/phpbbgallery/core/source'; |
|
61
|
|
|
|
|
62
|
|
|
$albums_table = $table_prefix . 'gallery_albums'; |
|
63
|
|
|
$roles_table = $table_prefix . 'gallery_roles'; |
|
|
|
|
|
|
64
|
|
|
$permissions_table = $table_prefix . 'gallery_permissions'; |
|
|
|
|
|
|
65
|
|
|
$modscache_table = $table_prefix . 'gallery_modscache'; |
|
|
|
|
|
|
66
|
|
|
$contests_table = $table_prefix . 'gallery_contests'; |
|
|
|
|
|
|
67
|
|
|
$users_table = $table_prefix . 'gallery_users'; |
|
68
|
|
|
$images_table = $table_prefix . 'gallery_images'; |
|
69
|
|
|
// Init album |
|
70
|
|
|
$phpbb_ext_gallery_core_album = $phpbb_container->get('phpbbgallery.core.album'); |
|
71
|
|
|
|
|
72
|
|
|
// init users |
|
73
|
|
|
$phpbb_gallery_user = $phpbb_container->get('phpbbgallery.core.user'); |
|
74
|
|
|
|
|
75
|
|
|
// init image |
|
76
|
|
|
$phpbb_gallery_image = $phpbb_container->get('phpbbgallery.core.image'); |
|
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
// init config |
|
79
|
|
|
$phpbb_ext_gallery_config = $phpbb_container->get('phpbbgallery.core.config'); |
|
80
|
|
|
|
|
81
|
|
|
$action = $request->variable('action', ''); |
|
82
|
|
|
$id = $request->variable('i', ''); |
|
83
|
|
|
$mode = 'overview'; |
|
84
|
|
|
|
|
85
|
|
|
// before we start let's check if directory structure is OK |
|
86
|
|
|
if (!is_writable($phpbb_root_path . 'files')) |
|
87
|
|
|
{ |
|
88
|
|
|
$template->assign_vars(array( |
|
89
|
|
|
'U_FILE_DIR_STATE' => $this->language->lang('NO_WRITE_ACCESS'), |
|
90
|
|
|
'U_FILE_DIR_STATE_ERROR' => 1, |
|
91
|
|
|
'U_CORE_DIR_STATE' => $this->language->lang('NO_WRITE_ACCESS'), |
|
92
|
|
|
'U_CORE_DIR_STATE_ERROR' => 1, |
|
93
|
|
|
'U_MEDIUM_DIR_STATE' => $this->language->lang('NO_WRITE_ACCESS'), |
|
94
|
|
|
'U_MEDIUM_DIR_STATE_ERROR' => 1, |
|
95
|
|
|
'U_MINI_DIR_STATE' => $this->language->lang('NO_WRITE_ACCESS'), |
|
96
|
|
|
'U_MINI_DIR_STATE_ERROR' => 1, |
|
97
|
|
|
'U_SOURCE_DIR_STATE' => $this->language->lang('NO_WRITE_ACCESS'), |
|
98
|
|
|
'U_SOURCE_DIR_STATE_ERROR' => 1, |
|
99
|
|
|
)); |
|
100
|
|
|
} |
|
101
|
|
|
else |
|
102
|
|
|
{ |
|
103
|
|
|
$template->assign_vars(array( |
|
104
|
|
|
'U_FILE_DIR_STATE' => $this->language->lang('WRITE_ACCESS'), |
|
105
|
|
|
'U_FILE_DIR_STATE_ERROR' => 0, |
|
106
|
|
|
)); |
|
107
|
|
|
if (!file_exists($phpbbgallery_core_file)) |
|
108
|
|
|
{ |
|
109
|
|
|
mkdir($phpbbgallery_core_file, 0755, true); |
|
110
|
|
|
$template->assign_vars(array( |
|
111
|
|
|
'U_CORE_DIR_STATE' => $this->language->lang('DIR_CREATED'), |
|
112
|
|
|
'U_CORE_DIR_STATE_ERROR' => 0, |
|
113
|
|
|
)); |
|
114
|
|
|
} |
|
115
|
|
|
else if (is_writable($phpbbgallery_core_file)) |
|
116
|
|
|
{ |
|
117
|
|
|
$template->assign_vars(array( |
|
118
|
|
|
'U_CORE_DIR_STATE' => $this->language->lang('WRITE_ACCESS'), |
|
119
|
|
|
'U_CORE_DIR_STATE_ERROR' => 0, |
|
120
|
|
|
)); |
|
121
|
|
|
} |
|
122
|
|
|
else |
|
123
|
|
|
{ |
|
124
|
|
|
$template->assign_vars(array( |
|
125
|
|
|
'U_CORE_DIR_STATE' => $this->language->lang('NO_WRITE_ACCESS'), |
|
126
|
|
|
'U_CORE_DIR_STATE_ERROR' => 1, |
|
127
|
|
|
)); |
|
128
|
|
|
} |
|
129
|
|
|
if (!file_exists($phpbbgallery_core_file_medium)) |
|
130
|
|
|
{ |
|
131
|
|
|
mkdir($phpbbgallery_core_file_medium, 0755, true); |
|
132
|
|
|
$template->assign_vars(array( |
|
133
|
|
|
'U_MEDIUM_DIR_STATE' => $this->language->lang('DIR_CREATED'), |
|
134
|
|
|
'U_MEDIUM_DIR_STATE_ERROR' => 0, |
|
135
|
|
|
)); |
|
136
|
|
|
} |
|
137
|
|
|
else if (is_writable($phpbbgallery_core_file_medium)) |
|
138
|
|
|
{ |
|
139
|
|
|
$template->assign_vars(array( |
|
140
|
|
|
'U_MEDIUM_DIR_STATE' => $this->language->lang('WRITE_ACCESS'), |
|
141
|
|
|
'U_MEDIUM_DIR_STATE_ERROR' => 0, |
|
142
|
|
|
)); |
|
143
|
|
|
} |
|
144
|
|
|
else |
|
145
|
|
|
{ |
|
146
|
|
|
$template->assign_vars(array( |
|
147
|
|
|
'U_MEDIUM_DIR_STATE' => $this->language->lang('NO_WRITE_ACCESS'), |
|
148
|
|
|
'U_MEDIUM_DIR_STATE_ERROR' => 1, |
|
149
|
|
|
)); |
|
150
|
|
|
} |
|
151
|
|
|
if (!file_exists($phpbbgallery_core_file_mini)) |
|
152
|
|
|
{ |
|
153
|
|
|
mkdir($phpbbgallery_core_file_mini, 0755, true); |
|
154
|
|
|
$template->assign_vars(array( |
|
155
|
|
|
'U_MINI_DIR_STATE' => $this->language->lang('DIR_CREATED'), |
|
156
|
|
|
'U_MINI_DIR_STATE_ERROR' => 0, |
|
157
|
|
|
)); |
|
158
|
|
|
} |
|
159
|
|
|
else if (is_writable($phpbbgallery_core_file_mini)) |
|
160
|
|
|
{ |
|
161
|
|
|
$template->assign_vars(array( |
|
162
|
|
|
'U_MINI_DIR_STATE' => $this->language->lang('WRITE_ACCESS'), |
|
163
|
|
|
'U_MINI_DIR_STATE_ERROR' => 0, |
|
164
|
|
|
)); |
|
165
|
|
|
} |
|
166
|
|
|
else |
|
167
|
|
|
{ |
|
168
|
|
|
$template->assign_vars(array( |
|
169
|
|
|
'U_MINI_DIR_STATE' => $this->language->lang('NO_WRITE_ACCESS'), |
|
170
|
|
|
'U_MINI_DIR_STATE_ERROR' => 1, |
|
171
|
|
|
)); |
|
172
|
|
|
} |
|
173
|
|
|
if (!file_exists($phpbbgallery_core_file_source)) |
|
174
|
|
|
{ |
|
175
|
|
|
mkdir($phpbbgallery_core_file_source, 0755, true); |
|
176
|
|
|
$template->assign_vars(array( |
|
177
|
|
|
'U_SOURCE_DIR_STATE' => $this->language->lang('DIR_CREATED'), |
|
178
|
|
|
'U_SOURCE_DIR_STATE_ERROR' => 0, |
|
179
|
|
|
)); |
|
180
|
|
|
} |
|
181
|
|
|
else if (is_writable($phpbbgallery_core_file_source)) |
|
182
|
|
|
{ |
|
183
|
|
|
$template->assign_vars(array( |
|
184
|
|
|
'U_SOURCE_DIR_STATE' => $this->language->lang('WRITE_ACCESS'), |
|
185
|
|
|
'U_SOURCE_DIR_STATE_ERROR' => 0, |
|
186
|
|
|
)); |
|
187
|
|
|
} |
|
188
|
|
|
else |
|
189
|
|
|
{ |
|
190
|
|
|
$template->assign_vars(array( |
|
191
|
|
|
'U_SOURCE_DIR_STATE' => $this->language->lang('NO_WRITE_ACCESS'), |
|
192
|
|
|
'U_SOURCE_DIR_STATE_ERROR' => 1, |
|
193
|
|
|
)); |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
if (!confirm_box(true)) |
|
|
|
|
|
|
197
|
|
|
{ |
|
198
|
|
|
$confirm = false; |
|
199
|
|
|
$album_id = 0; |
|
200
|
|
|
switch ($action) |
|
201
|
|
|
{ |
|
202
|
|
|
case 'images': |
|
203
|
|
|
$confirm = true; |
|
204
|
|
|
$confirm_lang = 'RESYNC_IMAGECOUNTS_CONFIRM'; |
|
205
|
|
|
break; |
|
206
|
|
|
case 'personals': |
|
207
|
|
|
$confirm = true; |
|
208
|
|
|
$confirm_lang = 'CONFIRM_OPERATION'; |
|
209
|
|
|
break; |
|
210
|
|
|
case 'stats': |
|
211
|
|
|
$confirm = true; |
|
212
|
|
|
$confirm_lang = 'CONFIRM_OPERATION'; |
|
213
|
|
|
break; |
|
214
|
|
|
case 'last_images': |
|
215
|
|
|
$confirm = true; |
|
216
|
|
|
$confirm_lang = 'CONFIRM_OPERATION'; |
|
217
|
|
|
break; |
|
218
|
|
|
case 'reset_rating': |
|
219
|
|
|
$album_id = $request->variable('reset_album_id', 0); |
|
220
|
|
|
$album_data = $phpbb_ext_gallery_core_album->get_info($album_id); |
|
221
|
|
|
$confirm = true; |
|
222
|
|
|
$confirm_lang = sprintf($this->language->lang('RESET_RATING_CONFIRM'), $album_data['album_name']); |
|
223
|
|
|
break; |
|
224
|
|
|
case 'purge_cache': |
|
225
|
|
|
$confirm = true; |
|
226
|
|
|
$confirm_lang = 'GALLERY_PURGE_CACHE_EXPLAIN'; |
|
227
|
|
|
break; |
|
228
|
|
|
case 'resync_albums_to_cpf': |
|
229
|
|
|
$confirm = true; |
|
230
|
|
|
$confirm_lang = 'GALLERY_RESYNC_ALBUMS_TO_CPF_CONFIRM'; |
|
231
|
|
|
break; |
|
232
|
|
|
case 'create_pega': |
|
233
|
|
|
$confirm = false; |
|
234
|
|
|
if (!$auth->acl_get('a_board')) |
|
235
|
|
|
{ |
|
236
|
|
|
trigger_error($this->language->lang('NO_AUTH_OPERATION') . adm_back_link($this->u_action), E_USER_WARNING); |
|
|
|
|
|
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
$username = $request->variable('username', '', true); |
|
240
|
|
|
$user_id = 0; |
|
241
|
|
|
if ($username) |
|
242
|
|
|
{ |
|
243
|
|
|
if (!function_exists('user_get_id_name')) |
|
244
|
|
|
{ |
|
245
|
|
|
$gallery_url->_include('functions_user', 'phpbb'); |
|
246
|
|
|
} |
|
247
|
|
|
user_get_id_name($user_id, $username); |
|
248
|
|
|
} |
|
249
|
|
|
if (is_array($user_id)) |
|
|
|
|
|
|
250
|
|
|
{ |
|
251
|
|
|
$user_id = (isset($user_id[0])) ? $user_id[0] : 0; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
$sql = 'SELECT username, user_colour, user_id |
|
255
|
|
|
FROM ' . USERS_TABLE . ' |
|
|
|
|
|
|
256
|
|
|
WHERE user_id = ' . (int) $user_id; |
|
257
|
|
|
$result = $db->sql_query($sql); |
|
258
|
|
|
$user_row = $db->sql_fetchrow($result); |
|
259
|
|
|
$db->sql_freeresult($result); |
|
260
|
|
|
if (!$user_row) |
|
261
|
|
|
{ |
|
262
|
|
|
trigger_error($this->language->lang('NO_USER') . adm_back_link($this->u_action), E_USER_WARNING); |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
$image_user = $phpbb_gallery_user->set_user_id($user_row['user_id']); |
|
|
|
|
|
|
266
|
|
|
$album_id = $phpbb_gallery_user->get_data('personal_album_id'); |
|
267
|
|
|
|
|
268
|
|
|
if ($album_id) |
|
269
|
|
|
{ |
|
270
|
|
|
trigger_error($this->language->lang('PEGA_ALREADY_EXISTS', $user_row['username']) . adm_back_link($this->u_action), E_USER_WARNING); |
|
271
|
|
|
} |
|
272
|
|
|
$album_id = $phpbb_ext_gallery_core_album->generate_personal_album($user_row['username'], $user_row['user_id'], $user_row['user_colour'], $phpbb_gallery_user); |
|
273
|
|
|
|
|
274
|
|
|
trigger_error($this->language->lang('PEGA_CREATED', $user_row['username']) . adm_back_link($this->u_action)); |
|
275
|
|
|
break; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
if ($confirm) |
|
279
|
|
|
{ |
|
280
|
|
|
confirm_box(false, (($album_id) ? $confirm_lang : $this->language->lang($confirm_lang)), build_hidden_fields(array( |
|
|
|
|
|
|
281
|
|
|
'i' => $id, |
|
282
|
|
|
'mode' => $mode, |
|
283
|
|
|
'action' => $action, |
|
284
|
|
|
'reset_album_id' => $album_id, |
|
285
|
|
|
))); |
|
286
|
|
|
} |
|
287
|
|
|
} |
|
288
|
|
|
else |
|
289
|
|
|
{ |
|
290
|
|
|
switch ($action) |
|
291
|
|
|
{ |
|
292
|
|
|
case 'images': |
|
293
|
|
|
if (!$auth->acl_get('a_board')) |
|
294
|
|
|
{ |
|
295
|
|
|
trigger_error($this->language->lang('NO_AUTH_OPERATION') . adm_back_link($this->u_action), E_USER_WARNING); |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
$total_images = $total_comments = 0; |
|
299
|
|
|
$phpbb_gallery_user->update_users('all', array('user_images' => 0)); |
|
300
|
|
|
|
|
301
|
|
|
$sql = 'SELECT COUNT(image_id) AS num_images, image_user_id AS user_id, SUM(image_comments) AS num_comments |
|
302
|
|
|
FROM ' . $images_table . ' |
|
303
|
|
|
WHERE image_status <> ' . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . ' |
|
304
|
|
|
AND image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN . ' |
|
305
|
|
|
GROUP BY image_user_id'; |
|
306
|
|
|
$result = $db->sql_query($sql); |
|
307
|
|
|
|
|
308
|
|
|
while ($row = $db->sql_fetchrow($result)) |
|
309
|
|
|
{ |
|
310
|
|
|
$total_images += $row['num_images']; |
|
311
|
|
|
$total_comments += (int) $row['num_comments']; |
|
312
|
|
|
|
|
313
|
|
|
$image_user = $phpbb_container->get('phpbbgallery.core.user'); |
|
314
|
|
|
$image_user->set_user_id($row['user_id'], false); |
|
315
|
|
|
$image_user->update_data(array( |
|
316
|
|
|
'user_images' => $row['num_images'], |
|
317
|
|
|
)); |
|
318
|
|
|
} |
|
319
|
|
|
$db->sql_freeresult($result); |
|
320
|
|
|
|
|
321
|
|
|
$phpbb_ext_gallery_config->set('num_images', $total_images); |
|
322
|
|
|
$phpbb_ext_gallery_config->set('num_comments', $total_comments); |
|
323
|
|
|
trigger_error($this->language->lang('RESYNCED_IMAGECOUNTS') . adm_back_link($this->u_action)); |
|
324
|
|
|
break; |
|
325
|
|
|
|
|
326
|
|
|
case 'personals': |
|
327
|
|
|
if (!$auth->acl_get('a_board')) |
|
328
|
|
|
{ |
|
329
|
|
|
trigger_error($this->language->lang('NO_AUTH_OPERATION') . adm_back_link($this->u_action), E_USER_WARNING); |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
$phpbb_gallery_user->update_users('all', array('personal_album_id' => 0)); |
|
333
|
|
|
|
|
334
|
|
|
$sql = 'SELECT album_id, album_user_id |
|
335
|
|
|
FROM ' . $albums_table . ' |
|
336
|
|
|
WHERE album_user_id <> ' . (int) \phpbbgallery\core\block::PUBLIC_ALBUM . ' |
|
337
|
|
|
AND parent_id = 0 |
|
338
|
|
|
GROUP BY album_user_id, album_id'; |
|
339
|
|
|
$result = $db->sql_query($sql); |
|
340
|
|
|
|
|
341
|
|
|
$number_of_personals = 0; |
|
342
|
|
|
while ($row = $db->sql_fetchrow($result)) |
|
343
|
|
|
{ |
|
344
|
|
|
$image_user = $phpbb_gallery_user->set_user_id($row['album_user_id'], false); |
|
345
|
|
|
$phpbb_gallery_user->update_data(array( |
|
346
|
|
|
'personal_album_id' => $row['album_id'], |
|
347
|
|
|
)); |
|
348
|
|
|
$number_of_personals++; |
|
349
|
|
|
} |
|
350
|
|
|
$db->sql_freeresult($result); |
|
351
|
|
|
$phpbb_ext_gallery_config->set('num_pegas', $number_of_personals); |
|
352
|
|
|
|
|
353
|
|
|
// Update the config for the statistic on the index |
|
354
|
|
|
$sql_array = array( |
|
355
|
|
|
'SELECT' => 'a.album_id, u.user_id, u.username, u.user_colour', |
|
356
|
|
|
'FROM' => array($albums_table => 'a'), |
|
357
|
|
|
|
|
358
|
|
|
'LEFT_JOIN' => array( |
|
359
|
|
|
array( |
|
360
|
|
|
'FROM' => array(USERS_TABLE => 'u'), |
|
361
|
|
|
'ON' => 'u.user_id = a.album_user_id', |
|
362
|
|
|
), |
|
363
|
|
|
), |
|
364
|
|
|
|
|
365
|
|
|
'WHERE' => 'a.album_user_id <> ' . (int) \phpbbgallery\core\block::PUBLIC_ALBUM . ' AND a.parent_id = 0', |
|
366
|
|
|
'ORDER_BY' => 'a.album_id DESC', |
|
367
|
|
|
); |
|
368
|
|
|
$sql = $db->sql_build_query('SELECT', $sql_array); |
|
369
|
|
|
|
|
370
|
|
|
$result = $db->sql_query_limit($sql, 1); |
|
371
|
|
|
$newest_pgallery = $db->sql_fetchrow($result); |
|
372
|
|
|
$db->sql_freeresult($result); |
|
373
|
|
|
|
|
374
|
|
|
$phpbb_ext_gallery_config->set('newest_pega_user_id', $newest_pgallery['user_id']); |
|
375
|
|
|
$phpbb_ext_gallery_config->set('newest_pega_username', $newest_pgallery['username']); |
|
376
|
|
|
$phpbb_ext_gallery_config->set('newest_pega_user_colour', $newest_pgallery['user_colour']); |
|
377
|
|
|
$phpbb_ext_gallery_config->set('newest_pega_album_id', $newest_pgallery['album_id']); |
|
378
|
|
|
|
|
379
|
|
|
trigger_error($this->language->lang('RESYNCED_PERSONALS') . adm_back_link($this->u_action)); |
|
380
|
|
|
break; |
|
381
|
|
|
|
|
382
|
|
|
case 'stats': |
|
383
|
|
|
if (!$auth->acl_get('a_board')) |
|
384
|
|
|
{ |
|
385
|
|
|
trigger_error($this->language->lang('NO_AUTH_OPERATION') . adm_back_link($this->u_action), E_USER_WARNING); |
|
386
|
|
|
} |
|
387
|
|
|
|
|
388
|
|
|
// Hopefully this won't take to long! >> I think we must make it batchwise |
|
389
|
|
|
$sql = 'SELECT image_id, image_filename |
|
390
|
|
|
FROM ' . $images_table . ' |
|
391
|
|
|
WHERE filesize_upload = 0'; |
|
392
|
|
|
$result = $db->sql_query($sql); |
|
393
|
|
|
while ($row = $db->sql_fetchrow($result)) |
|
394
|
|
|
{ |
|
395
|
|
|
$sql_ary = array( |
|
396
|
|
|
'filesize_upload' => @filesize($gallery_url->path('upload') . $row['image_filename']), |
|
397
|
|
|
'filesize_medium' => @filesize($gallery_url->path('medium') . $row['image_filename']), |
|
398
|
|
|
'filesize_cache' => @filesize($gallery_url->path('thumbnail') . $row['image_filename']), |
|
399
|
|
|
); |
|
400
|
|
|
$sql = 'UPDATE ' . $images_table . ' |
|
401
|
|
|
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' |
|
402
|
|
|
WHERE ' . $db->sql_in_set('image_id', $row['image_id']); |
|
403
|
|
|
$db->sql_query($sql); |
|
404
|
|
|
} |
|
405
|
|
|
$db->sql_freeresult($result); |
|
406
|
|
|
|
|
407
|
|
|
redirect($this->u_action); |
|
|
|
|
|
|
408
|
|
|
break; |
|
409
|
|
|
|
|
410
|
|
|
case 'last_images': |
|
411
|
|
|
$sql = 'SELECT album_id |
|
412
|
|
|
FROM ' . $albums_table; |
|
413
|
|
|
$result = $db->sql_query($sql); |
|
414
|
|
|
|
|
415
|
|
|
while ($row = $db->sql_fetchrow($result)) |
|
416
|
|
|
{ |
|
417
|
|
|
// 5 sql's per album, but you don't run this daily ;) |
|
418
|
|
|
$phpbb_ext_gallery_core_album->update_info($row['album_id']); |
|
419
|
|
|
} |
|
420
|
|
|
$db->sql_freeresult($result); |
|
421
|
|
|
trigger_error($this->language->lang('RESYNCED_LAST_IMAGES') . adm_back_link($this->u_action)); |
|
422
|
|
|
break; |
|
423
|
|
|
|
|
424
|
|
|
case 'reset_rating': |
|
425
|
|
|
$album_id = $request->variable('reset_album_id', 0); |
|
426
|
|
|
|
|
427
|
|
|
$image_ids = array(); |
|
428
|
|
|
$sql = 'SELECT image_id |
|
429
|
|
|
FROM ' . $images_table . ' |
|
430
|
|
|
WHERE image_album_id = ' . (int) $album_id; |
|
431
|
|
|
$result = $db->sql_query($sql); |
|
432
|
|
|
while ($row = $db->sql_fetchrow($result)) |
|
433
|
|
|
{ |
|
434
|
|
|
$image_ids[] = $row['image_id']; |
|
435
|
|
|
} |
|
436
|
|
|
$db->sql_freeresult($result); |
|
437
|
|
|
|
|
438
|
|
|
if (!empty($image_ids)) |
|
439
|
|
|
{ |
|
440
|
|
|
phpbb_gallery_image_rating::delete_ratings($image_ids, true); |
|
|
|
|
|
|
441
|
|
|
} |
|
442
|
|
|
|
|
443
|
|
|
trigger_error($this->language->lang('RESET_RATING_COMPLETED') . adm_back_link($this->u_action)); |
|
444
|
|
|
break; |
|
445
|
|
|
|
|
446
|
|
|
case 'purge_cache': |
|
447
|
|
|
if ($user->data['user_type'] != USER_FOUNDER) |
|
|
|
|
|
|
448
|
|
|
{ |
|
449
|
|
|
trigger_error($this->language->lang('NO_AUTH_OPERATION') . adm_back_link($this->u_action), E_USER_WARNING); |
|
450
|
|
|
} |
|
451
|
|
|
|
|
452
|
|
|
$cache_dir = @opendir($gallery_url->path('thumbnail')); |
|
453
|
|
|
while ($cache_file = @readdir($cache_dir)) |
|
|
|
|
|
|
454
|
|
|
{ |
|
455
|
|
|
if (preg_match('/(\.webp$|\.gif$|\.png$|\.jpg|\.jpeg)$/is', $cache_file)) |
|
456
|
|
|
{ |
|
457
|
|
|
@unlink($gallery_url->path('thumbnail') . $cache_file); |
|
|
|
|
|
|
458
|
|
|
} |
|
459
|
|
|
} |
|
460
|
|
|
@closedir($cache_dir); |
|
|
|
|
|
|
461
|
|
|
|
|
462
|
|
|
$medium_dir = @opendir($gallery_url->path('medium')); |
|
463
|
|
|
while ($medium_file = @readdir($medium_dir)) |
|
464
|
|
|
{ |
|
465
|
|
|
if (preg_match('/(\.webp$|\.gif$|\.png$|\.jpg|\.jpeg)$/is', $medium_file)) |
|
466
|
|
|
{ |
|
467
|
|
|
@unlink($gallery_url->path('medium') . $medium_file); |
|
468
|
|
|
} |
|
469
|
|
|
} |
|
470
|
|
|
@closedir($medium_dir); |
|
|
|
|
|
|
471
|
|
|
$upload_dir = @opendir($gallery_url->path('upload')); |
|
472
|
|
|
while ($upload_file = @readdir($upload_dir)) |
|
473
|
|
|
{ |
|
474
|
|
|
if (preg_match('/(\_wm.webp$|\_wm.gif$|\_wm.png$|\_wm.jpg|\_wm.jpeg)$/is', $upload_file)) |
|
475
|
|
|
{ |
|
476
|
|
|
@unlink($gallery_url->path('upload') . $upload_file); |
|
477
|
|
|
} |
|
478
|
|
|
} |
|
479
|
|
|
@closedir($upload_dir); |
|
|
|
|
|
|
480
|
|
|
|
|
481
|
|
|
for ($i = 1; $i <= $phpbb_ext_gallery_config->get('current_upload_dir'); $i++) |
|
482
|
|
|
{ |
|
483
|
|
|
$cache_dir = @opendir($gallery_url->path('thumbnail') . $i . '/'); |
|
484
|
|
|
while ($cache_file = @readdir($cache_dir)) |
|
485
|
|
|
{ |
|
486
|
|
|
if (preg_match('/(\.webp$|\.gif$|\.png$|\.jpg|\.jpeg)$/is', $cache_file)) |
|
487
|
|
|
{ |
|
488
|
|
|
@unlink($gallery_url->path('thumbnail') . $i . '/' . $cache_file); |
|
489
|
|
|
} |
|
490
|
|
|
} |
|
491
|
|
|
@closedir($cache_dir); |
|
|
|
|
|
|
492
|
|
|
|
|
493
|
|
|
$medium_dir = @opendir($gallery_url->path('medium') . $i . '/'); |
|
494
|
|
|
while ($medium_file = @readdir($medium_dir)) |
|
495
|
|
|
{ |
|
496
|
|
|
if (preg_match('/(\.webp$|\.gif$|\.png$|\.jpg|\.jpeg)$/is', $medium_file)) |
|
497
|
|
|
{ |
|
498
|
|
|
@unlink($gallery_url->path('medium') . $i . '/' . $medium_file); |
|
499
|
|
|
} |
|
500
|
|
|
} |
|
501
|
|
|
@closedir($medium_dir); |
|
|
|
|
|
|
502
|
|
|
$upload_dir = @opendir($gallery_url->path('upload') . $i . '/'); |
|
503
|
|
|
while ($upload_file = @readdir($upload_dir)) |
|
504
|
|
|
{ |
|
505
|
|
|
if (preg_match('/(\_wm.webp$|\_wm.gif$|\_wm.png$|\_wm.jpg|\_wm.jpeg)$/is', $upload_file)) |
|
506
|
|
|
{ |
|
507
|
|
|
@unlink($gallery_url->path('upload') . $upload_file); |
|
508
|
|
|
} |
|
509
|
|
|
} |
|
510
|
|
|
@closedir($upload_dir); |
|
|
|
|
|
|
511
|
|
|
} |
|
512
|
|
|
|
|
513
|
|
|
$sql_ary = array( |
|
514
|
|
|
'filesize_medium' => 0, |
|
515
|
|
|
'filesize_cache' => 0, |
|
516
|
|
|
); |
|
517
|
|
|
$sql = 'UPDATE ' . $images_table . ' |
|
518
|
|
|
SET ' . $db->sql_build_array('UPDATE', $sql_ary); |
|
519
|
|
|
$db->sql_query($sql); |
|
520
|
|
|
|
|
521
|
|
|
trigger_error($this->language->lang('PURGED_CACHE') . adm_back_link($this->u_action)); |
|
522
|
|
|
break; |
|
523
|
|
|
|
|
524
|
|
|
case 'resync_albums_to_cpf': |
|
525
|
|
|
$resync_albums_to_cpf_stage = 'gather'; |
|
526
|
|
|
break; |
|
527
|
|
|
} |
|
528
|
|
|
} |
|
529
|
|
|
|
|
530
|
|
|
/* Resync stats as per server |
|
531
|
|
|
* Time: 0.271s |
|
532
|
|
|
* Queries: 1087 |
|
533
|
|
|
* Peak Memory usage: 8.62MB |
|
534
|
|
|
*/ |
|
535
|
|
|
if (isset($resync_albums_to_cpf_stage)) |
|
536
|
|
|
{ |
|
537
|
|
|
// We will loop a resync |
|
538
|
|
|
// Let's gather some info |
|
539
|
|
|
$sql = 'SELECT user_id FROM ' . $users_table . ' ORDER BY user_id ASC'; |
|
540
|
|
|
$result = $db->sql_query($sql); |
|
541
|
|
|
while ($row = $db->sql_fetchrow($result)) |
|
542
|
|
|
{ |
|
543
|
|
|
$sync_users[] = (int) $row['user_id']; |
|
544
|
|
|
} |
|
545
|
|
|
$phpbb_gallery_user->set_personal_albums($sync_users); |
|
|
|
|
|
|
546
|
|
|
$db->sql_freeresult($result); |
|
547
|
|
|
} |
|
548
|
|
|
|
|
549
|
|
|
$boarddays = (time() - $config['board_startdate']) / 86400; |
|
550
|
|
|
$images_per_day = sprintf('%.2f', $config['phpbb_gallery_num_images'] / $boarddays); |
|
551
|
|
|
|
|
552
|
|
|
$sql = 'SELECT COUNT(album_user_id) AS num_albums |
|
553
|
|
|
FROM ' . $albums_table . ' |
|
554
|
|
|
WHERE album_user_id = 0'; |
|
555
|
|
|
$result = $db->sql_query($sql); |
|
556
|
|
|
$num_albums = (int) $db->sql_fetchfield('num_albums'); |
|
557
|
|
|
$db->sql_freeresult($result); |
|
558
|
|
|
|
|
559
|
|
|
$sql = 'SELECT SUM(filesize_upload) AS stat, SUM(filesize_medium) AS stat_medium, SUM(filesize_cache) AS stat_cache |
|
560
|
|
|
FROM ' . $images_table; |
|
561
|
|
|
$result = $db->sql_query($sql); |
|
562
|
|
|
$dir_sizes = $db->sql_fetchrow($result); |
|
563
|
|
|
$db->sql_freeresult($result); |
|
564
|
|
|
|
|
565
|
|
|
$template->assign_vars(array( |
|
566
|
|
|
'S_GALLERY_OVERVIEW' => true, |
|
567
|
|
|
'ACP_GALLERY_TITLE' => $this->language->lang('ACP_GALLERY_OVERVIEW'), |
|
568
|
|
|
'ACP_GALLERY_TITLE_EXPLAIN' => $this->language->lang('ACP_GALLERY_OVERVIEW_EXPLAIN'), |
|
569
|
|
|
|
|
570
|
|
|
'TOTAL_IMAGES' => $config['phpbb_gallery_num_images'], |
|
571
|
|
|
'IMAGES_PER_DAY' => $images_per_day, |
|
572
|
|
|
'TOTAL_ALBUMS' => $num_albums, |
|
573
|
|
|
'TOTAL_PERSONALS' => $config['phpbb_gallery_num_pegas'], |
|
574
|
|
|
'GUPLOAD_DIR_SIZE' => get_formatted_filesize($dir_sizes['stat']), |
|
|
|
|
|
|
575
|
|
|
'MEDIUM_DIR_SIZE' => get_formatted_filesize($dir_sizes['stat_medium']), |
|
576
|
|
|
'CACHE_DIR_SIZE' => get_formatted_filesize($dir_sizes['stat_cache']), |
|
577
|
|
|
'GALLERY_VERSION' => $config['phpbb_gallery_version'], |
|
578
|
|
|
'U_FIND_USERNAME' => $gallery_url->append_sid('phpbb', 'memberlist', 'mode=searchuser&form=action_create_pega_form&field=username&select_single=true'), |
|
579
|
|
|
'S_SELECT_ALBUM' => $phpbb_ext_gallery_core_album->get_albumbox(false, 'reset_album_id', false, false, false, (int) \phpbbgallery\core\block::PUBLIC_ALBUM, (int) \phpbbgallery\core\block::TYPE_UPLOAD), |
|
580
|
|
|
|
|
581
|
|
|
'S_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false, |
|
582
|
|
|
'U_ACTION' => $this->u_action, |
|
583
|
|
|
)); |
|
584
|
|
|
} |
|
585
|
|
|
} |
|
586
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.