Exemple #1
0
 /**
  * Function for uploading of images via the upload form
  * 
  * @class nggAdmin
  * @return void
  */
 function upload_images()
 {
     global $nggdb;
     // WPMU action
     if (nggWPMU::check_quota()) {
         return;
     }
     // Images must be an array
     $imageslist = array();
     // get selected gallery
     $galleryID = (int) $_POST['galleryselect'];
     if ($galleryID == 0) {
         nggGallery::show_error(__('No gallery selected !', 'nggallery'));
         return;
     }
     // get the path to the gallery
     $gallery = $nggdb->find_gallery($galleryID);
     if (empty($gallery->path)) {
         nggGallery::show_error(__('Failure in database, no gallery path set !', 'nggallery'));
         return;
     }
     // read list of images
     $dirlist = nggAdmin::scandir($gallery->abspath);
     $imagefiles = $_FILES['imagefiles'];
     if (is_array($imagefiles)) {
         foreach ($imagefiles['name'] as $key => $value) {
             // look only for uploded files
             if ($imagefiles['error'][$key] == 0) {
                 $temp_file = $imagefiles['tmp_name'][$key];
                 //clean filename and extract extension
                 $filepart = nggGallery::fileinfo($imagefiles['name'][$key]);
                 $filename = $filepart['basename'];
                 // check for allowed extension and if it's an image file
                 $ext = array('jpg', 'png', 'gif');
                 if (!in_array($filepart['extension'], $ext) || !@getimagesize($temp_file)) {
                     nggGallery::show_error('<strong>' . $imagefiles['name'][$key] . ' </strong>' . __('is no valid image file!', 'nggallery'));
                     continue;
                 }
                 // check if this filename already exist in the folder
                 $i = 0;
                 while (in_array($filename, $dirlist)) {
                     $filename = $filepart['filename'] . '_' . $i++ . '.' . $filepart['extension'];
                 }
                 $dest_file = $gallery->abspath . '/' . $filename;
                 //check for folder permission
                 if (!is_writeable($gallery->abspath)) {
                     $message = sprintf(__('Unable to write to directory %s. Is this directory writable by the server?', 'nggallery'), $gallery->abspath);
                     nggGallery::show_error($message);
                     return;
                 }
                 // save temp file to gallery
                 if (!@move_uploaded_file($temp_file, $dest_file)) {
                     nggGallery::show_error(__('Error, the file could not be moved to : ', 'nggallery') . $dest_file);
                     nggAdmin::check_safemode($gallery->abspath);
                     continue;
                 }
                 if (!nggAdmin::chmod($dest_file)) {
                     nggGallery::show_error(__('Error, the file permissions could not be set', 'nggallery'));
                     continue;
                 }
                 // add to imagelist & dirlist
                 $imageslist[] = $filename;
                 $dirlist[] = $filename;
             }
         }
     }
     if (count($imageslist) > 0) {
         // add images to database
         $image_ids = nggAdmin::add_Images($galleryID, $imageslist);
         //create thumbnails
         nggAdmin::do_ajax_operation('create_thumbnail', $image_ids, __('Create new thumbnails', 'nggallery'));
         //add the preview image if needed
         nggAdmin::set_gallery_preview($galleryID);
         nggGallery::show_message(count($image_ids) . __(' Image(s) successfully added', 'nggallery'));
     }
     return;
 }
