This commit is contained in:
Default
2025-04-18 16:02:44 +08:00
parent 7db551a21b
commit 3e4ec4b1cb
14 changed files with 829 additions and 44 deletions

View File

@@ -0,0 +1,166 @@
<?php
namespace template\taglib;
use think\template\TagLib;
class Chapter extends TagLib
{
protected $tags = [
'list' => ['attr' => 'limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val'],
'pager' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val'],
'info' => ['attr' => 'n_id,n_key', 'close' => 0],
];
private function customBuildVar($mixedArgs)
{
if (substr($mixedArgs, 0, 1) == '$') {
return $this->autoBuildVar($mixedArgs);
} else {
return is_numeric($mixedArgs) ? $mixedArgs : "'" . $mixedArgs . "'";
}
}
/**
* chapter pager
*
* @param arrya $tag
* @param string $content
* @return void
*/
public function tagPager($tag, $content)
{
$page = $tag['page'] ?? '0';
$limit = $tag['limit'] ?? '100';
$button_num = $tag['button_num'] ?? '10';
$n_id = $tag['n_id'] ?? '0';
$sort_type = $tag['sort_type'] ?? "";
$diff_key = $tag['diff_key'] ?? "";
$cache_life = $tag['cache_life'] ?? '0';
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$p_val = $tag['p_val'] ?? 'p_val';
$func = $tag['func'];
$n_id = $this->customBuildVar($n_id);
$sort_type = $this->customBuildVar($sort_type);
$button_num = $this->customBuildVar($button_num);
$page = $this->customBuildVar($page);
$limit = $this->customBuildVar($limit);
$diff_key = $this->customBuildVar($diff_key);
$cache_life = $this->customBuildVar($cache_life);
$func = $this->customBuildVar($func);
$strParse = <<<EOT
<?php
\$arrChapter = app(\\app\\services\\ChapterService::class)->getNovelPager([
'page' => {$page},
'limit' => {$limit},
'button_num' => {$button_num},
'n_id' => {$n_id},
'sort_type' => {$sort_type},
'diff_key' => {$diff_key},
'cache_life' => {$cache_life},
'func' => {$func},
]);
if (isset(\$arrChapter['data']) && is_array(\$arrChapter['data'])):
\${$p_val} = \$arrChapter['p_data'] ?? [];
?>
EOT;
$strParse .= <<<EOT
<?php foreach (\$arrChapter['data'] as \${$d_key} => \${$d_val}): ?>
EOT;
$strParse .= $content;
$strParse .= <<<EOT
<?php endforeach; ?>
<?php endif; ?>
EOT;
return $strParse;
}
/**
* chapter list
*
* @param arrya $tag
* @param string $content
* @return void
*/
public function tagList($tag, $content)
{
$count = $tag['count'] ?? '100';
$n_id = $tag['n_id'] ?? '0';
$sort_type = $tag['sort_type'] ?? "";
$diff_key = $tag['diff_key'] ?? "";
$cache_life = $tag['cache_life'] ?? '0';
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$count = $this->customBuildVar($count);
$n_id = $this->customBuildVar($n_id);
$sort_type = $this->customBuildVar($sort_type);
$diff_key = $this->customBuildVar($diff_key);
$cache_life = $this->customBuildVar($cache_life);
$strParse = <<<EOT
<?php
\$arrChapter = app(\\app\\services\\ChapterService::class)->getChapterList([
'n_id' => {$n_id},
'count' => {$count},
'sort_type' => {$sort_type},
'diff_key' => {$diff_key},
'cache_life' => {$cache_life},
]);
if (!empty(\$arrChapter) && is_array(\$arrChapter)):
?>
EOT;
$strParse .= <<<EOT
<?php foreach (\$arrChapter as \${$d_key} => \${$d_val}): ?>
EOT;
$strParse .= $content;
$strParse .= <<<EOT
<?php endforeach; ?>
<?php endif; ?>
EOT;
return $strParse;
}
/**
* chapter info
*
* @param arrya $tag
* @param string $content
* @return void
*/
public function tagInfo($tag)
{
$n_id = $tag['n_id'] ?? '0';
$c_sort_num = $tag['c_sort_num'] ?? 0;
$c_page = $tag['c_page'] ?? 0;
$c_key = $tag['c_key'] ?? 'arrChapter';
$n_id = $this->customBuildVar($n_id);
$c_sort_num = $this->customBuildVar($c_sort_num);
$c_page = $this->customBuildVar($c_page);
$strParse = <<<EOT
<?php
\$arrChapter = app(\\app\\services\\ChapterService::class)->getChapterInfo(
{$n_id},
{$c_sort_num},
{$c_page}
);
\${$c_key} = \$arrChapter ?? [];
?>
EOT;
return $strParse;
}
}

View File

@@ -10,6 +10,10 @@ class Novel extends TagLib
'list' => ['attr' => 'limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val'],
'pager' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val'],
'info' => ['attr' => 'n_id,n_key', 'close' => 0],
'sort' => ['attr' => 'd_key,d_val'],
'status' => ['attr' => 'd_key,d_val'],
'sex' => ['attr' => 'd_key,d_val'],
'category' => ['attr' => 'd_key,d_val'],
];
private function customBuildVar($mixedArgs)
@@ -165,4 +169,133 @@ EOT;
return $strParse;
}
/**
* 获取排序筛选参数
*
* @param array $tag
* @param string $content
* @return string
*/
public function tagSort($tag, $content)
{
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$strParse = <<<EOT
<?php
\$arrSort = app(\\app\\services\\NovelService::class)->arrSortType;
if (!empty(\$arrSort) && is_array(\$arrSort)):
?>
EOT;
$strParse .= <<<EOT
<?php foreach (\$arrSort as \${$d_key} => \${$d_val}): ?>
EOT;
$strParse .= $content;
$strParse .= <<<EOT
<?php endforeach; ?>
<?php endif; ?>
EOT;
return $strParse;
}
/**
* 获取状态筛选参数
*
* @param array $tag
* @param string $content
* @return string
*/
public function tagStatus($tag, $content)
{
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$strParse = <<<EOT
<?php
\$arrStatus = app(\\app\\services\\NovelService::class)->arrStatus;
if (!empty(\$arrStatus) && is_array(\$arrStatus)):
?>
EOT;
$strParse .= <<<EOT
<?php foreach (\$arrStatus as \${$d_key} => \${$d_val}): ?>
EOT;
$strParse .= $content;
$strParse .= <<<EOT
<?php endforeach; ?>
<?php endif; ?>
EOT;
return $strParse;
}
/**
* 获取状态筛选参数
*
* @param array $tag
* @param string $content
* @return string
*/
public function tagSex($tag, $content)
{
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$strParse = <<<EOT
<?php
\$arrSex = app(\\app\\services\\NovelService::class)->arrSex;
if (!empty(\$arrSex) && is_array(\$arrSex)):
?>
EOT;
$strParse .= <<<EOT
<?php foreach (\$arrSex as \${$d_key} => \${$d_val}): ?>
EOT;
$strParse .= $content;
$strParse .= <<<EOT
<?php endforeach; ?>
<?php endif; ?>
EOT;
return $strParse;
}
/**
* 获取状态筛选参数
*
* @param array $tag
* @param string $content
* @return string
*/
public function tagCategory($tag, $content)
{
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$strParse = <<<EOT
<?php
\$arrCategory = app(\\app\\services\\NovelService::class)->getCategoryFilter();
if (!empty(\$arrCategory) && is_array(\$arrCategory)):
?>
EOT;
$strParse .= <<<EOT
<?php foreach (\$arrCategory as \${$d_key} => \${$d_val}): ?>
EOT;
$strParse .= $content;
$strParse .= <<<EOT
<?php endforeach; ?>
<?php endif; ?>
EOT;
return $strParse;
}
}

View File

@@ -20,6 +20,14 @@ class Site extends TagLib
'replace' => ['attr' => 'code', 'close' => 0],
];
private function customBuildVar($mixedArgs)
{
if (substr($mixedArgs, 0, 1) == '$') {
return $this->autoBuildVar($mixedArgs);
} else {
return is_numeric($mixedArgs) ? $mixedArgs : "'" . $mixedArgs . "'";
}
}
/**
* cfg 标签处理函数-系统配置
@@ -215,31 +223,7 @@ EOD;
}
/**
* 干扰码
*
* @param array
* @return string
*/
public function tagGrm($tag)
{
$strDomain = isset($tag['domain']) ? $tag['domain'] : '';
$strPageCode = isset($tag['code']) ? $tag['code'] : '';
$intLine = isset($tag['line']) ? $tag['line'] : 0;
$strDifference = isset($tag['diff']) ? $tag['diff'] : '';
$intStartNumber = isset($tag['start']) ? (int)$tag['start'] : 10;
$intEndNumber = isset($tag['end']) ? (int)$tag['end'] : 30;
$intIndex = isset($tag['index']) ? (int)$tag['index'] : 10;
$intType = isset($tag['type']) ? (int)$tag['type'] : 2;
$strParse = <<<EOD
<?php
\$strUrl = \\app\\model\\GanRaoMaModel::getGrmCode("{$strDomain}","{$strPageCode}","{$intLine}","{$strDifference}",{$intStartNumber},{$intEndNumber},{$intIndex},{$intType});
echo \$strUrl;
?>
EOD;
return $strParse;
}
@@ -261,4 +245,39 @@ EOD;
EOD;
return $strParse;
}
/**
* get grm
*
* @param arrya $tag
* @param string $content
* @return void
*/
public function tagGrm($tag)
{
$page_code = $tag['page_code'] ?? '';
$diff = $tag['diff'] ?? '';
$num = $tag['num'] ?? 1;
$g_key = $tag['g_key'] ?? 'arrGrm';
$page_code = $this->customBuildVar($page_code);
$diff = $this->customBuildVar($diff);
$num = $this->customBuildVar($num);
$strParse = <<<EOT
<?php
\$arrChapter = app(\\app\\services\\SiteContext::class)->generateGrm(
{$page_code},
{$diff},
{$num}
);
\${$g_key} = \$arrChapter ?? [];
?>
EOT;
return $strParse;
}
}