Thursday, 28 February 2019 06:13

Get the URL of a K2 extra field image

K2 extra fields can be a royal pain sometimes. They are not nearly as flexible as they should be. For instance, using the image extra field spits renders the image inside it's <img src /> tags. But what if you just want the URL of the image? Perhaps you need the image URL to use inside a CSS background image. Here's how:

Note that the alias of the extra field in my example is myImage. Change this to match your own custom field alias.
Also note that I am using this code inside a mod_k2_content module.


<?php
$fetchSrc1 = explode('src="', $item->extraFields->myImage->value);
$fetchSrc2 = explode('"', $fetchSrc1[1]);
?>

<?php echo $fetchSrc2[0]; ?>

For using on K2 item pages, replace the first line with the following:


$fetchSrc1
= explode('src="', $this->item->extraFields->myImage->value);

Published in Blog

Sometimes you need to know the category of the current K2 item, but reneder this information outside of the K2 template files. To check anything K2 outside of the K2 container, the code below is a good starting point.
By expanding this code a bit, you can check for all sorts of things, always from outside of the K2 container. For instance, I can use the following inside the <head> tags to trigger something specific to an item.

    
<?php
// Check if the item belongs to a specific category

// Gets component, view, and ID from the non-SEF URL
$whatComp = JFactory::getApplication()->input->get('option');
$whatView = JFactory::getApplication()->input->get('view');
$whatId = JFactory::getApplication()->input->get('id');
// Check if you are on K2 and viewing an item
if($whatComp == 'com_k2' && $whatView == "item") {
// Check the database for the category ID of the current K2 item
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('catid');
$query->from($db->quoteName('#__k2_items'));
$query->where($db->quoteName('id')." = ".$db->quote($whatId));
$db->setQuery($query);
$myCatID = $db->loadResult();
// The number to be compared below is the ID of the category

if($myCatID == '17') {
// do something
}
}
?>

 

Published in Blog

<?php
$parent = JTable::getInstance('K2Category', 'Table');
$parent->load($this->category->parent);
echo $parent->name;
?>

Published in Blog
Tuesday, 30 October 2018 08:17

Disable Admin tools via FTP

Using FTP to regain access to your site's administrator, The failsafe way to regain access to your site's administrator backend is using an FTP application or your hosting control panel's File Manager to rename a file.

Go inside the plugins/system/admintools/admintools directory on your site (on older versions of Admin Tools: plugins/system/admintools). You will see a file named main.php. Rename it to main-disable.php. This will turn disable the Web Application Firewall from executing and you can access your site's back-end again.

After you have fixed the cause of your issue remember to rename main-disable.php back to main.php, otherwise your site will remain unprotected!

 

Published in Blog
Sunday, 10 December 2017 01:05

Remove spaces from image file names

I've been working on a website that uses Mijoshop (the Joomla e-Commerce and shopping cart component built using Opencart). Problems occurred when I wanted to use product images as CSS background images, rather than HTML images. The client had uploaded a bunch of images that contained spaces within the file names, making them unsuitable to be used in the CSS background-image property (which just left empty white spaces where the images should have appeared(. There were so many that it just wasn't feasable to rename them manually, so I needed to figure out an automated solution, which became a three step process:

  1. Install an Opencart script that future proofed the problem of file names containing images from this point on.
  2. Renaming the existing images already used on the server
  3. Modifying the SQL tables to match the newly renamed files names

Step 1 - Future proof Mijo Shop

I found this opencart ocmod script that removes spaces from any images uploaded. It worked great and was easy to install directly using the extensions installer from Mijoshop main menu. The file can be found here.

Whilst this ensured that any images uploaded from this point on wouldn't have any spaces withn the filenames, this script didn't fix the problem for any images already uploaded into the Opencart catalog. The next step in this solution addresed that problem.

 

Step 2 - rename the existing files

I found a handy program called Rename-it! which made easy work of btach removing all spaces in the exisiting files. I tested this locally on desktop rather than applying it directly to the server. Rename-It! is free, easy to use, and also didn't install any crappy third party bloat software. Too easy!

 

Step 3 - Match the database filenames with existing files

