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']) ){
    		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
			//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))
                    		@copy( $gallerypath.'/'.$file, $new_gallerypath.'/'.$file );
			$galleryfolder = $defaultpath.$galleryname;


Tested with Version 1.9.3 of NextGen gallery.

 Posted by at 21:21