<?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>phoenixheart - portfolio &#38; more &#187; jQuery</title> <atom:link href="http://www.phoenixheart.net/tag/jquery/feed/" rel="self" type="application/rss+xml" /><link>http://www.phoenixheart.net</link> <description>phoenixheart - portfolio &#38; more</description> <lastBuildDate>Wed, 25 Aug 2010 03:02:03 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <script type="text/javascript">/*<![CDATA[*/if(typeof Meebo=="undefined"){Meebo=function(){(Meebo._=Meebo._||[]).push(arguments)};(function(q){var args=arguments;if(!document.body){return setTimeout(function(){args.callee.apply(this,args)},100);}var d=document,b=d.body,m=b.insertBefore(d.createElement('div'),b.firstChild);s=d.createElement('script');m.id='meebo';m.style.display='none';m.innerHTML='<iframe id="meebo-iframe"></iframe>';s.src='http'+(q.https?'s':'')+'://'+(q.stage?'stage-':'')+'cim.meebo.com/cim/cim.php?network='+q.network;b.insertBefore(s,b.firstChild);})({network:'phoenixheartnet_bo16we'});}/*]]>*/</script> <item><title>Deal with browser incompliance using jQuery</title><link>http://www.phoenixheart.net/2009/04/deal-with-browser-incompliance-using-jquery/</link> <comments>http://www.phoenixheart.net/2009/04/deal-with-browser-incompliance-using-jquery/#comments</comments> <pubDate>Mon, 27 Apr 2009 07:34:51 +0000</pubDate> <dc:creator>phoenix.heart</dc:creator> <category><![CDATA[Client stuffs]]></category> <category><![CDATA[Featured]]></category> <category><![CDATA[css]]></category> <category><![CDATA[jQuery]]></category><guid
isPermaLink="false">http://www.phoenixheart.net/?p=256</guid> <description><![CDATA[Without a doubt, being a serious web guy you want your new site to look perfect on web browsers. Yes, mission would be simple &#8211; or sound simple &#8211; if there wasn&#8217;t something called browser wars for such a long time without any glorious winner (yet). The stupid result is, we poor web designers and [...]]]></description> <content:encoded><![CDATA[<p><span
class="drop-cap">W</span>ithout a doubt, being a serious web guy you want your new site to look perfect on web browsers. Yes, mission would be simple &#8211; or sound simple &#8211; if there wasn&#8217;t something called <a
href="http://en.wikipedia.org/wiki/Browser_wars">browser wars</a> for such a long time without any glorious winner (yet). The stupid result is, we poor web designers and programmers are still hopelessly struggling to keep our sites look the same on <a
href="http://en.wikipedia.org/wiki/Internet_Explorer">Internet Explorer</a> (DIE PIG, DIE!!!), <a
href="http://en.wikipedia.org/wiki/Mozilla_Firefox">Firefox</a>, <a
href="http://en.wikipedia.org/wiki/Opera_(web_browser)">Opera</a>, <a
href="http://en.wikipedia.org/wiki/Safari_(web_browser)">Safari</a>, just to find out that the oh so cool banner suddenly disappears from that new boy <a
href="http://en.wikipedia.org/wiki/Google_Chrome">Chrome</a>. FYI (psst) that was when I decided to stick with web that I started to learn cursing and swearing.</p><p>I am so proud to say that I decided to stop supporting IE 6 to save myself some precious life years and keep my head from getting bald long ago. But still, those guys in Microsoft they have IE 7 and 8 to haunt us. And despite of the so-called W3C standards, each of the remaining major browsers renders the pages differently here and there &#8211; margins, paddings, form elements, and so on. To deal with them, we use &#8220;hacks&#8221;. Perhaps the most well known hack is one below, called &#8220;conditional comments&#8221;:</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
</pre></td><td
class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--[if IE]&gt;</span>
<span style="color: #808080; font-style: italic;">Stuffs for Internet Explorer all versions</span>
<span style="color: #808080; font-style: italic;">&lt;![endif]--&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--[if IE 5]&gt;</span>
<span style="color: #808080; font-style: italic;">Stuffs for Internet Explorer 5</span>
<span style="color: #808080; font-style: italic;">&lt;![endif]--&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--[if IE 5.0]&gt;</span>
<span style="color: #808080; font-style: italic;">Stuffs for Internet Explorer 5.0</span>
<span style="color: #808080; font-style: italic;">&lt;![endif]--&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--[if IE 5.5]&gt;</span>
<span style="color: #808080; font-style: italic;">Stuffs for Internet Explorer 5.5</span>
<span style="color: #808080; font-style: italic;">&lt;![endif]--&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--[if IE 6]&gt;</span>
<span style="color: #808080; font-style: italic;">Stuffs for Internet Explorer 6</span>
<span style="color: #808080; font-style: italic;">&lt;![endif]--&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--[if IE 7]&gt;</span>
<span style="color: #808080; font-style: italic;">Stuffs for Internet Explorer 7</span>
<span style="color: #808080; font-style: italic;">&lt;![endif]--&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--[if IE 8]&gt;</span>
<span style="color: #808080; font-style: italic;">Stuffs for Internet Explorer 8</span>
<span style="color: #808080; font-style: italic;">&lt;![endif]--&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--[if gte IE 5]&gt;</span>
<span style="color: #808080; font-style: italic;">Stuffs for Internet Explorer 5 and up</span>
<span style="color: #808080; font-style: italic;">&lt;![endif]--&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--[if lt IE 6]&gt;</span>
<span style="color: #808080; font-style: italic;">Stuffs for Internet Explorer lower than 6</span>
<span style="color: #808080; font-style: italic;">&lt;![endif]--&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--[if lte IE 5.5]&gt;</span>
<span style="color: #808080; font-style: italic;">Stuffs for Internet Explorer lower or equal to 5.5</span>
<span style="color: #808080; font-style: italic;">&lt;![endif]--&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--[if gt IE 6]&gt;</span>
<span style="color: #808080; font-style: italic;">Stuffs for Internet Explorer greater than 6</span>
<span style="color: #808080; font-style: italic;">&lt;![endif]--&gt;</span></pre></td></tr></table></div><p>When this technique is great, it has two limitations. First, only IE is taken into account. When most of the time dealing with IE takes the majority, there are still cases when your sites looks different on Firefox, Safari, Opera etc. Second, the HTML code looks very ugly and unprofessional &#8211; just like we are humbly telling: sorry this is beyond my control&#8230; I must use a hack here&#8230; and here&#8230; sorry again&#8230; <span
id="more-256"></span></p><p>Then today when looking for a better solution, I stumbled upon a <a
href="http://www.tvidesign.co.uk/blog/CSS-Browser-detection-using-jQuery-instead-of-hacks.aspx">much better method</a> that overcomes all of our current problems &#8211; well, sort of. The idea behind it is using jQuery to detect the browser and its version, then add the corresponding class names into the &lt;body&gt; tag. For instance, if the visitor uses Internet Explorer 7, then &#8220;.browserIE&#8221; and &#8220;.browserIE7&#8243; are added. Then, in our CSS we specify the styles for this browser:</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
</pre></td><td
class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#aPainInThe4ssElement</span>
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/* generic styles for this pain */</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.browserIE7</span> <span style="color: #cc00cc;">#aPainInThe4ssElement</span>
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/* styles for this element on IE 7 */</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.browserFirefox</span> <span style="color: #cc00cc;">#aPainInThe4ssElement</span>
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/* styles for this element on all Firefox browsers */</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.browserSafari2</span> <span style="color: #cc00cc;">#aPainInThe4ssElement</span>
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/* styles for this element on Safari 2 */</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div><p>My hat off to <a
href="http://www.tvidesign.co.uk/meetTeam.aspx#JonHobbs-Smith">Jon</a> for this brilliant idea. Now dealing with different browsers is just a piece of cake!</p><p>Now the only thing I regret of is what took me so long to find out this solution.</p> <img
style='display:none' id="post-256-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2009/04/deal-with-browser-incompliance-using-jquery/',title:'Deal with browser incompliance using jQuery',tweet:'Without a doubt, being a serious web guy you want your new site to look perfect on web browsers. Yes',description:'Without a doubt, being a serious web guy you want your new site to look perfect on web browsers. Yes'})"><script type='text/javascript'>document.getElementById("post-256-blankimage").onload();</script>]]></content:encoded> <wfw:commentRss>http://www.phoenixheart.net/2009/04/deal-with-browser-incompliance-using-jquery/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>phpQuery</title><link>http://www.phoenixheart.net/2009/03/phpquery/</link> <comments>http://www.phoenixheart.net/2009/03/phpquery/#comments</comments> <pubDate>Mon, 09 Mar 2009 18:09:36 +0000</pubDate> <dc:creator>phoenix.heart</dc:creator> <category><![CDATA[Featured]]></category> <category><![CDATA[Server stuffs]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[phpquery]]></category><guid
isPermaLink="false">http://www.phoenixheart.net/?p=252</guid> <description><![CDATA[It&#8217;s been quite a while I don&#8217;t have any update on this blog (sorry my *ten* RSS subscribers&#8230;). If there is any excuse, then it should be the fact that I&#8217;ve just left Gameloft to join a start up, and you know it, the work load is just a bit heavier than what I expected. [...]]]></description> <content:encoded><![CDATA[<p>It&#8217;s been quite a while I don&#8217;t have any update on this blog (sorry my *ten* RSS subscribers&#8230;). If there is any excuse, then it should be the fact that I&#8217;ve just left Gameloft to join a start up, and you know it, the work load is just a bit heavier than what I expected. To make my life somewhat more difficult, one day I realized that the current theme of this blog was just too messy and not so flexible, so I decided to redesign it somehow. Well, the new theme is under development now, and all I can promise is it will be much easier for the eye.</p><p>Ok cut the chit-chat, today I have this new thing to share.</p><p>Here is one line of the oh-so-familiar code:</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div.old&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replaceWith</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div.new&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">clone</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.trash&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prepend</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Deleted&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>If you got no idea what the line means, then let us be honest to each  other: How long have you been under the rock? Man, it&#8217;s <a
href="http://www.jquery.com">jQuery</a>! And the code I&#8217;ve just shown is a really simple stupid example about <a
href="http://docs.jquery.com/Manipulation">manipulation</a>!</p><p>Now, once you know what it is and what it does, take a look at this:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">pq<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'div.old'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">replaceWith</span><span style="color: #009900;">&#40;</span>pq<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'div.new'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clone</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.trash'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepend</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Deleted'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>You must have got it right: it&#8217;s PHP &#8211; <abbr
title="Object Oriented Programming">OOP</abbr> PHP 5 to be precise. But what was that with those jQuery stuffs in the middle, you ask?</p><p>Well, it&#8217;s <a
href="http://code.google.com/p/phpquery">phpQuery</a>. And it&#8217;s what I&#8217;m about to introduce here and now. <span
id="more-252"></span></p><p>As the name calls, phpQuery is a jQuery port to PHP. Being based on the most famous Javascript library, phpQuery provides server-side, chainable, CSS3 selector driven <abbr
title="Document Object Model">DOM</abbr> <abbr
title="Application Programming Interface">API</abbr>. Many things in jQuery are available/doable in phpQuery &#8211; including but not limited to selectors, attributes, traversing, manipulation, utilities, even AJAX and events. And the syntax is just about, if not most of the time exactly the same as that in jQuery &#8211; of course if that dollar character doesn&#8217;t have a special role in PHP. Example, here is a sample selector code:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">pq<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.class ul &gt; li[rel='foo']:first:has(a)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Here is some traversing back and forth:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">pq<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'div &gt; p'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'div &gt; ul'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':has(a)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p:first'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nextAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">andSelf</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>With some attributes here and there:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">pq<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'href'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'newVal'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'className'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">html</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'newHtml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Impressive, no? So what is it for? What are the benefits of using phpQuery?</p><p>A bunch!</p><ul><li>From the simplest, imagine you are &#8220;stealing&#8221; some content from a website. Imagine you will need to parse the content out from that garbage of (X)HTML, Javascript and CSS tags. Imagine you suck at Regular Expression. How will you reach the goal then? No worries with phpQuery. Just load the (X)HTML content into phpQuery using phpQuery::newDocument(X)HTML(), do some basic selector parsing like pq(&#8220;div#holder :text:first:not(&#8216;.bad-boy&#8217;)&#8221;), and then val(), and then that&#8217;s it. Well, what do you say?</li><li>To some server side DOM creator helpers, when you need to fully control the DOM.</li><li>To a jQuery plugin named <a
href="http://code.google.com/p/phpquery/wiki/jQueryServer">jQueryServer</a> that beautifully allows you to &#8220;1. Connect to server and make an Ajax request to somewhere (crossdomain allowed), 2. Do some manipulations, you can even trigger a server-side event, and 3. Get processed data back to the browser&#8221;. Have you imagined it? Have you? Woa, I&#8217;m excited!</li><li>And last but not least, to something much more advanced, a TemplatE SysteM &#8211; they do call it <a
href="http://tobiasz123.wordpress.com/category/projects/querytemplates/">QueryTemplates</a>. This time it really gets big!</li></ul><p>No, don&#8217;t tell me you&#8217;re not impressed!</p> <img
style='display:none' id="post-252-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2009/03/phpquery/',title:'phpQuery',tweet:'It&#8217;s been quite a while I don&#8217;t have any update on this blog (sorry my *ten* RSS subscri',description:'It&#8217;s been quite a while I don&#8217;t have any update on this blog (sorry my *ten* RSS subscri'})"><script type='text/javascript'>document.getElementById("post-252-blankimage").onload();</script>]]></content:encoded> <wfw:commentRss>http://www.phoenixheart.net/2009/03/phpquery/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Google Search in an AJAX&#8217;ed way</title><link>http://www.phoenixheart.net/2008/12/google-search-in-an-ajaxed-way/</link> <comments>http://www.phoenixheart.net/2008/12/google-search-in-an-ajaxed-way/#comments</comments> <pubDate>Thu, 25 Dec 2008 08:07:40 +0000</pubDate> <dc:creator>phoenix.heart</dc:creator> <category><![CDATA[Client stuffs]]></category> <category><![CDATA[Featured]]></category> <category><![CDATA[Server stuffs]]></category> <category><![CDATA[ajax]]></category> <category><![CDATA[curl]]></category> <category><![CDATA[google]]></category> <category><![CDATA[jQuery]]></category><guid
isPermaLink="false">http://www.phoenixheart.net/?p=172</guid> <description><![CDATA[I have a good news and a bad news for today. The bad news is, I got hit by a f-king drunker several days ago in a traffic accident (Saigon&#8217;s traffic is pure shit) and had to take some macro surgeries. The good news is, due to this accident I have some free time to [...]]]></description> <content:encoded><![CDATA[<p><span
class="drop-cap">I</span> have a good news and a bad news for today. The bad news is, I got hit by a f-king drunker several days ago in a traffic accident (Saigon&#8217;s traffic is pure shit) and had to take some macro surgeries. The good news is, due to this accident I have some free time to think and do something &#8211; sense and nonsense, just for my habits.</p><p>So yesterday, this pal of mine showed (off) a web project he&#8217;s taking part in &#8211; a site called &#8220;<a
rel="nofollow" href="http://www.heygoo.com">HeyGoo</a>&#8220;. This site uses Google&#8217;s AJAX Search API (and Yahoo&#8217;s too, I&#8217;m not sure) to find and display result in an AJAX&#8217;ed way &#8211; that is, no pagination involved, instead users have to scroll to bottom for the next results to be shown up. Rather interesting, eh?</p><p>Well, my friend he seemed to be very proud of this project and putting all his hope to its success, so I didn&#8217;t want to discourage him. But honestly, I don&#8217;t see it as any revolution. Not talking about the old design with tables everywhere, the annoying target=&#8221;_blank&#8221; anchors and the so-cliché logo, I pointed out for him some problems the site was having:</p><ul><li>The search results are not so good. I searched for something on Google and it returned some hundreds of results, when HeyGoo told me it couldn&#8217;t find any. I don&#8217;t know why, hey, at least it is using Google Search API no?</li><li>There are certainly times that a user want to go to page, say, 3571, to see if his new forum ever reaches to Google. He can do that very easily with any &#8220;normal&#8221; search engine out there, but not with this HeyGoo where he must scroll 3570 times.</li><li>Biggest problem: the site currently doesn&#8217;t care about the loaded results. New results are appended, appended, appended, when old ones are still there in the top. Imagine how much memory the poor browser has to use up for this curious guy who&#8217;s scrolling over 317 pages and counting.</li></ul><p>With all these drawbacks vs. the only ajax advantage (personally I don&#8217;t see it as an advantage but another failure however), I doubt this site will do anything big. Anyhow as a friend I still wish it the best.</p><p>Now to the main part: despite of my skeptical thoughts, I still see the AJAX dynamic scroll content something interesting, and might be useful sometimes. So I sit down and wrote my own (very basic) version of the AJAX Search, where no pagination is involved and you must scroll for something new <img
src='http://www.phoenixheart.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> It took me 30 minutes for the core, and some 30 more for the layout tweaks. Before getting into the code, you can see the final working result <a
href="http://www.phoenixheart.net/projects/ajaxsearch/">here</a>.<span
id="more-172"></span></p><p>It&#8217;s rather simple. The whole &#8220;trick&#8221; was done in 2 part: the client JavaScript, and the server PHP.</p><h3>1. The JavaScript</h3><p>As usual, <a
href="http://www.jquery.com">jQuery</a> is my choice. First, bind to the &#8220;submit&#8221; event of the search form to handle searching.</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
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#f&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    e.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
    <span style="color: #006600; font-style: italic;">// don't search if there's a search in action, or the form is not valid</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>busy <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>validateForm<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#result&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#loading&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> q <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#q&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// indates that there's a search on the stage</span>
    busy <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// do an ajax call</span>
    $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;search.php&quot;</span><span style="color: #339933;">,</span>
        data<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#f&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#loading&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fast&quot;</span><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: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#result&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;start&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">// the start position of result is 0, since this is the first page</span>
                $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;q&quot;</span><span style="color: #339933;">,</span> q<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>      <span style="color: #006600; font-style: italic;">// save the last used keywords</span>
                expired <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>                    <span style="color: #006600; font-style: italic;">// the search has not expired (just started ;))</span>
                busy <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>                       <span style="color: #006600; font-style: italic;">// not busy anymore, ready for the next search</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        error<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: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#loading&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fast&quot;</span><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: #006600; font-style: italic;">// do something here?</span>
                busy <span style="color: #339933;">=</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>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>With the <a
href="http://brandonaaron.net/docs/dimensions/">Dimension plugin</a> now natively integrated into jQuery version 1.2.6, it&#8217;s 4 lines of code to detect if the user has scrolled to the bottom of the page and go get the next results.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #000066;">scroll</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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">scrollTop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> $<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</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>
        searchMore<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: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;</pre></td></tr></table></div><p>Now, the searchMore() function:</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
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> searchMore<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// if the site is busy with another search, or if the search has expired</span>
    <span style="color: #006600; font-style: italic;">// (no more results can be found), don't search</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>busy <span style="color: #339933;">||</span> expired<span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// if we don't have a previous search, don't search</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;q&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// i'm working, i'm working...</span>
    busy <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// the start page is increased by 1</span>
    $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;start&quot;</span><span style="color: #339933;">,</span> $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;start&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#loading&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// make another AJAX call</span>
    $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;search.php&quot;</span><span style="color: #339933;">,</span>
        data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;q=&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;q&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&amp;start=&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;start&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// multiplied by 10</span>
        success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#loading&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fast&quot;</span><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: #006600; font-style: italic;">// we have the next result, perfect</span>
            	<span style="color: #006600; font-style: italic;">// append it into the current result</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#result&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                busy <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// not so busy anymore</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        error<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: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#loading&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;fast&quot;</span><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: #006600; font-style: italic;">// do something here?</span>
                busy <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</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>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>There, the JavaScript is almost done. Of course there is a &#8220;validateForm()&#8221; function, but I guess it&#8217;s not necessary to include it into this post&#8230;</p><h3>2. The server stuff</h3><p>In order to retrieve the search results from Google, there are at least 2 ways:</p><ol><li>Using its <a
href="http://code.google.com/apis/ajaxsearch/">AJAX API</a>. Unfortunately, for some mysterious reasons, this didn&#8217;t work so well with me, as only 8 first pages can be retrieved. Any attempt to get the remaining results were answered with a 400 bad request error. I guess I missed something, maybe API or ATM <img
src='http://www.phoenixheart.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> but hell with it.</li><li>Making use of the traditional and very powerful cURL. My choice <img
src='http://www.phoenixheart.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></li></ol><p>Here is the entire content of my search.php page.</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
</pre></td><td
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.google.com/search?hl=en&amp;q='</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'q'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;start='</span> <span style="color: #339933;">.</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_REFERER<span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$body</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// do a simple preg_match to get the results</span>
<span style="color: #666666; font-style: italic;">// let's pray that Google won't change its HTML structure for search results so soon ;)</span>
<span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&lt;ol&gt;(.*?)&lt;/ol&gt;/i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// no match?</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;">$matches</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</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;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'start'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;script&gt;expired = true;&lt;/script&gt;&lt;li&gt;No more results were found.&lt;/li&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// set the &quot;expired&quot; JS var to true if this is called from searchMore() function</span>
    <span style="color: #b1b100;">else</span>
        <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;li&gt;Your search did not match any documents.&lt;/li&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Google uses relative path for the image sources and video links on its search pages</span>
<span style="color: #666666; font-style: italic;">// so we turn them into absolute links</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">utf8_encode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&quot;/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&quot;http://www.google.com/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>That&#8217;s all of the core part. Of course we must prepare the index HTML with all the form, div, ol, img and so on before getting into action, but it&#8217;s not that tricky. So you can visit <a
href="http://www.phoenixheart.net/projects/ajaxsearch/">the result here</a> and do some tests. Remember, this search tool is very basic, and I don&#8217;t have any intention to turn it into anything advanced <img
src='http://www.phoenixheart.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p> <img
style='display:none' id="post-172-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2008/12/google-search-in-an-ajaxed-way/',title:'Google Search in an AJAX&#8217;ed way',tweet:'I have a good news and a bad news for today. The bad news is, I got hit by a f-king drunker several ',description:'I have a good news and a bad news for today. The bad news is, I got hit by a f-king drunker several '})"><script type='text/javascript'>document.getElementById("post-172-blankimage").onload();</script>]]></content:encoded> <wfw:commentRss>http://www.phoenixheart.net/2008/12/google-search-in-an-ajaxed-way/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Digg This O&#8217; Mine</title><link>http://www.phoenixheart.net/2008/10/digg-this-o-mine/</link> <comments>http://www.phoenixheart.net/2008/10/digg-this-o-mine/#comments</comments> <pubDate>Wed, 29 Oct 2008 03:44:00 +0000</pubDate> <dc:creator>phoenix.heart</dc:creator> <category><![CDATA[Featured]]></category> <category><![CDATA[Freebies]]></category> <category><![CDATA[Server stuffs]]></category> <category><![CDATA[digg]]></category> <category><![CDATA[Digg This O' Mine]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[wordpress]]></category><guid
isPermaLink="false">http://www.phoenixheart.net/?p=112</guid> <description><![CDATA[Just like most of us here, I love WordPress, and I like Digg. And as you may know, Digg allows us to integrate the &#8220;Digg This&#8221; button into virtually any web page. Yes, this naturally includes my WordPress posts. Yay! The integration is dead simple. To display a &#8220;Digg This&#8221; button in my post, I [...]]]></description> <content:encoded><![CDATA[<p><span
class="drop-cap">J</span>ust like most of us here, I love WordPress, and I like Digg.</p><p>And as you may know, Digg allows us to <a
href="http://digg.com/tools/integrate">integrate the &#8220;Digg This&#8221; button</a> into virtually any web page. Yes, this naturally includes my WordPress posts. Yay!</p><p>The integration is dead simple. To display a &#8220;Digg This&#8221; button in my post, I only need to place this code somewhere:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
</pre></td><td
class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
    digg_url = &quot;My post's permalink&quot;;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://digg.com/tools/diggthis.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></td></tr></table></div><p>Or, in case I want to customize the button a bit:</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
