Anonymous user attachment warning message
If your site is configured to only allow logged-in users to access attachments, this snippet will display a warning message and login box when anonymous users access a node with attachments (which they would otherwise not know is there). I found that without this, logged out users couldn't access the attachments and couldn't work out why!
1. In the 'Block body' field paste...
<?php global $user; ?>
<?php if ($user->uid) : ?>
<span class="login_text">Welcome, </span> <?php print ($user->name); ?> <br>
<?php print l("Your Account",'user/'.$user->uid); ?> |
<?php print l("Log-Out","logout"); ?>
<?php else : ?>
<?php print "<strong>One, or more, documents are attached to this page. In order to download, print or access these documents you must be logged in.</strong>"; ?>
<?php print drupal_get_form('user_login_block'); ?>
<?php endif; ?>... and, activate PHP code option in this fields input format.
2. In the 'Role specific visibility settings' section...
Select 'anonymous user'
3. In the 'Page specific visibility settings' section paste...
<?php
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
$files = $node->files;
foreach ($files as $file) {
if ($file->list) {
return TRUE;
}
else {
return FALSE;
}
}
}
?>... and, activate PHP code option in this fields input format.
4. In the Administration | blocks screen don't forget to choose where to display the block - I chose 'content'.
That's it!
