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(),
|
|
|
|
|
|
|
|
'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
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
function build_plugins()
|
|
|
|
{
|
|
|
|
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) {
|
2015-07-03 22:44:26 +02:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
$Plugin = new $pluginClass;
|
|
|
|
|
2015-11-22 19:11:47 +01:00
|
|
|
// Default language and meta data for the plugin
|
|
|
|
$tmpMetaData = array();
|
|
|
|
$languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.'en_US.json';
|
|
|
|
$database = new dbJSON($languageFilename, false);
|
|
|
|
$tmpMetaData = $database->db['plugin-data'];
|
|
|
|
|
|
|
|
// Check if the plugin is translated.
|
2015-09-04 02:55:05 +02:00
|
|
|
$languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.$Site->locale().'.json';
|
2015-07-03 22:44:26 +02:00
|
|
|
if( Sanitize::pathFile($languageFilename) )
|
|
|
|
{
|
2015-07-07 00:22:03 +02:00
|
|
|
$database = new dbJSON($languageFilename, false);
|
2015-11-22 19:11:47 +01:00
|
|
|
$tmpMetaData = array_merge($tmpMetaData, $database->db['plugin-data']);
|
2015-07-03 22:44:26 +02:00
|
|
|
}
|
2015-07-14 04:16:28 +02:00
|
|
|
|
2015-11-22 19:11:47 +01:00
|
|
|
// Set plugin meta data
|
|
|
|
$Plugin->setData($tmpMetaData);
|
2015-07-03 22:44:26 +02:00
|
|
|
|
|
|
|
// Add words to language dictionary.
|
2015-11-22 19:11:47 +01:00
|
|
|
unset($database->db['plugin-data']);
|
|
|
|
$Language->add($database->db);
|
2015-07-03 22:44:26 +02:00
|
|
|
|
|
|
|
// Push Plugin to array all plugins installed and not installed.
|
2015-09-08 02:51:48 +02:00
|
|
|
$plugins['all'][$pluginClass] = $Plugin;
|
2015-06-27 00:12:26 +02:00
|
|
|
|
2015-11-22 19:11:47 +01:00
|
|
|
// If the plugin is installed, order by hooks.
|
2015-06-27 00:12:26 +02:00
|
|
|
if($Plugin->installed())
|
|
|
|
{
|
|
|
|
foreach($pluginsEvents as $event=>$value)
|
|
|
|
{
|
2015-08-07 23:33:43 +02:00
|
|
|
if(method_exists($Plugin, $event)) {
|
2015-06-27 00:12:26 +02:00
|
|
|
array_push($plugins[$event], $Plugin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// Main
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
build_plugins();
|