debug
This commit is contained in:
2
code/extend/.gitignore
vendored
2
code/extend/.gitignore
vendored
@@ -1,2 +0,0 @@
|
||||
*
|
||||
!.gitignore
|
||||
37
code/extend/SeoTdkHelper.php
Normal file
37
code/extend/SeoTdkHelper.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use app\admin\model\SiteModel;
|
||||
use app\admin\model\SeoTdkConfigModel;
|
||||
|
||||
class SeoTdkHelper
|
||||
{
|
||||
public static function getProcessedTdk($pageCode, $extraReplacements = [])
|
||||
{
|
||||
// 基础变量
|
||||
$strSiteName = SiteModel::getValBySiteIdByValCode('site_name');
|
||||
$strDomain = SiteModel::getValBySiteIdByValCode('site_domain');
|
||||
|
||||
// 页面 SEO 配置
|
||||
$SeoTdkConfigModel = SeoTdkConfigModel::getValByCode($pageCode);
|
||||
$strTdkTitle = $SeoTdkConfigModel['stc_title'] ?? '';
|
||||
$strTdkKeywords = $SeoTdkConfigModel['stc_keywords'] ?? '';
|
||||
$strTdkDescription = $SeoTdkConfigModel['stc_description'] ?? '';
|
||||
|
||||
// 默认变量
|
||||
$replacements = array_merge([
|
||||
'{{{site_name}}}' => $strSiteName,
|
||||
'{{{site_domain}}}' => $strDomain,
|
||||
], $extraReplacements);
|
||||
|
||||
// 替换
|
||||
$strTdkTitle = strtr($strTdkTitle, $replacements);
|
||||
$strTdkKeywords = strtr($strTdkKeywords, $replacements);
|
||||
$strTdkDescription = strtr($strTdkDescription, $replacements);
|
||||
|
||||
return [
|
||||
'strTdkTitle' => $strTdkTitle,
|
||||
'strTdkKeywords' => $strTdkKeywords,
|
||||
'strTdkDescription' => $strTdkDescription,
|
||||
];
|
||||
}
|
||||
}
|
||||
133
code/extend/processor/ImageProcessor.php
Normal file
133
code/extend/processor/ImageProcessor.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace processor;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use think\Exception;
|
||||
|
||||
class ImageProcessor
|
||||
{
|
||||
private static $instance = null;
|
||||
private $client;
|
||||
private $key;
|
||||
|
||||
private function __construct($key)
|
||||
{
|
||||
$this->client = new Client([
|
||||
'verify' => false // 忽略证书检测
|
||||
]);
|
||||
$this->key = $key;
|
||||
}
|
||||
|
||||
public static function getInstance($key = 0x88)
|
||||
{
|
||||
if (self::$instance == null) {
|
||||
self::$instance = new ImageProcessor($key = 0x88);
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function downloadAndEncryptImage($imageUrl, $directory)
|
||||
{
|
||||
try {
|
||||
// 下载图片
|
||||
$response = $this->client->get($imageUrl);
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
throw new Exception("Failed to download image: $imageUrl");
|
||||
}
|
||||
$imageData = $response->getBody()->getContents();
|
||||
|
||||
// 加密图片
|
||||
$encryptedData = $this->encrypt($imageData);
|
||||
|
||||
// 生成目录路径
|
||||
$relativePath = $this->generatePath($directory);
|
||||
|
||||
// 保存加密后的图片
|
||||
file_put_contents(public_path() . $relativePath, $encryptedData);
|
||||
|
||||
return '/' . $relativePath;
|
||||
} catch (RequestException $e) {
|
||||
throw new Exception("Request Error: " . $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
throw new Exception("Error: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function downloadImage( $intXiaoShuoSourceId,$imageUrl, $directory)
|
||||
{
|
||||
try {
|
||||
// 下载图片
|
||||
$response = $this->client->get($imageUrl);
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
throw new Exception("Failed to download image: $imageUrl");
|
||||
}
|
||||
$imageData = $response->getBody()->getContents();
|
||||
|
||||
// 加密图片
|
||||
//$encryptedData = $this->encrypt($imageData);
|
||||
|
||||
// 生成目录路径
|
||||
$relativePath = $this->generateImgPath($directory,$intXiaoShuoSourceId);
|
||||
|
||||
// 保存图片
|
||||
file_put_contents(public_path() . $relativePath, $imageData);
|
||||
|
||||
return '/' . $relativePath;
|
||||
} catch (RequestException $e) {
|
||||
throw new Exception("Request Error: " . $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
throw new Exception("Error: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function encrypt($data)
|
||||
{
|
||||
$bytes = array_values(unpack('C*', $data));
|
||||
$len = count($bytes);
|
||||
|
||||
for ($i = 0; $i < $len; $i++) {
|
||||
$bytes[$i] ^= $this->key;
|
||||
}
|
||||
|
||||
return pack('C*', ...$bytes);
|
||||
}
|
||||
|
||||
private function generateImgPath($directory,$intXiaoShuoSourceId)
|
||||
{
|
||||
$relativePath = $directory . '/pic/'.$intXiaoShuoSourceId;
|
||||
$basePath = public_path() . $relativePath;
|
||||
if (!is_dir($basePath)) {
|
||||
mkdir($basePath, 0777, true);
|
||||
}
|
||||
|
||||
$filePath = $relativePath . '.jpg'; ;
|
||||
return $filePath;
|
||||
}
|
||||
|
||||
private function generatePath($directory)
|
||||
{
|
||||
$datePath = date('Y/m/d');
|
||||
$hash = md5(uniqid(rand(), true));
|
||||
$hashPath = substr($hash, 0, 2) . '/' . substr($hash, 2, 2);
|
||||
|
||||
$relativePath = $directory . '/' . $datePath . '/' . $hashPath;
|
||||
$basePath = public_path() . $relativePath;
|
||||
if (!is_dir($basePath)) {
|
||||
mkdir($basePath, 0777, true);
|
||||
}
|
||||
|
||||
$filePath = $relativePath . '/' . uniqid() . '.jpg';
|
||||
return $filePath;
|
||||
}
|
||||
}
|
||||
|
||||
// // 示例用法
|
||||
// try {
|
||||
// $imageProcessor = ImageProcessor::getInstance();
|
||||
// $savedPath = $imageProcessor->downloadAndEncryptImage('https://example.com/path/to/image.jpg', 'abc');
|
||||
// echo "图片加密并保存到: " . $savedPath;
|
||||
// } catch (Exception $e) {
|
||||
// echo "错误: " . $e->getMessage();
|
||||
// }
|
||||
215
code/extend/template/page/CusteomPage.php
Normal file
215
code/extend/template/page/CusteomPage.php
Normal file
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
namespace template\page;
|
||||
|
||||
use think\Paginator;
|
||||
|
||||
class CusteomPage extends Paginator
|
||||
{
|
||||
/**
|
||||
* 上一页按钮
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
protected function getPreviousButton(string $text = "上一页"): string
|
||||
{
|
||||
|
||||
if ($this->currentPage() <= 1) {
|
||||
return $this->getDisabledTextWrapper($text);
|
||||
}
|
||||
|
||||
$url = $this->url(
|
||||
$this->currentPage() - 1
|
||||
);
|
||||
|
||||
return $this->getPageLinkWrapper($url, $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下一页按钮
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
protected function getNextButton(string $text = '下一页'): string
|
||||
{
|
||||
if (!$this->hasMore) {
|
||||
return $this->getDisabledTextWrapper($text);
|
||||
}
|
||||
|
||||
$url = $this->url($this->currentPage() + 1);
|
||||
|
||||
return $this->getPageLinkWrapper($url, $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* 页码按钮
|
||||
* @return string
|
||||
*/
|
||||
/**
|
||||
* 页码按钮
|
||||
* @return string
|
||||
*/
|
||||
protected function getLinks(): string
|
||||
{
|
||||
if ($this->simple) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$block = [
|
||||
'first' => null,
|
||||
'slider' => null,
|
||||
'last' => null,
|
||||
];
|
||||
|
||||
if ($this->lastPage <= 3) {
|
||||
// 如果总页数少于或等于3,显示所有页码
|
||||
$block['first'] = $this->getUrlRange(1, $this->lastPage);
|
||||
} else {
|
||||
if ($this->currentPage == 1) {
|
||||
// 如果当前页码是第一页,显示前两页和第三页
|
||||
$block['first'] = $this->getUrlRange(1, 3);
|
||||
} elseif ($this->currentPage == $this->lastPage) {
|
||||
// 如果当前页码是最后一页,显示最后三页
|
||||
$block['first'] = $this->getUrlRange($this->lastPage - 2, $this->lastPage);
|
||||
} else {
|
||||
// 否则,显示当前页码及其前后各一页
|
||||
$block['first'] = $this->getUrlRange($this->currentPage - 1, $this->currentPage + 1);
|
||||
}
|
||||
}
|
||||
|
||||
$html = '';
|
||||
|
||||
if (is_array($block['first'])) {
|
||||
$html .= $this->getUrlLinks($block['first']);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染分页html
|
||||
* @return mixed
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
if ($this->hasPages()) {
|
||||
if ($this->simple) {
|
||||
return sprintf(
|
||||
'<ul class="pager">%s %s</ul>',
|
||||
$this->getPreviousButton(),
|
||||
$this->getNextButton()
|
||||
);
|
||||
} else {
|
||||
return sprintf(
|
||||
'<ul class="pagination justify-content-center">%s %s %s %s</ul>%s',
|
||||
$this->getPreviousButton(),
|
||||
$this->getLinks(),
|
||||
$this->getNextButton(),
|
||||
$this->getTotalInfo(),
|
||||
$this->getTargePage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTargePage(): string
|
||||
{
|
||||
return '<div class="jump-box">
|
||||
<input type="number" name="page" class="page-link pagination-num" placeholder="跳转页">
|
||||
<button type="button" data-url="" data-max="' . $this->lastPage() . '"
|
||||
class="btn btn-primary btn-sm pagination-click">跳转</button>
|
||||
</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTotalInfo(): string
|
||||
{
|
||||
return '<li class="page-item"><span class="page-link">' . $this->currentPage() . '/' . $this->lastPage() . '</span></li>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成一个可点击的按钮
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $page
|
||||
* @return string
|
||||
*/
|
||||
protected function getAvailablePageWrapper(string $url, string $page): string
|
||||
{
|
||||
return '<li class="page-item"><a class="page-link" href="' . htmlentities($url) . '">' . $page . '</a></li>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成一个禁用的按钮
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
protected function getDisabledTextWrapper(string $text): string
|
||||
{
|
||||
return '<li class="page-item"><span class="page-link">' . $text . '</span></li>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成一个激活的按钮
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
protected function getActivePageWrapper(string $text): string
|
||||
{
|
||||
return '<li class="page-item active"><span class="page-link">' . $text . '</span></li>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成省略号按钮
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDots(): string
|
||||
{
|
||||
return $this->getDisabledTextWrapper('...');
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量生成页码按钮.
|
||||
*
|
||||
* @param array $urls
|
||||
* @return string
|
||||
*/
|
||||
protected function getUrlLinks(array $urls): string
|
||||
{
|
||||
$html = '';
|
||||
|
||||
foreach ($urls as $page => $url) {
|
||||
$html .= $this->getPageLinkWrapper($url, $page);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成普通页码按钮
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $page
|
||||
* @return string
|
||||
*/
|
||||
protected function getPageLinkWrapper(string $url, string $page): string
|
||||
{
|
||||
if ($this->currentPage() == $page) {
|
||||
return $this->getActivePageWrapper($page);
|
||||
}
|
||||
|
||||
return $this->getAvailablePageWrapper($url, $page);
|
||||
}
|
||||
}
|
||||
36
code/extend/template/taglib/Ad.php
Normal file
36
code/extend/template/taglib/Ad.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace template\taglib;
|
||||
|
||||
use think\template\TagLib;
|
||||
|
||||
class Ad extends TagLib
|
||||
{
|
||||
protected $tags = [
|
||||
'list' => ['attr' => 'code,order,limit,id', 'close' => 1]
|
||||
];
|
||||
|
||||
/**
|
||||
* list标签处理函数
|
||||
*
|
||||
* @param array $tag
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public function tagList($tag, $content)
|
||||
{
|
||||
$code = $tag['code'] ?? '';
|
||||
$order = $tag['order'] ?? 'asc';
|
||||
$limit = isset($tag['limit']) ? (int)$tag['limit'] : 10;
|
||||
$id = $tag['id'] ?? 'ad';
|
||||
|
||||
$parse = <<<EOD
|
||||
<?php
|
||||
\$adList = \\app\\admin\\model\\GuangGaoModel::getAdByCache("{$code}", {$limit}, "{$order}");
|
||||
?>
|
||||
{volist name="adList" id="{$id}"}
|
||||
$content
|
||||
{/volist}
|
||||
EOD;
|
||||
return $parse;
|
||||
}
|
||||
}
|
||||
35
code/extend/template/taglib/Rs.php
Normal file
35
code/extend/template/taglib/Rs.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace template\taglib;
|
||||
|
||||
use think\template\TagLib;
|
||||
|
||||
class Rs extends TagLib
|
||||
{
|
||||
protected $tags = [
|
||||
'list' => ['attr' => 'order,limit,id', 'close' => 1]
|
||||
];
|
||||
|
||||
/**
|
||||
* list标签处理函数
|
||||
*
|
||||
* @param array $tag
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public function tagList($tag, $content)
|
||||
{
|
||||
$order = $tag['order'] ?? 'asc';
|
||||
$limit = isset($tag['limit']) ? (int)$tag['limit'] : 10;
|
||||
$id = $tag['id'] ?? 'vo';
|
||||
|
||||
$parse = <<<EOD
|
||||
<?php
|
||||
\$adRs = \\app\\admin\\model\\ReSouModel::getRsByCache( {$limit}, "{$order}");
|
||||
?>
|
||||
{volist name="adRs" id="{$id}"}
|
||||
$content
|
||||
{/volist}
|
||||
EOD;
|
||||
return $parse;
|
||||
}
|
||||
}
|
||||
140
code/extend/template/taglib/Site.php
Normal file
140
code/extend/template/taglib/Site.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace template\taglib;
|
||||
|
||||
use think\template\TagLib;
|
||||
|
||||
class Site extends TagLib
|
||||
{
|
||||
protected $tags = [
|
||||
'cfg' => ['attr' => 'code,encode', 'close' => 0],
|
||||
'adcfg' => ['attr' => 'code,encode', 'close' => 0],
|
||||
'seotdk' => ['attr' => 'code,encode,valcode', 'close' => 0],
|
||||
'site' => ['attr' => 'code,encode,valcode', 'close' => 0],
|
||||
'wz' => ['attr' => 'wz', 'close' => 0],
|
||||
];
|
||||
|
||||
/**
|
||||
* site 标签处理函数
|
||||
*
|
||||
* @param array $tag
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public function tagSite($tag)
|
||||
{
|
||||
$encode = isset($tag['encode']) ? $tag['encode'] : 'false';
|
||||
$valcode = isset($tag['valcode']) ? $tag['valcode'] : '';
|
||||
|
||||
$parse = <<<EOD
|
||||
<?php
|
||||
\$strCfgVal = \\app\\admin\\model\\SiteModel::getValBySiteIdByValCode("{$valcode}");
|
||||
if ("{$encode}" === "true") {
|
||||
echo customEntities(\$strCfgVal);
|
||||
} else {
|
||||
echo \$strCfgVal ;
|
||||
}
|
||||
?>
|
||||
EOD;
|
||||
return $parse;
|
||||
}
|
||||
|
||||
/**
|
||||
* cfg 标签处理函数
|
||||
*
|
||||
* @param array $tag
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public function tagCfg($tag)
|
||||
{
|
||||
$code = isset($tag['code']) ? $tag['code'] : '';
|
||||
$encode = isset($tag['encode']) ? $tag['encode'] : 'false';
|
||||
|
||||
$parse = <<<EOD
|
||||
<?php
|
||||
\$strCfgVal = \\app\\admin\\model\\SystemConfigModel::getValByCode("{$code}");
|
||||
if ("{$encode}" === "true") {
|
||||
echo customEntities(\$strCfgVal);
|
||||
} else {
|
||||
echo \$strCfgVal;
|
||||
}
|
||||
?>
|
||||
EOD;
|
||||
return $parse;
|
||||
}
|
||||
|
||||
/**
|
||||
* adcfg标签处理函数
|
||||
*
|
||||
* @param array $tag
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public function tagAdcfg($tag)
|
||||
{
|
||||
$code = isset($tag['code']) ? $tag['code'] : '';
|
||||
$encode = isset($tag['encode']) ? $tag['encode'] : 'false';
|
||||
|
||||
$parse = <<<EOD
|
||||
<?php
|
||||
\$strCfgVal = \\app\\admin\\model\\GuangGaoPeiZhiModel::getValByCode("{$code}");
|
||||
if ("{$encode}" === "true") {
|
||||
echo customEntities(\$strCfgVal);
|
||||
} else {
|
||||
echo \$strCfgVal;
|
||||
}
|
||||
?>
|
||||
EOD;
|
||||
return $parse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* seotdk 标签处理函数
|
||||
*
|
||||
* @param array $tag
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public function tagSeotdk($tag)
|
||||
{
|
||||
$code = isset($tag['code']) ? $tag['code'] : '';
|
||||
$encode = isset($tag['encode']) ? $tag['encode'] : 'false';
|
||||
$valcode = isset($tag['valcode']) ? $tag['valcode'] : '';
|
||||
|
||||
$parse = <<<EOD
|
||||
<?php
|
||||
\$strCfgVal = \\app\\admin\\model\\SeoTdkConfigModel::getValByCodeByValCode("{$code}", "{$valcode}");
|
||||
if ("{$encode}" === "true") {
|
||||
echo customEntities(\$strCfgVal);
|
||||
} else {
|
||||
var_dump( \$strCfgVal);
|
||||
}
|
||||
?>
|
||||
EOD;
|
||||
return $parse;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 文字处理函数
|
||||
*
|
||||
* @param array $tag
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public function tagWz($tag)
|
||||
{
|
||||
$strWords = isset($tag['wz']) ? $tag['wz'] : '';
|
||||
|
||||
$parse = <<<EOD
|
||||
<?php
|
||||
\$strCfgVal = \\template\\ziku\\WordsEntities::getWords("{$strWords}");
|
||||
echo \$strCfgVal;
|
||||
?>
|
||||
EOD;
|
||||
return $parse;
|
||||
}
|
||||
}
|
||||
18
code/extend/template/ziku/WordsEntities.php
Normal file
18
code/extend/template/ziku/WordsEntities.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace template\ziku;
|
||||
|
||||
|
||||
class WordsEntities
|
||||
{
|
||||
static $arrZiKu = [];
|
||||
|
||||
static public function getWords($strWords)
|
||||
{
|
||||
|
||||
if (!isset(self::$arrZiKu[$strWords])) {
|
||||
self::$arrZiKu[$strWords] = customEntities($strWords);
|
||||
}
|
||||
return self::$arrZiKu[$strWords];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user