Keyword

Advanced Search

Search Results (Searched for: extra field order)

  • iChris
  • iChris's Avatar
06 Jul 2012 17:42 - 06 Jul 2012 18:07
Hello ! K2 Error + blank page was created by iChris

Hello ! K2 Error + blank page

Category: English K2 Community

[SOLVED]

Hello,

Christian, from Belgium. I use K2 for a long time, it is the only good free tool to manage an item. Thank you!

I would contact you because I have a problem with K2.

I develop a Joomla extension that I want the system compatible with K2, because I think your brilliant concept!

Articles must be imported into K2 from an external source.

Currently, the import completes successfully but in FRONTEND, I get this error: "Fatal error: Call to undefined method K2ModelItem :: getUserProfile () in / home/www/fashion/components/com_k2/helpers/utilities.php it line 63 "and a blank page.

I use the class ". ModelItem :: save" slightly modified. (Item entire model is imported into the extension).
In the database, everything seems OK (I compared with native recording) FRONTEND but nothing works.

Could you help me and tell me what I missed please?

Thanking you in advance.

Here k2 modified class I use:

function save($front = false, $toStore)
{

$mainframe = &JFactory::getApplication();
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.archive');
require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'lib'.DS.'class.upload.php');
$db = &JFactory::getDBO();
$user = &JFactory::getUser();
$row = &JTable::getInstance('K2Item', 'Table');
$params = &JComponentHelper::getParams('com_k2');
$nullDate = $db->getNullDate();
define( 'K2_JVERSION', '16' );
$jpath = JPATH_SITE.DS.'components'.DS.'com_k2';
define( 'JPATH_COMPONENT', $jpath );

if (!$row->bind($toStore))
{
$mainframe->redirect('index.php?option=com_k2&view=items', $row->getError(), 'error');
}

if ($front && $row->id == NULL)
{
JLoader::register('K2HelperPermissions', JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'helpers'.DS.'permissions.php');
if (!K2HelperPermissions::canAddItem($row->catid))
{
$mainframe->redirect('index.php?option=com_k2&view=item&task=add&tmpl=component', JText::_('K2_YOU_ARE_NOT_ALLOWED_TO_POST_TO_THIS_CATEGORY_SAVE_FAILED'), 'error');
}
}

($row->id) ? $isNew = false : $isNew = true;

if ($params->get('mergeEditors'))
{
$text = $row->introtext;
if ($params->get('xssFiltering'))
{
$filter = new JFilterInput( array(), array(), 1, 1, 0);
$text = $filter->clean($text);
}
$pattern = '#<hr\s+id=("|\')system-readmore("|\')\s*\/*>#i';
$tagPos = preg_match($pattern, $text);
if ($tagPos == 0)
{
$row->introtext = $text;
$row->fulltext = '';
}
else
list($row->introtext, $row->fulltext) = preg_split($pattern, $text, 2);
}
else
{
$row->introtext = JRequest::getVar('introtext', '', 'post', 'string', 2);
$row->fulltext = JRequest::getVar('fulltext', '', 'post', 'string', 2);
if ($params->get('xssFiltering'))
{
$filter = new JFilterInput( array(), array(), 1, 1, 0);
$row->introtext = $filter->clean($row->introtext);
$row->fulltext = $filter->clean($row->fulltext);
}
}

if ($row->id)
{
$datenow = &JFactory::getDate();
$row->modified = $datenow->toMySQL();
$row->modified_by = $user->get('id');
}
else
{
$row->ordering = $row->getNextOrder("catid = {$row->catid} AND trash = 0");
if ($row->featured)
$row->featured_ordering = $row->getNextOrder("featured = 1 AND trash = 0", 'featured_ordering');
}

$row->created_by = $row->created_by ? $row->created_by : $user->get('id');

if ($front)
{
$K2Permissions = &K2Permissions::getInstance();
if (!$K2Permissions->permissions->get('editAll'))
{
$row->created_by = $user->get('id');
}
}

if ($row->created && strlen(trim($row->created)) <= 10)
{
$row->created .= ' 00:00:00';
}

$config = &JFactory::getConfig();
$tzoffset = $config->getValue('config.offset');
$date = &JFactory::getDate($row->created, $tzoffset);
$row->created = $date->toMySQL();

if (strlen(trim($row->publish_up)) <= 10)
{
$row->publish_up .= ' 00:00:00';
}

$date = &JFactory::getDate($row->publish_up, $tzoffset);
$row->publish_up = $date->toMySQL();

if (trim($row->publish_down) == JText::_('K2_NEVER') || trim($row->publish_down) == '')
{
$row->publish_down = $nullDate;
}
else
{
if (strlen(trim($row->publish_down)) <= 10)
{
$row->publish_down .= ' 00:00:00';
}
$date = &JFactory::getDate($row->publish_down, $tzoffset);
$row->publish_down = $date->toMySQL();
}

$metadata = JRequest::getVar('meta', null, 'post', 'array');
if (is_array($metadata))
{
$txt = array();
foreach ($metadata as $k => $v)
{
if ($k == 'description')
{
$row->metadesc = $v;
}
elseif ($k == 'keywords')
{
$row->metakey = $v;
}
else
{
$txt[] = "$k=$v";
}
}
$row->metadata = implode("\n", $txt);
}

