/products/photocrati_nextgen/modules/ngglegacy/admin/manage-galleries.php

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