- Posts: 9
COMMUNITY FORUM
attachments k2 to registered users only
- ermanno
- Topic Author
- Offline
- New Member
Less
More
8 years 10 months ago #144011
by ermanno
attachments k2 to registered users only was created by ermanno
someone would know how to explain to limit the downloading attachments k2 to registered users only?
I found several guides on how to do this but none seem to work ... maybe because they were for older versions?
many thanks for the help
I found several guides on how to do this but none seem to work ... maybe because they were for older versions?
many thanks for the help
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
8 years 10 months ago #144020
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic attachments k2 to registered users only
You can access Joomla!'s user object and hide/ show specific content in the K2 item.
docs.joomla.org/Accessing_the_current_user_object
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
Please note that a user might still be able to see the attachments if he/she access the item using a different template. You can prevent this by a) creating a custom K2 plugin which handles only the attachments or an easier way would be to block all URL containing ?template= or &template= .
docs.joomla.org/Accessing_the_current_user_object
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
Please note that a user might still be able to see the attachments if he/she access the item using a different template. You can prevent this by a) creating a custom K2 plugin which handles only the attachments or an easier way would be to block all URL containing ?template= or &template= .
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Rinald Mamachev
- Offline
- New Member
Less
More
- Posts: 3
8 years 9 months ago #144856
by Rinald Mamachev
Replied by Rinald Mamachev on topic attachments k2 to registered users only
Hi Krikor
Many thanks for your reply. I have the same issue, I need to restrict download of the attachment to registered users only. Unfortunately, I am not a programmer and not sure how to add the codes to the files.
Are you able to explain in a bit more details how to achieve this for me?
Thanks in advance.
Regards
Rinald
Many thanks for your reply. I have the same issue, I need to restrict download of the attachment to registered users only. Unfortunately, I am not a programmer and not sure how to add the codes to the files.
Are you able to explain in a bit more details how to achieve this for me?
Thanks in advance.
Regards
Rinald
Please Log in or Create an account to join the conversation.
- ermanno
- Topic Author
- Offline
- New Member
Less
More
- Posts: 9
8 years 9 months ago #144857
by ermanno
Replied by ermanno on topic attachments k2 to registered users only
First, locate the file "item.php" used by the template.
If the template uses a K2 subtemplate for its location should be as follows:
/templates/NAME_OF_TEMPLATE/html/com_k2/templates/default/item.php
If this is NOT a subtemplate its position will be as follows:
/components/com_k2/templates/default/item.php
when you find the correct file, find the section of code that defines attachments within articles K2.
Usually "should" be present commentary:
<! - Item attachments ->
If there is noT search for the tags:
itemAttachmentsBlock
So position yourself BEFORE the code for the lock and enter the level control of who is viewing the page, not allowing the visibility to users "guest"
<? Php $ user = JFactory :: getUser (); ?>
<? Php if ($ this-> item-> params-> get ('itemAttachments') && count ($ this-> item-> attachments)):?>
<? Php if ($ user-> guest):?>
<P> Please log in to access the attachments </ p>
<? Php else:?>
Replace "Please log in to access the attachments" text with the text as you like ...
then at the END add closing:
<? Php endif; ?>
<? Php endif; ?>
and that's all!
If the template uses a K2 subtemplate for its location should be as follows:
/templates/NAME_OF_TEMPLATE/html/com_k2/templates/default/item.php
If this is NOT a subtemplate its position will be as follows:
/components/com_k2/templates/default/item.php
when you find the correct file, find the section of code that defines attachments within articles K2.
Usually "should" be present commentary:
<! - Item attachments ->
If there is noT search for the tags:
itemAttachmentsBlock
So position yourself BEFORE the code for the lock and enter the level control of who is viewing the page, not allowing the visibility to users "guest"
<? Php $ user = JFactory :: getUser (); ?>
<? Php if ($ this-> item-> params-> get ('itemAttachments') && count ($ this-> item-> attachments)):?>
<? Php if ($ user-> guest):?>
<P> Please log in to access the attachments </ p>
<? Php else:?>
Replace "Please log in to access the attachments" text with the text as you like ...
then at the END add closing:
<? Php endif; ?>
<? Php endif; ?>
and that's all!
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
8 years 9 months ago #144864
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic attachments k2 to registered users only
Hello,
This post will help you override/ locate item.php getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
This post will help you override/ locate item.php getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Rinald Mamachev
- Offline
- New Member
Less
More
- Posts: 3
8 years 9 months ago #144878
by Rinald Mamachev
Replied by Rinald Mamachev on topic attachments k2 to registered users only
Thanks,
I tried your code and this is what I have:
<!-- Item attachments -->
<!--To control access to attachments to registered users only -->
<?php $user = JFactory::getUser(); ?>
<?php if($this->item->params->get('itemAttachments') && count($this->item->attachments)): ?>
<?php if ($user->guest): ?>
<p> Please log in to download FULL text </p>
<?php else: ?>
<?php endif; ?>
<?php endif; ?>
<!-- end control access -->
<div class="itemAttachmentsBlock">
This code simply displays the text on the top of the page "Please log in to download FULL text" but the attachment link is still visible and downloadable by users. I had a dig and found another code that used to work on Joomla 2.5, older K2 component, but when I add it to my latest K2 on Joomla 3.4 the result is the same, I see the text to login to view attachment but no attachment and if I login, still the same text but no link to attachment, this is the code:
<!-- Item attachments -->
<?php if($this->item->params->get('itemAttachments') && count($this->item->attachments) && $this->user->guest): ?>
<!--if guest -->
<div class="itemAttachmentsBlock">
<span><?php echo JText::_('K2_DOWNLOAD_ATTACHMENTS'); ?></span>
<ul class="itemAttachments">
<li>
Login to view PDF
</li>
</ul>
</div>
<!--end if guest-->
<?php else: ?>
<!--if logged in-->
<div class="itemAttachmentsBlock">
<span><?php echo JText::_("Download attachments:"); ?></span>
<ul class="itemAttachments">
<?php foreach ($this->item->attachments as $attachment): ?>
<li>
<a title="<?php echo htmlentities($attachment->titleAttribute, ENT_QUOTES, 'UTF-8'); ?>" href="<?php echo JRoute::_('index.php?option=com_k2&view=item&task=download&id='.$attachment->id); ?>">
<?php echo $attachment->title ; ?>
</a>
<?php if($this->item->params->get('itemAttachmentsCounter')): ?>
<span>(<?php echo $attachment->hits; ?> <?php echo (count($attachment->hits)==1) ? JText::_("download") : JText::_("downloads"); ?>)</span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<div class="clr"></div>
</div>
<!--end if logged in-->
<?php endif; ?>
I don't know what to make of it. Any suggestions?
Regards
I tried your code and this is what I have:
<!-- Item attachments -->
<!--To control access to attachments to registered users only -->
<?php $user = JFactory::getUser(); ?>
<?php if($this->item->params->get('itemAttachments') && count($this->item->attachments)): ?>
<?php if ($user->guest): ?>
<p> Please log in to download FULL text </p>
<?php else: ?>
<?php endif; ?>
<?php endif; ?>
<!-- end control access -->
<div class="itemAttachmentsBlock">
This code simply displays the text on the top of the page "Please log in to download FULL text" but the attachment link is still visible and downloadable by users. I had a dig and found another code that used to work on Joomla 2.5, older K2 component, but when I add it to my latest K2 on Joomla 3.4 the result is the same, I see the text to login to view attachment but no attachment and if I login, still the same text but no link to attachment, this is the code:
<!-- Item attachments -->
<?php if($this->item->params->get('itemAttachments') && count($this->item->attachments) && $this->user->guest): ?>
<!--if guest -->
<div class="itemAttachmentsBlock">
<span><?php echo JText::_('K2_DOWNLOAD_ATTACHMENTS'); ?></span>
<ul class="itemAttachments">
<li>
Login to view PDF
</li>
</ul>
</div>
<!--end if guest-->
<?php else: ?>
<!--if logged in-->
<div class="itemAttachmentsBlock">
<span><?php echo JText::_("Download attachments:"); ?></span>
<ul class="itemAttachments">
<?php foreach ($this->item->attachments as $attachment): ?>
<li>
<a title="<?php echo htmlentities($attachment->titleAttribute, ENT_QUOTES, 'UTF-8'); ?>" href="<?php echo JRoute::_('index.php?option=com_k2&view=item&task=download&id='.$attachment->id); ?>">
<?php echo $attachment->title ; ?>
</a>
<?php if($this->item->params->get('itemAttachmentsCounter')): ?>
<span>(<?php echo $attachment->hits; ?> <?php echo (count($attachment->hits)==1) ? JText::_("download") : JText::_("downloads"); ?>)</span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<div class="clr"></div>
</div>
<!--end if logged in-->
<?php endif; ?>
I don't know what to make of it. Any suggestions?
Regards
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
8 years 9 months ago #144884
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic attachments k2 to registered users only
Between the else: and endif; here;
Paste the actual attachments code.
Get the original code from K2's default template.
<p> Please log in to download FULL text </p>
<?php else: ?>
<?php endif; ?>
Paste the actual attachments code.
Get the original code from K2's default template.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Rinald Mamachev
- Offline
- New Member
Less
More
- Posts: 3
8 years 9 months ago #144887
by Rinald Mamachev
Replied by Rinald Mamachev on topic attachments k2 to registered users only
It worked!
Many thanks!
Many thanks!
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
8 years 9 months ago #144889
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic attachments k2 to registered users only
You 're welcome Rinald
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- natecovington
- Offline
- Senior Member
Less
More
- Posts: 68
7 years 2 months ago #160033
by natecovington
Replied by natecovington on topic attachments k2 to registered users only
I wrote a blog post about this, in case it's helpful to someone:
www.covingtoncreations.com/blog/how-to-force-users-to-login-before-downloading-k2-item-attachments
www.covingtoncreations.com/blog/how-to-force-users-to-login-before-downloading-k2-item-attachments
Please Log in or Create an account to join the conversation.