function processor() { global $wpdb; check_admin_referer('ngg_album'); if (isset($_POST['add']) && isset($_POST['newalbum'])) { if (!nggGallery::current_user_can('NextGEN Add/Delete album')) { wp_die(__('Cheatin’ uh?')); } $result = nggdb::add_album($_POST['newalbum']); $this->currentID = $result ? $result : 0; //hook for other plugins do_action('ngg_add_album', $this->currentID); if ($result) { nggGallery::show_message(__('Update Successfully', 'nggallery')); } } if (isset($_POST['update']) && $this->currentID > 0) { $gid = ''; // get variable galleryContainer parse_str($_POST['sortorder']); if (is_array($gid)) { $serial_sort = serialize($gid); $wpdb->query("UPDATE {$wpdb->nggalbum} SET sortorder = '{$serial_sort}' WHERE id = {$this->currentID} "); } else { $wpdb->query("UPDATE {$wpdb->nggalbum} SET sortorder = '0' WHERE id = {$this->currentID} "); } //hook for other plugins do_action('ngg_update_album_sortorder', $this->currentID); nggGallery::show_message(__('Update Successfully', 'nggallery')); } if (isset($_POST['delete'])) { if (!nggGallery::current_user_can('NextGEN Add/Delete album')) { wp_die(__('Cheatin’ uh?')); } $result = nggdb::delete_album($this->currentID); //hook for other plugins do_action('ngg_delete_album', $this->currentID); // jump back to main selection $this->currentID = 0; if ($result) { nggGallery::show_message(__('Album deleted', 'nggallery')); } } }
function processor() { global $wpdb; check_admin_referer('ngg_album'); if (isset($_POST['add']) && isset($_POST['newalbum'])) { $newalbum = esc_attr($_POST['newalbum']); $result = $wpdb->query("INSERT INTO {$wpdb->nggalbum} (name, sortorder) VALUES ('{$newalbum}','0')"); $this->currentID = (int) $wpdb->insert_id; if ($result) { nggGallery::show_message(__('Update Successfully', 'nggallery')); } } if (isset($_POST['update']) && $this->currentID > 0) { // get variable galleryContainer parse_str($_POST['sortorder']); if (is_array($gid)) { $serial_sort = serialize($gid); $wpdb->query("UPDATE {$wpdb->nggalbum} SET sortorder = '{$serial_sort}' WHERE id = {$this->currentID} "); } else { $wpdb->query("UPDATE {$wpdb->nggalbum} SET sortorder = '0' WHERE id = {$this->currentID} "); } nggGallery::show_message(__('Update Successfully', 'nggallery')); } if (isset($_POST['delete'])) { $result = nggdb::delete_album($this->currentID); if ($result) { nggGallery::show_message(__('Album deleted', 'nggallery')); } } }
function nggallery_admin_manage_album() { global $wpdb; $albumID = (int) $_POST['act_album']; if ($_POST['update']) { check_admin_referer('ngg_album'); if ($_POST['newalbum']) { $newalbum = attribute_escape($_POST['newalbum']); $result = $wpdb->query("INSERT INTO {$wpdb->nggalbum} (name, sortorder) VALUES ('{$newalbum}','0')"); if ($result) { nggGallery::show_message(__('Update Successfully', 'nggallery')); } } if ($albumID > 0) { // get variable galleryContainer parse_str($_POST['sortorder']); if (is_array($gid)) { $serial_sort = serialize($gid); $wpdb->query("UPDATE {$wpdb->nggalbum} SET sortorder = '{$serial_sort}' WHERE id = {$albumID} "); } else { $wpdb->query("UPDATE {$wpdb->nggalbum} SET sortorder = '0' WHERE id = {$albumID} "); } nggGallery::show_message(__('Update Successfully', 'nggallery')); } } if ($_POST['delete']) { check_admin_referer('ngg_album'); $result = nggdb::delete_album($albumID); if ($result) { nggGallery::show_message(__('Album deleted', 'nggallery')); } } ?> <script type="text/javascript"> jQuery(document).ready( function() { jQuery('#selectContainer').sortable( { items: '.groupItem', placeholder: 'sort_placeholder', opacity: 0.7, tolerance: 'intersect', distance: 2, connectWith: ["#galleryContainer"] } ); jQuery('#galleryContainer').sortable( { items: '.groupItem', placeholder: 'sort_placeholder', opacity: 0.7, tolerance: 'intersect', distance: 2, connectWith: ["#selectContainer"] } ); jQuery('a.min').bind('click', toggleContent); // Hide used galleries jQuery('a#toggle_used').click(function() { jQuery('#selectContainer div.inUse').toggle(); return false; } ); // Maximize All Portlets (whole site, no differentiation) jQuery('a#all_max').click(function() { jQuery('div.itemContent:hidden').show(); return false; } ); // Minimize All Portlets (whole site, no differentiation) jQuery('a#all_min').click(function() { jQuery('div.itemContent:visible').hide(); return false; } ); // Auto Minimize if more than 4 (whole site, no differentiation) if(jQuery('a.min').length > 4) { jQuery('a.min').html('[+]'); jQuery('div.itemContent:visible').hide(); jQuery('#selectContainer div.inUse').toggle(); }; } ); var toggleContent = function(e) { var targetContent = jQuery('div.itemContent', this.parentNode.parentNode); if (targetContent.css('display') == 'none') { targetContent.slideDown(300); jQuery(this).html('[-]'); } else { targetContent.slideUp(300); jQuery(this).html('[+]'); } return false; } function ngg_serialize(s) { //serial = jQuery.SortSerialize(s); serial = jQuery('#galleryContainer').sortable('serialize'); jQuery('input[@name=sortorder]').val(serial); } </script> <div class="wrap album" id="wrap" > <h2><?php _e('Manage Albums', 'nggallery'); ?> </h2> <form id="selectalbum" method="POST" onsubmit="ngg_serialize()" accept-charset="utf-8"> <?php wp_nonce_field('ngg_album'); ?> <input name="sortorder" type="hidden" /> <div class="tablenav"> <div class="alignleft actions"> <?php _e('Select album', 'nggallery'); ?> <select id="act_album" name="act_album" onchange="this.form.submit();"> <option value="0" ><?php _e('No album selected', 'nggallery'); ?> </option> <?php $albumlist = $wpdb->get_results("SELECT * FROM {$wpdb->nggalbum} ORDER BY id ASC"); if (is_array($albumlist)) { foreach ($albumlist as $album) { if ($_POST['act_album'] == $album->id) { $selected = 'selected="selected" '; } else { $selected = ''; } echo '<option value="' . $album->id . '" ' . $selected . '>' . $album->name . '</option>' . "\n"; } } ?> </select> <?php if ($_POST['act_album'] > 0) { ?> <input class="button-primary action" type="submit" name="update" value="<?php _e('Update', 'nggallery'); ?> "/> <input type="submit" name="delete" class="button-secondary action" value="<?php _e('Delete', 'nggallery'); ?> " onclick="javascript:check=confirm('<?php _e('Delete album ?', 'nggallery'); ?> ');if(check==false) return false;"/> <?php } else { ?> <span><?php _e('Add new album', 'nggallery'); ?> </span><input class="search-input" id="newalbum" name="newalbum" type="text" value="" /> <input class="button-secondary action" type="submit" name="update" value="<?php _e('Add', 'nggallery'); ?> "/> <?php } ?> </div> </div> </form> <br style="clear: both;"/> <p> <div style="float:right;"> <a href="#" id="toggle_used"><?php _e('[Show all]', 'nggallery'); ?> </a> | <a href="#" id="all_max"><?php _e('[Maximize]', 'nggallery'); ?> </a> | <a href="#" id="all_min"><?php _e('[Minimize]', 'nggallery'); ?> </a> </div> <?php _e('After you create and select a album, you can drag and drop a gallery into your album below', 'nggallery'); ?> </p> <br class="clear"/> <div class="container"> <div id="selectContainer" class="groupWrapper"> <h3><?php _e('Select Gallery', 'nggallery'); ?> </h3> <?php $gallerylist = $wpdb->get_results("SELECT gid FROM {$wpdb->nggallery}"); //TODO:Code MUST be optimized, how to flag a used gallery better ? $used_list = getallusedgalleries(); if (is_array($gallerylist)) { if ($_POST['act_album'] == 0 or !isset($_POST['act_album'])) { foreach ($gallerylist as $gallery) { if (in_array($gallery->gid, $used_list)) { getgallerycontainer($gallery->gid, true); } else { getgallerycontainer($gallery->gid, false); } } } else { $act_album = $_POST['act_album']; $sortorder = $wpdb->get_var("SELECT sortorder FROM {$wpdb->nggalbum} WHERE id = '{$act_album}'"); $sort_array = unserialize($sortorder); // if something went wrong, initialize to empty array if (!is_array($sort_array)) { $sort_array = array(); } foreach ($gallerylist as $gallery) { if (!in_array($gallery->gid, $sort_array)) { if (in_array($gallery->gid, $used_list)) { getgallerycontainer($gallery->gid, true); } else { getgallerycontainer($gallery->gid, false); } } } } } ?> </div><!-- /#select container --> <div id="galleryContainer" class="groupWrapper"> <?php if ($_POST['act_album'] > 0) { $act_album = $_POST['act_album']; $album = $wpdb->get_row("SELECT * FROM {$wpdb->nggalbum} WHERE id = '{$act_album}'"); echo '<h3>' . __('Album Page ID', 'nggallery') . ' ' . $album->id . ' : ' . $album->name . '</h3>' . "\n"; if (!empty($album->sortorder)) { $sort_array = unserialize($album->sortorder); if (is_array($sort_array)) { foreach ($sort_array as $galleryid) { getgallerycontainer($galleryid, false); } } } } else { echo '<h3>' . __('No album selected!', 'nggallery') . '</h3>'; } ?> </div><!-- /#gallery container --> </div><!-- /#container --> </div><!-- /#wrap --> <?php }
function processor() { global $wpdb; check_admin_referer('ngg_album'); // Create album if (isset($_POST['add']) && isset($_POST['newalbum'])) { if (!nggGallery::current_user_can('NextGEN Add/Delete album')) { wp_die(__('Cheatin’ uh?')); } $album = new stdClass(); $album->name = $_POST['newalbum']; $result = $this->get_album_mapper()->save($album); $this->currentID = $album->{$album->id_field}; if (!$this->currentID) { $this->currentID = 0; } //hook for other plugins do_action('ngg_add_album', $this->currentID); if ($result) { nggGallery::show_message(__('Update Successfully', 'nggallery')); } } if (isset($_POST['update']) && $this->currentID > 0) { $gid = array(); // Get the current album being updated $album = $this->get_album_mapper()->find($this->currentID); // Get the list of galleries/sub-albums to be added to this album parse_str($_REQUEST['sortorder']); // Set the new sortorder $album->sortorder = $gid; // Ensure that a preview pic has been sent $this->_set_album_preview_pic($album); // Save the changes $this->get_album_mapper()->save($album); //hook for other plugins do_action('ngg_update_album_sortorder', $this->currentID); nggGallery::show_message(__('Update Successfully', 'nggallery')); } if (isset($_POST['delete'])) { if (!nggGallery::current_user_can('NextGEN Add/Delete album')) { wp_die(__('Cheatin’ uh?')); } $result = nggdb::delete_album($this->currentID); //hook for other plugins do_action('ngg_delete_album', $this->currentID); // jump back to main selection $this->currentID = 0; if ($result) { nggGallery::show_message(__('Album deleted', 'nggallery')); } } }