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

View file

@ -6,7 +6,7 @@ namespace Shimmie2;
use MicroHTML\HTMLElement;
use function MicroHTML\emptyHTML;
use function MicroHTML\{emptyHTML};
use function MicroHTML\A;
use function MicroHTML\FORM;
use function MicroHTML\INPUT;
@ -16,12 +16,7 @@ use function MicroHTML\PRE;
use function MicroHTML\P;
use function MicroHTML\SELECT;
use function MicroHTML\SPAN;
use function MicroHTML\TABLE;
use function MicroHTML\THEAD;
use function MicroHTML\TFOOT;
use function MicroHTML\TR;
use function MicroHTML\TH;
use function MicroHTML\TD;
use function MicroHTML\{TABLE,THEAD,TFOOT,TR,TH,TD};
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
{
public function render()
public function body_html(): string
{
global $config;
@ -123,14 +123,9 @@ class Page extends BasePage
}
$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();
print <<<EOD
<!doctype html>
<html lang="en">
$head_html
<body>
return <<<EOD
<header>
$title_link
<ul id="navbar" class="flat-list">
@ -148,8 +143,6 @@ class Page extends BasePage
$main_block_html
</article>
<footer><em>$footer_html</em></footer>
</body>
</html>
EOD;
}

View file

@ -51,7 +51,7 @@ Tips
class Page extends BasePage
{
public function render()
public function body_html(): string
{
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>" : "";
$head_html = $this->head_html();
$footer_html = $this->footer_html();
print <<<EOD
<!doctype html>
<html lang="en">
$head_html
<body>
return <<<EOD
<header>
$title_link
<ul id="navbar" class="flat-list">
@ -149,8 +144,6 @@ class Page extends BasePage
$main_block_html
</article>
<footer><div>$footer_html</div></footer>
</body>
</html>
EOD;
}

View file

@ -6,7 +6,7 @@ namespace Shimmie2;
class Page extends BasePage
{
public function render()
public function body_html(): string
{
$left_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>" : "";
$head_html = $this->head_html();
$footer_html = $this->footer_html();
print <<<EOD
<!doctype html>
<html lang="en">
$head_html
<body>
return <<<EOD
<header>
<h1>{$this->heading}</h1>
$subheading
@ -66,8 +61,6 @@ class Page extends BasePage
<hr>
$footer_html
</footer>
</body>
</html>
EOD;
}
}

View file

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

View file

@ -6,63 +6,15 @@ namespace Shimmie2;
class Page extends BasePage
{
public function render()
public function head_html(): string
{
global $config, $user;
$theme_name = $config->get_string('theme', 'default');
$data_href = get_base_href();
$header_html = $this->get_all_html_headers();
$data_href = get_base_href();
$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();
print <<<EOD
<!DOCTYPE html>
<html lang="en">
<head>
return <<<EOD
<title>{$this->title}</title>
<meta name="description" content="Rule 34, if it exists there is porn of it."/>
<meta name="viewport" content="width=1024">
@ -111,16 +63,63 @@ $header_html
}
// setTimeout(logTimes, 3000);
</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%">
<tr>
<td>
EOD;
include "themes/rule34v2/header.inc";
print <<<EOD
</td>
<td>$header_inc</td>
$head_block_html
</tr>
</table>
@ -158,8 +157,6 @@ Thank you!
<!-- BEGIN EroAdvertising ADSPACE CODE -->
<!--<script type="text/javascript" language="javascript" charset="utf-8" src="https://adspaces.ero-advertising.com/adspace/158168.js"></script>-->
<!-- END EroAdvertising ADSPACE CODE -->
</body>
</html>
EOD;
}
}

View file

@ -6,7 +6,7 @@ namespace Shimmie2;
class Page extends BasePage
{
public function render()
public function body_html(): string
{
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>" : "";
$head_html = $this->head_html();
$footer_html = $this->footer_html();
print <<<EOD
<!doctype html>
<html lang="en">
$head_html
<body>
return <<<EOD
<header>
<table id="header" class="bgtop" style="width: 100%; height: 113px;">
<tr>
@ -70,8 +65,6 @@ class Page extends BasePage
<footer>
$footer_html
</footer>
</body>
</html>
EOD;
}
}