diff --git a/core/basepage.php b/core/basepage.php index 13a26928..992f0708 100644 --- a/core/basepage.php +++ b/core/basepage.php @@ -138,9 +138,6 @@ class BasePage /** @var string */ public $subheading = ""; - /** @var string */ - public $quicknav = ""; - /** @var string[] */ public $html_headers = []; @@ -312,49 +309,8 @@ class BasePage # header('Expires: ' . gmdate('D, d M Y H:i:s', time() - 600) . ' GMT'); #} usort($this->blocks, "blockcmp"); - $pnbe = send_event(new PageNavBuildingEvent()); - - $nav_links = $pnbe->links; - - $active_link = null; - // To save on event calls, we check if one of the top-level links has already been marked as active - foreach ($nav_links as $link) { - if ($link->active===true) { - $active_link = $link; - break; - } - } - $sub_links = null; - // If one is, we just query for sub-menu options under that one tab - if ($active_link!==null) { - $psnbe = send_event(new PageSubNavBuildingEvent($active_link->name)); - $sub_links = $psnbe->links; - } else { - // Otherwise we query for the sub-items under each of the tabs - foreach ($nav_links as $link) { - $psnbe = send_event(new PageSubNavBuildingEvent($link->name)); - - // Now we check for a current link so we can identify the sub-links to show - foreach ($psnbe->links as $sub_link) { - if ($sub_link->active===true) { - $sub_links = $psnbe->links; - break; - } - } - // If the active link has been detected, we break out - if ($sub_links!==null) { - $link->active = true; - break; - } - } - } - - $sub_links = $sub_links??[]; - usort($nav_links, "sort_nav_links"); - usort($sub_links, "sort_nav_links"); - $this->add_auto_html_headers(); - $this->render($nav_links, $sub_links); + $this->render(); break; case PageMode::DATA: header("Content-Length: " . strlen($this->data)); @@ -504,10 +460,56 @@ class BasePage $this->add_html_header("", 44); } + protected function get_nav_links() + { + $pnbe = send_event(new PageNavBuildingEvent()); + + $nav_links = $pnbe->links; + + $active_link = null; + // To save on event calls, we check if one of the top-level links has already been marked as active + foreach ($nav_links as $link) { + if ($link->active===true) { + $active_link = $link; + break; + } + } + $sub_links = null; + // If one is, we just query for sub-menu options under that one tab + if ($active_link!==null) { + $psnbe = send_event(new PageSubNavBuildingEvent($active_link->name)); + $sub_links = $psnbe->links; + } else { + // Otherwise we query for the sub-items under each of the tabs + foreach ($nav_links as $link) { + $psnbe = send_event(new PageSubNavBuildingEvent($link->name)); + + // Now we check for a current link so we can identify the sub-links to show + foreach ($psnbe->links as $sub_link) { + if ($sub_link->active===true) { + $sub_links = $psnbe->links; + break; + } + } + // If the active link has been detected, we break out + if ($sub_links!==null) { + $link->active = true; + break; + } + } + } + + $sub_links = $sub_links??[]; + usort($nav_links, "sort_nav_links"); + usort($sub_links, "sort_nav_links"); + + return [$nav_links, $sub_links]; + } + /** * turns the Page into HTML */ - public function render(array $nav_links, array $sub_links) + public function render() { $head_html = $this->head_html(); $body_html = $this->body_html(); diff --git a/core/tests/basepage.test.php b/core/tests/basepage.test.php new file mode 100644 index 00000000..d1f98531 --- /dev/null +++ b/core/tests/basepage.test.php @@ -0,0 +1,48 @@ +set_mode(PageMode::PAGE); + ob_start(); + $page->display(); + ob_end_clean(); + $this->assertTrue(true); // doesn't crash + } + + public function test_file() + { + $page = new BasePage(); + $page->set_mode(PageMode::FILE); + $page->set_file("tests/pbx_screenshot.jpg"); + ob_start(); + $page->display(); + ob_end_clean(); + $this->assertTrue(true); // doesn't crash + } + + public function test_data() + { + $page = new BasePage(); + $page->set_mode(PageMode::DATA); + $page->set_data("hello world"); + ob_start(); + $page->display(); + ob_end_clean(); + $this->assertTrue(true); // doesn't crash + } + + public function test_redirect() + { + $page = new BasePage(); + $page->set_mode(PageMode::REDIRECT); + $page->set_redirect("/new/page"); + ob_start(); + $page->display(); + ob_end_clean(); + $this->assertTrue(true); // doesn't crash + } +} diff --git a/themes/danbooru/page.class.php b/themes/danbooru/page.class.php index 17d62c8f..beb9ca93 100644 --- a/themes/danbooru/page.class.php +++ b/themes/danbooru/page.class.php @@ -51,10 +51,12 @@ class Page extends BasePage $this->left_enabled = false; } - public function render(array $nav_links, array $sub_links) + public function render() { global $config; + list($nav_links, $sub_links) = $this->get_nav_links(); + $left_block_html = ""; $user_block_html = ""; $main_block_html = ""; diff --git a/themes/danbooru2/page.class.php b/themes/danbooru2/page.class.php index 1926d839..32e96a39 100644 --- a/themes/danbooru2/page.class.php +++ b/themes/danbooru2/page.class.php @@ -50,10 +50,12 @@ class Page extends BasePage $this->left_enabled = false; } - public function render(array $nav_links, array $sub_links) + public function render() { global $config; + list($nav_links, $sub_links) = $this->get_nav_links(); + $left_block_html = ""; $user_block_html = ""; $main_block_html = ""; diff --git a/themes/futaba/page.class.php b/themes/futaba/page.class.php index 6f6355da..452514ef 100644 --- a/themes/futaba/page.class.php +++ b/themes/futaba/page.class.php @@ -8,7 +8,7 @@ class Page extends BasePage $this->left_enabled = false; } - public function render($nav_links, $subnav_links) + public function render() { $left_block_html = ""; $main_block_html = ""; diff --git a/themes/lite/page.class.php b/themes/lite/page.class.php index a76879fc..84b27cb2 100644 --- a/themes/lite/page.class.php +++ b/themes/lite/page.class.php @@ -18,10 +18,11 @@ class Page extends BasePage $this->left_enabled = false; } - public function render(array $nav_links, array $sub_links) + public function render() { global $config; + list($nav_links, $sub_links) = $this->get_nav_links(); $theme_name = $config->get_string(SetupConfig::THEME, 'lite'); $site_name = $config->get_string(SetupConfig::TITLE); $data_href = get_base_href(); diff --git a/themes/material/page.class.php b/themes/material/page.class.php index b9b43271..110c28b5 100644 --- a/themes/material/page.class.php +++ b/themes/material/page.class.php @@ -1,10 +1,11 @@ get_nav_links(); $theme_name = $config->get_string(SetupConfig::THEME, 'material'); $site_name = $config->get_string(SetupConfig::TITLE); $data_href = get_base_href(); diff --git a/themes/rule34v2/page.class.php b/themes/rule34v2/page.class.php index eac342dc..90a2edd5 100644 --- a/themes/rule34v2/page.class.php +++ b/themes/rule34v2/page.class.php @@ -1,7 +1,7 @@