debug
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace app\home;
|
namespace app\home;
|
||||||
|
|
||||||
use app\model\ConverterMovel;
|
use app\model\ConverterMovel;
|
||||||
|
use app\model\GanRaoMaModel;
|
||||||
use think\App;
|
use think\App;
|
||||||
use think\exception\ValidateException;
|
use think\exception\ValidateException;
|
||||||
use think\facade\View;
|
use think\facade\View;
|
||||||
@@ -93,4 +94,21 @@ abstract class BaseController
|
|||||||
View::assign("TemplatesModel", $this->request->TemplatesModel);
|
View::assign("TemplatesModel", $this->request->TemplatesModel);
|
||||||
return View::fetch($strTemplate);
|
return View::fetch($strTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* generate GRM
|
||||||
|
*
|
||||||
|
* @param integer $intDeviceType
|
||||||
|
* @param integer $intNum
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function generateGrm(int $intDeviceType, string|int $strDiff, int $intNum)
|
||||||
|
{
|
||||||
|
$strDomain = $this->request->DomainModel->d_domain;
|
||||||
|
$strPageCode = $this->request->controller() . '@' . $this->request->action() . '@' . $intDeviceType;
|
||||||
|
|
||||||
|
$arrGRM = GanRaoMaModel::getGrmCode($strDomain, $strPageCode, $strDiff, $intNum);
|
||||||
|
|
||||||
|
View::assign("arrGRM", $arrGRM);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class Index extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function index(Request $Request)
|
public function index(Request $Request)
|
||||||
{
|
{
|
||||||
|
|
||||||
// 获取路由附加的参数
|
// 获取路由附加的参数
|
||||||
$boolIsMobile = $Request->param('boolIsMobile');
|
$boolIsMobile = $Request->param('boolIsMobile');
|
||||||
|
|
||||||
@@ -73,6 +74,7 @@ class Index extends BaseController
|
|||||||
|
|
||||||
$strView = $boolIsMobile ? '' : 'pc/index';
|
$strView = $boolIsMobile ? '' : 'pc/index';
|
||||||
|
|
||||||
|
$this->generateGrm(1, 0, 30);
|
||||||
return $this->rending($strView);
|
return $this->rending($strView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,6 +159,8 @@ class Index extends BaseController
|
|||||||
|
|
||||||
$strView = $boolIsMobile ? '' : 'pc/index';
|
$strView = $boolIsMobile ? '' : 'pc/index';
|
||||||
|
|
||||||
|
// 生成多少个干扰吗
|
||||||
|
$this->generateGrm(2, 0, 30);
|
||||||
return $this->rending($strView);
|
return $this->rending($strView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -713,8 +713,8 @@ class Novel extends BaseController
|
|||||||
* 小说章节列表页面
|
* 小说章节列表页面
|
||||||
*
|
*
|
||||||
* @param Request $Request
|
* @param Request $Request
|
||||||
* @param [type] $intNovelId 小说id
|
* @param int $intNovelId 小说id
|
||||||
* @param integer $intPage 目录分页
|
* @param int $intPage 目录分页
|
||||||
* @param string $strOrder 正序倒叙:zheng/dao
|
* @param string $strOrder 正序倒叙:zheng/dao
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@@ -785,7 +785,13 @@ class Novel extends BaseController
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
$strView = $boolIsMobile ? '' : 'pc/getNovelChapterAll';
|
if ($boolIsMobile) {
|
||||||
|
$strView = '';
|
||||||
|
$this->generateGrm(1, $intNovelId . '-' . $intPage, 30);
|
||||||
|
} else {
|
||||||
|
$strView = 'pc/getNovelChapterAll';
|
||||||
|
$this->generateGrm(2, $intNovelId . '-' . $intPage, 20);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->rending($strView);
|
return $this->rending($strView);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,28 @@ class GanRaoMaModel extends MongoModel
|
|||||||
protected $strCollection = 'gan_rao_ma';
|
protected $strCollection = 'gan_rao_ma';
|
||||||
|
|
||||||
|
|
||||||
|
static public $arrOptions = [
|
||||||
|
'typeMap' => [
|
||||||
|
'root' => 'array',
|
||||||
|
'document' => 'array',
|
||||||
|
'array' => 'array',
|
||||||
|
],
|
||||||
|
'projection' => [
|
||||||
|
'_id' => 0,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 可选属性
|
* 可选属性
|
||||||
*/
|
*/
|
||||||
const POSSIBLE_ATTRIBUTES = [
|
const POSSIBLE_ATTRIBUTES = [
|
||||||
'draggable', 'date-time', 'lang', 'id', 'dir', 'class'
|
'draggable',
|
||||||
|
'date-time',
|
||||||
|
'lang',
|
||||||
|
'id',
|
||||||
|
'dir',
|
||||||
|
'class'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,6 +73,8 @@ class GanRaoMaModel extends MongoModel
|
|||||||
'<p id="%s" class="%s" style="display:none;">%s</p>',
|
'<p id="%s" class="%s" style="display:none;">%s</p>',
|
||||||
'<strong id="%s" class="%s" style="display:none;">%s</strong>',
|
'<strong id="%s" class="%s" style="display:none;">%s</strong>',
|
||||||
'<em id="%s" class="%s" style="display:none;">%s</em>',
|
'<em id="%s" class="%s" style="display:none;">%s</em>',
|
||||||
|
|
||||||
|
'<%s id="%s"> </%s>',
|
||||||
];
|
];
|
||||||
|
|
||||||
const LETTERS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
const LETTERS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||||
@@ -113,7 +132,6 @@ class GanRaoMaModel extends MongoModel
|
|||||||
|
|
||||||
// 拼接标签
|
// 拼接标签
|
||||||
$strHtmlResult .= "<{$strTagName}{$strAttributes}></{$strTagName}>\n";
|
$strHtmlResult .= "<{$strTagName}{$strAttributes}></{$strTagName}>\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $strHtmlResult;
|
return $strHtmlResult;
|
||||||
@@ -169,61 +187,57 @@ class GanRaoMaModel extends MongoModel
|
|||||||
*
|
*
|
||||||
* @param string $strDomain 域名
|
* @param string $strDomain 域名
|
||||||
* @param string $strPageCode 视图编码
|
* @param string $strPageCode 视图编码
|
||||||
* @param int $intLine 所在行数
|
|
||||||
* @param string $strDifference 差异
|
* @param string $strDifference 差异
|
||||||
* @param int $intStartNumber 生成标签,随机起始位置 随机生成(10-20)个标签 10
|
* @param int $intNum 生成数量
|
||||||
* @param int $intEndNumber 生成标签,随机结束位置 随机生成(10-20)个标签 20
|
|
||||||
* @param int $intIndex 把标签转成数组,这个是索引,根据索引取哪一行标签
|
|
||||||
* @param int $intType 生成标签类型: 1.标准html标签,2.自定义标签
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
static public function getGrmCode($strDomain, $strPageCode, $intLine, $strDifference, $intStartNumber, $intEndNumber,$intIndex,$intType): string
|
static public function getGrmCode($strDomain, $strPageCode, $strDifference, $intNum)
|
||||||
{
|
{
|
||||||
|
|
||||||
$arrFilter = [
|
$arrFilter = [
|
||||||
'grm_domain' => (string) $strDomain,
|
'grm_domain' => (string) $strDomain,
|
||||||
'grm_page_code' => (string) $strPageCode,
|
'grm_page_code' => (string) $strPageCode,
|
||||||
'grm_page_line' => (string)$intLine,
|
|
||||||
'grm_page_diff' => (string) $strDifference,
|
'grm_page_diff' => (string) $strDifference,
|
||||||
];
|
];
|
||||||
$arrGrm = self::getInstance()->getOne($arrFilter);
|
$arrResult = self::getInstance()->getOne($arrFilter, self::$arrOptions);
|
||||||
|
|
||||||
if (empty($arrGrm)) {
|
if (empty($arrResult)) {
|
||||||
if($intType == 1){
|
|
||||||
$intNum = mt_rand($intStartNumber, $intEndNumber);
|
// $intNum = mt_rand($intStartNumber, $intEndNumber);
|
||||||
$arrGrmCode = self::$arrSelfClosing;
|
// $arrGrmCode = self::$arrSelfClosing;
|
||||||
shuffle($arrGrmCode);
|
// shuffle($arrGrmCode);
|
||||||
$arrGrmCode = array_slice($arrGrmCode, 0, $intNum);
|
// $arrGrmCode = array_slice($arrGrmCode, 0, $intNum);
|
||||||
$strGrmCode = implode('', $arrGrmCode);
|
// $strGrmCode = implode('', $arrGrmCode);
|
||||||
$intRandNum = substr_count($strGrmCode, '%s');
|
// $intRandNum = substr_count($strGrmCode, '%s');
|
||||||
$arrRandStr = self::generateRandomStrings($intRandNum);
|
// $arrRandStr = self::generateRandomStrings($intRandNum);
|
||||||
$strGrmCode = sprintf($strGrmCode, ...$arrRandStr);
|
// $strGrmCode = sprintf($strGrmCode, ...$arrRandStr);
|
||||||
}else{
|
|
||||||
$strGrmCode = self::generateRandomCustomizeHtml($intStartNumber, $intEndNumber);
|
$arrGrmCode = [];
|
||||||
|
while ($intNum-- > 0) {
|
||||||
|
$arrGrmCode[] = self::generateRandomCustomizeHtml(mt_rand(1, 3), mt_rand(4, 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
$arrData = $arrFilter;
|
$arrData = $arrFilter;
|
||||||
$arrData['grm_code'] = $strGrmCode;
|
$arrData['grm_code'] = $arrGrmCode;
|
||||||
self::getInstance()->insert($arrData);
|
self::getInstance()->insert($arrData);
|
||||||
} else {
|
} else {
|
||||||
$strGrmCode = $arrGrm['grm_code'];
|
$arrGrmCode = $arrResult['grm_code'];
|
||||||
}
|
}
|
||||||
// $arrGrmCode = self::splitTagsToArray($strGrmCode);
|
|
||||||
// $strGrmCode = $arrGrmCode[$intIndex];
|
return $arrGrmCode;
|
||||||
// echo $intIndex;
|
|
||||||
return $strGrmCode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function splitTagsToArray(string $htmlTags): array
|
static public function splitTagsToArray(string $htmlTags): array
|
||||||
{
|
{
|
||||||
// 按换行符分割,兼容不同系统
|
// 按换行符分割,兼容不同系统
|
||||||
$tagsArray = preg_split('/\r\n|\n|\r/', $htmlTags);
|
$tagsArray = preg_split('/\r\n|\n|\r/', $htmlTags);
|
||||||
|
|
||||||
// 去除空白行并清理首尾空格
|
// 去除空白行并清理首尾空格
|
||||||
$tagsArray = array_filter(array_map('trim', $tagsArray), function($tag) {
|
$tagsArray = array_filter(array_map('trim', $tagsArray), function ($tag) {
|
||||||
return !empty($tag);
|
return !empty($tag);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 重置索引
|
// 重置索引
|
||||||
return array_values($tagsArray);
|
return array_values($tagsArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ return [
|
|||||||
'collection' => 'gan_rao_ma',
|
'collection' => 'gan_rao_ma',
|
||||||
'indexes' => [
|
'indexes' => [
|
||||||
[
|
[
|
||||||
'key' => ['grm_domain' => 1, 'grm_page_code' => 1, 'grm_page_line' => 1, 'grm_page_diff' => 1],
|
'key' => ['grm_domain' => 1, 'grm_page_code' => 1, 'grm_page_diff' => 1],
|
||||||
'options' => ['unique' => true]
|
'options' => ['unique' => true]
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user