2013-03-10 07:24:15 +00:00
|
|
|
<?php
|
2019-08-07 19:53:59 +00:00
|
|
|
|
2019-09-29 16:37:03 +00:00
|
|
|
class CustomHtmlHeaders extends Extension
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2015-09-12 10:43:28 +00:00
|
|
|
# Adds setup block for custom <head> content
|
2019-05-28 16:59:38 +00:00
|
|
|
public function onSetupBuilding(SetupBuildingEvent $event)
|
|
|
|
{
|
|
|
|
$sb = new SetupBlock("Custom HTML Headers");
|
2015-08-03 14:40:20 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
// custom headers
|
|
|
|
$sb->add_longtext_option(
|
|
|
|
"custom_html_headers",
|
|
|
|
"HTML Code to place within <head></head> on all pages<br>"
|
|
|
|
);
|
2015-08-03 14:40:20 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
// modified title
|
|
|
|
$sb->add_choice_option("sitename_in_title", [
|
|
|
|
"none" => 0,
|
|
|
|
"as prefix" => 1,
|
|
|
|
"as suffix" => 2
|
|
|
|
], "<br>Add website name in title");
|
2015-08-03 14:40:20 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$event->panel->add_block($sb);
|
|
|
|
}
|
2019-08-07 19:53:59 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
public function onInitExt(InitExtEvent $event)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
$config->set_default_int("sitename_in_title", 0);
|
|
|
|
}
|
2019-08-07 19:53:59 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
# Load Analytics tracking code on page request
|
|
|
|
public function onPageRequest(PageRequestEvent $event)
|
|
|
|
{
|
|
|
|
$this->handle_custom_html_headers();
|
|
|
|
$this->handle_modified_page_title();
|
|
|
|
}
|
2019-08-07 19:53:59 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
private function handle_custom_html_headers()
|
|
|
|
{
|
|
|
|
global $config, $page;
|
2019-08-07 19:53:59 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$header = $config->get_string('custom_html_headers', '');
|
|
|
|
if ($header!='') {
|
|
|
|
$page->add_html_header($header);
|
2013-03-10 07:24:15 +00:00
|
|
|
}
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2019-08-07 19:53:59 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
private function handle_modified_page_title()
|
|
|
|
{
|
|
|
|
global $config, $page;
|
2019-08-07 19:53:59 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
// get config values
|
2019-08-02 19:40:03 +00:00
|
|
|
$site_title = $config->get_string(SetupConfig::TITLE);
|
2019-05-28 16:59:38 +00:00
|
|
|
$sitename_in_title = $config->get_int("sitename_in_title");
|
2019-08-07 19:53:59 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
// if feature is enabled & sitename isn't already in title
|
|
|
|
// (can occur on index & other pages)
|
|
|
|
if ($sitename_in_title != 0 && !strstr($page->title, $site_title)) {
|
|
|
|
if ($sitename_in_title == 1) {
|
|
|
|
$page->title = "$site_title - $page->title";
|
|
|
|
} // as prefix
|
|
|
|
elseif ($sitename_in_title == 2) {
|
|
|
|
$page->title = "$page->title - $site_title";
|
|
|
|
} // as suffix
|
2013-03-10 07:24:15 +00:00
|
|
|
}
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2013-03-10 07:24:15 +00:00
|
|
|
}
|