PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Relative links in download restricted documents?

s2Member Plugin. A Membership plugin for WordPress®.

Relative links in download restricted documents?

Postby dhempy » August 22nd, 2011, 5:22 pm

I've searched this forum without finding this scenario, and tried a few experiments without luck.

I've got a file I'm restricting with s2member's File Download Restrictions. The file in question is a Flash animation (lab.swf), but this question would apply to a protected .html file as well. This Flash file references another flash file (beaker.swf). Before we attempted to restrict access to the file, the container animation used a relative reference to the second animation, assuming it is in the same directory. So, lab.swf has the Flash equivalent of <img src="beaker.swf" /> in it.

Now that our link to the container file uses a query string
(e.g. http://example.com/?s2member_file_download=lab.swf ) , relative links lose the query string. The second file's HTTP request ends up like this:
(e.g. http://example.com/beaker.swf )

This file, of course, does not exist, and s2member never gets a change to process the s2member_file_download parameter.

We have the option of recompiling all our .swf files with hard-coded links including the query string, but this does not work when we deploy these files in other ways.

Is there a way to use relative links in a download-protected document? Perhaps use a virtual directory instead of a query string to link to the container file? Some other clever hack I'm overlooking?

FWIW, I'm new to s2member, fairly new to WordPress, and a 20-year web programmer veteran.

-dave

ps. I'm still evaluating s2member vs. other plugins for this project, and so far YOU GUYS ROCK!!!
User avatar
dhempy
Registered User
Registered User
 
Posts: 14
Joined: August 5, 2011

Re: Relative links in download restricted documents?

Postby Cristián Lávaque » August 23rd, 2011, 2:10 am

Thanks for the kudos, Dave! Glad you're liking s2Member. :)

I'm emailing Jason so he helps you with this.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Relative links in download restricted documents?

Postby Jason Caldwell » August 23rd, 2011, 7:38 pm

Thanks for the heads up on this thread Cristián.
~ and thanks for the excellent question.

Well, in HTML, I've seen site owners use a BASE HREF tag like this:
Code: Select all
<head>
<base href="http://example.com/?s2member_file_download=" />
</head>

In Flash though, that would not work. You could try mod_rewrite with a virtual directory. That way all requests for http://example.com/virtual-directory/file.swf would be re-written with mod_rewrite for Apache, by converting them to: http://example.com/?s2member_file_download=file.swf.

Either that, or you may need to pass a BASE HREF value into your Flash file using FlashVars, and then use that inside your ActionScript to reformulate all relative locations into full URLs.

I hope that helps :) Thanks for the KUDOS!!
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Relative links in download restricted documents?

Postby dhempy » August 24th, 2011, 9:37 am

Ah! Not sure why I didn't think of mod_rewrite. I'll give that a stab.

I had some success with <base href...> but had other issues.

Thanks, Jason!

-dave
User avatar
dhempy
Registered User
Registered User
 
Posts: 14
Joined: August 5, 2011

Re: Relative links in download restricted documents?

Postby dhempy » August 25th, 2011, 3:14 pm

Bingo!!! :-)

This basic rule got me the needed functionality, quite gracefully:

Code: Select all
RewriteRule ^lab_files/(.*)$ index.php?s2member_file_download=$1 [L] 


That converts this:
Code: Select all
http://example.com/lab_files/lab.swf

...to this:
Code: Select all
http://example.com/index.php?s2member_file_download=lab.swf


I added this to my root .htaccess file. I think you could put it in httpd.conf or s2member-files/.htaccess if it suited you. I then tweaked it a bit further to use the default virtual directories in our WordPress permalinks a bit more gracefully, and to only match Flash .swf files:

Code: Select all
RewriteRule ^apparatus/(.+\.swf)$ bogus_path/?s2member_file_download=$1 [L] 


This supports subfolders, so post slugs under custom post types work seamlessly, allowing differrent posts to use different files with the same name with no conflicts. (e.g. lab.swf in several different labs.) The "bogus_path" folder can be any path that does not exist and is not used on the site. No one ever sees that path.

This makes the following transformations:
Code: Select all
http://example.com/apparatus/force-table/lab.swf   becomes:
http://example.com/bogus_path?s2member_file_download=force_table/lab.swf

http://example.com/apparatus/gravity/lab.swf   becomes:
http://example.com/bogus_path?s2member_file_download=gravity/lab.swf


Most importantly, when lab.swf refers to src=beaker.swf (with no path/query information), it makes this request of the server:

Code: Select all
http://example.com/apparatus/force-table/beaker.swf


...which works perfectly. This is great for our site, where the will only be a dozen posts using this technique, without frequent updates. If this was seeing dozens of posts per day, using subfolders for each might be a bit annoying to maintain. Maybe better to have a naming convention that allows all files to be in one folder without fear of conflicts.

THANK YOU, JASON! You just got yourself a paying customer!

-dave


ps. I'm sure you recommend the following elsewhere, but I hadn't noticed it until now. FWIW, I created an .htaccess file in the s2member-files folder with one line:

Code: Select all
deny from all


This prevents someone from gaining some insight into our use of s2member (unlikely) and downloading the file directly, bypassing WordPress and s2member entirely.

And in the spirit of belts-n-suspenders paranoia, I added the following to httpd.conf, which duplicates the "deny from all" in the folder's .htaccess file:

Code: Select all
   <Directory /var/www/example.com/wp-content/plugins/s2member-files/   >
      Options -Indexes FollowSymLinks MultiViews
      Order allow,deny
      deny from all
   </Directory>


Cheers,
-dave
Last edited by dhempy on August 29th, 2011, 10:37 am, edited 1 time in total.
User avatar
dhempy
Registered User
Registered User
 
Posts: 14
Joined: August 5, 2011

Re: Relative links in download restricted documents?

Postby Cristián Lávaque » August 26th, 2011, 9:48 pm

Great stuff, Dave. Thanks for sharing it. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Relative links in download restricted documents?

Postby Jason Caldwell » August 27th, 2011, 3:54 pm

Awesome work Dave. Yea, I think we're going to include this technique in a future release of s2Member as a way to work around issues related to query strings and relative paths. Again, thank you!
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Relative links in download restricted documents?

Postby dhempy » August 29th, 2011, 10:37 am

:-D
User avatar
dhempy
Registered User
Registered User
 
Posts: 14
Joined: August 5, 2011

Re: Relative links in download restricted documents?

Postby Jason Caldwell » January 19th, 2012, 2:52 pm

s2Member now implements Advanced Mod-Rewrite Linkage that makes this easier.
See: viewtopic.php?f=4&t=16886&p=61010#p61010
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA


Return to s2Member Plugin

Who is online

Users browsing this forum: Google [Bot] and 2 guests

cron