nggallery_sortorder

The NextGEN Gallery nggallery sortorder function.

Description

nggallery_sortorder( (int) $galleryID = 0 ); 

Parameters (1)

0. $galleryid (int)
The galleryid.

Usage

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

Defined (1)

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

/products/photocrati_nextgen/modules/ngglegacy/admin/manage-sort.php  
  1. function nggallery_sortorder($galleryID = 0) { 
  2. global $wpdb, $ngg, $nggdb; 
  3.  
  4. if ($galleryID == 0) return; 
  5.  
  6. $galleryID = (int) $galleryID; 
  7.  
  8. if (isset ($_POST['updateSortorder'])) { 
  9. check_admin_referer('ngg_updatesortorder'); 
  10. // get variable new sortorder 
  11. parse_str($_POST['sortorder']); 
  12. if (is_array($sortArray)) { 
  13. $neworder = array(); 
  14. foreach($sortArray as $pid) { 
  15. $neworder[] = (int) $pid; 
  16. $sortindex = 1; 
  17. foreach($neworder as $pic_id) { 
  18. $wpdb->query("UPDATE $wpdb->nggpictures SET sortorder = '$sortindex' WHERE pid = $pic_id"); 
  19. $sortindex++; 
  20. C_Photocrati_Transient_Manager::flush('displayed_gallery_rendering'); 
  21.  
  22. do_action('ngg_gallery_sort', $galleryID); 
  23.  
  24. nggGallery::show_message(__('Sort order changed', 'nggallery')); 
  25.  
  26. // look for presort args 
  27. $presort = isset($_GET['presort']) ? $_GET['presort'] : false; 
  28. $dir = ( isset($_GET['dir']) && $_GET['dir'] == 'DESC' ) ? 'DESC' : 'ASC'; 
  29. $sortitems = array('pid', 'filename', 'alttext', 'imagedate'); 
  30. // ensure that nobody added some evil sorting :-) 
  31. if (in_array( $presort, $sortitems) ) 
  32. $picturelist = $nggdb->get_gallery($galleryID, $presort, $dir, false); 
  33. else 
  34. $picturelist = $nggdb->get_gallery($galleryID, 'sortorder', $dir, false); 
  35.  
  36. //this is the url without any presort variable 
  37. $clean_url = 'admin.php?page=nggallery-manage-gallery&mode=sort&gid=' . $galleryID; 
  38. //if we go back , then the mode should be edit 
  39. $back_url = 'admin.php?page=nggallery-manage-gallery&mode=edit&gid=' . $galleryID; 
  40.  
  41. // In the case somebody presort, then we take this url 
  42. if ( isset($_GET['dir']) || isset($_GET['presort']) ) 
  43. $base_url = $_SERVER['REQUEST_URI']; 
  44. else 
  45. $base_url = $clean_url; 
  46.  
  47. ?> 
  48. <script type="text/javascript"> 
  49. jQuery(document).ready(function($) { 
  50. if ($(this).data('ready')) return; 
  51.  
  52. // Enable sorting 
  53. $(".jqui-sortable").sortable({items: 'div.imageBox'}); 
  54.  
  55. $('#sortGallery').submit(function(e) { 
  56. var serial = ""; 
  57. var $images = $('div.imageBox'); 
  58. for (var i=0; i<$images.length; i++) { 
  59. var image_id = $images[i].id.split('-').pop(); 
  60. if (serial.length > 0) serial = serial + '&'; 
  61. serial = serial + "sortArray[]=" + image_id; 
  62. $('input[name=sortorder]').val(serial); 
  63. }); 
  64.  
  65. // Listen for events in other frames 
  66. if (window.Frame_Event_Publisher) { 
  67. Frame_Event_Publisher.listen_for('attach_to_post:manage_galleries attach_to_post:manage_images', function() { 
  68. window.location.href = window.location.href; 
  69. }); 
  70.  
  71. $(this).data('ready', true); 
  72. }); 
  73.  
  74.  
  75. </script> 
  76. <div class="wrap"> 
  77. <form id="sortGallery" method="POST" action="<?php echo $clean_url ?>" accept-charset="utf-8"> 
  78. <h2><?php _e('Sort Gallery', 'nggallery') ?></h2> 
  79. <div class="tablenav"> 
  80. <div class="alignleft actions"> 
  81. <?php wp_nonce_field('ngg_updatesortorder') ?> 
  82. <input class="button-primary action" type="submit" name="updateSortorder" value="<?php _e('Update Sort Order', 'nggallery') ?>" /> 
  83. </div> 
  84. <div class="alignright actions"> 
  85. <a href="<?php echo nextgen_esc_url( $back_url ); ?>" class="button"><?php _e('Back to gallery', 'nggallery'); ?></a> 
  86. </div> 
  87. </div> 
  88. <input name="sortorder" type="hidden" /> 
  89. <ul class="subsubsub"> 
  90. <li><?php _e('Presort', 'nggallery') ?> :</li> 
  91. <li><a href="<?php echo esc_attr(remove_query_arg('presort', $base_url)); ?>" <?php if ($presort == '') echo 'class="current"'; ?>><?php _e('Unsorted', 'nggallery') ?></a> |</li> 
  92. <li><a href="<?php echo esc_attr(add_query_arg('presort', 'pid', $base_url)); ?>" <?php if ($presort == 'pid') echo 'class="current"'; ?>><?php _e('Image ID', 'nggallery') ?></a> |</li> 
  93. <li><a href="<?php echo esc_attr(add_query_arg('presort', 'filename', $base_url)); ?>" <?php if ($presort == 'filename') echo 'class="current"'; ?>><?php _e('Filename', 'nggallery') ?></a> |</li> 
  94. <li><a href="<?php echo esc_attr(add_query_arg('presort', 'alttext', $base_url)); ?>" <?php if ($presort == 'alttext') echo 'class="current"'; ?>><?php _e('Alt/Title text', 'nggallery') ?></a> |</li> 
  95. <li><a href="<?php echo esc_attr(add_query_arg('presort', 'imagedate', $base_url)); ?>" <?php if ($presort == 'imagedate') echo 'class="current"'; ?>><?php _e('Date/Time', 'nggallery') ?></a> |</li> 
  96. <li><a href="<?php echo esc_attr(add_query_arg('dir', 'ASC', $base_url)); ?>" <?php if ($dir == 'ASC') echo 'class="current"'; ?>><?php _e('Ascending', 'nggallery') ?></a> |</li> 
  97. <li><a href="<?php echo esc_attr(add_query_arg('dir', 'DESC', $base_url)); ?>" <?php if ($dir == 'DESC') echo 'class="current"'; ?>><?php _e('Descending', 'nggallery') ?></a></li> 
  98. </ul> 
  99. </form> 
  100. <div id="debug" style="clear:both"></div> 
  101. <div class='jqui-sortable'> 
  102. <?php 
  103. if($picturelist) { 
  104. foreach($picturelist as $picture) { 
  105. ?> 
  106. <div class="imageBox" id="pid-<?php echo $picture->pid ?>"> 
  107. <div class="imageBox_theImage" style="background-image:url('<?php echo nextgen_esc_url( $picture->thumbURL ); ?>')"></div> 
  108. <div class="imageBox_label"><span><?php echo esc_html( stripslashes($picture->alttext) ); ?></span></div> 
  109. </div> 
  110. <?php 
  111. ?> 
  112. </div> 
  113. </div> 
  114.  
  115. <?php