__construct(); } /** * Init the album output * */ function __construct() { return true; } function controller() { global $nggdb; $this->currentID = isset($_REQUEST['act_album']) ? (int) $_REQUEST['act_album'] : 0 ; if (isset ($_POST['update']) || isset( $_POST['delete'] ) || isset( $_POST['add'] ) ) $this->processor(); if (isset ($_POST['update_album']) ) $this->update_album(); // get first all galleries & albums $this->albums = $nggdb->find_all_album(); $this->galleries = $nggdb->find_all_galleries(); $this->num_albums = count( $this->albums ); $this->num_galleries = count( $this->galleries ); $this->output(); } 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 update_album() { global $wpdb, $nggdb; check_admin_referer('ngg_thickbox_form'); if (!nggGallery::current_user_can( 'NextGEN Edit album settings' )) wp_die(__('Cheatin’ uh?')); $name = $_POST['album_name']; $desc = $_POST['album_desc']; $prev = (int) $_POST['previewpic']; $link = (int) $_POST['pageid']; // slug must be unique, we use the title for that $slug = nggdb::get_unique_slug( sanitize_title( $name ), 'album', $this->currentID ); $result = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->nggalbum SET slug= '%s', name= '%s', albumdesc= '%s', previewpic= %d, pageid= %d WHERE id = '%d'" , $slug, $name, $desc, $prev, $link, $this->currentID ) ); //hook for other plugin to update the fields do_action('ngg_update_album', $this->currentID, $_POST); if ($result) nggGallery::show_message(__('Update Successfully','nggallery')); } function output() { global $wpdb, $nggdb; //TODO:Code MUST be optimized, how to flag a used gallery better ? $used_list = $this->get_used_galleries(); ?>

currentID > 0){ ?>  

| |

albums ) ) { foreach($this->albums as $album) { $this->get_container('a' . $album->id); } } ?>

galleries ) ) { //get the array of galleries $sort_array = $this->currentID > 0 ? (array) $this->albums[$this->currentID]->galleries : array() ; foreach($this->galleries as $gallery) { if (!in_array($gallery->gid, $sort_array)) { if (in_array($gallery->gid,$used_list)) $this->get_container($gallery->gid,true); else $this->get_container($gallery->gid,false); } } } ?>
currentID > 0){ $album = $this->albums[$this->currentID]; ?>

id . ' : ' . esc_html( $album->name ); ?>

albums[$this->currentID]->galleries; foreach($sort_array as $galleryid) { $this->get_container($galleryid, false); } } else { ?>

currentID > 0) : ?> albums[ substr( $id, 1) ] ) return; $obj['id'] = $album->id; $obj['name'] = $obj['title'] = $album->name; $obj['type'] = 'album'; $class = 'album_obj'; // get the post name $post = get_post($album->pageid); $obj['pagenname'] = ($post == null) ? '---' : $post->post_title; // for speed reason we limit it to 50 if ( $this->num_albums < 50 ) { if ($album->previewpic != 0) { $image = $nggdb->find_image( $album->previewpic ); $preview_image = ( !is_null($image->thumbURL) ) ? '
' : ''; } } // this indicates that we have a album container $prefix = 'a'; } else { if ( !$gallery = $nggdb->find_gallery( $id ) ) return; $obj['id'] = $gallery->gid; $obj['name'] = $gallery->name; $obj['title'] = $gallery->title; $obj['type'] = 'gallery'; // get the post name $post = get_post($gallery->pageid); $obj['pagenname'] = ($post == null) ? '---' : $post->post_title; // for spped reason we limit it to 50 if ( $this->num_galleries < 50 ) { // set image url $image = $nggdb->find_image( $gallery->previewpic ); $preview_image = isset($image->thumbURL) ? '
' : ''; } $prefix = ''; } // add class if it's in use in other albums $used = $used ? ' inUse' : ''; echo '
[-] ID: ' . $obj['id'] . ' | ' . wp_html_excerpt( esc_html ( nggGallery::i18n( $obj['title'] ) ) , 25) . '
' . $preview_image . '

' . __('Name', 'nggallery') . ' : ' . esc_html ( nggGallery::i18n( $obj['name'] ) ). '

' . __('Title', 'nggallery') . ' : ' . esc_html ( nggGallery::i18n( $obj['title'] ) ) . '

' . __('Page', 'nggallery'). ' : ' . esc_html ( nggGallery::i18n( $obj['pagenname'] ) ) . '

' . apply_filters('ngg_display_album_item_content', '', $obj) . '
'; } /** * get all used galleries from all albums * * @return array $used_galleries_ids */ function get_used_galleries() { $used = array(); if ($this->albums) { foreach($this->albums as $key => $value) { $sort_array = $this->albums[$key]->galleries; foreach($sort_array as $galleryid) { if (!in_array($galleryid, $used)) $used[] = $galleryid; } } } return $used; } /** * PHP5 style destructor * * @return bool Always true */ function __destruct() { return true; } }