149 lines
3.9 KiB
PHP
149 lines
3.9 KiB
PHP
<?php
|
|
|
|
|
|
// Liste des modules
|
|
function module_list()
|
|
{
|
|
//Définir le répertoire de stockage des modules
|
|
|
|
}
|
|
|
|
function module_load_all(){}
|
|
|
|
function module_exists(){}
|
|
|
|
function module_load_include(){}
|
|
|
|
function module_load_all_includes(){}
|
|
|
|
/**
|
|
* A hook is a PHP function that is named foo_bar(), where "foo" is the name of
|
|
* the module (whose filename is thus foo.module) and "bar" is the name of the hook.
|
|
* Each hook has a defined set of parameters and a specified result type.
|
|
*
|
|
* The string "hook" is used as a placeholder for the module name is the hook
|
|
* definitions. For example, if the module file is called example.module,
|
|
* then hook_help() as implemented by that module would be defined as example_help().
|
|
*/
|
|
|
|
/**
|
|
* Determine whether a module implements a hook.
|
|
*
|
|
* @param $module
|
|
* The name of the module (without the .module extension).
|
|
* @param $hook
|
|
* The name of the hook (e.g. "help" or "menu").
|
|
* @return
|
|
* TRUE if the module is both installed and enabled, and the hook is
|
|
* implemented in that module.
|
|
*/
|
|
function module_hook($module, $hook) {
|
|
return function_exists($module .'_'. $hook);
|
|
}
|
|
|
|
/**
|
|
* Determine which modules are implementing a hook.
|
|
*
|
|
* @param $hook
|
|
* The name of the hook (e.g. "help" or "menu").
|
|
* @param $sort
|
|
* By default, modules are ordered by weight and filename, settings this option
|
|
* to TRUE, module list will be ordered by module name.
|
|
* @param $refresh
|
|
* For internal use only: Whether to force the stored list of hook
|
|
* implementations to be regenerated (such as after enabling a new module,
|
|
* before processing hook_enable).
|
|
* @return
|
|
* An array with the names of the modules which are implementing this hook.
|
|
*/
|
|
function module_implements($hook, $sort = FALSE, $refresh = FALSE) {
|
|
static $implementations;
|
|
|
|
if ($refresh) {
|
|
$implementations = array();
|
|
return;
|
|
}
|
|
|
|
if (!isset($implementations[$hook])) {
|
|
$implementations[$hook] = array();
|
|
$list = module_list(FALSE, TRUE, $sort);
|
|
foreach ($list as $module) {
|
|
if (module_hook($module, $hook)) {
|
|
$implementations[$hook][] = $module;
|
|
}
|
|
}
|
|
}
|
|
|
|
// The explicit cast forces a copy to be made. This is needed because
|
|
// $implementations[$hook] is only a reference to an element of
|
|
// $implementations and if there are nested foreaches (due to nested node
|
|
// API calls, for example), they would both manipulate the same array's
|
|
// references, which causes some modules' hooks not to be called.
|
|
// See also http://www.zend.com/zend/art/ref-count.php.
|
|
return (array)$implementations[$hook];
|
|
}
|
|
|
|
/**
|
|
* Invoque un point d'entrée.
|
|
*
|
|
* @param $module
|
|
* Le nom du module.
|
|
* @param $hook
|
|
* Le nom de la fonction.
|
|
* @param ...
|
|
* Les arguments nécessaire à la fonction.
|
|
* @return
|
|
* Valeur de retour.
|
|
*/
|
|
function module_invoke() {
|
|
$args = func_get_args();
|
|
$module = $args[0];
|
|
$hook = $args[1];
|
|
unset($args[0], $args[1]);
|
|
$function = $module .'_'. $hook;
|
|
if (module_hook($module, $hook)) {
|
|
return call_user_func_array($function, $args);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Invoke un point d'entrée dans tous les modules qui l'implémente.
|
|
*
|
|
* @param $hook
|
|
* The name of the hook to invoke.
|
|
* @param ...
|
|
* Arguments to pass to the hook.
|
|
* @return
|
|
* An array of return values of the hook implementations. If modules return
|
|
* arrays from their implementations, those are merged into one array.
|
|
*/
|
|
function module_invoke_all() {
|
|
$args = func_get_args();
|
|
$hook = $args[0];
|
|
unset($args[0]);
|
|
$return = array();
|
|
foreach (module_implements($hook) as $module) {
|
|
$function = $module .'_'. $hook;
|
|
$result = call_user_func_array($function, $args);
|
|
if (isset($result) && is_array($result)) {
|
|
$return = array_merge_recursive($return, $result);
|
|
}
|
|
else if (isset($result)) {
|
|
$return[] = $result;
|
|
}
|
|
}
|
|
|
|
return $return;
|
|
}
|
|
|
|
|
|
// Point d'entrée principal
|
|
|
|
// Point d'entrée menu
|
|
|
|
// Point d'entrée permissions
|
|
|
|
// Point d'entrée préférences
|
|
|
|
|