bludit/kernel/boot/rules/80.plugins.php

101 lines
2.9 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-07-23 03:45:54 +02:00
'onSiteHead'=>array(), // <html><head>HERE</head><body>...</body></html>
'onSiteBodyBegin'=>array(), // <html><head>...</head><body>HERE...</body></html>
'onSiteBodyEnd'=>array(), // <html><head>...</head><body>...HERE</body></html>
'onSiteSidebar'=>array(), // <html><head>...</head><body>...<sidebar>HERE</sidebar>...</body></html>
2015-06-27 00:12:26 +02:00
'onAdminHead'=>array(),
2015-07-23 03:45:54 +02:00
'onAdminBodyBegin'=>array(),
'onAdminBodyEnd'=>array(),
2015-06-27 00:12:26 +02:00
'onAdminSidebar'=>array(),
2015-07-20 05:14:12 +02:00
'beforeSiteLoad'=>array(),
'afterSiteLoad'=>array(),
2015-06-27 00:12:26 +02:00
'beforePostsLoad'=>array(),
'afterPostsLoad'=>array(),
'beforePagesLoad'=>array(),
'afterPagesLoad'=>array(),
'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-07-03 22:44:26 +02:00
// Set Plugin data
$languageFilename = PATH_PLUGINS.$Plugin->directoryName().'language'.DS.$Site->locale().'.json';
if( Sanitize::pathFile($languageFilename) )
{
2015-07-07 00:22:03 +02:00
$database = new dbJSON($languageFilename, false);
2015-07-03 22:44:26 +02:00
}
else
{
$languageFilename = PATH_PLUGINS.$Plugin->directoryName().'language'.DS.'en_US.json';
2015-07-07 00:22:03 +02:00
$database = new dbJSON($languageFilename, false);
2015-07-03 22:44:26 +02:00
}
2015-07-14 04:16:28 +02:00
2015-07-15 01:57:18 +02:00
$databaseArray = $database->db;
2015-07-07 03:05:17 +02:00
$Plugin->setData( $databaseArray['plugin-data'] );
2015-07-03 22:44:26 +02:00
// Add words to language dictionary.
2015-07-07 00:22:03 +02:00
unset($databaseArray['plugin-data']);
$Language->add($databaseArray);
2015-07-03 22:44:26 +02:00
// Push Plugin to array all plugins installed and not installed.
2015-06-27 00:12:26 +02:00
array_push($plugins['all'], $Plugin);
2015-07-03 22:44:26 +02:00
// If the plugin installed
2015-06-27 00:12:26 +02:00
if($Plugin->installed())
{
foreach($pluginsEvents as $event=>$value)
{
/*
if($Plugin->onSiteHead()!==false)
array_push($plugins['onSiteHead'], $Plugin);
*/
if($Plugin->{$event}()!==false) {
array_push($plugins[$event], $Plugin);
}
}
}
}
}
// ============================================================================
// Main
// ============================================================================
build_plugins();