增加详情json
This commit is contained in:
@@ -92,33 +92,66 @@ class VideoSiteMapLogic
|
||||
return $this->arrDomainModel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate Site Map
|
||||
* Generate Site Map & Video JSON
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generateSiteMap()
|
||||
{
|
||||
$arrResult = $this->VideoModel->findPaginatedWithCache([], 1, 1);
|
||||
// 1. 只查一次总数(非常重要)
|
||||
$arrResult = $this->VideoModel->findPaginatedWithCache([], 1, 1);
|
||||
$this->intTotal = $arrResult['total'];
|
||||
|
||||
// 2. sitemap index
|
||||
$this->generateMapIndex();
|
||||
|
||||
// 3. sitemap main
|
||||
$this->generateMapMain();
|
||||
|
||||
// 4. 统一分页数
|
||||
$intTotalPage = ceil($this->intTotal / $this->intPageSize);
|
||||
|
||||
// 5. 分页生成 sitemap + json(推荐放一起)
|
||||
for ($intPage = 1; $intPage <= $intTotalPage; $intPage++) {
|
||||
|
||||
// 原有 sitemap
|
||||
$this->generateMapInfo($intPage);
|
||||
|
||||
// 新增 JSON
|
||||
$this->generateVideoJsonByPage($intPage);
|
||||
}
|
||||
|
||||
echo date('Y-m-d H:i:s') . PHP_EOL;
|
||||
}
|
||||
/**
|
||||
* Generate Site Map
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
// public function generateSiteMap()
|
||||
// {
|
||||
// $arrResult = $this->VideoModel->findPaginatedWithCache([], 1, 1);
|
||||
// $this->intTotal = $arrResult['total'];
|
||||
|
||||
// $this->generateMapIndex();
|
||||
|
||||
// $this->generateMapMain();
|
||||
|
||||
// $intTotalPage = ceil($this->intTotal / $this->intPageSize);
|
||||
// for ($intPage = 1; $intPage <= $intTotalPage; $intPage++) {
|
||||
// $this->generateMapInfo($intPage);
|
||||
// }
|
||||
|
||||
// echo date('Y-m-d H:i:s') . PHP_EOL;
|
||||
// }
|
||||
|
||||
|
||||
protected function generateMapInfo(int $intPage)
|
||||
{
|
||||
$intStartPage = $intPage ;
|
||||
$intStart = ($intStartPage-=1) * $this->intPageSize;
|
||||
$intStartPage = $intPage;
|
||||
$intStart = ($intStartPage -= 1) * $this->intPageSize;
|
||||
foreach ($this->getDomain() as $DomainModel) {
|
||||
|
||||
$strDomainDir = $this->strSiteMapPath . $DomainModel->d_domain;
|
||||
@@ -168,17 +201,15 @@ EOF;
|
||||
$strContent = sprintf($strTemplate, $strUrl, $strPriority);
|
||||
file_put_contents($strMapVideosFile, $strContent, FILE_APPEND);
|
||||
file_put_contents($strMapVideosFileTxt, $strUrl . PHP_EOL, FILE_APPEND);
|
||||
|
||||
}
|
||||
|
||||
file_put_contents($strMapVideosFile, $strEnd, FILE_APPEND);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分批查询小说数据,并以生成器方式返回
|
||||
* 分批查询数据,并以生成器方式返回
|
||||
*
|
||||
* @param int $intStart 跳过的记录数(skip)
|
||||
* @param int $intCount 需要查询的总记录数
|
||||
@@ -194,9 +225,7 @@ EOF;
|
||||
while ($intRecordsFetched < $intRemainingRecords) {
|
||||
$intLimit = min($this->intBatchSize, $intRemainingRecords - $intRecordsFetched);
|
||||
$Cursor = $this->VideoModel->getCol()->find(
|
||||
[
|
||||
|
||||
],
|
||||
[],
|
||||
[
|
||||
'skip' => $intStart + $intRecordsFetched,
|
||||
'limit' => $intLimit,
|
||||
@@ -296,23 +325,23 @@ EOF;
|
||||
// foreach ($this->arrVideoArea as $strVideoAreaKey => $strVideoAreaVal) {
|
||||
// foreach ($this->arrVideoYear as $strVideoYearKey => $strVideoYearVal) {
|
||||
|
||||
$strKey = "VIDEO_CATEGORY_URL";
|
||||
$strDomain = $DomainModel->d_domain;
|
||||
$strController = "";
|
||||
$strAction = "";
|
||||
$arrArgs = [
|
||||
'strParentCategory' => $arrParentCategory['v_category_en'],
|
||||
'strCategory' => $arrChildrenCategory['v_category_en'],
|
||||
'strYear' => 'all',
|
||||
'strArea' => 'all',
|
||||
'strOrder' => $strSortKey,
|
||||
'strLang' => 'all',
|
||||
'intPage' => 1,
|
||||
];
|
||||
$strKey = "VIDEO_CATEGORY_URL";
|
||||
$strDomain = $DomainModel->d_domain;
|
||||
$strController = "";
|
||||
$strAction = "";
|
||||
$arrArgs = [
|
||||
'strParentCategory' => $arrParentCategory['v_category_en'],
|
||||
'strCategory' => $arrChildrenCategory['v_category_en'],
|
||||
'strYear' => 'all',
|
||||
'strArea' => 'all',
|
||||
'strOrder' => $strSortKey,
|
||||
'strLang' => 'all',
|
||||
'intPage' => 1,
|
||||
];
|
||||
|
||||
$strUri = $DomainModel->getFomartUrlEx($strKey, $strDomain, $strController, $strAction, $arrArgs);
|
||||
$strUrl = sprintf("https://www.%s%s", $DomainModel->d_domain, $strUri);
|
||||
$strContent = <<<EOF
|
||||
$strUri = $DomainModel->getFomartUrlEx($strKey, $strDomain, $strController, $strAction, $arrArgs);
|
||||
$strUrl = sprintf("https://www.%s%s", $DomainModel->d_domain, $strUri);
|
||||
$strContent = <<<EOF
|
||||
<url>
|
||||
<loc>{$strUrl}</loc>
|
||||
<lastmod>{$this->strDate}</lastmod>
|
||||
@@ -320,7 +349,7 @@ EOF;
|
||||
<priority>0.8</priority>
|
||||
</url>
|
||||
EOF;
|
||||
file_put_contents($strMapIndexFile, $strContent, FILE_APPEND);
|
||||
file_put_contents($strMapIndexFile, $strContent, FILE_APPEND);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@@ -412,4 +441,98 @@ EOF;
|
||||
file_put_contents($strMapIndexFile, $strContent, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
|
||||
public function generateVideoJsonAll(): void
|
||||
{
|
||||
$arrResult = $this->VideoModel->findPaginatedWithCache([], 1, 1);
|
||||
$this->intTotal = $arrResult['total'];
|
||||
|
||||
$intTotalPage = ceil($this->intTotal / $this->intPageSize);
|
||||
|
||||
for ($intPage = 1; $intPage <= $intTotalPage; $intPage++) {
|
||||
$this->generateVideoJsonByPage($intPage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页生成 Video JSON(与 sitemap-videos-* 完全一致)
|
||||
*
|
||||
* 每个 JSON 文件格式:
|
||||
* [
|
||||
* {
|
||||
* "keyword": "...",
|
||||
* "site": "...",
|
||||
* "href": "...",
|
||||
* "url": "#"
|
||||
* }
|
||||
* ]
|
||||
*/
|
||||
public function generateVideoJsonByPage(int $intPage): void
|
||||
{
|
||||
$intStart = ($intPage - 1) * $this->intPageSize;
|
||||
|
||||
foreach ($this->getDomain() as $DomainModel) {
|
||||
|
||||
$strDomainDir = $this->strSiteMapPath . $DomainModel->d_domain;
|
||||
if (!is_dir($strDomainDir)) {
|
||||
mkdir($strDomainDir, 0755, true);
|
||||
}
|
||||
|
||||
$strJsonFile = sprintf(
|
||||
'%s/video-list-%d.json',
|
||||
$strDomainDir,
|
||||
$intPage
|
||||
);
|
||||
|
||||
$fp = fopen($strJsonFile, 'w');
|
||||
|
||||
// JSON 数组开始
|
||||
fwrite($fp, "[\n");
|
||||
|
||||
$isFirst = true;
|
||||
|
||||
foreach ($this->fetchVideosByBatch($intStart, $this->intPageSize) as $Video) {
|
||||
|
||||
$strUri = $DomainModel->getFomartUrlEx(
|
||||
"VIDEO_INFO_URL",
|
||||
$DomainModel->d_domain,
|
||||
'',
|
||||
'',
|
||||
[
|
||||
'intVId' => $Video->v_id,
|
||||
'strPinYin' => $Video->v_name_en,
|
||||
]
|
||||
);
|
||||
|
||||
$strFullUrl = sprintf(
|
||||
'https://www.%s%s',
|
||||
$DomainModel->d_domain,
|
||||
$strUri
|
||||
);
|
||||
|
||||
$row = [
|
||||
'keyword' => $Video->v_name,
|
||||
'site' => $DomainModel->d_domain,
|
||||
'href' => $strFullUrl,
|
||||
'url' => '#',
|
||||
];
|
||||
|
||||
if (!$isFirst) {
|
||||
fwrite($fp, ",\n");
|
||||
}
|
||||
|
||||
fwrite(
|
||||
$fp,
|
||||
json_encode($row, JSON_UNESCAPED_UNICODE)
|
||||
);
|
||||
|
||||
$isFirst = false;
|
||||
}
|
||||
|
||||
// JSON 数组结束
|
||||
fwrite($fp, "\n]");
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user