microhtml for everything in <head>
I wanted to ensure that all pages (even the downtime page, terms page, home page, etc) had the appropriate `data-` attributes on `<body>` (because those are required for certain javascript, eg autocomplete, to work). One thing led to another and now everything in `head` is microhtml'ed
This commit is contained in:
parent
839b4b51e8
commit
f84bcaec01
23 changed files with 229 additions and 160 deletions
|
@ -6,7 +6,7 @@ namespace Shimmie2;
|
||||||
|
|
||||||
use MicroHTML\HTMLElement;
|
use MicroHTML\HTMLElement;
|
||||||
|
|
||||||
use function MicroHTML\{emptyHTML,rawHTML,HTML,HEAD,BODY};
|
use function MicroHTML\{emptyHTML,rawHTML,HTML,HEAD,BODY,TITLE, LINK, SCRIPT};
|
||||||
|
|
||||||
require_once "core/event.php";
|
require_once "core/event.php";
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ class BasePage
|
||||||
public string $subheading = "";
|
public string $subheading = "";
|
||||||
public bool $left_enabled = true;
|
public bool $left_enabled = true;
|
||||||
|
|
||||||
/** @var string[] */
|
/** @var HTMLElement[] */
|
||||||
public array $html_headers = [];
|
public array $html_headers = [];
|
||||||
|
|
||||||
/** @var string[] */
|
/** @var string[] */
|
||||||
|
@ -179,17 +179,6 @@ class BasePage
|
||||||
$this->left_enabled = false;
|
$this->left_enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a line to the HTML head section.
|
|
||||||
*/
|
|
||||||
public function add_html_header(string $line, int $position = 50): void
|
|
||||||
{
|
|
||||||
while (isset($this->html_headers[$position])) {
|
|
||||||
$position++;
|
|
||||||
}
|
|
||||||
$this->html_headers[$position] = $line;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a http header to be sent to the client.
|
* Add a http header to be sent to the client.
|
||||||
*/
|
*/
|
||||||
|
@ -222,17 +211,26 @@ class BasePage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a line to the HTML head section.
|
||||||
|
*/
|
||||||
|
public function add_html_header(HTMLElement $line, int $position = 50): void
|
||||||
|
{
|
||||||
|
while (isset($this->html_headers[$position])) {
|
||||||
|
$position++;
|
||||||
|
}
|
||||||
|
$this->html_headers[$position] = $line;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all the HTML headers that are currently set and return as a string.
|
* Get all the HTML headers that are currently set and return as a string.
|
||||||
*/
|
*/
|
||||||
public function get_all_html_headers(): string
|
public function get_all_html_headers(): HTMLElement
|
||||||
{
|
{
|
||||||
$data = '';
|
|
||||||
ksort($this->html_headers);
|
ksort($this->html_headers);
|
||||||
foreach ($this->html_headers as $line) {
|
return emptyHTML(
|
||||||
$data .= "\t\t" . $line . "\n";
|
...$this->html_headers
|
||||||
}
|
);
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -384,8 +382,15 @@ class BasePage
|
||||||
$theme_name = $config->get_string(SetupConfig::THEME, 'default');
|
$theme_name = $config->get_string(SetupConfig::THEME, 'default');
|
||||||
|
|
||||||
# static handler will map these to themes/foo/static/bar.ico or ext/static_files/static/bar.ico
|
# static handler will map these to themes/foo/static/bar.ico or ext/static_files/static/bar.ico
|
||||||
$this->add_html_header("<link rel='icon' type='image/x-icon' href='$data_href/favicon.ico'>", 41);
|
$this->add_html_header(LINK([
|
||||||
$this->add_html_header("<link rel='apple-touch-icon' href='$data_href/apple-touch-icon.png'>", 42);
|
'rel' => 'icon',
|
||||||
|
'type' => 'image/x-icon',
|
||||||
|
'href' => "$data_href/favicon.ico"
|
||||||
|
]), 41);
|
||||||
|
$this->add_html_header(LINK([
|
||||||
|
'rel' => 'apple-touch-icon',
|
||||||
|
'href' => "$data_href/apple-touch-icon.png"
|
||||||
|
]), 42);
|
||||||
|
|
||||||
//We use $config_latest to make sure cache is reset if config is ever updated.
|
//We use $config_latest to make sure cache is reset if config is ever updated.
|
||||||
$config_latest = 0;
|
$config_latest = 0;
|
||||||
|
@ -394,13 +399,24 @@ class BasePage
|
||||||
}
|
}
|
||||||
|
|
||||||
$css_cache_file = $this->get_css_cache_file($theme_name, $config_latest);
|
$css_cache_file = $this->get_css_cache_file($theme_name, $config_latest);
|
||||||
$this->add_html_header("<link rel='stylesheet' href='$data_href/$css_cache_file' type='text/css'>", 43);
|
$this->add_html_header(LINK([
|
||||||
|
'rel' => 'stylesheet',
|
||||||
|
'href' => "$data_href/$css_cache_file",
|
||||||
|
'type' => 'text/css'
|
||||||
|
]), 43);
|
||||||
|
|
||||||
$initjs_cache_file = $this->get_initjs_cache_file($theme_name, $config_latest);
|
$initjs_cache_file = $this->get_initjs_cache_file($theme_name, $config_latest);
|
||||||
$this->add_html_header("<script src='$data_href/$initjs_cache_file' type='text/javascript'></script>", 44);
|
$this->add_html_header(SCRIPT([
|
||||||
|
'src' => "$data_href/$initjs_cache_file",
|
||||||
|
'type' => 'text/javascript'
|
||||||
|
]));
|
||||||
|
|
||||||
$js_cache_file = $this->get_js_cache_file($theme_name, $config_latest);
|
$js_cache_file = $this->get_js_cache_file($theme_name, $config_latest);
|
||||||
$this->add_html_header("<script defer src='$data_href/$js_cache_file' type='text/javascript'></script>", 44);
|
$this->add_html_header(SCRIPT([
|
||||||
|
'defer' => true,
|
||||||
|
'src' => "$data_href/$js_cache_file",
|
||||||
|
'type' => 'text/javascript'
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_css_cache_file(string $theme_name, int $config_latest): string
|
private function get_css_cache_file(string $theme_name, int $config_latest): string
|
||||||
|
@ -549,10 +565,15 @@ class BasePage
|
||||||
*/
|
*/
|
||||||
public function render(): void
|
public function render(): void
|
||||||
{
|
{
|
||||||
global $config, $user;
|
print (string)$this->html_html(
|
||||||
|
$this->head_html(),
|
||||||
|
$this->body_html()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$head = $this->head_html();
|
public function html_html(HTMLElement $head, string|HTMLElement $body): HTMLElement
|
||||||
$body = $this->body_html();
|
{
|
||||||
|
global $user;
|
||||||
|
|
||||||
$body_attrs = [
|
$body_attrs = [
|
||||||
"data-userclass" => $user->class->name,
|
"data-userclass" => $user->class->name,
|
||||||
|
@ -560,24 +581,22 @@ class BasePage
|
||||||
"data-base-link" => make_link(""),
|
"data-base-link" => make_link(""),
|
||||||
];
|
];
|
||||||
|
|
||||||
print emptyHTML(
|
return emptyHTML(
|
||||||
rawHTML("<!doctype html>"),
|
rawHTML("<!doctype html>"),
|
||||||
HTML(
|
HTML(
|
||||||
["lang" => "en"],
|
["lang" => "en"],
|
||||||
HEAD(rawHTML($head)),
|
HEAD($head),
|
||||||
BODY($body_attrs, rawHTML($body))
|
BODY($body_attrs, rawHTML((string)$body))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function head_html(): string
|
protected function head_html(): HTMLElement
|
||||||
{
|
{
|
||||||
$html_header_html = $this->get_all_html_headers();
|
return emptyHTML(
|
||||||
|
TITLE($this->title),
|
||||||
return "
|
$this->get_all_html_headers(),
|
||||||
<title>{$this->title}</title>
|
);
|
||||||
$html_header_html
|
|
||||||
";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function body_html(): string
|
protected function body_html(): string
|
||||||
|
|
|
@ -6,7 +6,7 @@ namespace Shimmie2;
|
||||||
|
|
||||||
use MicroHTML\HTMLElement;
|
use MicroHTML\HTMLElement;
|
||||||
|
|
||||||
use function MicroHTML\{A,B,BR,IMG,emptyHTML,joinHTML};
|
use function MicroHTML\{A,B,BR,IMG,emptyHTML,joinHTML,LINK};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BaseThemelet
|
* Class BaseThemelet
|
||||||
|
@ -112,15 +112,15 @@ class BaseThemelet
|
||||||
$body = $this->build_paginator($page_number, $total_pages, $base, $query, $show_random);
|
$body = $this->build_paginator($page_number, $total_pages, $base, $query, $show_random);
|
||||||
$page->add_block(new Block(null, $body, "main", 90, "paginator"));
|
$page->add_block(new Block(null, $body, "main", 90, "paginator"));
|
||||||
|
|
||||||
$page->add_html_header("<link rel='first' href='".make_http(make_link($base.'/1', $query))."'>");
|
$page->add_html_header(LINK(['rel' => 'first', 'href' => make_link($base.'/1', $query)]));
|
||||||
if ($page_number < $total_pages) {
|
if ($page_number < $total_pages) {
|
||||||
$page->add_html_header("<link rel='prefetch' href='".make_http(make_link($base.'/'.($page_number + 1), $query))."'>");
|
$page->add_html_header(LINK(['rel' => 'prefetch', 'href' => make_link($base.'/'.($page_number + 1), $query)]));
|
||||||
$page->add_html_header("<link rel='next' href='".make_http(make_link($base.'/'.($page_number + 1), $query))."'>");
|
$page->add_html_header(LINK(['rel' => 'next', 'href' => make_link($base.'/'.($page_number + 1), $query)]));
|
||||||
}
|
}
|
||||||
if ($page_number > 1) {
|
if ($page_number > 1) {
|
||||||
$page->add_html_header("<link rel='previous' href='".make_http(make_link($base.'/'.($page_number - 1), $query))."'>");
|
$page->add_html_header(LINK(['rel' => 'previous', 'href' => make_link($base.'/'.($page_number - 1), $query)]));
|
||||||
}
|
}
|
||||||
$page->add_html_header("<link rel='last' href='".make_http(make_link($base.'/'.$total_pages, $query))."'>");
|
$page->add_html_header(LINK(['rel' => 'last', 'href' => make_link($base.'/'.$total_pages, $query)]));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function gen_page_link(string $base_url, ?string $query, int $page, string $name): HTMLElement
|
private function gen_page_link(string $base_url, ?string $query, int $page, string $name): HTMLElement
|
||||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shimmie2;
|
namespace Shimmie2;
|
||||||
|
|
||||||
|
use function MicroHTML\LINK;
|
||||||
|
|
||||||
class BrowserSearch extends Extension
|
class BrowserSearch extends Extension
|
||||||
{
|
{
|
||||||
public function onInitExt(InitExtEvent $event): void
|
public function onInitExt(InitExtEvent $event): void
|
||||||
|
@ -20,7 +22,12 @@ class BrowserSearch extends Extension
|
||||||
// We need to build the data for the header
|
// We need to build the data for the header
|
||||||
$search_title = $config->get_string(SetupConfig::TITLE);
|
$search_title = $config->get_string(SetupConfig::TITLE);
|
||||||
$search_file_url = make_link('browser_search.xml');
|
$search_file_url = make_link('browser_search.xml');
|
||||||
$page->add_html_header("<link rel='search' type='application/opensearchdescription+xml' title='$search_title' href='$search_file_url'>");
|
$page->add_html_header(LINK([
|
||||||
|
'rel' => 'search',
|
||||||
|
'type' => 'application/opensearchdescription+xml',
|
||||||
|
'title' => $search_title,
|
||||||
|
'href' => $search_file_url
|
||||||
|
]));
|
||||||
|
|
||||||
// The search.xml file that is generated on the fly
|
// The search.xml file that is generated on the fly
|
||||||
if ($event->page_matches("browser_search.xml")) {
|
if ($event->page_matches("browser_search.xml")) {
|
||||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shimmie2;
|
namespace Shimmie2;
|
||||||
|
|
||||||
|
use function MicroHTML\rawHTML;
|
||||||
|
|
||||||
class CustomHtmlHeaders extends Extension
|
class CustomHtmlHeaders extends Extension
|
||||||
{
|
{
|
||||||
# Adds setup block for custom <head> content
|
# Adds setup block for custom <head> content
|
||||||
|
@ -44,7 +46,7 @@ class CustomHtmlHeaders extends Extension
|
||||||
|
|
||||||
$header = $config->get_string('custom_html_headers', '');
|
$header = $config->get_string('custom_html_headers', '');
|
||||||
if ($header != '') {
|
if ($header != '') {
|
||||||
$page->add_html_header($header);
|
$page->add_html_header(rawHTML($header));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shimmie2;
|
namespace Shimmie2;
|
||||||
|
|
||||||
|
use function MicroHTML\{emptyHTML, TITLE, LINK};
|
||||||
|
|
||||||
class DowntimeTheme extends Themelet
|
class DowntimeTheme extends Themelet
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -30,16 +32,11 @@ class DowntimeTheme extends Themelet
|
||||||
$login_link = make_link("user_admin/login");
|
$login_link = make_link("user_admin/login");
|
||||||
$form = make_form($login_link);
|
$form = make_form($login_link);
|
||||||
|
|
||||||
$page->set_mode(PageMode::DATA);
|
$head = emptyHTML(
|
||||||
$page->set_code(503);
|
TITLE("Downtime"),
|
||||||
$page->set_data(
|
LINK(["rel" => "stylesheet", "href" => "$data_href/themes/$theme_name/style.css", "type" => "text/css"])
|
||||||
<<<EOD
|
);
|
||||||
<html lang="en">
|
$body = <<<EOD
|
||||||
<head>
|
|
||||||
<title>Downtime</title>
|
|
||||||
<link rel="stylesheet" href="$data_href/themes/$theme_name/style.css" type="text/css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="downtime">
|
<div id="downtime">
|
||||||
<section>
|
<section>
|
||||||
<h1 style="text-align: center;">Down for Maintenance</h1>
|
<h1 style="text-align: center;">Down for Maintenance</h1>
|
||||||
|
@ -66,9 +63,9 @@ class DowntimeTheme extends Themelet
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
EOD;
|
||||||
</html>
|
$page->set_mode(PageMode::DATA);
|
||||||
EOD
|
$page->set_code(503);
|
||||||
);
|
$page->set_data((string)$page->html_html($head, $body));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shimmie2;
|
namespace Shimmie2;
|
||||||
|
|
||||||
|
use function MicroHTML\TITLE;
|
||||||
|
|
||||||
class EmoticonListTheme extends Themelet
|
class EmoticonListTheme extends Themelet
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -13,19 +15,21 @@ class EmoticonListTheme extends Themelet
|
||||||
{
|
{
|
||||||
global $page;
|
global $page;
|
||||||
$data_href = get_base_href();
|
$data_href = get_base_href();
|
||||||
$html = "<html lang='en'><head><title>Emoticon list</title></head><body>";
|
$body = "<table><tr>";
|
||||||
$html .= "<table><tr>";
|
|
||||||
$n = 1;
|
$n = 1;
|
||||||
foreach ($list as $item) {
|
foreach ($list as $item) {
|
||||||
$name = pathinfo($item, PATHINFO_FILENAME);
|
$name = pathinfo($item, PATHINFO_FILENAME);
|
||||||
$html .= "<td><img alt='$name' src='$data_href/$item'> :$name:</td>";
|
$body .= "<td><img alt='$name' src='$data_href/$item'> :$name:</td>";
|
||||||
if ($n++ % 3 == 0) {
|
if ($n++ % 3 == 0) {
|
||||||
$html .= "</tr><tr>";
|
$body .= "</tr><tr>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$html .= "</tr></table>";
|
$body .= "</tr></table>";
|
||||||
$html .= "</body></html>";
|
|
||||||
$page->set_mode(PageMode::DATA);
|
$page->set_mode(PageMode::DATA);
|
||||||
$page->set_data($html);
|
$page->set_data((string)$page->html_html(
|
||||||
|
TITLE("Emoticon list"),
|
||||||
|
$body
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shimmie2;
|
namespace Shimmie2;
|
||||||
|
|
||||||
|
use function MicroHTML\SCRIPT;
|
||||||
|
|
||||||
class Filter extends Extension
|
class Filter extends Extension
|
||||||
{
|
{
|
||||||
/** @var FilterTheme */
|
/** @var FilterTheme */
|
||||||
|
@ -19,10 +21,10 @@ class Filter extends Extension
|
||||||
{
|
{
|
||||||
global $page;
|
global $page;
|
||||||
$this->theme->addFilterBox();
|
$this->theme->addFilterBox();
|
||||||
$page->add_html_header("<script>
|
$page->add_html_header(SCRIPT("
|
||||||
Array.from(document.getElementsByClassName('thumb')).forEach(function(post) {
|
Array.from(document.getElementsByClassName('thumb')).forEach(function(post) {
|
||||||
post.style.display='none';
|
post.style.display='none';
|
||||||
});</script>");
|
});"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onSetupBuilding(SetupBuildingEvent $event): void
|
public function onSetupBuilding(SetupBuildingEvent $event): void
|
||||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shimmie2;
|
namespace Shimmie2;
|
||||||
|
|
||||||
|
use function MicroHTML\{META};
|
||||||
|
|
||||||
class FilterTheme extends Themelet
|
class FilterTheme extends Themelet
|
||||||
{
|
{
|
||||||
public function addFilterBox(): void
|
public function addFilterBox(): void
|
||||||
|
@ -21,7 +23,7 @@ class FilterTheme extends Themelet
|
||||||
<a id='disable-all-filters' style='display: none;' href='#'>Disable all</a>
|
<a id='disable-all-filters' style='display: none;' href='#'>Disable all</a>
|
||||||
<a id='re-enable-all-filters' style='display: none;' href='#'>Re-enable all</a>
|
<a id='re-enable-all-filters' style='display: none;' href='#'>Re-enable all</a>
|
||||||
";
|
";
|
||||||
$page->add_html_header("<meta id='filter-tags' tags='$tags'>");
|
$page->add_html_header(META(['id' => 'filter-tags', 'tags' => $tags]));
|
||||||
$page->add_block(new Block("Filters", $html, "left", 10));
|
$page->add_block(new Block("Filters", $html, "left", 10));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shimmie2;
|
namespace Shimmie2;
|
||||||
|
|
||||||
|
use function MicroHTML\SCRIPT;
|
||||||
|
|
||||||
class GoogleAnalytics extends Extension
|
class GoogleAnalytics extends Extension
|
||||||
{
|
{
|
||||||
# Add analytics to config
|
# Add analytics to config
|
||||||
|
@ -21,7 +23,7 @@ class GoogleAnalytics extends Extension
|
||||||
|
|
||||||
$google_analytics_id = $config->get_string('google_analytics_id', '');
|
$google_analytics_id = $config->get_string('google_analytics_id', '');
|
||||||
if (stristr($google_analytics_id, "UA-")) {
|
if (stristr($google_analytics_id, "UA-")) {
|
||||||
$page->add_html_header("<script type='text/javascript'>
|
$page->add_html_header(SCRIPT(["type" => 'text/javascript'], "
|
||||||
var _gaq = _gaq || [];
|
var _gaq = _gaq || [];
|
||||||
_gaq.push(['_setAccount', '$google_analytics_id']);
|
_gaq.push(['_setAccount', '$google_analytics_id']);
|
||||||
_gaq.push(['_trackPageview']);
|
_gaq.push(['_trackPageview']);
|
||||||
|
@ -29,7 +31,8 @@ class GoogleAnalytics extends Extension
|
||||||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
||||||
ga.src = ('https:' === document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
ga.src = ('https:' === document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
||||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
||||||
})();</script>");
|
})();
|
||||||
|
"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shimmie2;
|
namespace Shimmie2;
|
||||||
|
|
||||||
|
use function MicroHTML\{SCRIPT};
|
||||||
|
|
||||||
class MP3FileHandlerTheme extends Themelet
|
class MP3FileHandlerTheme extends Themelet
|
||||||
{
|
{
|
||||||
public function display_image(Image $image): void
|
public function display_image(Image $image): void
|
||||||
|
@ -20,7 +22,10 @@ class MP3FileHandlerTheme extends Themelet
|
||||||
|
|
||||||
<p><a href='$ilink' id='audio-download'>Download</a>";
|
<p><a href='$ilink' id='audio-download'>Download</a>";
|
||||||
|
|
||||||
$page->add_html_header("<script src='{$data_href}/ext/handle_mp3/lib/jsmediatags.min.js' type='text/javascript'></script>");
|
$page->add_html_header(SCRIPT([
|
||||||
|
'src' => "$data_href/ext/handle_mp3/lib/jsmediatags.min.js",
|
||||||
|
'type' => 'text/javascript'
|
||||||
|
]));
|
||||||
$page->add_block(new Block("Music", $html, "main", 10));
|
$page->add_block(new Block("Music", $html, "main", 10));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shimmie2;
|
namespace Shimmie2;
|
||||||
|
|
||||||
|
use function MicroHTML\LINK;
|
||||||
|
|
||||||
class Holiday extends Extension
|
class Holiday extends Extension
|
||||||
{
|
{
|
||||||
public function onInitExt(InitExtEvent $event): void
|
public function onInitExt(InitExtEvent $event): void
|
||||||
|
@ -22,9 +24,11 @@ class Holiday extends Extension
|
||||||
{
|
{
|
||||||
global $config, $page;
|
global $config, $page;
|
||||||
if (date('d/m') == '01/04' && $config->get_bool("holiday_aprilfools")) {
|
if (date('d/m') == '01/04' && $config->get_bool("holiday_aprilfools")) {
|
||||||
$page->add_html_header(
|
$page->add_html_header(LINK([
|
||||||
"<link rel='stylesheet' href='".get_base_href()."/ext/holiday/stylesheets/aprilfools.css' type='text/css'>"
|
'rel' => 'stylesheet',
|
||||||
);
|
'href' => get_base_href() . '/ext/holiday/stylesheets/aprilfools.css',
|
||||||
|
'type' => 'text/css'
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,29 +4,24 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shimmie2;
|
namespace Shimmie2;
|
||||||
|
|
||||||
|
use function MicroHTML\{emptyHTML, TITLE, META, rawHTML};
|
||||||
|
|
||||||
class HomeTheme extends Themelet
|
class HomeTheme extends Themelet
|
||||||
{
|
{
|
||||||
public function display_page(Page $page, string $sitename, string $base_href, string $theme_name, string $body): void
|
public function display_page(Page $page, string $sitename, string $base_href, string $theme_name, string $body): void
|
||||||
{
|
{
|
||||||
$page->set_mode(PageMode::DATA);
|
$page->set_mode(PageMode::DATA);
|
||||||
$page->add_auto_html_headers();
|
$page->add_auto_html_headers();
|
||||||
$hh = $page->get_all_html_headers();
|
|
||||||
$page->set_data(
|
$page->set_data((string)$page->html_html(
|
||||||
<<<EOD
|
emptyHTML(
|
||||||
<!doctype html>
|
TITLE($sitename),
|
||||||
<html lang="en">
|
META(["http-equiv" => "Content-Type", "content" => "text/html;charset=utf-8"]),
|
||||||
<head>
|
META(["name" => "viewport", "content" => "width=device-width, initial-scale=1"]),
|
||||||
<title>$sitename</title>
|
$page->get_all_html_headers(),
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
),
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
$hh
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
$body
|
$body
|
||||||
</body>
|
));
|
||||||
</html>
|
|
||||||
EOD
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function build_body(string $sitename, string $main_links, string $main_text, string $contact_link, string $num_comma, string $counter_text): string
|
public function build_body(string $sitename, string $main_links, string $main_text, string $contact_link, string $num_comma, string $counter_text): string
|
||||||
|
|
|
@ -8,7 +8,7 @@ use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\{InputInterface,InputArgument};
|
use Symfony\Component\Console\Input\{InputInterface,InputArgument};
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
use function MicroHTML\{INPUT, emptyHTML};
|
use function MicroHTML\{INPUT, emptyHTML, STYLE};
|
||||||
|
|
||||||
require_once "config.php";
|
require_once "config.php";
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ class ImageIO extends Extension
|
||||||
|
|
||||||
$thumb_width = $config->get_int(ImageConfig::THUMB_WIDTH, 192);
|
$thumb_width = $config->get_int(ImageConfig::THUMB_WIDTH, 192);
|
||||||
$thumb_height = $config->get_int(ImageConfig::THUMB_HEIGHT, 192);
|
$thumb_height = $config->get_int(ImageConfig::THUMB_HEIGHT, 192);
|
||||||
$page->add_html_header("<style>:root {--thumb-width: {$thumb_width}px; --thumb-height: {$thumb_height}px;}</style>");
|
$page->add_html_header(STYLE(":root {--thumb-width: {$thumb_width}px; --thumb-height: {$thumb_height}px;}"));
|
||||||
|
|
||||||
if ($event->page_matches("image/delete", method: "POST", permission: Permissions::DELETE_IMAGE)) {
|
if ($event->page_matches("image/delete", method: "POST", permission: Permissions::DELETE_IMAGE)) {
|
||||||
global $page, $user;
|
global $page, $user;
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace Shimmie2;
|
||||||
use MicroHTML\HTMLElement;
|
use MicroHTML\HTMLElement;
|
||||||
|
|
||||||
use function MicroHTML\emptyHTML;
|
use function MicroHTML\emptyHTML;
|
||||||
use function MicroHTML\{BR,H3,HR,P};
|
use function MicroHTML\{BR,H3,HR,P,META};
|
||||||
|
|
||||||
class IndexTheme extends Themelet
|
class IndexTheme extends Themelet
|
||||||
{
|
{
|
||||||
|
@ -176,7 +176,7 @@ and of course start organising your images :-)
|
||||||
if (count($this->search_terms) > 0) {
|
if (count($this->search_terms) > 0) {
|
||||||
if ($this->page_number > 3) {
|
if ($this->page_number > 3) {
|
||||||
// only index the first pages of each term
|
// only index the first pages of each term
|
||||||
$page->add_html_header('<meta name="robots" content="noindex, nofollow">');
|
$page->add_html_header(META(["name" => "robots", "content" => "noindex, nofollow"]));
|
||||||
}
|
}
|
||||||
$query = url_escape(Tag::implode($this->search_terms));
|
$query = url_escape(Tag::implode($this->search_terms));
|
||||||
$page->add_block(new Block("Posts", $this->build_table($images, "#search=$query"), "main", 10, "image-list"));
|
$page->add_block(new Block("Posts", $this->build_table($images, "#search=$query"), "main", 10, "image-list"));
|
||||||
|
|
|
@ -6,7 +6,7 @@ namespace Shimmie2;
|
||||||
|
|
||||||
use MicroHTML\HTMLElement;
|
use MicroHTML\HTMLElement;
|
||||||
|
|
||||||
use function MicroHTML\INPUT;
|
use function MicroHTML\{INPUT,SCRIPT};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @phpstan-type NoteHistory array{image_id:int,note_id:int,review_id:int,user_name:string,note:string,date:string}
|
* @phpstan-type NoteHistory array{image_id:int,note_id:int,review_id:int,user_name:string,note:string,date:string}
|
||||||
|
@ -61,12 +61,15 @@ class NotesTheme extends Themelet
|
||||||
'note_id' => $note["id"],
|
'note_id' => $note["id"],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$page->add_html_header("<script type='text/javascript'>
|
$page->add_html_header(SCRIPT(
|
||||||
|
["type" => "text/javascript"],
|
||||||
|
"
|
||||||
window.notes = ".\Safe\json_encode($to_json).";
|
window.notes = ".\Safe\json_encode($to_json).";
|
||||||
window.notes_image_id = $image_id;
|
window.notes_image_id = $image_id;
|
||||||
window.notes_admin = ".($adminOptions ? "true" : "false").";
|
window.notes_admin = ".($adminOptions ? "true" : "false").";
|
||||||
window.notes_edit = ".($editOptions ? "true" : "false").";
|
window.notes_edit = ".($editOptions ? "true" : "false").";
|
||||||
</script>");
|
"
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shimmie2;
|
namespace Shimmie2;
|
||||||
|
|
||||||
use function MicroHTML\INPUT;
|
use function MicroHTML\META;
|
||||||
|
|
||||||
class RegenThumbTheme extends Themelet
|
class RegenThumbTheme extends Themelet
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,7 @@ class RegenThumbTheme extends Themelet
|
||||||
{
|
{
|
||||||
$page->set_title("Thumbnail Regenerated");
|
$page->set_title("Thumbnail Regenerated");
|
||||||
$page->set_heading("Thumbnail Regenerated");
|
$page->set_heading("Thumbnail Regenerated");
|
||||||
$page->add_html_header("<meta http-equiv=\"cache-control\" content=\"no-cache\">");
|
$page->add_html_header(META(['http-equiv' => 'cache-control', 'content' => 'no-cache']));
|
||||||
$page->add_block(new NavBlock());
|
$page->add_block(new NavBlock());
|
||||||
$page->add_block(new Block("Thumbnail", $this->build_thumb_html($image)));
|
$page->add_block(new Block("Thumbnail", $this->build_thumb_html($image)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shimmie2;
|
namespace Shimmie2;
|
||||||
|
|
||||||
|
use function MicroHTML\LINK;
|
||||||
|
|
||||||
class RSSComments extends Extension
|
class RSSComments extends Extension
|
||||||
{
|
{
|
||||||
public function onPostListBuilding(PostListBuildingEvent $event): void
|
public function onPostListBuilding(PostListBuildingEvent $event): void
|
||||||
|
@ -11,8 +13,12 @@ class RSSComments extends Extension
|
||||||
global $config, $page;
|
global $config, $page;
|
||||||
$title = $config->get_string(SetupConfig::TITLE);
|
$title = $config->get_string(SetupConfig::TITLE);
|
||||||
|
|
||||||
$page->add_html_header("<link rel=\"alternate\" type=\"application/rss+xml\" ".
|
$page->add_html_header(LINK([
|
||||||
"title=\"$title - Comments\" href=\"".make_link("rss/comments")."\" />");
|
'rel' => 'alternate',
|
||||||
|
'type' => 'application/rss+xml',
|
||||||
|
'title' => "$title - Comments",
|
||||||
|
'href' => make_link("rss/comments")
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onPageRequest(PageRequestEvent $event): void
|
public function onPageRequest(PageRequestEvent $event): void
|
||||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shimmie2;
|
namespace Shimmie2;
|
||||||
|
|
||||||
|
use function MicroHTML\{LINK};
|
||||||
|
|
||||||
class RSSImages extends Extension
|
class RSSImages extends Extension
|
||||||
{
|
{
|
||||||
public function onPostListBuilding(PostListBuildingEvent $event): void
|
public function onPostListBuilding(PostListBuildingEvent $event): void
|
||||||
|
@ -13,11 +15,19 @@ class RSSImages extends Extension
|
||||||
|
|
||||||
if (count($event->search_terms) > 0) {
|
if (count($event->search_terms) > 0) {
|
||||||
$search = url_escape(Tag::implode($event->search_terms));
|
$search = url_escape(Tag::implode($event->search_terms));
|
||||||
$page->add_html_header("<link id=\"images\" rel=\"alternate\" type=\"application/rss+xml\" ".
|
$page->add_html_header(LINK([
|
||||||
"title=\"$title - Posts with tags: $search\" href=\"".make_link("rss/images/$search/1")."\" />");
|
'rel' => 'alternate',
|
||||||
|
'type' => 'application/rss+xml',
|
||||||
|
'title' => "$title - Posts with tags: $search",
|
||||||
|
'href' => make_link("rss/images/$search/1")
|
||||||
|
]));
|
||||||
} else {
|
} else {
|
||||||
$page->add_html_header("<link id=\"images\" rel=\"alternate\" type=\"application/rss+xml\" ".
|
$page->add_html_header(LINK([
|
||||||
"title=\"$title - Posts\" href=\"".make_link("rss/images/1")."\" />");
|
'rel' => 'alternate',
|
||||||
|
'type' => 'application/rss+xml',
|
||||||
|
'title' => "$title - Posts",
|
||||||
|
'href' => make_link("rss/images/1")
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shimmie2;
|
namespace Shimmie2;
|
||||||
|
|
||||||
|
use function MicroHTML\{META};
|
||||||
|
|
||||||
class SiteDescription extends Extension
|
class SiteDescription extends Extension
|
||||||
{
|
{
|
||||||
public function onPageRequest(PageRequestEvent $event): void
|
public function onPageRequest(PageRequestEvent $event): void
|
||||||
|
@ -11,11 +13,17 @@ class SiteDescription extends Extension
|
||||||
global $config, $page;
|
global $config, $page;
|
||||||
if (!empty($config->get_string("site_description"))) {
|
if (!empty($config->get_string("site_description"))) {
|
||||||
$description = $config->get_string("site_description");
|
$description = $config->get_string("site_description");
|
||||||
$page->add_html_header("<meta name=\"description\" content=\"$description\">");
|
$page->add_html_header(META([
|
||||||
|
'name' => 'description',
|
||||||
|
'content' => $description
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
if (!empty($config->get_string("site_keywords"))) {
|
if (!empty($config->get_string("site_keywords"))) {
|
||||||
$keywords = $config->get_string("site_keywords");
|
$keywords = $config->get_string("site_keywords");
|
||||||
$page->add_html_header("<meta name=\"keywords\" content=\"$keywords\">");
|
$page->add_html_header(META([
|
||||||
|
'name' => 'keywords',
|
||||||
|
'content' => $keywords
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,8 @@ class SiteDescriptionTest extends ShimmiePHPUnitTestCase
|
||||||
$config->set_string("site_description", "A Shimmie testbed");
|
$config->set_string("site_description", "A Shimmie testbed");
|
||||||
$this->get_page("post/list");
|
$this->get_page("post/list");
|
||||||
$this->assertStringContainsString(
|
$this->assertStringContainsString(
|
||||||
'<meta name="description" content="A Shimmie testbed">',
|
"<meta name='description' content='A Shimmie testbed' />",
|
||||||
$page->get_all_html_headers()
|
(string)$page->get_all_html_headers()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ class SiteDescriptionTest extends ShimmiePHPUnitTestCase
|
||||||
$config->set_string("site_keywords", "foo,bar,baz");
|
$config->set_string("site_keywords", "foo,bar,baz");
|
||||||
$this->get_page("post/list");
|
$this->get_page("post/list");
|
||||||
$this->assertStringContainsString(
|
$this->assertStringContainsString(
|
||||||
'<meta name="keywords" content="foo,bar,baz">',
|
"<meta name='keywords' content='foo,bar,baz' />",
|
||||||
$page->get_all_html_headers()
|
(string)$page->get_all_html_headers()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shimmie2;
|
namespace Shimmie2;
|
||||||
|
|
||||||
|
use function MicroHTML\{emptyHTML, TITLE, META, rawHTML};
|
||||||
|
|
||||||
class TermsTheme extends Themelet
|
class TermsTheme extends Themelet
|
||||||
{
|
{
|
||||||
public function display_page(Page $page, string $sitename, string $path, string $body): void
|
public function display_page(Page $page, string $sitename, string $path, string $body): void
|
||||||
|
|
|
@ -18,7 +18,7 @@ use MicroCRUD\TextColumn;
|
||||||
use MicroCRUD\DateColumn;
|
use MicroCRUD\DateColumn;
|
||||||
use MicroCRUD\Table;
|
use MicroCRUD\Table;
|
||||||
|
|
||||||
use function MicroHTML\A;
|
use function MicroHTML\{A, STYLE};
|
||||||
|
|
||||||
class UserNameColumn extends TextColumn
|
class UserNameColumn extends TextColumn
|
||||||
{
|
{
|
||||||
|
@ -160,9 +160,9 @@ class UserPage extends Extension
|
||||||
$this->show_user_info();
|
$this->show_user_info();
|
||||||
|
|
||||||
if ($user->can(Permissions::VIEW_HELLBANNED)) {
|
if ($user->can(Permissions::VIEW_HELLBANNED)) {
|
||||||
$page->add_html_header("<style>DIV.hb, TR.hb TD {border: 1px solid red !important;}</style>");
|
$page->add_html_header(STYLE("DIV.hb, TR.hb TD {border: 1px solid red !important;}"));
|
||||||
} elseif (!$user->can(Permissions::HELLBANNED)) {
|
} elseif (!$user->can(Permissions::HELLBANNED)) {
|
||||||
$page->add_html_header("<style>.hb {display: none !important;}</style>");
|
$page->add_html_header(STYLE(".hb {display: none !important;}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($event->page_matches("user_admin/login", method: "GET")) {
|
if ($event->page_matches("user_admin/login", method: "GET")) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ namespace Shimmie2;
|
||||||
|
|
||||||
use MicroHTML\HTMLElement;
|
use MicroHTML\HTMLElement;
|
||||||
|
|
||||||
use function MicroHTML\{A, joinHTML, TABLE, TR, TD, INPUT, emptyHTML, DIV, BR};
|
use function MicroHTML\{A, joinHTML, TABLE, TR, TD, INPUT, emptyHTML, DIV, BR, META, LINK};
|
||||||
|
|
||||||
class ViewPostTheme extends Themelet
|
class ViewPostTheme extends Themelet
|
||||||
{
|
{
|
||||||
|
@ -14,12 +14,12 @@ class ViewPostTheme extends Themelet
|
||||||
{
|
{
|
||||||
global $page;
|
global $page;
|
||||||
|
|
||||||
$h_metatags = str_replace(" ", ", ", html_escape($image->get_tag_list()));
|
$h_metatags = str_replace(" ", ", ", $image->get_tag_list());
|
||||||
$page->add_html_header("<meta name=\"keywords\" content=\"$h_metatags\">");
|
$page->add_html_header(META(["name" => "keywords", "content" => $h_metatags]));
|
||||||
$page->add_html_header("<meta property=\"og:title\" content=\"$h_metatags\">");
|
$page->add_html_header(META(["property" => "og:title", "content" => $h_metatags]));
|
||||||
$page->add_html_header("<meta property=\"og:type\" content=\"article\">");
|
$page->add_html_header(META(["property" => "og:type", "content" => "article"]));
|
||||||
$page->add_html_header("<meta property=\"og:image\" content=\"".make_http($image->get_thumb_link())."\">");
|
$page->add_html_header(META(["property" => "og:image", "content" => make_http($image->get_thumb_link())]));
|
||||||
$page->add_html_header("<meta property=\"og:url\" content=\"".make_http(make_link("post/view/{$image->id}"))."\">");
|
$page->add_html_header(META(["property" => "og:url", "content" => make_http(make_link("post/view/{$image->id}"))]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,8 +38,8 @@ class ViewPostTheme extends Themelet
|
||||||
|
|
||||||
$query = $this->get_query();
|
$query = $this->get_query();
|
||||||
if(!$this->is_ordered_search()) {
|
if(!$this->is_ordered_search()) {
|
||||||
$page->add_html_header("<link id='nextlink' rel='next' href='".make_link("post/next/{$image->id}", $query)."'>");
|
$page->add_html_header(LINK(["id" => "nextlink", "rel" => "next", "href" => make_link("post/next/{$image->id}", $query)]));
|
||||||
$page->add_html_header("<link id='prevlink' rel='previous' href='".make_link("post/prev/{$image->id}", $query)."'>");
|
$page->add_html_header(LINK(["id" => "prevlink", "rel" => "previous", "href" => make_link("post/prev/{$image->id}", $query)]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue