NGG_Abstract_Image_Manager

Class NGG_Abstract_Image_Manager.

Defined (1)

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

/admin/manage/class-ngg-abstract-image-manager.php  
  1. abstract class NGG_Abstract_Image_Manager extends NGG_Manager { 
  2.  
  3. public function display() { 
  4.  
  5. parent::display(); 
  6.  
  7. if ( isset ( $_POST['update_images'] ) ) { 
  8. $this->handle_update_images(); 
  9.  
  10. /** 
  11. * @todo Make this better. 
  12. */ 
  13. protected function print_scripts() { 
  14. parent::print_scripts(); 
  15. ?> 
  16. <script type="text/javascript"> 
  17.  
  18. var defaultAction = function(dialog) { 
  19. jQuery(dialog).dialog('close'); 
  20. }; 
  21.  
  22. var doAction = defaultAction; 
  23.  
  24. /** 
  25. * Load the content with AJAX. 
  26. */ 
  27. jQuery('a.ngg-dialog').click(function() { 
  28. //Get the spinner. 
  29. var $spinner = jQuery("#spinner"); 
  30. var $this = jQuery(this); 
  31. var action = $this.data("action"); 
  32. var id = $this.data("id"); 
  33. var base_url = "<?php echo plugins_url('actions.php?cmd=', __FILE__) ?>"; 
  34.  
  35. if (!$spinner.length) { 
  36. jQuery("body").append('<div id="spinner"></div>'); 
  37.  
  38. $spinner.fadeIn(); 
  39.  
  40. var dialog = jQuery('<div style="display:none" class="ngg-load-dialog"></div>').appendTo('body'); 
  41. // load the remote content 
  42. dialog.load( 
  43. base_url + action + "&id=" + id,  
  44. {},  
  45. function() { 
  46. jQuery('#spinner').hide(); 
  47. //The doAction function must be defined in the actions.php file. 
  48. showDialog(dialog, ($this.attr('title')) ? $this.attr('title') : '', doAction); 
  49. ); 
  50. //prevent the browser to follow the link 
  51. return false; 
  52. }); 
  53.  
  54. /** 
  55. * Show a message on the image action modal window. 
  56. * @param message string The message. 
  57. */ 
  58. function showMessage(message) { 
  59. jQuery('#thumbMsg').html(message).css({'display': 'block'}); 
  60. setTimeout(function() { 
  61. jQuery('#thumbMsg').fadeOut('slow'); 
  62. }, 1500); 
  63.  
  64. var d = new Date(); 
  65. var $image = jQuery("#imageToEdit"); 
  66. var newUrl = $image.attr("src") + "?" + d.getTime(); 
  67. $image.attr("src", newUrl); 
  68. </script> 
  69.  
  70. <?php 
  71.  
  72. /** 
  73. * @todo Make a real DAO system for NextCellent. 
  74. * @todo Make this a lot faster by merging all these database commands 
  75. */ 
  76. private function handle_update_images() { 
  77.  
  78. if ( wp_verify_nonce( $_POST['_ngg_nonce_images'], 'ngg-update-images' ) === false ) { 
  79. nggGallery::show_error( __( 'You waited too long, or you cheated.', 'nggallery' ) ); 
  80.  
  81. return; 
  82.  
  83. global $wpdb, $nggdb; 
  84.  
  85. //TODO:Error message when update failed 
  86.  
  87. $description = isset ( $_POST['description'] ) ? $_POST['description'] : array(); 
  88. $alttext = isset ( $_POST['alttext'] ) ? $_POST['alttext'] : array(); 
  89. $exclude = isset ( $_POST['exclude'] ) ? $_POST['exclude'] : false; 
  90. $taglist = isset ( $_POST['tags'] ) ? $_POST['tags'] : false; 
  91. $pictures = isset ( $_POST['pid'] ) ? $_POST['pid'] : false; 
  92. $date = isset ( $_POST['date'] ) ? $_POST['date'] : "NOW()"; //Not sure if NOW() will work or not but in theory it should 
  93.  
  94. if ( is_array( $pictures ) ) { 
  95. foreach ( $pictures as $pid ) { 
  96. $image = $nggdb->find_image( $pid ); 
  97. if ( $image ) { 
  98. // description field 
  99. $image->description = $description[ $image->pid ]; 
  100. $image->date = $date[ $image->pid ]; 
  101. // only uptade this field if someone change the alttext 
  102. if ( $image->alttext != $alttext[ $image->pid ] ) { 
  103. $image->alttext = $alttext[ $image->pid ]; 
  104. $image->image_slug = nggdb::get_unique_slug( sanitize_title( $image->alttext ), 'image',  
  105. $image->pid ); 
  106.  
  107. // set exclude flag 
  108. if ( is_array( $exclude ) ) { 
  109. $image->exclude = ( array_key_exists( $image->pid, $exclude ) ) ? 1 : 0; 
  110. } else { 
  111. $image->exclude = 0; 
  112.  
  113. // update the database 
  114. $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->nggpictures SET image_slug = '%s', alttext = '%s', description = '%s', exclude = %d, imagedate = %s WHERE pid = %d",  
  115. $image->image_slug, $image->alttext, $image->description, $image->exclude, $image->date,  
  116. $image->pid ) ); 
  117. // remove from cache 
  118. wp_cache_delete( $image->pid, 'ngg_image' ); 
  119.  
  120. // hook for other plugins after image is updated 
  121. do_action( 'ngg_image_updated', $image ); 
  122.  
  123.  
  124. //TODO: This produce 300-400 queries ! 
  125. if ( is_array( $taglist ) ) { 
  126. foreach ( $taglist as $key => $value ) { 
  127. $tags = explode( ', ', $value ); 
  128. wp_set_object_terms( $key, $tags, 'ngg_tag' ); 
  129.  
  130. nggGallery::show_message( __( 'Update successful', "nggallery" ) );