Last updated March 19, 2012. Created by queryblitz on March 12, 2012.
Log in to edit this page.
This tutorial will show you how to offer file downloads to users who have flagged the current node. Uses for this might include having a "Buy This Item" flag and then displaying the file after the user has "bought" it.
Basically what we're going to do is set a file download CCK field to show in a block, and then set the block to display to a user only after they have flagged the node containing that field.
First, create a node type and add a file download CCK field to it.
Next, add a node flag and enable it for the node type containing the file download field. This is the flag users will have to flag in order to download the file, so you might call it something like "Buy" or "Purchase". (See this tutorial to learn how to charge userpoints when users flag the node.)
Install and enable the CCK Blocks module.
Edit the file download CCK field and set it to show as a block.
On the block settings page, set the "Show block on specific pages" to PHP, and enter this code into the text area:
<?php
if ((arg(0) == 'node') && is_numeric(arg(1))) {
$flag = flag_get_flag('name-of-flag');
if ($flag && $flag->is_flagged(arg(1))) {
return TRUE;
}
}
?>Change where it says name-of-flag to the machine name of the flag you're using.
See example at queryblitz.com/store.