if (!$row->check())
{
$mainframe->redirect('index.php?option=com_k2&view=item&cid='.$row->id, $row->getError(), 'error');
}

$dispatcher = &JDispatcher::getInstance();
JPluginHelper::importPlugin('k2');
$result = $dispatcher->trigger('onBeforeK2Save', array(&$row, $isNew));
if (in_array(false, $result, true))
{
JError::raiseError(500, $row->getError());
return false;
}

//Trigger the finder before save event
$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin('finder');
$results = $dispatcher->trigger('onFinderBeforeSave', array('com_k2.item', $row, $isNew));

// Try to save the video if there is no need to wait for item ID
if (!JRequest::getBool('del_video'))
{
if (!isset($files))
{

if (JRequest::getVar('remoteVideo'))
{
$fileurl = JRequest::getVar('remoteVideo');
$filetype = JFile::getExt($fileurl);
$row->video = '{'.$filetype.'remote}'.$fileurl.'{/'.$filetype.'remote}';
}

if (JRequest::getVar('videoID'))
{
$provider = JRequest::getWord('videoProvider');
$videoID = JRequest::getVar('videoID');
$row->video = '{'.$provider.'}'.$videoID.'{/'.$provider.'}';
}

if (JRequest::getVar('embedVideo', '', 'post', 'string', JREQUEST_ALLOWRAW))
{
$row->video = JRequest::getVar('embedVideo', '', 'post', 'string', JREQUEST_ALLOWRAW);
}
}
}

