- UID
- 1
- 积分
- 9955389
- 金币
- 9954926
- 阅读权限
- 200
- 注册时间
- 2020-5-22
- 在线时间
- 117 小时
管理员
- UID
- 1
- 阅读权限
- 200
- 积分
- 9955389
- 威望
- -1
- 金币
- 9954926
鲜花( 0) 鸡蛋( 0)
|
flarum/vendor/flarum/core/views/content.blade.php
- @if ($isRobot)
- {!! $content !!}
- @else
- <div id="flarum-loading" style="display: none">
- {{ $translator->trans('core.views.content.loading_text') }}
- </div>
- @endif
复制代码
判断如果是搜索引擎访问,就直接输出内容就行了。
至于isRobot这个变量,自己定义一个在 flarum/vendor/flarum/core/src/Http/WebApp/WebAppView.php
补充添加isRobot变量方法
1.flarum/vendor/flarum/core/src/Http/WebApp/WebAppView.php的render方法中添加如下代码:
- $this->view->share('isRobot', $this->isRobot());//添加蜘蛛识别
复制代码
2.添加类方法
- /**
- * 判断来源是否是蜘蛛
- * @return boolean [description]
- */
- private function isRobot() {
- $agent= strtolower($_SERVER['HTTP_USER_AGENT']);
- if (!empty($agent)) {
- $spiderSite= array(
- "TencentTraveler",
- "Baiduspider+",
- "BaiduGame",
- "Googlebot",
- "msnbot",
- "Sosospider+",
- "Sogou web spider",
- "ia_archiver",
- "Yahoo! Slurp",
- "YoudaoBot",
- "Yahoo Slurp",
- "MSNBot",
- "Java (Often spam bot)",
- "BaiDuSpider",
- "Voila",
- "Yandex bot",
- "BSpider",
- "twiceler",
- "Sogou Spider",
- "Speedy Spider",
- "Google AdSense",
- "Heritrix",
- "Python-urllib",
- "Alexa (IA Archiver)",
- "Ask",
- "Exabot",
- "Custo",
- "OutfoxBot/YodaoBot",
- "yacy",
- "SurveyBot",
- "legs",
- "lwp-trivial",
- "Nutch",
- "StackRambler",
- "The web archive (IA Archiver)",
- "Perl tool",
- "MJ12bot",
- "Netcraft",
- "MSIECrawler",
- "WGet tools",
- "larbin",
- "Fish search",
- );
- foreach($spiderSite as $val) {
- $str = strtolower($val);
- if (strpos($agent, $str) !== false) {
- return true;
- }
- }
- } else {
- return false;
- }
- }
复制代码 |
|
关于我们