Exemple #1
0
 /**
  * Import a ZIP file via a upload form or a URL
  * 
  * @class nggAdmin
  * @param int (optional) $galleryID
  * @return bool $result
  */
 function import_zipfile($galleryID)
 {
     global $ngg, $wpdb;
     if (nggWPMU::check_quota()) {
         return false;
     }
     $defaultpath = $ngg->options['gallerypath'];
     $zipurl = $_POST['zipurl'];
     // if someone entered a URL try to upload it
     if (!empty($zipurl) && function_exists('curl_init')) {
         if (!preg_match('/^http(s)?:\\/\\//i', $zipurl)) {
             nggGallery::show_error(__('No valid URL path ', 'nggallery'));
             return false;
         }
         $temp_zipfile = tempnam('/tmp', 'zipimport_');
         $filename = basename($zipurl);
         //Grab the zip via cURL
         $save = fopen($temp_zipfile, "w");
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_FILE, $save);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
         curl_setopt($ch, CURLOPT_URL, $zipurl);
         $success = curl_exec($ch);
         if (!$success) {
             nggGallery::show_error(__('Import via cURL failed.', 'nggallery') . ' Error code ' . curl_errno($ch) . ' : ' . curl_error($ch));
         }
         curl_close($ch);
         fclose($save);
         if (!$success) {
             return false;
         }
     } else {
         $temp_zipfile = $_FILES['zipfile']['tmp_name'];
         $filename = $_FILES['zipfile']['name'];
         // Chrome return a empty content-type : http://code.google.com/p/chromium/issues/detail?id=6800
         if (!preg_match('/chrome/i', $_SERVER['HTTP_USER_AGENT'])) {
             // check if file is a zip file
             if (!preg_match('/(zip|download|octet-stream)/i', $_FILES['zipfile']['type'])) {
                 @unlink($temp_zipfile);
                 // del temp file
                 nggGallery::show_error(__('Uploaded file was no or a faulty zip file ! The server recognized : ', 'nggallery') . $_FILES['zipfile']['type']);
                 return false;
             }
         }
     }
     // should this unpacked into a new folder ?
     if ($galleryID == '0') {
         //cleanup and take the zipfile name as folder name
         $foldername = sanitize_title(strtok($filename, '.'));
         $foldername = $defaultpath . $foldername;
     } else {
         // get foldername if selected
         $foldername = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$galleryID}' ");
     }
     if (empty($foldername)) {
         nggGallery::show_error(__('Could not get a valid foldername', 'nggallery'));
         return false;
     }
     // set complete folder path
     $newfolder = WINABSPATH . $foldername;
     // check first if the traget folder exist
     if (!is_dir($newfolder)) {
         // create new directories
         if (!wp_mkdir_p($newfolder)) {
             $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?', 'nggallery'), $newfolder);
             nggGallery::show_error($message);
             return false;
         }
         if (!wp_mkdir_p($newfolder . '/thumbs')) {
             nggGallery::show_error(__('Unable to create directory ', 'nggallery') . $newfolder . '/thumbs !');
             return false;
         }
     }
     // unzip and del temp file
     $result = nggAdmin::unzip($newfolder, $temp_zipfile);
     @unlink($temp_zipfile);
     if ($result) {
         $message = __('Zip-File successfully unpacked', 'nggallery') . '<br />';
         // parse now the folder and add to database
         $message .= nggAdmin::import_gallery($foldername);
         nggGallery::show_message($message);
     }
     return true;
 }
Exemple #2
0
 /**
  * Perform the upload and add a new hook for plugins
  * 
  * @return void
  */
 function processor()
 {
     global $wpdb, $ngg, $nggdb;
     $defaultpath = $ngg->options['gallerypath'];
     if (isset($_POST['addgallery'])) {
         check_admin_referer('ngg_addgallery');
         if (!nggGallery::current_user_can('NextGEN Add new gallery')) {
             wp_die(__('Cheatin&#8217; uh?'));
         }
         $newgallery = esc_attr($_POST['galleryname']);
         if (!empty($newgallery)) {
             nggAdmin::create_gallery($newgallery, $defaultpath);
         }
     }
     if (isset($_POST['zipupload'])) {
         check_admin_referer('ngg_addgallery');
         if (!nggGallery::current_user_can('NextGEN Upload a zip')) {
             wp_die(__('Cheatin&#8217; uh?'));
         }
         if ($_FILES['zipfile']['error'] == 0 || !empty($_POST['zipurl'])) {
             nggAdmin::import_zipfile(intval($_POST['zipgalselect']));
         } else {
             nggGallery::show_error(__('Upload failed!', 'nggallery'));
         }
     }
     if (isset($_POST['importfolder'])) {
         check_admin_referer('ngg_addgallery');
         if (!nggGallery::current_user_can('NextGEN Import image folder')) {
             wp_die(__('Cheatin&#8217; uh?'));
         }
         $galleryfolder = $_POST['galleryfolder'];
         if (!empty($galleryfolder) and $defaultpath != $galleryfolder) {
             nggAdmin::import_gallery($galleryfolder);
         }
     }
     if (isset($_POST['uploadimage'])) {
         check_admin_referer('ngg_addgallery');
         if (!nggGallery::current_user_can('NextGEN Upload in all galleries')) {
             wp_die(__('Cheatin&#8217; uh?'));
         }
         if ($_FILES['imagefiles']['error'][0] == 0) {
             $messagetext = nggAdmin::upload_images();
         } else {
             nggGallery::show_error(__('Upload failed! ' . nggAdmin::decode_upload_error($_FILES['imagefiles']['error'][0]), 'nggallery'));
         }
     }
     if (isset($_POST['swf_callback'])) {
         if ($_POST['galleryselect'] == '0') {
             nggGallery::show_error(__('No gallery selected !', 'nggallery'));
         } else {
             if ($_POST['swf_callback'] == '-1') {
                 nggGallery::show_error(__('Upload failed! ', 'nggallery'));
             } else {
                 $gallery = $nggdb->find_gallery((int) $_POST['galleryselect']);
                 nggAdmin::import_gallery($gallery->path);
             }
         }
     }
     if (isset($_POST['disable_flash'])) {
         check_admin_referer('ngg_addgallery');
         $ngg->options['swfUpload'] = false;
         update_option('ngg_options', $ngg->options);
     }
     if (isset($_POST['enable_flash'])) {
         check_admin_referer('ngg_addgallery');
         $ngg->options['swfUpload'] = true;
         update_option('ngg_options', $ngg->options);
     }
     do_action('ngg_update_addgallery_page');
 }
Exemple #3
0
 function post_processor_images()
 {
     global $wpdb, $ngg, $nggdb;
     // bulk update in a single gallery
     if (isset($_POST['bulkaction']) && isset($_POST['doaction'])) {
         check_admin_referer('ngg_updategallery');
         switch ($_POST['bulkaction']) {
             case 'no_action':
                 break;
             case 'rotate_cw':
                 nggAdmin::do_ajax_operation('rotate_cw', $_POST['doaction'], __('Rotate images', 'nggallery'));
                 break;
             case 'rotate_ccw':
                 nggAdmin::do_ajax_operation('rotate_ccw', $_POST['doaction'], __('Rotate images', 'nggallery'));
                 break;
             case 'recover_images':
                 nggAdmin::do_ajax_operation('recover_image', $_POST['doaction'], __('Recover from backup', 'nggallery'));
                 break;
             case 'set_watermark':
                 nggAdmin::do_ajax_operation('set_watermark', $_POST['doaction'], __('Set watermark', 'nggallery'));
                 break;
             case 'delete_images':
                 if (is_array($_POST['doaction'])) {
                     foreach ($_POST['doaction'] as $imageID) {
                         $image = $nggdb->find_image($imageID);
                         if ($image) {
                             if ($ngg->options['deleteImg']) {
                                 @unlink($image->imagePath);
                                 @unlink($image->thumbPath);
                                 @unlink($image->imagePath . "_backup");
                             }
                             do_action('ngg_delete_picture', $image->pid);
                             $delete_pic = nggdb::delete_image($image->pid);
                         }
                     }
                     if ($delete_pic) {
                         nggGallery::show_message(__('Pictures deleted successfully ', 'nggallery'));
                     }
                 }
                 break;
             case 'import_meta':
                 nggAdmin::do_ajax_operation('import_metadata', $_POST['doaction'], __('Import metadata', 'nggallery'));
                 break;
         }
     }
     if (isset($_POST['TB_bulkaction']) && isset($_POST['TB_ResizeImages'])) {
         check_admin_referer('ngg_thickbox_form');
         //save the new values for the next operation
         $ngg->options['imgWidth'] = (int) $_POST['imgWidth'];
         $ngg->options['imgHeight'] = (int) $_POST['imgHeight'];
         update_option('ngg_options', $ngg->options);
         $pic_ids = explode(',', $_POST['TB_imagelist']);
         nggAdmin::do_ajax_operation('resize_image', $pic_ids, __('Resize images', 'nggallery'));
     }
     if (isset($_POST['TB_bulkaction']) && isset($_POST['TB_NewThumbnail'])) {
         check_admin_referer('ngg_thickbox_form');
         //save the new values for the next operation
         $ngg->options['thumbwidth'] = (int) $_POST['thumbwidth'];
         $ngg->options['thumbheight'] = (int) $_POST['thumbheight'];
         $ngg->options['thumbfix'] = isset($_POST['thumbfix']) ? true : false;
         update_option('ngg_options', $ngg->options);
         $pic_ids = explode(',', $_POST['TB_imagelist']);
         nggAdmin::do_ajax_operation('create_thumbnail', $pic_ids, __('Create new thumbnails', 'nggallery'));
     }
     if (isset($_POST['TB_bulkaction']) && isset($_POST['TB_SelectGallery'])) {
         check_admin_referer('ngg_thickbox_form');
         $pic_ids = explode(',', $_POST['TB_imagelist']);
         $dest_gid = (int) $_POST['dest_gid'];
         switch ($_POST['TB_bulkaction']) {
             case 'copy_to':
                 // Copy images
                 nggAdmin::copy_images($pic_ids, $dest_gid);
                 break;
             case 'move_to':
                 // Move images
                 nggAdmin::move_images($pic_ids, $dest_gid);
                 break;
         }
     }
     if (isset($_POST['TB_bulkaction']) && isset($_POST['TB_EditTags'])) {
         // do tags update
         check_admin_referer('ngg_thickbox_form');
         // get the images list
         $pic_ids = explode(',', $_POST['TB_imagelist']);
         $taglist = explode(',', $_POST['taglist']);
         $taglist = array_map('trim', $taglist);
         if (is_array($pic_ids)) {
             foreach ($pic_ids as $pic_id) {
                 // which action should be performed ?
                 switch ($_POST['TB_bulkaction']) {
                     case 'no_action':
                         // No action
                         break;
                     case 'overwrite_tags':
                         // Overwrite tags
                         wp_set_object_terms($pic_id, $taglist, 'ngg_tag');
                         break;
                     case 'add_tags':
                         // Add / append tags
                         wp_set_object_terms($pic_id, $taglist, 'ngg_tag', TRUE);
                         break;
                     case 'delete_tags':
                         // Delete tags
                         $oldtags = wp_get_object_terms($pic_id, 'ngg_tag', 'fields=names');
                         // get the slugs, to vaoid  case sensitive problems
                         $slugarray = array_map('sanitize_title', $taglist);
                         $oldtags = array_map('sanitize_title', $oldtags);
                         // compare them and return the diff
                         $newtags = array_diff($oldtags, $slugarray);
                         wp_set_object_terms($pic_id, $newtags, 'ngg_tag');
                         break;
                 }
             }
             nggGallery::show_message(__('Tags changed', 'nggallery'));
         }
     }
     if (isset($_POST['updatepictures'])) {
         // Update pictures
         check_admin_referer('ngg_updategallery');
         if (nggGallery::current_user_can('NextGEN Edit gallery options') && !isset($_GET['s'])) {
             if (nggGallery::current_user_can('NextGEN Edit gallery title')) {
                 // don't forget to update the slug
                 $slug = nggdb::get_unique_slug(sanitize_title($_POST['title']), 'gallery', $this->gid);
                 $wpdb->query($wpdb->prepare("UPDATE {$wpdb->nggallery} SET title= '%s', slug= '%s' WHERE gid = %d", esc_attr($_POST['title']), $slug, $this->gid));
             }
             if (nggGallery::current_user_can('NextGEN Edit gallery path')) {
                 $wpdb->query($wpdb->prepare("UPDATE {$wpdb->nggallery} SET path= '%s' WHERE gid = %d", untrailingslashit(str_replace('\\', '/', trim(stripslashes($_POST['path'])))), $this->gid));
             }
             if (nggGallery::current_user_can('NextGEN Edit gallery description')) {
                 $wpdb->query($wpdb->prepare("UPDATE {$wpdb->nggallery} SET galdesc= '%s' WHERE gid = %d", esc_attr($_POST['gallerydesc']), $this->gid));
             }
             if (nggGallery::current_user_can('NextGEN Edit gallery page id')) {
                 $wpdb->query($wpdb->prepare("UPDATE {$wpdb->nggallery} SET pageid= '%d' WHERE gid = %d", (int) $_POST['pageid'], $this->gid));
             }
             if (nggGallery::current_user_can('NextGEN Edit gallery preview pic')) {
                 $wpdb->query($wpdb->prepare("UPDATE {$wpdb->nggallery} SET previewpic= '%d' WHERE gid = %d", (int) $_POST['previewpic'], $this->gid));
             }
             if (isset($_POST['author']) && nggGallery::current_user_can('NextGEN Edit gallery author')) {
                 $wpdb->query($wpdb->prepare("UPDATE {$wpdb->nggallery} SET author= '%d' WHERE gid = %d", (int) $_POST['author'], $this->gid));
             }
             wp_cache_delete($this->gid, 'ngg_gallery');
         }
         $this->update_pictures();
         //hook for other plugin to update the fields
         do_action('ngg_update_gallery', $this->gid, $_POST);
         nggGallery::show_message(__('Update successful', "nggallery"));
     }
     if (isset($_POST['scanfolder'])) {
         // Rescan folder
         check_admin_referer('ngg_updategallery');
         $gallerypath = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$this->gid}' ");
         nggAdmin::import_gallery($gallerypath);
     }
     if (isset($_POST['addnewpage'])) {
         // Add a new page
         check_admin_referer('ngg_updategallery');
         $parent_id = esc_attr($_POST['parent_id']);
         $gallery_title = esc_attr($_POST['title']);
         $gallery_name = $wpdb->get_var("SELECT name FROM {$wpdb->nggallery} WHERE gid = '{$this->gid}' ");
         // Create a WP page
         global $user_ID;
         $page['post_type'] = 'page';
         $page['post_content'] = '[nggallery id=' . $this->gid . ']';
         $page['post_parent'] = $parent_id;
         $page['post_author'] = $user_ID;
         $page['post_status'] = 'publish';
         $page['post_title'] = $gallery_title == '' ? $gallery_name : $gallery_title;
         $page = apply_filters('ngg_add_new_page', $page, $this->gid);
         $gallery_pageid = wp_insert_post($page);
         if ($gallery_pageid != 0) {
             $result = $wpdb->query("UPDATE {$wpdb->nggallery} SET title= '{$gallery_title}', pageid = '{$gallery_pageid}' WHERE gid = '{$this->gid}'");
             wp_cache_delete($this->gid, 'ngg_gallery');
             nggGallery::show_message(__('New gallery page ID', 'nggallery') . ' ' . $gallery_pageid . ' -> <strong>' . $gallery_title . '</strong> ' . __('created', 'nggallery'));
         }
         do_action('ngg_gallery_addnewpage', $this->gid);
     }
 }
Exemple #4
0
 function post_processor_images()
 {
     global $wpdb, $ngg, $nggdb;
     // bulk update in a single gallery
     if (isset($_POST['bulkaction']) && isset($_POST['doaction'])) {
         check_admin_referer('ngg_updategallery');
         switch ($_POST['bulkaction']) {
             case 'no_action':
                 break;
             case 'rotate_cw':
                 nggAdmin::do_ajax_operation('rotate_cw', $_POST['doaction'], __('Rotate images', 'nggallery'));
                 break;
             case 'rotate_ccw':
                 nggAdmin::do_ajax_operation('rotate_ccw', $_POST['doaction'], __('Rotate images', 'nggallery'));
                 break;
             case 'recover_images':
                 nggAdmin::do_ajax_operation('recover_image', $_POST['doaction'], __('Recover from backup', 'nggallery'));
                 break;
             case 'set_watermark':
                 nggAdmin::do_ajax_operation('set_watermark', $_POST['doaction'], __('Set watermark', 'nggallery'));
                 break;
             case 'delete_images':
                 if (is_array($_POST['doaction'])) {
                     foreach ($_POST['doaction'] as $imageID) {
                         $image = $nggdb->find_image($imageID);
                         if ($image) {
                             if ($ngg->options['deleteImg']) {
                                 $storage = C_Gallery_Storage::get_instance();
                                 $storage->delete_image($image->pid);
                             }
                             do_action('ngg_delete_picture', $image->pid);
                             $delete_pic = C_Image_Mapper::get_instance()->destroy($image->pid);
                         }
                     }
                     if ($delete_pic) {
                         nggGallery::show_message(__('Pictures deleted successfully ', 'nggallery'));
                     }
                 }
                 break;
             case 'import_meta':
                 nggAdmin::do_ajax_operation('import_metadata', $_POST['doaction'], __('Import metadata', 'nggallery'));
                 break;
         }
     }
     if (isset($_POST['TB_bulkaction']) && isset($_POST['TB_ResizeImages'])) {
         check_admin_referer('ngg_thickbox_form');
         //save the new values for the next operation
         $ngg->options['imgWidth'] = (int) $_POST['imgWidth'];
         $ngg->options['imgHeight'] = (int) $_POST['imgHeight'];
         update_option('ngg_options', $ngg->options);
         $pic_ids = explode(',', $_POST['TB_imagelist']);
         nggAdmin::do_ajax_operation('resize_image', $pic_ids, __('Resize images', 'nggallery'));
     }
     if (isset($_POST['TB_bulkaction']) && isset($_POST['TB_NewThumbnail'])) {
         check_admin_referer('ngg_thickbox_form');
         // save the new values for the next operation
         $settings = C_NextGen_Settings::get_instance();
         $settings->thumbwidth = (int) $_POST['thumbwidth'];
         $settings->thumbheight = (int) $_POST['thumbheight'];
         $settings->thumbfix = isset($_POST['thumbfix']) ? TRUE : FALSE;
         $settings->save();
         ngg_refreshSavedSettings();
         $pic_ids = explode(',', $_POST['TB_imagelist']);
         nggAdmin::do_ajax_operation('create_thumbnail', $pic_ids, __('Create new thumbnails', 'nggallery'));
     }
     if (isset($_POST['TB_bulkaction']) && isset($_POST['TB_SelectGallery'])) {
         check_admin_referer('ngg_thickbox_form');
         $pic_ids = explode(',', $_POST['TB_imagelist']);
         $dest_gid = (int) $_POST['dest_gid'];
         switch ($_POST['TB_bulkaction']) {
             case 'copy_to':
                 C_Gallery_Storage::get_instance()->copy_images($pic_ids, $dest_gid);
                 break;
             case 'move_to':
                 C_Gallery_Storage::get_instance()->move_images($pic_ids, $dest_gid);
                 break;
         }
     }
     if (isset($_POST['TB_bulkaction']) && isset($_POST['TB_EditTags'])) {
         // do tags update
         check_admin_referer('ngg_thickbox_form');
         // get the images list
         $pic_ids = explode(',', $_POST['TB_imagelist']);
         $taglist = explode(',', $_POST['taglist']);
         $taglist = array_map('trim', $taglist);
         if (is_array($pic_ids)) {
             foreach ($pic_ids as $pic_id) {
                 // which action should be performed ?
                 switch ($_POST['TB_bulkaction']) {
                     case 'no_action':
                         // No action
                         break;
                     case 'overwrite_tags':
                         // Overwrite tags
                         wp_set_object_terms($pic_id, $taglist, 'ngg_tag');
                         break;
                     case 'add_tags':
                         // Add / append tags
                         wp_set_object_terms($pic_id, $taglist, 'ngg_tag', TRUE);
                         break;
                     case 'delete_tags':
                         // Delete tags
                         $oldtags = wp_get_object_terms($pic_id, 'ngg_tag', 'fields=names');
                         // get the slugs, to vaoid  case sensitive problems
                         $slugarray = array_map('sanitize_title', $taglist);
                         $oldtags = array_map('sanitize_title', $oldtags);
                         // compare them and return the diff
                         $newtags = array_diff($oldtags, $slugarray);
                         wp_set_object_terms($pic_id, $newtags, 'ngg_tag');
                         break;
                 }
             }
             nggGallery::show_message(__('Tags changed', 'nggallery'));
         }
     }
     if (isset($_POST['updatepictures'])) {
         // Update pictures
         check_admin_referer('ngg_updategallery');
         if (nggGallery::current_user_can('NextGEN Edit gallery options') && !isset($_GET['s'])) {
             $tags = array('<a>', '<abbr>', '<acronym>', '<address>', '<b>', '<base>', '<basefont>', '<big>', '<blockquote>', '<br>', '<br/>', '<caption>', '<center>', '<cite>', '<code>', '<col>', '<colgroup>', '<dd>', '<del>', '<dfn>', '<dir>', '<div>', '<dl>', '<dt>', '<em>', '<fieldset>', '<font>', '<h1>', '<h2>', '<h3>', '<h4>', '<h5>', '<h6>', '<hr>', '<i>', '<ins>', '<label>', '<legend>', '<li>', '<menu>', '<noframes>', '<noscript>', '<ol>', '<optgroup>', '<option>', '<p>', '<pre>', '<q>', '<s>', '<samp>', '<select>', '<small>', '<span>', '<strike>', '<strong>', '<sub>', '<sup>', '<table>', '<tbody>', '<td>', '<tfoot>', '<th>', '<thead>', '<tr>', '<tt>', '<u>', '<ul>');
             $fields = array('title', 'galdesc');
             // Sanitize fields
             foreach ($fields as $field) {
                 $html = $_POST[$field];
                 $html = preg_replace('/\\s+on\\w+=(["\']).*?\\1/i', '', $html);
                 $html = preg_replace('/(<\\/[^>]+?>)(<[^>\\/][^>]*?>)/', '$1 $2', $html);
                 $html = strip_tags($html, implode('', $tags));
                 $_POST[$field] = $html;
             }
             // Update the gallery
             $mapper = C_Gallery_Mapper::get_instance();
             if ($entity = $mapper->find($this->gid)) {
                 foreach ($_POST as $key => $value) {
                     $entity->{$key} = $value;
                 }
                 $mapper->save($entity);
             }
             wp_cache_delete($this->gid, 'ngg_gallery');
         }
         $this->update_pictures();
         //hook for other plugin to update the fields
         do_action('ngg_update_gallery', $this->gid, $_POST);
         nggGallery::show_message(__('Update successful', 'nggallery'));
     }
     if (isset($_POST['scanfolder'])) {
         // Rescan folder
         check_admin_referer('ngg_updategallery');
         $gallerypath = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$this->gid}' ");
         nggAdmin::import_gallery($gallerypath, $this->gid);
     }
     // Add a new page
     if (isset($_POST['addnewpage'])) {
         check_admin_referer('ngg_updategallery');
         $parent_id = esc_attr($_POST['parent_id']);
         $gallery_title = esc_attr($_POST['title']);
         $mapper = C_Gallery_Mapper::get_instance();
         $gallery = $mapper->find($this->gid);
         $gallery_name = $gallery->name;
         // Create a WP page
         global $user_ID;
         $page['post_type'] = 'page';
         $page['post_content'] = apply_filters('ngg_add_page_shortcode', '[nggallery id="' . $this->gid . '"]');
         $page['post_parent'] = $parent_id;
         $page['post_author'] = $user_ID;
         $page['post_status'] = 'publish';
         $page['post_title'] = $gallery_title == '' ? $gallery_name : $gallery_title;
         $page = apply_filters('ngg_add_new_page', $page, $this->gid);
         $gallery_pageid = wp_insert_post($page);
         if ($gallery_pageid != 0) {
             $gallery->pageid = $gallery_pageid;
             $mapper->save($gallery);
             nggGallery::show_message(__('New gallery page ID', 'nggallery') . ' ' . $gallery_pageid . ' -> <strong>' . $gallery_title . '</strong> ' . __('created', 'nggallery'));
         }
         do_action('ngg_gallery_addnewpage', $this->gid);
     }
 }
