<?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>睡到25点 &#187; Blog Related</title>
	<atom:link href="http://www.voidman.com/category/blog-related/feed" rel="self" type="application/rss+xml" />
	<link>http://www.voidman.com</link>
	<description>个人博客，记录与分享，仅此而已。</description>
	<lastBuildDate>Fri, 30 Jul 2010 09:54:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Media Temple Hacked</title>
		<link>http://www.voidman.com/2009/11/media-temple-hacked.html</link>
		<comments>http://www.voidman.com/2009/11/media-temple-hacked.html#comments</comments>
		<pubDate>Fri, 27 Nov 2009 11:37:48 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[media temple]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=313</guid>
		<description><![CDATA[MT 居然采用明文方式存储用户 FTP/SSH 密码，于是杯具发生了 —— 貌似一台 GS 服务器被黑了，结果可想而知，我就在那 10% 的用户之列。博客页面 footer 被黑客挂了类似的代码： &#60;!-- [ea1bce76cc34b90bf0e3eb07e662b430 --&#62;&#60;!-- 9190819521 --&#62;&#60;noscript&#62;&#60;ul&#62;&#60;li&#62;&#60;a href=&#34;http://rg8rhg34h34h.cc/c&#34;&#62;.&#60;/a&#62;&#60;/li&#62;&#60;/ul&#62;&#60;/noscript&#62;&#60;!-- ea1bce76cc34b90bf0e3eb07e662b430] --&#62; 查找了一下被感染的文件： find ./ &#124; xargs grep 'eval(base64_decode(' find ./ &#124; xargs grep '&#60;!-- \[' find ./ -mtime 0 &#160; ./sparkleisle.com/html ./sparkleisle.com/html/index.html ./voidman.com/html ./voidman.com/html/index.php ./voidman.net/html ./voidman.net/html/index.html 所幸影响不大，手工修复了。 MT 对采用明文密码的解释是： “Clear Text” is a method of storing [...]]]></description>
			<content:encoded><![CDATA[<p>MT 居然采用明文方式存储用户 FTP/SSH 密码，于是杯具发生了 —— 貌似一台 GS 服务器被黑了，结果可想而知，我就在那 10% 的用户之列。博客页面 footer 被黑客挂了类似的代码：</p>

<div class="wp_syntax"><pre class="html4strict"><span style="color: #800000"><span style="color: #008000; font-style: italic;">&lt;!-- [ea1bce76cc34b90bf0e3eb07e662b430 --&gt;</span></span><span style="color: #800000"><span style="color: #008000; font-style: italic;">&lt;!-- 9190819521 --&gt;</span></span><span style="color: #800000"><span style="color: blue;">&lt;noscript&gt;</span></span><span style="color: #800000"><span style="color: blue;">&lt;ul&gt;</span></span><span style="color: #800000"><span style="color: blue;">&lt;li&gt;</span></span><span style="color: #800000"><span style="color: blue;">&lt;a</span> <span style="color: #ff0000;">href</span>=<span style="color: #ff00ff;">&quot;http://rg8rhg34h34h.cc/c&quot;</span>&gt;</span>.<span style="color: #800000"><span style="color: blue;">&lt;/a&gt;</span></span><span style="color: #800000"><span style="color: blue;">&lt;/li&gt;</span></span><span style="color: #800000"><span style="color: blue;">&lt;/ul&gt;</span></span><span style="color: #800000"><span style="color: blue;">&lt;/noscript&gt;</span></span><span style="color: #800000"><span style="color: #008000; font-style: italic;">&lt;!-- ea1bce76cc34b90bf0e3eb07e662b430] --&gt;</span></span></pre></div>

<p>查找了一下被感染的文件：</p>

<div class="wp_syntax"><pre class="bash"><span style="color: #c20cb9; font-weight: bold;">find</span> ./ | <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'eval(base64_decode('</span>
<span style="color: #c20cb9; font-weight: bold;">find</span> ./ | <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'&lt;!-- \['</span>
<span style="color: #c20cb9; font-weight: bold;">find</span> ./ <span style="color: #660033;">-mtime</span> <span style="color: #000000;">0</span>
&nbsp;
./sparkleisle.com/html
./sparkleisle.com/html/index.html
./voidman.com/html
./voidman.com/html/index.php
./voidman.net/html
./voidman.net/html/index.html</pre></div>

<p>所幸影响不大，手工修复了。</p>
<p>MT 对采用明文密码的解释是：</p>
<blockquote class="quote"><p>
“Clear Text” is a method of storing passwords in a database so that they are human readable. This preference was made to provide customers a convenient way of managing access to their services, e.g. connecting a PHP app to MySQL.
</p></blockquote>
<p>出发点是好的，可是做法太脑残了。</p>
<p>最后，雪特 AND 发可。</pre>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html" title="WordPress 的 Hook 机制在 Discuz 二次开发中的应用">WordPress 的 Hook 机制在 Discuz 二次开发中的应用</a></li><li><a href="http://www.voidman.com/2009/01/moved-to-mt-media-temple.html" title="Moved to (mt) Media Temple">Moved to (mt) Media Temple</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2009/11/media-temple-hacked.html">http://www.voidman.com/2009/11/media-temple-hacked.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2009/11/media-temple-hacked.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>At Reply Mail Notification 1.0 Release</title>
		<link>http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html</link>
		<comments>http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html#comments</comments>
		<pubDate>Wed, 15 Apr 2009 11:49:35 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[@reply]]></category>
		<category><![CDATA[at reply]]></category>
		<category><![CDATA[mail notification]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=277</guid>
		<description><![CDATA[终于将 At Reply Mail Notification 的后台回复功能加上，这样看起来算是一个插件了。不过没有提供后台插件管理选项，觉得没有这个必要，因为相关设置不多且修改频繁度并不会太高。先上截图： HTML 模版： 实际邮件效果（163邮箱），已经测试过的邮箱包括 gmail, yahoo.com, 163, 126, qq, live mail 后台回复界面： 访客回复界面： 更多详情和下载请点击： at-reply-mail-notification UPDATED at 2010-6-23 修复 WordPress 2.8 版本以后在后台留言管理中无法回复的问题 Related PostsAt Reply Mail Notification 测试贴对 Head META Description 的一些改进WordPress 的 Hook 机制在 Discuz 二次开发中的应用LBS 转 WordPress 不完全记录Wordpress 糟糕的重复评论检测方式让 Wordpress 自动删除 Post Revisions让 Google Sitemaps Generator 可以忽略指定的日志分类Wordpress 分页文章静态化的更优解决方案升级到 [...]]]></description>
			<content:encoded><![CDATA[<p>终于将 <a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html">At Reply Mail Notification</a> 的后台回复功能加上，这样看起来算是一个插件了。不过没有提供后台插件管理选项，觉得没有这个必要，因为相关设置不多且修改频繁度并不会太高。先上截图：</p>
<p><strong>HTML 模版：</strong><br />
<a href="http://img.voidman.com/wp/2009/04/mail_template_html.png"><img src="http://img.voidman.com/wp/2009/04/mail_template_html-600x333.png" alt="mail_template_html" title="mail_template_html" width="600" height="333" class="grayborder" /></a><br />
<span id="more-277"></span><br />
<strong>实际邮件效果</strong>（163邮箱），已经测试过的邮箱包括 gmail, yahoo.com, 163, 126, qq, live mail<br />
<a href="http://img.voidman.com/wp/2009/04/mail_html.png"><img src="http://img.voidman.com/wp/2009/04/mail_html-600x432.png" alt="mail_html" title="mail_html" width="600" height="432" class="grayborder" /></a></p>
<p><strong>后台回复界面：</strong><br />
<img src="http://img.voidman.com/wp/2009/04/admin_reply.png" alt="admin_reply" title="admin_reply" width="533" height="70" class="grayborder" /></p>
<p><strong>访客回复界面：</strong><br />
<img src="http://img.voidman.com/wp/2009/04/reply-button.png" alt="vistor_reply" title="vistor_reply" width="533" height="70" class="grayborder" /></p>
<p><strong>更多详情和下载请点击：</strong><br />
<a href="http://code.google.com/p/at-reply-mail-notification/" target="_blank">at-reply-mail-notification</a></p>
<p><strong>UPDATED at 2010-6-23</strong><br />
修复 WordPress 2.8 版本以后在后台留言管理中无法回复的问题</p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html" title="At Reply Mail Notification 测试贴">At Reply Mail Notification 测试贴</a></li><li><a href="http://www.voidman.com/2008/03/improve-wp-plugin-head-meta-description.html" title="对 Head META Description 的一些改进">对 Head META Description 的一些改进</a></li><li><a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html" title="WordPress 的 Hook 机制在 Discuz 二次开发中的应用">WordPress 的 Hook 机制在 Discuz 二次开发中的应用</a></li><li><a href="http://www.voidman.com/2009/03/lbs-to-wordpress.html" title="LBS 转 WordPress 不完全记录">LBS 转 WordPress 不完全记录</a></li><li><a href="http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html" title="Wordpress 糟糕的重复评论检测方式">Wordpress 糟糕的重复评论检测方式</a></li><li><a href="http://www.voidman.com/2008/11/automatically-delete-post-revisions.html" title="让 Wordpress 自动删除 Post Revisions">让 Wordpress 自动删除 Post Revisions</a></li><li><a href="http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html" title="让 Google Sitemaps Generator 可以忽略指定的日志分类">让 Google Sitemaps Generator 可以忽略指定的日志分类</a></li><li><a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html" title="Wordpress 分页文章静态化的更优解决方案">Wordpress 分页文章静态化的更优解决方案</a></li><li><a href="http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html" title="升级到 WordPress 2.6">升级到 WordPress 2.6</a></li><li><a href="http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html" title="升级到 WordPress 2.5 RC1">升级到 WordPress 2.5 RC1</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html">http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>LBS 转 WordPress 不完全记录</title>
		<link>http://www.voidman.com/2009/03/lbs-to-wordpress.html</link>
		<comments>http://www.voidman.com/2009/03/lbs-to-wordpress.html#comments</comments>
		<pubDate>Sun, 22 Mar 2009 04:04:27 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[iis rewrite]]></category>
		<category><![CDATA[lbs]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=250</guid>
		<description><![CDATA[<p class="page-links"><strong>Pages:</strong> 1 <a href="http://www.voidman.com/2009/03/lbs-to-wordpress-2.html">2</a></p>早就答应 Cure 要帮他把博客从 LBS 转到 WordPress，事实上从他的闪光花园开始长了杂草之后，我就一直鼓动他转到 WordPress 下。或许是一直借口太忙了又或是自我标榜的“完美主义”在作怪，总之断断续续拖拖拉拉，从一月份一直到前些日子才将闪光花园的 LBS 主题改写成 WordPress 版本的，基本上了保留了原貌，用 Cure 的话说和之前没什么两样。尝试用了下 CSS Sprite，把一大堆不同类的背景图片弄到一起看起来是个失误，不过暂时也懒得改了。 ACCESS TO MySQL 数据转换费了一些周折。找了个工具叫 Bullzip MS Access to MySQL，在 XP 下却不能正常使用，提示“Error in function 'cmdNext_Click'”之类的错误。官方论坛有人说是 ADO 不存在的缘故，不过折腾了半天问题照旧。后来在安装了 SQL SERVER 的WIN2003系统下成功将数据 Dump 成 SQL 文本，可中文却是乱码，崩溃。最后还是用了月光的转换软件搞定，不过月光的软件不会生成创建表结构的语句，所以还是两者结合了一下，才将 LBS 数据转到 MySQL 下。 LBS 数据导入到 WordPress 表中 根据需要，只转换了 blog_article、blog_category、blog_comment 三个表的数据，然后将数据导入 WordPress 表中： # 导入日志 INSERT [...]]]></description>
			<content:encoded><![CDATA[<p class="page-links"><strong>Pages:</strong> 1 <a href="http://www.voidman.com/2009/03/lbs-to-wordpress-2.html">2</a></p><p>早就答应 Cure 要帮他把博客从 LBS 转到 WordPress，事实上从他的<a href="http://www-s-isle.com/blog/">闪光花园</a>开始长了杂草之后，我就一直鼓动他转到 WordPress 下。或许是一直借口太忙了又或是自我标榜的“完美主义”在作怪，总之断断续续拖拖拉拉，从一月份一直到前些日子才将闪光花园的 LBS 主题改写成 WordPress 版本的，基本上了保留了原貌，用 Cure 的话说和之前没什么两样。尝试用了下 CSS Sprite，把一大堆不同类的背景图片弄到一起看起来是个失误，不过暂时也懒得改了。</p>
<p><strong>ACCESS TO MySQL</strong><br />
数据转换费了一些周折。找了个工具叫 Bullzip MS Access to MySQL，在 XP 下却不能正常使用，提示“Error in function 'cmdNext_Click'”之类的错误。官方论坛<a href="http://www.bullzip.com/phpBB/viewtopic.php?t=6338">有人说</a>是 ADO 不存在的缘故，不过折腾了半天问题照旧。后来在安装了 SQL SERVER 的WIN2003系统下成功将数据 Dump 成 SQL 文本，可中文却是乱码，崩溃。最后还是用了<a href="http://www.williamlong.info">月光</a>的<a href="http://www.williamlong.info/archives/1057.html">转换软件</a>搞定，不过月光的软件不会生成创建表结构的语句，所以还是两者结合了一下，才将 LBS 数据转到 MySQL 下。<br />
<span id="more-250"></span><br />
<strong>LBS 数据导入到 WordPress 表中</strong><br />
根据需要，只转换了 blog_article、blog_category、blog_comment 三个表的数据，然后将数据导入 WordPress 表中：</p>

<div class="wp_syntax"><pre class="mysql"><span style="color: #008200; font-style: italic;"># 导入日志</span>
<span style="color: #0000FF; ">INSERT</span> <span style="color: #0000FF; ">INTO</span>  wp_posts <span style="color: #000;">&#40;</span>ID, post_author, post_date, post_content, post_title, post_status, post_modified<span style="color: #000;">&#41;</span>
<span style="color: #0000FF; ">SELECT</span> log_id, <span style="color: #840000;">2</span>, log_postTime, <span style="color: #0000FF; ">CONCAT</span><span style="color: #000;">&#40;</span>log_content0, <span style="color: #0000FF; ">CHAR</span><span style="color: #000;">&#40;</span><span style="color: #840000;">13</span><span style="color: #000;">&#41;</span>, <span style="color: #FF00FF;">'&lt;!--more--&gt;'</span>, <span style="color: #0000FF; ">CHAR</span><span style="color: #000;">&#40;</span><span style="color: #840000;">13</span><span style="color: #000;">&#41;</span>, log_content1<span style="color: #000;">&#41;</span>, log_title, <span style="color: #FF00FF;">'publish'</span>, log_postTime
<span style="color: #0000FF; ">FROM</span> blog_article
&nbsp;
<span style="color: #008200; font-style: italic;"># 导入评论</span>
<span style="color: #0000FF; ">INSERT</span> <span style="color: #0000FF; ">INTO</span> wp_comments <span style="color: #000;">&#40;</span>comment_ID, comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content, comment_approved, comment_agent, comment_type, comment_parent, user_id <span style="color: #000;">&#41;</span>
<span style="color: #0000FF; ">SELECT</span> comm_id, log_id, comm_author, <span style="color: #FF00FF;">''</span>, <span style="color: #FF00FF;">''</span>, comm_ip, comm_postTime, comm_content, <span style="color: #840000;">1</span>, <span style="color: #FF00FF;">''</span>, <span style="color: #FF00FF;">''</span>, <span style="color: #840000;">0</span>, <span style="color: #840000;">0</span>
<span style="color: #0000FF; ">FROM</span> blog_comment
&nbsp;
<span style="color: #008200; font-style: italic;"># 更新日志的评论数</span>
<span style="color: #0000FF; ">UPDATE</span> wp_posts p, <span style="color: #000;">&#40;</span>SELECTcomment_post_ID AS pid, COUNT<span style="color: #000;">&#40;</span>*<span style="color: #000;">&#41;</span> AS counts <span style="color: #0000FF; ">FROM</span> wp_comments <span style="color: #0000FF; ">GROUP</span> <span style="color: #0000FF; ">BY</span> comment_post_ID<span style="color: #000;">&#41;</span> c
<span style="color: #0000FF; ">SET</span> p.comment_count = c.counts
<span style="color: #0000FF; ">WHERE</span> p.ID = c.pid
&nbsp;
<span style="color: #008200; font-style: italic;"># 导入日志类别</span>
<span style="color: #008200; font-style: italic;"># 类别不多，直接在后台里手工添加了</span>
&nbsp;
<span style="color: #008200; font-style: italic;"># 更新新旧类别对应关系</span>
<span style="color: #008200; font-style: italic;"># 在 blog_category 增加 cat_newid 字段，将类别的新ID填入此字段，同样手工操作了</span>
&nbsp;
<span style="color: #008200; font-style: italic;"># 导入日志与分类关系</span>
<span style="color: #0000FF; ">INSERT</span> <span style="color: #0000FF; ">INTO</span> wp_term_relationships <span style="color: #000;">&#40;</span>object_id, term_taxonomy_id<span style="color: #000;">&#41;</span>
<span style="color: #0000FF; ">SELECT</span> log_id, c.cat_newid
<span style="color: #0000FF; ">FROM</span> blog_article a, blog_category c
<span style="color: #0000FF; ">WHERE</span> a.log_catID = c.cat_id
&nbsp;
<span style="color: #008200; font-style: italic;"># 更新分类下日志数</span>
<span style="color: #0000FF; ">UPDATE</span> wp_term_taxonomy t, <span style="color: #000;">&#40;</span><span style="color: #0000FF; ">SELECT</span> term_taxonomy_id, count<span style="color: #000;">&#40;</span>*<span style="color: #000;">&#41;</span> AS counts <span style="color: #0000FF; ">FROM</span> wp_term_relationships <span style="color: #0000FF; ">GROUP</span> <span style="color: #0000FF; ">BY</span> term_taxonomy_id<span style="color: #000;">&#41;</span> r
<span style="color: #0000FF; ">SET</span> t.count = r.counts
<span style="color: #0000FF; ">WHERE</span> t.term_taxonomy_id = r.term_taxonomy_id</pre></div>

<p><strong>日志和评论内容UBB代码转换</strong><br />
Cure 的日志基本上只用了 URL, FONT, SIZE, CENTER, IMG 这几个 UBB 代码，所以干脆将数据导出到SQL文本中，直接用 Editplus 的正则替换功能将UBB 代码转成了 HTML 。</p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html" title="WordPress 的 Hook 机制在 Discuz 二次开发中的应用">WordPress 的 Hook 机制在 Discuz 二次开发中的应用</a></li><li><a href="http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html" title="At Reply Mail Notification 1.0 Release">At Reply Mail Notification 1.0 Release</a></li><li><a href="http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html" title="Wordpress 糟糕的重复评论检测方式">Wordpress 糟糕的重复评论检测方式</a></li><li><a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html" title="At Reply Mail Notification 测试贴">At Reply Mail Notification 测试贴</a></li><li><a href="http://www.voidman.com/2008/11/automatically-delete-post-revisions.html" title="让 Wordpress 自动删除 Post Revisions">让 Wordpress 自动删除 Post Revisions</a></li><li><a href="http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html" title="让 Google Sitemaps Generator 可以忽略指定的日志分类">让 Google Sitemaps Generator 可以忽略指定的日志分类</a></li><li><a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html" title="Wordpress 分页文章静态化的更优解决方案">Wordpress 分页文章静态化的更优解决方案</a></li><li><a href="http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html" title="升级到 WordPress 2.6">升级到 WordPress 2.6</a></li><li><a href="http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html" title="升级到 WordPress 2.5 RC1">升级到 WordPress 2.5 RC1</a></li><li><a href="http://www.voidman.com/2008/03/wordpress-theme-wpcandy-remix.html" title="WordPress Theme WPCandy Remix">WordPress Theme WPCandy Remix</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2009/03/lbs-to-wordpress.html">http://www.voidman.com/2009/03/lbs-to-wordpress.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2009/03/lbs-to-wordpress.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>WordPress 糟糕的重复评论检测方式</title>
		<link>http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html</link>
		<comments>http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html#comments</comments>
		<pubDate>Thu, 22 Jan 2009 14:13:49 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[comment]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[重复评论]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=231</guid>
		<description><![CDATA[去旧空间清理文件时，用 FTP 拉下一大堆 mysql slow queries 日志。由于我的博客平时几乎没什么人来访问，所以我也没怎么去关心是否存在 mysql slow queries。看了下日志，发现绝大部分 slow query 都是由 WordPress 的重复评论检测造成成的： 没想到居然直接用 Text 类型的 comment_content 字段来判断评论重复，太衰了。开始还怀疑是不是日志搞错了，于是找到相应的代码确认： // Simple duplicate check // expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content) $dupe = &#34;SELECT comment_ID FROM $wpdb-&#62;comments WHERE comment_post_ID = '$comment_post_ID' AND ( comment_author = '$comment_author' &#34;; if &#40; $comment_author_email &#41; $dupe .= &#34;OR comment_author_email = [...]]]></description>
			<content:encoded><![CDATA[<p>去旧空间清理文件时，用 FTP 拉下一大堆 mysql slow queries 日志。由于我的博客平时几乎没什么人来访问，所以我也没怎么去关心是否存在 mysql slow queries。看了下日志，发现绝大部分 slow query 都是由 WordPress 的重复评论检测造成成的：</p>
<p class="imgwrap">
<img src="http://img.voidman.com/wp/2009/01/wp_comment_mysql_slow_queries.png" alt="wp_comment_mysql_slow_queries" class="grayborder" style="padding: 2px"/>
</p>
<p>没想到居然直接用 Text 类型的 comment_content 字段来判断评论重复，太衰了。开始还怀疑是不是日志搞错了，于是找到相应的代码确认：<span id="more-231"></span></p>

<div class="wp_syntax"><pre class="php"><span style="color: #008000; font-style: italic;">// Simple duplicate check</span>
<span style="color: #008000; font-style: italic;">// expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content)</span>
<span style="color: #008080;">$dupe</span> = <span style="color: #ff00ff;">&quot;SELECT comment_ID FROM $wpdb-&gt;comments WHERE comment_post_ID = '$comment_post_ID' AND ( comment_author = '$comment_author' &quot;</span>;
<span style="color: blue;">if</span> <span style="color: #800000;">&#40;</span> <span style="color: #008080;">$comment_author_email</span> <span style="color: #800000;">&#41;</span>
  <span style="color: #008080;">$dupe</span> .= <span style="color: #ff00ff;">&quot;OR comment_author_email = '$comment_author_email' &quot;</span>;
<span style="color: #008080;">$dupe</span> .= <span style="color: #ff00ff;">&quot;) AND comment_content = '$comment_content' LIMIT 1&quot;</span>;
<span style="color: blue;">if</span> <span style="color: #800000;">&#40;</span> <span style="color: #008080;">$wpdb</span>-&gt;<span style="color: #006600;">get_var</span><span style="color: #800000;">&#40;</span><span style="color: #008080;">$dupe</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
  <span style="color: blue;">if</span> <span style="color: #800000;">&#40;</span> <span style="color: #ff0000;">defined</span><span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'DOING_AJAX'</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#41;</span>
    <span style="color: blue;">die</span><span style="color: #800000;">&#40;</span> __<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'Duplicate comment detected; it looks as though you<span style="">\'</span>ve already said that!'</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#41;</span>;
&nbsp;
  wp_die<span style="color: #800000;">&#40;</span> __<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'Duplicate comment detected; it looks as though you<span style="">\'</span>ve already said that!'</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#41;</span>;
<span style="color: #800000;">&#125;</span>
<span style="color: #008000; font-style: italic;">// 上述代码位于 wp-includes/comment.php 文件的 wp_allow_comment 函数中</span></pre></div>

<p>有点奇怪 WP 为什么不考虑加个 comment_hash 字段，将评论内容 hash 一下，然后建个索引，那检测速度肯定杠杠滴。</p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html" title="WordPress 的 Hook 机制在 Discuz 二次开发中的应用">WordPress 的 Hook 机制在 Discuz 二次开发中的应用</a></li><li><a href="http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html" title="At Reply Mail Notification 1.0 Release">At Reply Mail Notification 1.0 Release</a></li><li><a href="http://www.voidman.com/2009/03/lbs-to-wordpress.html" title="LBS 转 WordPress 不完全记录">LBS 转 WordPress 不完全记录</a></li><li><a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html" title="At Reply Mail Notification 测试贴">At Reply Mail Notification 测试贴</a></li><li><a href="http://www.voidman.com/2008/11/automatically-delete-post-revisions.html" title="让 Wordpress 自动删除 Post Revisions">让 Wordpress 自动删除 Post Revisions</a></li><li><a href="http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html" title="让 Google Sitemaps Generator 可以忽略指定的日志分类">让 Google Sitemaps Generator 可以忽略指定的日志分类</a></li><li><a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html" title="Wordpress 分页文章静态化的更优解决方案">Wordpress 分页文章静态化的更优解决方案</a></li><li><a href="http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html" title="升级到 WordPress 2.6">升级到 WordPress 2.6</a></li><li><a href="http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html" title="升级到 WordPress 2.5 RC1">升级到 WordPress 2.5 RC1</a></li><li><a href="http://www.voidman.com/2008/03/wordpress-theme-wpcandy-remix.html" title="WordPress Theme WPCandy Remix">WordPress Theme WPCandy Remix</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html">http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>At Reply Mail Notification 测试贴</title>
		<link>http://www.voidman.com/2009/01/at-reply-mail-notification-test.html</link>
		<comments>http://www.voidman.com/2009/01/at-reply-mail-notification-test.html#comments</comments>
		<pubDate>Mon, 19 Jan 2009 01:40:45 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[@reply]]></category>
		<category><![CDATA[at reply]]></category>
		<category><![CDATA[mail notification]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=228</guid>
		<description><![CDATA[想给博客加上访客留言被回复时邮件通知留言者的功能，本不想折腾，只不过试用了几个插件，都觉得不尽满意，便自己写了一个，先实现了几个功能： 访客可以针对每篇日志选择是否接收邮件通知 访客可以针对每篇日志选择接收何种评论通知 访客可以点击邮件底部的链接取消邮件通知 对于使用 @+留言者 形式的回复暂未作邮件通知，需点击留言者名称右边的小图标 回复。回复通知只对即日起的新留言有效。 欢迎在此留言，灌水。 Related PostsAt Reply Mail Notification 1.0 Release对 Head META Description 的一些改进WordPress 的 Hook 机制在 Discuz 二次开发中的应用LBS 转 WordPress 不完全记录Wordpress 糟糕的重复评论检测方式让 Wordpress 自动删除 Post Revisions让 Google Sitemaps Generator 可以忽略指定的日志分类Wordpress 分页文章静态化的更优解决方案升级到 WordPress 2.6升级到 WordPress 2.5 RC1Voidman.com &#124; Link: http://www.voidman.com/2009/01/at-reply-mail-notification-test.html]]></description>
			<content:encoded><![CDATA[<p>想给博客加上访客留言被回复时邮件通知留言者的功能，本不想折腾，只不过试用了几个插件，都觉得不尽满意，便自己写了一个，先实现了几个功能：</p>
<ul>
<li>访客可以针对每篇日志选择是否接收邮件通知</li>
<li>访客可以针对每篇日志选择接收何种评论通知</li>
<li>访客可以点击邮件底部的链接取消邮件通知</li>
</ul>
<p>对于使用 @+留言者 形式的回复暂未作邮件通知，需点击留言者名称右边的小图标 <img src="http://www.voidman.com/wp-content/themes/wpcandy/images/reply.png" alt="reply icon" /> 回复。回复通知只对即日起的新留言有效。</p>
<p>欢迎在此留言，灌水。</p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html" title="At Reply Mail Notification 1.0 Release">At Reply Mail Notification 1.0 Release</a></li><li><a href="http://www.voidman.com/2008/03/improve-wp-plugin-head-meta-description.html" title="对 Head META Description 的一些改进">对 Head META Description 的一些改进</a></li><li><a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html" title="WordPress 的 Hook 机制在 Discuz 二次开发中的应用">WordPress 的 Hook 机制在 Discuz 二次开发中的应用</a></li><li><a href="http://www.voidman.com/2009/03/lbs-to-wordpress.html" title="LBS 转 WordPress 不完全记录">LBS 转 WordPress 不完全记录</a></li><li><a href="http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html" title="Wordpress 糟糕的重复评论检测方式">Wordpress 糟糕的重复评论检测方式</a></li><li><a href="http://www.voidman.com/2008/11/automatically-delete-post-revisions.html" title="让 Wordpress 自动删除 Post Revisions">让 Wordpress 自动删除 Post Revisions</a></li><li><a href="http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html" title="让 Google Sitemaps Generator 可以忽略指定的日志分类">让 Google Sitemaps Generator 可以忽略指定的日志分类</a></li><li><a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html" title="Wordpress 分页文章静态化的更优解决方案">Wordpress 分页文章静态化的更优解决方案</a></li><li><a href="http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html" title="升级到 WordPress 2.6">升级到 WordPress 2.6</a></li><li><a href="http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html" title="升级到 WordPress 2.5 RC1">升级到 WordPress 2.5 RC1</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html">http://www.voidman.com/2009/01/at-reply-mail-notification-test.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2009/01/at-reply-mail-notification-test.html/feed</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Moved to (mt) Media Temple</title>
		<link>http://www.voidman.com/2009/01/moved-to-mt-media-temple.html</link>
		<comments>http://www.voidman.com/2009/01/moved-to-mt-media-temple.html#comments</comments>
		<pubDate>Wed, 07 Jan 2009 02:00:29 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[media temple]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=222</guid>
		<description><![CDATA[Bluehost 空间快到期了，续费要 $9.95/mo，近来访问速度也不那么稳定，于是打算和 bluehost 说拜拜，碰巧看见大猫在勾引大家，好么，那咱也用 gift card zhuangbility 一回。 虽然被“幸运”抽到需要电话确认订单，不过还好没有发生 RPWT，不然如若分配的 IP 已经被 GFWed 那就白折腾了。 简单地测试了下，ping 延时]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.voidman.com/wp/2009/01/mt-250x140-lt.png" alt="Media Temple" style="width:250px; height: 140px"/></p>
<p>Bluehost 空间快到期了，<a href="http://www.storyday.com/html/y2008/2035_bluehost-renew-price.html">续费</a>要 $9.95/mo，近来访问速度也不那么稳定，于是打算和 bluehost 说拜拜，碰巧看见<a href="http://ooxx.me/media-temple-gift-card.orz" title="(MT)Media Temple Gift Card">大猫在勾引大家</a>，好么，那咱也用 <a href="http://www.mediatemple.net/webhosting/thehostingcard/?utm_source=gcfooter&#038;utm_medium=link&#038;utm_campaign=gc08" title="The Hosting Gift Card">gift card</a> zhuangbility 一回。</p>
<p>虽然被“幸运”抽到需要电话确认订单，不过还好没有发生 RPWT，不然如若分配的 IP 已经被 GFWed 那就白折腾了。</p>
<p>简单地测试了下，ping 延时 <= 210ms，FTP 上传速度稳定在 52Kb/s，下载速度 140 Kb/s，对于 2M ADSL 来说，这速度我已经很满意了。</p>
<p>迁移过程基本顺利，除了设置数据库密码的时候被小小郁闷了下，貌似 MT 不支持在数据库密码中使用某些特殊字符。</p>
<p>BTW: 比较喜欢 MT 的界面，简洁而不失华丽。</p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2009/11/media-temple-hacked.html" title="Media Temple Hacked">Media Temple Hacked</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2009/01/moved-to-mt-media-temple.html">http://www.voidman.com/2009/01/moved-to-mt-media-temple.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2009/01/moved-to-mt-media-temple.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Favicon</title>
		<link>http://www.voidman.com/2008/12/favicon.html</link>
		<comments>http://www.voidman.com/2008/12/favicon.html#comments</comments>
		<pubDate>Wed, 03 Dec 2008 14:52:01 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[favicon]]></category>
		<category><![CDATA[favorites icon]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=208</guid>
		<description><![CDATA[昨日请Cure帮忙设计 favicon ，没想到今早就发过来了： 第一个取自虚空行者(voidman)的形象，看上去有些邪恶 ，我还是用第二个好了，试了下效果，感觉还不错。 Thanks to Cure. Voidman.com &#124; Link: http://www.voidman.com/2008/12/favicon.html]]></description>
			<content:encoded><![CDATA[<p>昨日请<a href="http://www.s-isle.com/blog">Cure</a>帮忙设计 favicon ，没想到今早就发过来了：</p>
<p class="imgwrap"><img src="/uploads/wp/2008/12/favicon.png" alt="favorites icon" class="grayborder" /></p>
<p>第一个取自虚空行者(voidman)的形象，看上去有些邪恶  <img src='http://www.voidman.com/wp-includes/images/smilies/icon_twisted.gif' alt=':twisted:' class='wp-smiley' />  ，我还是用第二个好了，试了下效果，感觉还不错。</p>
<p class="imgwrap"><img src="/uploads/wp/2008/12/favicon-effects.png" alt="favicon effects" class="grayborder" /></p>
<p>Thanks to <a href="http://www.s-isle.com/blog">Cure</a>.</p>
<hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2008/12/favicon.html">http://www.voidman.com/2008/12/favicon.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2008/12/favicon.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Yahoo 域名转出至 GoDaddy 记录</title>
		<link>http://www.voidman.com/2008/11/transfer-domain-from-yahoo-to-godaddy.html</link>
		<comments>http://www.voidman.com/2008/11/transfer-domain-from-yahoo-to-godaddy.html#comments</comments>
		<pubDate>Wed, 26 Nov 2008 12:53:38 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[domain transfer]]></category>
		<category><![CDATA[godaddy]]></category>
		<category><![CDATA[paypal]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=201</guid>
		<description><![CDATA[幸好提前去 Yahoo 看了下域名的续费情况，不然还不知道 Yahoo 的域名年费狂涨到 $34.95，实在是太不厚道了！ 于是决定将域名转出至 GoDaddy，不过却没想到过程却这么麻烦： 注册了国内的贝宝，发现不能添加信用卡才意识到注册错了地方，于是删除该帐号。 去注册了 PayPal 国际重新注册了帐号，花了两天时间验证了信用卡。 注册了 GoDaddy 帐号，填写相关信息，开始按步骤转入域名。不料折腾一晚上，checkout order 时始终提示“Transaction refused due to risk model”，抓狂。 咨询了 cosbeta，未果。本还想兑些美元直接付款，不过 cosbeta 说不一定有作用，PayPal 帐号可能太新了。 在 taobao 看见有人代购 e-Gift Card，可精确到美分。买了足够的金额，终于 checkout 成功。 上 Yahoo 解锁域名后，登录 GoDaddy 后点击 Pending Domain Transfers 继续开始转入域名进程，填写 Transaction ID, Security Code, Authorization Code 相关信息，点击了几个按钮后，等待域名转入邮件通知。 足足等了 5 天，终于收到 GoDaddy 发来的域名转入成功的确认邮件。在 [...]]]></description>
			<content:encoded><![CDATA[<p>幸好提前去 Yahoo 看了下域名的续费情况，不然还不知道 Yahoo 的域名年费<a href="http://tech.sina.com.cn/i/2008-06-29/09182290808.shtml" rel="external nofollow">狂涨</a>到 $34.95，实在是太不厚道了！</p>
<p>于是决定将域名转出至 GoDaddy，不过却没想到过程却这么麻烦： </p>
<ol>
<li>注册了国内的贝宝，发现不能添加信用卡才意识到注册错了地方，于是删除该帐号。</li>
<li>去注册了 PayPal 国际重新注册了帐号，花了两天时间验证了信用卡。 </li>
<li>注册了 GoDaddy 帐号，填写相关信息，开始按步骤转入域名。不料折腾一晚上，checkout order 时始终提示“Transaction refused due to risk model”，抓狂。</li>
<li>咨询了 <a href="http://www.storyday.com" rel="external nofollow">cosbeta</a>，未果。本还想兑些美元直接付款，不过 cosbeta 说不一定有作用，PayPal 帐号可能太新了。</li>
<li>在 taobao 看见有人代购 e-Gift Card，可精确到美分。买了足够的金额，终于 checkout 成功。</li>
<li>上 Yahoo 解锁域名后，登录 GoDaddy 后点击 Pending Domain Transfers 继续开始转入域名进程，填写 Transaction ID, Security Code, Authorization Code 相关信息，点击了几个按钮后，等待域名转入邮件通知。</li>
<li>足足等了 5 天，终于收到 GoDaddy 发来的域名转入成功的确认邮件。在 Yahoo 取消了域名服务。重新设置了域名解析。GoDaddy 解析速度很快。</li>
</ol>
<p>相关参考链接：<br />
<a href="http://help.yahoo.com/l/us/yahoo/smallbusiness/domains/accountmanagement/accountmanagement-24.html" rel="external nofollow">How do I transfer my yahoo domain to a new registrar</a><br />
<a title="域名转移到 Godaddy 图文教程" href="http://www.daigou.in/thread-95-1-6.html" rel="external nofollow">域名转移到 Godaddy 图文教程</a><br />
<a href="http://bbs.idcspy.com/thread-1618-1-1.html" rel="external nofollow">Godaddy 域名使用说明</a></p>
<hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2008/11/transfer-domain-from-yahoo-to-godaddy.html">http://www.voidman.com/2008/11/transfer-domain-from-yahoo-to-godaddy.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2008/11/transfer-domain-from-yahoo-to-godaddy.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>让 WordPress 自动删除 Post Revisions</title>
		<link>http://www.voidman.com/2008/11/automatically-delete-post-revisions.html</link>
		<comments>http://www.voidman.com/2008/11/automatically-delete-post-revisions.html#comments</comments>
		<pubDate>Tue, 18 Nov 2008 01:00:52 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[revisions]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP_Cron]]></category>
		<category><![CDATA[计划任务]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=188</guid>
		<description><![CDATA[貌似在 wp-config.php 中加入 define(’WP_POST_REVISIONS’, false); 来禁用 WordPress 的日志修订功能，post revision 还是会产生。gohsy 同学写了个插件 Revision Manager 来清理 post revision，不过个人觉得手动清理还是不够方便，决定利用 WordPress 的计划任务功能(WP_Cron)偷偷懒。 不想为了这小小的功能而多添加一个插件，所以在主题目录下的 functions.php 文件添加了以下代码： function delete_post_revisions&#40;&#41; &#123; global $wpdb; &#160; // Also need to delete the post meta and term relationships $wpdb-&#62;query&#40;&#34;DELETE FROM {$wpdb-&#62;postmeta} WHERE post_id IN (SELECT ID FROM {$wpdb-&#62;posts} WHERE post_type = 'revision')&#34;&#41;; $wpdb-&#62;query&#40;&#34;DELETE FROM {$wpdb-&#62;term_relationships} [...]]]></description>
			<content:encoded><![CDATA[<p>貌似在 <code>wp-config.php</code> 中加入 <code>define(’WP_POST_REVISIONS’, false);</code> 来禁用 WordPress 的日志修订功能，post revision 还是会产生。<a href="http://blog.gohsy.com/" rel="external nofollow">gohsy</a> 同学写了个插件 <a href="http://blog.gohsy.com/topics/delete-revision-plugin.html" rel="external nofollow">Revision Manager</a> 来清理 post revision，不过个人觉得手动清理还是不够方便，决定利用 WordPress 的计划任务功能(WP_Cron)偷偷懒。</p>
<p>不想为了这小小的功能而多添加一个插件，所以在主题目录下的 <code>functions.php</code> 文件添加了以下代码：</p>

<div class="wp_syntax"><pre class="php"><span style="color: blue;">function</span> delete_post_revisions<span style="color: #800000;">&#40;</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
  <span style="color: blue;">global</span> <span style="color: #008080;">$wpdb</span>;
&nbsp;
  <span style="color: #008000; font-style: italic;">// Also need to delete the post meta and term relationships</span>
  <span style="color: #008080;">$wpdb</span>-&gt;<span style="color: #006600;">query</span><span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">&quot;DELETE FROM {$wpdb-&gt;postmeta} WHERE post_id IN (SELECT ID FROM {$wpdb-&gt;posts} WHERE post_type = 'revision')&quot;</span><span style="color: #800000;">&#41;</span>;
  <span style="color: #008080;">$wpdb</span>-&gt;<span style="color: #006600;">query</span><span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">&quot;DELETE FROM {$wpdb-&gt;term_relationships} WHERE object_id IN (SELECT ID FROM {$wpdb-&gt;posts} WHERE post_type = 'revision')&quot;</span><span style="color: #800000;">&#41;</span>;
&nbsp;
  <span style="color: #008000; font-style: italic;">// Delete the post revisions</span>
  <span style="color: #008080;">$wpdb</span>-&gt;<span style="color: #006600;">query</span><span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">&quot;DELETE FROM {$wpdb-&gt;posts} WHERE post_type = 'revision'&quot;</span><span style="color: #800000;">&#41;</span>;
<span style="color: #800000;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic;">// Register the event</span>
add_action<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'delete_post_revisions_event'</span>, <span style="color: #ff00ff;">'delete_post_revisions'</span><span style="color: #800000;">&#41;</span>;
<span style="color: blue;">if</span> <span style="color: #800000;">&#40;</span>!wp_next_scheduled<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'delete_post_revisions_event'</span><span style="color: #800000;">&#41;</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
  wp_schedule_event<span style="color: #800000;">&#40;</span><span style="color: #ff0000;">time</span><span style="color: #800000;">&#40;</span><span style="color: #800000;">&#41;</span>, <span style="color: #ff00ff;">'daily'</span>, <span style="color: #ff00ff;">'delete_post_revisions_event'</span><span style="color: #800000;">&#41;</span>;
<span style="color: #800000;">&#125;</span></pre></div>

<p><span id="more-188"></span><br />
这样 WordPress 每天会自动删除 post revision (当然得在有人访问的前提下)。其实每天运行一次也有些过于频繁了，可以将时间间隔设置得更长一些，譬如一周或者二周甚至一个月。不过 WordPress 的 Cron API 本身只提供了 hourly, daily 两个选项，所以需要自己手工添加一些运行时间间隔选项。在刚才添加的代码<strong>之前</strong>添加以下代码，</p>

<div class="wp_syntax"><pre class="php"><span style="color: blue;">function</span> add_schedule_options<span style="color: #800000;">&#40;</span><span style="color: #008080;">$schedules</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
  <span style="color: #008080;">$custom_schedules</span> = <span style="color: blue;">array</span><span style="color: #800000;">&#40;</span>
    <span style="color: #ff00ff;">'weekly'</span> =&gt; <span style="color: blue;">array</span><span style="color: #800000;">&#40;</span> <span style="color: #ff00ff;">'interval'</span> =&gt; <span style="color: #800080;">604800</span>, <span style="color: #ff00ff;">'display'</span> =&gt; __<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'Once Weekly'</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#41;</span>, 
    <span style="color: #ff00ff;">'fortnightly'</span> =&gt; <span style="color: blue;">array</span><span style="color: #800000;">&#40;</span> <span style="color: #ff00ff;">'interval'</span> =&gt; <span style="color: #800080;">1209600</span>, <span style="color: #ff00ff;">'display'</span> =&gt; __<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'Once Fortnightly'</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#41;</span>, 
    <span style="color: #ff00ff;">'monthly'</span> =&gt; <span style="color: blue;">array</span><span style="color: #800000;">&#40;</span> <span style="color: #ff00ff;">'interval'</span> =&gt; <span style="color: #800080;">2592000</span>, <span style="color: #ff00ff;">'display'</span> =&gt; __<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'Once Monthly'</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#41;</span>, 
  <span style="color: #800000;">&#41;</span>;
&nbsp;
  <span style="color: blue;">return</span> <span style="color: #ff0000;">array_merge</span><span style="color: #800000;">&#40;</span><span style="color: #008080;">$custom_schedules</span>, <span style="color: #008080;">$schedules</span><span style="color: #800000;">&#41;</span>;
<span style="color: #800000;">&#125;</span>
add_filter<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'cron_schedules'</span>, <span style="color: #ff00ff;">'add_schedule_options'</span><span style="color: #800000;">&#41;</span>;</pre></div>

<p>然后把 <code>wp_schedule_event</code> 函数的第二个参数值 daily 改成 weekly 或  fortnightly 或 monthly 即可。</p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html" title="WordPress 的 Hook 机制在 Discuz 二次开发中的应用">WordPress 的 Hook 机制在 Discuz 二次开发中的应用</a></li><li><a href="http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html" title="At Reply Mail Notification 1.0 Release">At Reply Mail Notification 1.0 Release</a></li><li><a href="http://www.voidman.com/2009/03/lbs-to-wordpress.html" title="LBS 转 WordPress 不完全记录">LBS 转 WordPress 不完全记录</a></li><li><a href="http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html" title="Wordpress 糟糕的重复评论检测方式">Wordpress 糟糕的重复评论检测方式</a></li><li><a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html" title="At Reply Mail Notification 测试贴">At Reply Mail Notification 测试贴</a></li><li><a href="http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html" title="让 Google Sitemaps Generator 可以忽略指定的日志分类">让 Google Sitemaps Generator 可以忽略指定的日志分类</a></li><li><a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html" title="Wordpress 分页文章静态化的更优解决方案">Wordpress 分页文章静态化的更优解决方案</a></li><li><a href="http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html" title="升级到 WordPress 2.6">升级到 WordPress 2.6</a></li><li><a href="http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html" title="升级到 WordPress 2.5 RC1">升级到 WordPress 2.5 RC1</a></li><li><a href="http://www.voidman.com/2008/03/wordpress-theme-wpcandy-remix.html" title="WordPress Theme WPCandy Remix">WordPress Theme WPCandy Remix</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2008/11/automatically-delete-post-revisions.html">http://www.voidman.com/2008/11/automatically-delete-post-revisions.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2008/11/automatically-delete-post-revisions.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>让 Google Sitemaps Generator 可以忽略指定的日志分类</title>
		<link>http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html</link>
		<comments>http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html#comments</comments>
		<pubDate>Sat, 15 Nov 2008 12:38:18 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog Related]]></category>
		<category><![CDATA[Google Sitemaps Generator]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.voidman.com/?p=186</guid>
		<description><![CDATA[在之前使用 HemingwayEx 主题的时候我把一些只有半句或几句话的日志移动到了 asides 分类，而现在我不想让 Google Sitemaps Generator 插件生成 sitemap 的时候包括这些日志，也许只有我才会有这样奇怪的需求 。 可 Google XML Sitemaps 只能忽略指定的日志或页面，而不能忽略整个分类，所以只能自己动手了。 1. 打开插件目录下的 sitemap-core.php 文件，找到： $where.=&#34; AND post_password='' ORDER BY post_modified DESC&#34;; &#160; $sql .= $where; 修改成： $where.=&#34; AND post_password='' ORDER BY post_modified DESC&#34;; $where = apply_filters&#40;'sitemap_exclude_categories', $where&#41;; $sql .= $where; 2. 打开主题目录下的 functions.php 文件，添加一下代码： function sitemap_exclude_categories&#40;$where&#41; &#123; global [...]]]></description>
			<content:encoded><![CDATA[<p>在之前使用 <a href="http://nalinmakar.com/hemingwayex" rel="external nofollow">HemingwayEx</a> 主题的时候我把一些只有半句或几句话的日志移动到了 asides 分类，而现在我不想让 <a href="http://www.arnebrachhold.de/projects/wordpress-plugins/google-xml-sitemaps-generator/" rel="external nofollow">Google Sitemaps Generator</a> 插件生成 sitemap 的时候包括这些日志，也许只有我才会有这样奇怪的需求 <img src='http://www.voidman.com/wp-includes/images/smilies/icon_eek.gif' alt=':shock:' class='wp-smiley' />   。</p>
<p>可 Google XML Sitemaps 只能忽略指定的日志或页面，而不能忽略整个分类，所以只能自己动手了。</p>
<p>1. 打开插件目录下的 <code>sitemap-core.php</code> 文件，找到：</p>

<div class="wp_syntax"><pre class="php"><span style="color: #008080;">$where</span>.=<span style="color: #ff00ff;">&quot; AND post_password='' ORDER BY post_modified DESC&quot;</span>;
&nbsp;
<span style="color: #008080;">$sql</span> .= <span style="color: #008080;">$where</span>;</pre></div>

<p>修改成：</p>

<div class="wp_syntax"><pre class="php"><span style="color: #008080;">$where</span>.=<span style="color: #ff00ff;">&quot; AND post_password='' ORDER BY post_modified DESC&quot;</span>;
<span style="color: #008080;">$where</span> = apply_filters<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'sitemap_exclude_categories'</span>, <span style="color: #008080;">$where</span><span style="color: #800000;">&#41;</span>;
<span style="color: #008080;">$sql</span> .= <span style="color: #008080;">$where</span>;</pre></div>

<p><span id="more-186"></span><br />
2. 打开主题目录下的 <code>functions.php</code> 文件，添加一下代码：</p>

<div class="wp_syntax"><pre class="php"><span style="color: blue;">function</span> sitemap_exclude_categories<span style="color: #800000;">&#40;</span><span style="color: #008080;">$where</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
  <span style="color: blue;">global</span> <span style="color: #008080;">$wpdb</span>;
  <span style="color: #008080;">$cates</span> = <span style="color: blue;">array</span><span style="color: #800000;">&#40;</span><span style="color: #800080;">11</span><span style="color: #800000;">&#41;</span>; <span style="color: #008000; font-style: italic;">// 在这里指定要忽略的类别id，多个类别id用半角逗号分隔</span>
  <span style="color: blue;">if</span> <span style="color: #800000;">&#40;</span><span style="color: #ff0000;">count</span><span style="color: #800000;">&#40;</span><span style="color: #008080;">$cates</span><span style="color: #800000;">&#41;</span> &gt; <span style="color: #800080;">0</span><span style="color: #800000;">&#41;</span> <span style="color: #800000;">&#123;</span>
    <span style="color: #008080;">$table_posts</span> = <span style="color: #008080;">$wpdb</span>-&gt;<span style="color: #006600;">posts</span>;
    <span style="color: #008080;">$exclude</span> = <span style="color: #ff00ff;">&quot;(NOT EXISTS (
      SELECT r.object_id FROM {$wpdb-&gt;term_relationships} r 
      INNER JOIN {$wpdb-&gt;term_taxonomy} t ON r.term_taxonomy_id = t.term_taxonomy_id 
      WHERE t.taxonomy = 'category' AND t.term_id IN (&quot;</span>.<span style="color: #ff0000;">join</span><span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">','</span>, <span style="color: #008080;">$cates</span><span style="color: #800000;">&#41;</span>.<span style="color: #ff00ff;">&quot;) AND r.object_id = `&quot;</span>.<span style="color: #008080;">$table_posts</span>.<span style="color: #ff00ff;">&quot;`.ID
    ))&quot;</span>;
    <span style="color: #008080;">$where</span> = <span style="color: #008080;">$exclude</span>.<span style="color: #ff00ff;">'  AND '</span>.<span style="color: #008080;">$where</span>;
  <span style="color: #800000;">&#125;</span>
&nbsp;
  <span style="color: blue;">return</span> <span style="color: #008080;">$where</span>;
<span style="color: #800000;">&#125;</span>
add_filter<span style="color: #800000;">&#40;</span><span style="color: #ff00ff;">'sitemap_exclude_categories'</span>, <span style="color: #ff00ff;">'sitemap_exclude_categories'</span><span style="color: #800000;">&#41;</span>;</pre></div>

<p>通过 WordPress 自身提供的 Hook API 来实现功能主要是为了尽可能避免过多地修改原插件的代码，以免插件升级时带来麻烦。现在这样升级插件时只要重做第一步就可以了。</p>
<p><strong>UPDATE @ 2009-3-22</strong><br />
最新版本的 Google XML Sitemaps 插件增加了日志分类过滤功能，不过由于它会将被过滤分类下的所有日志 ID 都取出来然后用 NOT IN 来实现过滤，这样在日志数多的情况下效率不高。</p>
<h4>Related Posts</h4><ul class="related_post"><li><a href="http://www.voidman.com/2009/05/using-wordpress-plugin-api-hack-discuz.html" title="WordPress 的 Hook 机制在 Discuz 二次开发中的应用">WordPress 的 Hook 机制在 Discuz 二次开发中的应用</a></li><li><a href="http://www.voidman.com/2009/04/at-reply-mail-notification-1-release.html" title="At Reply Mail Notification 1.0 Release">At Reply Mail Notification 1.0 Release</a></li><li><a href="http://www.voidman.com/2009/03/lbs-to-wordpress.html" title="LBS 转 WordPress 不完全记录">LBS 转 WordPress 不完全记录</a></li><li><a href="http://www.voidman.com/2009/01/wordpress-is-using-a-bad-way-to-detect-duplicate-comment.html" title="Wordpress 糟糕的重复评论检测方式">Wordpress 糟糕的重复评论检测方式</a></li><li><a href="http://www.voidman.com/2009/01/at-reply-mail-notification-test.html" title="At Reply Mail Notification 测试贴">At Reply Mail Notification 测试贴</a></li><li><a href="http://www.voidman.com/2008/11/automatically-delete-post-revisions.html" title="让 Wordpress 自动删除 Post Revisions">让 Wordpress 自动删除 Post Revisions</a></li><li><a href="http://www.voidman.com/2008/11/the-better-solution-for-static-paged-post.html" title="Wordpress 分页文章静态化的更优解决方案">Wordpress 分页文章静态化的更优解决方案</a></li><li><a href="http://www.voidman.com/2008/07/upgraded-to-wordpress-v26.html" title="升级到 WordPress 2.6">升级到 WordPress 2.6</a></li><li><a href="http://www.voidman.com/2008/03/upgraded-to-wordpress-25-rc1.html" title="升级到 WordPress 2.5 RC1">升级到 WordPress 2.5 RC1</a></li><li><a href="http://www.voidman.com/2008/03/wordpress-theme-wpcandy-remix.html" title="WordPress Theme WPCandy Remix">WordPress Theme WPCandy Remix</a></li></ul><hr /><a href="http://www.voidman.com">Voidman.com</a> | Link: <a href="http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html">http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html</a><br /><img alt="linezing" width="1" height="1" src="http://img.tongji.linezing.com/288120/tongji.gif" />]]></content:encoded>
			<wfw:commentRss>http://www.voidman.com/2008/11/google-xml-sitemaps-ignore-the-specified-categories.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
