WordPress.org

Ready to get started?Download WordPress

Forums

NextGEN Download Gallery
[resolved] Linking to HR images (again) (24 posts)

  1. Jon Humphrey
    Member
    Posted 1 year ago #

    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/

  2. webaware
    Member
    Plugin Author

    Posted 1 year ago #

    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

  3. Jon Humphrey
    Member
    Posted 1 year ago #

    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

  4. webaware
    Member
    Plugin Author

    Posted 1 year ago #

    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

  5. Jon Humphrey
    Member
    Posted 1 year ago #

    Ross,
    I've just edited this post to say...

    You're my hero! :-D

    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

  6. webaware
    Member
    Plugin Author

    Posted 1 year ago #

    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

  7. Jon Humphrey
    Member
    Posted 1 year ago #

    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

  8. webaware
    Member
    Plugin Author

    Posted 1 year ago #

    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

  9. El_Duderino
    Member
    Posted 11 months ago #

    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!

  10. webaware
    Member
    Plugin Author

    Posted 11 months ago #

    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

  11. El_Duderino
    Member
    Posted 11 months ago #

    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.

  12. webaware
    Member
    Plugin Author

    Posted 11 months ago #

    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

  13. Die_Ripps
    Member
    Posted 11 months ago #

    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

  14. webaware
    Member
    Plugin Author

    Posted 11 months ago #

    @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

  15. mellowvision
    Member
    Posted 11 months ago #

    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.

  16. mellowvision
    Member
    Posted 11 months ago #

    forgot to check "notify me" :)

  17. webaware
    Member
    Plugin Author

    Posted 11 months ago #

    @mellowvision: please start a new topic, and fully describe your problem. This thread has more than one issue discussed already, I need you to please be specific in describing your problem in a new topic.

    cheers,
    Ross

  18. cevenson
    Member
    Posted 10 months ago #

    If you enable 'back up images' in the Nextgen options you can download the hires backed-up version rather than the web res version displayed on the site.

    Change the hires file path to
    $hiRes = $initialPath . "gallery/" . $loResImgDir ."/" . $loResImgName."_backup";

    Anyone know how to strip the _backup off the name before zipping?

  19. webaware
    Member
    Plugin Author

    Posted 10 months ago #

    G'day cevenson,

    El_Duderino in a post above tells how he did it. The next version of this plugin has a filter ngg_dlgallery_zip_pre_add that will allow you to specify the PCLZIP_CB_PRE_ADD filter without hacking the plugin; I hope to have it out by early next week, just need to find some time to finalise a couple of things.

    Very soon (I keep promising!) I'll have a premium plugin available that will cleanly handle all of this without need for modifications. Just need a little more clear air!

    cheers,
    Ross

  20. cevenson
    Member
    Posted 10 months ago #

    Ahh. Should have read the whole lot. Thanks

  21. AndrewRaia
    Member
    Posted 9 months ago #

    Hey guys, new user here so pardon if I miss something, but how does it know where to find the hi-res files? Is there a way to make it auto locate the backups that are created after gallery resizes them?

  22. AndrewRaia
    Member
    Posted 9 months ago #

    sorry I see cevenson posted it, ill need to figure it out, my apologies

  23. Stefanrem
    Member
    Posted 9 months ago #

    For me it is still hard to understand how to strip the _backup off the name before zipping. Can anyone tell me what code to put were. with the _backup in the file name the download plugin is useless to me.

  24. miclgael
    Member
    Posted 8 months ago #

    Hi there,

    Thank you for the plug-in, and those who have contributed to this post. It has gotten me very close to what my client needs (basically, just to download the Hi Res / backup version of the file)

    Do you think it would be possible to receive a quick summary of @El_Duderino's methods, with snippets?

    So far I have made the plug-in add on, and I have copied the code @cevenson posted into "NextGEN Download HiRes add-on"

    $hiRes = $initialPath . "gallery/" . $loResImgDir ."/" . $loResImgName."_backup";

    Thanks very much for your time.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic