nggallery_manage_gallery_main

The NextGEN Gallery nggallery manage gallery main function.

Description

nggallery_manage_gallery_main(); 

Usage

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

Defined (1)

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

/products/photocrati_nextgen/modules/ngglegacy/admin/manage-galleries.php  
  1. function nggallery_manage_gallery_main() { 
  2.  
  3. global $ngg, $nggdb, $wp_query; 
  4.  
  5. //Build the pagination for more than 25 galleries 
  6. $_GET['paged'] = isset($_GET['paged']) && ($_GET['paged'] > 0) ? absint($_GET['paged']) : 1; 
  7.  
  8. $items_per_page = apply_filters('ngg_manage_galleries_items_per_page', 25); 
  9.  
  10. $start = ( $_GET['paged'] - 1 ) * $items_per_page; 
  11.  
  12. if (!empty($_GET['order']) && in_array(strtoupper($_GET['order']), array('DESC', 'ASC'))) 
  13. $order = $_GET['order']; 
  14. else 
  15. $order = apply_filters('ngg_manage_galleries_items_order', 'ASC'); 
  16.  
  17. if (!empty($_GET['orderby']) && in_array($_GET['orderby'], array('gid', 'title', 'author'))) 
  18. $orderby = $_GET['orderby']; 
  19. else 
  20. $orderby = apply_filters('ngg_manage_galleries_items_orderby', 'gid'); 
  21.  
  22. $mapper = C_Gallery_Mapper::get_instance(); 
  23. $total_number_of_galleries = $mapper->count(); 
  24. $gallerylist = $mapper->select()->order_by($orderby, $order)->limit($items_per_page, $start)->run_query(); 
  25.  
  26. // Need for upgrading from 2.0.40 to 2.0.52 or later. 
  27. // For some reason, the installer doesn't always run. 
  28. // TODO: Remove in 2.1 
  29. if (!$gallerylist) { 
  30. global $wpdb; 
  31. if ($wpdb->get_results("SELECT gid FROM {$wpdb->nggallery} LIMIT 1")) { 
  32. $installer = new C_NggLegacy_Installer(); 
  33. $installer->install(); 
  34. $gallerylist = $mapper->select()->order_by($orderby, $order)->limit($items_per_page, $start)->run_query(); 
  35. $wp_list_table = new _NGG_Galleries_List_Table('nggallery-manage-gallery'); 
  36.  
  37. ?> 
  38. <script type="text/javascript"> 
  39. <!-- 
  40.  
  41. // Listen for frame events 
  42. jQuery(function($) { 
  43. if ($(this).data('ready')) return; 
  44.  
  45. if (window.Frame_Event_Publisher) { 
  46.  
  47. // If a new gallery is added, refresh the page 
  48. Frame_Event_Publisher.listen_for('attach_to_post:new_gallery attach_to_post:manage_images attach_to_post:images_added', function() { 
  49. window.location.href = window.location.href; 
  50. }); 
  51.  
  52. $(this).data('ready', true); 
  53. }); 
  54.  
  55.  
  56. function checkAll(form) 
  57. for (i = 0, n = form.elements.length; i < n; i++) { 
  58. if(form.elements[i].type == "checkbox") { 
  59. if(form.elements[i].name == "doaction[]") { 
  60. if(form.elements[i].checked == true) 
  61. form.elements[i].checked = false; 
  62. else 
  63. form.elements[i].checked = true; 
  64.  
  65. function getNumChecked(form) 
  66. var num = 0; 
  67. for (i = 0, n = form.elements.length; i < n; i++) { 
  68. if(form.elements[i].type == "checkbox") { 
  69. if(form.elements[i].name == "doaction[]") 
  70. if(form.elements[i].checked == true) 
  71. num++; 
  72. return num; 
  73.  
  74. // this function check for a the number of selected images, sumbmit false when no one selected 
  75. function checkSelected() { 
  76.  
  77. if (typeof document.activeElement == "undefined" && document.addEventListener) { 
  78. document.addEventListener("focus", function (e) { 
  79. document.activeElement = e.target; 
  80. }, true); 
  81.  
  82. if ( document.activeElement.name == 'post_paged' ) 
  83. return true; 
  84.  
  85. var numchecked = getNumChecked(document.getElementById('editgalleries')); 
  86.  
  87. if(numchecked < 1) { 
  88. alert('<?php echo esc_js(__('No images selected', 'nggallery')); ?>'); 
  89. return false; 
  90.  
  91. actionId = jQuery('#bulkaction').val(); 
  92.  
  93. switch (actionId) { 
  94. case "resize_images": 
  95. showDialog('resize_images', '<?php echo esc_js(__('Resize images', 'nggallery')); ?>'); 
  96. return false; 
  97. break; 
  98. case "new_thumbnail": 
  99. showDialog('new_thumbnail', '<?php echo esc_js(__('Create new thumbnails', 'nggallery')); ?>'); 
  100. return false; 
  101. break; 
  102.  
  103. return confirm('<?php echo sprintf(esc_js(__("You are about to start the bulk edit for %s galleries \n \n 'Cancel' to stop, 'OK' to proceed.", 'nggallery')), "' + numchecked + '") ; ?>'); 
  104.  
  105. function showDialog( windowId, title ) { 
  106. var form = document.getElementById('editgalleries'); 
  107. var elementlist = ""; 
  108. for (i = 0, n = form.elements.length; i < n; i++) { 
  109. if(form.elements[i].type == "checkbox") { 
  110. if(form.elements[i].name == "doaction[]") 
  111. if(form.elements[i].checked == true) 
  112. if (elementlist == "") 
  113. elementlist = form.elements[i].value; 
  114. else 
  115. elementlist += ", " + form.elements[i].value ; 
  116. jQuery("#" + windowId + "_bulkaction").val(jQuery("#bulkaction").val()); 
  117. jQuery("#" + windowId + "_imagelist").val(elementlist); 
  118. // now show the dialog 
  119. jQuery( "#" + windowId ).dialog({ 
  120. width: 640,  
  121. resizable : false,  
  122. modal: true,  
  123. title: title,  
  124. position: { 
  125. my: 'center',  
  126. at: 'center',  
  127. of: window.parent 
  128. }); 
  129. jQuery("#" + windowId + ' .dialog-cancel').click(function() { jQuery( "#" + windowId ).dialog("close"); }); 
  130.  
  131. function showAddGallery() { 
  132. jQuery( "#addGallery").dialog({ 
  133. width: 640,  
  134. resizable : false,  
  135. modal: true,  
  136. title: '<?php echo esc_js(__('Add new gallery', 'nggallery')); ?>',  
  137. position: { 
  138. my: 'center',  
  139. at: 'center',  
  140. of: window.parent 
  141. }); 
  142. jQuery("#addGallery .dialog-cancel").click(function() { jQuery( "#addGallery" ).dialog("close"); }); 
  143. //--> 
  144. </script> 
  145. <div class="wrap"> 
  146. <?php screen_icon( 'nextgen-gallery' ); ?> 
  147. <h2><?php echo _n( 'Manage Galleries', 'Manage Galleries', 2, 'nggallery'); ?></h2> 
  148. <form class="search-form" action="" method="get"> 
  149. <p class="search-box"> 
  150. <label class="hidden" for="media-search-input"><?php _e( 'Search Images', 'nggallery' ); ?>:</label> 
  151. <input type="hidden" id="page-name" name="page" value="nggallery-manage-gallery" /> 
  152. <input type="text" id="media-search-input" name="s" value="<?php the_search_query(); ?>" /> 
  153. <input type="submit" value="<?php _e( 'Search Images', 'nggallery' ); ?>" class="button" /> 
  154. </p> 
  155. </form> 
  156. <form id="editgalleries" class="nggform" method="POST" action="<?php echo nextgen_esc_url($ngg->manage_page->base_page . '&orderby=' . $orderby . '&order=' . $order . '&paged=' . $_GET['paged']); ?>" accept-charset="utf-8"> 
  157. <?php wp_nonce_field('ngg_bulkgallery') ?> 
  158. <input type="hidden" name="page" value="manage-galleries" /> 
  159.  
  160. <div class="tablenav top"> 
  161.  
  162. <div class="alignleft actions"> 
  163. <?php if ( function_exists('json_encode') ) : ?> 
  164. <select name="bulkaction" id="bulkaction"> 
  165. <option value="no_action" ><?php _e("Bulk actions", 'nggallery'); ?></option> 
  166. <option value="delete_gallery" ><?php _e("Delete", 'nggallery'); ?></option> 
  167. <option value="set_watermark" ><?php _e("Set watermark", 'nggallery'); ?></option> 
  168. <option value="new_thumbnail" ><?php _e("Create new thumbnails", 'nggallery'); ?></option> 
  169. <option value="resize_images" ><?php _e("Resize images", 'nggallery'); ?></option> 
  170. <option value="import_meta" ><?php _e("Import metadata", 'nggallery'); ?></option> 
  171. <option value="recover_images" ><?php _e("Recover from backup", 'nggallery'); ?></option> 
  172. </select> 
  173. <input name="showThickbox" class="button-secondary" type="submit" value="<?php _e('Apply', 'nggallery'); ?>" onclick="if ( !checkSelected() ) return false;" /> 
  174. <?php endif; ?> 
  175. <?php if ( current_user_can('NextGEN Upload images') && nggGallery::current_user_can( 'NextGEN Add new gallery' ) ) : ?> 
  176. <input name="doaction" class="button-secondary action" type="submit" onclick="showAddGallery(); return false;" value="<?php _e('Add new gallery', 'nggallery') ?>"/> 
  177. <?php endif; ?> 
  178. </div> 
  179.  
  180.  
  181. <?php $ngg->manage_page->pagination( 'top', $_GET['paged'], $total_number_of_galleries, $items_per_page ); ?> 
  182.  
  183. </div> 
  184. <table class="wp-list-table widefat" cellspacing="0"> 
  185. <thead> 
  186. <tr> 
  187. <?php $wp_list_table->print_column_headers(true); ?> 
  188. </tr> 
  189. </thead> 
  190. <tfoot> 
  191. <tr> 
  192. <?php $wp_list_table->print_column_headers(false); ?> 
  193. </tr> 
  194. </tfoot> 
  195. <tbody id="the-list"> 
  196. <?php 
  197.  
  198. if($gallerylist) { 
  199. //get the columns 
  200. $gallery_columns = $wp_list_table->get_columns(); 
  201. $hidden_columns = get_hidden_columns('nggallery-manage-gallery'); 
  202. $num_columns = count($gallery_columns) - count($hidden_columns); 
  203. $image_mapper = C_Image_Mapper::get_instance(); 
  204.  
  205. foreach($gallerylist as $gallery) { 
  206. $alternate = ( !isset($alternate) || $alternate == 'class="alternate"' ) ? '' : 'class="alternate"'; 
  207. $gid = $gallery->gid; 
  208. $name = (empty($gallery->title) ) ? $gallery->name : $gallery->title; 
  209. $author_user = get_userdata( (int) $gallery->author ); 
  210. ?> 
  211. <tr id="gallery-<?php echo $gid ?>" <?php echo $alternate; ?> > 
  212. <?php 
  213. foreach($gallery_columns as $gallery_column_key => $column_display_name) { 
  214. $class = "class=\"$gallery_column_key column-$gallery_column_key\""; 
  215.  
  216. $style = ''; 
  217. if ( in_array($gallery_column_key, $hidden_columns) ) 
  218. $style = ' style="display:none;"'; 
  219.  
  220. $attributes = "$class$style"; 
  221.  
  222. switch ($gallery_column_key) { 
  223. case 'cb' : 
  224. ?> 
  225. <th scope="row" class="column-cb check-column"> 
  226. <?php if (nggAdmin::can_manage_this_gallery($gallery->author)) { ?> 
  227. <input name="doaction[]" type="checkbox" value="<?php echo $gid ?>" /> 
  228. <?php } ?> 
  229. </th> 
  230. <?php 
  231. break; 
  232. case 'id' : 
  233. ?> 
  234. <td <?php echo $attributes ?>><?php echo $gid; ?></td> 
  235. <?php 
  236. break; 
  237. case 'title' : 
  238. ?> 
  239. <td class="title column-title"> 
  240. <?php if (nggAdmin::can_manage_this_gallery($gallery->author)) { ?> 
  241. <a href="<?php echo wp_nonce_url( $ngg->manage_page->base_page . '&mode=edit&gid=' . $gid, 'ngg_editgallery')?>" class='edit' title="<?php _e('Edit'); ?>" > 
  242. <?php echo esc_html( M_I18N::translate($name) ); ?> 
  243. </a> 
  244. <?php } else { ?> 
  245. <?php echo esc_html( M_I18N::translate($gallery->title) ); ?> 
  246. <?php } ?> 
  247. <div class="row-actions"></div> 
  248. </td> 
  249. <?php 
  250. break; 
  251. case 'description' : 
  252. ?> 
  253. <td <?php echo $attributes ?>><?php echo esc_html( M_I18N::translate($gallery->galdesc) ); ?> </td> 
  254. <?php 
  255. break; 
  256. case 'author' : 
  257. ?> 
  258. <td <?php echo $attributes ?>><?php echo esc_html( $author_user->display_name ); ?></td> 
  259. <?php 
  260. break; 
  261. case 'page_id' : 
  262. ?> 
  263. <td <?php echo $attributes ?>><?php echo $gallery->pageid; ?></td> 
  264. <?php 
  265. break; 
  266. case 'quantity' : 
  267. $gallery->counter = count( 
  268. $image_mapper->select($image_mapper->get_primary_key_column())-> 
  269. where(array("galleryid = %d", $gallery->{$gallery->id_field}))-> 
  270. run_query(FALSE, FALSE, TRUE) 
  271. ); 
  272.  
  273. ?> 
  274. <td <?php echo $attributes ?>><?php echo $gallery->counter; ?></td> 
  275. <?php 
  276. break; 
  277. default : 
  278. ?> 
  279. <td <?php echo $attributes ?>><?php do_action('ngg_manage_gallery_custom_column', $gallery_column_key, $gid); ?></td> 
  280. <?php 
  281. break; 
  282. } ?> 
  283. </tr> 
  284. <?php 
  285. } else { 
  286. echo '<tr><td colspan="7" align="center"><strong>' . __('No entries found', 'nggallery') . '</strong></td></tr>'; 
  287. ?> 
  288. </tbody> 
  289. </table> 
  290. <div class="tablenav bottom"> 
  291. <?php $ngg->manage_page->pagination( 'bottom', $_GET['paged'], $total_number_of_galleries, $items_per_page ); ?> 
  292. </div> 
  293. </form> 
  294. </div> 
  295. <!-- #addGallery --> 
  296. <div id="addGallery" style="display: none;" > 
  297. <form id="form-tags" method="POST" accept-charset="utf-8"> 
  298. <?php wp_nonce_field('ngg_addgallery'); ?> 
  299. <input type="hidden" name="page" value="manage-galleries" /> 
  300. <table width="100%" border="0" cellspacing="3" cellpadding="3" > 
  301. <tr> 
  302. <td> 
  303. <strong><?php _e('New Gallery', 'nggallery') ;?>:</strong> <input type="text" size="35" name="galleryname" value="" /><br /> 
  304. <?php if(!is_multisite()) { ?> 
  305. <?php _e('Create a new , empty gallery below the folder', 'nggallery') ;?> <strong><?php echo $ngg->options['gallerypath']; ?></strong><br /> 
  306. <?php } ?> 
  307. <i>( <?php _e('Allowed characters for file and folder names are', 'nggallery') ;?>: a-z, A-Z, 0-9, -, _ )</i> 
  308. </td> 
  309. </tr> 
  310. <?php do_action('ngg_add_new_gallery_form'); ?> 
  311. <tr align="right"> 
  312. <td class="submit"> 
  313. <input class="button-primary" type="submit" name="addgallery" value="<?php _e('OK', 'nggallery'); ?>" /> 
  314.   
  315. <input class="button-secondary dialog-cancel" type="reset" value=" <?php _e('Cancel', 'nggallery'); ?> " /> 
  316. </td> 
  317. </tr> 
  318. </table> 
  319. </form> 
  320. </div> 
  321. <!-- /#addGallery --> 
  322.  
  323. <!-- #resize_images --> 
  324. <div id="resize_images" style="display: none;" > 
  325. <form id="form-resize-images" method="POST" accept-charset="utf-8"> 
  326. <?php wp_nonce_field('ngg_thickbox_form') ?> 
  327. <input type="hidden" id="resize_images_imagelist" name="TB_imagelist" value="" /> 
  328. <input type="hidden" id="resize_images_bulkaction" name="TB_bulkaction" value="" /> 
  329. <input type="hidden" name="page" value="manage-galleries" /> 
  330. <table width="100%" border="0" cellspacing="3" cellpadding="3" > 
  331. <tr valign="top"> 
  332. <td> 
  333. <strong><?php _e('Resize Images to', 'nggallery'); ?>:</strong> 
  334. </td> 
  335. <td> 
  336. <input type="text" size="5" name="imgWidth" value="<?php echo $ngg->options['imgWidth']; ?>" /> x <input type="text" size="5" name="imgHeight" value="<?php echo $ngg->options['imgHeight']; ?>" /> 
  337. <br /><small><?php _e('Width x height (in pixel). NextGEN Gallery will keep ratio size', 'nggallery') ?></small> 
  338. </td> 
  339. </tr> 
  340. <tr align="right"> 
  341. <td colspan="2" class="submit"> 
  342. <input class="button-primary" type="submit" name="TB_ResizeImages" value="<?php _e('OK', 'nggallery'); ?>" /> 
  343.   
  344. <input class="button-secondary dialog-cancel" type="reset" value=" <?php _e('Cancel', 'nggallery'); ?> " /> 
  345. </td> 
  346. </tr> 
  347. </table> 
  348. </form> 
  349. </div> 
  350. <!-- /#resize_images --> 
  351.  
  352. <!-- #new_thumbnail --> 
  353. <div id="new_thumbnail" style="display: none;" > 
  354. <form id="form-new-thumbnail" method="POST" accept-charset="utf-8"> 
  355. <?php wp_nonce_field('ngg_thickbox_form') ?> 
  356. <input type="hidden" id="new_thumbnail_imagelist" name="TB_imagelist" value="" /> 
  357. <input type="hidden" id="new_thumbnail_bulkaction" name="TB_bulkaction" value="" /> 
  358. <input type="hidden" name="page" value="manage-galleries" /> 
  359. <table width="100%" border="0" cellspacing="3" cellpadding="3" > 
  360. <tr valign="top"> 
  361. <th align="left"><?php _e('Width x height (in pixel)', 'nggallery') ?></th> 
  362. <td> 
  363. <?php include(dirname(__FILE__) . '/thumbnails-template.php'); ?> 
  364. </td> 
  365. </tr> 
  366. <tr valign="top"> 
  367. <th align="left"><?php _e('Set fix dimension', 'nggallery') ?></th> 
  368. <td><input type="checkbox" name="thumbfix" value="1" <?php checked('1', $ngg->options['thumbfix']); ?> /> 
  369. <br /><small><?php _e('Ignore the aspect ratio, no portrait thumbnails', 'nggallery') ?></small></td> 
  370. </tr> 
  371. <tr align="right"> 
  372. <td colspan="2" class="submit"> 
  373. <input class="button-primary" type="submit" name="TB_NewThumbnail" value="<?php _e('OK', 'nggallery');?>" /> 
  374.   
  375. <input class="button-secondary dialog-cancel" type="reset" value=" <?php _e('Cancel', 'nggallery'); ?> " /> 
  376. </td> 
  377. </tr> 
  378. </table> 
  379. </form> 
  380. </div> 
  381. <!-- /#new_thumbnail --> 
  382.  
  383. <?php