IMPORTANT MESSAGE REGARDING THE FORUM

As you may already know, the JoomlaWorks Forum is powered by Kunena (the only decent forum component for Joomla).

Unfortunately, the latest update for Kunena has seemingly broken all code snippets (old and new) in the forum.

Until this message is removed, please paste any code as regular text - in other words, don't use the [code]...[/code] tags in Kunena's post editor.

Keyword

how to convert k2 items to default joomla articles

More
7 years 9 months ago #75130 by losa
what actually you are referring with this image

1dream of future thing on your website

which in future will have more that 30% operational content and usable links or what.

nothing on your website works

or you just think your avatar is awesome


which i think it is not

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

  • Steven Trooster
  • Steven Trooster's Avatar
  • Offline
  • Premium Member
More
1 month 5 days ago - 1 month 5 days ago #179754 by Steven Trooster
Replied by Steven Trooster on topic Re: how to convert k2 items to default joomla articles
There are some considerations here concerning galleries, images and extra fields

Galleries
K2 galleries are stored in media/k2/galleries Each gallery has a folder with the id of the article as the name of the folder. 
You can copy this directory and all its content to the images folder

Joomla articles can make use of SIG-pro, but it handles it differently. Where K2 stores the reference in a separate database field, Joomla articles has the code within the text of the article, like {gallery}name_of_folder{/gallery}

To add this gallery code to your articles, add the following to the sql query:

concat_ws('<br/>',`fulltext`, `gallery`) AS 'fulltext

The query will become:
 
INSERT INTO `DATABASENAME_PREFIX`.`PREFIX_content` (`id`, `title`, `alias`, `catid`, `introtext`, `fulltext`, `created`, `created_by`, `created_by_alias`, `checked_out`, `checked_out_time`, `modified`, `modified_by`, `publish_up`, `publish_down`, `access`, `featured`, `hits`, `language`)
SELECT `id`, `title`, `alias`, `catid`, `introtext`, concat_ws('<br/>',`fulltext`, `gallery`) AS 'fulltext', `created`, `created_by`, `created_by_alias`, `checked_out`, `checked_out_time`, `modified`, `modified_by`, `publish_up`, `publish_down`, `access`, `featured`, `hits`, `LANGUAGE`
FROM `si3ow_k2_items`;

Images
K2 has no reference to images in the database. The images are stored in media/k2/items/cache/. When you create a new article and add a header image, K2 will create 6 versions of that image. The filename is a MD5 hash of the word 'Image' and the id of the article (Note the capital I in Image). Followed by _Generic, _L, _M, _S, _XL and _XS. All images are in jpg format, even if the original is png or gif.

You can copy all the files from the cache directory to your images folder. I would suggest to create a subfolder called K2 or something of your liking, inside the folder stories.

You can choose which one of the 6 file sizes you want to use with your Joomla articles, and you can even use different sizes for intro text and for full text. The sql-code for creating a reference to the correct (extra large) file will be: 

CONCAT(MD5(CONCAT('Image',`id`)), '_XL.jpg')

Joomla content stores a reference to both intro text and full text in one field images. The content of that field is JSON format. 
{"image_intro":"","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}

Note that where K2 has two fields for the image caption (caption and credits), content only has a caption.
So the query for the XL images set as intro and full text will become:

CONCAT('{"image_intro":images\/stories\//k2"',MD5(CONCAT('Image',`id`)), '_XL.jpg','"float_intro":"","image_intro_alt":',`title`,'"","image_intro_caption":"',CONCAT(`image_caption`, ' Credits: ',`image_credits`),'","image_fulltext":',MD5(CONCAT('Image',`id`)), '_XL.jpg','"","float_fulltext":"","image_fulltext_alt":"',`title`,'","image_fulltext_caption":"',CONCAT(`image_caption`, ' Credits: ',`image_credits`),'"}' ) 

So the complete query should be:

INSERT INTO `DATABASENAME_PREFIX`.`PREFIX_content` (`id`, `title`, `alias`, `catid`, `introtext`, `fulltext`, `created`, `created_by`, `created_by_alias`, `checked_out`, `checked_out_time`, `modified`, `modified_by`, `publish_up`, `publish_down`, `images`, `access`, `featured`, `hits`, `language`)
SELECT `id`, `title`, `alias`, `catid`, `introtext`, concat_ws('<br/>',`fulltext`, `gallery`) AS 'fulltext', `created`, `created_by`, `created_by_alias`, `checked_out`, `checked_out_time`, `modified`, `modified_by`, `publish_up`, `publish_down`, CONCAT('{"image_intro":images\/stories\//k2"',MD5(CONCAT('Image',`id`)), '_XL.jpg','"float_intro":"","image_intro_alt":',`title`,'"","image_intro_caption":"',CONCAT(`image_caption`, ' Credits: ',`image_credits`),'","image_fulltext":',MD5(CONCAT('Image',`id`)), '_XL.jpg','"","float_fulltext":"","image_fulltext_alt":"',`title`,'","image_fulltext_caption":"',CONCAT(`image_caption`, ' Credits: ',`image_credits`),'"}' ), `access`, `featured`, `hits`, `LANGUAGE`
FROM `DATABASENAME_PREFIX`.`PREFIX_k2_items`;

(MySQL throws me an error. I'm not sure where it's wrong )

Extra fields
All of this doesn't covert your K2 extra fields to Joomla custom fields. K2 stores the extra fields information in one singe field in the items table. The format is JSON.
Joomla stores the custom fields in a separate table, with a row for each custom field value and a reference to the article id.

I have no idea how to convert the extra fields to custom fields with sql.

Note
Be aware the query above will insert the K2 item ID into the Joomla content table. If you already have articles in Joomla content, this might lead to conflicts.

 
Last edit: 1 month 5 days ago by Steven Trooster.

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


Powered by Kunena Forum