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(),
|
|
|
|
|
2017-05-17 18:48:51 +02:00
|
|
|
'beforeAdminLoad'=>array(),
|
|
|
|
'afterAdminLoad'=>array(),
|
2015-08-07 04:13:55 +02:00
|
|
|
'adminHead'=>array(),
|
|
|
|
'adminBodyBegin'=>array(),
|
|
|
|
'adminBodyEnd'=>array(),
|
|
|
|
'adminSidebar'=>array(),
|
2018-03-19 19:55:31 +01:00
|
|
|
'adminContentSidebar'=>array(),
|
2018-06-03 21:51:47 +02:00
|
|
|
'dashboard'=>array(),
|
2015-08-07 04:13:55 +02:00
|
|
|
|
2017-07-05 19:59:51 +02:00
|
|
|
'beforeAll'=>array(),
|
|
|
|
'afterAll'=>array(),
|
2016-01-08 00:43:09 +01:00
|
|
|
|
2018-10-01 16:34:28 +02:00
|
|
|
'paginator'=>array(),
|
|
|
|
|
2016-01-08 00:43:09 +01:00
|
|
|
'afterPageCreate'=>array(),
|
|
|
|
'afterPageModify'=>array(),
|
|
|
|
'afterPageDelete'=>array(),
|
|
|
|
|
2015-08-07 04:13:55 +02:00
|
|
|
'loginHead'=>array(),
|
|
|
|
'loginBodyBegin'=>array(),
|
|
|
|
'loginBodyEnd'=>array(),
|
|
|
|
|
2020-06-24 00:49:11 +02:00
|
|
|
'beforeVerifyUser'=>array(),
|
|
|
|
'afterVerifyUser'=>array(),
|
|
|
|
|
2015-06-27 00:12:26 +02:00
|
|
|
'all'=>array()
|
|
|
|
);
|
|
|
|
|
|
|
|
$pluginsEvents = $plugins;
|
|
|
|
unset($pluginsEvents['all']);
|
|
|
|
|
2019-05-09 17:19:56 +02:00
|
|
|
$pluginsInstalled = array();
|
|
|
|
|
2015-06-27 00:12:26 +02:00
|
|
|
// ============================================================================
|
|
|
|
// Functions
|
|
|
|
// ============================================================================
|
|
|
|
|
2016-01-14 05:42:18 +01:00
|
|
|
function buildPlugins()
|
2015-06-27 00:12:26 +02:00
|
|
|
{
|
|
|
|
global $plugins;
|
|
|
|
global $pluginsEvents;
|
2019-05-09 17:19:56 +02:00
|
|
|
global $pluginsInstalled;
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2018-07-17 19:13:01 +02:00
|
|
|
global $site;
|
2015-06-27 00:12:26 +02:00
|
|
|
|
2017-07-29 00:08:19 +02:00
|
|
|
// Get declared clasess BEFORE load plugins clasess
|
2015-06-27 00:12:26 +02:00
|
|
|
$currentDeclaredClasess = get_declared_classes();
|
|
|
|
|
2019-03-10 18:27:24 +01:00
|
|
|
// List plugins directories
|
|
|
|
$list = Filesystem::listDirectories(PATH_PLUGINS);
|
2015-06-27 00:12:26 +02:00
|
|
|
// Load each plugin clasess
|
2017-07-29 01:33:30 +02:00
|
|
|
foreach ($list as $pluginPath) {
|
2016-05-07 05:10:10 +02:00
|
|
|
// Check if the directory has the plugin.php
|
2017-07-29 00:08:19 +02:00
|
|
|
if (file_exists($pluginPath.DS.'plugin.php')) {
|
2019-03-10 18:27:24 +01:00
|
|
|
include_once($pluginPath.DS.'plugin.php');
|
2016-05-07 05:10:10 +02:00
|
|
|
}
|
2015-06-27 00:12:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get plugins clasess loaded
|
|
|
|
$pluginsDeclaredClasess = array_diff(get_declared_classes(), $currentDeclaredClasess);
|
|
|
|
|
2017-07-29 00:08:19 +02:00
|
|
|
foreach ($pluginsDeclaredClasess as $pluginClass) {
|
2015-06-27 00:12:26 +02:00
|
|
|
$Plugin = new $pluginClass;
|
|
|
|
|
2017-07-29 00:08:19 +02:00
|
|
|
// Check if the plugin is translated
|
2018-07-17 19:13:01 +02:00
|
|
|
$languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.$site->language().'.json';
|
2019-03-10 18:27:24 +01:00
|
|
|
if (!Sanitize::pathFile($languageFilename)) {
|
2017-07-29 00:08:19 +02:00
|
|
|
$languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.DEFAULT_LANGUAGE_FILE;
|
2015-07-03 22:44:26 +02:00
|
|
|
}
|
2015-07-14 04:16:28 +02:00
|
|
|
|
2016-01-14 05:42:18 +01:00
|
|
|
$database = file_get_contents($languageFilename);
|
|
|
|
$database = json_decode($database, true);
|
2015-07-03 22:44:26 +02:00
|
|
|
|
2017-07-29 00:08:19 +02:00
|
|
|
// Set name and description from the language file
|
2016-01-14 05:42:18 +01:00
|
|
|
$Plugin->setMetadata('name',$database['plugin-data']['name']);
|
|
|
|
$Plugin->setMetadata('description',$database['plugin-data']['description']);
|
|
|
|
|
2017-07-29 00:08:19 +02:00
|
|
|
// Remove name and description from the language file loaded and add new words if there are
|
|
|
|
// This function overwrite the key=>value
|
2016-01-14 05:42:18 +01:00
|
|
|
unset($database['plugin-data']);
|
2017-07-29 00:08:19 +02:00
|
|
|
if (!empty($database)) {
|
2018-08-05 17:54:20 +02:00
|
|
|
$L->add($database);
|
2016-01-14 05:42:18 +01:00
|
|
|
}
|
2015-07-03 22:44:26 +02:00
|
|
|
|
2017-07-29 00:08:19 +02:00
|
|
|
// $plugins['all'] Array with all plugins, installed and not installed
|
2016-08-09 04:43:33 +02:00
|
|
|
$plugins['all'][$pluginClass] = $Plugin;
|
2016-06-20 02:45:09 +02:00
|
|
|
|
2017-07-29 00:08:19 +02:00
|
|
|
// If the plugin is installed insert on the hooks
|
|
|
|
if ($Plugin->installed()) {
|
2020-05-12 18:24:06 +02:00
|
|
|
// Include custom hooks
|
|
|
|
if (!empty($Plugin->customHooks)) {
|
|
|
|
foreach ($Plugin->customHooks as $customHook) {
|
|
|
|
if (!isset($plugins[$customHook])) {
|
|
|
|
$plugins[$customHook] = array();
|
|
|
|
$pluginsEvents[$customHook] = array();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-09 17:19:56 +02:00
|
|
|
$pluginsInstalled[$pluginClass] = $Plugin;
|
2017-07-29 00:08:19 +02:00
|
|
|
foreach ($pluginsEvents as $event=>$value) {
|
|
|
|
if (method_exists($Plugin, $event)) {
|
2016-08-09 04:43:33 +02:00
|
|
|
array_push($plugins[$event], $Plugin);
|
2015-06-27 00:12:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-30 23:15:33 +02:00
|
|
|
|
2019-03-10 18:27:24 +01:00
|
|
|
// Sort the plugins by the position for the site sidebar
|
2017-07-30 23:15:33 +02:00
|
|
|
uasort($plugins['siteSidebar'], function ($a, $b) {
|
2020-05-12 18:24:06 +02:00
|
|
|
return $a->position()>$b->position();
|
|
|
|
}
|
|
|
|
);
|
2015-06-27 00:12:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// Main
|
|
|
|
// ============================================================================
|
|
|
|
|
2016-01-14 05:42:18 +01:00
|
|
|
buildPlugins();
|