WordPress eXtended Rss (WXR)文件格式解析

Sina2WordPress的第一步——解析WXR文件格式

WXR是Wordpress eXtended Rss的缩写,是WordPress针对博客信息特意设定的格式,它最大的优点是兼容性好,包含信息丰富

通过参照导出的文件,初步找到一个完备集(见下方代码),经测试在WP无任何内容情况下无信息缺漏错误现象

下方代码已经尽可能的注释了所有可能的标签和属性,并且由于一些标签和属性与Sina2WordPress关系不大,故未深究

< ?xml version="1.0" encoding="UTF-8" ?>

<rss version="2.0"
	xmlns:excerpt="http://wordpress.org/export/1.1/excerpt/"
	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:wp="http://wordpress.org/export/1.1/"
>
<!--RSS版本号和名字空间的扩展,以上为固定内容-->

<channel>
	<title>Blog Title</title>
	<!--博客的标题-->
	<link>http://blog.example.com</link>
	<!--博客的链接-->
	<description>Blog Description</description>
	<!--博客的说明/副标题-->
	<pubdate>Dec, 20 Jun 2012 23:59:59 +0000</pubdate>
	<!--WXR文件生成时间-->
	<language>en</language>
	<!--博客的语言,en / zh-cn-->
	<wp:wxr_version>1.1</wp:wxr_version>
	<!--WXR格式版本号-->
	<wp:base_site_url>http://example.com</wp:base_site_url>
	<!--网站根目录地址-->
	<wp:base_blog_url>http://blog.example.com</wp:base_blog_url>
	<!--博客根目录地址-->

	<wp:author><wp:author_id>1</wp:author_id><wp:author_login>admin_test</wp:author_login><wp:author_email>admin@example.org</wp:author_email><wp:author_display_name>< ![CDATA[AdMin test]]></wp:author_display_name><wp:author_first_name>< ![CDATA[AdMin]]></wp:author_first_name><wp:author_last_name>< ![CDATA[test]]></wp:author_last_name></wp:author>
	<!--
		作者列表,可多个
		wp:author_id:自增序号
		wp:author_login:用户名
		wp:author_email:邮箱
		wp:author_display_name:显示的作者名称
		wp:author_first_name、wp:author_last_name:如字面意,可为空,但需有<![CDATA[]]>
		P.S.< ![CDATA[**]]>可以理解成强制文本转换,保留文本中所有字符,以避免非法字符对XML文件的影响(后文不再赘述)
	-->

	<wp:category><wp:term_id>1</wp:term_id><wp:category_nicename>category_test</wp:category_nicename><wp:category_parent></wp:category_parent><wp:cat_name>< ![CDATA[分类测试]]></wp:cat_name></wp:category>
	<!--
		分类列表,可多个
		wp:term_id:自增序号,且分类和标签用的是同一个
		wp:category_nicename:URL友好名称,作为相关URL的一部分
		wp:category_parent:父分类,无即为空
		wp:cat_name:显示的分类名称
	-->

	<wp:tag><wp:term_id>2</wp:term_id><wp:tag_slug>tag_test</wp:tag_slug><wp:tag_name>< ![CDATA[标签测试]]></wp:tag_name></wp:tag>
	<!--
		标签列表,可多个
		wp:term_id:自增序号,与标签使用同一个序列
		wp:tag_slug:URL友好名称,作为相关URL的一部分
		wp:tag_name:显示的标签名称
	-->

	<generator>http://wordpress.org/?v=3.1.3</generator><!--WXR文件生成工具的标识-->

	<item><!--页面或者日志内容,每个为一个item-->
		<title>Title</title>
		<!--标题-->
		<link>http://blog.example.com/title/</link>
		<!--URL地址-->
		<pubdate>Thu, 15 Apr 2010 23:20:03 +0000</pubdate>
		<!--发布时间-->
		<dc:creator>admin</dc:creator>
		<!--文章作者-->
		<guid isPermaLink="false">http://blog.example.com/?page_id=1</guid>
		<!--
			GUID 意为 Global Unique IDentification,即全局唯一标识
			isPermaLink="false" 指示该地址非合法URL地址的属性
		-->
		<description></description>
		<content:encoded>< ![CDATA[Content_test_1]]></content:encoded>
		<!--这里是正文内容-->
		<excerpt:encoded>< ![CDATA[]]></excerpt:encoded>
		<!--文章摘录,供RSS/Atom使用,一般为空-->
		<wp:post_id>2</wp:post_id>
		<!--页面或日志的序号,两者使用同一序列-->
		<wp:post_date>2012-12-21 07:59:5</wp:post_date>
		<!--发表时间-->
		<wp:post_date_gmt>2010-12-20 23:59:59</wp:post_date_gmt>
		<!--发表时间(GMT)-->
		<wp:comment_status>open</wp:comment_status>
		<!--评论开启情况,open / closed-->
		<wp:ping_status>closed</wp:ping_status>
		<!--Ping开启情况,open / closed-->
		<wp:post_name>blog_title</wp:post_name>
		<!--URL友好的名称-->
		<wp:status>publish</wp:status>
		<!--页面或日志状态,publish / draft / pending / private-->
		<wp:post_parent>0</wp:post_parent>
		<!--只用于页面,指示父页面的id-->
		<wp:menu_order>0</wp:menu_order>
		<!--只用与页面,作为导航时的排序权值-->
		<wp:post_type>post</wp:post_type>
		<!--文章类型,post / page-->
		<wp:post_password></wp:post_password>
		<!--文章是否加密-->
		<wp:is_sticky>0</wp:is_sticky>
		<!--文章是否置顶,0 / 1-->

		<category domain="post_tag" nicename="tag_test">< ![CDATA[Tag Test]]></category>
		<category domain="category" nicename="category_test">< ![CDATA[Category]]></category>
		<!--
			日志或页面的标签和分类,可多个
			domain:标签对应post_tag,分类对应category
			nicename:对应标签或分类的URL友好名称
			<![CDATA[]]>:标签或分类的显示名称
		-->

		<wp:postmeta><!--日志或页面的元数据,可多个-->
			<wp:meta_key>_edit_last</wp:meta_key>
			<!--元数据的关键字-->
			<wp:meta_value>< ![CDATA[1]]></wp:meta_value>
			<!--元数据对应关键字的值-->
		</wp:postmeta>

		<wp:comment><!--评论,可多个-->
			<wp:comment_id>1</wp:comment_id>
			<!--自增序号,评论专用-->
			<wp:comment_author>< ![CDATA[anonymous]]></wp:comment_author>>
			<!--评论者用户名-->
			<wp:comment_author_email>anonymous@anonymous.com</wp:comment_author_email>
			<!--评论者邮箱-->
			<wp:comment_author_url>http://blog.anonymous.com</wp:comment_author_url>
			<!--评论者链接-->
			<wp:comment_author_ip>8.8.8.8</wp:comment_author_ip>
			<!--评论者IP-->
			<wp:comment_date>2012-12-21 07:59:59</wp:comment_date>
			<!--评论时间-->
			<wp:comment_date_gmt>2012-12-20 23:59:59</wp:comment_date_gmt>
			<!--评论时间(GMT)-->
			<wp:comment_content>< ![CDATA[Content of Comment]]></wp:comment_content>
			<!--评论内容-->
			<wp:comment_approved>1</wp:comment_approved>
			<!--评论是否被允许-->
			<wp:comment_type></wp:comment_type>
			<!--评论类型,空白表示一般评论,否则会标记位pingback-->
			<wp:comment_parent>0</wp:comment_parent>
			<!--父评论,指定所回复的评论-->
			<wp:comment_user_id>0</wp:comment_user_id>
			<!--如果评论者为注册用户,这里会记录用户ID-->
		</wp:comment>
	</item>
