ngg_ajax_operation

Image edit functions via AJAX.

Description

ngg_ajax_operation(); 

Usage

  1. if ( !function_exists( 'ngg_ajax_operation' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextgen-gallery/products/photocrati_nextgen/modules/ngglegacy/admin/ajax.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = ngg_ajax_operation(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/products/photocrati_nextgen/modules/ngglegacy/admin/ajax.php  
  1. function ngg_ajax_operation() { 
  2.  
  3. // if nonce is not correct it returns -1 
  4. check_ajax_referer( "ngg-ajax" ); 
  5.  
  6. // check for correct capability 
  7. if ( !is_user_logged_in() ) 
  8. die('-1'); 
  9.  
  10. // check for correct NextGEN capability 
  11. if ( !current_user_can('NextGEN Upload images') && !current_user_can('NextGEN Manage gallery') ) 
  12. die('-1'); 
  13.  
  14. // include the ngg function 
  15. include_once (dirname (__FILE__) . '/functions.php'); 
  16.  
  17. // Get the image id 
  18. if ( isset($_POST['image'])) { 
  19. $id = (int) $_POST['image']; 
  20. // let's get the image data 
  21. $picture = nggdb::find_image( $id ); 
  22. // what do you want to do ? 
  23. switch ( $_POST['operation'] ) { 
  24. case 'create_thumbnail' : 
  25. $result = nggAdmin::create_thumbnail($picture); 
  26. break; 
  27. case 'resize_image' : 
  28. $result = nggAdmin::resize_image($picture); 
  29. break; 
  30. case 'rotate_cw' : 
  31. $result = nggAdmin::rotate_image($picture, 'CW'); 
  32. nggAdmin::create_thumbnail($picture); 
  33. break; 
  34. case 'rotate_ccw' : 
  35. $result = nggAdmin::rotate_image($picture, 'CCW'); 
  36. nggAdmin::create_thumbnail($picture); 
  37. break; 
  38. case 'set_watermark' : 
  39. $result = nggAdmin::set_watermark($picture); 
  40. break; 
  41. case 'recover_image' : 
  42. $result = nggAdmin::recover_image($id) ? '1': '0'; 
  43. break; 
  44. case 'import_metadata' : 
  45. $result = C_Image_Mapper::get_instance()->reimport_metadata($id) ? '1' : '0'; 
  46. break; 
  47. case 'get_image_ids' : 
  48. $result = nggAdmin::get_image_ids( $id ); 
  49. break; 
  50. default : 
  51. die('-1'); 
  52. break; 
  53. // A success should return a '1' 
  54. die ($result); 
  55.  
  56. // The script should never stop here 
  57. die('0');