Pages\Misc: Change sitemap() method

This commit is contained in:
Visman 2023-11-09 20:24:07 +07:00
parent 2feaff7b5c
commit 2c87b98d24

View file

@ -13,7 +13,7 @@ namespace ForkBB\Models\Pages;
use ForkBB\Models\Page; use ForkBB\Models\Page;
use ForkBB\Models\Forum\Forum; use ForkBB\Models\Forum\Forum;
use ForkBB\Models\Topic\Topic; use ForkBB\Models\Topic\Topic;
use function \ForkBB\{__, num}; use function \ForkBB\__;
class Misc extends Page class Misc extends Page
{ {
@ -151,8 +151,10 @@ class Misc extends Page
$this->nameTpl = 'sitemap'; $this->nameTpl = 'sitemap';
if (1 !== $gGroup->g_read_board) {
} elseif (null === $id) {
// sitemap.xml // sitemap.xml
if (null === $id) {
foreach ($forums->loadTree(0)->descendants as $forum) { foreach ($forums->loadTree(0)->descendants as $forum) {
if ($forum->last_post > 0) { if ($forum->last_post > 0) {
$this->sitemap[$this->c->Router->link('Sitemap', ['id' => $forum->id])] = $forum->last_post; $this->sitemap[$this->c->Router->link('Sitemap', ['id' => $forum->id])] = $forum->last_post;
@ -165,8 +167,8 @@ class Misc extends Page
$this->nameTpl = 'sitemap_index'; $this->nameTpl = 'sitemap_index';
// sitemap0.xml
} elseif (0 === $id) { } elseif (0 === $id) {
// sitemap0.xml
if (1 !== $gGroup->g_view_users) { if (1 !== $gGroup->g_view_users) {
return $this->c->Message->message('Bad request'); return $this->c->Message->message('Bad request');
} }
@ -194,8 +196,8 @@ class Misc extends Page
)] = null; )] = null;
} }
// sitemapN.xml
} else { } else {
// sitemapN.xml
$forum = $forums->get($id); $forum = $forums->get($id);
if (! $forum instanceof Forum) { if (! $forum instanceof Forum) {
@ -234,22 +236,22 @@ class Misc extends Page
} }
} }
if (empty($this->sitemap)) {
$this->sitemap[$this->c->Router->link('Index')] = null;
}
$this->onlinePos = 'sitemap'; $this->onlinePos = 'sitemap';
$this->onlineDetail = null; $this->onlineDetail = null;
$this->header('Content-type', 'application/xml; charset=utf-8'); $this->header('Content-type', 'application/xml; charset=utf-8');
$d = num(\microtime(true) - $this->c->START, 3); $d = \number_format(\microtime(true) - $this->c->START, 3);
$this->c->Log->debug("{$this->nameTpl} : {$id} : time = {$d}", [ $this->c->Log->debug("{$this->nameTpl} : {$id} : time = {$d}", [
'user' => $this->user->fLog(), 'user' => $this->user->fLog(),
'headers' => true, 'headers' => true,
]); ]);
if (empty($this->sitemap)) {
return $this->c->Message->message('Bad request');
} else {
return $this; return $this;
} }
}
} }