Changeset 23037 for extensions/community/add_photos.php
- Timestamp:
- Jun 4, 2013, 12:55:59 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/community/add_photos.php
r16637 r23037 73 73 include_once(PHPWG_ROOT_PATH.'admin/include/photos_add_direct_process.inc.php'); 74 74 75 // +-----------------------------------------------------------------------+ 76 // | limits | 77 // +-----------------------------------------------------------------------+ 78 79 // has the user reached its limits? 80 $user['community_usage'] = community_get_user_limits($user['id']); 81 // echo '<pre>'; print_r($user['community_usage']); echo '</pre>'; 82 83 // +-----------------------------------------------------------------------+ 84 // | set properties, moderate, notify | 85 // +-----------------------------------------------------------------------+ 86 75 87 if (isset($image_ids) and count($image_ids) > 0) 76 88 { 89 $query = ' 90 SELECT 91 id, 92 file, 93 filesize 94 FROM '.IMAGES_TABLE.' 95 WHERE id IN ('.implode(',', $image_ids).') 96 ORDER BY id DESC 97 ;'; 98 $images = array_from_query($query); 99 100 $nb_images_deleted = 0; 101 102 // upload has just happened, maybe the user is over quota 103 if ($user_permissions['storage'] > 0 and $user['community_usage']['storage'] > $user_permissions['storage']) 104 { 105 foreach ($images as $image) 106 { 107 array_push( 108 $page['errors'], 109 sprintf(l10n('Photo %s rejected.'), $image['file']) 110 .' '.sprintf(l10n('Disk usage quota reached (%uMB)'), $user_permissions['storage']) 111 ); 112 113 delete_elements(array($image['id']), true); 114 foreach ($page['thumbnails'] as $tn_idx => $thumbnail) 115 { 116 if ($thumbnail['file'] == $image['file']) 117 { 118 unset($page['thumbnails'][$idx]); 119 } 120 } 121 122 $user['community_usage'] = community_get_user_limits($user['id']); 123 124 if ($user['community_usage']['storage'] <= $user_permissions['storage']) 125 { 126 // we stop the deletions 127 break; 128 } 129 } 130 } 131 132 if ($user_permissions['nb_photos'] > 0 and $user['community_usage']['nb_photos'] > $user_permissions['nb_photos']) 133 { 134 foreach ($images as $image) 135 { 136 array_push( 137 $page['errors'], 138 sprintf(l10n('Photo %s rejected.'), $image['file']) 139 .' '.sprintf(l10n('Maximum number of photos reached (%u)'), $user_permissions['nb_photos']) 140 ); 141 142 delete_elements(array($image['id']), true); 143 foreach ($page['thumbnails'] as $tn_idx => $thumbnail) 144 { 145 if ($thumbnail['file'] == $image['file']) 146 { 147 unset($page['thumbnails'][$idx]); 148 } 149 } 150 151 $user['community_usage'] = community_get_user_limits($user['id']); 152 153 if ($user['community_usage']['nb_photos'] <= $user_permissions['nb_photos']) 154 { 155 // we stop the deletions 156 break; 157 } 158 } 159 } 160 161 77 162 // reinitialize the informations to display on the result page 78 163 $page['infos'] = array(); … … 112 197 ); 113 198 } 114 115 // $category_id is set in the photos_add_direct_process.inc.php included script 116 $category_infos = get_cat_info($category_id); 117 $category_name = get_cat_display_name($category_infos['upper_names']); 118 119 array_push( 120 $page['infos'], 121 sprintf( 122 l10n('%d photos uploaded into album "%s"'), 123 count($page['thumbnails']), 124 '<em>'.$category_name.'</em>' 125 ) 126 ); 199 200 if (count($page['thumbnails']) > 0) 201 { 202 // $category_id is set in the photos_add_direct_process.inc.php included script 203 $category_infos = get_cat_info($category_id); 204 $category_name = get_cat_display_name($category_infos['upper_names']); 205 206 array_push( 207 $page['infos'], 208 sprintf( 209 l10n('%d photos uploaded into album "%s"'), 210 count($page['thumbnails']), 211 '<em>'.$category_name.'</em>' 212 ) 213 ); 214 } 127 215 128 216 // should the photos be moderated? … … 186 274 ); 187 275 } 188 189 mass_inserts( 190 COMMUNITY_PENDINGS_TABLE, 191 array_keys($inserts[0]), 192 $inserts 193 ); 194 195 // find the url to the medium size 196 $page['thumbnails'] = array(); 197 198 $query = ' 276 277 if (count($inserts) > 0) 278 { 279 mass_inserts( 280 COMMUNITY_PENDINGS_TABLE, 281 array_keys($inserts[0]), 282 $inserts 283 ); 284 285 // find the url to the medium size 286 $page['thumbnails'] = array(); 287 288 $query = ' 199 289 SELECT * 200 290 FROM '.IMAGES_TABLE.' 201 291 WHERE id IN ('.implode(',', $image_ids).') 202 292 ;'; 203 $result = pwg_query($query); 204 while ($row = pwg_db_fetch_assoc($result)) 205 { 206 $src_image = new SrcImage($row); 207 208 $page['thumbnails'][] = array( 209 'file' => $row['file'], 210 'src' => DerivativeImage::url(IMG_THUMB, $src_image), 211 'title' => $row['name'], 212 'link' => $image_url = DerivativeImage::url(IMG_MEDIUM, $src_image), 213 'lightbox' => true, 293 $result = pwg_query($query); 294 while ($row = pwg_db_fetch_assoc($result)) 295 { 296 $src_image = new SrcImage($row); 297 298 $page['thumbnails'][] = array( 299 'file' => $row['file'], 300 'src' => DerivativeImage::url(IMG_THUMB, $src_image), 301 'title' => $row['name'], 302 'link' => $image_url = DerivativeImage::url(IMG_MEDIUM, $src_image), 303 'lightbox' => true, 304 ); 305 } 306 307 array_push( 308 $page['infos'], 309 l10n('Your photos are waiting for validation, administrators have been notified') 214 310 ); 215 311 } 216 217 array_push(218 $page['infos'],219 l10n('Your photos are waiting for validation, administrators have been notified')220 );221 312 } 222 313 else … … 247 338 248 339 invalidate_user_cache(); 249 250 // let's notify administrators 251 include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); 252 253 $keyargs_content = array( 254 get_l10n_args('Hi administrators,', ''), 255 get_l10n_args('', ''), 256 get_l10n_args('Album: %s', get_cat_display_name($category_infos['upper_names'], null, false)), 257 get_l10n_args('User: %s', $user['username']), 258 get_l10n_args('Email: %s', $user['email']), 340 341 if (count($page['thumbnails'])) 342 { 343 // let's notify administrators 344 include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); 345 346 $keyargs_content = array( 347 get_l10n_args('Hi administrators,', ''), 348 get_l10n_args('', ''), 349 get_l10n_args('Album: %s', get_cat_display_name($category_infos['upper_names'], null, false)), 350 get_l10n_args('User: %s', $user['username']), 351 get_l10n_args('Email: %s', $user['email']), 352 ); 353 354 if ($moderate) 355 { 356 $keyargs_content[] = get_l10n_args('', ''); 357 358 array_push( 359 $keyargs_content, 360 get_l10n_args( 361 'Validation page: %s', 362 get_absolute_root_url().'admin.php?page=plugin-community-pendings' 363 ) 364 ); 365 } 366 367 pwg_mail_notification_admins( 368 get_l10n_args('%d photos uploaded by %s', array(count($image_ids), $user['username'])), 369 $keyargs_content, 370 false 371 ); 372 } 373 } 374 375 // +-----------------------------------------------------------------------+ 376 // | prepare form | 377 // +-----------------------------------------------------------------------+ 378 379 $template->set_filenames(array('add_photos' => dirname(__FILE__).'/add_photos.tpl')); 380 381 include_once(PHPWG_ROOT_PATH.'admin/include/photos_add_direct_prepare.inc.php'); 382 383 $quota_available = array( 384 'summary' => array(), 385 'details' => array(), 386 ); 387 388 // there is a limit on storage for this user 389 if ($user_permissions['storage'] > 0) 390 { 391 $remaining_storage = $user_permissions['storage'] - $user['community_usage']['storage']; 392 393 if ($remaining_storage <= 0) 394 { 395 echo 'limit storage reached<br>'; 396 // limit reached 397 $setup_errors[] = sprintf( 398 l10n('Disk usage quota reached (%uMB)'), 399 $user_permissions['storage'] 400 ); 401 } 402 else 403 { 404 $quota_available['summary'][] = $remaining_storage.'MB'; 405 406 $quota_available['details'][] = sprintf( 407 l10n('%s out of %s'), 408 $remaining_storage.'MB', 409 $user_permissions['storage'] 410 ); 411 412 $template->assign( 413 array( 414 'limit_storage' => $remaining_storage*1024*1024, 415 'limit_storage_total_mb' => $user_permissions['storage'], 416 ) 417 ); 418 } 419 } 420 421 // there is a limit on number of photos for this user 422 if ($user_permissions['nb_photos'] > 0) 423 { 424 $remaining_nb_photos = $user_permissions['nb_photos'] - $user['community_usage']['nb_photos']; 425 426 if ($remaining_nb_photos <= 0) 427 { 428 echo 'limit nb_photos reached<br>'; 429 // limit reached 430 $setup_errors[] = sprintf( 431 l10n('Maximum number of photos reached (%u)'), 432 $user_permissions['nb_photos'] 433 ); 434 } 435 else 436 { 437 $quota_available['summary'][] = l10n_dec('%d photo', '%d photos', $remaining_nb_photos); 438 439 $quota_available['details'][] = sprintf( 440 l10n('%s out of %s'), 441 l10n_dec('%d photo', '%d photos', $remaining_nb_photos), 442 $user_permissions['nb_photos'] 443 ); 444 445 $template->assign('limit_nb_photos', $remaining_nb_photos); 446 } 447 } 448 449 if (count($quota_available['details']) > 0) 450 { 451 $template->assign( 452 array( 453 'quota_summary' => sprintf( 454 l10n('Available %s.'), 455 implode(', ', $quota_available['summary']) 456 ), 457 'quota_details' => sprintf( 458 l10n('Available quota %s.'), 459 implode(', ', $quota_available['details']) 460 ), 461 ) 259 462 ); 260 261 if ($moderate) 262 { 263 $keyargs_content[] = get_l10n_args('', ''); 264 265 array_push( 266 $keyargs_content, 267 get_l10n_args( 268 'Validation page: %s', 269 get_absolute_root_url().'admin.php?page=plugin-community-pendings' 270 ) 271 ); 272 } 273 274 pwg_mail_notification_admins( 275 get_l10n_args('%d photos uploaded by %s', array(count($image_ids), $user['username'])), 276 $keyargs_content, 277 false 278 ); 279 } 280 281 // +-----------------------------------------------------------------------+ 282 // | prepare form | 283 // +-----------------------------------------------------------------------+ 284 285 $template->set_filenames(array('add_photos' => dirname(__FILE__).'/add_photos.tpl')); 286 287 include_once(PHPWG_ROOT_PATH.'admin/include/photos_add_direct_prepare.inc.php'); 463 } 464 465 $template->assign( 466 array( 467 'setup_errors'=> $setup_errors, 468 ) 469 ); 288 470 289 471 // we have to change the list of uploadable albums
Note: See TracChangeset
for help on using the changeset viewer.