[themes] have themes implement head_html/body_html rather than render

This commit is contained in:
Shish 2024-01-04 13:57:45 +00:00
parent 0c31a11f9b
commit 55d5dc0a35
8 changed files with 114 additions and 158 deletions

View file

@ -6,6 +6,8 @@ namespace Shimmie2;
use MicroHTML\HTMLElement; use MicroHTML\HTMLElement;
use function MicroHTML\{emptyHTML,rawHTML,HTML,HEAD,BODY};
require_once "core/event.php"; require_once "core/event.php";
enum PageMode: string enum PageMode: string
@ -530,16 +532,17 @@ class BasePage
*/ */
public function render() public function render()
{ {
$head_html = $this->head_html(); $head = $this->head_html();
$body_html = $this->body_html(); $body = $this->body_html();
print <<<EOD print emptyHTML(
<!doctype html> rawHTML("<!doctype html>"),
<html lang="en"> HTML(
$head_html ["lang" => "en"],
$body_html HEAD(rawHTML($head)),
</html> BODY(rawHTML($body))
EOD; )
);
} }
protected function head_html(): string protected function head_html(): string
@ -547,10 +550,8 @@ EOD;
$html_header_html = $this->get_all_html_headers(); $html_header_html = $this->get_all_html_headers();
return " return "
<head> <title>{$this->title}</title>
<title>{$this->title}</title> $html_header_html
$html_header_html
</head>
"; ";
} }
@ -585,22 +586,20 @@ EOD;
$footer_html = $this->footer_html(); $footer_html = $this->footer_html();
$flash_html = $this->flash ? "<b id='flash'>".nl2br(html_escape(implode("\n", $this->flash)))."</b>" : ""; $flash_html = $this->flash ? "<b id='flash'>".nl2br(html_escape(implode("\n", $this->flash)))."</b>" : "";
return " return "
<body> <header>
<header> <h1$wrapper>{$this->heading}</h1>
<h1$wrapper>{$this->heading}</h1> $sub_block_html
$sub_block_html </header>
</header> <nav>
<nav> $left_block_html
$left_block_html </nav>
</nav> <article>
<article> $flash_html
$flash_html $main_block_html
$main_block_html </article>
</article> <footer>
<footer> $footer_html
$footer_html </footer>
</footer>
</body>
"; ";
} }

View file

