<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>胡杨 &#187; Hu Remove Comment Links</title>
	<atom:link href="http://www.hu-yang.com/tag/hu-remove-comment-links/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hu-yang.com</link>
	<description>背水一战</description>
	<lastBuildDate>Tue, 01 Mar 2011 06:29:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WordPress 插件：去除评论中的超链接</title>
		<link>http://www.hu-yang.com/wordpress-%e6%8f%92%e4%bb%b6%ef%bc%9a%e5%8e%bb%e9%99%a4%e8%af%84%e8%ae%ba%e4%b8%ad%e7%9a%84%e8%b6%85%e9%93%be%e6%8e%a5/</link>
		<comments>http://www.hu-yang.com/wordpress-%e6%8f%92%e4%bb%b6%ef%bc%9a%e5%8e%bb%e9%99%a4%e8%af%84%e8%ae%ba%e4%b8%ad%e7%9a%84%e8%b6%85%e9%93%be%e6%8e%a5/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 12:02:33 +0000</pubDate>
		<dc:creator>胡杨</dc:creator>
				<category><![CDATA[电脑]]></category>
		<category><![CDATA[Hu No Comment Links]]></category>
		<category><![CDATA[Hu Remove Comment Links]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress 插件]]></category>

		<guid isPermaLink="false">http://www.hu-yang.com/?p=431</guid>
		<description><![CDATA[　　因为访客很少，我把Akismet也停用了，没想到最近几乎每天都会收一条英文的SPAM（这个&#8230;难道本少侠的名声都传到海外去了），为此特想了个法子去除评论中的超链接，做成２个插件的形式，其实代码就几句，也有很详细的注释，就不多说了，直接上代码。
hu_no_comment_links.php:
使评论不包含任何超链接(管理员不受影响)，并且在新窗口打开评论者的网站

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
&#60;?php
/*
Plugin Name: Hu No Comment Links
Plugin URI: http://www.hu-yang.com/
Description: 使评论不包含任何超链接(管理员不受影响)，并且在新窗口打开评论者的网站。
Version: 0.1
Author: Anthony Hu
Author URI: http://www.hu-yang.com/
*/
&#160;
// wp-includes/formatting.php中的make_clickable相关函数会把URL、email、ftp地址自动转为HTML形式的超链接。
// 以下语句去除这种自动转换
remove_filter&#40;'comment_text', 'make_clickable', 9&#41;;
&#160;
// 在新窗口打开评论者的网站
add_filter&#40;'get_comment_author_link', 'hu_popuplinks', 6&#41;;
function hu_popuplinks&#40;$text&#41; &#123;
	$text = preg_replace&#40;'/&#60;a (.+?)&#62;/i', &#34;&#60;a $1 target='_blank'&#62;&#34;, $text&#41;;
	return $text;
&#125;
&#160;
/*  评论中允许的HTML标记是在wp-includes/kses.php中定义的，
    要添加或去除哪些HTML标记只要覆盖kses.php中的$allowedtags变量就可以了。
    去除评论对HTML标记&#60;a&#62;的支持。 */
$allowedtags = array&#40;
	// 'a' =&#62; array(
	//	'href' =&#62; array (),
	//	'title' =&#62; array ()),
	'abbr' =&#62; array&#40;
		'title' [...]]]></description>
			<content:encoded><![CDATA[<p>　　因为访客很少，我把Akismet也停用了，没想到最近几乎每天都会收一条英文的SPAM（这个&#8230;难道本少侠的名声都传到海外去了），为此特想了个法子去除评论中的超链接，做成２个插件的形式，其实代码就几句，也有很详细的注释，就不多说了，直接上代码。</p>
<p><strong>hu_no_comment_links.php:</strong><br />
使评论不包含任何超链接(管理员不受影响)，并且在新窗口打开评论者的网站</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Plugin Name: Hu No Comment Links
Plugin URI: http://www.hu-yang.com/
Description: 使评论不包含任何超链接(管理员不受影响)，并且在新窗口打开评论者的网站。
Version: 0.1
Author: Anthony Hu
Author URI: http://www.hu-yang.com/
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// wp-includes/formatting.php中的make_clickable相关函数会把URL、email、ftp地址自动转为HTML形式的超链接。</span>
<span style="color: #666666; font-style: italic;">// 以下语句去除这种自动转换</span>
remove_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'comment_text'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'make_clickable'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 在新窗口打开评论者的网站</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'get_comment_author_link'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'hu_popuplinks'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> hu_popuplinks<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&lt;a (.+?)&gt;/i'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&lt;a <span style="color: #006699; font-weight: bold;">$1</span> target='_blank'&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*  评论中允许的HTML标记是在wp-includes/kses.php中定义的，
    要添加或去除哪些HTML标记只要覆盖kses.php中的$allowedtags变量就可以了。
    去除评论对HTML标记&lt;a&gt;的支持。 */</span>
<span style="color: #000088;">$allowedtags</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #666666; font-style: italic;">// 'a' =&gt; array(</span>
	<span style="color: #666666; font-style: italic;">//	'href' =&gt; array (),</span>
	<span style="color: #666666; font-style: italic;">//	'title' =&gt; array ()),</span>
	<span style="color: #0000ff;">'abbr'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'acronym'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'b'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'blockquote'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'cite'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #666666; font-style: italic;">//	'br' =&gt; array(),</span>
	<span style="color: #0000ff;">'cite'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'code'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'del'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'datetime'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #666666; font-style: italic;">//	'dd' =&gt; array(),</span>
	<span style="color: #666666; font-style: italic;">//	'dl' =&gt; array(),</span>
	<span style="color: #666666; font-style: italic;">//	'dt' =&gt; array(),</span>
	<span style="color: #0000ff;">'em'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'i'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #666666; font-style: italic;">//	'ins' =&gt; array('datetime' =&gt; array(), 'cite' =&gt; array()),</span>
	<span style="color: #666666; font-style: italic;">//	'li' =&gt; array(),</span>
	<span style="color: #666666; font-style: italic;">//	'ol' =&gt; array(),</span>
	<span style="color: #666666; font-style: italic;">//	'p' =&gt; array(),</span>
	<span style="color: #0000ff;">'q'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'cite'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'strike'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'strong'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #666666; font-style: italic;">//	'sub' =&gt; array(),</span>
	<span style="color: #666666; font-style: italic;">//	'sup' =&gt; array(),</span>
	<span style="color: #666666; font-style: italic;">//	'u' =&gt; array(),</span>
	<span style="color: #666666; font-style: italic;">//	'ul' =&gt; array(),</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><span id="more-431"></span><br />
<strong>hu_remove_comment_links.php:</strong><br />
使评论不包含任何超链接(但保留本站引用或回复的超链接），并且在新窗口打开评论者的网站。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Plugin Name: Hu Remove Comment Links
Plugin URI: http://www.hu-yang.com/
Description: 使评论不包含任何超链接(但保留本站引用或回复的超链接），并且在新窗口打开评论者的网站。
Version: 0.1
Author: Anthony Hu
Author URI: http://www.hu-yang.com/
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// wp-includes/formatting.php中的make_clickable相关函数会把URL、email、ftp地址自动转为HTML形式的超链接。</span>
<span style="color: #666666; font-style: italic;">// 以下语句去除这种自动转换</span>
remove_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'comment_text'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'make_clickable'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 在新窗口打开评论者的网站</span>
<span style="color: #000000; font-weight: bold;">function</span> hu_popuplinks<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&lt;a (.+?)&gt;/i'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&lt;a <span style="color: #006699; font-weight: bold;">$1</span> target='_blank'&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'get_comment_author_link'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'hu_popuplinks'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 去除非本站引用或回复的超链接</span>
<span style="color: #666666; font-style: italic;">// 本站引用或回复的超链接一般形式:&lt;a href=&quot;#comment-33&quot;&gt;comment-33&lt;/a&gt;</span>
<span style="color: #000000; font-weight: bold;">function</span> hu_remove_links<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$pattern</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/&lt;a [^&gt;]*?href=(?!<span style="color: #000099; font-weight: bold;">\&quot;</span>#)[^&gt;]*?&gt;(.*?)&lt;\/a&gt;/i&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$replacement</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$1</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pattern</span><span style="color: #339933;">,</span> <span style="color: #000088;">$replacement</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'comment_text'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'hu_remove_links'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">66</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>　　如果讨厌插件，也可以把相关代码放到主题的functions.php文件中。</p>
<p>　　源代码下载：<a href='http://www.hu-yang.com/uploads/2010/03/hu_no_comment_links.zip'>hu_no_comment_links.zip</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hu-yang.com/wordpress-%e6%8f%92%e4%bb%b6%ef%bc%9a%e5%8e%bb%e9%99%a4%e8%af%84%e8%ae%ba%e4%b8%ad%e7%9a%84%e8%b6%85%e9%93%be%e6%8e%a5/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

