Keyword

About k2 attachments

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 9 months ago #157578 by Meridies web
About k2 attachments was created by Meridies web
Hello i have one question , its quite easy one, before every k2 attachments i wanna some icon (best will be font awesome icons), so probably i will use word and pdf, and main thing when i add file lets say pdf in attachments ,k2 recognize its pdf and add that pdf icon or font awesome pdf icon before that title.

ty in advance

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 9 months ago #157597 by Krikor Boghossian
Replied by Krikor Boghossian on topic About k2 attachments
Hello,

You can use strpos php.net/manual/en/function.strpos.php in order to search through each filename or title ($attachment->title;) for a specific string like .pdf or .jpg. If it returns true you can then add the markup for an icon font.

Remember to use overrides instead of editing core files getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

Please Log in or Create an account to join the conversation.

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 9 months ago #157608 by Meridies web
Replied by Meridies web on topic About k2 attachments
can y please explain little bit more what to do, letst say i am using font awesome

Please Log in or Create an account to join the conversation.

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 9 months ago #157609 by Meridies web
Replied by Meridies web on topic About k2 attachments
this is my code but i have problems it wont work dunno why, i am not that good at php, can y alteast look at code.

it always show pdf icon, what i am doing wrong?
______________________________________________________

<?php
$mystring = '$attachment->title';
$findme = '.pdf';
$pos = strpos($mystring, $findme);

// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos !== false) {
echo '<i class="fa fa-file-word-o" aria-hidden="true"></i>';

} else {
echo'<i class="fa fa-file-pdf-o" aria-hidden="true"></i>';
}
?>

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 9 months ago #157616 by Krikor Boghossian
Replied by Krikor Boghossian on topic About k2 attachments
What does var_dump($pos); produce?

Also it should be:
$mystring = $attachment->title;

Please Log in or Create an account to join the conversation.

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 9 months ago #157620 by Meridies web
Replied by Meridies web on topic About k2 attachments
as i told i am not that good at php, can y help me and show me how to write this code, i dont know what does this produce var_dump($pos); produce,

as i told need helpw with the code, i just wanna show icon pdf if i have pdf attahcments and word icon if i have word attachments.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 9 months ago #157621 by Krikor Boghossian
Replied by Krikor Boghossian on topic About k2 attachments
Try this:
<?php
$mystring = $attachment->title;
$findme = '.pdf';
$pos = strpos($mystring, $findme);

// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos ===  true) {
echo '<i class="fa fa-file-word-o" aria-hidden="true"></i>';

} else {
echo'<i class="fa fa-file-pdf-o" aria-hidden="true"></i>';
}
?>

The quotes made the script to look for a string literally search for $attachment->title instead of the actual title.

Please Log in or Create an account to join the conversation.

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 9 months ago #157623 by Meridies web
Replied by Meridies web on topic About k2 attachments
where i add this code that y send me, this is item.php , where should i add that code so i always add icon before link.

i cant add here item.php code cause it say its spam, but where should i add this code?

Please Log in or Create an account to join the conversation.

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 9 months ago #157625 by Meridies web
Replied by Meridies web on topic About k2 attachments
and btw if i add new item lets say its docx, it always add that pdf icon

Please Log in or Create an account to join the conversation.

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 9 months ago #157627 by Meridies web
Replied by Meridies web on topic About k2 attachments
i think this is beacuse k2 attachments dont have that extension

Please Log in or Create an account to join the conversation.

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 9 months ago #157628 by Meridies web
Replied by Meridies web on topic About k2 attachments
this is what i use now..


<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>

Please Log in or Create an account to join the conversation.

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 9 months ago #157629 by Meridies web
Replied by Meridies web on topic About k2 attachments
where to add that code here?

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 9 months ago #157636 by Krikor Boghossian
Replied by Krikor Boghossian on topic About k2 attachments
The end result should be:
  <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
              $mystring = $attachment->title;
              $findme = '.pdf';
              $pos = strpos($mystring, $findme);

              // Note our use of ===. Simply == would not work as expected
              // because the position of 'a' was the 0th (first) character.
              if ($pos ===  true) {
              echo '<i class="fa fa-file-word-o" aria-hidden="true"></i>';

              } else {
              echo'<i class="fa fa-file-pdf-o" aria-hidden="true"></i>';
              }
            ?>

            <?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>

Please Log in or Create an account to join the conversation.

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 9 months ago #157638 by Meridies web
Replied by Meridies web on topic About k2 attachments
it doesnt work it show just pdf document not word document, even if i add word document

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 9 months ago #157639 by Krikor Boghossian
Replied by Krikor Boghossian on topic About k2 attachments
Sorry replace if ($pos === true) {

with if ($pos === false) {

Please Log in or Create an account to join the conversation.

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 9 months ago #157640 by Meridies web
Replied by Meridies web on topic About k2 attachments
if i do that then i only show word documents...

dont y get it something is bad written.

Please Log in or Create an account to join the conversation.

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 9 months ago #157642 by Meridies web
Replied by Meridies web on topic About k2 attachments
i manage to get it, when i add custom title, then it dont have that .pdf, but can i create so i get by filetpye not by title?

cause this way it only see title of document, and its ulgy if title is written with extension

Please Log in or Create an account to join the conversation.

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 8 months ago #157643 by Meridies web
Replied by Meridies web on topic About k2 attachments
i managed to solve this, but this is only for word and pdf, do y mybe how to add excel and mybe more?

ty

Please Log in or Create an account to join the conversation.

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 8 months ago #157644 by Meridies web
Replied by Meridies web on topic About k2 attachments
you know mybe is it possible to add more filetypes, this is only for word and pdf?

ty alot rly man

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 8 months ago #157653 by Krikor Boghossian
Replied by Krikor Boghossian on topic About k2 attachments
This can serve as a starting point.
It checks for xls and pp (s or t) files.
$attitle = $attachment->title;

// Filenames
$pdf = '.pdf';
$doc = '.doc';
$xls = '.xls';
$ppt = '.pp';

// Check to see which filename is found
$foundpdf = strpos($pdf, $attitle);
$founddoc = strpos($doc, $attitle);
$foundxls = strpos($xls, $attitle);
$foundppt = strpos($ppt, $attitle);

// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($foundpdf ===  true) 
{
	echo '<i class="fa fa-file-pdf-o" aria-hidden="true"></i>';

} 
elseif ( $founddoc === true ) 
{
	echo'<i class="fa fa-file-word-o" aria-hidden="true"></i>';
} 
elseif ( $foundxls === true ) 
{
	// DO SOMETHING
}
elseif ( $foundppt === true ) 
{
	// DO SOMETHING
}
else 
{
	// DEFAULT BEHAVIOUR	
}

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum