Detecting Kunena Version

From Kunena Wiki
Jump to: navigation, search

Contents

Introduction

This document is directed to extension developers who want to integrate their Joomla component, module or plugin with Kunena. This document describes how to detect different versions of Kunena and how to make sure that you're safe to use our API.

Key to symbols shown in red brackets

Some of the information in this document is specific to certain versions of Kunena; this is indicated with the following notation in this article:

  • (K x→) means "this exists for all versions of Kunena starting from version x"
  • (←K x) means "this exists for all versions of Kunena ending at version x"
  • (K x) means "this function exists only in Kunena version x"
  • (K x↔K y) means "this exists for all versions of Kunena starting from at version x and ending with version y"

Use Standard Methods

It is very important to use our standard methods to detect Kunena. Other methods may or may not work depending on the installation.

There are currently 3 possible manifest files:

  • manifest.xml (K 1.5)
  • kunena.xml (K 1.6→)
  • kunena.j16.xml (K 1.6.4↔K 1.7.1)

It's more reliable and faster to use our detection code instead.

Get Major Version

Usually it's enough to detect only major versions of Kunena. While there may be some new features introduced in bugfix releases, its generally safe to assume that your existing code will also work on any bugfix release (+0.0.1) that follows the version you have tested with.

If you only need to know major version of Kunena, here is the fastest way to detect all stable versions of Kunena.

function getKunenaMajorVersion() {
	if (class_exists('KunenaForum')) {
		return KunenaForum::versionMajor();
	} elseif (class_exists('Kunena')) {
		return substr(Kunena::version(), 0, 3);
	} elseif (is_file(JPATH_ADMINISTRATOR.'/components/com_kunena/api.php')) {
		// Oops, Kunena 1.6/2.0 API has been disabled (please enable System - Kunena plugin)
		return false;
	} elseif (is_file(JPATH_ROOT.'/components/com_kunena/lib/kunena.defines.php')) {
		return '1.5';
	} elseif (is_file(JPATH_ROOT.'/components/com_kunena/lib/kunena.version.php')) {
		return '1.0';
	}
	return false;
}

This detection code has been written to detect all Kunena versions. In Joomla! 1.6+ you only need the first two conditions.

Check if Kunena is Online

Kunena integration should only be used if Kunena is online. This allows administrators to have one switch to disable all Kunena integration, modules and plugins.

WARNING: When forum is offline, using Kunena API can be dangerous. For example administrator might be installing a new version of Kunena, causing our API and database to be in undefined state. In most cases the effects of using Kunena API can be seen as a white error pages, but any database update may also cause data corruptions.

If you want to keep the integration working even when Kunena Forum is offline, there's a way to check if Kunena 2.0 installer is running:

// Kunena 2.0/Kunena 3.0
$isInstalled = KunenaForum::installed ();

Kunena 2.0/Kunena 3.0

Kunena 2.0 Kunena 3.0

In Kunena 2.0 or Kunena 3.0 the task of finding out if Kunena is set to be online is very easy.

Note that Kunena forum is automatically put offline during the installation process.

// Kunena 2.0/Kunena 3.0
$isEnabled = KunenaForum::enabled ();

Kunena 1.7 and 1.6

Kunena 1.7 Kunena 1.6

Kunena 1.7 and 1.6 have similar online detection method than Kunena 2.0, but the class name was changed between the two versions.

Note that Kunena forum is automatically put offline during the installation process.

// Kunena 1.7 and 1.6
$isEnabled = Kunena::enabled ();

Kunena 1.5

Kunena 1.5

Kunena 1.5 needs a bit more work to detect if forum is online.

Note that this version doesn't have automatic offline switch when user installs a new version (unless he upgrades to any later version).

