loadLanguages();
$item = array(self::$this->_context => 'K2 ' . JText::_('K2_ITEMS'));
$items[] = $item;
return $items;
}
public function onJosettaLoadItem($context, $id = '')
{
if ((!empty($context) && ($context != $this->_context)) || (empty($id)))
{
return null;
}
$item = parent::onJosettaLoadItem($context, $id);
// Merge introtext and fulltext
$item->articletext = trim($item->fulltext) != '' ? $item->introtext . "
" . $item->fulltext : $item->introtext;
// Get tags
K2Model::addIncludePath(JPATH_SITE . '/components/com_k2/models');
JLoader::register('K2HelperUtilities', JPATH_SITE . '/components/com_k2/helpers/utilities.php');
$model = K2Model::getInstance('Item', 'K2Model');
$tags = $model->getItemTags($item->id);
$tmp = array();
foreach ($tags as $tag)
{
$tmp[] = $tag->name;
}
$item->tags = implode(', ', $tmp);
// Get extra fields
$extraFields = $model->getItemExtraFields($item->extra_fields);
$html = '';
if (count($extraFields))
{
$html .= '';
foreach ($extraFields as $key => $extraField)
{
$html .= '';
}
$html .= '
';
}
$item->extra_fields = $html;
// Return the item
return $item;
}
/**
* Save an item after it has been translated
* This will be called by Josetta when a user clicks
* the Save button. The context is passed so
* that each plugin knows if it must process the data or not
*
* if $item->reference_id is empty, this is
* a new item, otherwise we are updating the item
*
* $item->data contains the fields entered by the user
* that needs to be saved
*
*@param context type
*@param data in form of array
*
*return table id if data is inserted
*
*return false if error occurs
*
*/
public function onJosettaSaveItem($context, $item, &$errors)
{
if (($context != $this->_context))
{
return;
}
// load languages for form and error messages
$this->loadLanguages();
require_once JPATH_PLUGINS . '/josetta_ext/k2item/models/item.php';
$k2ItemModel = new JosettaK2ModelItem();
$savedItemId = $k2ItemModel->save($item);
if (empty($savedItemId))
{
// make sure errors are displayed
JosettaHelper::enqueueMessages($k2ItemModel->getErrors());
return false;
}
return $savedItemId;
}
}