Jump to content

Hooks


midnightstreamer
 Share

Recommended Posts

Hooks are used to customize the Panel behaviour based on event type.

Hook files are located in the /home/midnightstreamer/iptv_midnight_streamer/wwwdir/application/hooks directory and have to be prefixed by the custom_ keyword.

The add_hook function is used to register the callback functions.

Syntax

add_hook(string $event_type, integer $priority, string $callback_function)

 

Available Event Types are 

  • line/disable_line
  • line/enable_line
  • mag/disable_mag
  • mag/enable_mag

The callback functions execution order is defined by the priority parameter.

The callback functions have two array type parameters available for processing, $segments which contains the URL segments from the 3rd segment on and $post array which contains POST data.

For example if we want to call an API on another server while disabling/enabling a Line or MAG Device in our Panel, we can make a hook like this:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function disable_line($segments, $post)
{
		$CI =& get_instance();

		$line = $CI->lines_model->get_line($segments[0]);

		call_api('https://server.com:8001/', 'API_KEY', 'api/line/update', array('username' => $line->username, 'disabled' => 1));
}

function enable_line($segments, $post)
{
		$CI =& get_instance();

		$line = $CI->lines_model->get_line($segments[0]);

		call_api('https://server.com:8001/', 'API_KEY', 'api/line/update', array('username' => $line->username, 'disabled' => 0));
}

function disable_mag($segments, $post)
{
		$CI =& get_instance();

		$mac_address = $CI->mags_model->get_mag_mac_by_id($segments[0]);

		call_api('https://server.com:8001/', 'API_KEY', 'api/mag/update', array('mac_address' => $mac_address, 'disabled' => 1));
}

function enable_mag($segments, $post)
{
		$CI =& get_instance();

		$mac_address = $CI->mags_model->get_mag_mac_by_id($segments[0]);

		call_api('https://server.com:8001/', 'API_KEY', 'api/mag/update', array('mac_address' => $mac_address, 'disabled' => 0));
}

add_hook('line/disable_line', 1, 'disable_line');
add_hook('line/enable_line', 1, 'enable_line');

add_hook('mag/disable_mag', 1, 'disable_mag');
add_hook('mag/enable_mag', 1, 'enable_mag');

?>

 

Link to comment
Share on other sites

 Share

×
×
  • Create New...