Exemple #5
0
function nggallery_admin_add_gallery()
{
    global $wpdb, $ngg;
    // same as $_SERVER['REQUEST_URI'], but should work under IIS 6.0
    $filepath = admin_url() . 'admin.php?page=' . $_GET['page'];
    // link for the flash file
    $swf_upload_link = NGGALLERY_URLPATH . 'admin/upload.php';
    $swf_upload_link = wp_nonce_url($swf_upload_link, 'ngg_swfupload');
    //flash doesn't seem to like encoded ampersands, so convert them back here
    $swf_upload_link = str_replace('&#038;', '&', $swf_upload_link);
    $defaultpath = $ngg->options['gallerypath'];
    if ($_POST['addgallery']) {
        check_admin_referer('ngg_addgallery');
        $newgallery = attribute_escape($_POST['galleryname']);
        if (!empty($newgallery)) {
            nggAdmin::create_gallery($newgallery, $defaultpath);
        }
    }
    if ($_POST['zipupload']) {
        check_admin_referer('ngg_addgallery');
        if ($_FILES['zipfile']['error'] == 0) {
            $messagetext = nggAdmin::import_zipfile(intval($_POST['zipgalselect']));
        } else {
            nggGallery::show_error(__('Upload failed!', 'nggallery'));
        }
    }
    if ($_POST['importfolder']) {
        check_admin_referer('ngg_addgallery');
        $galleryfolder = $_POST['galleryfolder'];
        if (!empty($galleryfolder) and $defaultpath != $galleryfolder) {
            nggAdmin::import_gallery($galleryfolder);
        }
    }
    if ($_POST['uploadimage']) {
        check_admin_referer('ngg_addgallery');
        if ($_FILES['MF__F_0_0']['error'] == 0) {
            $messagetext = nggAdmin::upload_images();
        } else {
            nggGallery::show_error(__('Upload failed!', 'nggallery'));
        }
    }
    if (isset($_POST['swf_callback'])) {
        if ($_POST['galleryselect'] == "0") {
            nggGallery::show_error(__('No gallery selected !', 'nggallery'));
        } else {
            // get the path to the gallery
            $galleryID = (int) $_POST['galleryselect'];
            $gallerypath = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$galleryID}' ");
            nggAdmin::import_gallery($gallerypath);
        }
    }
    if (isset($_POST['disable_flash'])) {
        check_admin_referer('ngg_addgallery');
        $ngg->options['swfUpload'] = false;
        update_option('ngg_options', $ngg->options);
    }
    if (isset($_POST['enable_flash'])) {
        check_admin_referer('ngg_addgallery');
        $ngg->options['swfUpload'] = true;
        update_option('ngg_options', $ngg->options);
    }
    //get all galleries (after we added new ones)
    $gallerylist = nggdb::find_all_galleries();
    ?>
	
	<?php 
    if ($ngg->options['swfUpload']) {
        ?>
	<!-- SWFUpload script -->
	<script type="text/javascript">
		var ngg_swf_upload;
			
		window.onload = function () {
			ngg_swf_upload = new SWFUpload({
				// Backend settings
				upload_url : "<?php 
        echo $swf_upload_link;
        ?>
",
				flash_url : "<?php 
        echo NGGALLERY_URLPATH;
        ?>
admin/js/swfupload.swf",
				
				// Button Settings
				button_placeholder_id : "spanButtonPlaceholder",
				button_width: 300,
				button_height: 27,
				button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
				button_cursor: SWFUpload.CURSOR.HAND,
								
				// File Upload Settings
				file_size_limit : "<?php 
        echo wp_max_upload_size();
        ?>
b",
				file_types : "*.jpg;*.gif;*.png",
				file_types_description : "<?php 
        _e('Image Files', 'nggallery');
        ?>
",
				
				// Queue handler
				file_queued_handler : fileQueued,
				
				// Upload handler
				upload_start_handler : uploadStart,
				upload_progress_handler : uploadProgress,
				upload_error_handler : uploadError,
				upload_success_handler : uploadSuccess,
				upload_complete_handler : uploadComplete,
				
				post_params : {
					"auth_cookie" : "<?php 
        echo $_COOKIE[AUTH_COOKIE];
        ?>
",
					"galleryselect" : "0"
				},
				
				// i18names
				custom_settings : {
					"remove" : "<?php 
        _e('remove', 'nggallery');
        ?>
",
					"browse" : "<?php 
        _e('Browse...', 'nggallery');
        ?>
",
					"upload" : "<?php 
        _e('Upload images', 'nggallery');
        ?>
"
				},

				// Debug settings
				debug: false
				
			});
			
			// on load change the upload to swfupload
			initSWFUpload();
			
		};
	</script>
	
	<div class="wrap" id="progressbar-wrap">
		<div class="progressborder">
			<div class="progressbar" id="progressbar">
				<span>0%</span>
			</div>
		</div>
	</div>
	
	<?php 
    } else {
        ?>
	<!-- MultiFile script -->
	<script type="text/javascript">	
		jQuery(function(){
			jQuery('#imagefiles').MultiFile({
				STRING: {
			    	remove:'<?php 
        _e('remove', 'nggallery');
        ?>
'
  				}
		 	});
		});
	</script>
	<?php 
    }
    ?>
	<!-- jQuery Tabs script -->
	<script type="text/javascript">
		jQuery(function() {
			jQuery('#slider > ul').tabs({ fxFade: true, fxSpeed: 'fast' });	
		});
	</script>
		
	<div id="slider" class="wrap">
	
		<ul id="tabs">
			<li><a href="#addgallery"><?php 
    _e('Add new gallery', 'nggallery');
    ?>
