This commit is contained in:
Gitea
2022-03-30 09:13:50 +08:00
parent 15dfc6576b
commit 557aa3c555
179 changed files with 6115 additions and 4092 deletions

View File

@@ -4,7 +4,7 @@
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2020年06月27日
* 评论控制器
* 评论控制器
*/
namespace app\home\controller;
@@ -91,7 +91,7 @@ class CommentController extends Controller
session('lastsub', time()); // 记录最后提交时间
$this->log('文章' . $contentid . '评论提交成功!');
if ($this->config('comment_send_mail') && $this->config('message_send_to')) {
$mail_subject = "PbootCMS】您有新的文章评论信息,请注意查收!";
$mail_subject = "" . CMSNAME . "】您有新的文章评论信息,请注意查收!";
$mail_body = '评论内容:' . $comment . '<br>';
$mail_body .= '<br>来自网站 ' . get_http_url() . ' ' . date('Y-m-d H:i:s') . '';
sendmail($this->config(), $this->config('message_send_to'), $mail_subject, $mail_body);

View File

@@ -4,7 +4,7 @@
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2020年3月8日
* 表单控制器
* 表单控制器
*/
namespace app\home\controller;
@@ -89,7 +89,7 @@ class FormController extends Controller
session('lastsub', time()); // 记录最后提交时间
$this->log('提交表单数据成功!');
if ($this->config('form_send_mail') && $this->config('message_send_to')) {
$mail_subject = "PbootCMS】您有新的" . $value->form_name . "信息,请注意查收!";
$mail_subject = "" . CMSNAME . "】您有新的" . $value->form_name . "信息,请注意查收!";
$mail_body .= '<br>来自网站 ' . get_http_url() . ' ' . date('Y-m-d H:i:s') . '';
sendmail($this->config(), $this->config('message_send_to'), $mail_subject, $mail_body);
}

View File

@@ -54,7 +54,7 @@ class IndexController extends Controller
}
}
// 地址去后缀,并且强制模式
// 判断是否存在后缀
$url_rule_suffix = substr($this->config('url_rule_suffix'), 1);
$suffix = false;
$slash = false;
@@ -65,11 +65,12 @@ class IndexController extends Controller
$slash = true;
$path = trim($path, '/');
}
$path = escape_string($path);
$path_arr = $path ? explode('/', $path) : array();
// 开始路由
if (isset($path_arr) && count($path_arr) > 0) {
switch ($path_arr[0]) {
if (isset($path_arr) && count($path_arr) > 0 && preg_match('/^[\w\-\/]+$/', $path)) {
switch (strtolower($path_arr[0])) {
case 'search':
case 'keyword':
$search = new SearchController();
@@ -85,10 +86,14 @@ class IndexController extends Controller
$form->index();
break;
case 'sitemap':
case 'Sitemap':
case 'sitemap_xml':
$sitemap = new SitemapController();
$sitemap->index();
break;
case 'sitemap_txt':
$sitemap = new SitemapController();
$sitemap->linkTxt();
break;
case 'tag':
$tag = new TagController();
$tag->index();
@@ -101,37 +106,68 @@ class IndexController extends Controller
$comment = new CommentController();
$comment->{$path_arr[1]}();
break;
case 'spider':
$spider = new SpiderController();
$spider->index();
break;
default:
if (get($path_arr[0])) {
$this->getIndex();
$url_break_char = $this->config('url_break_char') ?: '_';
$url_rule_content_path = $this->config('url_rule_content_path') ? true : false;
$err = '';
$iscontent = false;
// 开始进行地址匹配
if (! $suffix && ! ! $sort = $this->model->getSort($path)) {
// 栏目名称,即栏目全路径匹配
} elseif (preg_match('/^([a-zA-Z0-9\-\/]+)' . $url_break_char . '([0-9]+)$/i', $path, $matchs) && ! ! $sort = $this->model->getSort($matchs[1])) {
// 栏目名称_分页栏目分页的情况
define('CMS_PAGE_CUSTOM', true); // 设置走自定义CMS分页
$_GET['page'] = $matchs[2]; // 设置分页参数
} else {
// 假设详情页地址,详情页匹配前段为栏目路径
$temp = $path_arr;
$contenturl = array_pop($temp);
$sorturl = implode('/', $temp);
$url_break_char = $this->config('url_break_char') ?: '_';
// 开始进行匹配
if (! ! $sort = $this->model->getSort($path)) {
// 栏目名称
$iscontent = false;
} elseif (preg_match('/^([a-zA-Z0-9\-\/]+)' . $url_break_char . '([0-9]+)$/i', $path, $matchs) && ! ! $sort = $this->model->getSort($matchs[1])) {
// 栏目名称_分页
$iscontent = false;
define('CMS_PAGE_CUSTOM', true);
$_GET['page'] = $matchs[2]; // 分页
} elseif (! ! $sorturl && ! ! $sort = $this->model->getSort($sorturl)) {
// 栏目名称/内容名称或ID要在第2个判断【栏目名称_分页】后
$data = $this->model->getContent($contenturl);
$iscontent = true;
} elseif (preg_match('/^list' . $url_break_char . '[0-9]+|about' . $url_break_char . '[0-9]+$/', $sorturl)) {
// 模型默认名称_栏目ID/内容名称或ID
$data = $this->model->getContent($contenturl);
$iscontent = true;
} else {
preg_match('/^([a-zA-Z0-9\-\/]+)(' . $url_break_char . '([0-9]+))?' . $url_break_char . '([0-9]+)$/i', $path, $matchs);
if ($url_rule_content_path && ! ! $data = $this->model->getContent($path)) {
$iscontent = true; // 短路径情况
} elseif (! $url_rule_content_path) {
// 详情页至少是2级对地址进行栏目和内容路径拆分访问详情页
$part1 = dirname($path);
$part2 = basename($path);
while ($part1 != '.') {
if ((! ! $sort = $this->model->getSort($part1)) && ! ! $data = $this->model->getContent($part2)) {
// 栏目名称/内容名称或ID
$iscontent = true;
$scode = $sort->scode;
break;
} elseif (preg_match('/^([a-zA-Z0-9\-\/]+)' . $url_break_char . '([0-9]+)$/i', $part1, $matchs) && ! ! $model = $this->model->checkModelUrlname($matchs[1])) {
// 模型名称_栏目ID/内容名称或ID
$data = $this->model->getContent($part2);
$iscontent = true;
$scode = $matchs[2];
// 限制串模型多路径
if (! ! $data->urlname && $matchs[1] != $data->urlname) {
$err = true;
}
break;
} else {
$part2 = basename($part1) . '/' . $part2;
$part1 = dirname($part1);
}
}
// 限制串栏目多路径
if ($scode != $data->scode) {
$err = true;
}
// 限制串内容ID及名称多路径
if (! ! $data->filename && $part2 != $data->filename) {
$err = true;
}
}
// 执行未配置栏目名称但是配置了模型路径的情况路径匹配
if (! $iscontent) {
preg_match('/^([a-zA-Z0-9\-\/]+)(' . $url_break_char . '([0-9]+))?' . $url_break_char . '([0-9]+)$/i', $path, $matchs);
if ($matchs[2] && $model = $this->model->checkModelUrlname($matchs[1])) {
// 模型名称_栏目ID_分页
define('CMS_PAGE_CUSTOM', false);
@@ -140,50 +176,47 @@ class IndexController extends Controller
} elseif (! ! $model = $this->model->checkModelUrlname($matchs[1])) {
// 模型名称_栏目ID
$sort = $this->model->getSort($matchs[4]);
} elseif (preg_match('/^([a-zA-Z0-9\-\/]+)' . $url_break_char . '([0-9]+)$/i', $sorturl, $matchs)) {
// 模型名称_栏目ID/内容名称或ID
if (! ! $model = $this->model->checkModelUrlname($matchs[1])) {
$data = $this->model->getContent($contenturl);
$iscontent = true;
}
}
// 限制串模型和栏目名称多路径,当栏目名称不为空时不允许使用模型路径
if ($sort->filename != '') {
$err = true;
}
// 限制串模型多路径
if (! ! $sort->urlname && $matchs[1] != $sort->urlname) {
$err = true;
}
}
if ($iscontent) {
define('CMS_PAGE', false); // 使用普通分页处理模型
if (! ! $data && $suffix) {
if ($data->acode != get_lg() && Config::get('lgautosw') !== '0') {
cookie('lg', $data->acode); // 调用内容语言与当前语言不一致时,自动切换语言
}
$this->getContent($data);
}
if ($iscontent) {
define('CMS_PAGE', false); // 使用普通分页处理模型
if (! ! $data && $suffix && ! $err) {
$this->getContentPage($data);
} else {
_404('您访问的内容不存在,请核对后重试!');
}
} else {
define('CMS_PAGE', true); // 使用cms分页处理模型
if (! ! $sort && ! $suffix && ! $err) {
if ($sort->type == 1) {
$this->getAboutPage($sort);
} else {
_404('您访问的内容不存在,请核对后重试!');
$this->getListPage($sort);
}
} else {
define('CMS_PAGE', true); // 使用cms分页处理模型
if (! ! $sort && ! $suffix) {
if ($sort->acode != get_lg() && Config::get('lgautosw') !== '0') {
cookie('lg', $sort->acode); // 调用栏目语言与当前语言不一致时,自动切换语言
}
if ($sort->type == 1) {
$this->getAbout($sort);
} else {
$this->getList($sort);
}
} else {
_404('您访问的页面不存在,请核对后重试!');
}
_404('您访问的页面不存在,请核对后重试!');
}
}
}
} else {
$this->getIndex();
$this->getIndexPage();
}
}
// 首页
private function getIndex()
private function getIndexPage()
{
$content = parent::parser($this->htmldir . 'index.html'); // 框架标签解析
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
@@ -195,8 +228,12 @@ class IndexController extends Controller
}
// 列表
private function getList($sort)
private function getListPage($sort)
{
// 调用栏目语言与当前语言不一致时,自动切换语言
if ($sort->acode != get_lg() && Config::get('lgautosw') !== '0') {
cookie('lg', $sort->acode);
}
if ($sort->listtpl) {
$this->checkPageLevel($sort->gcode, $sort->gtype, $sort->gnote);
$content = parent::parser($this->htmldir . $sort->listtpl); // 框架标签解析
@@ -216,8 +253,14 @@ class IndexController extends Controller
}
// 详情页
private function getContent($data)
private function getContentPage($data)
{
// 调用内容语言与当前语言不一致时,自动切换语言
if ($data->acode != get_lg() && Config::get('lgautosw') !== '0') {
cookie('lg', $data->acode);
}
// 读取模板
if (! ! $sort = $this->model->getSort($data->scode)) {
if ($sort->contenttpl) {
@@ -243,8 +286,13 @@ class IndexController extends Controller
}
// 单页
private function getAbout($sort)
private function getAboutPage($sort)
{
// 调用栏目语言与当前语言不一致时,自动切换语言
if ($sort->acode != get_lg() && Config::get('lgautosw') !== '0') {
cookie('lg', $sort->acode);
}
// 读取数据
if (! $data = $this->model->getAbout($sort->scode)) {
_404('您访问的内容不存在,请核对后重试!');

View File

@@ -290,10 +290,19 @@ class MemberController extends Controller
$nickname = post('nickname');
$useremail = post('useremail');
$usermobile = post('usermobile');
$opassword = post('opassword');
$password = post('password');
$rpassword = post('rpassword');
$headpic = str_replace(SITE_DIR, '', post('headpic'));
if (! $opassword) {
alert_back('请输入当前密码!');
} else {
if (! $this->model->checkUsername(" password='" . md5(md5($opassword)) . "' AND id='" . session('pboot_uid') . "'")) {
alert_back('您输入的当前密码不正确!');
}
}
if ($useremail) { // 邮箱校验
if (! preg_match('/^[\w]+@[\w\.]+\.[a-zA-Z]+$/', $useremail)) {
alert_back('邮箱格式不正确,请输入正确的邮箱账号!');
@@ -441,7 +450,7 @@ class MemberController extends Controller
$rs = false;
if ($to) {
session('lastsend', time()); // 记录最后提交时间
$mail_subject = "PbootCMS】您有新的验证码信息,请注意查收!";
$mail_subject = "" . CMSNAME . "】您有新的验证码信息,请注意查收!";
$code = create_code(4);
session('checkcode', strtolower($code));
$mail_body = "您的验证码为:" . $code;

View File

@@ -4,7 +4,7 @@
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2020年3月8日
* 留言控制器
* 留言控制器
*/
namespace app\home\controller;
@@ -96,7 +96,7 @@ class MessageController extends Controller
session('lastsub', time()); // 记录最后提交时间
$this->log('留言提交成功!');
if ($this->config('message_send_mail') && $this->config('message_send_to')) {
$mail_subject = "PbootCMS】您有新的" . $value->form_name . "信息,请注意查收!";
$mail_subject = "" . CMSNAME . "】您有新的" . $value->form_name . "信息,请注意查收!";
$mail_body .= '<br>来自网站 ' . get_http_url() . ' ' . date('Y-m-d H:i:s') . '';
sendmail($this->config(), $this->config('message_send_to'), $mail_subject, $mail_body);
}

View File

@@ -176,6 +176,17 @@ class ParserController extends Controller
$content = str_replace('{pboot:registerstatus}', $this->config('register_status') === '0' ? 0 : 1, $content); // 是否开启注册
$content = str_replace('{pboot:loginstatus}', $this->config('login_status') === '0' ? 0 : 1, $content); // 是否开启登录
$content = str_replace('{pboot:commentstatus}', $this->config('comment_status') === '0' ? 0 : 1, $content); // 是否开启评论
// 记录蜘蛛爬行
if ($this->config('spiderlog') !== '0') {
if ($this->config('tpl_html_cache')) { // 缓存时插入script,否则直接执行
$spidercode = "<script src='" . Url::home('Spider', null, 'url=' . URL) . "' async='async'></script>";
$content = preg_replace('/(<\/body>)/i', $spidercode . "\n$1", $content);
} else {
$spider = new SpiderController(URL);
$spider->index();
}
}
return $content;
}
@@ -184,8 +195,18 @@ class ParserController extends Controller
public function parserSiteLabel($content)
{
$pattern = '/\{pboot:site([\w]+)(\s+[^}]+)?\}/';
if (preg_match_all($pattern, $content, $matches)) {
$data = array();
// 页面自适应标题避免多横线
if (preg_match($pattern, $content)) {
$data = $this->model->getSite();
if (! $data->subtitle) {
$content = str_replace('{pboot:sitetitle}-{pboot:sitesubtitle}', '{pboot:sitetitle}', $content);
}
}
if (preg_match_all($pattern, $content, $matches)) {
$data = $data ?: $this->model->getSite();
$count = count($matches[0]);
for ($i = 0; $i < $count; $i ++) {
$params = $this->parserParam($matches[2][$i]);
@@ -386,6 +407,8 @@ class ParserController extends Controller
}
$parent = 0;
$num = 0;
$scode = 0;
$scode_arr = array();
foreach ($params as $key => $value) {
switch ($key) {
case 'parent':
@@ -394,14 +417,20 @@ class ParserController extends Controller
case 'num':
$num = $value;
break;
case 'scode':
$scode = $value;
$scode_arr = explode(',', $scode);
break;
}
}
if ($parent) { // 非顶级栏目起始
if (isset($data['tree'][$parent]['son'])) {
$out_data = $data['tree'][$parent]['son'];
} else {
$out_data = array();
if ($parent) { // 非顶级栏目起始,调用子栏目
$parent_arr = explode(',', $parent);
$out_data = array();
foreach ($parent_arr as $vp) {
if (isset($data['tree'][trim($vp)]['son'])) {
$out_data = array_merge($out_data, $data['tree'][trim($vp)]['son']);
}
}
} else { // 顶级栏目起始
$out_data = $data['top'];
@@ -422,6 +451,9 @@ class ParserController extends Controller
$out_html = '';
$key = 1;
foreach ($out_data as $value) { // 按查询的数据条数循环
if ($scode_arr && ! in_array($value['scode'], $scode_arr)) {
continue;
}
$one_html = $matches[2][$i];
if ($count2) {
for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
@@ -1505,6 +1537,7 @@ class ParserController extends Controller
// 获取调节参数
$params = $this->parserParam($matches[1][$i]);
$id = - 1;
$field = "pics";
if (! self::checkLabelLevel($params)) {
$content = str_replace($matches[0][$i], '', $content);
@@ -1525,12 +1558,15 @@ class ParserController extends Controller
case 'num':
$num = $value;
break;
case 'field':
$field = $value;
break;
}
}
// 读取内容多图
if (! ! $rs = $this->model->getContentPics(escape_string($id))) {
$pics = explode(',', $rs->pics);
if (! ! $rs = $this->model->getContentPics(escape_string($id), $field)) {
$pics = explode(',', $rs->$field);
$picstitle = explode(',', $rs->picstitle);
} else {
$pics = array();
@@ -1552,7 +1588,7 @@ class ParserController extends Controller
$out_html = '';
$key = 1;
foreach ($pics as $key => $value) { // 按查询图片条数循环
foreach ($pics as $vkey => $value) { // 按查询图片条数循环
$one_html = $matches[2][$i];
if (! $value)
continue;
@@ -1577,8 +1613,10 @@ class ParserController extends Controller
}
break;
case 'title':
$one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, isset($picstitle[$key]) ? $picstitle[$key] : ''), $one_html);
$one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, isset($picstitle[$vkey]) ? $picstitle[$vkey] : ''), $one_html);
break;
default:
$one_html = str_replace($matches2[0][$j], '', $one_html);
}
}
$key ++;
@@ -3270,7 +3308,7 @@ class ParserController extends Controller
}
eval('if(' . $matches[1][$i] . '){$flag="if";}else{$flag="else";}');
if (preg_match('/([\s\S]*)?\{else\}([\s\S]*)?/', $matches[2][$i], $matches2)) { // 判断是否存在else
if (preg_match('/^([\s\S]*)\{else\}([\s\S]*)$/', $matches[2][$i], $matches2)) { // 判断是否存在else
switch ($flag) {
case 'if': // 条件为真
if (isset($matches2[1])) {
@@ -3870,12 +3908,13 @@ class ParserController extends Controller
}
// 解析生成内容链接
protected function parserLink($type, $urlname, $page, $scode, $sortfilename, $id, $contentfilename)
public function parserLink($type, $urlname, $pagetype, $scode, $sortfilename, $id = '', $contentfilename = '')
{
$url_break_char = $this->config('url_break_char') ?: '_';
$url_rule_sort_suffix = $this->config('url_rule_sort_suffix') ? true : null;
$url_rule_content_path = $this->config('url_rule_content_path') ? true : false;
if ($type == 1) {
if ($type == 1 || $pagetype == 'about') {
$urlname = $urlname ?: 'about';
if ($sortfilename) {
$link = Url::home($sortfilename);
@@ -3884,21 +3923,29 @@ class ParserController extends Controller
}
} else {
$urlname = $urlname ?: 'list';
if ($page == 'list') {
if ($pagetype == 'list') {
if ($sortfilename) {
$link = Url::home($sortfilename);
} else {
$link = Url::home($urlname . $url_break_char . $scode);
}
} elseif ($page == 'content') {
if ($sortfilename && $contentfilename) {
$link = Url::home($sortfilename . '/' . $contentfilename, true);
} elseif ($sortfilename) {
$link = Url::home($sortfilename . '/' . $id, true);
} elseif ($contentfilename) {
$link = Url::home($urlname . $url_break_char . $scode . '/' . $contentfilename, true);
} elseif ($pagetype == 'content') {
if ($url_rule_content_path) {
if ($contentfilename) {
$link = Url::home($contentfilename, true);
} else {
$link = Url::home($id, true);
}
} else {
$link = Url::home($urlname . $url_break_char . $scode . '/' . $id, true);
if ($sortfilename && $contentfilename) {
$link = Url::home($sortfilename . '/' . $contentfilename, true);
} elseif ($sortfilename) {
$link = Url::home($sortfilename . '/' . $id, true);
} elseif ($contentfilename) {
$link = Url::home($urlname . $url_break_char . $scode . '/' . $contentfilename, true);
} else {
$link = Url::home($urlname . $url_break_char . $scode . '/' . $id, true);
}
}
} else {
$link = 'javascript:;';

View File

@@ -26,48 +26,28 @@ class SitemapController extends Controller
{
header("Content-type:text/xml;charset=utf-8");
$str = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
$str .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/">' . "\n";
$str .= $this->makeNode('', date('Y-m-d'), '1.00'); // 根目录
$url_break_char = $this->config('url_break_char') ?: '_';
$str .= '<urlset>' . "\n";
$str .= $this->makeNode('', date('Y-m-d'), '1.00', 'always'); // 根目录
$sorts = $this->model->getSorts();
$Parser = new ParserController();
foreach ($sorts as $value) {
if ($value->outlink) {
continue;
} elseif ($value->type == 1) {
$value->urlname = $value->urlname ?: 'list';
if ($value->filename) {
$link = Url::home($value->filename);
} else {
$link = Url::home($value->urlname . $url_break_char . $value->scode);
}
$str .= $this->makeNode($link, date('Y-m-d'), '0.80');
$link = $Parser->parserLink(1, $value->urlname, 'about', $value->scode, $value->filename);
$str .= $this->makeNode($link, date('Y-m-d'), '0.80', 'daily');
} else {
$value->urlname = $value->urlname ?: 'list';
if ($value->filename) {
$link = Url::home($value->filename);
} else {
$link = Url::home($value->urlname . $url_break_char . $value->scode);
}
$str .= $this->makeNode($link, date('Y-m-d'), '0.80');
$link = $Parser->parserLink(2, $value->urlname, 'list', $value->scode, $value->filename);
$str .= $this->makeNode($link, date('Y-m-d'), '0.80', 'daily');
$contents = $this->model->getSortContent($value->scode);
foreach ($contents as $value2) {
if ($value2->outlink) { // 外链
continue;
} else {
$value2->urlname = $value2->urlname ?: 'list';
if ($value2->filename && $value2->sortfilename) {
$link = Url::home($value2->sortfilename . '/' . $value2->filename, true);
} elseif ($value2->sortfilename) {
$link = Url::home($value2->sortfilename . '/' . $value2->id, true);
} elseif ($value2->contentfilename) {
$link = Url::home($value2->urlname . $url_break_char . $value2->scode . '/' . $value2->filename, true);
} else {
$link = Url::home($value2->urlname . $url_break_char . $value2->scode . '/' . $value2->id, true);
}
$link = $Parser->parserLink(2, $value2->urlname, 'content', $value2->scode, $value2->sortfilename, $value2->id, $value2->filename);
}
$str .= $this->makeNode($link, date('Y-m-d'), '0.60');
$str .= $this->makeNode($link, date('Y-m-d', strtotime($value2->date)), '0.60', 'daily');
}
}
}
@@ -75,16 +55,44 @@ class SitemapController extends Controller
}
// 生成结点信息
private function makeNode($link, $date, $priority = 0.60)
private function makeNode($link, $date, $priority = 0.60, $changefreq = 'always')
{
$node = '
<url>
<mobile:mobile type="pc,mobile"/>
<loc>' . get_http_url() . $link . '</loc>
<priority>' . $priority . '</priority>
<lastmod>' . $date . '</lastmod>
<changefreq>Always</changefreq>
<changefreq>' . $changefreq . '</changefreq>
</url>';
return $node;
}
// 文本格式
public function linkTxt()
{
header("Content-type:text/plain;charset=utf-8");
$sorts = $this->model->getSorts();
$Parser = new ParserController();
$str = get_http_url() . "\n";
foreach ($sorts as $value) {
if ($value->outlink) {
continue;
} elseif ($value->type == 1) {
$link = $Parser->parserLink(1, $value->urlname, 'about', $value->scode, $value->filename);
} else {
$link = $Parser->parserLink(2, $value->urlname, 'list', $value->scode, $value->filename);
$str .= get_http_url() . $link . "\n";
$contents = $this->model->getSortContent($value->scode);
foreach ($contents as $value2) {
if ($value2->outlink) { // 外链
continue;
} else {
$link = $Parser->parserLink(2, $value2->urlname, 'content', $value2->scode, $value2->sortfilename, $value2->id, $value2->filename);
}
$str .= get_http_url() . $link . "\n";
}
}
}
echo $str;
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @license This is not a freeware, use is subject to license terms
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2021年10月27日
*
*/
namespace app\home\controller;
use core\basic\Controller;
class SpiderController extends Controller
{
private $url;
public function __construct($url = null)
{
$this->url = $url ? escape_string($url) : get('url');
}
public function index()
{
$rs = $this->getSpider();
if ($rs !== false) {
$this->log($rs . '爬行' . $this->url);
}
}
private function getSpider()
{
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
if (strpos($useragent, 'googlebot') !== false) {
return 'Google';
} elseif (strpos($useragent, 'baiduspider') !== false) {
return 'Baidu';
} elseif (strpos($useragent, 'webscan') !== false) {
return '360WebScan';
} elseif (strpos($useragent, '360spider') !== false) {
return '360So';
} elseif (strpos($useragent, 'adsbot') !== false) {
return 'Adwords';
} elseif (strpos($useragent, 'bingbot') !== false) {
return 'Bing';
} elseif (strpos($useragent, 'slurp') !== false) {
return 'Yahoo';
} elseif (strpos($useragent, 'sosospider') !== false) {
return 'Soso';
} elseif (strpos($useragent, 'sogou') !== false) {
return 'Sogou';
} elseif (strpos($useragent, 'yodaobot') !== false) {
return 'Yodao';
} elseif (strpos($useragent, 'speedy') !== false) {
return 'Speedy';
} elseif (strpos($useragent, 'yandexbot') !== false) {
return 'Yandex';
} elseif (strpos($useragent, 'easouspider') !== false) {
return 'Easou';
} elseif (strpos($useragent, 'symantecspider') !== false) {
return 'Symantec';
} elseif (strpos($useragent, 'qiniu') !== false) {
return 'Qiniu';
} elseif (strpos($useragent, 'jiankongbao') !== false) {
return 'JianKongBao';
} elseif (strpos($useragent, 'dnspod') !== false) {
return 'DNSPod';
} elseif (strpos($useragent, 'linkpadbot') !== false) {
return 'Linkpad';
} elseif (strpos($useragent, 'mj12bot') !== false) {
return 'MJ12';
} elseif (strpos($useragent, 'dingtalkbot') !== false) {
return 'DingTalk';
} elseif (strpos($useragent, 'bytespider') !== false) {
return 'Byte';
} elseif (strpos($useragent, 'zoominfobot') !== false) {
return 'Zoominfo';
} elseif (strpos($useragent, 'yisouspider') !== false) {
return 'Yisou';
} elseif (strpos($useragent, 'spider') !== false) {
return 'other-spider';
} elseif (strpos($useragent, 'bot') !== false) {
return 'other-bot';
}
return false;
}
}