找回密码
 立即注册

QQ登录

只需一步,快速开始

Discuz! X3.2帖子内容外链自动加nofollow解决方案之一

系统自动把外链都加上nofollow属性,修改方法如下:
1、打开目录source/function/function_discuzcode.php文件,查找parseurl函数:

搜索
  1. function parseurl($url, $text, $scheme) {
  2.         global $_G;
  3.         if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\["']+/i", trim($text), $matches)) {
  4.                 $url = $matches[0];
  5.                 $length = 65;
  6.                 if(strlen($url) > $length) {
  7.                         $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
  8.                 }
  9.                 return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>';
  10.         } else {
  11.                 $url = substr($url, 1);
  12.                 if(substr(strtolower($url), 0, 4) == 'www.') {
  13.                         $url = 'http://'.$url;
  14.                 }
  15.                 $url = !$scheme ? $_G['siteurl'].$url : $url;
  16.                 return '<a href="'.$url.'" target="_blank">'.$text.'</a>';
  17.         }
  18. }
复制代码

修改为:
  1. function parseurl($url, $text, $scheme) {
  2.         global $_G;
  3.         if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\["']+/i", trim($text), $matches)) {
  4.                 $url = $matches[0];
  5.                 $length = 65;
  6.                 if(strlen($url) > $length) {
  7.                         $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
  8.                 }
  9.         $url = nofollow($url);
  10.                 return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>';
  11.         } else {
  12.                 $url = substr($url, 1);
  13.                 if(substr(strtolower($url), 0, 4) == 'www.') {
  14.                         $url = 'http://'.$url;
  15.                 }
  16.                 $url = !$scheme ? $_G['siteurl'].$url : $url;
  17.                 return '<a href="'.nofollow($url).'" target="_blank">'.$text.'</a>';
  18.         }
  19. }
复制代码



2.在parseurl函数后面新增nofollow函数,代码如下:
  1. function nofollow($url = '')
  2. {
  3.     $temp = array();

  4.     if( ! empty($url))
  5.     {
  6.         $temp = parse_url($url);

  7.         if(isset($temp['host']) && $temp['host'] != $_SERVER['HTTP_HOST'])
  8.         {
  9.             $url .= '" rel="nofollow"';
  10.         }
  11.     }

  12.     unset($temp);
  13.     return $url;
  14. }
复制代码


本教程由无限星辰工作室CRX349独家整理和提供,转载请注明地址,谢谢。本文地址:https://www.xmspace.net/thread-273-1-1.html
无限星辰工作室  好集导航 Discuz全集下载  星辰站长网  集热爱361  一品文学  手机小游戏合集   海外空间网 星辰api  星辰支付二维码管理平台 阿里云服务器 腾讯云服务器
服务Discuz!建站|DiscuzQ配置|二开|小程序|APP|搬家|挂马清理|防护|Win/Linux环境搭建|优化|运维|
服务理念:专业 诚信 友好QQ842062626 服务项目 Q群315524225

发表于 2014-11-15 01:51:22 | 显示全部楼层 |阅读模式

回复 | 使用道具 举报

该帖共收到 0 条回复!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

美图秀

    • fastadmin 后台界面使用字段数组类型
    • Discuz!x3.5 修改标题高亮颜色
    • Discuz!x3.5 应用中心 下载应用一直下载中
    • 帖子定时显示
    • 论坛辅助审核
拖动客服框
Online Service
点击这里给我发消息
点击这里联系我们
微信扫一扫
在线客服
快速回复 返回顶部 返回列表