</channel>
</rss>

参考:http://ipggi.wordpress.com/2011/03/16/the-wordpress-extended-rss-wxr-exportimport-xml-document-format-decoded-and-explained/

VPS杂记

入手VPS好久了,用的是LNMP架构,在Evernote中压了一些笔记,一一贴出来示众~

安装lnmp
注:版本可能有更新,0.7为截至2011/06/03的最新版

wget http://soft.vpser.net/lnmp/lnmp0.7.tar.gz
tar zxvf lnmp0.7.tar.gz
cd lnmp0.7/
./ubuntu.sh

创建虚拟主机

/root/vhost.sh

root账户的使用
平时使用普通账户登录,需要使用root权限的时候用su命令,然后再输入root命令,使用完root权限之后可以用ctrl+D退出权限,继续使用普通账户权限,这样可以防止权限的混乱

安装OpenVPN

wget http://vpsnoc.com/scripts/debian-openvpn.sh
chmod +x debian-openvpn.sh
./debian-openvpn.sh

按照提示安装完成后下载keys.tgz,将其解压到OpenVPN安装目录下的config子目录,然后启动OpenVPN就可以使用了

wordpress的rewrite问题
默认的规则有点小问题,替换为以下的即可:

if  (!-e $request_filename)
{
    rewrite (.*) /index.php;
}

