This commit is contained in:
make
2025-11-13 16:47:27 +08:00
parent a8c71d28cb
commit a18222deac
16 changed files with 160 additions and 388 deletions

View File

@@ -1,4 +1,5 @@
<?php
namespace template\taglib;
use think\template\TagLib;
@@ -6,9 +7,19 @@ use think\template\TagLib;
class Ad extends TagLib
{
protected $tags = [
'listxp' => ['attr' => 'code,order,count,id,diff_key,cache_life,d_key,d_val,export_nam', 'close' => 1],
'list' => ['attr' => 'code,order,limit,id', 'close' => 1]
];
private function customBuildVar($mixedArgs)
{
if (substr($mixedArgs, 0, 1) == '$') {
return $this->autoBuildVar($mixedArgs);
} else {
return is_numeric($mixedArgs) ? $mixedArgs : "'" . $mixedArgs . "'";
}
}
/**
* list标签处理函数
*
@@ -33,4 +44,56 @@ $content
EOD;
return $parse;
}
/**
* novel 自定义标签
*/
public function tagListxp($tag, $content)
{
$code = $tag['code'] ?? '';
$order = $tag['order'] ?? 'asc';
$count = isset($tag['count']) ? (int)$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';
$p_val = $tag['p_val'] ?? 'p_val';
$export_name = $tag['export_name'] ?? '';
$code = $this->customBuildVar($code);
$order = $this->customBuildVar($order);
$count = $this->customBuildVar($count);
$arrDataName = randomString(5);
$strParse = <<<EOT
<?php
\$arrDataName = \\app\\model\\GuangGaoModel::getAdByCache("{$code}", {$count}, "{$order}");
EOT;
if (empty($export_name)) {
$strParse .= <<<EOT
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;
} else {
$strParse .= <<<EOT
\${$export_name} = \${$arrDataName};
?>
EOT;
}
return $strParse;
}
}