</pre></td><td
class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
    digg_url     = &quot;My post's permalink&quot;;
&nbsp;
    digg_title   = &quot;My post's title&quot;;
&nbsp;
    // The background color *around* the button
    digg_bgcolor = &quot;#ff9900&quot;;
&nbsp;
    // The &quot;skin&quot; of the button. &quot;Compact&quot; means that tiny icon.
    digg_skin    = &quot;compact&quot;;
&nbsp;
    // Clicking on the button will open the Digg link in a new tab/window
    digg_window  = &quot;new&quot;;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://digg.com/tools/diggthis.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></td></tr></table></div><p>Can&#8217;t be simpler right? But I&#8217;m not satisfied with this&#8230; Firstly, I&#8217;m lazy and it bores me to death to copy and paste the scripts above into <em>every</em> new post. Second, if I change the permalink of my post, I&#8217;ll have to edit it to update the URL or the button will be in trouble. And third, it will be hell if someday I decide to change the layout of the buttons in <em>all</em> posts, or if Digg changes something in its integration code.</p><p>So I was thinking about a &#8220;Digg This&#8221; plugin that can automate everything for me. And it beat me to see that there&#8217;s none, or at least I couldn&#8217;t find any.<span
id="more-112"></span></p><p>Then I decided to write one myself. By the way, this is my first attempt to write a plugin for WordPress &#8211; I&#8217;ve hacked plenty though, like WP-Syntax, All In One SEO Pack etc. It took me one day and lot of headache, but finally I managed to get my Digg This O&#8217; Mine working smoothly, and I&#8217;m using it right now.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
Plugin Name: Digg This O' Mine
Plugin URI: http://www.phoenixheart.net/2008/10/digg-this-o-mine
Description: Place a &quot;Digg This&quot; button at the end of your posts, pages, or anywhere at your choice.
Version: 1.0
Author: Phoenixheart
Author URI: http://www.phoenixheart.net
*/</span></pre></td></tr></table></div><p>It can be downloaded <a
href="http://wordpress.org/extend/plugins/digg-this-o-mine">here</a>. Just like any other plugin, just unzip and upload it into your wp-content/plugins folder, activate it through the &#8220;Plugins&#8221; panel, and it will work out of the box. If you want more power, head to Settings-&gt;Digg This O&#8217; Mine to configure some options:</p><p><img
src="/wp-content/uploads/2008/10/dtom_options.gif" alt="Digg This O' Mine Options" width="474" height="379" /></p><p>(The numbers and shading effect are added using Photoshop).</p><p>The (background) color picker was implemented using the fantastic <a
href="http://acko.net/dev/farbtastic">Farbtastic</a> <a
href="http://www.jquery.com">jQuery</a> plugin.</p><p>Feel free to download, use, and maybe extend this plugin, as it&#8217;s licensed under <a
href="http://www.gnu.org/copyleft/gpl.html">GPL</a>. Comments and bug reports are always welcomed!</p><p><em>As the final line:</em> <span
style="text-decoration: line-through;">I attempted to <a
href="http://wordpress.org/extend/plugins/add/">add this plugin</a> into WordPress repository, but somehow I&#8217;ve not received any email from them. I would appreciate a lot if someone could guide me through the plugin adding process, as I&#8217;m now totally stuck.</span> I&#8217;ve managed to add it to WordPress. Now it&#8217;s an &#8220;official&#8221; plugin <a
href="http://wordpress.org/extend/plugins/digg-this-o-mine">there</a>.</p> <img
style='display:none' id="post-112-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2008/10/digg-this-o-mine/',title:'Digg This O&#8217; Mine',tweet:'Just like most of us here, I love WordPress, and I like Digg. And as you may know, Digg allows us to',description:'Just like most of us here, I love WordPress, and I like Digg. And as you may know, Digg allows us to'})"><script type='text/javascript'>document.getElementById("post-112-blankimage").onload();</script>]]></content:encoded> <wfw:commentRss>http://www.phoenixheart.net/2008/10/digg-this-o-mine/feed/</wfw:commentRss> <slash:comments>30</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)
Database Caching 4/11 queries in 0.006 seconds using disk

Served from: www.phoenixheart.net @ 2010-09-09 07:53:38 -->