Skip to content
tenzap edited this page Mar 9, 2022 · 2 revisions

Kalkun plugins use combination of HMVC (Hierarchical model–view–controller) and hook pattern.

Every plugin has it's own controller, model, view, library. In addition it can use Kalkun's core resources.

Path

All plugins must be located in application/plugins/.

A plugin is represented by a folder named as plugin_name.

A plugin must have a core file, also named: plugin_name.php.

For example, if you have a plugin called my_plugin then it must be placed in application/plugins/my_plugin/ and the core file is application/plugins/my_plugin/my_plugin.php.

Core file

The core file must contain the header, and the utility function.

You may also add a hook

Header

Every plugin must have a header containing information about the plugin. This information is inserted into database.

/**
* Plugin Name: Simple Autoreply
* Plugin URI: http://azhari.harahap.us
* Version: 0.1
* Description: Simple a.k.a stupid autoreply, reply to all incoming message
* Author: Azhari Harahap
* Author URI: http://azhari.harahap.us
*/

Utility function

The core file must include these utility function.

Utility function name must be prefixed with the plugin name followed by an underscore.

  • Install. This function is called when the plugin is first installed into the database
function simple_autoreply_install()
{
	return true;
}
  • Activate. This function is called when the plugin is first activated
function simple_autoreply_activate()
{
	return true;
}
  • Deactivate. This function is called when the plugin is deactivated
function simple_autoreply_deactivate()
{
	return true;
}

Adding a hook

  1. First you need to register the hook. Do it this way:
add_action(HOOK_NAME, FUNCTION_NAME, PRIORITY);

For example:

add_action("message.incoming.before", "simple_autoreply", 11);
  1. Create the function you just referenced in add_action. For example: Function simple_autoreply:
function simple_autoreply($sms)
{
	$config = simple_autoreply_initialize();
	$CI =& get_instance();
	$CI->load->model('Message_model');
	$data['coding'] = 'default';
	$data['class'] = '1';
	$data['dest'] = $sms->SenderNumber;
	$data['date'] = date('Y-m-d H:i:s');
	$data['message'] = $config['message'];
	$data['delivery_report'] = 'default';
	$data['uid'] = $config['uid'];
	$CI->Message_model->send_messages($data);
}

Available hooks

  • message.incoming.before
  • message.incoming.after
  • message.outgoing
  • message.outgoing_all
  • message.outgoing_dest_data
  • phonebook.contact.get
  • phonebook.contact.menu

Access Kalkun core resource

If you need to access the kalkun core resources (which you usually do with $this when in a controller, model...), this can't be done in the core file. For that you need to get it as below instead.

$CI =& get_instance();
$CI->load->model('Message_model');

Helper functions

If you want to load the configuration of the plugin, or the language files to have the translated labels, there are 2 helper functions in class Plugin_helper:

  • Plugin_helper::get_plugin_config('plugin_name');
  • Plugin_helper::load_lang('plugin_name');
Clone this wiki locally