Page 1 of 1

Allow access to a download protected file for anyone

PostPosted: May 31st, 2011, 3:35 am
by StenCade
Hi there, awesome product, thank you!

I am trying to use s2member in conjunction with the NextGEN gallery plugin. What I want is for anyone to be able to access the public album page, which shows a thumbnail, description, etc of each protected photo gallery. This is easy to do by making the album page public and the gallery pages protected.

However, I would also like the added security of download protection. I moved the gallery files into the s2member-files folder and set protected jpgs to display inline. The galleries work as expected. However, this obviously means that the thumbnail images, which are generated and stored by NextGEN all in the same subfolder, no longer display on my public page.

It would be a serious pain to have to code the thumbnails in manually, not to mention a bit too much for my client to handle. Is there a way that I can allow a handful of specific files in the same folder as my protected files to be seen by anyone? The Key thing doesn't work because I need anyone to be able to see the images as many times as they load the album page.

Thanks!
Sten

Re: Allow access to a download protected file for anyone

PostPosted: May 31st, 2011, 1:29 pm
by Cristián Lávaque
Hi Sten.

Why would the keys not work for that? They're not limited by number of downloads, they just have a 24 hour expiration, but the key gets generated each time the page is, thus starting a new 24 hrs before expiration.

Re: Allow access to a download protected file for anyone

PostPosted: May 31st, 2011, 6:33 pm
by StenCade
Hm, I must be doing something wrong then. I'm having to do a bit of hacking to get NextGEN to print the image link for me so there's some room for error...

Let me mess with is a bit and see if I can't find my mistake. At least I know I'm on the right track!

Re: Allow access to a download protected file for anyone

PostPosted: May 31st, 2011, 10:36 pm
by StenCade
OK! I got it working! I was giving s2member_file_download_key() the filename instead of the relative path AND filename.

Here's the code for anyone who needs this functionality.

NextGEN documentation will tell you how to edit the album-extend.php and where to put it and all that. So, in "album-extend.php" (or "album-compact.php"), just after the line
Code: Select all
<?php foreach ($galleries as $gallery) :

I inserted
Code: Select all
   /** Takes gallery thumbnail and edits the url so s2member will allow access by anyone **/
   $thumbfilename = "thumbs_".$gallery->previewname;
   $thumburl = $gallery->previewurl;
   //cut down to just the relative path
   $urlpieces = parse_url($thumburl);
   $thumbpath = $urlpieces['query'];
   //cut out the "s2member_file_download=" part
   $thumbpath = str_replace("s2member_file_download=", '', $thumbpath);
   //Make key
   $key = s2member_file_download_key("$thumbpath");
   //Add key
   $keystring = "&s2member_file_download_key=".$key;
   $keyedurl = $gallery->previewurl . $keystring;


Then just below that, in the "ngg-thumbnail" class, change
Code: Select all
src="<?php echo $gallery->previewurl ?>

into
Code: Select all
src="<?php /*Here's the part I changed*/ echo $keyedurl; ?>

Re: Allow access to a download protected file for anyone

PostPosted: May 31st, 2011, 10:57 pm
by Cristián Lávaque
Thanks for the update! I'm very glad you solved and thanks a lot for sharing your solution with others here; very appreciated. :)