[Pmwiki-users] Hooks (was Part II: Notes while setting up the beta site)
Christian Ridderström
chr
Tue Feb 17 08:43:42 CST 2004
On Tue, 17 Feb 2004, Christian Ridderstr?m wrote:
> This was a bit complicated, so I'm going to try and implement an array
> where you can add 'hook:s'.
The hooks were easy --- I add them like this:
addTo_customHook('addCurrentGroupToSearchBox');
where 'addCurrentGroupToSearchBox' is the name of a function that I want
to be run after I've included stdconfig.php. "Running the hook" is done
like this:
include_once("scripts/stdconfig.php");
run_customHook(); // Run customization hooks
which calls all the functions in the array $customHook.
Here's the code:
/** Function: Add the function $fcn to a hook-array, $hook.
The function is specified by giving a string with its name.
The function is prepended if $prepend is true (default is false).
Example: add_hook($customHook, 'a_hook_function');
*/
function add_to_hook(&$hook, $fcn, $prepend=false){
if(!isset($hook)) $hook=array();
if($prepend)
array_splice($hook, 0, 0, array($fcn));
else
$hook[] = $fcn; // Append hook
return $hook;
}
/** Function: Run the hook '$hook'
*/
function run_hook($hook){
return array_map('call_user_func',
array_filter($hook, 'function_exists'));
}
/** Function: Add $fcn to the (global) hook $customHook
The $customHook is "run" at the end of config.php (maybe in
the future it will be run from within pmwiki.php).
*/
function addTo_customHook($fcn, $prepend=false){
global $customHook;
return add_to_hook($customHook, $fcn, $prepend);
}
/** Function: Run the (global) hook $customHook
*/
function run_customHook(){
global $customHook;
return run_hook($customHook);
}
/Christian
--
Christian Ridderstr?m http://www.md.kth.se/~chr
More information about the pmwiki-users
mailing list