// JoomFish! Front-end editing compatibility
if ($mainframe->isSite() && JFile::exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomfish'.DS.'joomfish.php'))
{
if (version_compare(phpversion(), '5.0') < 0)
{
$tmpRow = $row;
}
else
{
$tmpRow = clone($row);
}
}

if (!$row->store())
{
$mainframe->redirect('index.php?option=com_k2&view=items', $row->getError(), 'error');
}

// JoomFish! Front-end editing compatibility
if ($mainframe->isSite() && JFile::exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomfish'.DS.'joomfish.php'))
{
$itemID = $row->id;
$row = $tmpRow;
$row->id = $itemID;
}

if (!$params->get('disableCompactOrdering'))
{
$row->reorder("catid = {$row->catid} AND trash = 0");
}
if ($row->featured && !$params->get('disableCompactOrdering'))
{
$row->reorder("featured = 1 AND trash = 0", 'featured_ordering');
}
$files = JRequest::get('files');

//Image
if ((int)$params->get('imageMemoryLimit'))
{
ini_set('memory_limit', (int)$params->get('imageMemoryLimit').'M');
}
$existingImage = JRequest::getVar('existingImage');
if (($files === 0 || $existingImage) && !JRequest::getBool('del_image'))
{

if ($files === 0)
{
$image = $files;
}
else
{
$image = JPATH_SITE.DS.JPath::clean($existingImage);
}

$handle = new Upload($image);
$handle->allowed = array('image/*');

if ($handle->uploaded)
{

//Image params
$category = &JTable::getInstance('K2Category', 'Table');
$category->load($row->catid);
$cparams = new JParameter($category->params);

if ($cparams->get('inheritFrom'))
{
$masterCategoryID = $cparams->get('inheritFrom');
$query = "SELECT * FROM #__k2_categories WHERE id=".(int)$masterCategoryID;
$db->setQuery($query, 0, 1);
$masterCategory = $db->loadObject();
$cparams = new JParameter($masterCategory->params);
}

$params->merge($cparams);

//Original image
$savepath = JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'src';
$handle->image_convert = 'jpg';
$handle->jpeg_quality = 100;
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = md5("Image".$row->id);
$handle->Process($savepath);

$filename = $handle->file_dst_name_body;
$savepath = JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache';

//XLarge image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'jpg';
$handle->jpeg_quality = $params->get('imagesQuality');
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_XL';
if (JRequest::getInt('itemImageXL'))
{
$imageWidth = JRequest::getInt('itemImageXL');
}
else
{
$imageWidth = $params->get('itemImageXL', '800');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);

//Large image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'jpg';
$handle->jpeg_quality = $params->get('imagesQuality');
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_L';
if (JRequest::getInt('itemImageL'))
{
$imageWidth = JRequest::getInt('itemImageL');
}
else
{
$imageWidth = $params->get('itemImageL', '600');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);

//Medium image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'jpg';
$handle->jpeg_quality = $params->get('imagesQuality');
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_M';
if (JRequest::getInt('itemImageM'))
{
$imageWidth = JRequest::getInt('itemImageM');
}
else
{
$imageWidth = $params->get('itemImageM', '400');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);

//Small image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'jpg';
$handle->jpeg_quality = $params->get('imagesQuality');
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_S';
if (JRequest::getInt('itemImageS'))
{
$imageWidth = JRequest::getInt('itemImageS');
}
else
{
$imageWidth = $params->get('itemImageS', '200');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);

//XSmall image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'jpg';
$handle->jpeg_quality = $params->get('imagesQuality');
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_XS';
if (JRequest::getInt('itemImageXS'))
{
$imageWidth = JRequest::getInt('itemImageXS');
}
else
{
$imageWidth = $params->get('itemImageXS', '100');
}
$handle->image_x = $imageWidth;
$handle->Process($savepath);

//Generic image
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'jpg';
$handle->jpeg_quality = $params->get('imagesQuality');
$handle->file_auto_rename = false;
$handle->file_overwrite = true;
$handle->file_new_name_body = $filename.'_Generic';
$imageWidth = $params->get('itemImageGeneric', '300');
$handle->image_x = $imageWidth;
$handle->Process($savepath);

if ($files === 0)
$handle->Clean();

}
else
{
$mainframe->redirect('index.php?option=com_k2&view=items', $handle->error, 'error');
}

}

if (JRequest::getBool('del_image'))
{

$current = &JTable::getInstance('K2Item', 'Table');
$current->load($row->id);
$filename = md5("Image".$current->id);

if (JFile::exists(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'items'.DS.'src'.DS.$filename.'.jpg'))
{
JFile::delete(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'items'.DS.'src'.DS.$filename.'.jpg');
}

if (JFile::exists(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$filename.'_XS.jpg'))
{
JFile::delete(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$filename.'_XS.jpg');
}

if (JFile::exists(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$filename.'_S.jpg'))
{
JFile::delete(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$filename.'_S.jpg');
}

if (JFile::exists(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$filename.'_M.jpg'))
{
JFile::delete(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$filename.'_M.jpg');
}

if (JFile::exists(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$filename.'_L.jpg'))
{
JFile::delete(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$filename.'_L.jpg');
}

if (JFile::exists(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$filename.'_XL.jpg'))
{
JFile::delete(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$filename.'_XL.jpg');
}

if (JFile::exists(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$filename.'_Generic.jpg'))
{
JFile::delete(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.$filename.'_Generic.jpg');
}

$row->image_caption = '';
$row->image_credits = '';

}

//Attachments
$attachments = JRequest::getVar('attachment_file', NULL, 'FILES', 'array');
$attachments_names = JRequest::getVar('attachment_name', '', 'POST', 'array');
$attachments_titles = JRequest::getVar('attachment_title', '', 'POST', 'array');
$attachments_title_attributes = JRequest::getVar('attachment_title_attribute', '', 'POST', 'array');
$attachments_existing_files = JRequest::getVar('attachment_existing_file', '', 'POST', 'array');

$attachmentFiles = array();

if (count($attachments))
{

foreach ($attachments as $k => $l)
{
foreach ($l as $i => $v)
{
if (!array_key_exists($i, $attachmentFiles))
$attachmentFiles[$i] = array();
$attachmentFiles[$i][$k] = $v;
}

}

$path = $params->get('attachmentsFolder', NULL);
if (is_null($path))
{
$savepath = JPATH_ROOT.DS.'media'.DS.'k2'.DS.'attachments';
}
else
{
$savepath = $path;
}

$counter = 0;

foreach ($attachmentFiles as $key => $file)
{

if ($file["tmp_name"] || $attachments_existing_files[$key])
{

$attachmentCleanUpFlag = true;

if ($attachments_existing_files[$key])
{
$file = JPATH_SITE.DS.JPath::clean($attachments_existing_files[$key]);
$attachmentCleanUpFlag = false;
}

$handle = new Upload($file);

if ($handle->uploaded)
{
$handle->file_auto_rename = true;
$handle->allowed[] = 'application/x-zip';
$handle->allowed[] = 'application/download';
$handle->Process($savepath);
$filename = $handle->file_dst_name;
if ($attachmentCleanUpFlag)
{
$handle->Clean();
}

$attachment = &JTable::getInstance('K2Attachment', 'Table');
$attachment->itemID = $row->id;
$attachment->filename = $filename;
$attachment->title = ( empty($attachments_titles[$counter])) ? $filename : $attachments_titles[$counter];
$attachment->titleAttribute = ( empty($attachments_title_attributes[$counter])) ? $filename : $attachments_title_attributes[$counter];
$attachment->store();
}
else
{
$mainframe->redirect('index.php?option=com_k2&view=items', $handle->error, 'error');
}
}

$counter++;
}

}

//Gallery
$flickrGallery = JRequest::getVar('flickrGallery');
if ($flickrGallery)
{
$row->gallery = '{gallery}'.$flickrGallery.'{/gallery}';
}

if (isset($files) && $files == 0 && !JRequest::getBool('del_gallery'))
{
$handle = new Upload($files);
$handle->file_auto_rename = true;
$savepath = JPATH_ROOT.DS.'media'.DS.'k2'.DS.'galleries';
$handle->allowed = array("application/download", "application/rar", "application/x-rar-compressed", "application/arj", "application/gnutar", "application/x-bzip", "application/x-bzip2", "application/x-compressed", "application/x-gzip", "application/x-zip-compressed", "application/zip", "multipart/x-zip", "multipart/x-gzip", "application/x-unknown", "application/x-zip");

if ($handle->uploaded)
{

$handle->Process($savepath);
$handle->Clean();

if (JFolder::exists($savepath.DS.$row->id))
{
JFolder::delete($savepath.DS.$row->id);
}

if (!JArchive::extract($savepath.DS.$handle->file_dst_name, $savepath.DS.$row->id))
{
$mainframe->redirect('index.php?option=com_k2&view=items', JText::_('K2_GALLERY_UPLOAD_ERROR_CANNOT_EXTRACT_ARCHIVE'), 'error');
}
else
{
$row->gallery = '{gallery}'.$row->id.'{/gallery}';
}
JFile::delete($savepath.DS.$handle->file_dst_name);
$handle->Clean();

}
else
{
$mainframe->redirect('index.php?option=com_k2&view=items', $handle->error, 'error');
}
}

if (JRequest::getBool('del_gallery'))
{

$current = &JTable::getInstance('K2Item', 'Table');
$current->load($row->id);

if (JFolder::exists(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'galleries'.DS.$current->id))
{
JFolder::delete(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'galleries'.DS.$current->id);
}
$row->gallery = '';
}

//Video
if (!JRequest::getBool('del_video'))
{
if (isset($files) && $files == 0)
{

$videoExtensions = array("flv", "mp4", "ogv", "webm", "f4v", "m4v", "3gp", "3g2", "mov", "mpeg", "mpg", "avi", "wmv", "divx");
$audioExtensions = array("mp3", "aac", "m4a", "ogg", "wma");
$validExtensions = array_merge($videoExtensions, $audioExtensions);
$filetype = JFile::getExt($files);

if (!in_array($filetype, $validExtensions))
{
$mainframe->redirect('index.php?option=com_k2&view=items', JText::_('K2_INVALID_VIDEO_FILE'), 'error');
}

if (in_array($filetype, $videoExtensions))
{
$savepath = JPATH_ROOT.DS.'media'.DS.'k2'.DS.'videos';
}
else
{
$savepath = JPATH_ROOT.DS.'media'.DS.'k2'.DS.'audio';
}

$filename = JFile::stripExt($files);

JFile::upload($files, $savepath.DS.$row->id.'.'.$filetype);
$filetype = JFile::getExt($files);
$row->video = '{'.$filetype.'}'.$row->id.'{/'.$filetype.'}';

}

}
else
{

$current = &JTable::getInstance('K2Item', 'Table');
$current->load($row->id);

preg_match_all("#^{(.*?)}(.*?){#", $current->video, $matches, PREG_PATTERN_ORDER);
$videotype = $matches[1][0];
$videofile = $matches[2][0];

if (in_array($videotype, $videoExtensions))
{
if (JFile::exists(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'videos'.DS.$videofile.'.'.$videotype))
JFile::delete(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'videos'.DS.$videofile.'.'.$videotype);
}

if (in_array($videotype, $audioExtensions))
{
if (JFile::exists(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'audio'.DS.$videofile.'.'.$videotype))
JFile::delete(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'audio'.DS.$videofile.'.'.$videotype);
}

$row->video = '';
$row->video_caption = '';
$row->video_credits = '';
}

//Extra fields
$objects = array();
$variables = JRequest::get('post', 4);
foreach ($variables as $key => $value)
{
if (( bool )JString::stristr($key, 'K2ExtraField_'))
{
$object = new JObject;
$object->set('id', JString::substr($key, 13));
$object->set('value', $value);
unset($object->_errors);
$objects[] = $object;
}
}

$csvFiles = JRequest::get('files');
foreach ($csvFiles as $key => $file)
{
if (( bool )JString::stristr($key, 'K2ExtraField_'))
{
$object = new JObject;
$object->set('id', JString::substr($key, 13));
$csvFile = $file[0];
if (!empty($csvFile) && JFile::getExt($file[0]) == 'csv')
{
$handle = @fopen($csvFile, 'r');
$csvData = array();
while (($data = fgetcsv($handle, 1000)) !== FALSE)
{
$csvData[] = $data;
}
fclose($handle);
$object->set('value', $csvData);
}
else
{
require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'lib'.DS.'JSON.php');
$json = new Services_JSON;
$object->set('value', $json->decode(JRequest::getVar('K2CSV_'.$object->id)));
if (JRequest::getBool('K2ResetCSV_'.$object->id))
$object->set('value', null);
}
unset($object->_errors);
$objects[] = $object;
}
}

require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'lib'.DS.'JSON.php');
$json = new Services_JSON;
$row->extra_fields = $json->encode($objects);

