From 3e4ec4b1cb9b6f9dc476330076076b17f85ca9a6 Mon Sep 17 00:00:00 2001 From: Default Date: Fri, 18 Apr 2025 16:02:44 +0800 Subject: [PATCH 1/2] debug --- code/app/home/controller/Novel.php | 16 +- .../home/view/default/test/test01/index.html | 53 +++- code/app/model/CategoryModel.php | 1 + code/app/model/ChapterModel.php | 34 +++ code/app/model/GanRaoMaModel.php | 2 +- code/app/model/NovelModel.php | 1 - code/app/services/ChapterService.php | 254 ++++++++++++++++++ code/app/services/NovelService.php | 20 +- code/app/services/SiteContext.php | 16 ++ code/config/view.php | 4 +- code/extend/template/taglib/Chapter.php | 166 ++++++++++++ code/extend/template/taglib/Novel.php | 133 +++++++++ code/extend/template/taglib/Site.php | 67 +++-- doc/TemplateTag.md | 106 ++++++++ 14 files changed, 829 insertions(+), 44 deletions(-) create mode 100644 code/extend/template/taglib/Chapter.php diff --git a/code/app/home/controller/Novel.php b/code/app/home/controller/Novel.php index 5f7ab1b..bef662d 100644 --- a/code/app/home/controller/Novel.php +++ b/code/app/home/controller/Novel.php @@ -204,13 +204,13 @@ class Novel extends BaseController $arrPage = $NovelModel->getCustomPage01($strKey, $intPage, $intLimit, $intLifeTime, $intGender, $strSearchStatus); $strTemplate = ''; - $intButtomNum = 5; + $intButtonNum = 5; if ($boolIsMobile == false) { - $intButtomNum = 10; + $intButtonNum = 10; $strTemplate = 'pc/getLibrary'; } - $arrPaginator = CusteomPage02::generate($intPage, $arrPage['total'], $intLimit, $strBaseUrl, $intButtomNum); + $arrPaginator = CusteomPage02::generate($intPage, $arrPage['total'], $intLimit, $strBaseUrl, $intButtonNum); // 更新值 ConverterMovel::setVal([ @@ -855,13 +855,13 @@ class Novel extends BaseController $arrPage = $ChapterModel->findPaginatedWithCache($arrFilter, $intPage, $intLimit, $arrSort, $strKey, $intLifeTime); - $intButtomNum = 5; + $intButtonNum = 5; if ($boolIsMobile == false) { - $intButtomNum = 10; + $intButtonNum = 10; } $strBaseUrl = app(NovelService::class)->getNovelCatalogUrl($intNId, $arrNovel['n_name_pinyin'], $strOrder, '{page}'); - $arrPaginator = CusteomPage02::generate($intPage, $arrPage['total'], $intLimit, $strBaseUrl, $intButtomNum); + $arrPaginator = CusteomPage02::generate($intPage, $arrPage['total'], $intLimit, $strBaseUrl, $intButtonNum); // 更新值 ConverterMovel::setVal([ @@ -941,11 +941,11 @@ class Novel extends BaseController $arrPage = $NovelModel->findPaginatedWithCache($arrFilter, $intPage, $intLimit, [], $strKey); - $intButtomNum = 10; + $intButtonNum = 10; $strBaseUrl = app(NovelService::class)->getNovelSearchUrl($strSearchKeywords, '{page}'); - $arrPaginator = CusteomPage02::generate($intPage, $arrPage['total'], $intLimit, $strBaseUrl, $intButtomNum); + $arrPaginator = CusteomPage02::generate($intPage, $arrPage['total'], $intLimit, $strBaseUrl, $intButtonNum); // 更新值 ConverterMovel::setVal([ diff --git a/code/app/home/view/default/test/test01/index.html b/code/app/home/view/default/test/test01/index.html index d243548..14fad69 100644 --- a/code/app/home/view/default/test/test01/index.html +++ b/code/app/home/view/default/test/test01/index.html @@ -1,8 +1,57 @@ +{site:grm page_code="fdasfadsf" diff="fadsfdsa" num="10" g_key="arrGrm" /} +{php}var_dump($arrGrm);{/php} + + -{novel:info n_id="33" n_key="arrNovel01" n_forge_id="1125940" /} -{$arrNovel01.n_name} + + + + + + + + + + + + + diff --git a/code/app/model/CategoryModel.php b/code/app/model/CategoryModel.php index 71608d0..08da1b3 100644 --- a/code/app/model/CategoryModel.php +++ b/code/app/model/CategoryModel.php @@ -97,6 +97,7 @@ class CategoryModel extends MongoModel return self::$arrCategory; } + /** * Undocumented function * diff --git a/code/app/model/ChapterModel.php b/code/app/model/ChapterModel.php index 1526aab..f6b557f 100644 --- a/code/app/model/ChapterModel.php +++ b/code/app/model/ChapterModel.php @@ -209,6 +209,40 @@ class ChapterModel extends MongoModel return $arrResult; } + /** + * Undocumented function + * + * @param array $arrFilter + * @param integer $intCount + * @param array $arrSort + * @param array $arrOptions + * @param boolean $boolReadContent + * @return null|array + */ + public function findManyShuffledWithCache( + array $arrFilter, + int $intCount = 0, + array $arrSort = ['c_sort_num' => -1], + string $strKey = '', + int $intLifeTime = 24 * 3600, + bool $boolReadContent = false + ): null|array { + $arrResult = $this->checkCacheByKey($strKey); + if ($arrResult !== NULL) { + return $arrResult; + } + + if (empty($arrOptions)) { + $arrOptions = self::$arrChapterOptions; + } + + $arrResult = $this->findMany($arrFilter, $intCount, $arrSort, [], $boolReadContent); + + $this->setCacheByKey($strKey, $arrResult, $intLifeTime); + + return $arrResult; + } + /** * Undocumented function * diff --git a/code/app/model/GanRaoMaModel.php b/code/app/model/GanRaoMaModel.php index 7d824bd..18720ae 100644 --- a/code/app/model/GanRaoMaModel.php +++ b/code/app/model/GanRaoMaModel.php @@ -204,7 +204,7 @@ class GanRaoMaModel extends MongoModel * @param string $strPageCode 视图编码 * @param string $strDifference 差异 * @param int $intNum 生成数量 - * @return string + * @return array */ static public function getGrmCode($strDomain, $strPageCode, $strDifference, $intNum) { diff --git a/code/app/model/NovelModel.php b/code/app/model/NovelModel.php index f807e05..0e63aec 100644 --- a/code/app/model/NovelModel.php +++ b/code/app/model/NovelModel.php @@ -149,7 +149,6 @@ class NovelModel extends MongoModel } } - /** * find one novel * diff --git a/code/app/services/ChapterService.php b/code/app/services/ChapterService.php index aee3a44..3113193 100644 --- a/code/app/services/ChapterService.php +++ b/code/app/services/ChapterService.php @@ -3,6 +3,10 @@ namespace app\services; use app\model\ChapterModel; +use app\model\ConverterMovel; +use app\model\NovelModel; +use template\page\CusteomPage02; +use think\facade\View; class ChapterService { @@ -20,9 +24,259 @@ class ChapterService */ public $ChapterModel; + /** + * NovelModel + * + * @var NovelModel + */ + public $NovelModel; + public function __construct(SiteContext $SiteContext) { $this->SiteContext = $SiteContext; + $this->NovelModel = NovelModel::getInstance(); $this->ChapterModel = ChapterModel::getInstance(); } + + public $arrSortType = [ + 'zheng' => '正序', + 'dao' => '倒叙', + ]; + + + /** + * 获取小说数据 + * + * @param array $arrParams + * @return array + */ + public function getChapterList(array $arrParams): array + { + $intCount = (int)$arrParams['count'] ?? 10; + $intNId = (int)$arrParams['n_id'] ?? 0; + $strSortType = (string)$arrParams['sort_type'] ?? ''; + $strDiffKey = (string) $arrParams['diff_key'] ?? ''; + $intCacheLifeTime = (int)$arrParams['cache_life'] ?? 0; + + $arrFilter = [ + 'n_id' => $intNId, + 'c_page' => 0, + ]; + + $arrFilter['n_id'] = $intNId; + + $arrSort = []; + + # sort filter + if (!empty($strSortType)) { + switch ($strSortType) { + case 'zheng': + $arrSort['c_sort_num'] = 1; + break; + case 'dao': + $arrSort['c_sort_num'] = -1; + break; + } + } + + $strCacheKey = ''; + $intLifeTime = 0; + + # cache filter + if ($intCacheLifeTime > 0) { + $strCacheKey = sprintf( + 'ChapterService:getChapterList:%s:%s:%s:%s:%s', + $this->SiteContext->DomainModel->d_domain, + md5(serialize($arrFilter)), + md5(serialize($arrSort)), + $intCount, + $strDiffKey, + ); + + $intLifeTime = $intLifeTime; + } + + $arrChapter = $this->ChapterModel->findManyShuffledWithCache( + $arrFilter, + $intCount, + $arrSort, + $strCacheKey, + $intLifeTime, + ); + + return $arrChapter; + } + + + /** + * 获取小说分页数据 + * + * @param array $arrParams + * @return array + */ + public function getNovelPager(array $arrParams): array + { + $arrParams = [ + 'page' => max((int)($arrParams['page'] ?? 1), 1), + 'limit' => (int)($arrParams['limit'] ?? 10), + 'n_id' => (int)($arrParams['n_id'] ?? 0), + 'button_num' => (int)($arrParams['button_num'] ?? 0), + 'sort_type' => (string)($arrParams['sort_type'] ?? ''), + 'diff_key' => (string)($arrParams['diff_key'] ?? ''), + 'key' => (string)($arrParams['key'] ?? ''), + 'cache_life' => (int)($arrParams['cache_life'] ?? 0), + 'func' => (string)($arrParams['func']), + ]; + + if (!in_array($arrParams['sort_type'], array_keys($this->arrSortType))) { + $arrParams['sort_type'] = 'zheng'; + } + + $intPage = $arrParams['page']; + $intLimit = $arrParams['limit']; + $intNId = $arrParams['n_id']; + + $strSortType = $arrParams['sort_type']; + $strDiffKey = $arrParams['diff_key']; + $intCacheLifeTime = $arrParams['cache_life']; + $Func = $arrParams['func']; + + if ($intPage <= 0) { + $intPage = 1; + } + + $arrFilter = [ + '$and' => [], + ]; + + $arrFilter['$and'][] = ['n_id' => $intNId]; + $arrFilter['$and'][] = ['c_page' => 0]; + + $arrSort = []; + + # sort filter + if (!empty($strSortType)) { + switch ($strSortType) { + case 'zheng': + $arrSort['c_sort_num'] = 1; + break; + case 'dao': + $arrSort['c_sort_num'] = -1; + break; + } + } + + $strCacheKey = ''; + $intLifeTime = 0; + + # cache filter + if ($intCacheLifeTime > 0) { + $strCacheKey = sprintf( + 'Service:getNovelList:%s:%s:%s:%s:%s:%s', + $this->SiteContext->DomainModel->d_domain, + md5(serialize($arrFilter)), + md5(serialize($arrSort)), + $intPage, + $intLimit, + $strDiffKey, + ); + + $intLifeTime = $intLifeTime; + } + + $arrNovel = $this->ChapterModel->findPaginatedWithCache( + $arrFilter, + $intPage, + $intLimit, + $arrSort, + $strCacheKey, + $intLifeTime, + ); + + $arrPager = call_user_func([$this, $Func], $arrParams, $arrSort, $arrNovel); + + $arrResult = [ + 'data' => $arrNovel['data'], + 'p_data' => $arrPager, + ]; + + return $arrResult; + } + + + /** + * 根据NId获取小说详情 + * + * @param integer $intNId + * @return void + */ + public function getChapterInfo(int $intNId, int $intCSortNum, int $intCPage) + { + // 小说详情 + $arrNovel = $this->NovelModel->getNovelByNId($intNId); + + // 章节 + $ChapterModel = ChapterModel::getInstance(); + $arrFilter = ['n_id' => $intNId, 'c_sort_num' => $intCSortNum, 'c_page' => $intCPage]; + + + $arrChapter = $ChapterModel->findOne($arrFilter); + $strChapterDescription = ''; + + // 上一章节和下一章节 + $arrPreChapter = $arrNextChapter = []; + + if ($arrChapter) { + $arrPreChapter = $ChapterModel->getPreChapter($arrChapter['n_id'], $arrChapter['c_sort_num'], $arrChapter['c_page']); + $arrNextChapter = $ChapterModel->getNextChapter($arrChapter['n_id'], $arrChapter['c_sort_num'], $arrChapter['c_page']); + + // 要点-先从章节随机截取,后面如果用上ai,看看使用ai 提炼 精简内容 + $strChapterDescription = strip_tags($arrChapter['c_content']); + $intCount = mb_strlen($strChapterDescription); + $strChapterDescription = ($intCount > 50) ? mb_substr($strChapterDescription, 0, 50) : $strChapterDescription; + + $arrChapter['c_content'] = base64_encode($arrChapter['c_content']); + } + + $arrChapter['pre_chapter'] = $arrPreChapter; + $arrChapter['next_chapter'] = $arrNextChapter; + + // 更新值 + ConverterMovel::setVal([ + 'intPage' => 1, + 'strNovelName' => $arrNovel['n_name'], + 'strNovelAuthor' => $arrNovel['n_author'], + 'strNovelCategoryName' => $arrNovel['n_category'], + 'strNovelStatus' => $arrNovel['n_status'], + 'strNovelDescription' => $arrNovel['n_description'], + 'strChapterDescription' => $strChapterDescription, + 'strNovelChapterName' => $arrChapter['c_name'], + 'strNovelChapterSort' => $arrChapter['c_sort_num'], + ]); + + return $arrChapter; + } + + + /** + * 搜索定制分页 + * + * @param array $arrFilter 查询条件字段 + * @param array $arrSort 查询排序字段 + * @param array $arrChapter 查询出来的数据 + * @return array + */ + public function generateChapterPager(array $arrParams, array $arrSort, array $arrChapter): array + { + + $arrNovel = $this->NovelModel->getNovelByNId($arrParams['n_id']); + $intButtonNum = $arrParams['button_num']; + $intPage = $arrChapter['page']; + $intLimit = $arrChapter['limit']; + + $strBaseUrl = app(NovelService::class)->getNovelCatalogUrl($arrParams['n_id'], $arrNovel['n_name_pinyin'], $arrParams['sort_type'], '{page}'); + $arrPaginator = CusteomPage02::generate($intPage, $arrChapter['total'], $intLimit, $strBaseUrl, $intButtonNum); + + return $arrPaginator; + } } diff --git a/code/app/services/NovelService.php b/code/app/services/NovelService.php index c7d930e..af4c93d 100644 --- a/code/app/services/NovelService.php +++ b/code/app/services/NovelService.php @@ -209,27 +209,36 @@ class NovelService } - - protected $arrSortType = [ + public $arrSortType = [ 'all' => '全部排序', 'news' => '最新入库', 'tuijian' => '推荐', 'update' => '最新更新', ]; - protected $arrStatus = [ + public $arrStatus = [ 'all' => '所有', 'lianzai' => '连载中', 'wanjie' => '已完结', ]; - protected $arrSex = [ + public $arrSex = [ 'all' => '所有', 'man' => '男生', 'women' => '女生', ]; + /** + * GetCategoryFilter + * + * @return array + */ + public function getCategoryFilter(): array + { + return array_combine(CategoryModel::$arrCategoryPinYin, CategoryModel::$arrCategory); + } + /** * 获取小说数据 * @@ -511,14 +520,13 @@ class NovelService // 小说详情 $arrNovel = $this->NovelModel->getNovelByNId($intNId); - if( $intNForgeId>0){ + if ($intNForgeId > 0) { foreach ($arrNovel['n_forge_novel'] as $arrForgeNovel) { if ($arrForgeNovel['n_forge_id'] == $intNForgeId) { $arrNovel['n_name'] = $arrForgeNovel['n_forge_title']; break; } } - } // 分类拼音 diff --git a/code/app/services/SiteContext.php b/code/app/services/SiteContext.php index 4af3a05..2820171 100644 --- a/code/app/services/SiteContext.php +++ b/code/app/services/SiteContext.php @@ -4,6 +4,7 @@ namespace app\services; use app\model\ConverterMovel; use app\model\DomainModel; +use app\model\GanRaoMaModel; use app\model\TemplatesModel; use think\facade\Request; use think\facade\Config; @@ -109,4 +110,19 @@ class SiteContext return ConverterMovel::convert($strTitleTemplate); } + + /** + * 获取干扰码 + * + * @param string $strPageCode + * @param string $strDiff + * @param integer $intNum + * @return array + */ + public function generateGrm(string $strPageCode, string $strDiff, int $intNum): array + { + $strDomain = $this->DomainModel->d_domain; + + return GanRaoMaModel::getGrmCode($strDomain, $strPageCode, $strDiff, $intNum); + } } diff --git a/code/config/view.php b/code/config/view.php index e00861a..2bdee2f 100644 --- a/code/config/view.php +++ b/code/config/view.php @@ -15,7 +15,7 @@ return [ // 模板文件名分隔符 'view_depr' => DIRECTORY_SEPARATOR, // 允许 PHP 函数调用 - 'tpl_deny_php' => false, + 'tpl_deny_php' => false, // 模板引擎普通标签开始标记 'tpl_begin' => '{', // 模板引擎普通标签结束标记 @@ -27,7 +27,7 @@ return [ // 自定义标签 - 'taglib_pre_load' => '\\template\\taglib\\Ad,\\template\\taglib\\Site,\\template\\taglib\\Rs,\\template\\taglib\\Novel', + 'taglib_pre_load' => '\\template\\taglib\\Ad,\\template\\taglib\\Site,\\template\\taglib\\Rs,\\template\\taglib\\Novel,\\template\\taglib\\Chapter', // 模板渲染缓存 'display_cache' => env('VIEW_DISPLAY_CACHE', false), diff --git a/code/extend/template/taglib/Chapter.php b/code/extend/template/taglib/Chapter.php new file mode 100644 index 0000000..a9ab90f --- /dev/null +++ b/code/extend/template/taglib/Chapter.php @@ -0,0 +1,166 @@ + ['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 = <<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 .= << \${$d_val}): ?> +EOT; + $strParse .= $content; + $strParse .= << + +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 = <<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 .= << \${$d_val}): ?> +EOT; + $strParse .= $content; + $strParse .= << + +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 = <<getChapterInfo( + {$n_id}, + {$c_sort_num}, + {$c_page} +); + + \${$c_key} = \$arrChapter ?? []; +?> +EOT; + + return $strParse; + } +} diff --git a/code/extend/template/taglib/Novel.php b/code/extend/template/taglib/Novel.php index 533650b..e45282e 100644 --- a/code/extend/template/taglib/Novel.php +++ b/code/extend/template/taglib/Novel.php @@ -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 = <<arrSortType; + +if (!empty(\$arrSort) && is_array(\$arrSort)): + +?> +EOT; + $strParse .= << \${$d_val}): ?> +EOT; + $strParse .= $content; + $strParse .= << + +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 = <<arrStatus; + +if (!empty(\$arrStatus) && is_array(\$arrStatus)): + +?> +EOT; + $strParse .= << \${$d_val}): ?> +EOT; + $strParse .= $content; + $strParse .= << + +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 = <<arrSex; + +if (!empty(\$arrSex) && is_array(\$arrSex)): + +?> +EOT; + $strParse .= << \${$d_val}): ?> +EOT; + $strParse .= $content; + $strParse .= << + +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 = <<getCategoryFilter(); + +if (!empty(\$arrCategory) && is_array(\$arrCategory)): + +?> +EOT; + $strParse .= << \${$d_val}): ?> +EOT; + $strParse .= $content; + $strParse .= << + +EOT; + return $strParse; + } } diff --git a/code/extend/template/taglib/Site.php b/code/extend/template/taglib/Site.php index 0a37b2a..72e4a9b 100644 --- a/code/extend/template/taglib/Site.php +++ b/code/extend/template/taglib/Site.php @@ -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; - 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 = <<generateGrm( + {$page_code}, + {$diff}, + {$num} +); + + \${$g_key} = \$arrChapter ?? []; +?> +EOT; + + return $strParse; + } } diff --git a/doc/TemplateTag.md b/doc/TemplateTag.md index 380e66f..db83734 100644 --- a/doc/TemplateTag.md +++ b/doc/TemplateTag.md @@ -142,6 +142,112 @@ {novel:info n_id="33" n_key="arrNovel01" n_forge_id="1125940" /} {$arrNovel01.n_name} +# 05、获取小说状态筛选条件 +# 传参与默认值(传参用下面的变量名,名称不需要$符号, 值的话如果用第三方变量作为值,需要带$符号): + $d_key ?? 'd_key'; # 查询出来的数据遍历的时候, 下标键变量的名称 + $d_val ?? 'd_val'; # 查询出来的数据遍历的时候, 值的名称 +# 样例 +{novel:status d_key="key" d_val="val"} +
  • 键: {$key} - 值: {$val}
  • +{/novel:status} + +# 06、获取小说性别筛选条件 +# 传参与默认值(传参用下面的变量名,名称不需要$符号, 值的话如果用第三方变量作为值,需要带$符号): + $d_key ?? 'd_key'; # 查询出来的数据遍历的时候, 下标键变量的名称 + $d_val ?? 'd_val'; # 查询出来的数据遍历的时候, 值的名称 +# 样例 +{novel:sex d_key="key" d_val="val"} +
  • 键: {$key} - 值: {$val}
  • +{/novel:sex} + +# 07、获取小说排序筛选条件 +# 传参与默认值(传参用下面的变量名,名称不需要$符号, 值的话如果用第三方变量作为值,需要带$符号): + $d_key ?? 'd_key'; # 查询出来的数据遍历的时候, 下标键变量的名称 + $d_val ?? 'd_val'; # 查询出来的数据遍历的时候, 值的名称 +# 样例 +{novel:sort d_key="key" d_val="val"} +
  • 键: {$key} - 值: {$val}
  • +{/novel:sort} +# 08、获取小说分类筛选条件 +# 传参与默认值(传参用下面的变量名,名称不需要$符号, 值的话如果用第三方变量作为值,需要带$符号): + $d_key ?? 'd_key'; # 查询出来的数据遍历的时候, 下标键变量的名称 + $d_val ?? 'd_val'; # 查询出来的数据遍历的时候, 值的名称 +# 样例 +{novel:category d_key="key" d_val="val"} +
  • 键: {$key} - 值: {$val}
  • +{/novel:category} + + +# 09、 获取指定小说多个章节数据并且遍历 +# 传参与默认值(传参用下面的变量名,名称不需要$符号, 值的话如果用第三方变量作为值,需要带$符号): + $count ?? '10'; # 查询条数 + $n_id ; # 小说ID + $sort_type ?? "all"; # 排序方式 + $diff_key ?? ""; # 缓存键值差异 + $cache_life ?? '0'; # 缓存时间,如果需要开启缓存,这个字段必须传,而且必须大于0 + $d_key ?? 'd_key'; # 查询出来的数据遍历的时候, 下标键变量的名称 + $d_val ?? 'd_val'; # 查询出来的数据遍历的时候, 值的名称 +# 样例 +{chapter:list count="10" n_id="$Request.get.n_id" d_key="d_key" d_val="chapter" cache_life="1000"} +
  • + Index: {$d_key} + 章节名称: {$chapter.c_name} + 章节序号: {$chapter.c_sort_num} +
  • +{/chapter:list} + + +# 10、 获取指定小说多个章节数据并且遍历 +# 传参与默认值(传参用下面的变量名,名称不需要$符号, 值的话如果用第三方变量作为值,需要带$符号): + $count ?? '10'; # 查询条数 + $n_id ; # 小说ID + $sort_type ?? "all"; # 排序方式 + $diff_key ?? ""; # 缓存键值差异 + $cache_life ?? '0'; # 缓存时间,如果需要开启缓存,这个字段必须传,而且必须大于0 + $d_key ?? 'd_key'; # 查询出来的数据遍历的时候, 下标键变量的名称 + $d_val ?? 'd_val'; # 查询出来的数据遍历的时候, 值的名称 +# 样例 +{chapter:list count="10" n_id="$Request.get.n_id" d_key="d_key" d_val="chapter" cache_life="1000"} +
  • + Index: {$d_key} + 章节名称: {$chapter.c_name} + 章节序号: {$chapter.c_sort_num} +
  • +{/chapter:list} + + +# 11、 获取指定小说分页数据并且遍历 +# 传参与默认值(传参用下面的变量名,名称不需要$符号, 值的话如果用第三方变量作为值,需要带$符号): + $page ?? '1'; # 页码 + $limit ?? '10'; # 查询条数 + $n_id ; # 小说ID + $sort_type ?? "all"; # 排序方式 + $button_num ?? "10"; # 分页按钮数量 + + $diff_key ?? ""; # 缓存键值差异 + $cache_life ?? '0'; # 缓存时间,如果需要开启缓存,这个字段必须传,而且必须大于0 + $d_key ?? 'd_key'; # 查询出来的数据遍历的时候, 下标键变量的名称 + $d_val ?? 'd_val'; # 查询出来的数据遍历的时候, 值的名称 + $p_val ?? 'p_val'; # 分页页码数据,这是一个数组。和之前控制器渲染的那个数组一致的。 + $func ; # 这个参数是一个回调方法名,用来渲染分页页码数据的,该方法需要在 NovelService 类里面实现,func(array $arrParams, array $arrSort, array $arrNovel) +# 样例 +{chapter:pager page="1" limit="10" n_id="$Request.get.n_id" d_key="d_key" d_val="chapter" cache_life="1000" button_num="3" sort_type="dao" func="generateChapterPager"} +
  • + Index: {$d_key} + 章节名称: {$chapter.c_name} + 章节序号: {$chapter.c_sort_num} +
  • +{/chapter:pager} + +# 12、 获取干扰码 +# 传参与默认值(传参用下面的变量名,名称不需要$符号, 值的话如果用第三方变量作为值,需要带$符号): + + $page_code ?? ""; # 页面编码 + $diff ?? ""; # 差异值 + $limit ?? '1'; # 查询条数 +# 样例 +{site:grm page_code="fdasfadsf" diff="fadsfdsa" num="10" g_key="arrGrm" /} +{php}var_dump($arrGrm);{/php} ``` \ No newline at end of file From cf9ad1f065d5d510a7a727463f693bde91dc2825 Mon Sep 17 00:00:00 2001 From: Default Date: Fri, 18 Apr 2025 16:19:54 +0800 Subject: [PATCH 2/2] debug --- code/app/home/config/router.php | 8 ++++---- code/app/home/view/default/test/test01/faker.html | 14 ++++++++++++++ code/app/home/view/default/test/test01/index.html | 8 ++++---- code/app/services/SiteContext.php | 15 +++++++++++++++ 4 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 code/app/home/view/default/test/test01/faker.html diff --git a/code/app/home/config/router.php b/code/app/home/config/router.php index fb51299..8cfa882 100644 --- a/code/app/home/config/router.php +++ b/code/app/home/config/router.php @@ -5,16 +5,16 @@ declare(strict_types=1); use app\home\controller\Index; use app\home\controller\Novel; use app\home\controller\User; +use app\services\SiteContext; use think\facade\Route; -Route::get('/article/fenlei/:category', function (\think\Request $Request) { - return view('test/test01/index.html'); +Route::get('/article/fenlei/:category', function (\think\Request $Request, SiteContext $SiteContext) { + return view($SiteContext->getHomeView()); }); - /** * 路由配置文件 */ @@ -83,7 +83,7 @@ $arrRoutes = [ * 完整路由 * 暂时不需要开放 * 使用: {site:nflurl gender="$strGender" category="$CategoryPinyin" status="all" order="all" page="1"/} - */ + */ // '/shuku/:strGender/:strCategory/:strStatus/:strOrder/page:intPage', // '/books/:strGender/:strCategory/:strStatus/:strOrder/page:intPage', // '/library/:strGender/:strCategory/:strStatus/:strOrder/page:intPage', diff --git a/code/app/home/view/default/test/test01/faker.html b/code/app/home/view/default/test/test01/faker.html new file mode 100644 index 0000000..2b71d63 --- /dev/null +++ b/code/app/home/view/default/test/test01/faker.html @@ -0,0 +1,14 @@ + + + +{novel:info n_id="$DomainModel->n_id" n_key="arrNovel01" n_forge_id="1125940" /} + {$arrNovel01.n_name} - 首页 + + + + {$arrNovel01.n_description} + + + + + diff --git a/code/app/home/view/default/test/test01/index.html b/code/app/home/view/default/test/test01/index.html index 14fad69..9c7e4d6 100644 --- a/code/app/home/view/default/test/test01/index.html +++ b/code/app/home/view/default/test/test01/index.html @@ -1,5 +1,5 @@ -{site:grm page_code="fdasfadsf" diff="fadsfdsa" num="10" g_key="arrGrm" /} -{php}var_dump($arrGrm);{/php} + @@ -50,8 +50,8 @@ - +{novel:info n_id="33" n_key="arrNovel01" n_forge_id="1125940" /} +{$arrNovel01.n_name} diff --git a/code/app/services/SiteContext.php b/code/app/services/SiteContext.php index 2820171..fd3044f 100644 --- a/code/app/services/SiteContext.php +++ b/code/app/services/SiteContext.php @@ -125,4 +125,19 @@ class SiteContext return GanRaoMaModel::getGrmCode($strDomain, $strPageCode, $strDiff, $intNum); } + + /** + * get home view + * + * @return string + */ + public function getHomeView(): string + { + if ($this->DomainModel->n_id > 0) { + $strView = 'test/test01/faker.html'; + } else { + $strView = 'test/test01/index.html'; + } + return $strView; + } }