</a></li>
			<?php 
    if (wpmu_enable_function('wpmuZipUpload')) {
        ?>
			<li><a href="#zipupload"><?php 
        _e('Upload a Zip-File', 'nggallery');
        ?>
</a></li>
			<?php 
    }
    if (!IS_WPMU) {
        ?>
			<li><a href="#importfolder"><?php 
        _e('Import image folder', 'nggallery');
        ?>
</a></li>
			<?php 
    }
    ?>
			<li><a href="#uploadimage"><?php 
    _e('Upload Images', 'nggallery');
    ?>
</a></li>
		</ul>

		<!-- create gallery -->
		<div id="addgallery">
		<h2><?php 
    _e('Add new gallery', 'nggallery');
    ?>
</h2>
			<form name="addgallery" id="addgallery_form" method="POST" action="<?php 
    echo $filepath;
    ?>
" accept-charset="utf-8" >
			<?php 
    wp_nonce_field('ngg_addgallery');
    ?>
				<table class="form-table"> 
				<tr valign="top"> 
					<th scope="row"><?php 
    _e('New Gallery', 'nggallery');
    ?>
:</th> 
					<td><input type="text" size="35" name="galleryname" value="" /><br />
					<?php 
    if (!IS_WPMU) {
        ?>
					<?php 
        _e('Create a new , empty gallery below the folder', 'nggallery');
        ?>
  <strong><?php 
        echo $defaultpath;
        ?>
</strong><br />
					<?php 
    }
    ?>
					<i>( <?php 
    _e('Allowed characters for file and folder names are', 'nggallery');
    ?>
: a-z, A-Z, 0-9, -, _ )</i></td>
				</tr>
				</table>
				<div class="submit"><input class="button-primary" type="submit" name= "addgallery" value="<?php 
    _e('Add gallery', 'nggallery');
    ?>
