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 . 'nextcellent-gallery/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).

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