给Discuz X论坛帖子的外部链接增加nofollow属性
2014-01-06 15:57
417 查看
给Discuz X论坛的外部链接增加nofollow方法,测试版本Discuz! X3.1,其它版本未经测试
打开目录source/function/function_discuzcode.php文件,查找parseurl函数,对照以下代码进行修改:
在parseurl函数后面新增nofollow函数,代码如下:
打开目录source/function/function_discuzcode.php文件,查找parseurl函数,对照以下代码进行修改:
function parseurl($url, $text, $scheme) { global $_G; if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) { $url = $matches[0]; $length = 65; if(strlen($url) > $length) { $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3)); } $url = nofollow($url); return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>'; } else { $url = substr($url, 1); if(substr(strtolower($url), 0, 4) == 'www.') { $url = 'http://'.$url; } $url = !$scheme ? $_G['siteurl'].$url : $url; return '<a href="'.nofollow($url).'" target="_blank">'.$text.'</a>'; } }
在parseurl函数后面新增nofollow函数,代码如下:
function nofollow($url = '') { $temp = array(); if( ! empty($url)) { $temp = parse_url($url); if(isset($temp['host']) && $temp['host'] != $_SERVER['HTTP_HOST']) { $url .= '" rel="nofollow"'; } } unset($temp); return $url; }
相关文章推荐
- discuz论坛找出贴子中所有外部链接
- 链接属性rel=’external’、rel=’nofollow’、rel=’external nofollow’三种写法的区别
- c语言3种链接属性: 外部(external), 内部(internal),无设置(none)
- const、static、内部链接属性和外部链接属性整理
- 如何增加外部链接 网站增加外部链接方法
- dedecms和discuz!论坛安装不同虚拟主机商不同数据库上面的帖子
- discuz论坛友情链接竖排改成横排的方法,测试可用
- const、static、内部链接属性和外部链接属性整理
- Discuz!论坛教程之去掉帖子列表页的附件图标的方法
- spring使用外部属性配置数据库链接No suitable driver错误
- Discuz X3.2 论坛关闭后,MySQL帖子导出为.csv
- c语言3种链接属性: 外部(external), 内部(internal),无设置(none)
- enctype属性 +asp 连接数据库出现错误+ DISCUZ论坛的一些修改
- c语言3种链接属性: 外部(external), 内部(internal),无设置(none)
- 学习Discuz! X3.2记录:去掉论坛首页的“Archiver”、“小黑屋”等链接
- 链接rel属性external、nofollow、external nofollow三种写法的区别
- 链接外部样式表标签link中的rel/rev属性
- 【微信:hatybeijing】京女编程老师寻IT牛人建i8lei.com"爱芭蕾"论坛(如:Discuz)和搭建微信的发帖阅读帖子功能
- 从数据库直接导入帖子到Discuz 论坛.
- PHP过滤外部链接及外部图片 添加rel="nofollow"属性