FIX SITE MAP

This commit is contained in:
Default
2025-04-24 01:18:17 +08:00
parent 7494188846
commit 8754bbc58e
11 changed files with 571 additions and 84 deletions

View File

@@ -217,14 +217,14 @@ class ChapterService
* @param integer $intCPage
* @return void
*/
public function getChapterInfo(int $intNId, int $intCSortNum = 0, int $intCPage = 0)
public function getChapterInfo(int $intNId, int|NULL $intCSortNum = 0, int|NULL $intCPage = 0)
{
// 小说详情
$arrNovel = $this->NovelModel->getNovelByNId($intNId);
$ChapterModel = ChapterModel::getInstance();
if ($intCSortNum == 0 && $intCPage == 0) {
if ($intCSortNum === NULL && $intCPage === NULL) {
// 最新章节
$arrChapter = $ChapterModel->getLatestChapterByNId($intNId);
} else {

View File

@@ -48,25 +48,6 @@ class NovelService
$this->NovelClicksModel = NovelClicksModel::getInstance();
}
/**
* Undocumented function
*
* @param array $arrArgs
* @return string
*/
public function getPageUrl($strKey, array $arrArgs,): string
{
$strSfVal = $this->SiteContext->DomainModel->getFomartSubject($strKey, '', false);
$arrKeys = [];
$arrVals = [];
foreach ($arrArgs as $strKey => $strVal) {
$arrKeys[] = '{' . $strKey . '}';
$arrVals[] = $strVal;
}
return str_replace($arrKeys, $arrVals, $strSfVal);
}
/**
* Undocumented function
@@ -78,7 +59,7 @@ class NovelService
public function getNovelInfoUrl($intNId, $intPinYin): string
{
$strKey = 'NOVEL_INFO_URL';
$strUrl = $this->getPageUrl($strKey, [
$strUrl = $this->SiteContext->DomainModel->getFomartUrl($strKey, [
'intNId' => $intNId,
'strPinYin' => $intPinYin
]);
@@ -95,7 +76,7 @@ class NovelService
public function getForgeNovelInfoUrl($intNId, $intPinYin, $intNForgeId): string
{
$strKey = 'KAN_NOVEL_INFO_URL';
$strUrl = $this->getPageUrl($strKey, [
$strUrl = $this->SiteContext->DomainModel->getFomartUrl($strKey, [
'intNId' => $intNId,
'strPinYin' => $intPinYin,
'intNForgeId' => $intNForgeId,
@@ -108,15 +89,15 @@ class NovelService
* Undocumented function
*
* @param int $intNId
* @param int $intPinYin
* @param string $intPinYin
* @param int $intChapterSort
* @param integer $intChapterPage
* @return string
*/
public function getNovelChapterUrl(int $intNId, $intPinYin, $intChapterSort, $intChapterPage = 0): string
public function getNovelChapterUrl(int $intNId, string $intPinYin, int $intChapterSort, int $intChapterPage = 0): string
{
$strKey = 'CONTENT_INFO_URL';
$strUrl = $this->getPageUrl($strKey, [
$strUrl = $this->SiteContext->DomainModel->getFomartUrl($strKey, [
'intNId' => $intNId,
'strPinYin' => $intPinYin,
'intChapterSort' => $intChapterSort,
@@ -136,28 +117,28 @@ class NovelService
public function getNovelLasterChapterUrl($intNId, $intPinYin): string
{
$strKey = 'NEWS_CONTENT_INFO_URL';
$strUrl = $this->getPageUrl($strKey, [
$strUrl = $this->SiteContext->DomainModel->getFomartUrl($strKey, [
'intNId' => $intNId,
'strPinYin' => $intPinYin,
]);
return (string)$strUrl;
}
/**
* 小说分类/书库
* Undocumented function
* 获取小说分类URl
*
* @param [type] $strGender
* @param [type] $strCategory
* @param [type] $strStatus
* @param [type] $strOrder
* @param [type] $intPage
* @param string $strGender
* @param string $strCategory
* @param string $strStatus
* @param string $strOrder
* @param integer $intPage
* @return string
*/
public function getNovelCategoryUrl($strGender, $strCategory, $strStatus, $strOrder, $intPage): string
public function getNovelCategoryUrl(string $strGender, string $strCategory, string $strStatus, string $strOrder, int|string $intPage): string
{
$strKey = 'CATEGORY_INFO_URL';
$strUrl = $this->getPageUrl($strKey, [
$strUrl = $this->SiteContext->DomainModel->getFomartUrl($strKey, [
'strGender' => !empty($strGender) ? $strGender : '',
'strCategory' => !empty($strCategory) ? $strCategory : 'all',
'strStatus' => !empty($strStatus) ? $strStatus : 'all',
@@ -172,19 +153,18 @@ class NovelService
/**
* 排行榜url
* Undocumented function
*
* @param [type] $strGender
* @param [type] $strCategory
* @param [type] $strStatus
* @param [type] $strOrder
* @param [type] $intPage
* @param string $strGender
* @param string $strCategory
* @param string $strStatus
* @param string $strOrder
* @param integer $intPage
* @return string
*/
public function getNovelRankUrl($strGender, $strCategory, $strStatus, $strOrder, $intPage): string
public function getNovelRankUrl(string $strGender, string $strCategory, string $strStatus, string $strOrder, int $intPage): string
{
$strKey = 'RANK_LIST_URL';
$strUrl = $this->getPageUrl($strKey, [
$strUrl = $this->SiteContext->DomainModel->getFomartUrl($strKey, [
'strGender' => !empty($strGender) ? $strGender : '',
'strCategory' => !empty($strCategory) ? $strCategory : 'all',
'strStatus' => !empty($strStatus) ? $strStatus : 'all',
@@ -208,7 +188,7 @@ class NovelService
public function getNovelCatalogUrl($intNId, $intPinYin, $strOrder, $intPage = 1): string
{
$strKey = 'NOVEL_CATALOG_URL';
$strUrl = $this->getPageUrl($strKey, [
$strUrl = $this->SiteContext->DomainModel->getFomartUrl($strKey, [
'intNId' => $intNId,
'strPinYin' => $intPinYin,
'strOrder' => $strOrder,
@@ -228,31 +208,13 @@ class NovelService
public function getNovelSearchUrl($strKeyWords, $intPage = 1): string
{
$strKey = 'SEARCH_INFO_URL';
$strUrl = $this->getPageUrl($strKey, [
$strUrl = $this->SiteContext->DomainModel->getFomartUrl($strKey, [
'intPage' => $intPage,
'strSearchKeywords' => $strKeyWords
]);
return (string)$strUrl;
}
/**
* GetCategoryFilter
*
* @return array
*/
public function getCategoryFilter(string $strNSex = ''): array
{
if ($strNSex == 'man') {
return CategoryModel::$arrCategoryAll['man'];
} else if ($strNSex == 'women') {
return CategoryModel::$arrCategoryAll['women'];
} else {
return array_combine(CategoryModel::$arrCategoryPinYin, CategoryModel::$arrCategory);
}
}
/**
* 获取排行榜小说
*
@@ -654,7 +616,7 @@ class NovelService
$intLimit = $arrNovel['limit'] ?? 10;
$intTotal = $arrNovel['total'] ?? 0;
$intButtomNum = $arrParams['button_num'];
$strBaseUrl = app(NovelService::class)->getNovelCategoryUrl($strGender, $strCategory, $strStatus, $strOrder, '{page}');
$strBaseUrl = $this->getNovelCategoryUrl($strGender, $strCategory, $strStatus, $strOrder, '{page}');
$arrPaginator = CusteomPage02::generate($intPage, $intTotal, $intLimit, $strBaseUrl, $intButtomNum);

View File

@@ -14,6 +14,7 @@ use think\facade\Request;
use think\facade\Config;
use think\exception\HttpException;
use think\facade\View;
use think\Response;
class SiteContext
{
@@ -58,6 +59,7 @@ class SiteContext
* @var NovelClicksModel
*/
public $NovelClicksModel;
public function __construct()
{
$this->Request = request();
@@ -313,7 +315,7 @@ class SiteContext
$strOrder = $this->Request->param('strOrder');
$strStatus = $this->Request->param('strStatus');
$strNovelOrder = '';
if(!empty($strOrder) && $strOrder != 'all'){
if (!empty($strOrder) && $strOrder != 'all') {
$strNovelOrder = StaticConfig::$arrNovelRankSortType[$strOrder];
}
ConverterMovel::setVal([
@@ -322,4 +324,54 @@ class SiteContext
'strNovelStatus' => empty($strStatus) ? "" : StaticConfig::$arrNovelStatus[$strStatus],
]);
}
public function getSiteMapByCode(string $strCode): Response
{
$strFile = root_path('storage/SiteMap') . $this->DomainModel->d_domain . '/';
$intPage = $this->Request->route('page', 1);
switch ($strCode) {
case 'INDEX':
$strFile .= 'sitemap_index.xml';
break;
case 'MAIN':
$strFile .= 'sitemap-main.xml';
break;
case 'CATALOG':
$strFile .= "sitemap-books-catalog-{$intPage}.xml";
break;
case 'BOOK':
$strFile .= "sitemap-books-{$intPage}.xml";
break;
case 'CHAPTER':
$strFile .= "sitemap-chapters-{$intPage}.xml";
break;
default:
throw new \think\exception\HttpException(404, 'Sitemap file not found');
break;
}
if (!file_exists($strFile)) {
throw new \think\exception\HttpException(404, 'Sitemap file not found');
}
$Stream = fopen($strFile, 'rb');
if (!$Stream) {
http_response_code(500);
echo 'Failed to open file stream';
exit;
}
header('Content-Type: application/xml');
header('Content-Length: ' . filesize($strFile));
header('Content-Disposition: inline');
while (!feof($Stream)) {
echo fread($Stream, 8192);
flush();
}
fclose($Stream);
exit;
}
}

View File

@@ -2,6 +2,7 @@
namespace app\services;
use app\model\CategoryModel;
class StaticConfig
{
@@ -35,4 +36,20 @@ class StaticConfig
'zheng' => '正序',
'dao' => '倒叙',
];
/**
* GetCategoryFilter
*
* @return array
*/
static function getCategoryFilter(string $strNSex = ''): array
{
if ($strNSex == 'man') {
return CategoryModel::$arrCategoryAll['man'];
} else if ($strNSex == 'women') {
return CategoryModel::$arrCategoryAll['women'];
} else {
return array_combine(CategoryModel::$arrCategoryPinYin, CategoryModel::$arrCategory);
}
}
}