"/></div>
			</form>
		</div>
		<?php 
    if (wpmu_enable_function('wpmuZipUpload')) {
        ?>
		<!-- zip-file operation -->
		<div id="zipupload">
		<h2><?php 
        _e('Upload a Zip-File', 'nggallery');
        ?>
</h2>
			<form name="zipupload" id="zipupload_form" method="POST" enctype="multipart/form-data" action="<?php 
        echo $filepath . '#zipupload';
        ?>
" accept-charset="utf-8" >
			<?php 
        wp_nonce_field('ngg_addgallery');
        ?>
				<table class="form-table"> 
				<tr valign="top"> 
					<th scope="row"><?php 
        _e('Select Zip-File', 'nggallery');
        ?>
:</th> 
					<td><input type="file" name="zipfile" id="zipfile" size="35" class="uploadform"/><br />
					<?php 
        _e('Upload a zip file with images', 'nggallery');
        ?>
</td> 
				</tr>
				<tr valign="top"> 
					<th scope="row"><?php 
        _e('in to', 'nggallery');
        ?>
</th> 
					<td><select name="zipgalselect">
					<option value="0" ><?php 
        _e('a new gallery', 'nggallery');
        ?>
</option>
					<?php 
        foreach ($gallerylist as $gallery) {
            $name = empty($gallery->title) ? $gallery->name : $gallery->title;
            echo '<option value="' . $gallery->gid . '" >' . $name . '</option>' . "\n";
        }
        ?>
					</select>
					<br /><?php 
        echo _e('Note : The upload limit on your server is ', 'nggallery') . "<strong>" . ini_get('upload_max_filesize') . "Byte</strong>\n";
        ?>
					<br /><?php 
        if (IS_WPMU && wpmu_enable_function('wpmuQuotaCheck')) {
            display_space_usage();
        }
        ?>
</td> 
				</tr> 
				</table>
				<div class="submit"><input class="button-primary" type="submit" name= "zipupload" value="<?php 
        _e('Start upload', 'nggallery');
        ?>
"/></div>
			</form>
		</div>
		<?php 
    }
    if (!IS_WPMU) {
        ?>
		<!-- import folder -->
		<div id="importfolder">
		<h2><?php 
        _e('Import image folder', 'nggallery');
        ?>
</h2>
			<form name="importfolder" id="importfolder_form" method="POST" action="<?php 
        echo $filepath . '#importfolder';
        ?>
" accept-charset="utf-8" >
			<?php 
        wp_nonce_field('ngg_addgallery');
        ?>
				<table class="form-table"> 
				<tr valign="top"> 
					<th scope="row"><?php 
        _e('Import from Server path:', 'nggallery');
        ?>
</th> 
					<td><input type="text" size="35" name="galleryfolder" value="<?php 
        echo $defaultpath;
        ?>
" /><br />
					<?php 
        _e('Import a folder with all images.', 'nggallery');
        ?>
					<?php 
        if (SAFE_MODE) {
            ?>
<br /><?php 
            _e(' Please note : For safe-mode = ON you need to add the subfolder thumbs manually', 'nggallery');
        }
        ?>
</td> 
				</tr>
				</table>
				<div class="submit"><input class="button-primary" type="submit" name= "importfolder" value="<?php 
        _e('Import folder', 'nggallery');
        ?>
"/></div>
			</form>
		</div>
		<?php 
    }
    ?>
 
		<!-- upload images -->
		<div id="uploadimage">
		<h2><?php 
    _e('Upload Images', 'nggallery');
    ?>
</h2>
			<form name="uploadimage" id="uploadimage_form" method="POST" enctype="multipart/form-data" action="<?php 
    echo $filepath . '#uploadimage';
    ?>
" accept-charset="utf-8" >
			<?php 
    wp_nonce_field('ngg_addgallery');
    ?>
				<table class="form-table"> 
				<tr valign="top"> 
					<th scope="row"><?php 
    _e('Upload image', 'nggallery');
    ?>
</th>
					<td><span id='spanButtonPlaceholder'></span><input type="file" name="imagefiles" id="imagefiles" size="35" class="imagefiles"/></td>
				</tr> 
				<tr valign="top"> 
					<th scope="row"><?php 
    _e('in to', 'nggallery');
    ?>
</th> 
					<td><select name="galleryselect" id="galleryselect">
					<option value="0" ><?php 
    _e('Choose gallery', 'nggallery');
    ?>
</option>
					<?php 
    foreach ($gallerylist as $gallery) {
        $name = empty($gallery->title) ? $gallery->name : $gallery->title;
        echo '<option value="' . $gallery->gid . '" >' . $name . '</option>' . "\n";
    }
    ?>
					</select>
					<br /><?php 
    echo _e('Note : The upload limit on your server is ', 'nggallery') . "<strong>" . ini_get('upload_max_filesize') . "Byte</strong>\n";
    ?>
					<br /><?php 
    if (IS_WPMU && wpmu_enable_function('wpmuQuotaCheck')) {
        display_space_usage();
    }
    ?>
</td> 
				</tr> 
				</table>
				<div class="submit">
					<?php 
    if ($ngg->options['swfUpload']) {
        ?>
					<input type="submit" name="disable_flash" id="disable_flash" title="<?php 
        _e('The batch upload requires Adobe Flash 9, disable it if you have problems', 'nggallery');
        ?>
" value="<?php 
        _e('Disable flash upload', 'nggallery');
        ?>
" />
					<?php 
    } else {
        ?>
					<input type="submit" name="enable_flash" id="enable_flash" title="<?php 
        _e('Upload multiple files at once by ctrl/shift-selecting in dialog', 'nggallery');
        ?>
" value="<?php 
        _e('Enable flash based upload', 'nggallery');
        ?>
" />
					<?php 
    }
    ?>
					<input class="button-primary" type="submit" name="uploadimage" id="uploadimage_btn" value="<?php 
    _e('Upload images', 'nggallery');
    ?>
