Where does k2 component store its images in the database? - joomla

I want to retrieve/query images stored by joomla k2 component (under the Image Tab).

To display the K2 item image you can use this
echo "media/k2/items/cache/".md5("Image".K2 ITEM ID HERE)."_XL.jpg";

It's not stored in the database at all.
They use the md5 hash on the actual K2 item ID, and that is how they rename and save the image in the folder media/k2/items/cache/.
Anywhere the K2 item is pulled up, they use JFile::exists (which is used to check if a file exists in the path set) with the path
URL-ROOT."media/k2/items/cache/".md5("image" . K2 ITEM ID HERE)."_XL.jpg"
and if the file is there, it shows the image.
Also, the _XL.jpg will change depending on what size the image is set to display on the page, be it a thumbnail, large, XL, etc.
I know that isn't what you wanted to hear, but that is how they do it :) Hope that helps man!

Though you got the answer sharing the info may be helpful:
If working within the K2 Templates (Html overrides) following can be used to access the image added via K2 image tab.
$this->item->image
OR
$this->item->imageXLarge (size you want)
you get relative url : /media/k2/items/cache/29642a1d30cebf98734fb424b2b1316b_L.jpg

You can find the originals in the media/k2/items/src/ directory. Also, #David is correct, "Image" is needed as prefix to the k2 item id.

Related

Joomla - use full article image instead of intro image

I wanted to ask if there is a possibility to force Joomla to use full article image if intro image is empty (everywhere where image should be visible).
Is there a setting for this? Is it a feature of a template or Joomla engine itself? Right now I always have to specify both of this images, cause if I specify one only full article image Joomla does not display miniature in many places. If I specify the other one miniature is there but when I enter article it is missing.
I always end up having to specify the same image twice. Is there any way around this?
Thanks
UPDATE1:
I ended up overwriting the template for article to display $images->intro_image whenever $images->image_fulltext is not available.
This solves my problems yet one joomla user tells me she is sure that they were able to do that before without any modifications in the template. So now I'm just wondering if there is a setting for this in Joomla Admin so that it does not have to be forced in template code
It turned out that each element of my page except full article used intro_image. So what I did was to copy out the part responsible for showing article into the html folder of my template and just added a php code to use intro image instead of fulltext image (if it is present). You basically need to change $image->fulltext to $image->intro_image in the condition. But remember to keep the original condition as an elseif condition if you want to be able to still use full text image

Oscommerce display default product image and prevent it from deletion

I am working on an oscommerce project where i want to display default product image (i.e no image available) if product image is not uploaded.And even i want it to prevent from deletion.I have tried to upload product not available image for 2-3 products but when deleting products i.e final last product image also gets deleted from the folder.I want that if user doesn't upload image then by default no_product_available.jpg should be shown in CATEGORIES.php as well as PRODUCT_INFO.php.
Can anyone help me to do this ? I am using oscommerce default template.
I think I understand what you would like to do... Pretty much you're saying that if someone doesn't upload an image with a product or category then you would like the no_image.jpg image to be displayed instead of nothing being displayed. Additionally, you would like for the no_image.jpg to not be deleted if the category or product is deleted. I think I can help with this...
You need to modify the tep_image() function located in catalog/includes/function/html_output.php
Replace...
if ( (empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) {
return false;
}
With...
if (!is_file($src)) {
$src = "images/no_image.jpg";
}
Now when you use the tep_image() function if no image was uploaded or if the file is specified but missing from the server then no_image.jpg will be displayed. When the category or product is deleted the is no_image.jpg file is not associated with the category or product so nothing is deleted. Obviously, replace "images/no_image.jpg" with the correct location and filename for your default no image file. Also, you may wish to modify the code above to get the specific behavior you want but this is a good starting point to achieve what you want.
The index.php and product_info.php pages use tep_image()... So, you should be all set there. If you're making your own page or modifying an existing one then you would of course need to use the tep_image() function to get the no_image.jpg output functionality. The parameters for tep_image() are...
tep_image($src, $alt = '', $width = '', $height = '', $parameters = '')
UPDATE:
tep_image should already be in both the index.php (the page that generates the category/product list pages) and product_info.php. Just open either file and search for "tep_image" without quotes or parentheses. You should find several instances in both files. Examine the code to understand what has already been done so that when you add a new image you understand the correct syntax.
Pretty much just place tep_image where you want your new image to show up on the page. You need to be familiar with HTML and PHP to read through the page and determine where you want the image placed. If you want to move the current image then you might be able to just cut and paste the current tep_image code to a your new location.
You can also use "Inspect Element" in Chrome in the right click menu to help determine location. Just open the page you want to add an image to and right click in the area you want to add an image to. Then look at the surrounding page source code. Now you have an idea what to look for in the PHP file.
BTW, the index.php page is a little tricky. That page is responsible for the homepage, category listing pages, and product listing pages. Also, there are several other module PHP pages that are Included (so the source code is in a different file that you'll need to track down if that's the area you want to add the image to). Make sense ;-)
Give it a try and write back with what want specifically and you did to achieve it. There are lots of people that have helped me in the past. So, I'm happy to help.