The tables in the website database need to match the newly renamed files. We can do this with a simple SQL find and replace script that removes the spaces in the filenames. make sure to change the table name and column name to match those used by your website

UPDATE table_name
SET image = REPLACE(column_name, ' ', '');

Published in Blog
Wednesday, 22 November 2017 02:23

Adding extra fields to the Joomla contact form

The default Joomla contact form component does allow us to modify it slightly and add new fields to the contact form. New fields are contained within a field group. Follow the steps below and view the video tutorial for further explanation on these concepts.

  • Go to "Components" and "Contacts".
  • Click "Field Groups" in the left-hand sidebar.
  • This is the important new task: choose "Mail" from the dropdown menu. This means your fields will be attached to contact forms that users can rely on to send email. If we choose "Contact" or "Category", our fields will only be available to site administrators. If you choose "Contact", this will be similar to the Address, City or Suburb, etc fields we saw above.

Adding extra fields to the Joomla contact form  1

  • Click "New".
  • Title: Extra Contact Details
  • Save the field group and make sure your next screen looks like this:

Adding extra fields to the Joomla contact form   2

  • Click "Fields" in the left-hand sidebar.
  • Again, choose "Mail" in the dropdown menu:

Adding extra fields to the Joomla contact form   3

  • Click "New".
  • Title: What is Your Question About?
  • Type: Checkboxes

Adding extra fields to the Joomla contact form   4

  • Field Group: Extra Contact Details
  • Checkbox Values: Enter topics that people might be contacting you about.

Adding extra fields to the Joomla contact form   5

  • Click the "Permissions" tab.
  • Set "Edit Custom Field Value" to "Allowed". This will allow anyone to enter data into this field.

Adding extra fields to the Joomla contact form   6

  • Visit the front of your site and your contact form will now have a custom field:

Adding extra fields to the Joomla contact form   7

Published in Blog
Wednesday, 22 November 2017 00:42

Embedding videos into a Gantry particle position

This tutorial will show you how to embed a video into a Gantry particle position on a Joomla website. This tutorial does require the website to have installed the Joomla Works All Videos plugin.

Whilst in this tutorial I use a video that is hosted on Youtube, the same concepts can be slightly modified for any videos that are hosted on your own web server. For a deeper explanation of the differences I suggest watching my previous tutorial Embedding locally hosted videos on a Joomla website.

Published in Blog
Tuesday, 21 November 2017 23:10

Creating a contact form in Joomla

Whilst many advanced form components are available for Joomla (such as the excellent RS Forms Pro), creating a fully functioning contact page with a form is actually very easy to build natively within Joomla. No additional components are required as everything you need is built into Joomal by default.

This tutorial will walk you through the steps to create a contact form (as pictured below), and also point out a small glitch within Joomla and how to solve it.

Creating a contact form in Joomla

Published in Blog

The Joomla Works All Videos plugin is a great addition to your Joomla website to display videos directly within your articles. Videos's can be hosted on a third party service such as Youtube or Vimeo, or can be hosted directly on your own webserver alongside your Joomla website.

However, in my experience I've found that there are a couple of issues that need to be resolved when hosting videos on your own web server:

  1. Using the plugins responsive settings doesn't work correctly, resulting in videos that don't span 100% across the page (or parent containers width)
  2. Once embedded, videos are displaying as a boring black square with a white play icon

These issues only arise with vidoes hosted on your own server, and not those hosted on a service such as Youtube or Vimeo.

This tutorial video addresses both those problems, and provides solutions to have your locally hosted videos displaying as anticipated.

There is some additional CSS code that is required, which can be found on my Bit Bucket page over here. This CSS snippet needs to be added to your Joomla theme's style sheet.

Note: In this tutorial video I use the Kraken template for Joomla, and the Kraken template for Joomla. Whilst it's not neccessary to use both of these it's worth mentioing that I add the CSS hack above directly into the Gantry parameters rather than append it into my themes style sheet. Both methods will work just fine.

Published in Blog

This is a super handy cheat sheet compiled by the K2 team that solves many PHP conditional statements:

https://github.com/kricore/Advanced-templating-with-K2/blob/master/_inc/cheatsheet.php#L28-L55

Published in Blog
Page 1 of 3