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); } }
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); 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': // 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", stripslashes($_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", stripslashes($_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); } }