本文转自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先处理文章的转义字符
这样就处理完毕了,商品也是类似处理。