<?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>PhilNaTechnology</title>
	<atom:link href="http://philna.com/category/technology/feed/" rel="self" type="application/rss+xml" />
	<link>http://philna.com</link>
	<description>找寻那些幸福...</description>
	<lastBuildDate>Wed, 16 Jun 2010 04:52:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>获取 VeryCD 站点标题</title>
		<link>http://philna.com/2010/06/get-titles-of-verycd/</link>
		<comments>http://philna.com/2010/06/get-titles-of-verycd/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 04:20:32 +0000</pubDate>
		<dc:creator>yinheli</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://philna.com/2010/06/get-titles-of-verycd/</guid>
		<description><![CDATA[前段时间眼红好友们的人人帐号级别都很高, 我就写了一个模拟登录的脚本, 每天定时登录人人并发布一个新的状态, 加快升级. 在考虑状态用语的时候, 突然想到了电驴子 VeryCD 的标题每次都不一样, 而且很多语句都非常励志, 或者积极向上. 于是考虑把它爬下来, 随机选择一个, 作为人人网状态发布. 现在我把读取 VeryCD 网站标题的代码张贴一下. PHP 方式 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 /** * 取得当日 VeryCD 的随机标题 * * @return array */ function getTitlesOfVeryCD&#40;&#41; &#123; $orgContent = file_get_contents&#40;'http://www.verycd.com/statics/title.saying'&#41;; $matchResult = preg_match&#40;'/new\s+Array\((.+)\);\s+_VC_/', [...]]]></description>
			<content:encoded><![CDATA[<p>前段时间眼红好友们的人人帐号级别都很高, 我就写了一个模拟登录的脚本, 每天定时登录人人并发布一个新的状态, 加快升级. 在考虑状态用语的时候, 突然想到了电驴子 VeryCD 的标题每次都不一样, 而且很多语句都非常励志, 或者积极向上. 于是考虑把它爬下来, 随机选择一个, 作为人人网状态发布. 现在我把读取 VeryCD 网站标题的代码张贴一下.  <img src='http://philna.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  </p>
<p><span id="more-225"></span></p>
<h2>PHP 方式</h2>

<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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933;">/**
 * 取得当日 VeryCD 的随机标题
 * 
 * @return array
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> getTitlesOfVeryCD<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$orgContent</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.verycd.com/statics/title.saying'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$matchResult</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/new\s+Array\((.+)\);\s+_VC_/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$orgContent</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$results</span> <span style="color: #339933;">=</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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$matchResult</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'\'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">', $matches[1]);
		foreach ($results as &amp;$v) {
			$v = str_replace('</span>\<span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>	
	<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$orgContent</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$results</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Java 方式</h3>

<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
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.BufferedReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStreamReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URL</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.regex.Matcher</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.regex.Pattern</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * 读取 VeryCD 的随机标题
 * 
 * @author yinheli
 *
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TitlesOfVeryCD <span style="color: #009900;">&#123;</span>
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * 取得当日全部的标题
	 * 
	 * @return 当天的标题数组
	 * @throws IOException
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> get<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">URL</span> url <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.verycd.com/statics/title.saying&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">BufferedReader</span> br <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span>
			<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span>
				url.<span style="color: #006633;">openConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		StringBuilder contentSB <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StringBuilder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span> line <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>line <span style="color: #339933;">=</span> br.<span style="color: #006633;">readLine</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: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			contentSB.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		br.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003399;">String</span> content <span style="color: #339933;">=</span> contentSB.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		Pattern p <span style="color: #339933;">=</span> Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;new<span style="color: #000099; font-weight: bold;">\\</span>s+Array<span style="color: #000099; font-weight: bold;">\\</span>((.+)<span style="color: #000099; font-weight: bold;">\\</span>);<span style="color: #000099; font-weight: bold;">\\</span>s+_VC_&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		Matcher m <span style="color: #339933;">=</span> p.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> results <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>m.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			results <span style="color: #339933;">=</span> m.<span style="color: #006633;">group</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;',<span style="color: #000099; font-weight: bold;">\\</span>s?&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> results.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				results<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> results<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;'&quot;</span>, <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> results<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Related Posts</h3>
<ul class="related_posts">
<li><a href="http://philna.com/2009/03/close-the-ads/" title="给广告一个关闭的按钮" rel="bookmark inlinks">给广告一个关闭的按钮</a><span class="count">( 22 )</span></li>
<li><a href="http://philna.com/2009/02/php-verification-code/" title="Php图片验证" rel="bookmark inlinks">Php图片验证</a><span class="count">( 16 )</span></li>
<li><a href="http://philna.com/2009/10/nofollow-links/" title="给首页的友情链接添加 nofollow" rel="bookmark inlinks">给首页的友情链接添加 nofollow</a><span class="count">( 25 )</span></li>
<li><a href="http://philna.com/2008/11/php-substr/" title="Php substr截取中文乱码" rel="bookmark inlinks">Php substr截取中文乱码</a><span class="count">( 6 )</span></li>
<li><a href="http://philna.com/2010/05/smallimagetool/" title="图片批量压缩小工具" rel="bookmark inlinks">图片批量压缩小工具</a><span class="count">( 15 )</span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://philna.com/2010/06/get-titles-of-verycd/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>数组重载在 WordPress 主题或插件设置中的应用</title>
		<link>http://philna.com/2010/01/use-array-overloading-in-the-wordpress-theme-or-plug-in-settings/</link>
		<comments>http://philna.com/2010/01/use-array-overloading-in-the-wordpress-theme-or-plug-in-settings/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 15:17:42 +0000</pubDate>
		<dc:creator>yinheli</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://philna.com/2010/01/use-array-overloading-in-the-wordpress-theme-or-plug-in-settings/</guid>
		<description><![CDATA[现在大部分的 WordPress 主题和插件都有后台设置页面, 为主题或插件添加自定义的一些功能. 这些设置会将被保存到数据库中. 然后在主题或插件中使用它们. 通常人们都是用 global 这样的关键字将他们的设置声明为一个全局变量. 或者在各个页面上都使用 get_options 这样的函数去取得设置. 然而我觉得那样处理并不好. 这里我写了个自认为较好的办法. 欢迎大家批评指正. 该方法用到了数组重载. 数组重载是将对象作为数组使用的一个过程. 为了实现这个你需要用到 ArrayAccess 接口. 以下是 ArrayAccess 接口代码清单: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 interface ArrayAccess &#123; &#160; /** * @param offset [...]]]></description>
			<content:encoded><![CDATA[<p>现在大部分的 WordPress 主题和插件都有后台设置页面, 为主题或插件添加自定义的一些功能. 这些设置会将被保存到数据库中. 然后在主题或插件中使用它们. 通常人们都是用 global 这样的关键字将他们的设置声明为一个全局变量. 或者在各个页面上都使用 get_options 这样的函数去取得设置. 然而我觉得那样处理并不好. 这里我写了个自认为较好的办法. 欢迎大家批评指正.</p>
<p>该方法用到了数组重载. 数组重载是将对象作为数组使用的一个过程. 为了实现这个你需要用到 ArrayAccess 接口.</p>
<p><span id="more-220"></span></p>
<h3>以下是 ArrayAccess 接口代码清单:</h3>

<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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">interface</span> ArrayAccess  <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009933;">/**
	 * @param offset 确定给定偏移量是否存在于数组中
	 */</span>
	abstract <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> offsetExists <span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933;">/**
	 * @param offset 取得给定偏移量上的数据
	 */</span>
	abstract <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> offsetGet <span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933;">/**
	 * @param offset 设置或替换给定偏移量上的数据
	 * @param value 要设置或替换的数据
	 */</span>
	abstract <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> offsetSet <span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933;">/**
	 * @param offset 置空给定偏移量上的数据
	 */</span>
	abstract <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> offsetUnset <span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>具体的实现办法如如下代码所示: 在这个类中我们用到了单件(例)模式.</h3>

<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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933;">/**
 * Get options
 *
 * @author yinheli
 *
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> PhilNaGetOpt implements ArrayAccess <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009933;">/**
	 * 所有设置
	 *
	 * @var array
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$philnaOpt</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933;">/**
	 * 获取设置对象
	 *
	 * @var PhilNaGetOpt
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #990000;">static</span> <span style="color: #000088;">$_instance</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933;">/**
	 * 从数据库中取得设置
	 *
	 * @return null
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$r</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'philnaopt'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">philnaOpt</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$r</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933;">/**
	 * 不许克隆
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> __clone<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933;">/**
	 * 获取 PhilNaGetOpt 单一实例
	 *
	 * @return PhilNaGetOpt
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #990000;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$_instance</span> instanceof <span style="color: #000000; font-weight: bold;">self</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$_instance</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$_instance</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933;">/**
	 * 重新取得设置
	 *
	 * @return null
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> reGet<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933;">/**
	 * 给定的偏移量是否存在?
	 *
	 * @return bool
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> offsetExists<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">philnaOpt</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933;">/**
	 * 返回给定偏移量上的数据
	 *
	 * @return null|mix
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> offsetGet<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">philnaOpt</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">philnaOpt</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">return</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">philnaOpt</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">philnaOpt</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933;">/**
	 * 设置给定偏移量上的数据
	 *
	 * @return bool|mix
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> offsetSet<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">philnaOpt</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">philnaOpt</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$val</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$val</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933;">/**
	 * 置空给定偏移量上的数据
	 *
	 * @return bool
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> offsetUnset<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">philnaOpt</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">philnaOpt</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>接下来我们我们只需要在代码的最开始时实例化刚刚的那个读取设置的类. 并将它存储到全局数组里. 例如在主题中. 我们可以在 functions.php 文件中首先做这样的事情.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'philnaopt'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> PhilNaGetOpt<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>然后我们就不用理会其他的情况, 只需要在你需要的地方调用那个设置对象. 就像是使用数组一样. 而不用不考虑它是否存在着你需要的那个键值. 很多情况下它简化了我们的一些条件判断.</p>
<h3>比如我们要判断是否需要显示首页通知</h3>
<p><strong>一般情况下.</strong> 我们的判断是:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666;">// 取得设置</span>
<span style="color: #000088;">$opt</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'philnaopt'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666;">// 判断是否有通知要显示</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$opt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'notice'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$opt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'notice'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$opt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'notice_content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$opt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'notice_content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">echo</span> <span style="color: #000088;">$opt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'notice_content'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>而是用<strong>新的办法后</strong>是这样的:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666;">// 判断并显示通知</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'philnaopt'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'notice'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'philnaopt'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'notice_content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">echo</span> <span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'philnaopt'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'notice_content'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>说明:</em><br />
当然在很多人的代码中我经常看不到 isset() 这样的函数. 事实上, 如果在开启报告全部错误的情况下. 我们在判断一个数组中的值. 我们首先要判断是否存在相应的键值. 否则 PHP 会产生一个 NOTICE 级别的错误. 加isset()这样的判断在我看来是一种比较规范的写法.</p>
<p>使用数组重载来调用设置有一个最大好处是简化判断. 当然更主要的是它规范了代码, 避免了使用 global 这样不优雅的代码.</p>
<p><strong>注意:</strong> 这个 PHP 特性只能使用在 PHP 版本 5.1.0 及其以上. 如果你使用古老的版本. 那只能作罢了.</p>
<h3>Related Posts</h3>
<ul class="related_posts">
<li><a href="http://philna.com/2009/09/highlight-keywords/" title="高亮搜索结果" rel="bookmark inlinks">高亮搜索结果</a><span class="count">( 20 )</span></li>
<li><a href="http://philna.com/2009/04/phina2/" title="主题发布: PhilNa2 " rel="bookmark inlinks">主题发布: PhilNa2 </a><span class="count">( 135 )</span></li>
<li><a href="http://philna.com/2008/12/add-ads-without-plugins/" title="不用插件放广告" rel="bookmark inlinks">不用插件放广告</a><span class="count">( 12 )</span></li>
<li><a href="http://philna.com/2009/12/prevent-the-direct-post-spam/" title="阻止直接 POST 过来的 Spam" rel="bookmark inlinks">阻止直接 POST 过来的 Spam</a><span class="count">( 37 )</span></li>
<li><a href="http://philna.com/2009/03/my-plugin-ajax-home-page/" title="我做的插件: Ajax home page" rel="bookmark inlinks">我做的插件: Ajax home page</a><span class="count">( 71 )</span></li>
<li><a href="http://philna.com/2008/10/think-again-about-the-installation-of-wordpress/" title="安装wordpress中的多余步骤?" rel="bookmark inlinks">安装wordpress中的多余步骤?</a><span class="count">( 4 )</span></li>
<li><a href="http://philna.com/2009/04/comment-sms-alert-2/" title="评论短信提醒 (补充)" rel="bookmark inlinks">评论短信提醒 (补充)</a><span class="count">( 31 )</span></li>
<li><a href="http://philna.com/2008/12/which-plugins-i-have-installed/" title="我安装的插件" rel="bookmark inlinks">我安装的插件</a><span class="count">( 25 )</span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://philna.com/2010/01/use-array-overloading-in-the-wordpress-theme-or-plug-in-settings/feed/</wfw:commentRss>
		<slash:comments>45</slash:comments>
		</item>
		<item>
		<title>阻止直接 POST 过来的 Spam</title>
		<link>http://philna.com/2009/12/prevent-the-direct-post-spam/</link>
		<comments>http://philna.com/2009/12/prevent-the-direct-post-spam/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 14:30:30 +0000</pubDate>
		<dc:creator>yinheli</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[comment]]></category>
		<category><![CDATA[Plugin]]></category>

		<guid isPermaLink="false">http://philna.com/2009/12/prevent-the-direct-post-spam/</guid>
		<description><![CDATA[几天前收到很多 spam, 居然大部分来自同一个 IP. 我只好在数据库里用 SQL 语句删掉. 再去看访问日志. 发现这个 IP 几乎是直接向我的 wp-comments-post.php 这个文件 POST 数据. 也就是说它根本没有访问文章. 我很气愤. 现在想到的解决方案是用 SESSION 来阻止. 写成插件 ( Stop post spam ). 本地测试有效. 但要是用了 HTML 静态缓存就不知到了. 可能会导致任何人都无法提交? 不过总的来说这个是不适合完全静态页面的, 除非我们的隐藏域设置为固定的值? 这个有恐怕无法到达很好的阻止作用. 两难啊. 唉. 反正我也不用缓存插件. 不管了. 交给爱折腾的人吧. 再和大家说说我的流程是怎样的. 插件激活后通过 StopPOSTSpam 类的构造函数挂载方法到 WordPress 自身的 HOOKs 上. (怎么听上去有点拗口&#8230; (- -!)) 用到的钩子: init, template_redirect, comment_form, pre_comment_on_post [...]]]></description>
			<content:encoded><![CDATA[<p>几天前收到很多 spam, 居然大部分来自同一个 IP. 我只好在数据库里用 SQL 语句删掉. 再去看访问日志. 发现这个 IP 几乎是直接向我的 wp-comments-post.php 这个文件 POST 数据. 也就是说它根本没有访问文章. 我很气愤.</p>
<p>现在想到的解决方案是用 SESSION 来阻止. 写成插件 <em>( Stop post spam )</em>. 本地测试有效. 但要是用了 HTML 静态缓存就不知到了. 可能会导致任何人都无法提交? 不过总的来说这个是不适合完全静态页面的, 除非我们的隐藏域设置为固定的值? 这个有恐怕无法到达很好的阻止作用. 两难啊. 唉. 反正我也不用缓存插件. 不管了. 交给爱折腾的人吧.</p>
<h2>再和大家说说我的流程是怎样的.</h2>
<p><span id="more-218"></span></p>
<p>插件激活后通过 StopPOSTSpam 类的构造函数挂载方法到 WordPress 自身的 HOOKs 上. (怎么听上去有点拗口&#8230; (- -!))</p>
<p>用到的钩子: init, template_redirect, comment_form,  pre_comment_on_post</p>
<h2>具体实现流程: </h2>
<p>正常访问状态, 访客访问可以评论的页面(比如普通的日志页面), PHP 执行如下:</p>
<ul>
<li>init 会将ready状态设置为 true.</li>
<li>到执行 template_redirect 的时候判断是否为评论的页面, 是则创建随机 SESSION 否则插件不再执行 Spam 判断</li>
<li>评论表达中通过 comment_form 这个 hook 添加刚刚创建的 SESSION 隐藏域.</li>
<li>提交评论的时候通过 pre_comment_on_post 这个 hook 判断 SESSION. 当然 ready 状态为 false 不判断.</li>
</ul>
<p>直接POST数据时: 没有通过 template_redirect 这一步来生成 SESSION 当然是不能通过的. 它会被当成 spam 而阻止进一步向数据库提交. </p>
<p>最后祝大家元旦快乐, 我不想写感悟, 也不想总结. 反正这半年来过的真是不怎么样. 这算是2009最后一个小时的文章吧. 过几天的考试. 唉~ 我可能会死 &#8216;很惨&#8217; . 有时间和爱心的朋友到时候可要过来安慰我啊&#8230;</p>
<p><a href="http://code.google.com/p/philna/downloads/list" title="get WP Plugin Stop post spam">下载这个插件.</a></p>
<p><strong>Update:</strong></p>
<p>在无法使用 session 的情况下改为判断来路. 不知是否试用于静态页面. 欢迎测试.<br />
<h3>Related Posts</h3>
<ul class="related_posts">
<li><a href="http://philna.com/2009/09/simple-javascript-cache/" title="基于 javascript 的简单缓存思路" rel="bookmark inlinks">基于 javascript 的简单缓存思路</a><span class="count">( 3 )</span></li>
<li><a href="http://philna.com/2008/10/think-again-about-the-installation-of-wordpress/" title="安装wordpress中的多余步骤?" rel="bookmark inlinks">安装wordpress中的多余步骤?</a><span class="count">( 4 )</span></li>
<li><a href="http://philna.com/2009/10/nofollow-links/" title="给首页的友情链接添加 nofollow" rel="bookmark inlinks">给首页的友情链接添加 nofollow</a><span class="count">( 25 )</span></li>
<li><a href="http://philna.com/2009/04/jqurey-ajax/" title="Ajax之jQuery" rel="bookmark inlinks">Ajax之jQuery</a><span class="count">( 33 )</span></li>
<li><a href="http://philna.com/2008/10/the-nterface-wordpress27-improved/" title="wordpress 2.7 试用 界面大有改进" rel="bookmark inlinks">wordpress 2.7 试用 界面大有改进</a><span class="count">( 0 )</span></li>
<li><a href="http://philna.com/2009/02/php-verification-code/" title="Php图片验证" rel="bookmark inlinks">Php图片验证</a><span class="count">( 16 )</span></li>
<li><a href="http://philna.com/2008/12/which-plugins-i-have-installed/" title="我安装的插件" rel="bookmark inlinks">我安装的插件</a><span class="count">( 25 )</span></li>
<li><a href="http://philna.com/2009/03/wp-pagenavi-issue/" title="wp-pagenavi的问题" rel="bookmark inlinks">wp-pagenavi的问题</a><span class="count">( 35 )</span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://philna.com/2009/12/prevent-the-direct-post-spam/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
		<item>
		<title>Google Ajax Custom Search</title>
		<link>http://philna.com/2009/11/google-ajax-custom-search/</link>
		<comments>http://philna.com/2009/11/google-ajax-custom-search/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 00:32:29 +0000</pubDate>
		<dc:creator>yinheli</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[Google]]></category>

		<guid isPermaLink="false">http://philna.com/2009/11/google-ajax-custom-search/</guid>
		<description><![CDATA[好久没有关注 Google 自定义搜索. 今天上去一看很多地方都改掉了. Google 更偏向于使用他的 Ajax API. 好吧, 我也来研究一下. 基本来说文档还是很详尽的. 做了个小尝试. 利用 Google Ajax API 写了个 Google 自定义搜索. 可以用来搜索本站内容. 注意: 原则上 Google 要求保留它的 logo. 所以大家在使用的时候还是最后加上. 这也是对 Google 的一种尊重吧. 我写的 DEMO 在这里. 以后有时间考虑给主题加上吧. 也需要等到下一个主题了. 现在越来越觉的主题主题集成的东西太多. 非常不利于修改和维护. 而且代码也写得不优雅. 重来实在是没有时间. Related Posts Ajax学习之一个post方法(例子)( 9 ) jQuery版ajax comment pager( 19 ) 图片里放哪里?( 17 ) Google Friend Connect( 20 [...]]]></description>
			<content:encoded><![CDATA[<p>好久没有关注 Google 自定义搜索. 今天上去一看很多地方都改掉了. Google 更偏向于使用他的 Ajax API. 好吧, 我也来研究一下. 基本来说文档还是很详尽的.</p>
<p>做了个小尝试. 利用 Google Ajax API 写了个 Google 自定义搜索. 可以用来搜索本站内容. </p>
<p>注意: 原则上 Google 要求保留它的 logo. 所以大家在使用的时候还是最后加上. 这也是对 Google 的一种尊重吧.</p>
<p>我写的<a href="http://philna.com/tutorials/2009/google_ajax_custom_search/"> DEMO</a> 在这里.</p>
<p><span id="more-217"></span></p>
<p>以后有时间考虑给主题加上吧. 也需要等到下一个主题了. 现在越来越觉的主题主题集成的东西太多. 非常不利于修改和维护. 而且代码也写得不优雅. 重来实在是没有时间.<br />
<h3>Related Posts</h3>
<ul class="related_posts">
<li><a href="http://philna.com/2009/04/learning-ajax-2/" title="学习Ajax之XMLHttpRequest对象" rel="bookmark inlinks">学习Ajax之XMLHttpRequest对象</a><span class="count">( 12 )</span></li>
<li><a href="http://philna.com/2008/12/google-friend-connect/" title="Google Friend Connect" rel="bookmark inlinks">Google Friend Connect</a><span class="count">( 20 )</span></li>
<li><a href="http://philna.com/2009/04/learning-ajax-3/" title="Ajax学习之一个post方法(例子)" rel="bookmark inlinks">Ajax学习之一个post方法(例子)</a><span class="count">( 9 )</span></li>
<li><a href="http://philna.com/2009/04/learning-ajax-1/" title="学习Ajax第一篇(了解)" rel="bookmark inlinks">学习Ajax第一篇(了解)</a><span class="count">( 11 )</span></li>
<li><a href="http://philna.com/2009/04/jqurey-ajax/" title="Ajax之jQuery" rel="bookmark inlinks">Ajax之jQuery</a><span class="count">( 33 )</span></li>
<li><a href="http://philna.com/2008/10/2001-googl/" title="看看2001年的Google" rel="bookmark inlinks">看看2001年的Google</a><span class="count">( 1 )</span></li>
<li><a href="http://philna.com/2008/11/staroffice-google/" title="StarOffice被Google退了" rel="bookmark inlinks">StarOffice被Google退了</a><span class="count">( 5 )</span></li>
<li><a href="http://philna.com/2009/09/simple-javascript-cache/" title="基于 javascript 的简单缓存思路" rel="bookmark inlinks">基于 javascript 的简单缓存思路</a><span class="count">( 3 )</span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://philna.com/2009/11/google-ajax-custom-search/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>无限级导航菜单</title>
		<link>http://philna.com/2009/11/unlimited-class-navigation-menu/</link>
		<comments>http://philna.com/2009/11/unlimited-class-navigation-menu/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 11:51:15 +0000</pubDate>
		<dc:creator>yinheli</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://philna.com/?p=216</guid>
		<description><![CDATA[上次看到有个 web 招聘笔试题里有个题大意是这样的: 是否尝试写过无限级的导航菜单? 我一时兴致就尝试写了一下. 要想兼容 IE(6/7/8) 系列还真的挺费事. 不得不动用 javascript 以及在 CSS 中使用 hacker. 对 Javascript 我只懂些皮毛. 要想做出些动画效果那几乎不可能. 只好用 jQuery 了. 我现在做了个DEMO. 要修改其动画效果只需要改改 js 中的鼠标效果即可. jQuery 自带的几个动画效果都可以. 当然你还可以发挥你的想象写些自定义动画. DEMO Related Posts 修改inove主题( 28 ) 基于 javascript 的简单缓存思路( 3 ) Ajax之jQuery( 33 ) 评论按钮被拉伸Bug( 10 ) jQuery版ajax comment pager( 19 ) 抽时间学点jQuery( 18 ) Ajax学习之一个post方法(例子)( 9 [...]]]></description>
			<content:encoded><![CDATA[<p>上次看到有个 web 招聘笔试题里有个题大意是这样的: 是否尝试写过无限级的导航菜单? 我一时兴致就尝试写了一下. </p>
<p>要想兼容 IE(6/7/8) 系列还真的挺费事. 不得不动用 javascript 以及在 CSS 中使用 hacker. 对 Javascript 我只懂些皮毛. 要想做出些动画效果那几乎不可能. 只好用 jQuery 了.</p>
<p>我现在做了个DEMO. 要修改其动画效果只需要改改 js 中的鼠标效果即可. jQuery 自带的几个动画效果都可以. 当然你还可以发挥你的想象写些自定义动画.</p>
<p><span id="more-216"></span></p>
<p><a href="http://philna.com/tutorials/2009/menu/menu.html" title="无限级导航菜单">DEMO</a><br />
<h3>Related Posts</h3>
<ul class="related_posts">
<li><a href="http://philna.com/2009/04/learning-ajax-3/" title="Ajax学习之一个post方法(例子)" rel="bookmark inlinks">Ajax学习之一个post方法(例子)</a><span class="count">( 9 )</span></li>
<li><a href="http://philna.com/2009/03/my-plugin-ajax-home-page/" title="我做的插件: Ajax home page" rel="bookmark inlinks">我做的插件: Ajax home page</a><span class="count">( 71 )</span></li>
<li><a href="http://philna.com/2009/02/js-check-outlinks/" title="js判断外链并新窗口打开" rel="bookmark inlinks">js判断外链并新窗口打开</a><span class="count">( 7 )</span></li>
<li><a href="http://philna.com/2008/12/js-smooth-move/" title="页面内锚点平滑移动" rel="bookmark inlinks">页面内锚点平滑移动</a><span class="count">( 30 )</span></li>
<li><a href="http://philna.com/2008/12/learn-jquery/" title="抽时间学点jQuery" rel="bookmark inlinks">抽时间学点jQuery</a><span class="count">( 18 )</span></li>
<li><a href="http://philna.com/2008/12/js-copyright/" title="用js适当添加版权信息" rel="bookmark inlinks">用js适当添加版权信息</a><span class="count">( 14 )</span></li>
<li><a href="http://philna.com/2009/04/learning-ajax-1/" title="学习Ajax第一篇(了解)" rel="bookmark inlinks">学习Ajax第一篇(了解)</a><span class="count">( 11 )</span></li>
<li><a href="http://philna.com/2009/04/jqurey-ajax/" title="Ajax之jQuery" rel="bookmark inlinks">Ajax之jQuery</a><span class="count">( 33 )</span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://philna.com/2009/11/unlimited-class-navigation-menu/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Comment Fetion Alert 2.0.0 dev 发布</title>
		<link>http://philna.com/2009/11/comment-fetion-alert-2-0-0-dev/</link>
		<comments>http://philna.com/2009/11/comment-fetion-alert-2-0-0-dev/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 05:50:25 +0000</pubDate>
		<dc:creator>yinheli</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[comment]]></category>
		<category><![CDATA[Fetion]]></category>

		<guid isPermaLink="false">http://philna.com/2009/11/comment-fetion-alert-2-0-0-dev/</guid>
		<description><![CDATA[整个重新写过. 丰富了后台选项. 最重要的是去掉了对 curl 扩展的依赖. 很多的细节我也不多说了. 现在发布 dev 版本给大家测试. 有问题尽快提交给我. 我好做进一步的修正. 下载 补充: 我哥们 Grubylee 给我写了比较详细的说明. 移步看看 Related Posts jQuery版ajax comment pager( 19 ) 评论短信提醒( 24 ) 修正热情评论员( 17 ) 插件发布:Comment Fetion Alert( 86 ) 阻止直接 POST 过来的 Spam( 37 ) 评论添加:热情评论员( 22 )]]></description>
			<content:encoded><![CDATA[<p>整个重新写过. 丰富了后台选项. 最重要的是去掉了对 curl 扩展的依赖. 很多的细节我也不多说了. 现在发布 dev 版本给大家测试. 有问题尽快提交给我. 我好做进一步的修正.</p>
<p><a href="http://code.google.com/p/philna/downloads/list">下载</a></p>
<p>补充:<br />
我哥们 Grubylee 给我写了比较详细的说明. <a href="http://www.liqinghai.com/wordpress-comment-fetion-alert-2-0-0-dev/">移步看看</a><br />
<h3>Related Posts</h3>
<ul class="related_posts">
<li><a href="http://philna.com/2009/12/prevent-the-direct-post-spam/" title="阻止直接 POST 过来的 Spam" rel="bookmark inlinks">阻止直接 POST 过来的 Spam</a><span class="count">( 37 )</span></li>
<li><a href="http://philna.com/2009/03/comment-sms-alert/" title="评论短信提醒" rel="bookmark inlinks">评论短信提醒</a><span class="count">( 24 )</span></li>
<li><a href="http://philna.com/2009/04/fix-enthusiastic-commentator/" title="修正热情评论员" rel="bookmark inlinks">修正热情评论员</a><span class="count">( 17 )</span></li>
<li><a href="http://philna.com/2009/04/comment-fetion-alert/" title="插件发布:Comment Fetion Alert" rel="bookmark inlinks">插件发布:Comment Fetion Alert</a><span class="count">( 86 )</span></li>
<li><a href="http://philna.com/2009/03/jquery-ajax-comment-pager/" title="jQuery版ajax comment pager" rel="bookmark inlinks">jQuery版ajax comment pager</a><span class="count">( 19 )</span></li>
<li><a href="http://philna.com/2009/02/enthusiastic-commentator/" title="评论添加:热情评论员" rel="bookmark inlinks">评论添加:热情评论员</a><span class="count">( 22 )</span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://philna.com/2009/11/comment-fetion-alert-2-0-0-dev/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>缓存头像的插件 cache avatar</title>
		<link>http://philna.com/2009/10/cache-avatar/</link>
		<comments>http://philna.com/2009/10/cache-avatar/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 13:19:34 +0000</pubDate>
		<dc:creator>yinheli</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://philna.com/2009/10/cache-avatar/</guid>
		<description><![CDATA[抽空写了个缓存头像的插件 &#8211; cache avatar 可以把讨论头像缓存到本地服务器. 随着博客越来越多 gravatar 的站点压力越来越大. 偶尔有头像下载缓慢的情况. 尤其在评论很多的情况下评论者头像往往是最后才载入完成. 因此对站点速度有点苛刻的朋友需要缓存一下评论头像. 插件后台可设置缓存时间. 需要的朋友可下载. Related Posts 修正热情评论员( 17 ) WordPress IE查看源文件乱码解决( 14 ) 我做的插件: Ajax home page( 71 ) 不用插件放广告( 12 ) 建立自己的专属页面( 38 ) 主题发布:PhilNa( 160 ) 本站装的插件( 7 ) 图片里放哪里?( 17 )]]></description>
			<content:encoded><![CDATA[<p>抽空写了个缓存头像的插件 &#8211; cache avatar</p>
<p>可以把讨论头像缓存到本地服务器. 随着博客越来越多 gravatar 的站点压力越来越大. 偶尔有头像下载缓慢的情况. 尤其在评论很多的情况下评论者头像往往是最后才载入完成. 因此对站点速度有点苛刻的朋友需要缓存一下评论头像.</p>
<p>插件后台可设置缓存时间.</p>
<p><span id="more-214"></span></p>
<p>需要的朋友可<a href="http://code.google.com/p/philna/downloads/list" title="Goto google code and get cache avatar">下载</a>.<br />
<h3>Related Posts</h3>
<ul class="related_posts">
<li><a href="http://philna.com/2009/09/simple-javascript-cache/" title="基于 javascript 的简单缓存思路" rel="bookmark inlinks">基于 javascript 的简单缓存思路</a><span class="count">( 3 )</span></li>
<li><a href="http://philna.com/2009/02/set-up-e-mail-form-without-plugin/" title="不用插件实现wordpress邮件表单" rel="bookmark inlinks">不用插件实现wordpress邮件表单</a><span class="count">( 14 )</span></li>
<li><a href="http://philna.com/2009/03/wordpress-theme-philna/" title="主题:PhilNa" rel="bookmark inlinks">主题:PhilNa</a><span class="count">( 33 )</span></li>
<li><a href="http://philna.com/2009/04/fix-enthusiastic-commentator/" title="修正热情评论员" rel="bookmark inlinks">修正热情评论员</a><span class="count">( 17 )</span></li>
<li><a href="http://philna.com/2009/04/wordpress-custom-field/" title="WordPress custom field之header应用" rel="bookmark inlinks">WordPress custom field之header应用</a><span class="count">( 25 )</span></li>
<li><a href="http://philna.com/2009/02/php-verification-code/" title="Php图片验证" rel="bookmark inlinks">Php图片验证</a><span class="count">( 16 )</span></li>
<li><a href="http://philna.com/2008/11/wordpress-ie-garbled/" title="WordPress IE查看源文件乱码解决" rel="bookmark inlinks">WordPress IE查看源文件乱码解决</a><span class="count">( 14 )</span></li>
<li><a href="http://philna.com/2008/11/wordpress-update-to-265/" title="WordPress更新至2.6.5" rel="bookmark inlinks">WordPress更新至2.6.5</a><span class="count">( 11 )</span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://philna.com/2009/10/cache-avatar/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>给首页的友情链接添加 nofollow</title>
		<link>http://philna.com/2009/10/nofollow-links/</link>
		<comments>http://philna.com/2009/10/nofollow-links/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 07:09:37 +0000</pubDate>
		<dc:creator>yinheli</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://philna.com/?p=212</guid>
		<description><![CDATA[介绍个简便的办法给用 wordpress 的朋友, 用来给首页的友情链接添加 nofollow. 只有几行代码,很简单. 如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 /** * 给首页友情链接添加 nofollow * * 你可以举一反三, 用它来对友情链接做些修改 * * @author yinheli * @link http://philna.com * @param array $links 链接 * @return array 修改过的链接 */ function [...]]]></description>
			<content:encoded><![CDATA[<p>介绍个简便的办法给用 wordpress 的朋友, 用来给首页的友情链接添加 nofollow. 只有几行代码,很简单. 如下:</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933;">/**
 * 给首页友情链接添加 nofollow
 *
 * 你可以举一反三, 用它来对友情链接做些修改
 *
 * @author yinheli
 * @link http://philna.com
 * @param array $links 链接
 * @return array 修改过的链接
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> myBookmarksInHomepage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$links</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666;">/*判断是否为首页 你也可以用其他的判断用于其他的页面*/</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_home<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666;">/*历遍*/</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$links</span> <span style="color: #b1b100;">as</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666;">/*你可以添加其他的判断对来针对你需要修改的链接*/</span>
			<span style="color: #000088;">$value</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link_rel</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'external nofollow'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$links</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_bookmarks'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'myBookmarksInHomepage'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span id="more-212"></span></p>
<p>把上面的代码放到主题的 functions.php 中即可.</p>
<p>你还可以多加些判断比如针对某个分类. 甚至只针对某个链接. 这应该是最灵活的处理办法了.</p>
<p>最后说明一下: 本站不交换链接, 所有以交换链接为名提交的评论将被删除. 你要是经常来我这里留言, 混熟了我自然会给你加上链接.<br />
<h3>Related Posts</h3>
<ul class="related_posts">
<li><a href="http://philna.com/2008/10/the-nterface-wordpress27-improved/" title="wordpress 2.7 试用 界面大有改进" rel="bookmark inlinks">wordpress 2.7 试用 界面大有改进</a><span class="count">( 0 )</span></li>
<li><a href="http://philna.com/2009/02/enthusiastic-commentator/" title="评论添加:热情评论员" rel="bookmark inlinks">评论添加:热情评论员</a><span class="count">( 22 )</span></li>
<li><a href="http://philna.com/2009/03/wordpress-theme-philna/" title="主题:PhilNa" rel="bookmark inlinks">主题:PhilNa</a><span class="count">( 33 )</span></li>
<li><a href="http://philna.com/2010/06/get-titles-of-verycd/" title="获取 VeryCD 站点标题" rel="bookmark inlinks">获取 VeryCD 站点标题</a><span class="count">( 35 )</span></li>
<li><a href="http://philna.com/2009/03/philna/" title="主题发布:PhilNa" rel="bookmark inlinks">主题发布:PhilNa</a><span class="count">( 160 )</span></li>
<li><a href="http://philna.com/2009/02/set-up-e-mail-form-without-plugin/" title="不用插件实现wordpress邮件表单" rel="bookmark inlinks">不用插件实现wordpress邮件表单</a><span class="count">( 14 )</span></li>
<li><a href="http://philna.com/2008/11/php-substr/" title="Php substr截取中文乱码" rel="bookmark inlinks">Php substr截取中文乱码</a><span class="count">( 6 )</span></li>
<li><a href="http://philna.com/2009/03/my-exclusive-page/" title="建立自己的专属页面" rel="bookmark inlinks">建立自己的专属页面</a><span class="count">( 38 )</span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://philna.com/2009/10/nofollow-links/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>基于 javascript 的简单缓存思路</title>
		<link>http://philna.com/2009/09/simple-javascript-cache/</link>
		<comments>http://philna.com/2009/09/simple-javascript-cache/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 07:50:37 +0000</pubDate>
		<dc:creator>yinheli</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://philna.com/2009/09/simple-javascript-cache/</guid>
		<description><![CDATA[我在博客上用了很多的 javascript 代码, 来实现些简单的动画效果和 Ajax . 本意是为了好看, 增强用户体验但是也不得不有所牺牲: 1. 可能会增加数据库请求. 2. 无法使用浏览器前进后退按钮. 今天写个思路来缓解一下第一个问题 ( 数据库请求 ) 注意只是缓解. 因为不是真正的缓存. 我们知道所以的 Ajax 请求其实和不同的请求是没有什么两样的. 但它也有自己的特点: 通过特定的 URL 请服务器请求数据. 可能包含特定的头部信息 ( RequestHeader ) . 服务器端有专门的代码来识别这些特殊请求, 并作相应处理. Ajax 只是可能增加数据库请求, 并不是绝对会增加数据库请求. 这个要具体情况具体分析. 像我目前使用的这种分页方法就没有增加反而是减少请求. 我的思路是将请求返回的数据在展示的同时也放到一个数组变量里, 在下次请求的时候直接从这个缓存变量中取值. 因此, 这时 Ajax 的请求顺序变为: 先判断缓存如果有需要的数据则返回缓存数据, 没有则执行 Ajax 请求, 并在请求成功后缓存返回数据. 以 Ajax 分页 举例: 1 2 3 [...]]]></description>
			<content:encoded><![CDATA[<p>我在博客上用了很多的 javascript 代码, 来实现些简单的动画效果和 Ajax . 本意是为了好看, 增强用户体验但是也不得不有所牺牲: 1. 可能会增加数据库请求. 2. 无法使用浏览器前进后退按钮.</p>
<p>今天写个思路来缓解一下第一个问题 ( 数据库请求 ) 注意只是缓解. 因为不是真正的缓存.</p>
<p>我们知道所以的 Ajax 请求其实和不同的请求是没有什么两样的. 但它也有自己的特点:</p>
<ol>
<li>通过特定的 URL 请服务器请求数据. </li>
<li>可能包含特定的头部信息 ( RequestHeader ) .</li>
<li>服务器端有专门的代码来识别这些特殊请求, 并作相应处理. </li>
</ol>
<p>Ajax 只是可能增加数据库请求, 并不是绝对会增加数据库请求. 这个要具体情况具体分析. 像我目前使用的这种分页方法就没有增加反而是减少请求.</p>
<p>我的思路是将请求返回的数据在展示的同时也放到一个数组变量里, 在下次请求的时候直接从这个缓存变量中取值. 因此, 这时 Ajax 的请求顺序变为: 先判断缓存如果有需要的数据则返回缓存数据, 没有则执行 Ajax 请求, 并在请求成功后缓存返回数据.</p>
<p>以 Ajax 分页 举例:</p>
<p><span id="more-206"></span></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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600;">/* 建立一个用于缓存的数组 */</span>
<span style="color: #003366; font-weight: bold;">var</span> ajaxpageCache <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">function</span> ajaxpage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009966;">/* 取得链接 */</span>
	<span style="color: #003366; font-weight: bold;">var</span> nav_a <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#navigation a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009966;">/* 注册链接单击事件 */</span>
	nav_a.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #009966;">/* 获取链接值 */</span>
		<span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009966;">/* 判断缓存, 缓存中有值则使用缓存数据 */</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ajaxpageCache<span style="color: #009900;">&#91;</span>url<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#content'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>ajaxpageCache<span style="color: #009900;">&#91;</span>url<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009966;">/* 平滑移动到头部的动画 */</span>
			$.<span style="color: #660066;">scrollTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#header'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">800</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009966;">/* 重新注册该事件 */</span>
			ajaxpage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009966;">/* 阻止打开链接 */</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #009966;">/* ... 省略的代码 ... */</span>
&nbsp;
		<span style="color: #009966;">/* 请求前 */</span>
		<span style="color: #003366; font-weight: bold;">var</span> beforeSend <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #009966;">/* ... 省略的代码 ... */</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009966;">/* 请求失败时 */</span>
		<span style="color: #003366; font-weight: bold;">var</span> error <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>request<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #009966;">/* ... 省略的代码 ... */</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009966;">/* 请求成功 */</span>
		<span style="color: #003366; font-weight: bold;">var</span> success <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #009966;">/* 展示(显示返回数据) */</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#content'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009966;">/* 写入缓存 */</span>
			ajaxpageCache<span style="color: #009900;">&#91;</span>url<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> data<span style="color: #339933;">;</span>
			<span style="color: #009966;">/* ... 省略的代码 ... */</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009966;">/* 启动 Ajax 请求 */</span>
		ajax<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'POST'</span><span style="color: #339933;">,</span> url<span style="color: #339933;">,</span> data<span style="color: #339933;">,</span> beforeSend<span style="color: #339933;">,</span> error<span style="color: #339933;">,</span> success<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009966;">/* 阻止打开链接 */</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>这种缓存思路只是对重复使用相同数据的请求适用. 比如这种大页面翻页等.因为只要页面重新加载所有缓存内容将消失.</p>
<p>当然, 没有好处我也不会使用. 它的优点是在请求重复性数据时不产生数据库请求, 直接从客户端返回数据也让内容显示几乎没有延时. 在本地测试 Ajax 的时候可能并没有什么感觉, 一旦上传到网站, 在网速较慢的情况下就很明显的感觉慢. </p>
<p>考虑更高级一点的应用</p>
<ol>
<li>使用预加载, 即预先在&#8217;后台偷偷&#8217;将下一页的内容加载到缓存. (目前我还不想使用. 因为不是每个人都一定要看下一页的)</li>
<li>定时清空指定的缓存数据.</li>
</ol>
<h3>Related Posts</h3>
<ul class="related_posts">
<li><a href="http://philna.com/2009/04/learning-ajax-2/" title="学习Ajax之XMLHttpRequest对象" rel="bookmark inlinks">学习Ajax之XMLHttpRequest对象</a><span class="count">( 12 )</span></li>
<li><a href="http://philna.com/2009/02/set-up-e-mail-form-without-plugin/" title="不用插件实现wordpress邮件表单" rel="bookmark inlinks">不用插件实现wordpress邮件表单</a><span class="count">( 14 )</span></li>
<li><a href="http://philna.com/2008/12/mouseover-to-show-comment-no1/" title="鼠标悬浮实现显示留言内容(上)" rel="bookmark inlinks">鼠标悬浮实现显示留言内容(上)</a><span class="count">( 22 )</span></li>
<li><a href="http://philna.com/2009/02/enthusiastic-commentator/" title="评论添加:热情评论员" rel="bookmark inlinks">评论添加:热情评论员</a><span class="count">( 22 )</span></li>
<li><a href="http://philna.com/2010/01/use-array-overloading-in-the-wordpress-theme-or-plug-in-settings/" title="数组重载在 WordPress 主题或插件设置中的应用" rel="bookmark inlinks">数组重载在 WordPress 主题或插件设置中的应用</a><span class="count">( 45 )</span></li>
<li><a href="http://philna.com/2008/10/the-nterface-wordpress27-improved/" title="wordpress 2.7 试用 界面大有改进" rel="bookmark inlinks">wordpress 2.7 试用 界面大有改进</a><span class="count">( 0 )</span></li>
<li><a href="http://philna.com/2008/10/wordpress-security-fix/" title="wordpress security fix [安全更新]" rel="bookmark inlinks">wordpress security fix [安全更新]</a><span class="count">( 1 )</span></li>
<li><a href="http://philna.com/2009/02/get-feed-add-some-personality/" title="给feed输出内容添加些'个性'" rel="bookmark inlinks">给feed输出内容添加些&#8217;个性&#8217;</a><span class="count">( 11 )</span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://philna.com/2009/09/simple-javascript-cache/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>高亮搜索结果</title>
		<link>http://philna.com/2009/09/highlight-keywords/</link>
		<comments>http://philna.com/2009/09/highlight-keywords/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 08:28:48 +0000</pubDate>
		<dc:creator>yinheli</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[前一段时间给博客添加了搜索评论的功能, 被人骂成是鸡肋. 忧伤. 劳动成果居然没有得到肯定. 我也很就没有分享技巧性的东西了, 好吧, 这篇文章告诉大家怎么高亮搜索结果. 为什么要高亮 也可以说是目的, 让用户搜索的结果更加一目了然. 原理 这个功能的实现方法是用正则表达式替换关键字. 代码 将以下代码放到你主题的 functions.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 [...]]]></description>
			<content:encoded><![CDATA[<p>前一段时间给博客添加了搜索评论的功能, 被人骂成是鸡肋. 忧伤. 劳动成果居然没有得到肯定.</p>
<p>我也很就没有分享技巧性的东西了, 好吧, 这篇文章告诉大家怎么高亮搜索结果.</p>
<h3>为什么要高亮</h3>
<p>也可以说是目的, 让用户搜索的结果更加一目了然.</p>
<h3>原理</h3>
<p>这个功能的实现方法是用正则表达式替换关键字.</p>
<h3>代码</h3>
<p>将以下代码放到你主题的 functions.php 文件中即可 ( 大量中文注释,不懂的请注意看 ).</p>
<p><span id="more-205"></span></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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933;">/**
 * 搜索结果高亮关键字
 *
 * 特征: 简单的分词高亮效果
 *
 * 本函数摘自 wordpress 主题 PhilNa2 version 2.0.4
 *
 * @author yinheli
 * @link http://philna.com
 * @copyright Copyright (C) 2008 - 2009 yinheli Open Source Matters. All rights reserved.
 * @since 2.0
 * @version 1.5
 * @package PhilNa2
 * @lastmodified  $Date:2009-09-06 $
 * @see add_filter()
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> highlightSearchWords<span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666;">/* 对于非搜索页面直接返回 */</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>is_search<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$c</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">global</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">;</span>
	<span style="color: #666666;">/* 测试的办法,你可以看到具体的全部请求内容 */</span>
	<span style="color: #666666;">//return print_r($wp_query,true);</span>
	<span style="color: #666666;">/* 颜色集合 */</span>
	<span style="color: #000088;">$hightLightColors</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#FF0'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'#A0FF40'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'#FFD700'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'DAA520'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$keywords</span> <span style="color: #339933;">=</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;">/* 取得关键字 */</span>
	<span style="color: #000088;">$keywords</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query_vars</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'search_terms'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #666666;">/* 非法字符 主要是特殊字符 */</span>
	<span style="color: #000088;">$notAllowed</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;$&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;(&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;*&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;+&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;?&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;[&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;]&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>,&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;^&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;{&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;}&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;|&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666;">/* 没有关键字直接返回 */</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keywords</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$c</span><span style="color: #339933;">;</span>
	<span style="color: #666666;">/*
	对于想单(双)引号(',&quot;)
	这样的字符wp本身在查询的时候会去掉的.
	但是留下个空的值.并且会查询数据库
	暂时不知道为什么wp要这么处理
	猜想是:文章中难免有html标签,有标签意味着有引号.
	搜索引号就没有多大意义.
	原本以为加引号代表精确搜索,结果出现了乱码
	经测试发现是以上原因
&nbsp;
	∴ 这里做个判断.免得在替换的换的时候出错
	*/</span>
	<span style="color: #666666;">/* 去掉空值 */</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$keywords</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$index</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keywords</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$index</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666;">/* 依然为空 直接返回 */</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keywords</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$c</span><span style="color: #339933;">;</span>
	<span style="color: #666666;">/* 如果是搜索评论,去掉第一个关键字. 这里是针对我添加的评论搜索 */</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">searchComments</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keywords</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666;">/* 选择颜色数组索引 */</span>
	<span style="color: #000088;">$slecet</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666;">/*
	开始历遍,每个(种)关键字
	将从颜色集合数据组中选用使用不同的颜色
	注意:
	同一个关键字在文章不同的地方,颜色是相同的
	*/</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$keywords</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$keyword</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666;">/* 关键字数量大于颜色数组数量时,索引重置 */</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$slecet</span> <span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hightLightColors</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$slecet</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #666666;">/* 选择一种颜色 */</span>
		<span style="color: #000088;">$hightLightColor</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$hightLightColors</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$slecet</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #666666;">/* 累加索引 */</span>
		<span style="color: #000088;">$slecet</span><span style="color: #339933;">++;</span>
		<span style="color: #666666;">/* 滤过非法字符 必须将这些字符转义 */</span>
		<span style="color: #000088;">$RegExpkeyword</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$keyword</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$notAllowed</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$RegExpkeyword</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'\\'</span><span style="color: #339933;">.</span><span style="color: #000088;">$v</span><span style="color: #339933;">,</span><span style="color: #000088;">$RegExpkeyword</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666;">/* 正则表达式(这是替换[高亮]的关键) 不区分大写小写 */</span>
		<span style="color: #000088;">$RegExp</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/<span style="color: #006699; font-weight: bold;">$RegExpkeyword</span>(?=[^&lt;&gt;]*&lt;)/i&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #666666;">/* 开始替换 */</span>
		<span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$RegExp</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'&lt;span style=&quot;background:'</span><span style="color: #339933;">.</span><span style="color: #000088;">$hightLightColor</span><span style="color: #339933;">.</span><span style="color: #0000ff;">';&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$keyword</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/span&gt;'</span><span style="color: #339933;">,</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$c</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666;">/*将函数挂到 the_content 这个滤过器上, 并将优先级设置高一点*/</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'highlightSearchWords'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>废话</h3>
<p>可能这个还不是完美.</p>
<p>当然还可以用其他的办法实现, 比如 javascript .也是相同的原理, 你几乎可以完全套用我的正则表达式.</p>
<p>目前可以兼容 WP-Syntax 这个插件. 经我测试没有发现毛病. 至于他的有些关键字比如括号之类的.我也不得而知.</p>
<p>请大家帮忙<strong>推广</strong>一下我的主题吧. 我看到下载量实在有点少.</p>
<p>所谓技巧, 无非是些乱七八糟的代码. 也没有几句有用的话. 谢谢你这么认真地看到这里.瓦咔咔. <img src='http://philna.com/wp-includes/images/smilies/icon_razz.gif' alt=':razz:' class='wp-smiley' />  </p>
<h3>Related Posts</h3>
<ul class="related_posts">
<li><a href="http://philna.com/2009/03/wp-pagenavi-issue/" title="wp-pagenavi的问题" rel="bookmark inlinks">wp-pagenavi的问题</a><span class="count">( 35 )</span></li>
<li><a href="http://philna.com/2009/04/contribution-plugin/" title="简单的WordPress投稿插件" rel="bookmark inlinks">简单的WordPress投稿插件</a><span class="count">( 37 )</span></li>
<li><a href="http://philna.com/2008/12/add-ads-without-plugins/" title="不用插件放广告" rel="bookmark inlinks">不用插件放广告</a><span class="count">( 12 )</span></li>
<li><a href="http://philna.com/2008/11/wordpress-update-to-265/" title="WordPress更新至2.6.5" rel="bookmark inlinks">WordPress更新至2.6.5</a><span class="count">( 11 )</span></li>
<li><a href="http://philna.com/2009/04/jqurey-ajax/" title="Ajax之jQuery" rel="bookmark inlinks">Ajax之jQuery</a><span class="count">( 33 )</span></li>
<li><a href="http://philna.com/2009/02/get-feed-add-some-personality/" title="给feed输出内容添加些'个性'" rel="bookmark inlinks">给feed输出内容添加些&#8217;个性&#8217;</a><span class="count">( 11 )</span></li>
<li><a href="http://philna.com/2009/03/my-exclusive-page/" title="建立自己的专属页面" rel="bookmark inlinks">建立自己的专属页面</a><span class="count">( 38 )</span></li>
<li><a href="http://philna.com/2009/03/wordpress-theme-philna/" title="主题:PhilNa" rel="bookmark inlinks">主题:PhilNa</a><span class="count">( 33 )</span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://philna.com/2009/09/highlight-keywords/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>