require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'models'.DS.'extrafield.php');
$extraFieldModel = new K2ModelExtraField;
$row->extra_fields_search = '';

foreach ($objects as $object)
{
$row->extra_fields_search .= $extraFieldModel->getSearchValue($object->id, $object->value);
$row->extra_fields_search .= ' ';
}

//Tags
if ($user->gid < 24 && $params->get('lockTags'))
$params->set('taggingSystem', 0);
$db = &JFactory::getDBO();
$query = "DELETE FROM #__k2_tags_xref WHERE itemID={intval($row->id)}";
$db->setQuery($query);
$db->query();

if ($params->get('taggingSystem'))
{

if ($user->gid < 24 && $params->get('lockTags'))
JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));

$tags = JRequest::getVar('tags', NULL, 'POST', 'array');
if (count($tags))
{
$tags = array_unique($tags);
foreach ($tags as $tag)
{
$tag = str_replace('-', '', $tag);
$query = "SELECT id FROM #__k2_tags WHERE name=".$db->Quote($tag);
$db->setQuery($query);
$tagID = $db->loadResult();
if ($tagID)
{
$query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval($tagID)}, {intval($row->id)})";
$db->setQuery($query);
$db->query();
}
else
{
$K2Tag = &JTable::getInstance('K2Tag', 'Table');
$K2Tag->name = $tag;
$K2Tag->published = 1;
$K2Tag->check();
$K2Tag->store();
$query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval($K2Tag->id)}, {intval($row->id)})";
$db->setQuery($query);
$db->query();
}
}
}

}
else
{
$tags = JRequest::getVar('selectedTags', NULL, 'POST', 'array');
if (count($tags))
{
foreach ($tags as $tagID)
{
$query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval($tagID)}, {intval($row->id)})";
$db->setQuery($query);
$db->query();
}
}

}

