RSS - Latest posts WordPress NextGen gallery tweak

Home » 2008 » 11 » WordPress NextGen gallery tweak

Recently I found myself in that very anoying situation where a very good piece of software seemed to lack just this one function… again. I have been doing a gallery website and used the NextGen gallery plugin to display the photos. Unfortunatelly it was a case of a gallery per post with about 1 or 2 photos per gallery.

The biggest issue with this setting was the process of creating galleries. By default in NextGen you create the gallery on one page, upload the images in another, and then create new post yet elsewhere. But there had to be a way to at least merge the gallery creation with photo upload, especially considering a new gallery form consisted of a single “gallery name” field.Surprisingly enough after checking the code, both actions are actually processed in the same place. Thus by adding a new field on the photo upload form this time consuming problem could be solved:

Edit the file: wp-content/plugins/nggallery/admin/wp25/addgallery.php (line: 15)

// link for the flash file
$swf_upload_link = NGGALLERY_URLPATH . 'admin/wp25/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('&', '&', $swf_upload_link);

$defaultpath = $ngg_options['gallerypath'];

if ($_POST['addgallery'] || !empty($_POST['newgalleryname'])){
  if(!empty($_POST['newgalleryname']))
    $_POST['galleryname'] = $_POST['newgalleryname'];
  check_admin_referer('ngg_addgallery');
  $newgallery = attribute_escape($_POST['galleryname']);
  if (!empty($newgallery))
    $_POST['galleryselect'] = nggAdmin::create_gallery($newgallery, $defaultpath);
}
if ($_POST['zipupload']){

Edit the file: wp-content/plugins/nggallery/admin/wp25/addgallery.php (line: 263)

	<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
			$gallerylist = $wpdb->get_results("SELECT * FROM $wpdb->nggallery ORDER BY gid ASC");
			if(is_array($gallerylist)) {
				foreach($gallerylist as $gallery) {
					echo '<option value="'.$gallery->gid.'" >'.$gallery->name.' | '.$gallery->title.'</option>'."n";
				}
			}
		?>
		</select> <label>or <input type="text" name="newgalleryname"  /></label>
		<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>

Edit the file: wp-content/plugins/nggallery/admin/wp25/functions.php (line: 77)

if ($result) {
	nggallery::show_error(__('Gallery', 'nggallery').' <strong>'.$galleryname.'</strong> '.__('already exists', 'nggallery'));
	return false;
} else {
	$result = $wpdb->query("INSERT INTO $wpdb->nggallery (name, path, title) VALUES ('$galleryname', '$nggpath', '$gallerytitle') ");
	if ($result) nggallery::show_message(__('Gallery', 'nggallery').' <strong>'.$wpdb->insert_id." : ".$galleryname.'</strong> '.__('successfully created!','nggallery')."
".__('You can show this gallery with the tag','nggallery').'<strong> </strong>');
	return $wpdb->insert_id;
}  

 

You can leave a response, or trackback from your own site.

Add Comment

  1. JessicaCloca says:

    I love it! That is way cool man! The steps weren’t that complicated too, which is great.

  2. Ben Lacey says:

    Very nice! I stopped using WordPress because clients always want something that is not available in a certain CMS without a LOT of additional hacks.

    I was tempted to use WordPress and NextGen for RSF but I found NextGen Gallery too clumsy and ‘complex’ for a non-technical user.

    Nice post. Might try this someday.