From 59227b16256871c6759bb74bc0b80ce18d5824a0 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 9 Sep 2024 08:40:35 +0100 Subject: [PATCH] [themes] only apply grid layout to pages generated using the default Page::body_html, fixes #1272 --- core/page.php | 33 ++++++++++++++++++++------------- ext/ext_manager/theme.php | 2 +- ext/home/main.php | 4 +--- ext/home/theme.php | 13 +++++++++---- themes/danbooru/page.class.php | 5 +++-- themes/danbooru2/page.class.php | 5 +++-- themes/default/style.css | 8 +++++--- themes/futaba/page.class.php | 5 +++-- themes/lite/page.class.php | 5 +++-- themes/warm/page.class.php | 5 +++-- 10 files changed, 51 insertions(+), 34 deletions(-) diff --git a/core/page.php b/core/page.php index ba1bbba5d..cb3d639a0 100644 --- a/core/page.php +++ b/core/page.php @@ -572,34 +572,40 @@ public function render(): void ); } - public function html_html(HTMLElement $head, string|HTMLElement $body): HTMLElement + public function html_html(HTMLElement $head, HTMLElement $body): HTMLElement { - global $user; - - $body_attrs = [ - "data-userclass" => $user->class->name, - "data-base-href" => get_base_href(), - "data-base-link" => make_link(""), - ]; - return emptyHTML( rawHTML(""), HTML( ["lang" => "en"], - HEAD($head), - BODY($body_attrs, $body) + $head, + $body, ) ); } protected function head_html(): HTMLElement { - return emptyHTML( + return HEAD( TITLE($this->title), $this->get_all_html_headers(), ); } + /** + * @return array + */ + public function body_attrs(string $class): array + { + global $user; + return [ + "class" => $class, + "data-userclass" => $user->class->name, + "data-base-href" => get_base_href(), + "data-base-link" => make_link(""), + ]; + } + protected function body_html(): HTMLElement { $left_block_html = []; @@ -625,7 +631,8 @@ protected function body_html(): HTMLElement $footer_html = $this->footer_html(); $flash_html = $this->flash_html(); - return emptyHTML( + return BODY( + $this->body_attrs("grid"), HTML_HEADER( H1($this->heading), ...$sub_block_html diff --git a/ext/ext_manager/theme.php b/ext/ext_manager/theme.php index fff770f7c..3dcfff171 100644 --- a/ext/ext_manager/theme.php +++ b/ext/ext_manager/theme.php @@ -115,7 +115,7 @@ public function display_table(Page $page, array $extensions, bool $editable): vo $cat_html = [ A(["href" => make_link()], "Index"), - BR(), + " ", ]; foreach ($categories as $cat) { $cat_html[] = A(["href" => "#".$cat->value], $cat->value); diff --git a/ext/home/main.php b/ext/home/main.php index 0208eee50..c6395e510 100644 --- a/ext/home/main.php +++ b/ext/home/main.php @@ -15,13 +15,11 @@ public function onPageRequest(PageRequestEvent $event): void { global $config, $page; if ($event->page_matches("home")) { - $base_href = get_base_href(); $sitename = $config->get_string(SetupConfig::TITLE); - $theme_name = $config->get_string(SetupConfig::THEME); $body = $this->get_body(); - $this->theme->display_page($page, $sitename, $base_href, $theme_name, $body); + $this->theme->display_page($page, $sitename, $body); } } diff --git a/ext/home/theme.php b/ext/home/theme.php index 3772c6bfd..a603dff57 100644 --- a/ext/home/theme.php +++ b/ext/home/theme.php @@ -6,11 +6,11 @@ use MicroHTML\HTMLElement; -use function MicroHTML\{emptyHTML, TITLE, META, rawHTML}; +use function MicroHTML\{BODY, emptyHTML, TITLE, META, rawHTML}; class HomeTheme extends Themelet { - public function display_page(Page $page, string $sitename, string $base_href, string $theme_name, HTMLElement $body): void + public function display_page(Page $page, string $sitename, HTMLElement $body): void { $page->set_mode(PageMode::DATA); $page->add_auto_html_headers(); @@ -28,6 +28,8 @@ public function display_page(Page $page, string $sitename, string $base_href, st public function build_body(string $sitename, string $main_links, string $main_text, string $contact_link, string $num_comma, string $counter_text): HTMLElement { + global $page; + $main_links_html = empty($main_links) ? "" : ""; $message_html = empty($main_text) ? "" : "
$main_text
"; $counter_html = empty($counter_text) ? "" : "
$counter_text
"; @@ -41,7 +43,9 @@ public function build_body(string $sitename, string $main_links, string $main_te "; - return rawHTML(" + return BODY( + $page->body_attrs("home"), + rawHTML("

$sitename

$main_links_html @@ -54,6 +58,7 @@ public function build_body(string $sitename, string $main_links, string $main_te Running Shimmie2
- "); + ") + ); } } diff --git a/themes/danbooru/page.class.php b/themes/danbooru/page.class.php index 42d461e3b..e1c9a23e6 100644 --- a/themes/danbooru/page.class.php +++ b/themes/danbooru/page.class.php @@ -6,7 +6,7 @@ use MicroHTML\HTMLElement; -use function MicroHTML\{DIV, LI, A, rawHTML, emptyHTML, UL, ARTICLE, FOOTER, EM, HEADER, H1, NAV}; +use function MicroHTML\{BODY, DIV, LI, A, rawHTML, emptyHTML, UL, ARTICLE, FOOTER, EM, HEADER, H1, NAV}; /** * Name: Danbooru Theme @@ -121,7 +121,8 @@ public function body_html(): HTMLElement $flash_html = $this->flash_html(); $footer_html = $this->footer_html(); - return emptyHTML( + return BODY( + $this->body_attrs("grid"), HEADER( $title_link, UL(["id" => "navbar", "class" => "flat-list"], $custom_links), diff --git a/themes/danbooru2/page.class.php b/themes/danbooru2/page.class.php index e191acae5..191284b00 100644 --- a/themes/danbooru2/page.class.php +++ b/themes/danbooru2/page.class.php @@ -6,7 +6,7 @@ use MicroHTML\HTMLElement; -use function MicroHTML\{DIV, LI, A, rawHTML, emptyHTML, UL, ARTICLE, FOOTER, EM, HEADER, H1, NAV}; +use function MicroHTML\{BODY, DIV, LI, A, rawHTML, emptyHTML, UL, ARTICLE, FOOTER, EM, HEADER, H1, NAV}; /** * Name: Danbooru 2 Theme @@ -122,7 +122,8 @@ public function body_html(): HTMLElement $flash_html = $this->flash_html(); $footer_html = $this->footer_html(); - return emptyHTML( + return BODY( + $this->body_attrs("grid"), HEADER( $title_link, UL(["id" => "navbar", "class" => "flat-list"], $custom_links), diff --git a/themes/default/style.css b/themes/default/style.css index 88005e397..0efa51fa7 100644 --- a/themes/default/style.css +++ b/themes/default/style.css @@ -61,13 +61,15 @@ HEADER H1 { overflow: hidden; } BODY { - display: grid; - grid-template-columns: 216px auto; - grid-gap: 0 10px; background: var(--page); color: var(--text); margin: 0; } +BODY.grid { + display: grid; + grid-template-columns: 216px auto; + grid-gap: 0 10px; +} H1 { background: var(--title); border: 1px solid var(--title-border); diff --git a/themes/futaba/page.class.php b/themes/futaba/page.class.php index 488bc629f..4d623bc38 100644 --- a/themes/futaba/page.class.php +++ b/themes/futaba/page.class.php @@ -6,7 +6,7 @@ use MicroHTML\HTMLElement; -use function MicroHTML\{DIV, LI, A, rawHTML, emptyHTML, UL, ARTICLE, FOOTER, HR, HEADER, H1, NAV}; +use function MicroHTML\{BODY, DIV, LI, A, rawHTML, emptyHTML, UL, ARTICLE, FOOTER, HR, HEADER, H1, NAV}; class FutabaPage extends Page { @@ -48,7 +48,8 @@ public function body_html(): HTMLElement $flash_html = $this->flash_html(); $footer_html = $this->footer_html(); - return emptyHTML( + return BODY( + $this->body_attrs("grid"), HEADER( H1($this->heading), $subheading, diff --git a/themes/lite/page.class.php b/themes/lite/page.class.php index 60b8e5410..166af7bfa 100644 --- a/themes/lite/page.class.php +++ b/themes/lite/page.class.php @@ -6,7 +6,7 @@ use MicroHTML\HTMLElement; -use function MicroHTML\{emptyHTML, HEADER, FOOTER, DIV, SCRIPT, A, B, IMG, NAV, ARTICLE, rawHTML, SECTION}; +use function MicroHTML\{BODY, emptyHTML, HEADER, FOOTER, DIV, SCRIPT, A, B, IMG, NAV, ARTICLE, rawHTML, SECTION}; /** * Name: Lite Theme @@ -94,7 +94,8 @@ public function body_html(): HTMLElement $footer_html = $this->footer_html(); - return emptyHTML( + return BODY( + $this->body_attrs("grid"), HEADER( $menu, $custom_sublinks, diff --git a/themes/warm/page.class.php b/themes/warm/page.class.php index 8e921065b..0083ce15f 100644 --- a/themes/warm/page.class.php +++ b/themes/warm/page.class.php @@ -6,7 +6,7 @@ use MicroHTML\HTMLElement; -use function MicroHTML\{A, TABLE, TR, TD, SMALL, rawHTML, emptyHTML, DIV, ARTICLE, FOOTER, HEADER, H1, NAV}; +use function MicroHTML\{BODY, A, TABLE, TR, TD, SMALL, rawHTML, emptyHTML, DIV, ARTICLE, FOOTER, HEADER, H1, NAV}; class WarmPage extends Page { @@ -46,7 +46,8 @@ public function body_html(): HTMLElement $flash_html = $this->flash_html(); $footer_html = $this->footer_html(); - return emptyHTML( + return BODY( + $this->body_attrs("grid"), HEADER( DIV( ["style" => "text-align: center;"],