if ($front)
{
if (!K2HelperPermissions::canPublishItem($row->catid) && $row->published)
{
$row->published = 0;
$mainframe->enqueueMessage(JText::_('K2_YOU_DONT_HAVE_THE_PERMISSION_TO_PUBLISH_ITEMS'), 'notice');
}
}

$query = "UPDATE #__k2_items SET
video_caption = ".$db->Quote($row->video_caption).",
video_credits = ".$db->Quote($row->video_credits).", ";

if (!is_null($row->video))
{
$query .= " video = ".$db->Quote($row->video).", ";
}
if (!is_null($row->gallery))
{
$query .= " gallery = ".$db->Quote($row->gallery).", ";
}
$query .= " extra_fields = ".$db->Quote($row->extra_fields).",
extra_fields_search = ".$db->Quote($row->extra_fields_search)." ,
published = ".$db->Quote($row->published)."
WHERE id = ".$row->id;
$db->setQuery($query);

if (!$db->query())
{
$mainframe->redirect('index.php?option=com_k2&view=items', $db->getErrorMsg(), 'error');
}

$row->checkin();

$cache = &JFactory::getCache('com_k2');
$cache->clean();

$dispatcher->trigger('onAfterK2Save', array(&$row, $isNew));
if (K2_JVERSION == '16')
{
$dispatcher->trigger('onContentAfterSave', array(&$row, $isNew));
}
else
{
$dispatcher->trigger('onAfterContentSave', array(&$row, $isNew));
}

//Trigger the finder after save event
$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin('finder');
$results = $dispatcher->trigger('onFinderAfterSave', array('com_k2.item', $row, $isNew));

switch (JRequest::getCmd('task'))
{
case 'apply' :
$msg = JText::_('K2_CHANGES_TO_ITEM_SAVED');
$link = 'index.php?option=com_k2&view=item&cid='.$row->id;
break;
case 'saveAndNew' :
$msg = JText::_('K2_ITEM_SAVED');
$link = 'index.php?option=com_k2&view=item';
break;
case 'save' :
default :
$msg = JText::_('K2_ITEM_SAVED');
if ($front)
$link = 'index.php?option=com_k2&view=item&task=edit&cid='.$row->id.'&tmpl=component&Itemid='.JRequest::getInt('Itemid');
else
$link = 'index.php?option=com_k2&view=items';
break;
}
return $row->id;
}

  • savvas
  • savvas's Avatar
26 Jun 2012 16:33
Replied by savvas on topic Extra fields in K2 items

Extra fields in K2 items

Category: English K2 Community



I know about the fields ordering. As you see in the photo above i have my gallery, some text (ιθυηιθυιθυ) and the additional info (Πρόσθετες Πληροφορίες). I want to embed a map as a text and when i do it i comes after the text that i wrote before. Can i have text above the additional info area or i have to make template overide?
  • Lefteris
  • Lefteris's Avatar
26 Jun 2012 16:02
Replied by Lefteris on topic Extra fields in K2 items

Extra fields in K2 items

Category: English K2 Community

Hi. It depends on how you are going to implement the map. K2 extra fields have ordering so you can sort them as you want. If howwever you want to change the order of elements ( for example display title after extra fields ) you need to make a template override.
  • Keeper91
  • Keeper91's Avatar
22 Jun 2012 11:46
Joomla Plugin output in K2 Plugin was created by Keeper91

Joomla Plugin output in K2 Plugin

Category: English K2 Community

I created a simple K2 Plugin starting from the Exmaple K2 Plugin for Developers. This plugin just take a text input and output it in the frontend. My idea was to include in the input a code for a Joomla Plugin, in this case, Jant Image Gallery, so that it would be shown in the frontend, but it doesnt work.