WordPress文件权限

chown -R www.www /blog

解决在Ubuntu上搭建Android开发环境缺少WST包的问题

前言:之前写过一篇《Ubuntu 10.04安装Android开发环境》,每天都有不少访问量,估计很多就是遇到了这个问题,一直压在Evernote里没有翻出来,现在已转入Arch阵营,没有再次验证解决方案的正确性,完全参照印象和笔记,有问题尽管留言

平台:Ubuntu 10.10和Ubuntu 11.04,10.04(写那一篇日志的时候)无此问题

原因:Ubuntu下的Eclipse是Ubuntu社区打包的,非完整版,少了WST包的支持

现象:安装ADT的时候会提示类似如下错误(版本号可能会有不同):

Cannot complete the install because one or more required items could not be found.  Software being installed: Android Development Tools 10.0.1.v201103111512-110841 (com.android.ide.eclipse.adt.feature.group 0.0.1.v201103111512-110841)  Missing requirement: Android Development Tools 10.0.1.v201103111512-10841 (com.android.ide.eclipse.adt.feature.group 10.0.1.v201103111512-110841) requires 'org.eclipse.wst.sse.core 0.0.0' but it could not be found

解决方案
方案1:直接从Eclipse官网下载完整的安装包
方案2:遵照以下菜单顺序或提示执行

1:Help --> Install New Software --> Add --> type 'http://download.eclipse.org/releases/galileo' in the Location -->OK
2:Help --> Install New Software --> Add --> type 'http://dl.google.com/eclipse/plugin/3.5' in the Location --> OK
3:Please make sure the option 'Contact all updates sites during install to find required software' is checked.
4:Restart Eclipse,Reinstall ADT

相关参照
1)http://code.google.com/intl/es/eclipse/docs/faq.html#wstinstallerror
2)http://code.google.com/intl/es/eclipse/docs/install-eclipse-3.5.html

P.S.本文参与“第二届 Google 暑期大学生博客分享大赛 – 2011 Android 成长篇”,感谢大家支持

Shell 自动补全

1) /etc/passwd

It shows like this

huxuan:x:1002:1002::/home/huxuan:/bin/bash

in format of

Username:Password:User ID (UID):Group ID (GID):User ID Info:Home directory:Command/shell

Make sure the Command/shell is the “/bin/bash” and not the “/bin/sh” which may be the default value.

2) $HOME$/.bashrc or /etc/bash.bashrc
Make sure the code blew is not commented out.

if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

3) Reference
http://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/

使用密钥自动登录SSH(更新ssh-copy-id)

【更新】
lyxint提醒,发现了ssh-copy-id命令,第二步可以更简单的实现
ssh-copy-id -i ~/.ssh/id_rsa.pub username@hostname
其中username为用户名,hostname为服务器\VPS的IP\地址

1)在本机生成公钥密钥
ssh-keygen -t rsa
一路回车,选择默认路径即可,默认路径为~/.ssh/

2)将本地公钥上传至服务器
cat ~/.ssh/id_rsa.pub|ssh username@hostname ‘sh -c “cat – >>~/.ssh/authorized_keys”‘
其中username为用户名,hostname为服务器\VPS的IP\地址

3)ssh设置文件的几点说明(一般是默认即可)
路径:/etc/ssh/sshd_config
相关行:
PubkeyAuthentication yes #开启公钥验证
#AuthorizedKeysFile %h/.ssh/authorized_keys #公钥的位置,建议使用默认路径