Combu Addons

The version 2.1 of Combu brought the new cool feature of add-ons support, for example License Manager. The really cool thing here is that you can create your own add-ons and share them with other users of Combu or even sell them yourself at your favored online store, we will not ask for royalties or any other cost from the income that you would earn from your hand-crafted add-ons. Of course you cannot include in your package any add-on or portion of it made by other developers if you are going to sell or share unless you are provided with explicit consent from the author, else you will breach copyright laws.

Install and uninstall the add-ons

The add-ons must be placed in the folder /addons of your Combu server installation, an add-on usually consists of a folder with a file addon.php and eventually other files. If you have 2 add-ons with the same folder name then you will have to rename one of them and make proper changes to their configuration or eventually source code. You don’t need to do anything else, Combu API will take care to automatically loop through any sub-folder of /addons and load the valid add-ons found.

To uninstall an add-on you only have to delete its folder from /addons

Create your add-ons

The add-ons are handled by the class AddonModule and any add-on is an object of this class, the folder /addons is automatically scanned by Combu API in AddonModule::LoadAddons(). The first step to create a new add-on is to create a new folder in /addons, you should choose a proper name for your add-on so that it’s almost unique, and create a new file addon.php in the folder (all any other extra file used by your add-on must be in this folder or subfolders).

The file addon.php is the loader of your add-on, so it’s here that you will have to write your initialization code: since it is run by AddonModule, you will have automatically access to a variable called $addon of type AddonModule that you can configure at your needs.

The first step is to give a name to your module:

$addon->Name = "My awesome add-on";

If your add-on will have pages to be displayed in the administration console:

// The 1st parameter is the display text, the 2nd is the file URL (is relative to the add-on folder)
$addon->AddAdminMenu("Display menu", "your_admin_file.php");

If your add-on needs to be notified when an account is created:

function MyAwesomeAddon_OnUserCreate ($user) {
   // do something, $user is of type CB_Account
$addon->OnUserCreate = "MyAwesomeAddon_OnUserCreate";

If your add-on needs to be notified when an account is updated:

function MyAwesomeAddon_OnUserUpdate ($user) {
   // do something, $user is of type CB_Account
$addon->OnUserUpdate = "MyAwesomeAddon_OnUserUpdate";

If your add-on needs to be notified when an account is deleted:

function MyAwesomeAddon_OnUserDelete ($user) {
   // do something, $user is of type CB_Account
$addon->OnUserDelete = "MyAwesomeAddon_OnUserDelete";

If your add-on needs to edit the output user data that is sent to the clients:

function MyAwesomeAddon_OnUserCustomDataOutput ($user, &$customData) {
   // do something, $user is of type CB_Account and $customData is the associative key/value array of the custom data
   $customData["NewKey"] = "NewValue"; // you can add/edit data to output
   unset($customData["MyHiddenKey"]); // or you can delete data from output
$addon->OnUserCustomDataOutput = "MyAwesomeAddon_OnUserCustomDataOutput";

If your add-on needs to deny an account custom data from being updated by clients: