Refactor page class logic for checkstatus and add to tag page

This commit is contained in:
Dale Davies
2022-07-25 17:06:10 +01:00
parent 0cf55c9917
commit 7794cc0cf2
2 changed files with 12 additions and 9 deletions

View File

@@ -23,6 +23,8 @@ class HomePage extends AbstractPage {
}
$csrfsection = $this->session->getSection('csrf');
$unsplashdata = $this->cache->load('unsplash');
$showsearch = $this->config->parse_bool($this->config->get('showsearch', false));
$checkstatus = $this->config->parse_bool($this->config->get('checkstatus', false));
$templatecontext = [
'csrftoken' => $csrfsection->get('token'),
'greeting' => $greeting,
@@ -34,11 +36,9 @@ class HomePage extends AbstractPage {
'unsplash' => !!$this->config->get('unsplashapikey', false),
'unsplashcolor' => $unsplashdata?->color,
'wwwurl' => $this->config->get_wwwurl(),
'checkstatus' => $this->config->parse_bool($this->config->get('checkstatus', false)),
'checkstatus' => $checkstatus,
];
$showsearch = $this->config->parse_bool($this->config->get('showsearch', false));
$showstatus = $this->config->parse_bool($this->config->get('showsearch', false));
if ($showsearch || $showstatus) {
if ($showsearch || $checkstatus) {
$templatecontext['sitesjson'] = json_encode((new \Jump\Sites($this->config, $this->cache))->get_sites_for_frontend());
if ($showsearch) {
$templatecontext['searchengines'] = json_encode((new \Jump\SearchEngines($this->config, $this->cache))->get_search_engines());

View File

@@ -23,6 +23,8 @@ class TagPage extends AbstractPage {
$title = 'Tag: '.$this->tagname;
$csrfsection = $this->session->getSection('csrf');
$unsplashdata = $this->cache->load('unsplash');
$showsearch = $this->config->parse_bool($this->config->get('showsearch', false));
$checkstatus = $this->config->parse_bool($this->config->get('checkstatus', false));
$templatecontext = [
'csrftoken' => $csrfsection->get('token'),
'greeting' => $this->tagname,
@@ -34,12 +36,13 @@ class TagPage extends AbstractPage {
'unsplash' => !!$this->config->get('unsplashapikey', false),
'unsplashcolor' => $unsplashdata?->color,
'wwwurl' => $this->config->get_wwwurl(),
'checkstatus' => $checkstatus,
];
if ($this->config->parse_bool($this->config->get('showsearch', false))) {
$templatecontext = array_merge($templatecontext, [
'searchengines' => json_encode((new \Jump\SearchEngines($this->config, $this->cache))->get_search_engines()),
'searchjson' => json_encode((new \Jump\Sites($this->config, $this->cache))->get_sites_for_search()),
]);
if ($showsearch || $checkstatus) {
$templatecontext['sitesjson'] = json_encode((new \Jump\Sites($this->config, $this->cache))->get_sites_for_frontend());
if ($showsearch) {
$templatecontext['searchengines'] = json_encode((new \Jump\SearchEngines($this->config, $this->cache))->get_search_engines());
}
}
return $template->render($templatecontext);
}