Including CB API for usage outside of CB

Ever wonder if you can design your Joomla components to work on any platform easily? You can actually, but keep note this requires Community Builder to be installed. You can include the CB API directly into your modules, components, or plugins. You will then have the power of CB API at your finger tips.

if ( ( ! file_exists( JPATH_SITE . '/libraries/CBLib/CBLib/Core/CBLib.php' ) ) || ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) ) {
	echo 'CB not installed'; return;
}

include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' );

Now the above will give you access to many of the functions provided by the foundation and in most cases this is all you'll need. However if you want to use class functions and plugin functions or even database functions you need to follow the include with a cb import.

cbimport( 'cb.html' );

The above will give you remaining access to CBs APIs. New CBLib APIs however use autoloading and is recommended to use an editor that can provide autocomplete for ease of use. Additionally if you need language files loaded in at a specific location or early you can use the below.

cbimport( 'language.front' );

None of this will load in CBs styling however. So if you output fields directly after doing the above they will have no CSS styling if CB styling hasn't already loaded. To load in CBs template CSS file you have to call the following.

outputCbTemplate();

Facebook Twitter LinkedIn