bludit/bl-kernel/boot/rules/60.plugins.php

107 lines
2.5 KiB
PHP
Raw Normal View History

2015-06-27 00:12:26 +02:00
<?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Variables
// ============================================================================
$plugins = array(
2015-08-07 19:22:13 +02:00
'siteHead'=>array(),
'siteBodyBegin'=>array(),
'siteBodyEnd'=>array(),
'siteSidebar'=>array(),
'beforeSiteLoad'=>array(),
'afterSiteLoad'=>array(),
2015-08-07 04:13:55 +02:00
'pageBegin'=>array(),
'pageEnd'=>array(),
'postBegin'=>array(),
'postEnd'=>array(),
'adminHead'=>array(),
'adminBodyBegin'=>array(),
'adminBodyEnd'=>array(),
'adminSidebar'=>array(),
2015-08-08 02:39:10 +02:00
'beforeAdminLoad'=>array(),
'afterAdminLoad'=>array(),
2015-08-07 04:13:55 +02:00
2016-01-08 00:43:09 +01:00
'beforeRulesLoad'=>array(),
'afterFormSave'=>array(),
2016-01-08 00:43:09 +01:00
'afterPostCreate'=>array(),
'afterPostModify'=>array(),
'afterPostDelete'=>array(),
'afterPageCreate'=>array(),
'afterPageModify'=>array(),
'afterPageDelete'=>array(),
2015-08-07 04:13:55 +02:00
'loginHead'=>array(),
'loginBodyBegin'=>array(),
'loginBodyEnd'=>array(),
2015-06-27 00:12:26 +02:00
'all'=>array()
);
$pluginsEvents = $plugins;
unset($pluginsEvents['all']);
// ============================================================================
// Functions
// ============================================================================
2016-01-14 05:42:18 +01:00
function buildPlugins()
2015-06-27 00:12:26 +02:00
{
global $plugins;
global $pluginsEvents;
2015-07-03 22:44:26 +02:00
global $Language;
global $Site;
2015-06-27 00:12:26 +02:00
// List plugins directories
$list = Filesystem::listDirectories(PATH_PLUGINS);
// Get declared clasess before load plugins clasess, this list doesn't have the plugins clasess.
$currentDeclaredClasess = get_declared_classes();
// Load each plugin clasess
foreach($list as $pluginPath) {
2016-05-07 05:10:10 +02:00
// Check if the directory has the plugin.php
if(file_exists($pluginPath.DS.'plugin.php')) {
include($pluginPath.DS.'plugin.php');
}
2015-06-27 00:12:26 +02:00
}
// Get plugins clasess loaded
$pluginsDeclaredClasess = array_diff(get_declared_classes(), $currentDeclaredClasess);
foreach($pluginsDeclaredClasess as $pluginClass)
{
// Ignore non-plugin classes
if ( !is_subclass_of( $pluginClass, 'Plugin' ) )
{
continue;
}
$Plugin = new $pluginClass();
2015-07-03 22:44:26 +02:00
2016-08-09 04:43:33 +02:00
// Push Plugin to array all plugins installed and not installed.
$plugins['all'][$pluginClass] = $Plugin;
2016-06-20 02:45:09 +02:00
2016-08-09 04:43:33 +02:00
// If the plugin is installed, order by hooks.
if($Plugin->installed()) {
2016-06-20 02:45:09 +02:00
2016-08-09 04:43:33 +02:00
foreach($pluginsEvents as $event=>$value) {
2016-06-20 02:45:09 +02:00
2016-08-09 04:43:33 +02:00
if(method_exists($Plugin, $event)) {
array_push($plugins[$event], $Plugin);
2015-06-27 00:12:26 +02:00
}
}
}
}
}
// ============================================================================
// Main
// ============================================================================
2016-01-14 05:42:18 +01:00
buildPlugins();