forked from plegall/Piwigo-community
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_photos.php
479 lines (401 loc) · 14 KB
/
add_photos.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
<?php
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
// | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation |
// | |
// | This program is distributed in the hope that it will be useful, but |
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA. |
// +-----------------------------------------------------------------------+
if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
global $template, $conf, $user;
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
include_once(COMMUNITY_PATH.'include/functions_community.inc.php');
define('PHOTOS_ADD_BASE_URL', make_index_url(array('section' => 'add_photos')));
$user_permissions = $user['community_permissions'];
if (!$user_permissions['community_enabled'])
{
redirect(make_index_url());
}
// +-----------------------------------------------------------------------+
// | process form |
// +-----------------------------------------------------------------------+
$page['errors'] = array();
$page['infos'] = array();
// this is for "browser uploader", for Flash Uploader the problem is solved
// with function community_uploadify_privacy_level (see main.inc.php)
$_POST['level'] = 16;
if (isset($_GET['processed']))
{
$hacking_attempt = false;
// is the user authorized to upload in this album?
if (!in_array($_POST['category'], $user_permissions['upload_categories']))
{
echo 'Hacking attempt, you have no permission to upload in this album';
$hacking_attempt = true;
}
if ($hacking_attempt)
{
if (isset($_SESSION['uploads'][ $_POST['upload_id'] ]))
{
delete_elements($_SESSION['uploads'][ $_POST['upload_id'] ], true);
}
exit();
}
}
include_once(COMMUNITY_PATH.'include/photos_add_direct_process.inc.php');
// +-----------------------------------------------------------------------+
// | limits |
// +-----------------------------------------------------------------------+
// has the user reached its limits?
$user['community_usage'] = community_get_user_limits($user['id']);
// echo '<pre>'; print_r($user['community_usage']); echo '</pre>';
// +-----------------------------------------------------------------------+
// | set properties, moderate, notify |
// +-----------------------------------------------------------------------+
if (isset($image_ids) and count($image_ids) > 0)
{
$query = '
SELECT
id,
file,
filesize
FROM '.IMAGES_TABLE.'
WHERE id IN ('.implode(',', $image_ids).')
ORDER BY id DESC
;';
$images = array_from_query($query);
$nb_images_deleted = 0;
// upload has just happened, maybe the user is over quota
if ($user_permissions['storage'] > 0 and $user['community_usage']['storage'] > $user_permissions['storage'])
{
foreach ($images as $image)
{
array_push(
$page['errors'],
sprintf(l10n('Photo %s rejected.'), $image['file'])
.' '.sprintf(l10n('Disk usage quota reached (%uMB)'), $user_permissions['storage'])
);
delete_elements(array($image['id']), true);
foreach ($page['thumbnails'] as $tn_idx => $thumbnail)
{
if ($thumbnail['file'] == $image['file'])
{
unset($page['thumbnails'][$idx]);
}
}
$user['community_usage'] = community_get_user_limits($user['id']);
if ($user['community_usage']['storage'] <= $user_permissions['storage'])
{
// we stop the deletions
break;
}
}
}
if ($user_permissions['nb_photos'] > 0 and $user['community_usage']['nb_photos'] > $user_permissions['nb_photos'])
{
foreach ($images as $image)
{
array_push(
$page['errors'],
sprintf(l10n('Photo %s rejected.'), $image['file'])
.' '.sprintf(l10n('Maximum number of photos reached (%u)'), $user_permissions['nb_photos'])
);
delete_elements(array($image['id']), true);
foreach ($page['thumbnails'] as $tn_idx => $thumbnail)
{
if ($thumbnail['file'] == $image['file'])
{
unset($page['thumbnails'][$idx]);
}
}
$user['community_usage'] = community_get_user_limits($user['id']);
if ($user['community_usage']['nb_photos'] <= $user_permissions['nb_photos'])
{
// we stop the deletions
break;
}
}
}
// reinitialize the informations to display on the result page
$page['infos'] = array();
if (count($page['thumbnails']) > 0)
{
// $category_id is set in the photos_add_direct_process.inc.php included script
$category_infos = get_cat_info($category_id);
$category_name = get_cat_display_name($category_infos['upper_names']);
array_push(
$page['infos'],
sprintf(
l10n('%d photos uploaded into album "%s"'),
count($page['thumbnails']),
'<em>'.$category_name.'</em>'
)
);
}
}
// +-----------------------------------------------------------------------+
// | prepare form |
// +-----------------------------------------------------------------------+
$template->set_template_dir(realpath(dirname(__FILE__)));
$template->set_filename('add_photos', 'add_photos.tpl');
// +-----------------------------------------------------------------------+
// | Uploaded photos |
// +-----------------------------------------------------------------------+
if (isset($page['thumbnails']))
{
$template->assign(
array(
'thumbnails' => $page['thumbnails'],
)
);
// only display the batch link if we have more than 1 photo
if (count($page['thumbnails']) > 1)
{
$template->assign(
array(
'batch_link' => $page['batch_link'],
'batch_label' => sprintf(
l10n('Manage this set of %d photos'),
count($page['thumbnails'])
),
)
);
}
}
$upload_max_filesize = min(
get_ini_size('upload_max_filesize'),
get_ini_size('post_max_size')
);
if ($upload_max_filesize == get_ini_size('upload_max_filesize'))
{
$upload_max_filesize_shorthand = get_ini_size('upload_max_filesize', false);
}
else
{
$upload_max_filesize_shorthand = get_ini_size('post_max_filesize', false);
}
$template->assign(
array(
'upload_max_filesize' => $upload_max_filesize,
'upload_max_filesize_shorthand' => $upload_max_filesize_shorthand,
)
);
include_once(PHPWG_ROOT_PATH.'admin/include/photos_add_direct_prepare.inc.php');
if (isset($conf['upload_form_all_types']) and $conf['upload_form_all_types'])
{
$upload_file_types = $conf['file_ext'];
}
else
{
$upload_file_types = $conf['picture_ext'];
}
$unique_exts = array_unique(array_map('strtolower', $upload_file_types));
$is_windows = true;
if (stripos($_SERVER['HTTP_USER_AGENT'], 'Win') === false)
{
$is_windows = false;
}
$uploadify_exts = array();
foreach ($unique_exts as $ext)
{
$uploadify_exts[] = $ext;
// Windows is not case sensitive and there is a bug with Firefox on
// Windows: the list of extensions is truncated and last extensions are
// not taken into account, so we have to make it as short as possible.
if (!$is_windows)
{
$uploadify_exts[] = strtoupper($ext);
}
}
$upload_modes = array('html', 'multiple');
$upload_mode = isset($conf['upload_mode']) ? $conf['upload_mode'] : 'multiple';
if (isset($_GET['upload_mode']) and $upload_mode != $_GET['upload_mode'] and in_array($_GET['upload_mode'], $upload_modes))
{
$upload_mode = $_GET['upload_mode'];
conf_update_param('upload_mode', $upload_mode);
}
// what is the upload switch mode
$index_of_upload_mode = array_flip($upload_modes);
$upload_mode_index = $index_of_upload_mode[$upload_mode];
$upload_switch = $upload_modes[ ($upload_mode_index + 1) % 2 ];
$template->assign(
array(
'uploadify_path' => COMMUNITY_PATH.'uploadify',
'upload_file_types' => implode(', ', $unique_exts),
'uploadify_fileTypeExts' => implode(';', prepend_append_array_items($uploadify_exts, '*.', '')),
'upload_mode' => $upload_mode,
'form_action' => PHOTOS_ADD_BASE_URL.'&upload_mode='.$upload_mode.'&processed=1',
'switch_url' => PHOTOS_ADD_BASE_URL.'&upload_mode='.$upload_switch,
'upload_id' => md5(rand()),
'session_id' => session_id(),
'another_upload_link' => PHOTOS_ADD_BASE_URL.(isset($_GET['category_id']) ? '&category_id='.$_GET['category_id'] : ''),
)
);
$quota_available = array(
'summary' => array(),
'details' => array(),
);
// there is a limit on storage for this user
if ($user_permissions['storage'] > 0)
{
$remaining_storage = $user_permissions['storage'] - $user['community_usage']['storage'];
if ($remaining_storage <= 0)
{
// limit reached
$setup_errors[] = sprintf(
l10n('Disk usage quota reached (%uMB)'),
$user_permissions['storage']
);
}
else
{
$quota_available['summary'][] = $remaining_storage.'MB';
$quota_available['details'][] = sprintf(
l10n('%s out of %s'),
$remaining_storage.'MB',
$user_permissions['storage']
);
$template->assign(
array(
'limit_storage' => $remaining_storage*1024*1024,
'limit_storage_total_mb' => $user_permissions['storage'],
)
);
}
}
// there is a limit on number of photos for this user
if ($user_permissions['nb_photos'] > 0)
{
$remaining_nb_photos = $user_permissions['nb_photos'] - $user['community_usage']['nb_photos'];
if ($remaining_nb_photos <= 0)
{
// limit reached
$setup_errors[] = sprintf(
l10n('Maximum number of photos reached (%u)'),
$user_permissions['nb_photos']
);
}
else
{
$quota_available['summary'][] = l10n_dec('%d photo', '%d photos', $remaining_nb_photos);
$quota_available['details'][] = sprintf(
l10n('%s out of %s'),
l10n_dec('%d photo', '%d photos', $remaining_nb_photos),
$user_permissions['nb_photos']
);
$template->assign('limit_nb_photos', $remaining_nb_photos);
}
}
if (count($quota_available['details']) > 0)
{
$template->assign(
array(
'quota_summary' => sprintf(
l10n('Available %s.'),
implode(', ', $quota_available['summary'])
),
'quota_details' => sprintf(
l10n('Available quota %s.'),
implode(', ', $quota_available['details'])
),
)
);
}
$template->assign(
array(
'setup_errors'=> $setup_errors,
)
);
// we have to change the list of uploadable albums
$upload_categories = $user_permissions['upload_categories'];
if (count($upload_categories) == 0)
{
$upload_categories = array(-1);
}
$query = '
SELECT id,name,uppercats,global_rank
FROM '.CATEGORIES_TABLE.'
WHERE id IN ('.implode(',', $upload_categories).')
;';
display_select_cat_wrapper(
$query,
$selected_category,
'category_options'
);
$create_subcategories = false;
if ($user_permissions['create_whole_gallery'] or count($user_permissions['create_categories']) > 0)
{
$create_subcategories = true;
}
$create_categories = $user_permissions['create_categories'];
if (count($user_permissions['create_categories']) == 0)
{
$create_categories = array(-1);
}
$query = '
SELECT id,name,uppercats,global_rank
FROM '.CATEGORIES_TABLE.'
WHERE id IN ('.implode(',', $create_categories).')
;';
display_select_cat_wrapper(
$query,
$selected_category,
'category_parent_options'
);
$category_options_selected = array();
if (isset($_GET['category_id']))
{
check_input_parameter('category_id', $_GET, false, PATTERN_ID);
$category_options_selected = array($_GET['category_id']);
}
$template->assign(
array(
'category_options_selected' => $category_options_selected,
'create_subcategories' => $create_subcategories,
'create_whole_gallery' => $user_permissions['create_whole_gallery'],
)
);
if (isset($conf['community_ask_for_properties']) and $conf['community_ask_for_properties'])
{
$template->assign(
array(
'community_ask_for_properties' => true,
)
);
}
// +-----------------------------------------------------------------------+
// | display page |
// +-----------------------------------------------------------------------+
if (count($page['errors']) != 0)
{
$template->assign('errors', $page['errors']);
}
if (count($page['infos']) != 0)
{
$template->assign('infos', $page['infos']);
}
$title = l10n('Upload Photos');
$page['body_id'] = 'theUploadPage';
$template->assign_var_from_handle('PLUGIN_INDEX_CONTENT_BEGIN', 'add_photos');
$template->clear_assign(array('U_MODE_POSTED', 'U_MODE_CREATED'));
$template->assign(
array(
'TITLE' => '<a href="'.get_gallery_home_url().'">'.l10n('Home').'</a>'.$conf['level_separator'].$title,
)
);
?>