Refactored Sitemap class (#648)

This commit is contained in:
Roman Kelesidis 2023-03-20 23:27:28 +07:00 committed by GitHub
commit 5f0649073f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 14 deletions

View file

@ -14,7 +14,7 @@ if (!defined('IN_AJAX')) {
global $bb_cfg, $lang; global $bb_cfg, $lang;
$mode = (string)$this->request['mode']; $mode = (string)$this->request['mode'];
$map = new TorrentPier\Legacy\Sitemap(); $map = new TorrentPier\Sitemap();
$html = ''; $html = '';
switch ($mode) { switch ($mode) {

View file

@ -11,7 +11,7 @@ if (!defined('BB_ROOT')) {
die(basename(__FILE__)); die(basename(__FILE__));
} }
$map = new TorrentPier\Legacy\Sitemap(); $map = new TorrentPier\Sitemap();
$map->createSitemap(); $map->createSitemap();
if (file_exists(SITEMAP_DIR . '/sitemap.xml')) { if (file_exists(SITEMAP_DIR . '/sitemap.xml')) {

View file

@ -7,14 +7,16 @@
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License * @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
*/ */
namespace TorrentPier\Legacy; namespace TorrentPier;
use InvalidArgumentException;
use samdark\sitemap\Sitemap as STM; use samdark\sitemap\Sitemap as STM;
use samdark\sitemap\Index as IDX; use samdark\sitemap\Index as IDX;
/** /**
* Class Sitemap * Class Sitemap
* @package TorrentPier\Legacy * @package TorrentPier
*/ */
class Sitemap class Sitemap
{ {
@ -23,7 +25,7 @@ class Sitemap
* *
* @return array * @return array
*/ */
private function getForumUrls() private function getForumUrls(): array
{ {
global $datastore; global $datastore;
@ -53,7 +55,7 @@ class Sitemap
* *
* @return array * @return array
*/ */
private function getTopicUrls() private function getTopicUrls(): array
{ {
global $datastore; global $datastore;
@ -84,7 +86,7 @@ class Sitemap
* *
* @return array * @return array
*/ */
private function getStaticUrls() private function getStaticUrls(): array
{ {
global $bb_cfg; global $bb_cfg;
@ -111,9 +113,9 @@ class Sitemap
* *
* @return array * @return array
* *
* @throws \InvalidArgumentException * @throws InvalidArgumentException
*/ */
private function buildDynamicSitemap() private function buildDynamicSitemap(): array
{ {
$sitemap = new STM(SITEMAP_DIR . '/sitemap_dynamic.xml'); $sitemap = new STM(SITEMAP_DIR . '/sitemap_dynamic.xml');
@ -135,9 +137,9 @@ class Sitemap
* *
* @return array * @return array
* *
* @throws \InvalidArgumentException * @throws InvalidArgumentException
*/ */
private function buildStaticSitemap() private function buildStaticSitemap(): array
{ {
$staticSitemap = new STM(SITEMAP_DIR . '/sitemap_static.xml'); $staticSitemap = new STM(SITEMAP_DIR . '/sitemap_static.xml');
@ -155,9 +157,9 @@ class Sitemap
* *
* @return bool * @return bool
* *
* @throws \InvalidArgumentException * @throws InvalidArgumentException
*/ */
public function createSitemap() public function createSitemap(): bool
{ {
$index = new IDX(SITEMAP_DIR . '/sitemap.xml'); $index = new IDX(SITEMAP_DIR . '/sitemap.xml');
@ -186,7 +188,7 @@ class Sitemap
* *
* @return string * @return string
*/ */
public function sendSitemap($url, $map) public function sendSitemap($url, $map): string
{ {
$file = $url . urlencode($map); $file = $url . urlencode($map);