When I write "{jant_lightgallery path=xxx/} " in the K2 Plugin textfield I created, it shows in the frontend only the code, but not the gallery. The same code works for the Article Content and even for the Extra Fields.

What should I do in order to make it work also in a K2 plugin?
  • scott cameron
  • scott cameron's Avatar
22 Jun 2012 08:13 - 22 Jun 2012 08:16
SIGPro iamge borders and spacing was created by scott cameron

SIGPro iamge borders and spacing

Category: Simple Image Gallery PRO

1. which file(s) do I need to edit in order to remove the grey border around images

2. I've hidden most of the extra information but as you can see there is huge white space separating the rows...my question is how do a reduce the space when fields are not displayed? would this be a a SIGPro fix or a template problem?

goto www.eastcoastcreative.ca menu item test2
  • kwnstantinoulis
  • kwnstantinoulis's Avatar
11 Jun 2012 00:03
Replied by kwnstantinoulis on topic itemExtraFieldsValue as list instead of commas

itemExtraFieldsValue as list instead of commas

Category: English K2 Community

The code you posted seems to pull out the extra fields as a list's elements. An unordered list to be exact.
If you want them as comma seperated values, use the code below:
Julián wrote: Hi there, i was looking at the code in ../components/com_k2/templates/default/item.php
<div class="itemExtraFields"> <h3><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h3> <ul> <?php foreach ($this->item->extra_fields as $key=>$extraField): ?> <?php if($extraField->value): ?> <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"> <span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span> <span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span> </li> <?php endif; ?> <?php endforeach; ?> </ul> <div class="clr"></div> </div>
But i dont know how to pull those extrafields values as a list instead of comma separated. Anyone can pointme out in the right direction?

Thanks

  • Suba
  • Suba's Avatar
08 Jun 2012 01:57 - 08 Jun 2012 01:58
Change order of custom fields was created by Suba

Change order of custom fields

Category: English K2 Community

How do I change order of the Extra Fields ?
When I go to index.php?option=com_k2&view=extrafields, both the up/down arrays and the order textbox are read-only.
  • Jarno Seppänen
  • Jarno Seppänen's Avatar
02 Jun 2012 06:51
iframes to extra fields was created by Jarno Seppänen

iframes to extra fields

Category: English K2 Community

Hi!
I try to embedd that code...
<iframe src="rcm.amazon.com/e/cm?t=itstescom-20&o=1&p=8&l=as1&asins=B004M8RPBI&ref=tf_til&fc1=000000&IS2=1<1=_blank&m=amazon&lc1=0000FF&bc1=000000&bg1=FFFFFF&f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0">
it's a picture link to Amazon online store. (affiliate ads).
I can't embed that link, I bought JCE Editor and iframe plugin and I can add iframes everywhere except extra field. Is it possible that K2 allow that iframe tags everywhere but not in extra fields. So can anyone help me.
  • Cristian Negruzzi
  • Cristian Negruzzi's Avatar
17 May 2012 05:20

Re: Tool for importing / exporting items to / from K2

Category: English K2 Community

Greetings, I have a question, could you help me o direct to how to import items into k2 from code?
I've made a program to import intems into my product category, items are inserted into k2 intems, i can edit them there but none of them are displayed in frontend. I did it by a mysql query like that:
INSERT INTO `jos_k2_items` ( `title`, `alias`, `catid`, `published`, `introtext`, `fulltext`, `image_caption`, `image_credits`, `video`, `video_caption`, `video_credits`, `gallery`, `extra_fields`, `extra_fields_search`, `created`, `created_by`, `created_by_alias`, `modified`, `modified_by`, `publish_up`, `publish_down`, `checked_out`, `checked_out_time`, `trash`, `access`, `ordering`, `featured`, `featured_ordering`, `hits`, `metadata`, `metadesc`, `metakey`, `params`, `plugins`, `language` ) values ( 'Product Item Title', 'product-item-title-alias', 15, 1, '', '', '', '', NULL, '','',NULL, '[{"id":"2","value":"23"},{"id":"5","value":"0"},{"id":"4","value":"0"},{"id":"6","value":"1"},{"id":"7","value":"5404"}]', '', "2012-05-12 19:00:00", 62, "", "0000-00-00 00:00:00", 62, "2012-05-12 19:00:00", "0000-00-00 00:00:00", 0, "0000-00-00 00:00:00", 0, 0, 0, 0, 0, 1, '', '', '', '', '', '' )
Would you be so kind to tell what i did wrong? What else is to be done to make items displayed in frontend?
  • Cristian Negruzzi
  • Cristian Negruzzi's Avatar
13 May 2012 15:39
insert into _k2_items was created by Cristian Negruzzi

insert into _k2_items

Category: English K2 Community

