Add new 'head' hook

- Add new App->registerStylesheet method
- Reworked App->init_pagehead into App->initHead
This commit is contained in:
Hypolite Petovan 2018-09-20 21:30:51 -04:00
父節點 30f8fb82b6
當前提交 2ae6556b32
共有 5 個檔案被更改,包括 33 行新增11 行删除

查看文件

@ -252,6 +252,11 @@ Called after conversion of bbcode to HTML.
Called after tag conversion of HTML to bbcode (e.g. remote message posting)
`$b` is a string converted text
### head
Called when building the `<head>` sections.
Stylesheets should be registered using this hook.
`$b` is an HTML string of the `<head>` tag.
### page_header
Called after building the page navigation section.
`$b` is a string HTML of nav region.
@ -288,8 +293,8 @@ Called after HTML content functions have completed.
### footer
Called after HTML content functions have completed.
Deferred Javascript files should be registered using this hook.
`$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:
@ -568,6 +573,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('head');
Addon::callHooks('footer');
### src/Model/Item.php

查看文件

@ -395,7 +395,7 @@ if ($a->module_loaded) {
* theme choices made by the modules can take effect.
*/
$a->init_pagehead();
$a->initHead();
/*
* Build the page ending -- this is stuff that goes right before

查看文件

@ -96,13 +96,21 @@ class App
public $force_max_items = 0;
public $theme_events_in_profile = true;
public $stylesheets = [];
public $footerScripts = [];
public function registerStylesheet($path)
{
$url = str_replace($this->get_basepath() . DIRECTORY_SEPARATOR, '', $path);
$this->stylesheets[] = trim($url, '/');
}
public function registerFooterScript($path)
{
$url = str_replace($this->get_basepath() . DIRECTORY_SEPARATOR, '', $path);
$this->footerScripts[] = $this->get_baseurl() . '/' . trim($url, '/');
$this->footerScripts[] = trim($url, '/');
}
/**
@ -741,7 +749,7 @@ class App
$this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
}
public function init_pagehead()
public function initHead()
{
$interval = ((local_user()) ? PConfig::get(local_user(), 'system', 'update_interval') : 40000);
@ -766,9 +774,6 @@ class App
* since the code added by the modules frequently depends on it
* being first
*/
if (!isset($this->page['htmlhead'])) {
$this->page['htmlhead'] = '';
}
// If we're using Smarty, then doing replace_macros() will replace
// any unrecognized variables with a blank string. Since we delay
@ -791,7 +796,9 @@ 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');
$this->page['htmlhead'] = replace_macros($tpl, [
@ -805,8 +812,9 @@ class App
'$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'];
}
@ -845,10 +853,10 @@ class App
Core\Addon::callHooks('footer', $this->page['footer']);
$tpl = get_markup_template('footer.tpl');
$this->page['footer'] .= replace_macros($tpl, [
$this->page['footer'] = replace_macros($tpl, [
'$baseurl' => $this->get_baseurl(),
'$footerScripts' => $this->footerScripts,
]);
]) . $this->page['footer'];
}
public function set_curl_code($code)

查看文件

@ -11,6 +11,10 @@
<link rel="stylesheet" type="text/css" href="{{$stylesheet}}" media="all" />
{{foreach $stylesheets as $stylesheetUrl}}
<link rel="stylesheet" href="{{$stylesheetUrl}}" type="text/css" media="screen" />
{{/foreach}}
<!--
<link rel="shortcut icon" href="images/friendica-32.png" />
<link rel="apple-touch-icon" href="images/friendica-128.png"/>

查看文件

@ -33,6 +33,10 @@
<link rel="stylesheet" href="view/theme/frio/css/hovercard.css" type="text/css" media="screen"/>
<link rel="stylesheet" href="view/theme/frio/css/font-awesome.custom.css" type="text/css" media="screen"/>
{{foreach $stylesheets as $stylesheetUrl}}
<link rel="stylesheet" href="{{$stylesheetUrl}}" type="text/css" media="screen" />
{{/foreach}}
<!--
<link rel="shortcut icon" href="images/friendica-32.png" />
<link rel="apple-touch-icon" href="images/friendica-128.png"/>