Possible to hook into NextGen to submit to gallery?
-
We are currently using the very outdated “NextGEN Public Uploader” to allow the public to upload images to a NextGEN gallery. (It’s still working, but is not being kept up.)
We’d like to transition to something like your plugin, however, I was wondering if you could give me any hints as to how we might use your filters or hooks to accomplish the same thing NextGEN Public Uploader does? It submits the images to a particular NextGEN gallery, and pre-checks the “Exclude?” box, making it so the image will not be viewable until we approve it by unchecking that.
You can see the current public submission section by scrolling down to “Upload your cartoon here” on the page linked.
Thanks for any help.
The page I need help with: [log in to see the link]
-
Hi, I took a look to NextGEN Public Uploader code. How is the gallery defined?
Nickolas
Hi Nickolas,
Thanks for taking a look. There may be a lot of NextGen users out there like us that would be interested in this.
What do you mean, ‘how is the gallery defined?’
On the page where you want to allow uploads, you just use a shortcode. Also, the NextGen galleries all have IDs, the one we’re allowing public uploads to is 18.
James
Ok, so the following hook will add the uploaded files to gallery with ID 18 and will mark the files as excluded:
if (!function_exists('wfu_after_upload_handler')) { function wfu_after_upload_handler($changable_data, $additional_data) { $Gallery_ID = 18; $NextGEN_ok = ( class_exists("C_Gallery_Storage") && class_exists("C_Image_Mapper") && class_exists("C_Gallery_Mapper") ); if ( !$NextGEN_ok ) { wfu_debug_log("NextGEN classes not found. Is NextGEN plugin active?\n"); return $changable_data; } $storage = C_Gallery_Storage::get_instance(); $image_mapper = C_Image_Mapper::get_instance(); $gallery_mapper = C_Gallery_Mapper::get_instance(); $gallery = $gallery_mapper->find( $Gallery_ID ); if ( !$gallery->path ) { wfu_debug_log("NextGEN gallery with ID $Gallery_ID not found!\n"); return $changable_data; } $files = $additional_data["files"]; foreach ( $files as $file ) { $uploaded = ( $file["upload_result"] == "warning" || $file["upload_result"] == "success" ); $path = $file["filepath"]; if ( $uploaded && file_exists($path) ) { $image = $storage->object->upload_base64_image($gallery, file_get_contents($path), wfu_basename($path)); if ( $image ) { $image->exclude = 1; $image_mapper->save( $image ); } else wfu_debug_log("File ".wfu_basename($path)." was not saved in gallery ".$Gallery_ID."\n"); } } return $changable_data; } add_filter('wfu_after_upload', 'wfu_after_upload_handler', 10, 2); }
You need to put it in functions.php file of your theme.
Give it ia try and let me know.
Regards
Nickolas
Brilliant! It works perfectly, except for one thing: For Lightbox effects in NextGen, we use Responsive Lightbox & Gallery, and in NextGen, that is hooked into via NextGen’s “Other Settings” being set at Custom, and using: data-rel=”lightbox-%GALLERY_NAME%”. However, the lightbox is not working on this page now. Not sure if it’s related to your plugin, however.
But, on the Reader-Created Cartoons page where the WFU shortcode is, I’m getting this warning in Firefox Inspect: Use of Mutation Events is deprecated. Use MutationObserver instead. It points to: wordpress_file_upload_functions.js:19:361
Also, is there a way to let people add a description that will be recorded into the Description field for NextGen? That shows up under their image (when the lightbox is working). This was an option in NextGEN Public Uploader. I see WFU allows for “additional fields,” but I don’t see how that could be used to do this.
Thanks a lot, and I really think you should make this a regular part of your plugin, and you should tout it, as there are a ton of NextGen users, and I’ll bet a lot of them would like this ability.
- This reply was modified 5 years, 8 months ago by jamminjames.
Another question: Would the function you wrote affect all uploads on the site, sending them all to the NextGen gallery? If so, how can we change it to be triggered only by the shortcode on that particular page? (So I can use the plugin elsewhere for other things.)
Hi, replace the hook with the following one:
if (!function_exists('wfu_after_upload_handler')) { function wfu_after_upload_handler($changable_data, $additional_data) { $Gallery_ID = 18; $Description_Field_ID = 1; $Shortcode_ID = 1; if ( $additional_data["sid"] == $Shortcode_ID ) { $NextGEN_ok = ( class_exists("C_Gallery_Storage") && class_exists("C_Image_Mapper") && class_exists("C_Gallery_Mapper") ); if ( !$NextGEN_ok ) { wfu_debug_log("NextGEN classes not found. Is NextGEN plugin active?\n"); return $changable_data; } $storage = C_Gallery_Storage::get_instance(); $image_mapper = C_Image_Mapper::get_instance(); $gallery_mapper = C_Gallery_Mapper::get_instance(); $gallery = $gallery_mapper->find( $Gallery_ID ); if ( !$gallery->path ) { wfu_debug_log("NextGEN gallery with ID $Gallery_ID not found!\n"); return $changable_data; } $files = $additional_data["files"]; foreach ( $files as $file ) { $uploaded = ( $file["upload_result"] == "warning" || $file["upload_result"] == "success" ); $path = $file["filepath"]; if ( $uploaded && file_exists($path) ) { $image = $storage->object->upload_base64_image($gallery, file_get_contents($path), wfu_basename($path)); if ( $image ) { $image->exclude = 1; if ( $Description_Field_ID > 0 && isset($file["user_data"][$Description_Field_ID - 1]) ) $image->description = $file["user_data"][$Description_Field_ID - 1]["value"]; $image_mapper->save( $image ); } else wfu_debug_log("File ".wfu_basename($path)." was not saved in gallery ".$Gallery_ID."\n"); } } return $changable_data; } } add_filter('wfu_after_upload', 'wfu_after_upload_handler', 10, 2); }
Variable $Description_Field_ID defines the field ID in the form that prompts the user to add a description. If you have only one field, then it will be 1.
Variable $Shortcode_ID defines the ID of the shortcode. By default it is 1. If you set it to something else, only images uploaded by that shortcode will be added to NextGEN.Regarding the data-rel attribute, have you made any custom changes to NextGEN Other Options?
The Mutation Events is probably a bug. I will check it.
Regards
Nickolas
You are amazing, Nickolas. Works perfectly. Again, I’d recommend making this a permanent part of the plugin, and letting NextGen users know about it — maybe even add it to your main plugin description, as many people would like this functionality, and I don’t think any other plugin provides it, other than the defunct one I was using.
Regarding the problem I’m having with the lightbox and the data-rel attribute, I discovered it’s happening on some other posts as well, not just the one using WordPress File Upload. I have not made any other custom changes to NextGEN’s Other Options, just for Lightbox Effects. In the “Effect” dropdown, I chose “Custom,” and in “Code” I have
data-rel="lightbox-%GALLERY_NAME%"
. I’ve been going through all the post settings and NextGen settings for each post, to make sure everything is exactly the same. It’s very strange, but the js for the lightbox is not getting included on the offending pages for some reason (I checked the page source), but is on the others.- This reply was modified 5 years, 8 months ago by jamminjames.
I followed your procedure. When I open a gallery in a page, I see data-rel attribute inside every image.
Then I activated the hook and uploaded a new image. It was added to the gallery successfully. I then went to Manage Gallery, located the image and deactivated “Excluded” property, so that it is visible.
When I opened the gallery again in the page, the data-rel attribute was correctly added inside the new image.
Did you follow the same procedure also?
Nickolas
It’s not the data-rel attribute on the thumbnails that’s the problem, it’s that the responsive-lightbox script is not being loaded on the page, so the lightbox display of images doesn’t work.
You can see the difference on this page, where it’s working. Click on a thumbnail, and the lightbox displays the images: https://www.humortimes.com/6576/rob-rogers-editorial-cartoons/.
For some reason, the responsive-lightbox script is not being loaded on the https://www.humortimes.com/amateur-cartoons/ page. Clicking on a thumbnail, it simply shows the image without the lightbox, so you can’t swipe or click to the next image, etc, like you can with the lightbox.
If you look at the page sources for each page, you can see the script is being loaded on one, but not the other.
All the settings are the same: The NextGen gallery settings, the post settings, format, etc. I flushed all the caches as well. So, I don’t understand it.
I installed NextGEN and the lightbox in my environment. They seem to work fine. Did you check lightbox settings?
Nickolas
Well, yes, I’d been over those as well as the NextGen settings several times. However, this time I unchecked “Conditional loading – Enable to load scripts and styles only on pages that have images or galleries in post content,” and now it’s working.
I figured it would know when there’s a NextGen gallery there, but apparently not always. It’s odd, because as I said, it was working on some pages. All of the posts are set as “standard” format pages, not “gallery”, so that’s not it.
I’d prefer not to load unnecessary scripts on pages, but I guess I can live with it.
Thanks for helping me work through this, and especially for your fine plugin and the custom code you wrote for me!
Do you think you’ll integrate it into the regular plugin?
Yes this is a very good idea. I will add it in the shortcode options, in Interoperability tab. It will be included in the next release, coming in a few weeks with options for setting custom gallery ID, alt-text, description, tags and exclude setting.
I made an announcement about it today through Iptanus page in facebook and twitter.
Thank you for your suggestion. I will kindly offer you the Pro version if you want free-of-charge, however you need to send me an email at [email protected] because I am not allowed to discuss Pro version issues from this forum.
Regards
Nickolas
That’s awesome! I think it’ll be a very popular use of your app. (I’d suggest touting that use of the plugin early in your description, once it’s operational.)
That’s very generous, thank you, I’ll email you!
WOW! Thank you for this thread! I have been using NexGEN Public Uploader for years for my bbPress forum page. I allow anonymous forum use and needed a way to allow dog owners to upload their photos of ill dogs safely into a NexGEN gallery that is set to run a slideshow in the sidebar. Unfortunately the NexGEN Public Uploader had to be removed, the plugin was causing errors on the site.
I searched for new file uploader and finally settled on WordPress File Uploader. So I also would love to have it hook into my NexGEN gallery.
Thank you so much for the wonderful plugin! It is so important for our dog owners to share their dog pictures, we run 300-400 photos through a slide show, those that survived and those who didn’t.
My solution before I read this thread was that the admins would go into the Media gallery and download the photos to their computer and then move them back up to the NexGEN gallery. Right now I am having a problem that the SELECT FILE and UPLOAD buttons only display when someone is logged in, but not for our anonymous forum users. I believe that there must be some way to allow this and that is my next step to research.
So, @nickboss, if I copy the second page of code and drop it into my functions.php file (where should I put this exactly?), (making sure to note the correct gallery ID) this should work? I don’t often mess with the php files like this. Unfortunately I never made a child theme since this site was built 11 years ago, but I do keep track of my changes so I can go in and remove that code if there is a problem.
Thank you for your help, MatocaHi, edit the shortcode with the shortcode composer of the plugin and locate options Upload Roles and Upload Users. Check “Include guests” option so that non-logged users can view the upload form.
Yes if you put the second script at the end of functions.php file of your theme and set the correct gallery ID it would work (hopefully). If you mesh it up and your website crashes, you can role back changes through FTP access.
Regards
Nickolas
- The topic ‘Possible to hook into NextGen to submit to gallery?’ is closed to new replies.