From 5f0649073f4f6871967853cb3c22543ec675ed5b Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Mon, 20 Mar 2023 23:27:28 +0700 Subject: [PATCH] Refactored Sitemap class (#648) --- library/ajax/sitemap.php | 2 +- library/includes/cron/jobs/sitemap.php | 2 +- src/{Legacy => }/Sitemap.php | 26 ++++++++++++++------------ 3 files changed, 16 insertions(+), 14 deletions(-) rename src/{Legacy => }/Sitemap.php (91%) diff --git a/library/ajax/sitemap.php b/library/ajax/sitemap.php index 82be6174d..987bc3c5d 100644 --- a/library/ajax/sitemap.php +++ b/library/ajax/sitemap.php @@ -14,7 +14,7 @@ if (!defined('IN_AJAX')) { global $bb_cfg, $lang; $mode = (string)$this->request['mode']; -$map = new TorrentPier\Legacy\Sitemap(); +$map = new TorrentPier\Sitemap(); $html = ''; switch ($mode) { diff --git a/library/includes/cron/jobs/sitemap.php b/library/includes/cron/jobs/sitemap.php index 2f952dadf..fe3adf675 100644 --- a/library/includes/cron/jobs/sitemap.php +++ b/library/includes/cron/jobs/sitemap.php @@ -11,7 +11,7 @@ if (!defined('BB_ROOT')) { die(basename(__FILE__)); } -$map = new TorrentPier\Legacy\Sitemap(); +$map = new TorrentPier\Sitemap(); $map->createSitemap(); if (file_exists(SITEMAP_DIR . '/sitemap.xml')) { diff --git a/src/Legacy/Sitemap.php b/src/Sitemap.php similarity index 91% rename from src/Legacy/Sitemap.php rename to src/Sitemap.php index 143306b3f..7f81b1063 100644 --- a/src/Legacy/Sitemap.php +++ b/src/Sitemap.php @@ -7,14 +7,16 @@ * @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\Index as IDX; /** * Class Sitemap - * @package TorrentPier\Legacy + * @package TorrentPier */ class Sitemap { @@ -23,7 +25,7 @@ class Sitemap * * @return array */ - private function getForumUrls() + private function getForumUrls(): array { global $datastore; @@ -53,7 +55,7 @@ class Sitemap * * @return array */ - private function getTopicUrls() + private function getTopicUrls(): array { global $datastore; @@ -84,7 +86,7 @@ class Sitemap * * @return array */ - private function getStaticUrls() + private function getStaticUrls(): array { global $bb_cfg; @@ -111,9 +113,9 @@ class Sitemap * * @return array * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ - private function buildDynamicSitemap() + private function buildDynamicSitemap(): array { $sitemap = new STM(SITEMAP_DIR . '/sitemap_dynamic.xml'); @@ -135,9 +137,9 @@ class Sitemap * * @return array * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ - private function buildStaticSitemap() + private function buildStaticSitemap(): array { $staticSitemap = new STM(SITEMAP_DIR . '/sitemap_static.xml'); @@ -155,9 +157,9 @@ class Sitemap * * @return bool * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ - public function createSitemap() + public function createSitemap(): bool { $index = new IDX(SITEMAP_DIR . '/sitemap.xml'); @@ -186,7 +188,7 @@ class Sitemap * * @return string */ - public function sendSitemap($url, $map) + public function sendSitemap($url, $map): string { $file = $url . urlencode($map);