This commit is contained in:
Default
2025-04-21 22:32:40 +08:00
parent 52236ab6f7
commit f21ece4de1
8 changed files with 204 additions and 80 deletions

View File

@@ -7,7 +7,7 @@ use think\template\TagLib;
class Novel extends TagLib
{
protected $tags = [
'list' => ['attr' => 'limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val', 'close' => 1],
'list' => ['attr' => 'count,n_category,sort_type,n_status,n_sex,diff_key,cache_life,d_key,d_val', 'close' => 1],
'pager' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val,func,export_name', 'close' => 1],
'pagerexp' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val,func,export_name', 'close' => 0],
'info' => ['attr' => 'n_id,n_key', 'close' => 0],
@@ -15,6 +15,8 @@ class Novel extends TagLib
'status' => ['attr' => 'd_key,d_val'],
'sex' => ['attr' => 'd_key,d_val'],
'category' => ['attr' => 'd_key,d_val,n_sex'],
'ranklist' => ['attr' => 'count,sort_type,n_status,n_sex,diff_key,cache_life,d_key,d_val', 'close' => 1],
];
private function customBuildVar($mixedArgs)
@@ -27,8 +29,67 @@ class Novel extends TagLib
}
/**
* novel 自定义标签
* tagRankList
*
* @param array $tag
* @param string $content
* @return void
*/
public function tagRankList($tag, $content)
{
$count = $tag['count'] ?? '10';
$sort_type = $tag['sort_type'] ?? "";
$n_status = $tag['n_status'] ?? "all";
$n_sex = $tag['n_sex'] ?? "all";
$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';
$sort_type = $this->customBuildVar($sort_type);
$n_status = $this->customBuildVar($n_status);
$n_sex = $this->customBuildVar($n_sex);
$diff_key = $this->customBuildVar($diff_key);
$cache_life = $this->customBuildVar($cache_life);
$arrDataName = randomString(5);
$strParse = <<<EOT
<?php
\${$arrDataName} = app(\\app\\services\\NovelService::class)->getRankList([
'count' => {$count},
'sort_type' => {$sort_type},
'n_status' => {$n_status},
'n_sex' => {$n_sex},
'diff_key' => {$diff_key},
'cache_life' => {$cache_life}
]);
if (!empty(\${$arrDataName}) && is_array(\${$arrDataName})):
?>
EOT;
$strParse .= <<<EOT
<?php foreach (\${$arrDataName} as \${$d_key} => \${$d_val}): ?>
EOT;
$strParse .= $content;
$strParse .= <<<EOT
<?php endforeach; ?>
<?php endif; ?>
EOT;
return $strParse;
}
/**
* tagPagerExp
*
* @param array $tag
* @param string $content
* @return void
*/
public function tagPagerExp($tag, $content)
{
@@ -36,7 +97,11 @@ class Novel extends TagLib
}
/**
* novel 自定义标签
* tagPager
*
* @param array $tag
* @param string $content
* @return void
*/
public function tagPager($tag, $content)
{

View File

@@ -20,6 +20,7 @@ class Site extends TagLib
'replace' => ['attr' => 'code,diff', 'close' => 0],
'forgelist' => ['attr' => 'count,diff_key,cache_life,d_key,d_val', 'close' => 1],
'helper' => ['attr' => 'func', 'close' => 0],
];
private function customBuildVar($mixedArgs)
@@ -31,28 +32,48 @@ class Site extends TagLib
}
}
/**
* 小说详情URL生成器
*
* @param array $n_id
* @return string
*/
public function tagHelper($tag)
{
$strFunc = (string)$tag['func'];
/**
* tagRankList
*
* @param array $tag
* @param string $content
* @return void
*/
public function tagForgeList($tag, $content)
{
$count = $tag['count'] ?? '10';
$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';
// $strFunc = $this->customBuildVar($strFunc);
$diff_key = $this->customBuildVar($diff_key);
$cache_life = $this->customBuildVar($cache_life);
$strParse = <<<EOD
<?php
app(\\app\\services\\SiteContext::class)->{$strFunc}();
?>
EOD;
return $strParse;
}
$arrDataName = randomString(5);
$strParse = <<<EOT
/**
* tagRankList
*
* @param array $tag
* @param string $content
* @return void
*/
public function tagForgeList($tag, $content)
{
$count = $tag['count'] ?? '10';
$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';
$diff_key = $this->customBuildVar($diff_key);
$cache_life = $this->customBuildVar($cache_life);
$arrDataName = randomString(5);
$strParse = <<<EOT
<?php
\${$arrDataName} = app(\\app\\services\\SiteContext::class)->getForgeList([
'count' => {$count},
@@ -64,16 +85,16 @@ if (!empty(\${$arrDataName}) && is_array(\${$arrDataName})):
?>
EOT;
$strParse .= <<<EOT
$strParse .= <<<EOT
<?php foreach (\${$arrDataName} as \${$d_key} => \${$d_val}): ?>
EOT;
$strParse .= $content;
$strParse .= <<<EOT
$strParse .= $content;
$strParse .= <<<EOT
<?php endforeach; ?>
<?php endif; ?>
EOT;
return $strParse;
}
return $strParse;
}
/**
* cfg 标签处理函数-系统配置
@@ -258,7 +279,7 @@ EOD;
$strStatus = isset($tag['status']) ? $tag['status'] : 'all';
$strOrder = isset($tag['order']) ? $tag['order'] : '';
$intPage = isset($tag['page']) ? $tag['page'] : 1;
$strGender = $this->customBuildVar($strGender);
$strCategory = $this->customBuildVar($strCategory);
$strStatus = $this->customBuildVar($strStatus);
@@ -297,11 +318,6 @@ EOD;
return $strParse;
}
/**
* 内容替换
*
@@ -343,7 +359,7 @@ EOD;
$page_code = $this->customBuildVar($page_code);
$diff = $this->customBuildVar($diff);
$num = $this->customBuildVar($num);
$arrDataName = randomString(5);
$strParse = <<<EOT