" />
				</div>
			</form>
		</div>
	</div>
	<?php 
}
Exemple #6
0
 function import_zipfile($galleryID)
 {
     global $ngg, $wpdb;
     if (nggAdmin::check_quota()) {
         return false;
     }
     $defaultpath = $ngg->options['gallerypath'];
     $temp_zipfile = $_FILES['zipfile']['tmp_name'];
     $filename = $_FILES['zipfile']['name'];
     // check if file is a zip file
     if (!eregi('zip|download|octet-stream', $_FILES['zipfile']['type'])) {
         @unlink($temp_zipfile);
         // del temp file
         nggGallery::show_error(__('Uploaded file was no or a faulty zip file ! The server recognize : ', 'nggallery') . $_FILES['zipfile']['type']);
         return false;
     }
     // should this unpacked into a new folder ?
     if ($galleryID == '0') {
         //cleanup and take the zipfile name as folder name
         $foldername = sanitize_title(strtok($filename, '.'));
         $foldername = $defaultpath . $foldername;
     } else {
         // get foldername if selected
         $foldername = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$galleryID}' ");
     }
     if (empty($foldername)) {
         nggGallery::show_error(__('Could not get a valid foldername', 'nggallery'));
         return false;
     }
     // set complete folder path
     $newfolder = WINABSPATH . $foldername;
     // check first if the traget folder exist
     if (!is_dir($newfolder)) {
         // create new directories
         if (!wp_mkdir_p($newfolder)) {
             $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?', 'nggallery'), $newfolder);
             nggGallery::show_error($message);
             return false;
         }
         if (!wp_mkdir_p($newfolder . '/thumbs')) {
             nggGallery::show_error(__('Unable to create directory ', 'nggallery') . $newfolder . '/thumbs !');
             return false;
         }
     }
     // unzip and del temp file
     $result = nggAdmin::unzip($newfolder, $temp_zipfile);
     @unlink($temp_zipfile);
     if ($result) {
         $message = __('Zip-File successfully unpacked', 'nggallery') . '<br />';
         // parse now the folder and add to database
         $message .= nggAdmin::import_gallery($foldername);
         nggGallery::show_message($message);
     }
     return true;
 }