// The following requires are needed only for Kunena 1.5.0a and 1.5.1b
require_once (JPATH_ROOT  .DS. 'components' .DS. 'com_kunena' .DS. 'lib' .DS. 'kunena.defines.php');
require_once (KUNENA_PATH_LIB .DS. 'kunena.debug.php');
require_once (KUNENA_PATH_LIB .DS. 'kunena.user.class.php');
// Kunena 1.5.2+
require_once JPATH_ROOT .DS. 'components' .DS. 'com_kunena' .DS. 'lib' .DS. 'kunena.config.class.php';
$kconfig = CKunenaConfig::getInstance();
$isEnabled = !$kconfig->board_offline;

Minor Version Detection

Kunena version detection is different from version to version.

Always detect newer version before older one because of the old method may return wrong version number!

You can compare different Kunena versions by using PHP function version_compare().

Kunena 2.0/Kunena 3.0

Kunena 2.0 Kunena 3.0

Kunena 2.0/Kunena 3.0 has System - Kunena plugin which automatically loads KunenaForum class, autoloader and some defines. Kunena requires this plugin to be enabled at all times, so it is our official way to detect all newer versions of Kunena.

// Detects Kunena 2.0 or later version
if (class_exists('KunenaForum')) {

	// Get current version (if you need it)
	$version = KunenaForum::version();

	// Make sure that your extension works with installed version of Kunena (use minimal required version), if you want detects Kunena 3.0, just replace 2.0 by 3.0
	$compatible = KunenaForum::isCompatible('2.0');

        // You should not use Kunena integration if Kunena is offline
	$enabled = KunenaForum::enabled ();
}

Kunena 1.7 and 1.6

Kunena 1.6 Kunena 1.7

Kunena 1.7 and 1.6 also use System - Kunena plugin to bootstrap its API.

The older API is incompatible with Kunena 2.0 and is missing most of the power that Kunena 2.0 framework has.

// Detects Kunena 1.6 and 1.7
if (class_exists('Kunena')) {

        // Get current version (if you need it)
	$version = Kunena::version();

        // You should not use Kunena integration if Kunena is offline
	$enabled = Kunena::enabled ();
}

NOTE: Detecting 1.6.0 Alpha/Beta/RC releases requires you to use Kunena 1.5 detection methods.

Kunena 1.5

Kunena 1.5

Kunena 1.5 has fairly simple version detection mechanism.

// Detects Kunena 1.5, 1.6 and 1.7
$api = JPATH_ROOT  .DS. 'components' .DS. 'com_kunena' .DS. 'lib' .DS. 'kunena.defines.php';
if (JFile::exists($api)) {
	// Kunena 1.5.0+ detected
	require_once $api;
	$version = defined(KUNENA_VERSION) ? KUNENA_VERSION : '1.5.0a';
}

Kunena 2.0 and 1.0 doesn't have this file (but the file can be left behind).

Kunena 1.0

Kunena 1.0

For historical interest, code below shows how to fetch any Kunena 1.0 version. It also works in Kunena 1.5 (just remember to change legacy code), but is not the preferred way because of SQL query in it:

// Detects Kunena 1.0 and 1.5
$api = $mainframe->getCfg('absolute_path"').'/administrator/components/com_kunena/lib/fx.upgrade.class.php';
if (JFile::exists($api)) {
	$VersionInfo = fx_Upgrade::getLatestVersion('#__fb_version');
	$version = $VersionInfo->version;
}

Compat 15 native.png Unsupported detection method (K 1.0.9↔K 1.7.2)

In Joomla! 1.5 you can also use following code to get Kunena version number in 1.0.9 - 1.7.2, but note that it's slower than the official detection codes:

// Detects Kunena 1.0, 1.5, 1.6 and 1.7 (unofficial way)
$api = JPATH_ROOT  .DS. 'components' .DS. 'com_kunena' .DS. 'lib' .DS. 'kunena.version.php';
if (JFile::exists( $api)) {
	// Kunena 1.0.6+ detected
	require_once $api;
	// We need this check because of the older releases also have the file
	if (class_exists('CKunenaVersion')) {
		// Kunena 1.0.9 - 1.7.2
		$VersionInfo = CKunenaVersion::versionArray();
		$version = $VersionInfo->version;
	}
}
Personal tools
Namespaces

Variants
Actions
NAVIGATION
Toolbox
Interface Language