Adding Multiple Attachment for Joomla K2 Component according to the number of JoomFish’s language hack

Auto detecting Joomfish languages with your K2 Component, making your attachment number of field to match with JoomFish Component site languages.
Please follow the below steps to achieve this.


Step 1

/administrator/components/com_k2/tables/k2attachment.php add this in around line 357

var $lang = null;

Step 2

/administrator/components/com_k2/model/item.php add this in around line 357, in “save” function

$attachments_language_code = JRequest::getVar('language_code', '', 'POST', 'array'); 

add this in around line 400, in “save” function

$attachments_language_code = JRequest::getVar('language_code', '', 'POST', 'array'); 

Step 3

/components/com_k2/models/item.php add this in around line 911, in “getItemAttachments” function

$lang = JRequest::getCmd( 'lang' );

Original

$query="SELECT * FROM #__k2_attachments WHERE itemID=".(int)$itemID;

Change it to

$query="SELECT * FROM #__k2_attachments WHERE itemID=".(int)$itemID . " and lang = '".$lang."'";

Step 4

/administrator/components/com_k2/views/item/tmpl/default.php change the javascript function “addAttachment”, replace the old one.

function addAttachment(){
   var div = new Element('div',{'style':'border-top: 1px dotted #ccc; margin: 4px; padding: 10px;'}).injectInside($('itemAttachments'));
   var str = "";
   str += "<input type=\"button\" value=\"<?php echo JText::_('Remove',true); ?>\" onclick=\"this.getParent().remove();\">";
   <?
	$lang =& JFactory::getLanguage();
	$alllangs = $lang->getKnownLanguages();
	foreach ($alllangs as $key=>$value) {
		list($langcode, $countryCode) = explode("-", $key);
   ?>
   var divlang = new Element('div').injectInside(div);
   var input = new Element('input',{'name':'attachment_file[]','type':'file'}).injectInside(divlang);
   var br = new Element('br').injectInside(divlang);
   var label = new Element('label').setHTML('<?php echo JText::_('Link title (optional)', true); ?>').injectInside(divlang);
   var input = new Element('input',{'name':'attachment_title[]','type':'text', 'class':'linkTitle'}).injectInside(divlang);
   var br = new Element('br').injectInside(divlang);
   var label = new Element('label').setHTML('<?php echo JText::_('Link title attribute (optional)', true); ?>').injectInside(divlang);
   var textarea = new Element('textarea',{'name':'attachment_title_attribute[]','cols':'30', 'rows':'3'}).injectInside(divlang);
   var br = new Element('br').injectInside(divlang);
   var languagecode = new Element('input',{'name':'language_code[]','type':'hidden', 'value':'<?=$langcode?>'}).injectInside(divlang);
   str += "<div>";
   str += "<div style=\"float:left; width:150px; font-weight:bold;\"><?=$value["name"]?></div>";
   str += "<div style=\"float:left;\">" +  divlang.innerHTML + "</div><div style=\"clear:both;\"></div>";
   str += "</div>";
<?
	}
?>
 div.innerHTML = str;

   }

Step 5 – Database

enter this in your sql server (you will need phpmyadmin for this)

ALTER TABLE `jos_k2_attachments` ADD `lang` VARCHAR( 10 ) NULL

Step 6 – Need Help?

We do accept freelance customization to K2 and Joomfish development.
The freelance price for customization is USD50/hr*
*Minimum charge will be USD100
Interested Party please email us at info[a]designersandbox[dot]com

Related Posts Plugin for WordPress, Blogger...

I hope you have enjoyed this post, be sure to subscribe to my rss feed by click the subscribe button at the top.

Good Luck!

Be Sure to Subscribe to our feed or follow us on twitter to get the latest updates/patches
End of Article, Thanks for reading.
You can leave a response, or trackback from your own site.

3 Responses to “Adding Multiple Attachment for Joomla K2 Component according to the number of JoomFish’s language hack”

  1. We absolutely love your blog and find almost all of your post’s to be exactly what I’m looking for. Does one offer guest writers to write content in your case? I wouldn’t mind publishing a post or elaborating on a lot of the subjects you write with regards to here. Again, awesome weblog!

  2. dmza says:

    i've got K2 v2.5.5 and Joomla 1.5, and the files are not the same. Please help me
    Step 1
    - /administrator/components/com_k2/tables/k2attachment.php this file has only 28 lines
    Step 2
    - /administrator/components/com_k2/model/item.php "Model" folder doesn't exist
    Step 4
    cant find the the java function, i just see a div with id="addAttachment"

  3. dmza says:

    Any help?

Leave a Reply