I've made a third party application to add automatically items to my k2 product catalog, items are inserted into database but not visible in frontend.
First i've tested this in phpMyAdmin - same problem, the script is working fine but items stil not displayed.
INSERT INTO `jos_k2_items` ( `title`, `alias`, `catid`, `published`, `introtext`, `fulltext`, `image_caption`, `image_credits`, `video`, `video_caption`, `video_credits`, `gallery`, `extra_fields`, `extra_fields_search`, `created`, `created_by`, `created_by_alias`, `modified`, `modified_by`, `publish_up`, `publish_down`, `checked_out`, `checked_out_time`, `trash`, `access`, `ordering`, `featured`, `featured_ordering`, `hits`, `metadata`, `metadesc`, `metakey`, `params`, `plugins`, `language` ) values ( 'Product Item Title', 'product-item-title-alias', 15, 1, '', '', '', '', NULL, '','',NULL, '[{"id":"2","value":"23"},{"id":"5","value":"0"},{"id":"4","value":"0"},{"id":"6","value":"1"},{"id":"7","value":"5404"}]', '', "2012-05-12 19:00:00", 62, "", "0000-00-00 00:00:00", 62, "2012-05-12 19:00:00", "0000-00-00 00:00:00", 0, "0000-00-00 00:00:00", 0, 0, 0, 0, 0, 1, '', '', '', '', '', '' )
What i am doing wrong? How to add items correctly?
  • william white
  • william white's Avatar
12 May 2012 22:57
Replied by william white on topic How to create a new extra field type ?

How to create a new extra field type ?

Category: English K2 Community

I havent actually done it, but it goes along the lines as this
joomcar.net/description-k2eo
If you read the description on the website it says
This module consists of two parts:

module part (mod_k2_eo);
plugin part that provide ordering function.

A module to display, and a plugin to manipulate the data so to speak.
That is the general idea, probably a good idea to get this and read the code....when time permits
  • Aimery Marsily
  • Aimery Marsily's Avatar
12 May 2012 00:29
Replied by Aimery Marsily on topic Search for K2 Item by Location

Search for K2 Item by Location

Category: English K2 Community

The biggest issue you will have (I have the same) is to be able to sort your K2 items in the K2 page by your extra-field value, there are no custom way of outputting the content. It's only by the default given value like Alphabetic, New first, etc... no way, except by hacking the core to create a custom output content and display it with the K2 template....

For your system of geolocation you can use the powerfull JSON output from the GoogleMap API : developers.google.com/maps/documentation/geocoding/

I use it to store in an extra field the Lat and Long of my item (realestate like system). I have a param in my items that contain the ZipCode and I use the JSON to get the Lat and Long and save it with them on the fly : ZIPCODE / LAT / LONG.

If you find a native way for the ordering I'll thank you ;-)
  • Altjon Kodra
  • Altjon Kodra's Avatar
11 May 2012 09:06
Replied by Altjon Kodra on topic Extra field values - ordering

Extra field values - ordering

Category: English K2 Community

I have the same problem!!! I think this is really a HUGE limit to K2 extrafields.

I have a list with 300 names alphabeticlly ordered and if I want to add a new name that starts with A... think about it!!!

The only option is to DELETE all 300 names and write everything from scratch, NO GOOD!

Please somebody help with this, it should be possible to re-order values in the extrafields.

Thanks
  • Pastey
  • Pastey's Avatar
10 May 2012 20:10
Search for K2 Item by Location was created by Pastey

Search for K2 Item by Location

Category: English K2 Community

Hi Guys,

Im building a fairly large public blog at the moment with k2 and one requirement is that a user must be able to refine their search by location or preferably the returned results are ordered by location (closest first). Every item will have a postcode and this will be stored within an extra field.

I wondered if anyone on here had come up against anything like this and could give me some directions as to where to start. Ive looked at the google maps api but there are some fairly restrictive limits in terms of usage, is there a better way to achieve this? Is there an extension that already does this (ive looked on JED but cannot see anything)? Or is there another service which may be better than googlemaps?

One thought i did have was to create another table in the db, workout and store the long lat values of the postcodes on content input and then do a calculation within the search (before returning the results) which would determine the ordering of the results. Is this even possible?

Cheers,
Pastey
  • Janette Tilley
  • Janette Tilley's Avatar
02 May 2012 13:27
Replied by Janette Tilley on topic Extra Fields

Extra Fields

Category: English K2 Community

I posted exactly the same question about a week ago. No replies.
This seems like important functionality. Even if the default values can't be automatically re-ordered, at least a manual re-ordering seems like minimum functionality.
Can anyone suggest a work-around?
Or request this as a future feature?
  • matthew turner
  • matthew turner's Avatar
28 Apr 2012 17:17 - 28 Apr 2012 17:20
Replied by matthew turner on topic extra fields in related items by tag

extra fields in related items by tag

Category: English K2 Community

Hi,
I recently needed to do this for a clients website.
They needed the related items to be from another single category only, and needed a way to display the related items in a specific order.... (and not in the category list order, date order, alphabetical or item id or the reverse order of any of these!)
I only went as far as retrieving this specific extrafield from the array but the following might help you out, as it is all done in a template over ride - (so updates to K2 do not wipe out your changes) :


<?php if($this->item->params->get('itemRelated') && isset($this->relatedItems)): ?>

