蚂蚁商户发布文章、商品是可以添加外链或者直接用外部图片,但是这对分类网站运营不利。 所以要对外链进行过滤,演示网站,蚂蚁分类的源码。
下面就说下怎么处理自动给外链自动加上nofollow属性。
1、添加过滤外链函数
打开/include/global.php 添加处理函数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
function tsnofollow( $content , $domain = "https://www.0516fangchan.com" ){ preg_match_all( '/href="(.*?)"/' , $content , $matches ); if ( $matches ){ foreach ( $matches [1] as $val ){ if ( strpos ( $val , $domain )===false ) $content = str_replace ( 'href="' . $val . '"' , 'href="' . $val . '" rel="external nofollow" ' , $content ); } } preg_match_all( '/src="(.*?)"/' , $content , $matches ); if ( $matches ){ foreach ( $matches [1] as $val ){ if ( strpos ( $val , $domain )===false ) $content = str_replace ( 'src="' . $val . '"' , 'src="' . $val . '" rel="external nofollow" ' , $content ); } } return $content ; } |
*$domain 是不用过滤的域名,全部过滤就不用给默认值
2、发布文章调用处理函数
打开/member/include/inc_document.php查找$content = isset($_post['content'])在后面添加
1
|
$content = addnofollow( stripslashes ( $content )); |
*注意必须要加stripslashes先处理文章的转义字符
这样就处理完毕了,商品也是类似处理。
如对本文有疑问, 点击进行留言回复!!
[ACTF2020 新生赛]Include 1【文件包含】【读取代码】
算法题解 - 牛客编程巅峰赛S1第6场 - 黄金&钻石&王者组
推荐一个程序员必备网站之一:Dev Hints ,非常实用!
网友评论