- Posts: 25
COMMUNITY FORUM
Limit Attachment Downloads to Registered Users?
- benbogart
- Topic Author
- Offline
- Junior Member
Less
More
12 years 11 months ago #57102
by benbogart
Limit Attachment Downloads to Registered Users? was created by benbogart
Is it possible to limite attachment downloads to registered users?
Please Log in or Create an account to join the conversation.
- troponin
- Offline
- Platinum Member
Less
More
- Posts: 398
12 years 11 months ago - 12 years 11 months ago #57103
by troponin
Replied by troponin on topic Re: Limit Attachment Downloads to Registered Users?
You'll have to set a if...else Clause in the item.php where you check the Usergroup of the User like :
Log in or Create an account to join the conversation.
- benbogart
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 25
12 years 11 months ago #57104
by benbogart
Replied by benbogart on topic Re: Limit Attachment Downloads to Registered Users?
Thank you!
Please Log in or Create an account to join the conversation.
- Adrian Cumpanasu
- Offline
- New Member
Less
More
- Posts: 17
12 years 5 months ago - 12 years 5 months ago #57105
by Adrian Cumpanasu
Replied by Adrian Cumpanasu on topic Re: Limit Attachment Downloads to Registered Users?
can you give me exactly the path to item.php?
Also, where exactly should this code be inserted?
can the code be adapted to restrict download if the item is featured?
I tried this code in components/com_k2/templates/default/item.php but I get a blank page.
Here are the lines of code I found:
then I replaced this:with
So I get a blank page. not working the way I understood.
Also, where exactly should this code be inserted?
can the code be adapted to restrict download if the item is featured?
I tried this code in components/com_k2/templates/default/item.php but I get a blank page.
Here are the lines of code I found:
<?php if($this->item->params->get('itemAttachments') && count($this->item->attachments)): ?>
<!-- Item attachments -->
<div class="itemAttachmentsBlock">
<span><?php echo JText::_('K2_DOWNLOAD_ATTACHMENTS'); ?></span>
<ul class="itemAttachments">
<?php foreach ($this->item->attachments as $attachment): ?>
<li>
<a title="<?php echo K2HelperUtilities::cleanHtml($attachment->titleAttribute); ?>" href="<?php echo $attachment->link; ?>"><?php echo $attachment->title; ?></a>
<?php if($this->item->params->get('itemAttachmentsCounter')): ?>
<span>(<?php echo $attachment->hits; ?> <?php echo ($attachment->hits==1) ? JText::_('K2_DOWNLOAD') : JText::_('K2_DOWNLOADS'); ?>)</span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
then I replaced this:
<?php if($this->item->params->get('itemAttachments') && count($this->item->attachments)): ?>
<?php $user =& JFactory::getUser(); ?>
<php if($user->get('guest') ==0 ): ?>
So I get a blank page. not working the way I understood.
Please Log in or Create an account to join the conversation.
- Adrian Cumpanasu
- Offline
- New Member
Less
More
- Posts: 17
12 years 5 months ago - 12 years 5 months ago #57106
by Adrian Cumpanasu
Replied by Adrian Cumpanasu on topic Re: Limit Attachment Downloads to Registered Users?
Wow, I did it!!! I found a condition on the comments lines, copied and modified it.
This is what I have now working:
This code hides the download link and display a registration text for unregistered users.
But what I really need is to show all articles and links to guests, but only on the featured articles to show the article but hide the download link.
I will try to do it myself even if I don't know php. I tell you if I succeed. I would appreciate some help.
This is what I have now working:
<?php if($this->item->params->get('itemAttachments') && count($this->item->attachments)): ?>
<?php $user = &JFactory::getUser(); if ($user->guest): ?>
<h2>You need to <a href="http://digitalprimes.com/index.php/component/users/?view=registration">register</a> to download this file.</h2>
<h3>...registration is free</h3>
<?php endif; ?>
<?php $user = &JFactory::getUser(); if (!$user->guest): ?>
<div class="itemAttachmentsBlock">
<span><?php echo JText::_('K2_DOWNLOAD_ATTACHMENTS'); ?></span>
<ul class="itemAttachments">
<?php foreach ($this->item->attachments as $attachment): ?>
<li>
<a title="<?php echo K2HelperUtilities::cleanHtml($attachment->titleAttribute); ?>" href="<?php echo $attachment->link; ?>"><?php echo $attachment->title; ?></a>
<?php if($this->item->params->get('itemAttachmentsCounter')): ?>
<span>(<?php echo $attachment->hits; ?> <?php echo ($attachment->hits==1) ? JText::_('K2_DOWNLOAD') : JText::_('K2_DOWNLOADS'); ?>)</span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<?php endif; ?>
This code hides the download link and display a registration text for unregistered users.
But what I really need is to show all articles and links to guests, but only on the featured articles to show the article but hide the download link.
I will try to do it myself even if I don't know php. I tell you if I succeed. I would appreciate some help.
Please Log in or Create an account to join the conversation.
- Ro
- Offline
- New Member
Less
More
- Posts: 7
12 years 4 months ago #57107
by Ro
Replied by Ro on topic Re: Limit Attachment Downloads to Registered Users?
Hello all!
I´m also looking for a way of doing this and, although this method do work (thank you all involved in the solution!), I´m concerned regarding one detail: this limit decides whether if the donload link is shown or not, but if anyone did know the URL of the download link, the attachment could be downloaded, either being logged in the system or not.
In fact, I´ve also tried to make a "Copy link URL" of an attachment of a site that is offline (still in developement), and pasted that link in a new browser. The download is active, even when the site is offline.
Would it be possible to include a limitation inside the script that serves the attachment?
Thanks in advance!
Best regards.
I´m also looking for a way of doing this and, although this method do work (thank you all involved in the solution!), I´m concerned regarding one detail: this limit decides whether if the donload link is shown or not, but if anyone did know the URL of the download link, the attachment could be downloaded, either being logged in the system or not.
In fact, I´ve also tried to make a "Copy link URL" of an attachment of a site that is offline (still in developement), and pasted that link in a new browser. The download is active, even when the site is offline.
Would it be possible to include a limitation inside the script that serves the attachment?
Thanks in advance!
Best regards.
Please Log in or Create an account to join the conversation.