mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 16:35:19 +00:00
allow themes to mess with the navbar contents without a custom template. It's done as a callback using a transient plugin hook.
For instance to get rid of the notifications link: insert_hook('nav','strip_notify'); function strip_notify($a,&$b) { unset($b['nav']['notifications']); }
This commit is contained in:
parent
8cd9a2c3a9
commit
7536ed6e44
3 changed files with 42 additions and 5 deletions
3
boot.php
3
boot.php
|
@ -2459,6 +2459,8 @@ function construct_page(&$a) {
|
|||
* Build the page - now that we have all the components
|
||||
*/
|
||||
|
||||
require_once(theme_include('theme_init.php'));
|
||||
|
||||
$installing = false;
|
||||
|
||||
if($a->module == 'setup')
|
||||
|
@ -2473,7 +2475,6 @@ function construct_page(&$a) {
|
|||
}
|
||||
}
|
||||
|
||||
require_once(theme_include('theme_init.php'));
|
||||
|
||||
if(($p = theme_include(current_theme() . '.js')) != '')
|
||||
head_add_js($p);
|
||||
|
|
|
@ -201,16 +201,19 @@ EOT;
|
|||
if($banner === false)
|
||||
$banner = 'red';
|
||||
|
||||
$x = array('nav' => $nav, 'usermenu' => $userinfo );
|
||||
call_hooks('nav', $x);
|
||||
|
||||
$tpl = get_markup_template('nav.tpl');
|
||||
|
||||
$a->page['nav'] .= replace_macros($tpl, array(
|
||||
'$baseurl' => $a->get_baseurl(),
|
||||
'$langselector' => ((get_config('system','select_language')) ? lang_selector() : ''),
|
||||
'$sitelocation' => $sitelocation,
|
||||
'$nav' => $nav,
|
||||
'$nav' => $x['nav'],
|
||||
'$banner' => $banner,
|
||||
'$emptynotifications' => t('Nothing new here'),
|
||||
'$userinfo' => $userinfo,
|
||||
'$userinfo' => $x['usermenu'],
|
||||
'$localuser' => local_user(),
|
||||
'$sel' => $a->nav_sel,
|
||||
'$apps' => $a->get_apps(),
|
||||
|
|
|
@ -181,12 +181,14 @@ function unregister_hook($hook,$file,$function) {
|
|||
//
|
||||
// It might not be obvious but themes can manually add hooks to the $a->hooks
|
||||
// array in their theme_init() and use this to customise the app behaviour.
|
||||
// UPDATE: use insert_hook($hookname,$function_name) to do this
|
||||
//
|
||||
|
||||
|
||||
function load_hooks() {
|
||||
$a = get_app();
|
||||
$a->hooks = array();
|
||||
if(! is_array($a->hooks))
|
||||
$a->hooks = array();
|
||||
$r = q("SELECT * FROM hook WHERE true ORDER BY priority DESC");
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
|
@ -197,6 +199,36 @@ function load_hooks() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @function insert_hook($hook,$fn)
|
||||
*
|
||||
* Insert a short-lived hook into the running page request.
|
||||
* Hooks are normally persistent so that they can be called
|
||||
* across asynchronous processes such as delivery and poll
|
||||
* processes.
|
||||
*
|
||||
* insert_hook lets you attach a hook callback immediately
|
||||
* which will not persist beyond the life of this page request
|
||||
* or the current process.
|
||||
*
|
||||
* @param string $hook;
|
||||
* name of hook to attach callback
|
||||
* @param string $fn;
|
||||
* function name of callback handler
|
||||
*
|
||||
*/
|
||||
|
||||
function insert_hook($hook,$fn) {
|
||||
$a = get_app();
|
||||
if(! is_array($a->hooks))
|
||||
$a->hooks = array();
|
||||
if(! array_key_exists($hook,$a->hooks))
|
||||
$a->hooks[$hook] = array();
|
||||
$a->hooks[$hook][] = array('',$fn);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function call_hooks($name, &$data = null) {
|
||||
|
@ -204,7 +236,8 @@ function call_hooks($name, &$data = null) {
|
|||
|
||||
if((is_array($a->hooks)) && (array_key_exists($name,$a->hooks))) {
|
||||
foreach($a->hooks[$name] as $hook) {
|
||||
@include_once($hook[0]);
|
||||
if($hook[0])
|
||||
@include_once($hook[0]);
|
||||
if(function_exists($hook[1])) {
|
||||
$func = $hook[1];
|
||||
$func($a,$data);
|
||||
|
|
Loading…
Reference in a new issue