Skip to main content
Addons Started by emanuele · · Read 10919 times 0 Members and 1 Guest are viewing this topic.

Addons

Code: [Copy]
	if (($loaders = cache_get_data('addon_loaders', 3600)) === null)
{
$addondirs = glob(ADDONSDIR . '/*', GLOB_ONLYDIR);
foreach ($addondirs as $dir)
{
$loader = array();
$loader['file'] = $dir . '/index.php';

if (file_exists($loader['file']))
{
require_once($loader['file']);
$function = ucfirst(basename($dir)) . '_Addon';

if (class_exists($function))
$loader['function'] = array($function, 'Hooks');
elseif (function_exists($function))
$loader['function'] = $function;
else
continue;

call_user_func($loader['function']);
$loaders[] = $loader;
}
}
cache_put_data('addon_loaders', $loaders, 3600);
}
elseif (!empty($loaders))
{
foreach ($loaders as $loader)
{
require_once($loader['file']);
call_user_func($loader['function']);
}
}

Just before
Code: [Copy]
call_integration_include_hook('integrate_pre_include');

So, putting addons into a specific directory with an index.php properly formatted, will allow to load the hooks automatically.
Cached because addons shouldn't change so frequently and it avoids few filesystem accesses.

Something like this would be enough:
Code: [Copy]
class Test_Addon
{
public static function Hooks()
{
add_integration_function('a_hook', 'my_function', false);
}
}

or for lazier people:
Code: [Copy]
function Test_Addon()
{
add_integration_function('a_hook', 'my_function', false);
}
Bugs creator.
Features destroyer.
Template killer.