Add new footer hook

- Add new App->footerScripts array
- Add footer.tpl template
- Add documentation
- Rework App->init_page_end to App->initFooter
This commit is contained in:
Hypolite Petovan 2018-09-20 21:01:05 -04:00
parent 7dd6fb3b3c
commit 55f1d7b90e
4 changed files with 56 additions and 44 deletions

View File

@ -286,6 +286,11 @@ No hook data.
Called after HTML content functions have completed.
`$b` is (string) HTML of content div.
### footer
Called after HTML content functions have completed.
`$b` is (string) HTML of footer div/element.
Used to load deferred Javascript files.
### avatar_lookup
Called when looking up the avatar. `$b` is an array:
@ -563,6 +568,7 @@ Here is a complete list of all hook callbacks with file locations (as of 01-Apr-
### src/App.php
Addon::callHooks('load_config');
Addon::callHooks('footer');
### src/Model/Item.php

View File

@ -153,10 +153,6 @@ if (! x($_SESSION, 'authenticated')) {
header('X-Account-Management-Status: none');
}
/* set up page['htmlhead'] and page['end'] for the modules to use */
$a->page['htmlhead'] = '';
$a->page['end'] = '';
$_SESSION['sysmsg'] = defaults($_SESSION, 'sysmsg' , []);
$_SESSION['sysmsg_info'] = defaults($_SESSION, 'sysmsg_info' , []);
$_SESSION['last_updated'] = defaults($_SESSION, 'last_updated', []);
@ -326,10 +322,6 @@ if (file_exists($theme_info_file)) {
/* initialise content region */
if (! x($a->page, 'content')) {
$a->page['content'] = '';
}
if ($a->mode == App::MODE_NORMAL) {
Addon::callHooks('page_content_top', $a->page['content']);
}
@ -411,18 +403,7 @@ $a->init_pagehead();
* Build the page ending -- this is stuff that goes right before
* the closing </body> tag
*/
$a->init_page_end();
// If you're just visiting, let javascript take you home
if (x($_SESSION, 'visitor_home')) {
$homebase = $_SESSION['visitor_home'];
} elseif (local_user()) {
$homebase = 'profile/' . $a->user['nickname'];
}
if (isset($homebase)) {
$a->page['content'] .= '<script>var homebase="' . $homebase . '" ; </script>';
}
$a->initFooter();
/*
* now that we've been through the module content, see if the page reported
@ -444,23 +425,6 @@ if ($a->module != 'install' && $a->module != 'maintenance') {
Nav::build($a);
}
/*
* Add a "toggle mobile" link if we're using a mobile device
*/
if ($a->is_mobile || $a->is_tablet) {
if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
$link = 'toggle_mobile?address=' . curPageURL();
} else {
$link = 'toggle_mobile?off=1&address=' . curPageURL();
}
$a->page['footer'] = replace_macros(
get_markup_template("toggle_mobile_footer.tpl"),
[
'$toggle_link' => $link,
'$toggle_text' => L10n::t('toggle mobile')]
);
}
/**
* Build the page - now that we have all the components
*/

View File

@ -96,6 +96,15 @@ class App
public $force_max_items = 0;
public $theme_events_in_profile = true;
public $footerScripts = [];
public function registerFooterScript($path)
{
$url = str_replace($this->get_basepath() . DIRECTORY_SEPARATOR, '', $path);
$this->footerScripts[] = $this->get_baseurl() . '/' . trim($url, '/');
}
/**
* @brief An array for all theme-controllable parameters
*
@ -802,15 +811,45 @@ class App
]) . $this->page['htmlhead'];
}
public function init_page_end()
public function initFooter()
{
if (!isset($this->page['end'])) {
$this->page['end'] = '';
if (!isset($this->page['footer'])) {
$this->page['footer'] = '';
}
$tpl = get_markup_template('end.tpl');
$this->page['end'] = replace_macros($tpl, [
'$baseurl' => $this->get_baseurl()
]) . $this->page['end'];
// If you're just visiting, let javascript take you home
if (!empty($_SESSION['visitor_home'])) {
$homebase = $_SESSION['visitor_home'];
} elseif (local_user()) {
$homebase = 'profile/' . $a->user['nickname'];
}
if (isset($homebase)) {
$this->page['footer'] .= '<script>var homebase="' . $homebase . '";</script>' . "\n";
}
/*
* Add a "toggle mobile" link if we're using a mobile device
*/
if ($this->is_mobile || $this->is_tablet) {
if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
$link = 'toggle_mobile?address=' . curPageURL();
} else {
$link = 'toggle_mobile?off=1&address=' . curPageURL();
}
$this->page['footer'] .= replace_macros(get_markup_template("toggle_mobile_footer.tpl"), [
'$toggle_link' => $link,
'$toggle_text' => Core\L10n::t('toggle mobile')
]);
}
Core\Addon::callHooks('footer', $this->page['footer']);
$tpl = get_markup_template('footer.tpl');
$this->page['footer'] .= replace_macros($tpl, [
'$baseurl' => $this->get_baseurl(),
'$footerScripts' => $this->footerScripts,
]);
}
public function set_curl_code($code)

View File

@ -0,0 +1,3 @@
{{foreach $footerScripts as $scriptUrl}}
<script type="text/javascript" src="{{$scriptUrl}}"></script>
{{/foreach}}