Exemple #7
0
 function processor()
 {
     global $wpdb, $ngg;
     if ($this->mode == 'delete') {
         // Delete a gallery
         check_admin_referer('ngg_editgallery');
         // get the path to the gallery
         $gallerypath = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$this->gid}' ");
         if ($gallerypath) {
             // delete pictures
             //TODO:Remove also Tag reference
             $imagelist = $wpdb->get_col("SELECT filename FROM {$wpdb->nggpictures} WHERE galleryid = '{$this->gid}' ");
             if ($ngg->options['deleteImg']) {
                 if (is_array($imagelist)) {
                     foreach ($imagelist as $filename) {
                         @unlink(WINABSPATH . $gallerypath . '/thumbs/thumbs_' . $filename);
                         @unlink(WINABSPATH . $gallerypath . '/' . $filename);
                     }
                 }
                 // delete folder
                 @rmdir(WINABSPATH . $gallerypath . '/thumbs');
                 @rmdir(WINABSPATH . $gallerypath);
             }
         }
         $delete_pic = $wpdb->query("DELETE FROM {$wpdb->nggpictures} WHERE galleryid = {$this->gid}");
         $delete_galllery = $wpdb->query("DELETE FROM {$wpdb->nggallery} WHERE gid = {$this->gid}");
         if ($delete_galllery) {
             nggGallery::show_message(__ngettext('Gallery', 'Galleries', 1, 'nggallery') . ' \'' . $this->gid . '\' ' . __('deleted successfully', 'nggallery'));
         }
         $this->mode = 'main';
         // show mainpage
     }
     if ($this->mode == 'delpic') {
         // Delete a picture
         //TODO:Remove also Tag reference
         check_admin_referer('ngg_delpicture');
         $filename = $wpdb->get_var("SELECT filename FROM {$wpdb->nggpictures} WHERE pid = '{$this->pid}' ");
         if ($filename) {
             $gallerypath = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$this->gid}' ");
             if ($gallerypath) {
                 $thumb_folder = nggGallery::get_thumbnail_folder($gallerypath, FALSE);
                 if ($ngg->options['deleteImg']) {
                     @unlink(WINABSPATH . $gallerypath . '/thumbs/thumbs_' . $filename);
                     @unlink(WINABSPATH . $gallerypath . '/' . $filename);
                 }
             }
             $delete_pic = $wpdb->query("DELETE FROM {$wpdb->nggpictures} WHERE pid = {$this->pid}");
         }
         if ($delete_pic) {
             nggGallery::show_message(__('Picture', 'nggallery') . ' \'' . $this->pid . '\' ' . __('deleted successfully', 'nggallery'));
         }
         $this->mode = 'edit';
         // show pictures
     }
     if (isset($_POST['bulkaction']) && isset($_POST['doaction'])) {
         // do bulk update
         check_admin_referer('ngg_updategallery');
         $gallerypath = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$this->gid}' ");
         $imageslist = array();
         if (is_array($_POST['doaction'])) {
             foreach ($_POST['doaction'] as $imageID) {
                 $imageslist[] = $wpdb->get_var("SELECT filename FROM {$wpdb->nggpictures} WHERE pid = '{$imageID}' ");
             }
         }
         switch ($_POST['bulkaction']) {
             case 'no_action':
                 // No action
                 break;
             case 'set_watermark':
                 // Set watermark
                 nggAdmin::do_ajax_operation('set_watermark', $_POST['doaction'], __('Set watermark', 'nggallery'));
                 break;
             case 'new_thumbnail':
                 // Create new thumbnails
                 nggAdmin::do_ajax_operation('create_thumbnail', $_POST['doaction'], __('Create new thumbnails', 'nggallery'));
                 break;
             case 'resize_images':
                 // Resample images
                 nggAdmin::do_ajax_operation('resize_image', $_POST['doaction'], __('Resize images', 'nggallery'));
                 break;
             case 'delete_images':
                 // Delete images
                 if (is_array($_POST['doaction'])) {
                     if ($gallerypath) {
                         $thumb_folder = nggGallery::get_thumbnail_folder($gallerypath, FALSE);
                         foreach ($_POST['doaction'] as $imageID) {
                             $filename = $wpdb->get_var("SELECT filename FROM {$wpdb->nggpictures} WHERE pid = '{$imageID}' ");
                             if ($ngg->options['deleteImg']) {
                                 @unlink(WINABSPATH . $gallerypath . '/' . $thumb_folder . '/' . "thumbs_" . $filename);
                                 @unlink(WINABSPATH . $gallerypath . '/' . $filename);
                             }
                             $delete_pic = $wpdb->query("DELETE FROM {$wpdb->nggpictures} WHERE pid = {$imageID}");
                         }
                     }
                     if ($delete_pic) {
                         nggGallery::show_message(__('Pictures deleted successfully ', "nggallery"));
                     }
                 }
                 break;
             case 'import_meta':
                 // Import Metadata
                 nggAdmin::import_MetaData($_POST['doaction']);
                 nggGallery::show_message(__('Import metadata finished', "nggallery"));
                 break;
         }
     }
     // will be called after a ajax operation
     if (isset($_POST['ajax_callback'])) {
         if ($_POST['ajax_callback'] == 1) {
             nggGallery::show_message(__('Operation successfull. Please clear your browser cache.', "nggallery"));
         }
         $this->mode = 'edit';
     }
     if (isset($_POST['TB_bulkaction']) && isset($_POST['TB_SelectGallery'])) {
         check_admin_referer('ngg_thickbox_form');
         $pic_ids = explode(",", $_POST['TB_imagelist']);
         $dest_gid = (int) $_POST['dest_gid'];
         switch ($_POST['TB_bulkaction']) {
             case 'copy_to':
                 // Copy images
                 nggAdmin::copy_images($pic_ids, $dest_gid);
                 break;
             case 'move_to':
                 // Move images
                 nggAdmin::move_images($pic_ids, $dest_gid);
                 break;
         }
     }
     if (isset($_POST['TB_bulkaction']) && isset($_POST['TB_EditTags'])) {
         // do tags update
         check_admin_referer('ngg_thickbox_form');
         // get the images list
         $pic_ids = explode(",", $_POST['TB_imagelist']);
         $taglist = explode(",", $_POST['taglist']);
         $taglist = array_map('trim', $taglist);
         if (is_array($pic_ids)) {
             foreach ($pic_ids as $pic_id) {
                 // which action should be performed ?
                 switch ($_POST['TB_bulkaction']) {
                     case 'no_action':
                         // No action
                         break;
                     case 'overwrite_tags':
                         // Overwrite tags
                         wp_set_object_terms($pic_id, $taglist, 'ngg_tag');
                         break;
                     case 'add_tags':
                         // Add / append tags
                         wp_set_object_terms($pic_id, $taglist, 'ngg_tag', TRUE);
                         break;
                     case 'delte_tags':
                         // Delete tags
                         $oldtags = wp_get_object_terms($pic_id, 'ngg_tag', 'fields=names');
                         // get the slugs, to vaoid  case sensitive problems
                         $slugarray = array_map('sanitize_title', $taglist);
                         $oldtags = array_map('sanitize_title', $oldtags);
                         // compare them and return the diff
                         $newtags = array_diff($oldtags, $slugarray);
                         wp_set_object_terms($pic_id, $newtags, 'ngg_tag');
                         break;
                 }
             }
             nggGallery::show_message(__('Tags changed', "nggallery"));
         }
     }
     if (isset($_POST['updatepictures'])) {
         // Update pictures
         check_admin_referer('ngg_updategallery');
         $gallery_title = attribute_escape($_POST['title']);
         $gallery_path = attribute_escape($_POST['path']);
         $gallery_desc = attribute_escape($_POST['gallerydesc']);
         $gallery_pageid = (int) $_POST['pageid'];
         $gallery_preview = (int) $_POST['previewpic'];
         $wpdb->query("UPDATE {$wpdb->nggallery} SET title= '{$gallery_title}', path= '{$gallery_path}', galdesc = '{$gallery_desc}', pageid = '{$gallery_pageid}', previewpic = '{$gallery_preview}' WHERE gid = '{$this->gid}'");
         if (isset($_POST['author'])) {
             $gallery_author = (int) $_POST['author'];
             $wpdb->query("UPDATE {$wpdb->nggallery} SET author = '{$gallery_author}' WHERE gid = '{$this->gid}'");
         }
         if ($this->showTags) {
             $this->update_tags();
         } else {
             $this->update_pictures();
         }
         //hook for other plugin to update the fields
         do_action('ngg_update_gallery', $this->gid, $_POST);
         nggGallery::show_message(__('Update successful', "nggallery"));
     }
     if (isset($_POST['scanfolder'])) {
         // Rescan folder
         check_admin_referer('ngg_updategallery');
         $gallerypath = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$this->gid}' ");
         nggAdmin::import_gallery($gallerypath);
     }
     if (isset($_POST['addnewpage'])) {
         // Add a new page
         check_admin_referer('ngg_updategallery');
         $parent_id = attribute_escape($_POST['parent_id']);
         $gallery_title = attribute_escape($_POST['title']);
         $gallery_name = $wpdb->get_var("SELECT name FROM {$wpdb->nggallery} WHERE gid = '{$this->gid}' ");
         // Create a WP page
         global $user_ID;
         $page['post_type'] = 'page';
         $page['post_content'] = '[nggallery id=' . $this->gid . ']';
         $page['post_parent'] = $parent_id;
         $page['post_author'] = $user_ID;
         $page['post_status'] = 'publish';
         $page['post_title'] = $gallery_title == '' ? $gallery_name : $gallery_title;
         $gallery_pageid = wp_insert_post($page);
         if ($gallery_pageid != 0) {
             $result = $wpdb->query("UPDATE {$wpdb->nggallery} SET title= '{$gallery_title}', pageid = '{$gallery_pageid}' WHERE gid = '{$this->gid}'");
             nggGallery::show_message(__('New gallery page ID', 'nggallery') . ' ' . $pageid . ' -> <strong>' . $gallery_title . '</strong> ' . __('created', 'nggallery'));
         }
     }
     if (isset($_POST['backToGallery'])) {
         $this->mode = 'edit';
     }
     // show sort order
     if (isset($_POST['sortGallery'])) {
         $this->mode = 'sort';
     }
 }