How is K2 image information stored?

We have imported the old Joomla content into K2. In the original content the article image was simply placed inline using the html editor, but although the images do show up, they don't look at all like those handled by K2 using the tab image > browse server. K2 images looks much better.
Since we have about 1000 articles I would like to make a script that can convert the images to the "K2 way". My main problem here is that I can't figure out how K2 stores this image information. I have tried comparing two mysql dumps, before and after adding an image, but I have not been able to determine which tables are involved.
So my question is: How and where is K2 article image informartion handled?
Of course, if there already exists a solution that can do this kind of conversion, I would like to know that as well.
Even after logging and analyzing all SQL queries I still can't find where in the DB K2 image info is stored. And there is a reason why: It doesn't use the DB at all.
Images are stored in
/media/k2/items/cache/
/media/k2/items/src/
using the md5 sum of the K2 item ID as the base of the filename. It then looks on the fly for images in these folders to display when you browse the articles.
There is a bit more info here:
Where does k2 componet store its images in the database?
I have now made a script that will convert embedded images to K2 external images.
Easily way to get original image instead of resized for K2 item, for example:
$image=str_replace("cache","src",$item->image);
$image=str_replace(array("_XS","_S","_M","_L","_XL"),"",$image);

Thumbnail different from actual image

Here is a scenerio, on my products page I want to add an image of the product dimensions but for this image I want to use thumbnail which is different from the actual image which will say Dimensions. This will be applied to all the products across the store. So there will be one thumnail image for all the products that will be associated with it’s dimensional image. I want to show it on the gallery page as last image.
Any help would be greatly appreciated.
Regards,
Avian
If I'm understanding you correctly, you just want every product to have a thumbnail that can be set to be one of several images.
You will need to create a custom attribute for your products, and then programmatically set your current inventory to your defaults. (Or manually change them) There is a knowledgebase article that will assist you with custom options (if applicable), or another article I found via Google to assist in custom attributes.
It's likely not the best way of doing it, but an example of the JavaScript method I was talking about is simply to add the following into a JS file on your server.
document.observe("dom:loaded", function() {
$$('.catalog-product-view .image-thumb:last img').each(function(item){item.src = 'http://domain.com/path/to/image.jpg'});
}

Magento - adding a new field to the product options in admin

I'd like to add a new tab to the 'catalog->manage products->product information' page in the admin. Underneath the 'images' tab, I'd like to add a new tab for video, with a simple text input for adding a video url, which I can then grab for the frontend.
Anyone any ideas where the files are that I need to edit? I've been looking for the last couple hours with no joy. I found the list of current options in Mage_Catalog_Model_Resource_Eav_Mysql4_Setup but can't figure out how to add to them...
Seems it gets some from Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs. If I copy one of the tab sections here and change the title to Video, I can get it to display in the tabs on the left. But how do I then add the options for it?
What you are trying to do, from the sounds of it, is to create a custom field and add it to your catalog data. The good news is that you don't need to muck around in the PHP for that.
Head to Catalog -> Attributes -> Manage Attributes and create a new attribute for yourself called "Video URL" (or something to that effect). This will probably be a text field, and you may want to hide it from comparison on the frontend of the site (select "No" for all those boxes at the bottom of the form).
Once you've created an attribute, you will need to add it to an attribute set. If all your products are of one "type", and if you didn't create any other attribute sets, this should be only one step. Head to Catalog -> Attributes -> Manage Attribute Sets and create a "New Group" called "Video" and drag your new video url attribute into it. Save the attribute set and you should now have your new tab.
The only complication from what I read in your post could be positioning it underneath the images tab. Magento adds several tabs statically (the long way, in the PHP) and doesn't generally obey ordering of the tab groups. Consider the time tradeoff.
Hope that helps. Thanks,
Joe
Per your other comments, for the URLs a simple attribute would work but files would tend to be more difficult. To add a custom tab, as you said, you can edit (or in the case of a plugin, override) Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs::_prepareLayout and add your tab. You'll need to add a block or template to display your tab contents.
After that, you'll need to store the data somewhere. Looking in Adminhtml/controllers/ProductController, you should be able to hook into the catalog_product_prepare_save event to get data from $event->getRequest() and push it onto the product or save another entity as necessary.
I'm not sure how well file saving semantics would work on a product, so you may want to do your own data storage in the extension and then provide something like a getVideoForProduct method to retrieve it.
Then the only thing left to do is modify the catalog/product/view.phtml template file to include your thumbs and create a controller in your extension to provide a modal w/ the video (or do it in JS).
I know that's a bit of a general answer, but it's the rough path you would need to take for tabs. Let me know if any specific part of that is unclear.
Thanks,
Joe

Resources