1
0
Fork 0

Merge pull request #5773 from MrPetovan/task/rewrite-js-hooks

Rewrite JS hooks
This commit is contained in:
Michael Vogel 2018-10-01 17:10:30 +00:00 committed by GitHub
commit 103535d620
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 213 additions and 318 deletions

View file

@ -96,6 +96,41 @@ class App
public $force_max_items = 0;
public $theme_events_in_profile = true;
public $stylesheets = [];
public $footerScripts = [];
/**
* Register a stylesheet file path to be included in the <head> tag of every page.
* Inclusion is done in App->initHead().
* The path can be absolute or relative to the Friendica installation base folder.
*
* @see App->initHead()
*
* @param string $path
*/
public function registerStylesheet($path)
{
$url = str_replace($this->get_basepath() . DIRECTORY_SEPARATOR, '', $path);
$this->stylesheets[] = trim($url, '/');
}
/**
* Register a javascript file path to be included in the <footer> tag of every page.
* Inclusion is done in App->initFooter().
* The path can be absolute or relative to the Friendica installation base folder.
*
* @see App->initFooter()
*
* @param string $path
*/
public function registerFooterScript($path)
{
$url = str_replace($this->get_basepath() . DIRECTORY_SEPARATOR, '', $path);
$this->footerScripts[] = trim($url, '/');
}
/**
* @brief An array for all theme-controllable parameters
*
@ -309,7 +344,6 @@ class App
'aside' => '',
'bottom' => '',
'content' => '',
'end' => '',
'footer' => '',
'htmlhead' => '',
'nav' => '',
@ -738,7 +772,17 @@ class App
$this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
}
public function init_pagehead()
/**
* Initializes App->page['htmlhead'].
*
* Includes:
* - Page title
* - Favicons
* - Registered stylesheets (through App->registerStylesheet())
* - Infinite scroll data
* - head.tpl template
*/
public function initHead()
{
$interval = ((local_user()) ? PConfig::get(local_user(), 'system', 'update_interval') : 40000);
@ -759,23 +803,13 @@ class App
$this->page['title'] = $this->config['sitename'];
}
/* put the head template at the beginning of page['htmlhead']
* since the code added by the modules frequently depends on it
* being first
*/
if (!isset($this->page['htmlhead'])) {
$this->page['htmlhead'] = '';
if (!empty($this->theme['stylesheet'])) {
$stylesheet = $this->theme['stylesheet'];
} else {
$stylesheet = $this->getCurrentThemeStylesheetPath();
}
// If we're using Smarty, then doing replace_macros() will replace
// any unrecognized variables with a blank string. Since we delay
// replacing $stylesheet until later, we need to replace it now
// with another variable name
if ($this->theme['template_engine'] === 'smarty3') {
$stylesheet = $this->get_template_ldelim('smarty3') . '$stylesheet' . $this->get_template_rdelim('smarty3');
} else {
$stylesheet = '$stylesheet';
}
$this->registerStylesheet($stylesheet);
$shortcut_icon = Config::get('system', 'shortcut_icon');
if ($shortcut_icon == '') {
@ -788,9 +822,15 @@ class App
}
// get data wich is needed for infinite scroll on the network page
$invinite_scroll = infinite_scroll_data($this->module);
$infinite_scroll = infinite_scroll_data($this->module);
Core\Addon::callHooks('head', $this->page['htmlhead']);
$tpl = get_markup_template('head.tpl');
/* put the head template at the beginning of page['htmlhead']
* since the code added by the modules frequently depends on it
* being first
*/
$this->page['htmlhead'] = replace_macros($tpl, [
'$baseurl' => $this->get_baseurl(),
'$local_user' => local_user(),
@ -801,21 +841,56 @@ class App
'$update_interval' => $interval,
'$shortcut_icon' => $shortcut_icon,
'$touch_icon' => $touch_icon,
'$stylesheet' => $stylesheet,
'$infinite_scroll' => $invinite_scroll,
'$infinite_scroll' => $infinite_scroll,
'$block_public' => intval(Config::get('system', 'block_public')),
'$stylesheets' => $this->stylesheets,
]) . $this->page['htmlhead'];
}
public function init_page_end()
/**
* Initializes App->page['footer'].
*
* Includes:
* - Javascript homebase
* - Mobile toggle link
* - Registered footer scripts (through App->registerFooterScript())
* - footer.tpl template
*/
public function initFooter()
{
if (!isset($this->page['end'])) {
$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/' . $this->user['nickname'];
}
$tpl = get_markup_template('end.tpl');
$this->page['end'] = replace_macros($tpl, [
'$baseurl' => $this->get_baseurl()
]) . $this->page['end'];
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,
]) . $this->page['footer'];
}
public function set_curl_code($code)