@ -6,7 +6,7 @@ namespace Shimmie2;
use MicroHTML\HTMLElement; use MicroHTML\HTMLElement;
use function MicroHTML\emptyHTML; use function MicroHTML\{emptyHTML};
use function MicroHTML\A; use function MicroHTML\A;
use function MicroHTML\FORM; use function MicroHTML\FORM;
use function MicroHTML\INPUT; use function MicroHTML\INPUT;
@ -16,12 +16,7 @@ use function MicroHTML\PRE;
use function MicroHTML\P; use function MicroHTML\P;
use function MicroHTML\SELECT; use function MicroHTML\SELECT;
use function MicroHTML\SPAN; use function MicroHTML\SPAN;
use function MicroHTML\TABLE; use function MicroHTML\{TABLE,THEAD,TFOOT,TR,TH,TD};
use function MicroHTML\THEAD;
use function MicroHTML\TFOOT;
use function MicroHTML\TR;
use function MicroHTML\TH;
use function MicroHTML\TD;
function SHM_FORM(string $target, string $method = "POST", bool $multipart = false, string $form_id = "", string $onsubmit = "", string $name = ""): HTMLElement function SHM_FORM(string $target, string $method = "POST", bool $multipart = false, string $form_id = "", string $onsubmit = "", string $name = ""): HTMLElement
{ {

View file

@ -50,7 +50,7 @@ Tips
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
class Page extends BasePage class Page extends BasePage
{ {
public function render() public function body_html(): string
{ {
global $config; global $config;
@ -123,33 +123,26 @@ class Page extends BasePage
} }
$flash_html = $this->flash ? "<b id='flash'>".nl2br(html_escape(implode("\n", $this->flash)))."</b>" : ""; $flash_html = $this->flash ? "<b id='flash'>".nl2br(html_escape(implode("\n", $this->flash)))."</b>" : "";
$head_html = $this->head_html();
$footer_html = $this->footer_html(); $footer_html = $this->footer_html();
print <<<EOD return <<<EOD
<!doctype html> <header>
<html lang="en"> $title_link
$head_html <ul id="navbar" class="flat-list">
<body> $custom_links
<header> </ul>
$title_link <ul id="subnavbar" class="flat-list">
<ul id="navbar" class="flat-list"> $custom_sublinks
$custom_links </ul>
</ul> </header>
<ul id="subnavbar" class="flat-list"> $subheading
$custom_sublinks $sub_block_html
</ul> $left
</header> <article class="$withleft">
$subheading $flash_html
$sub_block_html $main_block_html
$left </article>
<article class="$withleft"> <footer><em>$footer_html</em></footer>
$flash_html
$main_block_html
</article>
<footer><em>$footer_html</em></footer>
</body>
</html>
EOD; EOD;
} }

View file

@ -51,7 +51,7 @@ Tips
class Page extends BasePage class Page extends BasePage
{ {
public function render() public function body_html(): string
{ {
global $config; global $config;
@ -124,14 +124,9 @@ class Page extends BasePage
} }
$flash_html = $this->flash ? "<b id='flash'>".nl2br(html_escape(implode("\n", $this->flash)))."</b>" : ""; $flash_html = $this->flash ? "<b id='flash'>".nl2br(html_escape(implode("\n", $this->flash)))."</b>" : "";
$head_html = $this->head_html();
$footer_html = $this->footer_html(); $footer_html = $this->footer_html();
print <<<EOD return <<<EOD
<!doctype html>
<html lang="en">
$head_html
<body>
<header> <header>
$title_link $title_link
<ul id="navbar" class="flat-list"> <ul id="navbar" class="flat-list">
@ -149,8 +144,6 @@ class Page extends BasePage
$main_block_html $main_block_html
</article> </article>
<footer><div>$footer_html</div></footer> <footer><div>$footer_html</div></footer>
</body>
</html>
EOD; EOD;
} }

View file

@ -6,7 +6,7 @@ namespace Shimmie2;
class Page extends BasePage class Page extends BasePage
{ {
public function render() public function body_html(): string
{ {
$left_block_html = ""; $left_block_html = "";
$main_block_html = ""; $main_block_html = "";
@ -44,14 +44,9 @@ class Page extends BasePage
} }
$flash_html = $this->flash ? "<b id='flash'>".nl2br(html_escape(implode("\n", $this->flash)))."</b>" : ""; $flash_html = $this->flash ? "<b id='flash'>".nl2br(html_escape(implode("\n", $this->flash)))."</b>" : "";
$head_html = $this->head_html();
$footer_html = $this->footer_html(); $footer_html = $this->footer_html();
print <<<EOD return <<<EOD
<!doctype html>
<html lang="en">
$head_html
<body>
<header> <header>
<h1>{$this->heading}</h1> <h1>{$this->heading}</h1>
$subheading $subheading
@ -66,8 +61,6 @@ class Page extends BasePage
<hr> <hr>
$footer_html $footer_html
</footer> </footer>
</body>
</html>
EOD; EOD;
} }
} }

View file

@ -17,7 +17,7 @@ use MicroHTML\HTMLElement;
class Page extends BasePage class Page extends BasePage
{ {
public function render() public function body_html(): string
{ {
global $config; global $config;
@ -82,14 +82,9 @@ class Page extends BasePage
$main_block_html = "<article>$flash_html{$main_block_html}</article>"; $main_block_html = "<article>$flash_html{$main_block_html}</article>";
} }
$head_html = $this->head_html();
$footer_html = $this->footer_html(); $footer_html = $this->footer_html();
print <<<EOD return <<<EOD
<!doctype html>
<html lang="en">
$head_html
<body>
<header> <header>
$menu $menu
$custom_sublinks $custom_sublinks
@ -100,8 +95,6 @@ class Page extends BasePage
<footer> <footer>
$footer_html $footer_html
</footer> </footer>
</body>
</html>
EOD; EOD;
} /* end of function display_page() */ } /* end of function display_page() */

View file

@ -6,63 +6,15 @@ namespace Shimmie2;
class Page extends BasePage class Page extends BasePage
{ {
public function render() public function head_html(): string
{ {
global $config, $user; global $config, $user;
$theme_name = $config->get_string('theme', 'default'); $theme_name = $config->get_string('theme', 'default');
$data_href = get_base_href();
$header_html = $this->get_all_html_headers(); $header_html = $this->get_all_html_headers();
$data_href = get_base_href();
$left_block_html = ""; return <<<EOD
$right_block_html = "";
$main_block_html = "";
$head_block_html = "";
$sub_block_html = "";
$main_headings = 0;
foreach ($this->blocks as $block) {
if ($block->section == "main" && !empty($block->header) && $block->header != "Comments") {
$main_headings++;
}
}
foreach ($this->blocks as $block) {
switch ($block->section) {
case "left":
$left_block_html .= $block->get_html(true);
break;
case "right":
$right_block_html .= $block->get_html(true);
break;
case "head":
$head_block_html .= "<td class='headcol'>".$block->get_html(false)."</td>";
break;
case "main":
if ($main_headings == 1) {
$block->header = null;
}
$main_block_html .= $block->get_html(false);
break;
case "subheading":
$sub_block_html .= $block->body; // $block->get_html(true);
break;
default:
print "<p>error: {$block->header} using an unknown section ({$block->section})";
break;
}
}
$query = !empty(CustomIndexTheme::$_search_query) ? html_escape(Tag::implode(CustomIndexTheme::$_search_query)) : "";
assert(!is_null($query)); # used in header.inc, do not remove :P
$flash_html = $this->flash ? "<b id='flash'>".nl2br(html_escape(implode("\n", $this->flash)))."</b>" : "";
$generated = autodate(date('c'));
$footer_html = $this->footer_html();
print <<<EOD
<!DOCTYPE html>
<html lang="en">
<head>
<title>{$this->title}</title> <title>{$this->title}</title>
<meta name="description" content="Rule 34, if it exists there is porn of it."/> <meta name="description" content="Rule 34, if it exists there is porn of it."/>
<meta name="viewport" content="width=1024"> <meta name="viewport" content="width=1024">
@ -111,16 +63,63 @@ $header_html
} }
// setTimeout(logTimes, 3000); // setTimeout(logTimes, 3000);
</script> </script>
</head> EOD;
}
<body> public function body_html(): string
{
global $config, $user;
$left_block_html = "";
$right_block_html = "";
$main_block_html = "";
$head_block_html = "";
$sub_block_html = "";
$main_headings = 0;
foreach ($this->blocks as $block) {
if ($block->section == "main" && !empty($block->header) && $block->header != "Comments") {
$main_headings++;
}
}
foreach ($this->blocks as $block) {
switch ($block->section) {
case "left":
$left_block_html .= $block->get_html(true);
break;
case "right":
$right_block_html .= $block->get_html(true);
break;
case "head":
$head_block_html .= "<td class='headcol'>".$block->get_html(false)."</td>";
break;
case "main":
if ($main_headings == 1) {
$block->header = null;
}
$main_block_html .= $block->get_html(false);
break;
case "subheading":
$sub_block_html .= $block->body; // $block->get_html(true);
break;
default:
print "<p>error: {$block->header} using an unknown section ({$block->section})";
break;
}
}
$query = !empty(CustomIndexTheme::$_search_query) ? html_escape(Tag::implode(CustomIndexTheme::$_search_query)) : "";
assert(!is_null($query)); # used in header.inc, do not remove :P
$flash_html = $this->flash ? "<b id='flash'>".nl2br(html_escape(implode("\n", $this->flash)))."</b>" : "";
$generated = autodate(date('c'));
$footer_html = $this->footer_html();
$header_inc = file_get_contents("themes/rule34v2/header.inc");
return <<<EOD
<table id="header" width="100%"> <table id="header" width="100%">
<tr> <tr>
<td> <td>$header_inc</td>
EOD;
include "themes/rule34v2/header.inc";
print <<<EOD
</td>
$head_block_html $head_block_html
</tr> </tr>
</table> </table>
@ -158,8 +157,6 @@ Thank you!
<!-- BEGIN EroAdvertising ADSPACE CODE --> <!-- BEGIN EroAdvertising ADSPACE CODE -->
<!--<script type="text/javascript" language="javascript" charset="utf-8" src="https://adspaces.ero-advertising.com/adspace/158168.js"></script>--> <!--<script type="text/javascript" language="javascript" charset="utf-8" src="https://adspaces.ero-advertising.com/adspace/158168.js"></script>-->
<!-- END EroAdvertising ADSPACE CODE --> <!-- END EroAdvertising ADSPACE CODE -->
</body>
</html>
EOD; EOD;
} }
} }

View file

@ -6,7 +6,7 @@ namespace Shimmie2;
class Page extends BasePage class Page extends BasePage
{ {
public function render() public function body_html(): string
{ {
global $config; global $config;
@ -40,14 +40,9 @@ class Page extends BasePage
} }
$flash_html = $this->flash ? "<b id='flash'>".nl2br(html_escape(implode("\n", $this->flash)))."</b>" : ""; $flash_html = $this->flash ? "<b id='flash'>".nl2br(html_escape(implode("\n", $this->flash)))."</b>" : "";
$head_html = $this->head_html();
$footer_html = $this->footer_html(); $footer_html = $this->footer_html();
print <<<EOD return <<<EOD
<!doctype html>
<html lang="en">
$head_html
<body>
<header> <header>
<table id="header" class="bgtop" style="width: 100%; height: 113px;"> <table id="header" class="bgtop" style="width: 100%; height: 113px;">
<tr> <tr>
@ -70,8 +65,6 @@ class Page extends BasePage
<footer> <footer>
$footer_html $footer_html
</footer> </footer>
</body>
</html>
EOD; EOD;
} }
} }