Support » Plugin: NextGEN Download Gallery » Linking to HR images (again)

  • Resolved Jon Humphrey

    (@jonrandahl)


    Ross,

    First, Thank you! You’ve made my life so much easier!
    Second, Here’s a little javascript I’ve updated and thought it might help others:

    $("#ngg-download-frm").submit(function(event) {
    		if ($("input[name='pid[]']:checked", this).length == 0) {
    			event.preventDefault();
    			alert("Please select one or more images to download.");
    		}
    	})
    	.on('click','input[type="checkbox"]',function(c){
    		$(c.target).parents('figure').find('img').toggleClass("selectedDownload");
    	})
    	.on('click','a',function(a){
    		a.preventDefault();
    		$(a.target).parents('figure').find('input[type="checkbox"]').click();
    	});
    
    	var $selected = 0;
    
    	$("input.ngg-download-selectall").show().click(function() {
    		if ($selected == 0) {
    			$(this.form).find("input[name='pid[]']").prop({checked: true});
    			$(this.form).find('img').addClass("selectedDownload");
    			$(this).val("Deselect All");
    			$selected = 1;
    		} else {
    			$(this).closest("form").find("input[name='pid[]']").prop({checked: false});
    			$(this).closest("form").find('img').removeClass("selectedDownload");
    			$(this).val("Select All");
    			$selected = 0;
    		}
    	});

    Finally, and the most important part, I’m trying to link to a completely different path, either to just a separate directory on the server OR to the cloud (AmazonS3 or Azure) and therefore need to update/rewrite each image path before it’s grabbed for the zip.

    I tried changing the following to set a different folder but am still linking to the lo-res and not sure why?

    File: nextgen-download-gallery.php

    Your code: (@ ln#242)

    foreach ($images as $image) {
    				$image = $nggdb->find_image($image);
    				if ($image) {
    					$loRes = $image->imagePath;
    				}
    			}

    my code:

    foreach ($images as $image) {
    				$image = $nggdb->find_image($image);
    				if ($image) {
    					$loRes = $image->imagePath;
    					$loResSrc =  pathinfo($loRes);
    					$loResImgName = $loResSrc['basename'];
    					$loResImgDir = basename( $loResSrc['dirname'] );
    					list($initialPath,$localPath) = explode("gallery",$loRes);
    					$files[] = $initialPath . "gallery/client-hi-res/" . $loResImgDir ."/" . $loResImgName;
    				}
    			}

    Any help to what I could do to either pass in a “basepath” as an argument via shortcode (best) or to force a new path as I’m trying to above (ok) would be immensely appreciated!

    This is behind password protected pages but would be happy to set something up for you to see if you would like, just let me know?

    Thank you for your time and patience, I look forward to anyone’s reply!

    Jon

    http://wordpress.org/extend/plugins/nextgen-download-gallery/

Viewing 15 replies - 1 through 15 (of 23 total)
  • Plugin Author webaware

    (@webaware)

    G’day Jon,

    Interesting use, I like it. I’m going to release a new version in a minute that lets you filter the image path, rather than hacking the plugin. Here’s some sample code, incorporating your code above, and some error logging so that you can see what’s going on:

    add_filter('ngg_dlgallery_image_path', function($loRes) {
    
        $loResSrc =  pathinfo($loRes);
        $loResImgName = $loResSrc['basename'];
        $loResImgDir = basename( $loResSrc['dirname'] );
        list($initialPath,$localPath) = explode("gallery",$loRes);
        $hiRes = $initialPath . "gallery/client-hi-res/" . $loResImgDir ."/" . $loResImgName;
    
    //~ error_log(print_r($loResSrc,1));
    error_log("initialPath = $initialPath");
    error_log("localPath = $localPath");
    error_log("hiRes = $hiRes");
    error_log("loRes = $loRes\n");
    
        return $hiRes;
    
    });

    Turn on WP_DEBUG and WP_DEBUG_LOG per Debugging in WordPress, and you’ll get those error log messages in a debug.log file.

    When I ran your code, using the filter above, it worked just fine:

    initialPath = /var/www/html/wptest/wp-content/
    localPath = /hunter-river-shipping/2011-04-30-16-50-34.jpg
    hiRes = /var/www/html/wptest/wp-content/gallery/client-hi-res/hunter-river-shipping/2011-04-30-16-50-34.jpg
    loRes = /var/www/html/wptest/wp-content/gallery/hunter-river-shipping/2011-04-30-16-50-34.jpg

    cheers,
    Ross

    Jon Humphrey

    (@jonrandahl)

    Thanks Ross,
    I’ll wait for you to release then and update the plugin. I’m glad you liked the code enough to use it, I’m still somewhat new to wordpress so it’s all a uphill for me!

    Cheers,
    Jon

    Plugin Author webaware

    (@webaware)

    G’day Jon,

    I haven’t added your code to the plugin, I’ve added a filter that lets you add your code to your own plugin, or your theme’s functions.php file, so that you won’t lose your code when you update this plugin 🙂

    But I’m planning a premium plugin sometime in the future, and this use case is very interesting; I’ll definitely consider making that a basic feature in the premium plugin.

    If you check for updates, under Dashboard on your admin menu, you should find the new version with the filter.

    cheers,
    Ross

    Jon Humphrey

    (@jonrandahl)

    Ross,
    I’ve just edited this post to say…

    You’re my hero! 😀

    I’ve added the filter to the functions, leaving “as is” based on your assessment and voila! we have a hi-res zip file that’s just downloaded!!!!!

    Now to go to step two and have the download gallery open in a lightbox as not to slow the lo-res slideshow initial load … care to hit two home runs in one night? 😉

    Again thank you for all your time and patience, I cannot express my gratitude enough!

    Sincerely,
    Jon

    Plugin Author webaware

    (@webaware)

    G’day Jon,

    Take this block of code and paste it into a file called “ngg-download-hires.php” or similar, and save it into the wp-content/plugins folder. You can then activate it from the WordPress admin plugins page.

    <?php
    /*
    Plugin Name: NextGEN Download HiRes add-on
    Description: Filter image paths from NextGEN Download Gallery to divert them to hi-res versions
    Version: 0.0.1
    */
    
    add_filter('ngg_dlgallery_image_path', function($loRes) {
    
        $loResSrc =  pathinfo($loRes);
        $loResImgName = $loResSrc['basename'];
        $loResImgDir = basename( $loResSrc['dirname'] );
        list($initialPath,$localPath) = explode("gallery",$loRes);
        $hiRes = $initialPath . "gallery/client-hi-res/" . $loResImgDir ."/" . $loResImgName;
    
    //~ error_log(print_r($loResSrc,1));
    error_log("initialPath = $initialPath");
    error_log("localPath = $localPath");
    error_log("hiRes = $hiRes");
    error_log("loRes = $loRes\n");
    
        //~ return $hiRes;
        return $loRes;
    
    });

    Bam! your first WordPress plugin 🙂

    cheers,
    Ross

    Jon Humphrey

    (@jonrandahl)

    Ross,

    Now you’ve got me thinking of ways to expand on this even further! I’ll mark the issue as resolved and get check back to see if anyone else expands on it more!

    Once more, thank you!

    J

    Plugin Author webaware

    (@webaware)

    G’day Jon,

    Thanks for the expression of gratitude 🙂

    For the download gallery template, did you know that you can take a copy into your own theme and customise it there? You can then hack it to bits and change what is output completely, including adding your own JavaScript such as lightboxes. See my blog post, “Creating a custom gallery template for NextGEN Gallery” for how to create custom galleries without changing the core plugin files.

    To bring up the whole download gallery in a lightbox, I’d look at writing an AJAX hook that calls do_shortcode() and returns it via AJAX. Most lightboxes can retrieve content from AJAX sources.

    cheers,
    Ross

    Hi,
    I have a question as I had a smiliar problem and also “hacked” the original code in order to fix it. I was also trying to allow users to download image files in a higher resolution.
    But I made use of the fact, that the original files are kept as *.jpg_backup and I amended the code, so that these were downloaded instead.

    I recently updated to a newer version of download gallery and for some reason I did not save my older modified version.

    Then I read about the filter you added and thought “Even better, this way I won’t have to worry about updates in the future”.
    But now it seems to me, that I can change the path of the files to be zipped (including the name), but I cannot give them a different name to be used within the zip.
    Obviously I don’t want them to have the extension .jpg_backup, but just .jpg. It seems that the zip library that is being used now does not give you the option to give a separate filename in the archive.

    Is there any way around this?

    Thanks!

    Plugin Author webaware

    (@webaware)

    G’day @el_duderino,

    Interesting approach, I like it! I’ll have a look at how the PclZip class builds its zip file and let you know whether I can do this as a simple filter.

    cheers,
    Ross

    Just wanted to let you know that I managed to find a way to do this by using a callback function from PclZip.

    $properties = $zip->create($files, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_CB_PRE_ADD, ‘my_callback_pre_add’);

    You specify a function that is called before adding a file and within that function you can manipulate the stored filename.

    Plugin Author webaware

    (@webaware)

    G’day El_Duderino,

    I love it when a problem solves itself! Thanks, and thanks for sharing the solution. I’ll include it as a filter call in the next version.

    cheers,
    Ross

    Hi webaware,

    thanks so much for developing such a great plug in (NextGEN Download HiRes add-on).
    Short question. How is it working?
    I have the plug in active in my wordpress repository.
    What are the next steps? Is it working via short code? Or what do I have to setup for a proper use?

    Thank so much!
    Best,
    frank

    Plugin Author webaware

    (@webaware)

    @die_ripps: please start a new support thread when asking for support, don’t add to an existing / resolved thread if you want an answer 🙂

    In answer to your question, you can add a template parameter to a shortcode, as described in the installation instructions:

    http://wordpress.org/plugins/nextgen-download-gallery/installation/

    In the latest NextGEN Gallery you can type in “download” where it asks you to pick a gallery template. v2.0.27 still doesn’t support gallery templates for albums though, so I recommend you stick with v1.9.13 of NextGEN Gallery for now.

    cheers,
    Ross

    I’m having a similar issue, but I’m stuck with the v2 Nextgen plugin… I’ve tried several approaches and always get close, but none of the options “just work” correctly.

    Having a hard time figuring out a solution for v2.

    forgot to check “notify me” 🙂

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘Linking to HR images (again)’ is closed to new replies.