Using Squeeze with FileField Stats allows the user to view the node prior to download and then directs them to the webform upon clicking the file link. After submission of the form the file is downloaded.

What would it take to automatically direct the user back to the original node following file download?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kbk’s picture

I've figured out a way to do this. Comments on how hackish it is or how to improve it are welcome. Both changes are to squeeze.module. Add the following after $current_menu_item is set in the squeeze_init() function:

  if (squeeze_is_supported_type($current_menu_item['page_arguments'][0]->type)) {
    $_SESSION['original_node'] = $current_menu_item['page_arguments'][0]->nid;
  }

Place the following at the end of the squeeze_webform_save_sid_on_submit() function:

  if ($_SESSION['original_node']) {
     drupal_goto('node/'. $_SESSION['original_node']);
     $_SESSION['original_node'] = FALSE;
  }

Edit: nevermind, this aborts the download.

pavel.karoukin’s picture

kbk, this is actually a one feature I would like to see.

To implement it, we need to redirect user back to node and add some JS code into footer to start download.
Also we will need to add message with link to direct download of the file for cases where JS do not work.

fietserwin’s picture

@scrypt: I think you are on the right track about the order of events. However, I never looked into "these download pages" that say 'your download should start automatically within 5 seconds, or click here if not.'

The link to the download though, should be on the page. At least it was when squeeze intercepted the download ... Message could be something like "Thank you for filling in your details. The download should now automatically start. If not, click again on the link to the document." but should probably be configurable (and passed through t() or, officially, translated with i18n_string as it is user input).

Some searching brought me to: http://stackoverflow.com/questions/156686/how-to-start-automatic-download-of-a-file-in-internet-explorer. Answer 4, together with the fac tthat the link to the download is on the page, brought me the solution: just add this javascript:

$("<downloadLinkSelector>" ).click();

Where is the selector to get the link to the download link. To get that selector, may not be so easy as you might think, as there is no id, no class ...

kbk’s picture

I may have a developer who can work on this if you can't get to it. Is this the case? If so, any additional thoughts or documentation that you can throw out would probably facilitate development of the patch.

pavel.karoukin’s picture

kbk, it is great that you can take care of it. Ideally I would see new setting in admin for "download will start now" message. Then this message will be shown via drupal_set_message() after redirecting user from webform back to node.

To start file download, link to file might be passed via Drupal.settings JS variable to some simple javascript to start file download...

Something like this just to start ball rolling. Let me know if this is too vague.

kevinchampion’s picture

Status: Active » Needs review
FileSize
5.75 KB

Here's a patch to add in this feature. It adds 2 new admin settings, one to turn the redirecting on (set to on by default), and one to customize the drupal_set_message displayed at the top of the redirected page as suggested by @scrypt. Here's how it works:

It adds a new SESSION variable in squeeze_init to store the origin path. At first I just used the node of the protected page/file as the origin, but after discussion with @kbk, it became clear that that wouldn't gracefully handle the instance where a protected page/file was linked to from some other page on the site. So, I built in squeeze_get_origin to check HTTP_REFERER to find out where the true origin is instead of relying on the node. This handles 4 use cases:

  1. if you try to access protected content directly with no referrer, it redirects to the associated node
  2. if you are linked directly to protected content from outside the site, it redirects to the associated node
  3. if you are linked to a protected file from its associated node, it redirects back to the associated node
  4. if you are linked directly to protected content from a different page inside the site, it redirects back to that page (not to the associated node)

In squeeze_webform_save_sid_on_submit it checks for the presence of this new SESSION variable and if it exists, sets the message, sets the redirect path, and declares another SESSION variable. Then using the 'view' case in squeeze_nodeapi, it checks for the existence of the new variable and spits out some javascript to initiate the download if it exists.

pavel.karoukin’s picture

Thank you for a patch. I will get back to site in a week or so, to test it in near-production environment.

In the mean time If someone else can confirm it work, please post here your testing results.

kbk’s picture

FYI, I went ahead and deployed this. The download doesn't begin automatically for me. The page redirect works (setup similar to point 4. in comment #6, above) and the admin components are in place.

Here's an example if you want to try: http://umbs.lsa.umich.edu/research/data/major-and-minor-landforms-of-umb...