商家发布文章、商品外链及远程图片自动添加nofollow属性

本文转自https://www.baitg.cn/article-show-id-44.html
蚂蚁商户发布文章、商品是可以添加外链或者直接用外部图片,但是这对分类网站运营不利。 所以要对外链进行过滤。

    下面就说下怎么处理自动给外链自动加上nofollow属性。

1、添加过滤外链函数

打开/include/global.php 添加处理函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function tsNofollow( c o n t e n t , content, content,domain=“https://www.0516buy.cn”){
preg_match_all(’/href="(.?)"/’, c o n t e n t , content, content,matches);
if(KaTeX parse error: Expected '}', got 'EOF' at end of input: …es){ foreach(matches[1] as KaTeX parse error: Expected '}', got 'EOF' at end of input: … if( strpos(val,$domain)===false ) c o n t e n t = s t r r e p l a c e ( ′ h r e f = " ′ . content=str_replace('href="'. content=strreplace(href=".val.’"’, ‘href="’. v a l . ′ " r e l = " e x t e r n a l n o f o l l o w " ′ , val.'" rel="external nofollow" ', val."rel="externalnofollow",content);
}
}
preg_match_all(’/src="(.
?)"/’, c o n t e n t , content, content,matches);
if(KaTeX parse error: Expected '}', got 'EOF' at end of input: …es){ foreach(matches[1] as KaTeX parse error: Expected '}', got 'EOF' at end of input: … if( strpos(val,$domain)===false ) c o n t e n t = s t r r e p l a c e ( ′ s r c = " ′ . content=str_replace('src="'. content=strreplace(src=".val.’"’, ‘src="’. v a l . ′ " r e l = " e x t e r n a l n o f o l l o w " ′ , val.'" rel="external nofollow" ', val."rel="externalnofollow",content);
}
}
return KaTeX parse error: Expected 'EOF', got '}' at position 10: content; }̲ *domain 是不用过滤的域名,全部过滤就不用给默认值

2、发布文章调用处理函数

打开/member/include/inc_document.php查找 c o n t e n t = i s s e t ( content = isset( content=isset(_POST[‘content’])在后面添加

1
c o n t e n t = a d d N o f o l l o w ( s t r i p s l a s h e s ( content = addNofollow(stripslashes( content=addNofollow(stripslashes(content));
*注意必须要加stripslashes先处理文章的转义字符

这样就处理完毕了,商品也是类似处理。

http://www.0516fangchan.com/zx/xzxview9.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值