
With custom hooks, you can place your plugin's data anywhere you want. For example, you have a footer and you want to have links in your footer. There is a link plugin that displays links in the SiteBar with "<? Php Theme :: plugins ('siteSidebar');?>". If you put this code in your footer, all plugins that use "siteSidebar" will be placed in your footer. With my pull request you can now create your own hooks and it can be guaranteed that only a single plugin places its data there but only if its the only plugin implementing your custom hook. How to create custom hooks: in your plugin.php you have to place a public function "registerHooks" returning an array of String. ´´´ public function registerHooks() { return array( "akLinks", "akBusinessHours" ); } ```
135 lines
3.6 KiB
PHP
135 lines
3.6 KiB
PHP
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
// ============================================================================
|
|
// Variables
|
|
// ============================================================================
|
|
|
|
$plugins = array(
|
|
'siteHead'=>array(),
|
|
'siteBodyBegin'=>array(),
|
|
'siteBodyEnd'=>array(),
|
|
'siteSidebar'=>array(),
|
|
'beforeSiteLoad'=>array(),
|
|
'afterSiteLoad'=>array(),
|
|
|
|
'pageBegin'=>array(),
|
|
'pageEnd'=>array(),
|
|
|
|
'beforeAdminLoad'=>array(),
|
|
'afterAdminLoad'=>array(),
|
|
'adminHead'=>array(),
|
|
'adminBodyBegin'=>array(),
|
|
'adminBodyEnd'=>array(),
|
|
'adminSidebar'=>array(),
|
|
'adminContentSidebar'=>array(),
|
|
'dashboard'=>array(),
|
|
|
|
'beforeAll'=>array(),
|
|
'afterAll'=>array(),
|
|
|
|
'paginator'=>array(),
|
|
|
|
'afterPageCreate'=>array(),
|
|
'afterPageModify'=>array(),
|
|
'afterPageDelete'=>array(),
|
|
|
|
'loginHead'=>array(),
|
|
'loginBodyBegin'=>array(),
|
|
'loginBodyEnd'=>array(),
|
|
|
|
'all'=>array()
|
|
);
|
|
|
|
$pluginsEvents = $plugins;
|
|
unset($pluginsEvents['all']);
|
|
|
|
// ============================================================================
|
|
// Functions
|
|
// ============================================================================
|
|
|
|
function buildPlugins()
|
|
{
|
|
global $plugins;
|
|
global $pluginsEvents;
|
|
global $L;
|
|
global $site;
|
|
|
|
// List plugins directories
|
|
$list = Filesystem::listDirectories(PATH_PLUGINS);
|
|
|
|
// Get declared clasess BEFORE load plugins clasess
|
|
$currentDeclaredClasess = get_declared_classes();
|
|
|
|
// Load each plugin clasess
|
|
foreach ($list as $pluginPath) {
|
|
// Check if the directory has the plugin.php
|
|
if (file_exists($pluginPath.DS.'plugin.php')) {
|
|
include($pluginPath.DS.'plugin.php');
|
|
}
|
|
}
|
|
|
|
// Get plugins clasess loaded
|
|
$pluginsDeclaredClasess = array_diff(get_declared_classes(), $currentDeclaredClasess);
|
|
|
|
foreach ($pluginsDeclaredClasess as $pluginClass) {
|
|
$Plugin = new $pluginClass;
|
|
|
|
// Check if the plugin is translated
|
|
$languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.$site->language().'.json';
|
|
if( !Sanitize::pathFile($languageFilename) ) {
|
|
$languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.DEFAULT_LANGUAGE_FILE;
|
|
}
|
|
|
|
$database = file_get_contents($languageFilename);
|
|
$database = json_decode($database, true);
|
|
|
|
// Set name and description from the language file
|
|
$Plugin->setMetadata('name',$database['plugin-data']['name']);
|
|
$Plugin->setMetadata('description',$database['plugin-data']['description']);
|
|
|
|
// Remove name and description from the language file loaded and add new words if there are
|
|
// This function overwrite the key=>value
|
|
unset($database['plugin-data']);
|
|
if (!empty($database)) {
|
|
$L->add($database);
|
|
}
|
|
|
|
// $plugins['all'] Array with all plugins, installed and not installed
|
|
$plugins['all'][$pluginClass] = $Plugin;
|
|
|
|
// If the plugin is installed insert on the hooks
|
|
if ($Plugin->installed()) {
|
|
foreach ($pluginsEvents as $event=>$value) {
|
|
if (method_exists($Plugin, $event)) {
|
|
array_push($plugins[$event], $Plugin);
|
|
}
|
|
}
|
|
|
|
/* THIS PART IS FOR CUSTOM HOOKS */
|
|
if(method_exists($Plugin, "registerHooks"))
|
|
{
|
|
foreach (call_user_func("{$Plugin->className()}::registerHooks") as $customEvent)
|
|
{
|
|
if (method_exists($Plugin, $customEvent))
|
|
{
|
|
$plugins[$customEvent] = array();
|
|
array_push($plugins[$customEvent], $Plugin);
|
|
}
|
|
}
|
|
}
|
|
/* THIS PART IS FOR CUSTOM HOOKS */
|
|
}
|
|
|
|
uasort($plugins['siteSidebar'], function ($a, $b) {
|
|
return $a->position()>$b->position();
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
// ============================================================================
|
|
// Main
|
|
// ============================================================================
|
|
|
|
buildPlugins();
|