<?php //var_dump($this->relatedItems);
// Sort the data with volume descending, edition ascending["ordering"]
// Add $data as the last parameter, to sort by the common key
//$mynewOrder = array_multisort($item->id, SORT_ASC, $this->relatedItems);
//$mynewOrder = asort($this->relatedItems->item->id);
//$mynewOrder = array_multisort($item->id, SORT_ASC, $this->relatedItems);
//array_multisort($this->relatedItems,SORT_DESC );

?>
<?php
foreach ($this->relatedItems as $val)
{
$sortArrayRank[] = $val->ordering;
$MYvalobj[] = $val->extra_fields;
}

array_multisort(array_values($MYvalobj), $this->relatedItems);
?>

<!-- Related items by tag -->
<div class="itemRelated">
<h2>Testimonials</h2>
<ul>
<?php foreach($this->relatedItems as $key=>$item): ?>
<?php // if item not from category 4 check routine start ?>
<?php if($item->catid == 4): ?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?>">


<?php
$MYobj = $item->extra_fields;
$obj = json_decode($MYobj);

echo "<h1> ";
echo $obj[0]->value;
echo "</h1><br />";

?>
</li>
<li> ....</li>
etc....
<?php endif;// if item not from category 4 check end ?>
</ul>

Hope this helps point you in the right direction - I will be doing further work with this method and will post other changes.....
Regards
Mat
  • Janette Tilley
  • Janette Tilley's Avatar
26 Apr 2012 19:34
Replied by Janette Tilley on topic Extra field values - ordering

Extra field values - ordering

Category: English K2 Community

I have exactly the same problem--no one can help?
Essentially, it seems, you need to know all the possible values of your content first to create the default list. This doesn't allow the possibility of growth or change over time which seems counterproductive.
This is especially important if using the extra fields search and filter extension: the frontend user will see a drop-down list that is not in any logical order.
Is this just a limit of the K2 extra fields??
  • ATHANASIOS ILIOPOULOS
  • ATHANASIOS ILIOPOULOS's Avatar
20 Apr 2012 18:32 - 20 Apr 2012 18:39
customize item.php - translated extra field values was created by ATHANASIOS ILIOPOULOS

customize item.php - translated extra field values

Category: English K2 Community

I hope somebody here can give an answer to my question.

I am using several custom k2 templates assigned to categories & corresponding extra field groups (data types lets say). My site is bilingual ... For example i have:

extra field group: efg1
custom k2 template: templ1
extra fields: ef1, ef2, ..., ef20

I have modified my item.php file in order only to show some (lets say: ef1, ef3, ef5, ef6) extra fields in the following way (item.php):
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields --> <div class="itemExtraFields"> <h3><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h3> <ul> <?php $fields = OnDesign::GetFields($this->item->extra_fields, "Dinning Facilities,Accommodation Facilities,Other Facilities,Free Camping,Nudism,Related Routes & Paths,Regions,Location,Access - full information"); ?> <?php $cnt = 0; foreach ($fields as $key => $value):?> <li class="<?php echo ($cnt++ % 2) ? "odd" : "even"; ?>"> <span class="itemExtraFieldsLabel"><?php echo $key; ?>:</span> <span class="itemExtraFieldsValue"><?php echo $value; ?></span> </li> <?php endforeach; ?> </ul> <div class="clr"></div> </div> <?php endif; ?>


The code for Function OnDesign::GetFields is the following:
<?php class OnDesign { public static function GetFields($extraFields, $fieldsToGet) { $res = array(); if (is_string($fieldsToGet)) { $fieldsToGet = explode(",", $fieldsToGet); foreach($fieldsToGet as &$f) $f = trim($f); } foreach($extraFields as $key => $extraField) { if (in_array($extraField->name, $fieldsToGet)) $res[$extraField->name] = $extraField->value; } return $res; } }

The PROBLEM is that if an extra field is translated through joomfish, the corresponding field label and value are not been populated.

a test page is shown here:





where the fields: nudism, and free camping are not populated (there are translated in greek) ...
  • Aldawen
  • Aldawen's Avatar
10 Apr 2012 17:25
Order extra fields in admin panel was created by Aldawen

Order extra fields in admin panel

Category: English K2 Community

Hi,
pardon me it that's a silly question but I'm new to K2. So far I think I already figured some key points around categories, items and extra fields. But I'm wondering why I can't reorder the extra fields in the admin panel? Order arrows are grey and the numbers can't be overwritten. It's acitve for items and categories but not on the extra fields page. What have I overlooked? Using Joomla 2.5.4 with K2 2.5.6

Thank you!
Susanne
  • Peter Grube
  • Peter Grube's Avatar
09 Apr 2012 04:39
Replied by Peter Grube on topic how to insert an "Extra Field"?

how to insert an "Extra Field"?

Category: English K2 Community

I consider should be made a movie in order to exactly see how this things are done. A video is going to be more than 1000 words. Is going to be great to have a video to see how to add a extra field, how to add a picture and to apply hislide feature, a movie to show as different scenarios about what you can make with K2 from scratch to the final product.

Regards,

Leonard



I would have say this the smartest idea I have read here, I would also add a category where we could post template overides for different layouts, I have just completed one for a simple catalogue layout I would contribute.
Displaying 341 - 360 out of 529 results.

Powered by Kunena Forum