Apr 102012
 

Problem: Whenever I want to import images into new gallery from server directory, NextGen instead of creating own copy of all images in the defined gallery path (General Options->Gallery path) is working on the source directory changing source images. Later if the source directory is (re)moved, the gallery itself contains nothing else than dead image links.

So here is my little NextGen patch – before the images will be imported into new NextGen gallery the source directory is be copied into the Gallery path directory. This way source images are not changed anymore and NextGen can safely work on the copy of images.

Just replace the if ( isset($_POST['importfolder']) ) IF condition in extgen-gallery/admin/addgallery.php with the code below:

    	if ( isset($_POST['importfolder']) ){
    		check_admin_referer('ngg_addgallery');
    
    		if ( !nggGallery::current_user_can( 'NextGEN Import image folder' ))
    			wp_die(__('Cheatin’ uh?'));
    
    		$galleryfolder = $_POST['galleryfolder'];
    		if ( ( !empty($galleryfolder) ) AND ($defaultpath != $galleryfolder) ) {
			$galleryname = basename($galleryfolder);
			$galleryname = apply_filters('ngg_gallery_name', $galleryname);
			$gallerypath = WINABSPATH.$galleryfolder;
			
			$new_gallerypath = WINABSPATH.$defaultpath.$galleryname;
			
			//create gallery directory in defaultpath
			wp_mkdir_p($new_gallerypath);
            		
			//copy files
			$objects = scandir($gallerypath);
                	$ext = array('jpeg', 'jpg', 'png', 'gif');
			foreach( $objects as $file )
                	{
                    		$filepart = pathinfo($file);
				if( $file == "." || $file == ".." || !in_array($filepart['extension'], $ext))
                        		continue;
                    		@copy( $gallerypath.'/'.$file, $new_gallerypath.'/'.$file );
                	}
			$galleryfolder = $defaultpath.$galleryname;

    			nggAdmin::import_gallery($galleryfolder);
		}
    	}

Tested with Version 1.9.3 of NextGen gallery.

 Posted by at 21:21

  One Response to “NextGen Gallery Import Image folder – fix”

  1. Great – thanks – just what I was looking for.
    Already deleted source images by accident… 🙁
    But will be good to avoid the ‘next time’.
    Can this be made into a NextGen extension?
    best regards, Mike

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*