Exemple #2
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);
     }
 }
 /**
  * nggAdmin::import_gallery()
  * TODO: Check permission of existing thumb folder & images
  *
  * @class nggAdmin
  * @param string $galleryfolder contains relative path to the gallery itself
  * @return void
  */
 static function import_gallery($galleryfolder, $gallery_id = NULL)
 {
     global $wpdb, $user_ID;
     // get the current user ID
     wp_get_current_user();
     $created_msg = '';
     // remove trailing slash at the end, if somebody use it
     $galleryfolder = untrailingslashit($galleryfolder);
     $fs = C_Fs::get_instance();
     if (is_null($gallery_id)) {
         $gallerypath = $fs->join_paths($fs->get_document_root('content'), $galleryfolder);
     } else {
         $storage = C_Gallery_Storage::get_instance();
         $gallerypath = $storage->get_gallery_abspath($gallery_id);
     }
     if (!is_dir($gallerypath)) {
         nggGallery::show_error(sprintf(__("Directory <strong>%s</strong> doesn&#96;t exist!", 'nggallery'), esc_html($gallerypath)));
         return;
     }
     // read list of images
     $new_imageslist = nggAdmin::scandir($gallerypath);
     if (empty($new_imageslist)) {
         nggGallery::show_message(sprintf(__("Directory <strong>%s</strong> contains no pictures", 'nggallery'), esc_html($gallerypath)));
         return;
     }
     // take folder name as gallery name
     $galleryname = basename($galleryfolder);
     $galleryname = apply_filters('ngg_gallery_name', $galleryname);
     // check for existing gallery folder
     if (is_null($gallery_id)) {
         $gallery_id = $wpdb->get_var("SELECT gid FROM {$wpdb->nggallery} WHERE path = '{$galleryfolder}' ");
     }
     if (!$gallery_id) {
         // now add the gallery to the database
         $gallery_id = nggdb::add_gallery($galleryname, $galleryfolder, '', 0, 0, $user_ID);
         if (!$gallery_id) {
             nggGallery::show_error(__('Database error. Could not add gallery!', 'nggallery'));
             return;
         } else {
             do_action('ngg_created_new_gallery', $gallery_id);
         }
         $created_msg = sprintf(_n("Gallery <strong>%s</strong> successfully created!", 'Galleries <strong>%s</strong> successfully created!', 1, 'nggallery'), esc_html($galleryname));
     }
     // Look for existing image list
     $old_imageslist = $wpdb->get_col("SELECT filename FROM {$wpdb->nggpictures} WHERE galleryid = '{$gallery_id}' ");
     // if no images are there, create empty array
     if ($old_imageslist == NULL) {
         $old_imageslist = array();
     }
     // check difference
     $new_images = array_diff($new_imageslist, $old_imageslist);
     // all images must be valid files
     foreach ($new_images as $key => $picture) {
         // filter function to rename/change/modify image before
         $picture = apply_filters('ngg_pre_add_new_image', $picture, $gallery_id);
         $new_images[$key] = $picture;
         if (!@getimagesize($gallerypath . '/' . $picture)) {
             unset($new_images[$key]);
             @unlink($gallerypath . '/' . $picture);
         }
     }
     // add images to database
     $image_ids = nggAdmin::add_Images($gallery_id, $new_images);
     do_action('ngg_after_new_images_added', $gallery_id, $image_ids);
     //add the preview image if needed
     nggAdmin::set_gallery_preview($gallery_id);
     // now create thumbnails
     nggAdmin::do_ajax_operation('create_thumbnail', $image_ids, __('Create new thumbnails', 'nggallery'));
     //TODO:Message will not shown, because AJAX routine require more time, message should be passed to AJAX
     $message = $created_msg . sprintf(_n('%s picture successfully added', '%s pictures successfully added', count($image_ids), 'nggallery'), count($image_ids));
     $message .= ' [<a href="' . admin_url() . 'admin.php?page=nggallery-manage-gallery&mode=edit&gid=' . $gallery_id . '" >';
     $message .= __('Edit gallery', 'nggallery');
     $message .= '</a>]';
     nggGallery::show_message($message);
     return;
 }
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 upload_images()
 {
     // upload of pictures
     global $wpdb;
     // WPMU action
     if (nggAdmin::check_quota()) {
         return;
     }
     // Images must be an array
     $imageslist = array();
     // get selected gallery
     $galleryID = (int) $_POST['galleryselect'];
     if ($galleryID == 0) {
         nggGallery::show_error(__('No gallery selected !', 'nggallery'));
         return;
     }
     // get the path to the gallery
     $gallerypath = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$galleryID}' ");
     if (!$gallerypath) {
         nggGallery::show_error(__('Failure in database, no gallery path set !', 'nggallery'));
         return;
     }
     // read list of images
     $dirlist = nggAdmin::scandir(WINABSPATH . $gallerypath);
     foreach ($_FILES as $key => $value) {
         // look only for uploded files
         if ($_FILES[$key]['error'] == 0) {
             $temp_file = $_FILES[$key]['tmp_name'];
             $filepart = pathinfo(strtolower($_FILES[$key]['name']));
             // required until PHP 5.2.0
             $filepart['filename'] = substr($filepart["basename"], 0, strlen($filepart["basename"]) - (strlen($filepart["extension"]) + 1));
             $filename = sanitize_title($filepart['filename']) . '.' . $filepart['extension'];
             // check for allowed extension
             $ext = array('jpeg', 'jpg', 'png', 'gif');
             if (!in_array($filepart['extension'], $ext)) {
                 nggGallery::show_error('<strong>' . $_FILES[$key]['name'] . ' </strong>' . __('is no valid image file!', 'nggallery'));
                 continue;
             }
             // check if this filename already exist in the folder
             $i = 0;
             while (in_array($filename, $dirlist)) {
                 $filename = sanitize_title($filepart['filename']) . '_' . $i++ . '.' . $filepart['extension'];
             }
             $dest_file = WINABSPATH . $gallerypath . '/' . $filename;
             //check for folder permission
             if (!is_writeable(WINABSPATH . $gallerypath)) {
                 $message = sprintf(__('Unable to write to directory %s. Is this directory writable by the server?', 'nggallery'), WINABSPATH . $gallerypath);
                 nggGallery::show_error($message);
                 return;
             }
             // save temp file to gallery
             if (!@move_uploaded_file($_FILES[$key]['tmp_name'], $dest_file)) {
                 nggGallery::show_error(__('Error, the file could not moved to : ', 'nggallery') . $dest_file);
                 nggAdmin::check_safemode(WINABSPATH . $gallerypath);
                 continue;
             }
             if (!nggAdmin::chmod($dest_file)) {
                 nggGallery::show_error(__('Error, the file permissions could not set', 'nggallery'));
                 continue;
             }
             // add to imagelist & dirlist
             $imageslist[] = $filename;
             $dirlist[] = $filename;
         }
     }
     if (count($imageslist) > 0) {
         // add images to database
         $image_ids = nggAdmin::add_Images($galleryID, $imageslist);
         //create thumbnails
         nggAdmin::do_ajax_operation('create_thumbnail', $image_ids, __('Create new thumbnails', 'nggallery'));
         //add the preview image if needed
         nggAdmin::set_gallery_preview($galleryID);
         nggGallery::show_message(count($image_ids) . __(' Image(s) successfully added', 'nggallery'));
     }
     return;
 }
Exemple #6
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';
     }
 }