<?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>James Wilson -blog &#187; Coding</title>
	<atom:link href="http://ja.meswilson.com/blog/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://ja.meswilson.com/blog</link>
	<description></description>
	<lastBuildDate>Thu, 17 Jun 2010 22:52:05 +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>Burn bootloader for Arduino Duemilanove w/ Atmega328 using avrdude 5.10</title>
		<link>http://ja.meswilson.com/blog/2010/04/20/burn-bootloader-for-arduino-duemilanove-w-atmega328-using-avrdude-5-10/</link>
		<comments>http://ja.meswilson.com/blog/2010/04/20/burn-bootloader-for-arduino-duemilanove-w-atmega328-using-avrdude-5-10/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 08:12:34 +0000</pubDate>
		<dc:creator>James Wilson</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Hardware]]></category>

		<guid isPermaLink="false">http://ja.meswilson.com/blog/?p=257</guid>
		<description><![CDATA[This is using a new Arduino Duemilanove board with a regular Atmega328p, with no bootloader. I wanted to do the BitBang mode, since I didn&#039;t want to get or make anything else, and the ArduinoISP, I didn&#039;t have access to another Arduino. So I pieced together 3 different guides, I finally got it working. This [...]]]></description>
			<content:encoded><![CDATA[<p>This is using a new Arduino Duemilanove board with a regular Atmega328p, with no bootloader. I wanted to do the BitBang mode, since I didn&#039;t want to get or make anything else, and the ArduinoISP, I didn&#039;t have access to another Arduino. So I pieced together <a href="http://www.geocities.jp/arduino_diecimila/bootloader/index_old_en.html">3</a> <a href="http://doswa.com/blog/2009/12/20/avrdude-58-with-ftdi-bitbang-patch-on-linux/">different</a> <a href="http://www.kerrywong.com/2010/04/02/on-atmega328-bootloading-with-ftdi-bitbang-method/">guides</a>, I finally got it working.</p>
<p>This assumes you have a Duemilanove with Atmega328p. Running Ubuntu 9.10, though really any distro will work, though how you get the dependencies will vary. Also, you have the Arduino IDE installed to /usr/share/arduino, which if you install using the deb source method, it will be.</p>
<p>First, setup the Arduino as shown <a href="http://www.geocities.jp/arduino_diecimila/bootloader/connecting.html">here</a>. I used the first wiring guide, but either should work.</p>
<p>Next, setup avrdude on Ubuntu. I followed <a href="http://doswa.com/blog/2009/12/20/avrdude-58-with-ftdi-bitbang-patch-on-linux/">this guide</a>, but used avrdude 5.10, instead of 5.8. The commands remain the same, except instead of downloading 5.8, you download 5.10.</p>
<p>Here&#039;s what I ran:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>download.savannah.gnu.org<span style="color: #000000; font-weight: bold;">/</span>releases-noredirect<span style="color: #000000; font-weight: bold;">/</span>avrdude<span style="color: #000000; font-weight: bold;">/</span>avrdude-5.10.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> xfvz avrdude-5.10.tar.gz 
<span style="color: #7a0874; font-weight: bold;">cd</span> avrdude-<span style="color: #000000;">5.10</span><span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">8</span> <span style="color: #000000;">7</span> <span style="color: #000000;">6</span> <span style="color: #000000;">5</span> <span style="color: #000000;">4</span> <span style="color: #000000;">3</span> <span style="color: #000000;">2</span> <span style="color: #000000;">1</span> <span style="color: #000000;">0</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">-O</span> patch-<span style="color: #007800;">$i</span>.diff http:<span style="color: #000000; font-weight: bold;">//</span>savannah.nongnu.org<span style="color: #000000; font-weight: bold;">/</span>patch<span style="color: #000000; font-weight: bold;">/</span>download.php?<span style="color: #007800;">file_id</span>=<span style="color: #000000;">1851</span><span style="color: #007800;">$i</span>; <span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> patch-<span style="color: #000000; font-weight: bold;">*</span>.diff; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">patch</span> <span style="color: #660033;">-p0</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #007800;">$file</span>; <span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.ftdichip.com<span style="color: #000000; font-weight: bold;">/</span>Drivers<span style="color: #000000; font-weight: bold;">/</span>D2XX<span style="color: #000000; font-weight: bold;">/</span>Linux<span style="color: #000000; font-weight: bold;">/</span>libftd2xx0.4.16.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> xzf libftd2xx<span style="color: #000000; font-weight: bold;">*</span>.tar.gz
<span style="color: #c20cb9; font-weight: bold;">cp</span> libftd2xx<span style="color: #000000; font-weight: bold;">*/</span>static_lib<span style="color: #000000; font-weight: bold;">/*</span> .
<span style="color: #c20cb9; font-weight: bold;">cp</span> libftd2xx<span style="color: #000000; font-weight: bold;">*/*</span>.h .
<span style="color: #c20cb9; font-weight: bold;">cp</span> libftd2xx<span style="color: #000000; font-weight: bold;">*/*</span>.cfg .
.<span style="color: #000000; font-weight: bold;">/</span>configure 
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>arduino<span style="color: #000000; font-weight: bold;">/</span>hardware<span style="color: #000000; font-weight: bold;">/</span>arduino<span style="color: #000000; font-weight: bold;">/</span>bootloaders<span style="color: #000000; font-weight: bold;">/</span>atmega<span style="color: #000000; font-weight: bold;">/</span>ATmegaBOOT_168_atmega328.hex .</pre></div></div>

<p>Then you edit the file, <code>Makefile</code>:<br />
<code>CFLAGS = -g -O2</code> -> <code>CFLAGS = -g -O2 -DHAVE_LIBUSB -DSUPPORT_FT245R</code><br />
<code>LIBS = -lreadline -lncurses -ltermcap</code> -> <code>LIBS = -lreadline -lncurses -ltermcap ./libftd2xx.a.0.4.16 -lrt</code></p>
<p>Then just run <code>make</code>.</p>
<p>Third, run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> .<span style="color: #000000; font-weight: bold;">/</span>avrdude <span style="color: #660033;">-C</span> avrdude.conf <span style="color: #660033;">-c</span> duemilanove <span style="color: #660033;">-P</span> ft0 <span style="color: #660033;">-p</span> m328p <span style="color: #660033;">-t</span> <span style="color: #660033;">-B</span> <span style="color: #000000;">4800</span></pre></div></div>

<p>And in that:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">erase
<span style="color: #c20cb9; font-weight: bold;">w</span> efuse <span style="color: #000000;">0</span> 0x05
<span style="color: #c20cb9; font-weight: bold;">w</span> hfuse <span style="color: #000000;">0</span> 0xda
<span style="color: #c20cb9; font-weight: bold;">w</span> lfuse <span style="color: #000000;">0</span> 0xff
q</pre></div></div>

<p>This sets up the efuse, hfuse, and ifuse values. This has to be run at a lower baud rate.</p>
<p>Fourth, run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> .<span style="color: #000000; font-weight: bold;">/</span>avrdude <span style="color: #660033;">-C</span> avrdude.conf <span style="color: #660033;">-c</span> duemilanove <span style="color: #660033;">-P</span> ft0 <span style="color: #660033;">-p</span> m328p <span style="color: #660033;">-U</span> flash:<span style="color: #c20cb9; font-weight: bold;">w</span>:ATmegaBOOT_168_atmega328.hex</pre></div></div>

<p>The bootloader has been flashed. Lock it by running:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> .<span style="color: #000000; font-weight: bold;">/</span>avrdude <span style="color: #660033;">-C</span> avrdude.conf <span style="color: #660033;">-c</span> duemilanove <span style="color: #660033;">-P</span> ft0 <span style="color: #660033;">-p</span> m328p <span style="color: #660033;">-t</span></pre></div></div>

<p>And enter:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">w</span> lock <span style="color: #000000;">0</span> 0x0f
q</pre></div></div>

<p>Now, your Atmega328 should be ready to use. You can try it by uploading the example Blink from the IDE.</p>
]]></content:encoded>
			<wfw:commentRss>http://ja.meswilson.com/blog/2010/04/20/burn-bootloader-for-arduino-duemilanove-w-atmega328-using-avrdude-5-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changed The Domain</title>
		<link>http://ja.meswilson.com/blog/2009/01/06/changed-the-domain/</link>
		<comments>http://ja.meswilson.com/blog/2009/01/06/changed-the-domain/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 07:25:21 +0000</pubDate>
		<dc:creator>James Wilson</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[this]]></category>

		<guid isPermaLink="false">http://ja.meswilson.com/blog/?p=229</guid>
		<description><![CDATA[I changed the location to ja.meswilson.com/blog/. Most of the old links should work and redirect here. I added the redirects in lighttpd.conf. I&#039;ll probably start posting more. Going to try to start doing some more online work, and I&#039;ll write about them or what have you. Also, new theme.]]></description>
			<content:encoded><![CDATA[<p>I changed the location to <a href="http://ja.meswilson.com/blog/">ja.meswilson.com/blog/</a>.</p>
<p>Most of the old links should work and redirect here. I added the redirects in lighttpd.conf.</p>
<p>I&#039;ll probably start posting more. Going to try to start doing some more online work, and I&#039;ll write about them or what have you.</p>
<p>Also, new theme.</p>
]]></content:encoded>
			<wfw:commentRss>http://ja.meswilson.com/blog/2009/01/06/changed-the-domain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Widget A Day: Take 2</title>
		<link>http://ja.meswilson.com/blog/2008/10/30/widget-a-day-take-2/</link>
		<comments>http://ja.meswilson.com/blog/2008/10/30/widget-a-day-take-2/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 06:19:07 +0000</pubDate>
		<dc:creator>James Wilson</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Widget-A-Day]]></category>
		<category><![CDATA[Widgets]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://ja.meswilson.com/blog/2008/10/30/widget-a-day-take-2/</guid>
		<description><![CDATA[Since I&#039;m bored, and some of my old widgets have had some feature requests, so I think I&#039;ll try Widget A Day again. I&#039;m going for at least 14 widgets, so 2 weeks, some being updated versions of the older ones. It would most likely start the beginning of next week. (Edit- not happening this [...]]]></description>
			<content:encoded><![CDATA[<p>Since I&#039;m bored, and some of my old widgets have had some feature requests, so I think I&#039;ll try <a href="http://ja.meswilson.com/blog/category/widget-a-day/">Widget A Day</a> again. I&#039;m going for at least 14 widgets, so 2 weeks, some being updated versions of the older ones. </p>
<p>It would most likely start the beginning of next week. (Edit- not happening this week, but should be next week)</p>
<p>If you have requests or ideas, post them here. I need them to be able to do this.</p>
]]></content:encoded>
			<wfw:commentRss>http://ja.meswilson.com/blog/2008/10/30/widget-a-day-take-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Paintball Headlines Theme</title>
		<link>http://ja.meswilson.com/blog/2008/08/24/paintball-headlines-theme/</link>
		<comments>http://ja.meswilson.com/blog/2008/08/24/paintball-headlines-theme/#comments</comments>
		<pubDate>Sun, 24 Aug 2008 19:03:19 +0000</pubDate>
		<dc:creator>James Wilson</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Themes]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://ja.meswilson.com/blog/2008/08/24/paintball-headlines-theme/</guid>
		<description><![CDATA[I said I would post the theme for headlines when I thought it was acceptable. There are still problems, but whatever. Anyways, this theme is based upon this tutorial theme, but changed to have multiple author support, support tags and categories, and be a double right column instead of a column on both sides. There [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://paintballheadlines.com/2008/08/05/huzzah-new-theme/">I said I would post the theme</a> for <a href="http://paintballheadlines.com">headlines</a> when I thought it was acceptable. There are still problems, but whatever.</p>
<p>Anyways, this theme is based upon <a href="http://css-tricks.com/designing-for-wordpress-complete-series-downloads/">this tutorial theme</a>, but changed to have multiple author support, support tags and categories, and be a double right column instead of a column on both sides. There are a few other little changes in there.</p>
<p><a href="http://github.com/omgmovieslol/Paintball-Headlines-Theme">Github Repository</a></p>
<p>I&#039;ll try to update the theme whenever I change anything; I just have to remember to do a <code>svn ci</code> each time.</p>
<p>To run by default and not get errors, you need do need a few plugins, like wp_dtree. There&#039;s also a classifieds plugin that I wrote just for headlines that&#039;s needed, but I don&#039;t plan on releasing that, since it contains db info and it&#039;s pretty much just a MySQL query. In sidebar.php, just comment out the <code>get_classifieds_new(10);</code> code.</p>
<p>Edit: Changed to Github, since DevjaVu went away.</p>
]]></content:encoded>
			<wfw:commentRss>http://ja.meswilson.com/blog/2008/08/24/paintball-headlines-theme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Widget-A-Day</title>
		<link>http://ja.meswilson.com/blog/2007/05/24/wordpress-widget-a-day/</link>
		<comments>http://ja.meswilson.com/blog/2007/05/24/wordpress-widget-a-day/#comments</comments>
		<pubDate>Fri, 25 May 2007 01:26:50 +0000</pubDate>
		<dc:creator>James Wilson</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Widget-A-Day]]></category>

		<guid isPermaLink="false">http://ja.meswilson.com/blog/2007/05/24/wordpress-widget-a-day/</guid>
		<description><![CDATA[I&#039;ve been wanting to do a &#039;Something-A-Some-amount-of-time&#039;, and since I just made a WordPress Widget, which is pretty easy, and with WordPress 2.2, widget support is available by default, I decided to do a &#039;WordPress Widget-A-Day&#039;. Over the next week, though I&#039;ll probably start today, so I guess it&#039;ll have 4 extra or maybe just [...]]]></description>
			<content:encoded><![CDATA[<p>I&#039;ve been wanting to do a &#039;Something-A-Some-amount-of-time&#039;, and since I just made a WordPress Widget, which is pretty easy, and with WordPress 2.2, <a href="http://wordpress.org/development/2007/05/wordpress-22/">widget support is available by default</a>, I decided to do a &#039;WordPress Widget-A-Day&#039;.</p>
<p>Over the next week, though I&#039;ll probably start today, so I guess it&#039;ll have 4 extra or maybe just 1 depending on my motivation, I&#039;ll make and release a widget for WordPress everyday. These might not be fancy, they might not even be original, though I&#039;m going to try to not make ones that already exist with the same functionality, but they&#039;ll be widgets.</p>
<p>If you have any ideas or suggestions, comment or <a href="http://ja.meswilson.com/blog/contact/">contact me</a>.</p>
<p><a href="http://ja.meswilson.com/blog/category/widget-a-day/">View posts about Widget-A-Day</a> or <a href="http://ja.meswilson.com/blog/category/widget-a-day/feed/">subscribe to the Widget-A-Day feed</a></p>
<p>Hopefully, I won&#039;t fail at this.</p>
]]></content:encoded>
			<wfw:commentRss>http://ja.meswilson.com/blog/2007/05/24/wordpress-widget-a-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple XML is Simpler!</title>
		<link>http://ja.meswilson.com/blog/2007/05/19/simple-xml-is-simpler/</link>
		<comments>http://ja.meswilson.com/blog/2007/05/19/simple-xml-is-simpler/#comments</comments>
		<pubDate>Sat, 19 May 2007 07:04:00 +0000</pubDate>
		<dc:creator>James Wilson</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://ja.meswilson.com/blog/2007/05/19/simple-xml-is-simpler/</guid>
		<description><![CDATA[Genius! Sucks that it isn&#039;t for PHP 4. For this site, at the moment, I&#039;m forced to use PHP4, since PHP5 breaks permalinks for WordPress for some reason. It&#039;s not WordPress&#039;s fault, though. Just the crappiness that is this shared hosting. Anyways, I&#039;ve used SimpleXML for most of XML parsing in PHP. Mainly for the [...]]]></description>
			<content:encoded><![CDATA[<p>Genius!</p>
<p>Sucks that it isn&#039;t for PHP 4. For this site, at the moment, I&#039;m forced to use PHP4, since PHP5 breaks permalinks for WordPress for some reason. It&#039;s not WordPress&#039;s fault, though. Just the crappiness that is this shared hosting.</p>
<p>Anyways, I&#039;ve used SimpleXML for most of XML parsing in PHP. Mainly for the reason that I&#039;m lazy. This time, I wanted the site to run on here under PHP4, so I didn&#039;t have that success. But PHP&#039;s <a href="http://www.php.net/manual/en/ref.xml.php">XML Parser</a> shouldn&#039;t be too bad, right?</p>
<p>Here&#039;s how to go through all the <code>&lt;item&gt;</code> tags in an RSS feed via SimpleXML and placing them into an associative array:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$sxml</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleXMLElement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sxml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$item_title</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$item_link</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'desc'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$item_desc</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'date'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$item_date</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now in XML Parser:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$parser</span> <span style="color: #339933;">=</span> <span style="color: #990000;">xml_parser_create</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'UTF-8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">xml_parser_set_option</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parser</span><span style="color: #339933;">,</span> XML_OPTION_SKIP_WHITE<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;">xml_parse_into_struct</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$xml</span><span style="color: #339933;">,</span> <span style="color: #000088;">$vals</span><span style="color: #339933;">,</span> <span style="color: #000088;">$index</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">xml_parser_free</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parser</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$feed</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: #000088;">$items</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: #000088;">$length</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$item_title</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$index</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$item_title</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">:</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$index</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$item_title</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$titleoffset</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$item_title</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span> ? <span style="color: #cc66cc;">1</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$linkoffset</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$item_link</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span> ? <span style="color: #cc66cc;">1</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$descoffset</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$item_desc</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$desc</span><span style="color: #009900;">&#41;</span> ? <span style="color: #cc66cc;">1</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dateoffset</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$item_date</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$date</span><span style="color: #009900;">&#41;</span> ? <span style="color: #cc66cc;">1</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$length</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vals</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$index</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$item_title</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #000088;">$titleoffset</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vals</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$index</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$item_link</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #000088;">$linkoffset</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'desc'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vals</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$index</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$item_desc</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #000088;">$descoffset</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'date'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vals</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$index</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$item_date</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #000088;">$dateoffset</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Only about 10 more lines and ridiculous looking arrays.</p>
<p>This also doesn&#039;t show that you have to run <code>strtoupper($tagname)</code> on all of the tags you want.</p>
<p>One thing that SimpleXML couldn&#039;t do is parse elements with a colon in them. Like <code>&lt;dc:creator&gt;</code> or <code>&lt;content:encoded&gt;</code>. A simple fix was just to run <code>str_replace("&lt;dc:creator&gt;","&lt;creator&gt;",$xml)</code></p>
<p>Uggh. At least the annoying part is finally out of the way, I hope.</p>
<p><b>Update</b>- Haha. That doesn&#039;t even work. It&#039;s nowhere near the correct order. But I totally forgot about <a href="http://magpierss.sourceforge.net/">MagpieRSS</a>. I&#039;m using that instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://ja.meswilson.com/blog/2007/05/19/simple-xml-is-simpler/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Fun with Digg&#039;s API</title>
		<link>http://ja.meswilson.com/blog/2007/05/08/fun-with-diggs-api/</link>
		<comments>http://ja.meswilson.com/blog/2007/05/08/fun-with-diggs-api/#comments</comments>
		<pubDate>Wed, 09 May 2007 01:36:31 +0000</pubDate>
		<dc:creator>James Wilson</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://ja.meswilson.com/blog/2007/05/08/fun-with-diggs-api/</guid>
		<description><![CDATA[Digg&#039;s api was released about a week ago a while ago, and since that time, various flash projects have surfaced, probably due to that pesky contest. But I don&#039;t have any flash experience, so PHP, here we come. We&#039;re going to make various tag clouds, a Reddit clone, Reddit/Better RSS feed, and a live diggs [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://apidoc.digg.com">Digg&#039;s api</a> was released about <del datetime="2007-05-09T01:30:45+00:00">a week ago</del> a while ago, and since that time, <a href="http://www.gskinner.com/DiggTop/">various</a> <a href="http://www.yourminis.com/minis/yourminis/hart/mini:diggest">flash</a> projects have surfaced, probably due to that <a href="http://digg.com/contest">pesky contest</a>. But I don&#039;t have any flash experience, so PHP, here we come.</p>
<p>We&#039;re going to make various tag clouds, a Reddit clone, Reddit/Better RSS feed, and a live diggs app.</p>
<p><strong>Update &#8211; 05/09/07 &#8211; 3 PM</strong> &#8211; Stupid host seems to be having database issues. Great. I wish I could afford a dedicated, or I guess VPS, so I don&#039;t have to put with this crap.</p>
<p><strong>Update &#8211; 05/09/07 &#8211; 6 PM</strong> &#8211; It seems that it was a combination of their db sucking and the fact they got rid of some essential pear packages. WTF?</p>
<p><strong>Update &#8211; 05/12/07 &#8211; 11 AM</strong> &#8211; Yup. They cut off my MySQL abilities. I can&#039;t connect to any of my databases on xrho.com. This site is fine however. I guess inserting 100+ entries a minute might have annoyed them?</p>
<p><strong>Update &#8211; 05/17/07 &#8211; 7 PM</strong> &#8211; The MySQL abilities are still cut off. Fucking netfirms. Also, it seems in one of my updates, it cut off the bottom, which also happened to include the download links. You can download a <a href="http://xrho.com/digg/digg.zip">ZIP</a> or <a href="http://xrho.com/digg/digg.tar.gz">Gzip</a> of the files. Since I&#039;m having problems with that, feel free to download them and run them on your own site. Let me know if you do so I can add the link.</p>
<p>Demos of most of the scripts are available <a href="http://xrho.com/digg/">here</a>, and more specifically:</p>
<ul>
<li><a href="http://xrho.com/digg/reddit.php">Reddit Clone</a></li>
<li><a href="http://feeds.feedburner.com/dreddit">RSS Feed</a></li>
<li><a href="http://xrho.com/digg/livediggs.php">Live Diggs</a></li>
</ul>
<p>Due to the length of this post, I&#039;m splitting it. I hate making people click through, but it&#039;s long enough to constitute it.<br />
<span id="more-69"></span></p>
<h2>Part A: The Setup</h2>
<style type="text/css">
.pre {
 overflow:auto;
 height: 200px;
}
</style>
<p>First, we need the <a href="http://pear.php.net">Pear</a> package, from <a href="http://bugs.joestump.net/code/Services_Digg/Services_Digg-0.0.2.tgz">http://bugs.joestump.net/code/Services_Digg/Services_Digg-0.0.2.tgz</a>. You can install it using the Pear install command, but I just copied the folder into my directory.</p>
<p>We&#039;re going to be using MySQL database, so create a new database and here is the table structure I used:</p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- </span>
<span style="color: #808080; font-style: italic;">-- Table structure for table `diggslive`</span>
<span style="color: #808080; font-style: italic;">-- </span>
&nbsp;
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`diggslive`</span> <span style="color: #FF00FF;">&#40;</span>
  <span style="color: #008000;">`digging<span style="color: #008080; font-weight: bold;">_</span>id`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #FF9900; font-weight: bold;">unsigned</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #FF9900; font-weight: bold;">auto_increment</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`story<span style="color: #008080; font-weight: bold;">_</span>id`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #FF9900; font-weight: bold;">unsigned</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`id`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #FF9900; font-weight: bold;">unsigned</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`username`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">250</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">collate</span> latin1_general_ci <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`time`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`status`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">45</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">collate</span> latin1_general_ci <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span>  <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`digging<span style="color: #008080; font-weight: bold;">_</span>id`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <span style="color: #FF9900; font-weight: bold;">UNIQUE</span> <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`id`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`id`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`username`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`username`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`story<span style="color: #008080; font-weight: bold;">_</span>id`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`story<span style="color: #008080; font-weight: bold;">_</span>id`</span><span style="color: #FF00FF;">&#41;</span>
<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">ENGINE</span><span style="color: #CC0099;">=</span>MyISAM  <span style="color: #990099; font-weight: bold;">DEFAULT</span> <span style="color: #FF9900; font-weight: bold;">CHARSET</span><span style="color: #CC0099;">=</span>latin1 <span style="color: #CC0099; font-weight: bold;">COLLATE</span><span style="color: #CC0099;">=</span>latin1_general_ci <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #CC0099;">=</span><span style="color: #008080;">137897</span> <span style="color: #000033;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- --------------------------------------------------------</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- </span>
<span style="color: #808080; font-style: italic;">-- Table structure for table `diggstories`</span>
<span style="color: #808080; font-style: italic;">-- </span>
&nbsp;
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`diggstories`</span> <span style="color: #FF00FF;">&#40;</span>
  <span style="color: #008000;">`digg<span style="color: #008080; font-weight: bold;">_</span>id`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #FF9900; font-weight: bold;">unsigned</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #FF9900; font-weight: bold;">auto_increment</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`title`</span> <span style="color: #999900; font-weight: bold;">text</span> character <span style="color: #990099; font-weight: bold;">set</span> latin1 <span style="color: #CC0099; font-weight: bold;">collate</span> latin1_general_ci <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`description`</span> <span style="color: #999900; font-weight: bold;">text</span> character <span style="color: #990099; font-weight: bold;">set</span> latin1 <span style="color: #CC0099; font-weight: bold;">collate</span> latin1_general_ci <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`diggs`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">5</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`comments`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">4</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`id`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #FF9900; font-weight: bold;">unsigned</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`link`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">1000</span><span style="color: #FF00FF;">&#41;</span> character <span style="color: #990099; font-weight: bold;">set</span> latin1 <span style="color: #CC0099; font-weight: bold;">collate</span> latin1_general_ci <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`submitted`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`promoted`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`href`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">1000</span><span style="color: #FF00FF;">&#41;</span> character <span style="color: #990099; font-weight: bold;">set</span> latin1 <span style="color: #CC0099; font-weight: bold;">collate</span> latin1_general_ci <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`status`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">45</span><span style="color: #FF00FF;">&#41;</span> character <span style="color: #990099; font-weight: bold;">set</span> latin1 <span style="color: #CC0099; font-weight: bold;">collate</span> latin1_general_ci <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`user<span style="color: #008080; font-weight: bold;">_</span>id`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #FF9900; font-weight: bold;">unsigned</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`username`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">250</span><span style="color: #FF00FF;">&#41;</span> character <span style="color: #990099; font-weight: bold;">set</span> latin1 <span style="color: #CC0099; font-weight: bold;">collate</span> latin1_general_ci <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`icon`</span> <span style="color: #999900; font-weight: bold;">text</span> character <span style="color: #990099; font-weight: bold;">set</span> latin1 <span style="color: #CC0099; font-weight: bold;">collate</span> latin1_general_ci <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`registered`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`profileviews`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #FF9900; font-weight: bold;">unsigned</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`topic<span style="color: #008080; font-weight: bold;">_</span>long`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">100</span><span style="color: #FF00FF;">&#41;</span> character <span style="color: #990099; font-weight: bold;">set</span> latin1 <span style="color: #CC0099; font-weight: bold;">collate</span> latin1_general_ci <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`topic<span style="color: #008080; font-weight: bold;">_</span>short`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">100</span><span style="color: #FF00FF;">&#41;</span> character <span style="color: #990099; font-weight: bold;">set</span> latin1 <span style="color: #CC0099; font-weight: bold;">collate</span> latin1_general_ci <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`container<span style="color: #008080; font-weight: bold;">_</span>long`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">100</span><span style="color: #FF00FF;">&#41;</span> character <span style="color: #990099; font-weight: bold;">set</span> latin1 <span style="color: #CC0099; font-weight: bold;">collate</span> latin1_general_ci <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`container<span style="color: #008080; font-weight: bold;">_</span>short`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">100</span><span style="color: #FF00FF;">&#41;</span> character <span style="color: #990099; font-weight: bold;">set</span> latin1 <span style="color: #CC0099; font-weight: bold;">collate</span> latin1_general_ci <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`host`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">250</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">collate</span> utf8_bin <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span>  <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`digg<span style="color: #008080; font-weight: bold;">_</span>id`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <span style="color: #FF9900; font-weight: bold;">UNIQUE</span> <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`href`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`href`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <span style="color: #FF9900; font-weight: bold;">FULLTEXT</span> <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`title`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`title`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <span style="color: #FF9900; font-weight: bold;">FULLTEXT</span> <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`description`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`description`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <span style="color: #FF9900; font-weight: bold;">FULLTEXT</span> <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`title<span style="color: #008080; font-weight: bold;">_</span>2`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`title`</span><span style="color: #000033;">,</span><span style="color: #008000;">`description`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <span style="color: #FF9900; font-weight: bold;">FULLTEXT</span> <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`link`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`link`</span><span style="color: #FF00FF;">&#41;</span>
<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">ENGINE</span><span style="color: #CC0099;">=</span>MyISAM  <span style="color: #990099; font-weight: bold;">DEFAULT</span> <span style="color: #FF9900; font-weight: bold;">CHARSET</span><span style="color: #CC0099;">=</span>utf8 <span style="color: #CC0099; font-weight: bold;">COLLATE</span><span style="color: #CC0099;">=</span>utf8_bin <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #CC0099;">=</span><span style="color: #008080;">3818</span> <span style="color: #000033;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- --------------------------------------------------------</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- </span>
<span style="color: #808080; font-style: italic;">-- Table structure for table `diggusers`</span>
<span style="color: #808080; font-style: italic;">-- </span>
&nbsp;
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #008000;">`diggusers`</span> <span style="color: #FF00FF;">&#40;</span>
  <span style="color: #008000;">`user<span style="color: #008080; font-weight: bold;">_</span>id`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #FF9900; font-weight: bold;">unsigned</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #FF9900; font-weight: bold;">auto_increment</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`username`</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">250</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">collate</span> latin1_general_ci <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`icon`</span> <span style="color: #999900; font-weight: bold;">text</span> <span style="color: #CC0099; font-weight: bold;">collate</span> latin1_general_ci<span style="color: #000033;">,</span>
  <span style="color: #008000;">`registered`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
  <span style="color: #008000;">`profileviews`</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #FF9900; font-weight: bold;">unsigned</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #990099; font-weight: bold;">default</span> <span style="color: #008000;">'0'</span><span style="color: #000033;">,</span>
  <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span>  <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`user<span style="color: #008080; font-weight: bold;">_</span>id`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <span style="color: #FF9900; font-weight: bold;">UNIQUE</span> <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`username`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`username`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <span style="color: #990099; font-weight: bold;">KEY</span> <span style="color: #008000;">`username<span style="color: #008080; font-weight: bold;">_</span>2`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`username`</span><span style="color: #FF00FF;">&#41;</span>
<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">ENGINE</span><span style="color: #CC0099;">=</span><span style="color: #990099; font-weight: bold;">InnoDB</span> <span style="color: #990099; font-weight: bold;">DEFAULT</span> <span style="color: #FF9900; font-weight: bold;">CHARSET</span><span style="color: #CC0099;">=</span>latin1 <span style="color: #CC0099; font-weight: bold;">COLLATE</span><span style="color: #CC0099;">=</span>latin1_general_ci <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #CC0099;">=</span><span style="color: #008080;">2550</span> <span style="color: #000033;">;</span></pre></div></div>

</div>
<p>There are 3 tables. Table diggstories will store the all the info about the the popular stories that is given to us through the api. There are 3 FULLTEXT indecies to enable a better search as shown later. </p>
<p>Now for the config file. Edit as necessary for your setup:<br />
<b>config.php</b>:</p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$dbhost</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dbuser</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;root&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dbpass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dbname</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;digg&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Connect to DB, now!</span>
<span style="color: #666666; font-style: italic;">// Regular connection</span>
<span style="color: #339933;">@</span><span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dbhost</span><span style="color: #339933;">,</span><span style="color: #000088;">$dbuser</span><span style="color: #339933;">,</span><span style="color: #000088;">$dbpass</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MySQL Connection error&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Persistent conenction</span>
<span style="color: #666666; font-style: italic;">// @mysql_pconnect($dbhost,$dbuser,$dbpass) or deadlyerror(&quot;MySQL Connection error (persistent) &quot;);</span>
<span style="color: #339933;">@</span><span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dbname</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Unable to select database&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</div>
<p>Here are some functions that we&#039;ll use later.<br />
<b>functions.php</b>:</p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</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;">get_magic_quotes_gpc</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>
          <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">//check if this function exists</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mysql_real_escape_string&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">//for PHP version &lt; 4.3.0 use addslashes</span>
    <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</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: #000088;">$value</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> dehtml<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&amp;(?!(amp|[#0-9]+|lt|gt|quot|copy|nbsp);)/ix&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&amp;amp;&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;#160;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&amp;#173;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&amp;#8205;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&amp;#8204;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&amp;#8237;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&amp;#8238;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//$content = preg_replace('/&amp;(?![a-z0-9]+;)/i', '&amp;amp;', $content); </span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&gt;&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: #0000ff;">&quot;),array(&quot;</span><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">&amp;</span><span style="color: #666666; font-style: italic;">#39;&quot;,&quot;&amp;quot;&quot;),$content);
</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> timeparse<span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$since</span> <span style="color: #339933;">=</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$time</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$since</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$since</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$since</span> second ago&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$since</span> seconds ago&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$since</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$since</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$since</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$since</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$since</span> minute ago&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$since</span> minutes ago&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$since</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">86400</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$since</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$since</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$since</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$since</span> hour ago&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$since</span> hours ago&quot;</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: #000088;">$since</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$since</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">86400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$since</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$since</span> day ago&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$since</span> days ago&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> toshort<span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">strtolower</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; &quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;_&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> host<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$exploded</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><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: #b1b100;">return</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;www.&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$exploded</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</div>
<h2>Part B: Getting data</h2>
<h3>Getting the stories</h3>
<p>First off, let&#039;s populate our database with stories. This will take as many stories as possible and inserts them into out `diggstories` table. We are also going to insert our user info that it finds.</p>
<p><b>insert.php</b>:</p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
&nbsp;
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user_agent'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Trendds/1.0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'max_execution_time'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'config.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">include</span> <span style="color: #0000ff;">'functions.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Services/Digg.php'</span><span style="color: #339933;">;</span>
Services_Digg<span style="color: #339933;">::</span><span style="color: #000088;">$appKey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.ja.meswilson.com/blog/Services_Digg_Proxy.php'</span><span style="color: #339933;">;</span>
Services_Digg<span style="color: #339933;">::</span><span style="color: #000088;">$uri</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://services.digg.com'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3525</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$count</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'count'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'offset'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$request</span> <span style="color: #339933;">=</span> Services_Digg<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Stories'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">popular</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">stories</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$story</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$userinfo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT `user_id`, `profileviews` FROM `diggusers` WHERE `username` = '&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' LIMIT 1&quot;</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: #990000;">mysql_numrows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$userinfo</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO `diggusers`
				( `user_id` , `username`, `icon`, `registered`, `profileviews` )
				VALUES ( 
					NULL, 
					'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;', 
					'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">icon</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;', 
					'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registered</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
					'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">profileviews</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'
				) &quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Inserting user: &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_error</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: #000088;">$user_id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_insert_id</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;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$user_id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$userinfo</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;user_id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO `diggstories` ( 
		`digg_id`, `title`, `description`, `diggs`, `comments`, `id`, `link`, `submitted`, `promoted`, `href`, `status`, 
			`user_id` , `username`, `icon`, `registered`, `profileviews`, `topic_long`, `topic_short`, `container_long`, `container_short`, `host`
		)
		VALUES (
			NULL, 
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;', 
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;', 
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">diggs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comments</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;', 
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">submit_date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">promote_date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">href</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">status</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">icon</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registered</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">profileviews</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">topic</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">topic</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">short_name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">container</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">container</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">short_name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
			'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span>host<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'
		) &quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE `diggstories` 
			SET `diggs` = '&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">diggs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;', `comments` = '&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comments</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'
			WHERE `id` = '&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' 
			LIMIT 1
			&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</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: #009900;">&#125;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$offset</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$offset</span> <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">total</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</div>
<p>The first lines,<br />
<code>ini_set('user_agent', 'Trendds/1.0');<br />
ini_set('max_execution_time', 3600);</code><br />
set the User-Agent and increases the max execution time, since getting over 3000 stories takes some time, and <a href="http://apidoc.digg.com/BasicConcepts#UserAgents">setting a user agent is required</a>.</p>
<p><code class="over">Services_Digg::$appKey = 'http://www.ja.meswilson.com/blog/Services_Digg_Proxy.php';<br />
Services_Digg::$uri = 'http://services.digg.com';</code><br />
set the api key and uri, as shown in the Pear tests.</p>
<p>Next, we start requesting and inserting the info. This runs through a while and for each loop inserting each story.</p>
<p>After running that, you should now have about a 3000 entry `diggstories` table along with a couple thousand entry `diggusers` table.</p>
<p>In order to keep these updated, we can run <b>update.php</b> every so often. I did 5 minutes, but that seems to be a bit overkill. </p>
<p><b>update.php</b>:</p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
&nbsp;
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user_agent'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Trendds/1.0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'max_execution_time'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'config.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">include</span> <span style="color: #0000ff;">'functions.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Services/Digg.php'</span><span style="color: #339933;">;</span>
Services_Digg<span style="color: #339933;">::</span><span style="color: #000088;">$appKey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.ja.meswilson.com/blog/Services_Digg_Proxy.php'</span><span style="color: #339933;">;</span>
Services_Digg<span style="color: #339933;">::</span><span style="color: #000088;">$uri</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://services.digg.com'</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'count'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$request</span> <span style="color: #339933;">=</span> Services_Digg<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Stories'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">popular</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//print_r($request);</span>
<span style="color: #666666; font-style: italic;">//exit;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">stories</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$story</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000088;">$userinfo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT `user_id`, `profileviews` FROM `diggusers` WHERE `username` = '&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' LIMIT 1&quot;</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: #990000;">mysql_numrows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$userinfo</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO `diggusers`
			( `user_id` , `username`, `icon`, `registered`, `profileviews` )
			VALUES ( 
				NULL, 
				'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;', 
				'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">icon</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;', 
				'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registered</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
				'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">profileviews</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'
			) &quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Inserting user: &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_error</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: #000088;">$user_id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_insert_id</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;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$user_id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$userinfo</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;user_id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO `diggstories` ( 
	`digg_id`, `title`, `description`, `diggs`, `comments`, `id`, `link`, `submitted`, `promoted`, `href`, `status`, 
		`user_id` , `username`, `icon`, `registered`, `profileviews`, `topic_long`, `topic_short`, `container_long`, `container_short`, `host`
	)
	VALUES (
		NULL, 
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;', 
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;', 
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">diggs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comments</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;', 
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">submit_date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">promote_date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">href</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">status</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">icon</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registered</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">profileviews</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">topic</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">topic</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">short_name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">container</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">container</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">short_name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
		'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span>host<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'
	) &quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE `diggstories` 
		SET `diggs` = '&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">diggs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;', `comments` = '&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comments</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'
		WHERE `id` = '&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' 
		LIMIT 1
		&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</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: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</div>
<p>In order to not refresh or have a cron job (though if you plan on using this more, a cron job would be good), you can just run <b>crondigg.py</b>, or crondigg.pyw if you don&#039;t want to see a window, to keep the database updated. You will need to edit value for url to point to the location of your update.php.</p>
<p><b>crondigg.py</b></p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#! /usr/bin/env python</span>
&nbsp;
url = <span style="color: #483d8b;">'http://localhost/digg/update.php'</span>
wait = <span style="color: #ff4500;">300</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span>,<span style="color: #dc143c;">time</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff4500;">1</span>:
	<span style="color: #ff7700;font-weight:bold;">try</span>:
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Requesting %s <span style="color: #000099; font-weight: bold;">\r</span>'</span> <span style="color: #66cc66;">%</span> url,
		<span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot; &quot;</span> <span style="color: #66cc66;">*</span> <span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>+<span style="color: #ff4500;">12</span><span style="color: black;">&#41;</span>,<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\r</span>'</span>,
		count = <span style="color: #ff4500;">0</span>
		<span style="color: #ff7700;font-weight:bold;">while</span> count <span style="color: #66cc66;">&lt;</span> wait:
			<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Waiting %d seconds <span style="color: #000099; font-weight: bold;">\r</span>'</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>wait-count<span style="color: black;">&#41;</span>,
			count+=<span style="color: #ff4500;">1</span>
			<span style="color: #dc143c;">time</span>.<span style="color: black;">sleep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
	<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">KeyboardInterrupt</span>:
		<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
		<span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span></pre></div></div>

</div>
<p>Note: This python script was written on Windows, where it works fine. On linux however, it&#039;s a different story. It still works, just the output doesn&#039;t.</p>
<h3>Gettings diggs</h3>
<p>Next, we&#039;re going to get individual diggs. We&#039;re not going to go back in time and get as many diggs as possible. The database will get really big pretty quickly, so don&#039;t worry about it. </p>
<p><b>updatediggs.php</b>:</p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
&nbsp;
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user_agent'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Trendds/1.0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'max_execution_time'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'config.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">include</span> <span style="color: #0000ff;">'functions.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Services/Digg.php'</span><span style="color: #339933;">;</span>
Services_Digg<span style="color: #339933;">::</span><span style="color: #000088;">$appKey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.ja.meswilson.com/blog/Services_Digg_Proxy.php'</span><span style="color: #339933;">;</span>
Services_Digg<span style="color: #339933;">::</span><span style="color: #000088;">$uri</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://services.digg.com'</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000088;">$api</span> <span style="color: #339933;">=</span> Services_Digg<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Stories'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// To keep track of the current timestamp. This could just be mysql_result(mysql_query(&quot;SELECT `time` FROM `diggslive` ORDER BY `time` DESC LIMIT 1&quot;),0,&quot;time&quot;)  but a txt file is easier.</span>
<span style="color: #666666; font-style: italic;">//$mindate = file_get_contents('lastdiggs.txt')-1;</span>
<span style="color: #000088;">$mindate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT `time` FROM `diggslive` ORDER BY `time` DESC LIMIT 1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;time&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//$mindate = time() - 3600;</span>
&nbsp;
<span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$total</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$runs</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get as many diggs as possible since the last update</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$offset</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$total</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'count'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'min_date'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$mindate</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'offset'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$offset</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$diggs</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$api</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">diggs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// Go through each digg</span>
	<span style="color: #666666; font-style: italic;">//print_r($diggs);</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$diggs</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">diggs</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$digg</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// This is pretty annoying. It's true if the insert failed. It might not be the most sensible thing, but it's about 2 in the morning, and I like it</span>
		<span style="color: #000088;">$inserted</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Insert the digg</span>
		<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO `diggslive` 
			(`digging_id`, `story_id`, `id`, `username`, `time`, `status`)
			VALUES (
				NULL,
				'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$digg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">story</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
				'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$digg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
				'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$digg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
				'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$digg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;',
				'&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$digg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">status</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'
			)&quot;</span><span style="color: #009900;">&#41;</span> or setcheck<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</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: #339933;">!</span><span style="color: #000088;">$inserted</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Increase the digg count of the story, since it just got dugg</span>
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE `diggstories` SET `diggs` = `diggs`+1 WHERE `id` = '&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$digg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' LIMIT 1&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</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: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">// If this is the first run, update the timestamp. We could use time(), but it might be slightly off. If we take the timestamp of a later run, it'll be later than what we got back.</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$runs</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> AND <span style="color: #000088;">$diggs</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timestamp</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$timestamp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$diggs</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timestamp</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$runs</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$total</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$diggs</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">total</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">print</span> <span style="color: #000088;">$offset</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$offset</span> <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// If the timestamp isn't foobared, update the file. If there are network problems or something, this can be wrong. I don't think I've still truely fixed that, but whatever.</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;">$timestamp</span><span style="color: #009900;">&#41;</span> AND <span style="color: #000088;">$timestamp</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span> AND <span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$timestamp</span><span style="color: #009900;">&#41;</span> AND <span style="color: #000088;">$timestamp</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1000000</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lastdiggs.txt'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #000088;">$timestamp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// This will change the variable to say if it inserted successfully or not, because doing ... or $inserted = true;   doesn't work. -_-</span>
<span style="color: #000000; font-weight: bold;">function</span> setcheck<span style="color: #009900;">&#40;</span><span style="color: #000088;">$bool</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$inserted</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$inserted</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bool</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</div>
<p>Before you can use this, you need to insert some digg or something into `diggslive` with `time` set to the current timestamp. After another digg gets inserted, you can get rid of this entry.</p>
<p>This just gets the diggs of all the stories since the last digg we got. The timestamp is one less than the time of the last digg. This is to make sure we got the diggs that occureed at the same second as the previous one.</p>
<p>This also edits a file called lastdigg.txt, which is just an alternative to the sql query.</p>
<p>As I said earlier, the table gets big. Mine was at around 330k entries before I started running deletes. Let&#039;s get rid of any diggs older than a day. We don&#039;t really need them.</p>
<p><b>removediggs.p</b>:</p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'config.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DELETE FROM `diggslive` WHERE `time` &lt; &quot;</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">24</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span>or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</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: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;OPTIMIZE TABLE `diggslive` &quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</div>
<p>To keep this updated, you can run <code>crondiggs.py</code>. This requests your updatediggs.php file every 30 seconds.</p>
<p><b>crondiggs.py</b></p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#! /usr/bin/env python</span>
&nbsp;
url = <span style="color: #483d8b;">'http://localhost/digg/updatediggs.php'</span>
url2 = <span style="color: #483d8b;">'http://localhost/digg/removediggs.php'</span>
wait = <span style="color: #ff4500;">30</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span>,<span style="color: #dc143c;">time</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff4500;">1</span>:
	<span style="color: #ff7700;font-weight:bold;">try</span>:
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Requesting %s <span style="color: #000099; font-weight: bold;">\r</span>'</span> <span style="color: #66cc66;">%</span> url,
		<span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">%</span> <span style="color: #ff4500;">10</span> == <span style="color: #ff4500;">0</span>:
			<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Requesting %s <span style="color: #000099; font-weight: bold;">\r</span>'</span> <span style="color: #66cc66;">%</span> url2,
			<span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>url2<span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot; &quot;</span> <span style="color: #66cc66;">*</span> <span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span>+<span style="color: #ff4500;">12</span><span style="color: black;">&#41;</span>,<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\r</span>'</span>,
		count = <span style="color: #ff4500;">0</span>
		<span style="color: #ff7700;font-weight:bold;">while</span> count <span style="color: #66cc66;">&lt;</span> wait:
			<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Waiting %d seconds <span style="color: #000099; font-weight: bold;">\r</span>'</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>wait-count<span style="color: black;">&#41;</span>,
			count+=<span style="color: #ff4500;">1</span>
			<span style="color: #dc143c;">time</span>.<span style="color: black;">sleep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
	<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">KeyboardInterrupt</span>:
		<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
		<span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span></pre></div></div>

</div>
<h2>Part Gamma: Tag Clouds</h2>
<p>Now it&#039;s time to use all this new fangled data we&#039;re collecting, and what&#039;s more Web 2.0 than tag clouds? And since we&#039;re lazy, we&#039;re going to use <a href="http://prism-perfect.net/archive/php-tag-cloud-tutorial/">this tag cloud script</a>.</p>
<p>First cloud set, the container cloud set. The containers are the main topics, like Technology, Science, Sports, etc. </p>
<p><a href='http://www.flickr.com/photos/71576576@N00/477500808/' title='concloud.png'><img src='http://farm1.static.flickr.com/223/477519828_7102f23596.jpg?v=0' alt='concloud.png' /></a></p>
<p><b>concloud.php</b>:</p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// most from: http://prism-perfect.net/archive/php-tag-cloud-tutorial/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// connect to database at some point</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// In the SQL below, change these three things:</span>
<span style="color: #666666; font-style: italic;">// thing is the column name that you are making a tag cloud for</span>
<span style="color: #666666; font-style: italic;">// id is the primary key</span>
<span style="color: #666666; font-style: italic;">// my_table is the name of the database table</span>
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'config.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT container_long AS tag, COUNT(digg_id) AS quantity, container_short
  FROM diggstories
  GROUP BY container_long
  ORDER BY container_long ASC&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// here we loop through the results and put them into a simple array:</span>
<span style="color: #666666; font-style: italic;">// $tag['thing1'] = 12;</span>
<span style="color: #666666; font-style: italic;">// $tag['thing2'] = 25;</span>
<span style="color: #666666; font-style: italic;">// etc. so we can use all the nifty array functions</span>
<span style="color: #666666; font-style: italic;">// to calculate the font-size of each tag</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$shortname</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'container_short'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'quantity'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// change these font sizes if you will</span>
<span style="color: #000088;">$max_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">250</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// max font size in %</span>
<span style="color: #000088;">$min_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// min font size in %</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// get the largest and smallest array values</span>
<span style="color: #000088;">$max_qty</span> <span style="color: #339933;">=</span> <span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$min_qty</span> <span style="color: #339933;">=</span> <span style="color: #990000;">min</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// find the range of values</span>
<span style="color: #000088;">$spread</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$max_qty</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_qty</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$spread</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// we don't want to divide by zero</span>
    <span style="color: #000088;">$spread</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// determine the font-size increment</span>
<span style="color: #666666; font-style: italic;">// this is the increase per tag quantity (times used)</span>
<span style="color: #000088;">$step</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$max_size</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_size</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$spread</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// loop through our tag array</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// calculate CSS font-size</span>
    <span style="color: #666666; font-style: italic;">// find the $value in excess of $min_qty</span>
    <span style="color: #666666; font-style: italic;">// multiply by the font-size increment ($size)</span>
    <span style="color: #666666; font-style: italic;">// and add the $min_size set above</span>
    <span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$min_size</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_qty</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$step</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// uncomment if you want sizes in whole %:</span>
    <span style="color: #666666; font-style: italic;">// $size = ceil($size);</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// you'll need to put the link destination in place of the #</span>
    <span style="color: #666666; font-style: italic;">// (assuming your tag links to some sort of details page)</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$shortname</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: #0000ff;">'&quot; style=&quot;font-size: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$size</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'%&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// perhaps adjust this title attribute for the things that are tagged</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">' title=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' things tagged with '</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt; '</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// notice the space at the end of the link</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</div>
<p>That&#039;s pretty boring though. Maybe regular categories, like Apple, Linux/Unix, Playable Web Games, etc, will be more interesting.</p>
<p><a href='http://www.flickr.com/photos/71576576@N00/477546015/' title='catcloud.png'><img src='http://farm1.static.flickr.com/203/477546015_76ffca6cfb.jpg?v=0' alt='catcloud.png' /></a></p>
<p><b>catcloud.php</b></p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// most from: http://prism-perfect.net/archive/php-tag-cloud-tutorial/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// connect to database at some point</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// In the SQL below, change these three things:</span>
<span style="color: #666666; font-style: italic;">// thing is the column name that you are making a tag cloud for</span>
<span style="color: #666666; font-style: italic;">// id is the primary key</span>
<span style="color: #666666; font-style: italic;">// my_table is the name of the database table</span>
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'config.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'functions.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT topic_long AS tag, COUNT(digg_id) AS quantity, topic_short
  FROM diggstories
  GROUP BY topic_long
  ORDER BY topic_long ASC&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// here we loop through the results and put them into a simple array:</span>
<span style="color: #666666; font-style: italic;">// $tag['thing1'] = 12;</span>
<span style="color: #666666; font-style: italic;">// $tag['thing2'] = 25;</span>
<span style="color: #666666; font-style: italic;">// etc. so we can use all the nifty array functions</span>
<span style="color: #666666; font-style: italic;">// to calculate the font-size of each tag</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$shortname</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'topic_short'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'quantity'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// change these font sizes if you will</span>
<span style="color: #000088;">$max_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">250</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// max font size in %</span>
<span style="color: #000088;">$min_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// min font size in %</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// get the largest and smallest array values</span>
<span style="color: #000088;">$max_qty</span> <span style="color: #339933;">=</span> <span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$min_qty</span> <span style="color: #339933;">=</span> <span style="color: #990000;">min</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// find the range of values</span>
<span style="color: #000088;">$spread</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$max_qty</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_qty</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$spread</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// we don't want to divide by zero</span>
    <span style="color: #000088;">$spread</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// determine the font-size increment</span>
<span style="color: #666666; font-style: italic;">// this is the increase per tag quantity (times used)</span>
<span style="color: #000088;">$step</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$max_size</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_size</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$spread</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// loop through our tag array</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// calculate CSS font-size</span>
    <span style="color: #666666; font-style: italic;">// find the $value in excess of $min_qty</span>
    <span style="color: #666666; font-style: italic;">// multiply by the font-size increment ($size)</span>
    <span style="color: #666666; font-style: italic;">// and add the $min_size set above</span>
    <span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$min_size</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_qty</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$step</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// uncomment if you want sizes in whole %:</span>
    <span style="color: #666666; font-style: italic;">// $size = ceil($size);</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// you'll need to put the link destination in place of the #</span>
    <span style="color: #666666; font-style: italic;">// (assuming your tag links to some sort of details page)</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;http://digg.com/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$shortname</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: #0000ff;">'&quot; style=&quot;font-size: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$size</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'%&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// perhaps adjust this title attribute for the things that are tagged</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">' title=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' things tagged with '</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt; '</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// notice the space at the end of the link</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</div>
<p>A little better. How about a user cloud based on submissions?</p>
<p><a href="http://www.flickr.com/photos/71576576@N00/477509156/"><img src="http://farm1.static.flickr.com/204/477509156_77ffab6a5a.jpg?v=0" alt="usercloud.png" /></a></p>
<p><b>usercloud.php</b>:</p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// most from: http://prism-perfect.net/archive/php-tag-cloud-tutorial/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// connect to database at some point</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// In the SQL below, change these three things:</span>
<span style="color: #666666; font-style: italic;">// thing is the column name that you are making a tag cloud for</span>
<span style="color: #666666; font-style: italic;">// id is the primary key</span>
<span style="color: #666666; font-style: italic;">// my_table is the name of the database table</span>
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'config.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT username AS tag, COUNT(digg_id) AS quantity
  FROM diggstories
  GROUP BY username
  ORDER BY username ASC&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// here we loop through the results and put them into a simple array:</span>
<span style="color: #666666; font-style: italic;">// $tag['thing1'] = 12;</span>
<span style="color: #666666; font-style: italic;">// $tag['thing2'] = 25;</span>
<span style="color: #666666; font-style: italic;">// etc. so we can use all the nifty array functions</span>
<span style="color: #666666; font-style: italic;">// to calculate the font-size of each tag</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//$shortname[$row['tag']] = $row['container_short'];</span>
    <span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'quantity'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// change these font sizes if you will</span>
<span style="color: #000088;">$max_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">250</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// max font size in %</span>
<span style="color: #000088;">$min_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// min font size in %</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// get the largest and smallest array values</span>
<span style="color: #000088;">$max_qty</span> <span style="color: #339933;">=</span> <span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$min_qty</span> <span style="color: #339933;">=</span> <span style="color: #990000;">min</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// find the range of values</span>
<span style="color: #000088;">$spread</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$max_qty</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_qty</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$spread</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// we don't want to divide by zero</span>
    <span style="color: #000088;">$spread</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// determine the font-size increment</span>
<span style="color: #666666; font-style: italic;">// this is the increase per tag quantity (times used)</span>
<span style="color: #000088;">$step</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$max_size</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_size</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$spread</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// loop through our tag array</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// calculate CSS font-size</span>
    <span style="color: #666666; font-style: italic;">// find the $value in excess of $min_qty</span>
    <span style="color: #666666; font-style: italic;">// multiply by the font-size increment ($size)</span>
    <span style="color: #666666; font-style: italic;">// and add the $min_size set above</span>
    <span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$min_size</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_qty</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$step</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// uncomment if you want sizes in whole %:</span>
    <span style="color: #666666; font-style: italic;">// $size = ceil($size);</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// you'll need to put the link destination in place of the #</span>
    <span style="color: #666666; font-style: italic;">// (assuming your tag links to some sort of details page)</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;http://digg.com/users/'</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; style=&quot;font-size: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$size</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'%&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// perhaps adjust this title attribute for the things that are tagged</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">' title=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' things tagged with '</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt; '</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// notice the space at the end of the link</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</div>
<p>Pretty big, but let&#039;s try bigger. A user cloud based on number of diggs.</p>
<p><a href="http://www.flickr.com/photos/71576576@N00/477500812/"><img src="http://farm1.static.flickr.com/232/477500812_75d352ced2.jpg?v=0" alt="diggusercloud.png" /></a></p>
<p><b>diggusercloud.php</b>:</p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// most from: http://prism-perfect.net/archive/php-tag-cloud-tutorial/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// connect to database at some point</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// In the SQL below, change these three things:</span>
<span style="color: #666666; font-style: italic;">// thing is the column name that you are making a tag cloud for</span>
<span style="color: #666666; font-style: italic;">// id is the primary key</span>
<span style="color: #666666; font-style: italic;">// my_table is the name of the database table</span>
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'config.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT username AS tag, COUNT(digging_id) AS quantity
  FROM diggslive
  GROUP BY username
  ORDER BY username ASC&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// here we loop through the results and put them into a simple array:</span>
<span style="color: #666666; font-style: italic;">// $tag['thing1'] = 12;</span>
<span style="color: #666666; font-style: italic;">// $tag['thing2'] = 25;</span>
<span style="color: #666666; font-style: italic;">// etc. so we can use all the nifty array functions</span>
<span style="color: #666666; font-style: italic;">// to calculate the font-size of each tag</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$href</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'href'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'quantity'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// change these font sizes if you will</span>
<span style="color: #000088;">$max_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">250</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// max font size in %</span>
<span style="color: #000088;">$min_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// min font size in %</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// get the largest and smallest array values</span>
<span style="color: #000088;">$max_qty</span> <span style="color: #339933;">=</span> <span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$min_qty</span> <span style="color: #339933;">=</span> <span style="color: #990000;">min</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// find the range of values</span>
<span style="color: #000088;">$spread</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$max_qty</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_qty</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$spread</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// we don't want to divide by zero</span>
    <span style="color: #000088;">$spread</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// determine the font-size increment</span>
<span style="color: #666666; font-style: italic;">// this is the increase per tag quantity (times used)</span>
<span style="color: #000088;">$step</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$max_size</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_size</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$spread</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// loop through our tag array</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// calculate CSS font-size</span>
    <span style="color: #666666; font-style: italic;">// find the $value in excess of $min_qty</span>
    <span style="color: #666666; font-style: italic;">// multiply by the font-size increment ($size)</span>
    <span style="color: #666666; font-style: italic;">// and add the $min_size set above</span>
    <span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$min_size</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_qty</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$step</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// uncomment if you want sizes in whole %:</span>
    <span style="color: #666666; font-style: italic;">// $size = ceil($size);</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// you'll need to put the link destination in place of the #</span>
    <span style="color: #666666; font-style: italic;">// (assuming your tag links to some sort of details page)</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;http://digg.com/users/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; style=&quot;font-size: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$size</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'%&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// perhaps adjust this title attribute for the things that are tagged</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">' title=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' things tagged with '</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt; '</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// notice the space at the end of the link</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</div>
<p>Great. How about a story cloud based on the number of diggs?</p>
<p><a href="http://www.flickr.com/photos/71576576@N00/477554527/"><img src="http://farm1.static.flickr.com/206/477554527_b7c09b864d.jpg?v=0" alt="diggcloud.png" /></a></p>
<p><b>diggcloud.php</b>:</p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// most from: http://prism-perfect.net/archive/php-tag-cloud-tutorial/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// connect to database at some point</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// In the SQL below, change these three things:</span>
<span style="color: #666666; font-style: italic;">// thing is the column name that you are making a tag cloud for</span>
<span style="color: #666666; font-style: italic;">// id is the primary key</span>
<span style="color: #666666; font-style: italic;">// my_table is the name of the database table</span>
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'config.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT title AS tag, COUNT(digg_id) AS quantity, href
  FROM diggstories
  GROUP BY diggs
  ORDER BY diggs ASC&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// here we loop through the results and put them into a simple array:</span>
<span style="color: #666666; font-style: italic;">// $tag['thing1'] = 12;</span>
<span style="color: #666666; font-style: italic;">// $tag['thing2'] = 25;</span>
<span style="color: #666666; font-style: italic;">// etc. so we can use all the nifty array functions</span>
<span style="color: #666666; font-style: italic;">// to calculate the font-size of each tag</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$href</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'href'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'quantity'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// change these font sizes if you will</span>
<span style="color: #000088;">$max_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">250</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// max font size in %</span>
<span style="color: #000088;">$min_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// min font size in %</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// get the largest and smallest array values</span>
<span style="color: #000088;">$max_qty</span> <span style="color: #339933;">=</span> <span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$min_qty</span> <span style="color: #339933;">=</span> <span style="color: #990000;">min</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// find the range of values</span>
<span style="color: #000088;">$spread</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$max_qty</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_qty</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$spread</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// we don't want to divide by zero</span>
    <span style="color: #000088;">$spread</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// determine the font-size increment</span>
<span style="color: #666666; font-style: italic;">// this is the increase per tag quantity (times used)</span>
<span style="color: #000088;">$step</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$max_size</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_size</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$spread</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// loop through our tag array</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// calculate CSS font-size</span>
    <span style="color: #666666; font-style: italic;">// find the $value in excess of $min_qty</span>
    <span style="color: #666666; font-style: italic;">// multiply by the font-size increment ($size)</span>
    <span style="color: #666666; font-style: italic;">// and add the $min_size set above</span>
    <span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$min_size</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_qty</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$step</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// uncomment if you want sizes in whole %:</span>
    <span style="color: #666666; font-style: italic;">// $size = ceil($size);</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// you'll need to put the link destination in place of the #</span>
    <span style="color: #666666; font-style: italic;">// (assuming your tag links to some sort of details page)</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$href</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: #0000ff;">'&quot; style=&quot;font-size: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$size</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'%&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// perhaps adjust this title attribute for the things that are tagged</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">' title=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' things tagged with '</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt; '</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// notice the space at the end of the link</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</div>
<p>But wait, that doesn&#039;t look right. That&#039;s because we can&#039;t use basically the same SQL query as before. It&#039;s grouping the stories by the amount of diggs, so that if there are 3 stories with 750 diggs, and only 1 story with 751 diggs, the 3 stories will be larger. Since the weight of the story is already set as an entry, we don&#039;t need to group it, so we can just use this SQL query:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> title <span style="color: #990099; font-weight: bold;">AS</span> tag<span style="color: #000033;">,</span> diggs<span style="color: #000033;">,</span> href
  <span style="color: #990099; font-weight: bold;">FROM</span> diggstories
  <span style="color: #990099; font-weight: bold;">ORDER BY</span> title <span style="color: #990099; font-weight: bold;">ASC</span></pre></div></div>

<p><a href="http://www.flickr.com/photos/71576576@N00/477500830/"><img src="http://farm1.static.flickr.com/205/477500830_e17fdc07f5.jpg?v=0" alt="realdiggcloud.png" /></a></p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// most from: http://prism-perfect.net/archive/php-tag-cloud-tutorial/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// connect to database at some point</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// In the SQL below, change these three things:</span>
<span style="color: #666666; font-style: italic;">// thing is the column name that you are making a tag cloud for</span>
<span style="color: #666666; font-style: italic;">// id is the primary key</span>
<span style="color: #666666; font-style: italic;">// my_table is the name of the database table</span>
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'config.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT title AS tag, diggs, href
  FROM diggstories
  ORDER BY title ASC&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// here we loop through the results and put them into a simple array:</span>
<span style="color: #666666; font-style: italic;">// $tag['thing1'] = 12;</span>
<span style="color: #666666; font-style: italic;">// $tag['thing2'] = 25;</span>
<span style="color: #666666; font-style: italic;">// etc. so we can use all the nifty array functions</span>
<span style="color: #666666; font-style: italic;">// to calculate the font-size of each tag</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$href</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'href'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'diggs'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// change these font sizes if you will</span>
<span style="color: #000088;">$max_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">250</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// max font size in %</span>
<span style="color: #000088;">$min_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// min font size in %</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// get the largest and smallest array values</span>
<span style="color: #000088;">$max_qty</span> <span style="color: #339933;">=</span> <span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$min_qty</span> <span style="color: #339933;">=</span> <span style="color: #990000;">min</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// find the range of values</span>
<span style="color: #000088;">$spread</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$max_qty</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_qty</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$spread</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// we don't want to divide by zero</span>
    <span style="color: #000088;">$spread</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// determine the font-size increment</span>
<span style="color: #666666; font-style: italic;">// this is the increase per tag quantity (times used)</span>
<span style="color: #000088;">$step</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$max_size</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_size</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$spread</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// loop through our tag array</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// calculate CSS font-size</span>
    <span style="color: #666666; font-style: italic;">// find the $value in excess of $min_qty</span>
    <span style="color: #666666; font-style: italic;">// multiply by the font-size increment ($size)</span>
    <span style="color: #666666; font-style: italic;">// and add the $min_size set above</span>
    <span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$min_size</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_qty</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$step</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// uncomment if you want sizes in whole %:</span>
    <span style="color: #666666; font-style: italic;">// $size = ceil($size);</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// you'll need to put the link destination in place of the #</span>
    <span style="color: #666666; font-style: italic;">// (assuming your tag links to some sort of details page)</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$href</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: #0000ff;">'&quot; style=&quot;font-size: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$size</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'%&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// perhaps adjust this title attribute for the things that are tagged</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">' title=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' things tagged with '</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt; '</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// notice the space at the end of the link</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</div>
<p>If you noticed in insert.php and update.php, we had an entry called &#039;host&#039;. This is equal to whatever the hostname of the link. Let&#039;s make a host cloud based on the amount of stories.</p>
<p><a href="http://www.flickr.com/photos/71576576@N00/477500818/"><img src="http://farm1.static.flickr.com/228/477500818_1f8d4eb037.jpg?v=0" alt="hostcloud.png" /></a></p>
<p><b>hostcloud.php</b>:</p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// most from: http://prism-perfect.net/archive/php-tag-cloud-tutorial/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// connect to database at some point</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// In the SQL below, change these three things:</span>
<span style="color: #666666; font-style: italic;">// thing is the column name that you are making a tag cloud for</span>
<span style="color: #666666; font-style: italic;">// id is the primary key</span>
<span style="color: #666666; font-style: italic;">// my_table is the name of the database table</span>
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'config.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT host AS tag, COUNT(digg_id) AS quantity
  FROM diggstories
  GROUP BY host
  ORDER BY host ASC&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// here we loop through the results and put them into a simple array:</span>
<span style="color: #666666; font-style: italic;">// $tag['thing1'] = 12;</span>
<span style="color: #666666; font-style: italic;">// $tag['thing2'] = 25;</span>
<span style="color: #666666; font-style: italic;">// etc. so we can use all the nifty array functions</span>
<span style="color: #666666; font-style: italic;">// to calculate the font-size of each tag</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$href</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'href'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'quantity'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// change these font sizes if you will</span>
<span style="color: #000088;">$max_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">250</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// max font size in %</span>
<span style="color: #000088;">$min_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// min font size in %</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// get the largest and smallest array values</span>
<span style="color: #000088;">$max_qty</span> <span style="color: #339933;">=</span> <span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$min_qty</span> <span style="color: #339933;">=</span> <span style="color: #990000;">min</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// find the range of values</span>
<span style="color: #000088;">$spread</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$max_qty</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_qty</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$spread</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// we don't want to divide by zero</span>
    <span style="color: #000088;">$spread</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// determine the font-size increment</span>
<span style="color: #666666; font-style: italic;">// this is the increase per tag quantity (times used)</span>
<span style="color: #000088;">$step</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$max_size</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_size</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$spread</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// loop through our tag array</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// calculate CSS font-size</span>
    <span style="color: #666666; font-style: italic;">// find the $value in excess of $min_qty</span>
    <span style="color: #666666; font-style: italic;">// multiply by the font-size increment ($size)</span>
    <span style="color: #666666; font-style: italic;">// and add the $min_size set above</span>
    <span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$min_size</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_qty</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$step</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// uncomment if you want sizes in whole %:</span>
    <span style="color: #666666; font-style: italic;">// $size = ceil($size);</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// you'll need to put the link destination in place of the #</span>
    <span style="color: #666666; font-style: italic;">// (assuming your tag links to some sort of details page)</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;search.php?links='</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; style=&quot;font-size: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$size</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'%&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// perhaps adjust this title attribute for the things that are tagged</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">' title=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' things tagged with '</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt; '</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// notice the space at the end of the link</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</div>
<p>Where to go: Tag clouds are fun. You can easily set it to only show a certain time period, like the past day or week, or you could use both the diggstories and diggslive tables to see what people are digging. You could also combine it with the search that we&#039;ll talk about next.</p>
<h2>Part Dogma &#8211; Improved Search</h2>
<p>As I said earlier, the `diggstories` table has 4 FULLTEXT indecies, so let&#039;s use those to create a better search. It&#039;s not necessarily all that better than the current one, and won&#039;t search upcoming stories, but to some, it might be better.</p>
<p>This will allow you to search using multiple queries, like let&#039;s say you want to find all of the stories dealing nintendo from arstechnica.com. This search can easily handle that.</p>
<p>It uses <a href="http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html">MySQL FULLTEXT search</a> to handle it. This has the basic format of <code> WHERE MATCH(`columns`) AGAINST ('query')</code> and will return the results based on the relevance.</p>
<p><a href="http://xrho.com/digg/search.php">Better Search</a></p>
<p><a href="http://flickr.com/photos/71576576@N00/477597214/"><img src="http://farm1.static.flickr.com/211/477597214_c29fc1d53c.jpg?v=0" alt="search1.png" /></a></p>
<p><a href="http://flickr.com/photos/71576576@N00/477597218/"><img src="http://farm1.static.flickr.com/170/477597218_f7c310739b.jpg?v=0" alt="search2.png" /></a></p>
<p><b>search.php</b>:</p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</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> AND <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> AND <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'desc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> AND <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'links'</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: #000000; font-weight: bold;">?&gt;</span>
&lt;form action=&quot;search.php&quot; method=&quot;get&quot;&gt;
Search title and desc: &lt;input type=&quot;text&quot; name=&quot;q&quot; /&gt;&lt;br /&gt;&lt;br /&gt;
&lt;b&gt;OR&lt;/b&gt;
&lt;br /&gt;&lt;br /&gt;
Search in title: &lt;input type=&quot;text&quot; name=&quot;title&quot; /&gt;&lt;br /&gt;
Search in desc: &lt;input type=&quot;text&quot; name=&quot;desc&quot; /&gt;&lt;br /&gt;
Search in links: &lt;input type=&quot;text&quot; name=&quot;links&quot; /&gt;&lt;br /&gt;&lt;br /&gt;
&nbsp;
&lt;br /&gt;
&lt;input type=&quot;submit&quot; value=&quot;Search&quot; /&gt;
&nbsp;
&lt;/form&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'config.php'</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'functions.php'</span><span style="color: #339933;">;</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;">$_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> AND <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: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$where</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot; MATCH (`title`, `description`) AGAINST ('&quot;</span><span style="color: #339933;">.</span>sqlquote<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;">&quot;') &quot;</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;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> AND <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$where</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot; MATCH (`title`) AGAINST ('&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;') &quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</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;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'desc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> AND <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'desc'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$where</span> <span style="color: #339933;">.=</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$where</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;AND&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; MATCH (`description`) AGAINST ('&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'desc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;') &quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</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;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'links'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> AND <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'links'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$where</span> <span style="color: #339933;">.=</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$where</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;AND&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; MATCH (`link`) AGAINST ('&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'links'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;') &quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT `title`, `description`, `diggs`, `comments`, `link`, `href` 
		FROM `diggstories` 
		WHERE <span style="color: #006699; font-weight: bold;">$where</span>&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$num</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_numrows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;No results found&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;table align=&quot;</span>center<span style="color: #0000ff;">&quot;&gt;
	&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Story&lt;/th&gt;&lt;th&gt;Diggs&lt;/th&gt;&lt;th&gt;Comments&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$num</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td&gt;&lt;a href=&quot;</span><span style="color: #0000ff;">&quot;.dehtml(mysql_result(<span style="color: #006699; font-weight: bold;">$result</span>,<span style="color: #006699; font-weight: bold;">$i</span>,&quot;</span><span style="color: #990000;">link</span><span style="color: #0000ff;">&quot;)).&quot;</span><span style="color: #0000ff;">&quot; title=&quot;</span><span style="color: #0000ff;">&quot;.dehtml(mysql_result(<span style="color: #006699; font-weight: bold;">$result</span>,<span style="color: #006699; font-weight: bold;">$i</span>,&quot;</span>description<span style="color: #0000ff;">&quot;)).&quot;</span><span style="color: #0000ff;">&quot;&gt;&quot;</span><span style="color: #339933;">.</span>dehtml<span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/a&gt; [&lt;a href=&quot;</span><span style="color: #0000ff;">&quot;.dehtml(mysql_result(<span style="color: #006699; font-weight: bold;">$result</span>,<span style="color: #006699; font-weight: bold;">$i</span>,&quot;</span>href<span style="color: #0000ff;">&quot;)).&quot;</span><span style="color: #0000ff;">&quot;&gt;More&lt;/a&gt;]&lt;/td&gt;
		&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;diggs&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;
		&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;comments&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;
		&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/table&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;span style=&quot;</span>float<span style="color: #339933;">:</span>right<span style="color: #339933;">;</span><span style="color: #0000ff;">&quot;&gt;<span style="color: #006699; font-weight: bold;">$num</span> results&lt;/span&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

</div>
<p>Where to go: There are a lot of things that can be done to improve this. Maybe add a fetaure to only return stories with over a certain amount of diggs or comments, or that were submitted between certain dates</p>
<h2>Part Alien &#8211; Reggit/Dreddit &#8211; Reddit clone</h2>
<h3>Homepage</h3>
<p>Everyone loves the clean, sexy layout of <a href="http://reddit.com">reddit</a>, so let&#039;s take Digg&#039;s data and throw it into a reddit layout.</p>
<p>Pretty easy to make. Just copy their page layout and CSS, and throw the digg story information in there. I removed the header and footer from it, since none will really work, and we don&#039;t have some badass logo. It&#039;s just sorted by promoted time, and not popularity, though it could probably be modded to take account that.</p>
<p><a href="http://www.flickr.com/photos/71576576@N00/477500814/"><img src="http://farm1.static.flickr.com/214/477500814_c821a61d39.jpg?v=0" alt="reddit-digg ss" /></a></p>
<p><b><a href="http://xrho.com/digg/reddit.php">Reddit Clone</a></b></p>
<p><b>reddit.php</b></p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'config.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'functions.php'</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /&gt;
&lt;title&gt;digg + reddit = reggit... or dreddit&lt;/title&gt;
&lt;script src=&quot;http://reddit.com/static/psrs.js&quot; language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;http://reddit.com/static/reddit.js&quot; language=&quot;javascript&quot; type='text/javascript'&gt;&lt;/script&gt;
&lt;link rel='stylesheet' href='http://reddit.com/static/styles.css' type='text/css' /&gt;
&lt;link rel='shortcut icon' href='http://reddit.com/favicon.ico' type=&quot;image/x-icon&quot; /&gt;
&lt;script language='javascript'&gt;
    var a = new Image();
    a.src =&quot;http://static.reddit.com/aupmod.png&quot;;
    var b = new Image();
    b.src = &quot;http://static.reddit.com/adownmod.png&quot;;
&nbsp;
&lt;/script&gt;
&nbsp;
&lt;/head&gt;
&lt;body&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'offset'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> AND <span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'offset'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'offset'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT `title`, `diggs`, `comments`, `link`, `href`, `host`, `id`, `username`, `submitted`
	FROM `diggstories`
&nbsp;
	ORDER BY `promoted` DESC
	LIMIT <span style="color: #006699; font-weight: bold;">$offset</span>, 25&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$num</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_numrows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div id='main'&gt;
        &lt;table id=&quot;siteTable&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$num</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;tr id=&quot;</span>story<span style="color: #0000ff;">&quot;.mysql_result(<span style="color: #006699; font-weight: bold;">$result</span>,<span style="color: #006699; font-weight: bold;">$i</span>,&quot;</span>id<span style="color: #0000ff;">&quot;).&quot;</span><span style="color: #0000ff;">&quot;&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;&lt;td colspan=&quot;</span><span style="color: #cc66cc;">1</span><span style="color: #0000ff;">&quot; class=&quot;</span>evenRow spacing top<span style="color: #0000ff;">&quot;&gt;&lt;/td&gt;
    &lt;td colspan=&quot;</span><span style="color: #cc66cc;">4</span><span style="color: #0000ff;">&quot; class=&quot;</span>evenRow spacing top<span style="color: #0000ff;">&quot;&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;tr class=&quot;</span>evenRow<span style="color: #0000ff;">&quot;&gt;&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&lt;td colspan=&quot;</span><span style="color: #cc66cc;">1</span><span style="color: #0000ff;">&quot; class=&quot;</span>oddRow spacing top<span style="color: #0000ff;">&quot;&gt;&lt;/td&gt;
    &lt;td colspan=&quot;</span><span style="color: #cc66cc;">4</span><span style="color: #0000ff;">&quot; class=&quot;</span>oddRow spacing top<span style="color: #0000ff;">&quot;&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;tr class=&quot;</span>oddRow<span style="color: #0000ff;">&quot;&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;td valign=&quot;</span>top<span style="color: #0000ff;">&quot; class=&quot;</span>numbercol<span style="color: #0000ff;">&quot; rowspan=&quot;</span><span style="color: #cc66cc;">3</span><span style="color: #0000ff;">&quot;&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #000088;">$offset</span><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: #0000ff;">&quot;.&lt;/td&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span>  <span style="color: #0000ff;">&quot;&lt;td valign=&quot;</span>top<span style="color: #0000ff;">&quot; rowspan=&quot;</span><span style="color: #cc66cc;">3</span><span style="color: #0000ff;">&quot;&gt;
        &lt;div id=&quot;</span>up<span style="color: #0000ff;">&quot;.mysql_result(<span style="color: #006699; font-weight: bold;">$result</span>,<span style="color: #006699; font-weight: bold;">$i</span>,&quot;</span>id<span style="color: #0000ff;">&quot;).&quot;</span><span style="color: #0000ff;">&quot; class=&quot;</span>arrow up<span style="color: #0000ff;">&quot; onclick=&quot;</span>javascript<span style="color: #339933;">:</span>mod<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.mysql_result(<span style="color: #006699; font-weight: bold;">$result</span>,<span style="color: #006699; font-weight: bold;">$i</span>,&quot;</span>id<span style="color: #0000ff;">&quot;).&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #0000ff;">&quot;&gt; &lt;/div&gt;
        &lt;div id=&quot;</span>down<span style="color: #0000ff;">&quot;.mysql_result(<span style="color: #006699; font-weight: bold;">$result</span>,<span style="color: #006699; font-weight: bold;">$i</span>,&quot;</span>id<span style="color: #0000ff;">&quot;).&quot;</span><span style="color: #0000ff;">&quot; class=&quot;</span>arrow down<span style="color: #0000ff;">&quot; onclick=&quot;</span>javascript<span style="color: #339933;">:</span>mod<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.mysql_result(<span style="color: #006699; font-weight: bold;">$result</span>,<span style="color: #006699; font-weight: bold;">$i</span>,&quot;</span>id<span style="color: #0000ff;">&quot;).&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #0000ff;">&quot;/&gt;
    &lt;/td&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; &lt;td colspan=&quot;</span><span style="color: #cc66cc;">3</span><span style="color: #0000ff;">&quot; id=&quot;</span>titlerow<span style="color: #0000ff;">&quot;.mysql_result(<span style="color: #006699; font-weight: bold;">$result</span>,<span style="color: #006699; font-weight: bold;">$i</span>,&quot;</span>id<span style="color: #0000ff;">&quot;).&quot;</span><span style="color: #0000ff;">&quot;&gt;
        &lt;a id=&quot;</span>title<span style="color: #0000ff;">&quot;.mysql_result(<span style="color: #006699; font-weight: bold;">$result</span>,<span style="color: #006699; font-weight: bold;">$i</span>,&quot;</span>id<span style="color: #0000ff;">&quot;).&quot;</span><span style="color: #0000ff;">&quot; class=&quot;</span>title<span style="color: #0000ff;">&quot; href=&quot;</span><span style="color: #0000ff;">&quot;.dehtml(mysql_result(<span style="color: #006699; font-weight: bold;">$result</span>,<span style="color: #006699; font-weight: bold;">$i</span>,&quot;</span><span style="color: #990000;">link</span><span style="color: #0000ff;">&quot;)).&quot;</span><span style="color: #0000ff;">&quot;                                   &gt;          &quot;</span><span style="color: #339933;">.</span>dehtml<span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/a&gt;
&nbsp;
        &lt;span class=&quot;</span>little<span style="color: #0000ff;">&quot;&gt; (&quot;</span><span style="color: #339933;">.</span>dehtml<span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;host&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&lt;/span&gt; 
    &lt;/td&gt;
&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;&lt;tr class=&quot;</span>evenRow<span style="color: #0000ff;">&quot;&gt;&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&lt;tr class=&quot;</span>oddRow<span style="color: #0000ff;">&quot;&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;td valign=&quot;</span>top<span style="color: #0000ff;">&quot; class=&quot;</span>wide little<span style="color: #0000ff;">&quot; colspan=&quot;</span><span style="color: #cc66cc;">3</span><span style="color: #0000ff;">&quot;&gt;
&nbsp;
&lt;span id=&quot;</span>score<span style="color: #0000ff;">&quot;.mysql_result(<span style="color: #006699; font-weight: bold;">$result</span>,<span style="color: #006699; font-weight: bold;">$i</span>,&quot;</span>id<span style="color: #0000ff;">&quot;).&quot;</span><span style="color: #0000ff;">&quot;&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;diggs&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; diggs&lt;/span&gt;
posted &quot;</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;submitted&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;   hours ago by &lt;a href=&quot;</span>http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//digg.com/user/&quot;.mysql_result($result,$i,&quot;username&quot;).&quot;&quot;&gt;&quot;.mysql_result($result,$i,&quot;username&quot;).&quot; &lt;/a&gt;</span>
    <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;bylink&quot;</span>          <span style="color: #339933;">&gt;</span>         <span style="color: #0000ff;">&quot;.mysql_result(<span style="color: #006699; font-weight: bold;">$result</span>,<span style="color: #006699; font-weight: bold;">$i</span>,&quot;</span>comments<span style="color: #0000ff;">&quot;).&quot;</span> comments     <span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span><span style="color: #0000ff;">&quot;;
	echo &quot;</span><span style="color: #339933;">&lt;</span>tr <span style="color: #339933;">&gt;&lt;</span>td colspan<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;3&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;evenRow&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;oddRow&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; spacing&quot;</span><span style="color: #339933;">&gt;&lt;/</span>td<span style="color: #339933;">&gt;&lt;/</span>tr<span style="color: #339933;">&gt;</span><span style="color: #0000ff;">&quot;;
}
?&gt;</span>
    &lt;/table&gt;
        &lt;p class=&quot;menu&quot;&gt; view more:
&nbsp;
&nbsp;
         &lt;a href=&quot;reddit.php?offset=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$offset</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">25</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;next Ã‚Â»&lt;/a&gt;
        &lt;/p&gt;
&nbsp;
&lt;/div&gt;
&nbsp;
&lt;/body&gt;&lt;/html&gt;</pre></div></div>

</div>
<p>Where to go: Subreddits, like technology.redditclone to only show the stories from the container &#039;Technology&#039;, or apple.redditclone or apple.technology.redditclone to only show stories from the topic &#039;Apple&#039;. Sort by popularity or &#034;hotness&#034;, like reddit&#039;s homepage. Maybe something like <code>ORDER BY `diggs` / (".time()." - `promoted`)</code>, but better.</p>
<h3>RSS</h3>
<p>Another great part of reddit is their <a href="http://reddit.com/.rss">RSS feed</a>. No fluff, no mess, just links, so let&#039;s rid that off too. This is also really easy to make. If you&#039;ve ever had to make an RSS feed from a DB, you&#039;ll have no trouble.</p>
<p>The RSS feed consists of a title that links directly to the article, with the content having links [link] which goes to the article, [more] which goes to the Digg page, and a [dugg] links which goes to the Duggmirror link.</p>
<p><a href="http://www.flickr.com/photos/71576576@N00/477509154/"><img src="http://farm1.static.flickr.com/182/477509154_beeb3f35a0.jpg?v=0" alt="reddit digg rss" /></a></p>
<p><b><a href="http://feeds.feedburner.com/dreddit">Reddit / Better RSS Feed</a></b></p>
<p><b>redditrss.php</b>:</p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'config.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'functions.php'</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000088;">$stories</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT `title`, `href`, `link`,`promoted` FROM `diggstories` ORDER BY `promoted` DESC LIMIT 0, 40&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
rss_start<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_numrows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stories</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$count</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$count</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	rss_row<span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stories</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stories</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stories</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;link&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stories</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;promoted&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
rss_stop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> rss_start<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: text/xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;?xml version=&quot;</span><span style="color:#800080;">1.0</span><span style="color: #0000ff;">&quot;?&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;rss version=&quot;2.0&quot; xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot;&gt;&lt;channel&gt;
        &lt;title&gt;reggit/dreddit: what's new on digg&lt;/title&gt;
        &lt;link&gt;http://digg.com/&lt;/link&gt;
        &lt;description&gt;The latest stories, voted on by users like you.&lt;/description&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> rss_stop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/channel&gt;&lt;/rss&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> rss_row<span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #339933;">,</span><span style="color: #000088;">$href</span><span style="color: #339933;">,</span><span style="color: #000088;">$link</span><span style="color: #339933;">,</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>&lt;item&gt;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&lt;title&gt;&quot;</span><span style="color: #339933;">.</span>dehtml<span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/title&gt;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&lt;link&gt;&quot;</span><span style="color: #339933;">.</span>dehtml<span style="color: #009900;">&#40;</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/link&gt;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&lt;dc:date&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">gmdate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;T&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/dc:date&gt;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>
	<span style="color: #000099; font-weight: bold;">\t</span>&lt;description&gt;&lt;![CDATA[&lt;a href=&quot;</span><span style="color: #0000ff;">&quot;.dehtml(<span style="color: #006699; font-weight: bold;">$link</span>).&quot;</span><span style="color: #0000ff;">&quot;&gt;[link]&lt;/a&gt; &lt;a href=&quot;</span><span style="color: #000088;">$href</span><span style="color: #0000ff;">&quot;&gt;[more]&lt;/a&gt; &lt;a href=&quot;</span><span style="color: #0000ff;">&quot;.str_replace(&quot;</span>digg<span style="color: #339933;">.</span>com<span style="color: #0000ff;">&quot;,&quot;</span>duggmirror<span style="color: #339933;">.</span>com<span style="color: #0000ff;">&quot;,<span style="color: #006699; font-weight: bold;">$href</span>).&quot;</span><span style="color: #0000ff;">&quot;&gt;[dugg]&lt;/a&gt;]]&gt;&lt;/description&gt;
	&lt;/item&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</div>
<p>Where to go: The RSS feed can further be customized to enable the ability to have the RSS feed of only certain categories, or of only stories containing certain phrases.</p>
<h2>Part Fun &#8211; Live Diggs &#8211; A real application</h2>
<p>After screwing with pointless tag clouds and a neat, although not important, reddit clone, we can now build an actual application.</p>
<p>This app will allow you to enter a title of a stories and watch as people digg it. It will display the username and time dugg, and refresh all ajaxily, cause it&#039;s got to web 2.0, right?</p>
<p>First, you enter the title of the story, which then will try to find it&#039;s story id first by searching our database, then, if that fails, using the Digg API story search.</p>
<p>Once it has the story id, it now displays at most the last 30 diggs, and refreshing every 30 seconds to add new diggs. The diggs are retrieved from our database, though using the digg api to select the new diggs could be done just as well, but we have a table full of diggs, and we&#039;re going to use it, dammit! Plus, I think it&#039;s a little nicer on digg, since if you have a fair amount of users, instead of that lot of people requesting or your server on their behalf requesting diggs every 30 seconds, there is just a consistent 1 request every 30 seconds.</p>
<p>Anyways, the javascript in this is just hacked together using prototype.js, meaning there are probably better ways to do this, but whatever. This works&#8230;.for the most part. Sometimes there might be repeat here and there, but nothing devastating.</p>
<p><a href="http://www.flickr.com/photos/71576576@N00/477500824/"><img src="http://farm1.static.flickr.com/193/477500824_2e39274dcc.jpg?v=0" alt="livediggs.png" /></a></p>
<p><a href="http://flickr.com/photos/71576576@N00/477509150/"><img src="http://farm1.static.flickr.com/167/477509150_0e4a71571b.jpg?v=0" alt="livediggs1.png" /></a></p>
<p>Here it is:</p>
<p><b><a href="http://xrho.com/diggs/livediggs.php">Live Diggs</a></b></p>
<p><b>livediggs.php</b>:</p>
<div class="pre">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'config.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'functions.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Services/Digg.php'</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<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;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> AND <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT `id` FROM `diggstories` WHERE `title` = '&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' LIMIT 1&quot;</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: #990000;">mysql_numrows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'mode'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;ajax&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;storyid=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: livediggs.php?storyid=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">// This doesn't work?</span>
	<span style="color: #000088;">$api</span> <span style="color: #339933;">=</span> Services_Digg<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Stories'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$story</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$api</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStoryByTitle</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/[^a-z0-9]/ix&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;_&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//print_r($story);</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;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#41;</span> AND <span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span> AND <span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'mode'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;ajax&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;storyid=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: livediggs.php?storyid=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$story</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;storynotfound&quot;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'storyid'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> AND <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'storyid'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span> AND <span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'storyid'</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>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'mode'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;ajax&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<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;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'time'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> AND <span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'time'</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: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'time'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&amp;&amp;&amp;timestamp=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;&amp;&amp;&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000088;">$where</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot; AND `digging_id` &gt; '&quot;</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'time'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' &quot;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM `diggslive` WHERE `story_id` = '&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'storyid'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' <span style="color: #006699; font-weight: bold;">$where</span> ORDER BY `time` DESC&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">//echo $query;</span>
			<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$num</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_numrows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$num</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">//echo &quot;digger=&quot;.mysql_result($result,$i,&quot;user&quot;).&quot;&amp;time=&quot;.timeparse(mysql_result($result,$i,&quot;time&quot;)).&quot;\n&quot;;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;tr class=&quot;</span>digg<span style="color: #0000ff;">&quot;&gt;&lt;td&gt;&lt;a href=&quot;</span>http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//digg.com/users/&quot;.mysql_result($result,$i,&quot;username&quot;).&quot;&quot;&gt;&quot;.mysql_result($result,$i,&quot;username&quot;).&quot;&lt;/a&gt;&lt;/td&gt;&lt;td class=&quot;time&quot; id=&quot;&quot;.mysql_result($result,$i,&quot;time&quot;).&quot;&quot;&gt;&quot;.timeparse(mysql_result($result,$i,&quot;time&quot;)).&quot;&lt;/td&gt;&lt;/tr&gt;&quot;;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&amp;&amp;&amp;timestamp=&quot;</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'time'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span><span style="color: #000088;">$num</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;digging_id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;&amp;&amp;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">exit</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: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM `diggslive` WHERE `story_id` = '&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'storyid'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' ORDER BY `time` DESC LIMIT 0, 30&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$num</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_numrows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;No diggs :(&quot;</span><span style="color: #339933;">;</span>
&nbsp;
				std_stop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;table id=&quot;</span>diggs<span style="color: #0000ff;">&quot; align=&quot;</span>center<span style="color: #0000ff;">&quot;&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$num</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;tr class=&quot;</span>digg<span style="color: #0000ff;">&quot;&gt;&lt;td&gt;&lt;a href=&quot;</span>http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//digg.com/users/&quot;.mysql_result($result,$i,&quot;username&quot;).&quot;&quot;&gt;&quot;.mysql_result($result,$i,&quot;username&quot;).&quot;&lt;/a&gt;&lt;/td&gt;&lt;td class=&quot;time&quot; id=&quot;&quot;.mysql_result($result,$i,&quot;time&quot;).&quot;&quot;&gt;&quot;.timeparse(mysql_result($result,$i,&quot;time&quot;)).&quot;&lt;/td&gt;&lt;/tr&gt;&quot;;</span>
&nbsp;
&nbsp;
&nbsp;
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/table&gt;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;script type=&quot;</span>text<span style="color: #339933;">/</span>javascript<span style="color: #0000ff;">&quot;&gt; time = &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;digging_id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;; &lt;/script&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		std_start<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM `diggslive` WHERE `story_id` = '&quot;</span><span style="color: #339933;">.</span>sqlquote<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'storyid'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'  ORDER BY `time` LIMIT 0, 30&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$num</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_numrows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</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;">$num</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;No diggs :(&quot;</span><span style="color: #339933;">;</span>
			std_stop<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;">echo</span> <span style="color: #0000ff;">&quot;&lt;table id=&quot;</span>diggs<span style="color: #0000ff;">&quot; align=&quot;</span>center<span style="color: #0000ff;">&quot;&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$num</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;tr class=&quot;</span>digg<span style="color: #0000ff;">&quot;&gt;&lt;td&gt;&lt;a href=&quot;</span>http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//digg.com/user/&quot;.mysql_result($result,$i,&quot;username&quot;).&quot;&quot;&gt;&quot;.mysql_result($result,$i,&quot;username&quot;).&quot;&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&quot;.timeparse(mysql_result($result,$i,&quot;time&quot;)).&quot;&lt;/td&gt;&lt;/tr&gt;&quot;;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">//$lastdiggid = mysql_result($result,$num-1,&quot;digging_id&quot;);</span>
		<span style="color: #666666; font-style: italic;">//echo $lastdiggid.&quot;!!@#!@#&quot;;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/table&gt;&quot;</span><span style="color: #339933;">;</span>
		std_stop<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: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	std_start<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	form<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	std_stop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> std_start<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>Live Diggs<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;js/prototype.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;!--&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;js/scriptaculous.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;--&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #990000;">time</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">// global $lastdiggid; echo $lastdiggid; ?&gt;;</span>
<span style="color: #000000; font-weight: bold;">var</span> resp <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> submitform<span style="color: #009900;">&#40;</span>title<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'loading'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>show<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> uri <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;livediggs.php&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> params <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;title=&quot;</span><span style="color: #339933;">+</span>escape<span style="color: #009900;">&#40;</span>title<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;&amp;mode=ajax&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> ajax <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Ajax<span style="color: #339933;">.</span>Request<span style="color: #009900;">&#40;</span>
		uri<span style="color: #339933;">,</span>
		<span style="color: #009900;">&#123;</span>method<span style="color: #339933;">:</span><span style="color: #0000ff;">'get'</span><span style="color: #339933;">,</span> parameters<span style="color: #339933;">:</span> params<span style="color: #339933;">,</span> onFailure<span style="color: #339933;">:</span> loadpage<span style="color: #339933;">,</span> onComplete<span style="color: #339933;">:</span> getdiggs<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> getdiggs<span style="color: #009900;">&#40;</span>info<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	resp <span style="color: #339933;">=</span> info<span style="color: #339933;">.</span>responseText<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>resp <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;storynotfound&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>show<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'loading'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>hide<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> uri <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;livediggs.php&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> params <span style="color: #339933;">=</span> resp<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;&amp;mode=ajax&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> ajax <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Ajax<span style="color: #339933;">.</span>Request<span style="color: #009900;">&#40;</span>
		uri<span style="color: #339933;">,</span>
		<span style="color: #009900;">&#123;</span>method<span style="color: #339933;">:</span><span style="color: #0000ff;">'get'</span><span style="color: #339933;">,</span> parameters<span style="color: #339933;">:</span> params<span style="color: #339933;">,</span> onFailure<span style="color: #339933;">:</span> loadpage<span style="color: #339933;">,</span> onComplete<span style="color: #339933;">:</span>firstdone <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//update(resp);</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> firstdone<span style="color: #009900;">&#40;</span>info<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	response <span style="color: #339933;">=</span> info<span style="color: #339933;">.</span>responseText<span style="color: #339933;">;</span>
	response<span style="color: #339933;">.</span>evalScripts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>innerHTML <span style="color: #339933;">=</span> response<span style="color: #339933;">;</span>
&nbsp;
	update<span style="color: #009900;">&#40;</span>resp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span>story<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	updater<span style="color: #009900;">&#40;</span>story<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	setTimeout<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'update(&quot;'</span><span style="color: #339933;">+</span>story<span style="color: #339933;">+</span><span style="color: #0000ff;">'&quot;)'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">30000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> updater<span style="color: #009900;">&#40;</span>story<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> uri <span style="color: #339933;">=</span> <span style="color: #0000ff;">'livediggs.php'</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> params <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;time=&quot;</span><span style="color: #339933;">+</span><span style="color: #990000;">time</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;&amp;mode=ajax&amp;&quot;</span><span style="color: #339933;">+</span>story<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> ajax <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Ajax<span style="color: #339933;">.</span>Request<span style="color: #009900;">&#40;</span>
		uri<span style="color: #339933;">,</span>
		<span style="color: #009900;">&#123;</span> method<span style="color: #339933;">:</span><span style="color: #0000ff;">'get'</span><span style="color: #339933;">,</span>parameters<span style="color: #339933;">:</span> params<span style="color: #339933;">,</span> onFailure<span style="color: #339933;">:</span>loadpage<span style="color: #339933;">,</span> onComplete<span style="color: #339933;">:</span>updatepage<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> updatepage<span style="color: #009900;">&#40;</span>resp<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> diggs <span style="color: #339933;">=</span> resp<span style="color: #339933;">.</span>responseText<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #990000;">pos</span> <span style="color: #339933;">=</span> diggs<span style="color: #339933;">.</span>indexOf<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;&amp;&amp;timestamp=&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> timestamp <span style="color: #339933;">=</span> diggs<span style="color: #339933;">.</span>substring<span style="color: #009900;">&#40;</span><span style="color: #990000;">pos</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">13</span><span style="color: #339933;">,</span><span style="color: #990000;">pos</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">23</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	diggs <span style="color: #339933;">=</span> diggs<span style="color: #339933;">.</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">pos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">time</span> <span style="color: #339933;">=</span> timestamp<span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'diggs'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>innerHTML <span style="color: #339933;">=</span> diggs<span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'diggs'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>innerHTML<span style="color: #339933;">;</span>
	updatetimes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	removeold<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> updatetimes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> times <span style="color: #339933;">=</span> $$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'td.time'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">var</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>times<span style="color: #339933;">.</span>length<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		times<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span>innerHTML <span style="color: #339933;">=</span> timeparse<span style="color: #009900;">&#40;</span>times<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span>id<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;">function</span> removeold<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> olds <span style="color: #339933;">=</span> $$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tr.digg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">30</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>olds<span style="color: #339933;">.</span>length<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		olds<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span>remove<span style="color: #009900;">&#40;</span>olds<span style="color: #009900;">&#91;</span>i<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: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> timeparse<span style="color: #009900;">&#40;</span>thetime<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> curtime <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #990000;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	curtime <span style="color: #339933;">=</span> Math<span style="color: #339933;">.</span><span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span>curtime<span style="color: #339933;">.</span>getTime<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> since <span style="color: #339933;">=</span> curtime <span style="color: #339933;">-</span> thetime<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>since <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>since <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> ? since<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; second ago&quot;</span> <span style="color: #339933;">:</span> since<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; seconds ago&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>since <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		since <span style="color: #339933;">=</span> Math<span style="color: #339933;">.</span><span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span>since<span style="color: #339933;">/</span><span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>since <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> ? since<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; minute ago&quot;</span> <span style="color: #339933;">:</span> since<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; minutes ago&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>since <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">86400</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		since <span style="color: #339933;">=</span> Math<span style="color: #339933;">.</span><span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span>since<span style="color: #339933;">/</span><span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>since <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> ? since<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; hour ago&quot;</span> <span style="color: #339933;">:</span> since<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; hours ago&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		since <span style="color: #339933;">=</span> Math<span style="color: #339933;">.</span><span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span>since<span style="color: #339933;">/</span><span style="color: #cc66cc;">86400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>since <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> ? since<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; day ago&quot;</span> <span style="color: #339933;">:</span> since<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; days ago&quot;</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;">function</span> loadpage<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: #0000ff;">'error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>innerHTML <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Some crazy AJAX error probably&quot;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>show<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: #000000; font-weight: bold;">&lt;/script&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> std_stop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/body&gt;&lt;/html&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> form<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div id=&quot;</span>content<span style="color: #0000ff;">&quot;&gt;
&lt;div style=&quot;</span>text<span style="color: #339933;">-</span>align<span style="color: #339933;">:</span>center<span style="color: #339933;">;</span> font<span style="color: #339933;">-</span>size<span style="color: #339933;">:</span> <span style="color: #cc66cc;">150</span><span style="color: #339933;">%;</span><span style="color: #0000ff;">&quot;&gt;This will allow you to watch people digg your story, live!&lt;br /&gt; 	
&lt;span id=&quot;</span>error<span style="color: #0000ff;">&quot; style=&quot;</span>display<span style="color: #339933;">:</span> none<span style="color: #339933;">;</span> color<span style="color: #339933;">:</span>red<span style="color: #339933;">;</span><span style="color: #0000ff;">&quot; &gt; Story not found&lt;br /&gt;&lt;/span&gt;
&lt;form action=&quot;</span>livediggs<span style="color: #339933;">.</span>php<span style="color: #0000ff;">&quot; onsubmit=&quot;</span><span style="color: #b1b100;">return</span> submitform<span style="color: #009900;">&#40;</span>this<span style="color: #339933;">.</span>title<span style="color: #339933;">.</span>value<span style="color: #009900;">&#41;</span><span style="color: #0000ff;">&quot; id=&quot;</span>titleform<span style="color: #0000ff;">&quot;&gt;
&lt;input type=&quot;</span>hidden<span style="color: #0000ff;">&quot; name=&quot;</span>nothing<span style="color: #0000ff;">&quot; value=&quot;</span><span style="color: #0000ff;">&quot; /&gt;&lt;!-- This is a stupid hack, because for some reason the first input form couldn't have a starting value attribute. --&gt;
&lt;input type=&quot;</span>text<span style="color: #0000ff;">&quot; name=&quot;</span>title<span style="color: #0000ff;">&quot; value=&quot;</span>Enter your story title<span style="color: #0000ff;">&quot; style=&quot;</span>font<span style="color: #339933;">-</span>size<span style="color: #339933;">:</span> <span style="color: #cc66cc;">125</span><span style="color: #339933;">%;</span> width<span style="color: #339933;">:</span><span style="color: #cc66cc;">75</span><span style="color: #339933;">%;</span> text<span style="color: #339933;">-</span>align<span style="color: #339933;">:</span> center<span style="color: #339933;">;</span> <span style="color: #0000ff;">&quot;  onfocus=&quot;</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>this<span style="color: #339933;">.</span>value <span style="color: #339933;">==</span> <span style="color: #0000ff;">'Enter your story title'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> this<span style="color: #339933;">.</span>value <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #0000ff;">&quot; /&gt;
&lt;br /&gt;&lt;input type=&quot;</span>submit<span style="color: #0000ff;">&quot; value=&quot;</span>Watch Diggs<span style="color: #0000ff;">&quot;  style=&quot;</span>font<span style="color: #339933;">-</span>size<span style="color: #339933;">:</span> <span style="color: #cc66cc;">125</span><span style="color: #339933;">%;</span> text<span style="color: #339933;">-</span>align<span style="color: #339933;">:</span> center<span style="color: #339933;">;</span><span style="color: #0000ff;">&quot; /&gt; &lt;span id=&quot;</span>loading<span style="color: #0000ff;">&quot; style=&quot;</span>display<span style="color: #339933;">:</span>none<span style="color: #339933;">;</span><span style="color: #0000ff;">&quot;&gt;&lt;img style=&quot;</span>display<span style="color: #339933;">:</span>inline<span style="color: #0000ff;">&quot; src=&quot;</span>ajax<span style="color: #339933;">-</span>loader<span style="color: #339933;">.</span>gif<span style="color: #0000ff;">&quot; alt=&quot;</span>loading<span style="color: #339933;">...</span><span style="color: #0000ff;">&quot; /&gt;&lt;/span&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/div&gt;
&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

</div>
<h2>Conclusion</h2>
<p>:</p>
<p>If you want to download all of these scripts, you can do so here:<br />
<b><a href="http://xrho.com/digg/digg.zip">Download &#8211; ZIP</a></b><br />
<b><a href="http://xrho.com/digg/digg.tar.gz">Download &#8211; Gzip</a></b></p>
<p>They&#039;re licensed under GPL. If you have any questions, suggestions, or comments, just leave a comment or <a href="/contact/">contact me</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ja.meswilson.com/blog/2007/05/08/fun-with-diggs-api/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Great. Friendly URLs aren&#039;t working anymore.</title>
		<link>http://ja.meswilson.com/blog/2007/05/01/great-friendly-urls-arent-working-anymore/</link>
		<comments>http://ja.meswilson.com/blog/2007/05/01/great-friendly-urls-arent-working-anymore/#comments</comments>
		<pubDate>Tue, 01 May 2007 18:24:59 +0000</pubDate>
		<dc:creator>James Wilson</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://ja.meswilson.com/blog/?p=76</guid>
		<description><![CDATA[So for some reason, friendly urls are broken. I mentioned earlier how to get friendly urls working on Netfirms, but now that is fucked up. Great Netfirms, keep sucking complete ass. For the time being, I&#039;ve reverted back to the old style, however result in Google will still be messed up. Expect a rant about [...]]]></description>
			<content:encoded><![CDATA[<p>So for some reason, friendly urls are broken. I mentioned earlier <a href="/?p=49">how to get friendly urls working on Netfirms</a>, but now that is fucked up. Great Netfirms, keep sucking complete ass. For the time being, I&#039;ve reverted back to the old style, however result in Google will still be messed up. Expect a rant about the shittiness of the Netfirm&#039;s service soon, once I find a new host. Anyone have any recommendations? </p>
<p>I also was going to have a big post about Digg&#039;s API today, but that&#039;s looking much less likely now.</p>
<p><b>Update</b>: I think I got them working. The only explanation I can think of is that I switched from PHP 4 to 5 last night. That really shouldn&#039;t have fucked it up, but I put it back to PHP 4, and now it seems to work. Fucking stupid, since I <em>need</em> PHP 5 for the digg script. I guess I can distribute it on xrho.com.</p>
]]></content:encoded>
			<wfw:commentRss>http://ja.meswilson.com/blog/2007/05/01/great-friendly-urls-arent-working-anymore/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WP-Cache and Netfirms</title>
		<link>http://ja.meswilson.com/blog/2007/04/28/wp-cache-and-netfirms/</link>
		<comments>http://ja.meswilson.com/blog/2007/04/28/wp-cache-and-netfirms/#comments</comments>
		<pubDate>Sat, 28 Apr 2007 23:04:18 +0000</pubDate>
		<dc:creator>James Wilson</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://ja.meswilson.com/blog/2007/04/28/wp-cache-and-netfirms/</guid>
		<description><![CDATA[In order to get WP-Cache to work with an account on Netfirms, you have to go through a few extra steps. In order to do these, you need to have SSH enabled, and have some sort of way to connect to it, like PuTTY on Windows. First, download the wp-cache files and upload them to [...]]]></description>
			<content:encoded><![CDATA[<p>In order to get <a href="http://mnm.uib.es/gallir/wp-cache-2/">WP-Cache</a> to work with an account on Netfirms, you have to go through a few extra steps. In order to do these, you need to have SSH enabled, and have some sort of way to connect to it, like <a href="www.chiark.greenend.org.uk/~sgtatham/putty/">PuTTY</a> on Windows.</p>
<p>First, <a href="http://mnm.uib.es/gallir/wp-cache-2/">download the wp-cache files</a> and upload them to your plugins directory.</p>
<p>Then, connect via SSH and cd to your wordpress directory, and chmod &#039;wp-content&#039; to 777. This is done by executing, <code>chmod 0777 wp-content</code>.</p>
<p>Now, go to the Plugins tab in your WordPress admin panel, and activate WP-Cache.</p>
<p>Next, go to the Options->WP-Cache tab and click Enable it.</p>
<p><b>This will show an error and your blog will not be accessible. This is expected, and will be fixed quickly</b></p>
<p>Now, connect via SSH and cd to your wp-content directory, and chmod the &#039;cache directory&#039; to 777. This is done by <code>chmod 0777 cache</code>.</p>
<p>Now, you need to create a symbolic link and chmod that correctly. This is done by:</p>
<p><code>ln -s plugins/wp-cache/wp-cache-phase1.php advanced-cache.php<br />
chmod 0777 advanced-cache.php</code></p>
<p>Now, reload the Options->Wp-Cache page. Click Enable it again, and it now should be enabled and working.</p>
<p>If you have problems, you can disable WP-Cache by editing wp-config.php and removing the line<br />
<code>define('WP_CACHE',true);</code></p>
]]></content:encoded>
			<wfw:commentRss>http://ja.meswilson.com/blog/2007/04/28/wp-cache-and-netfirms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PEAR &amp; Efficiency = Crap</title>
		<link>http://ja.meswilson.com/blog/2007/04/18/pear-efficiency-crap/</link>
		<comments>http://ja.meswilson.com/blog/2007/04/18/pear-efficiency-crap/#comments</comments>
		<pubDate>Wed, 18 Apr 2007 05:02:48 +0000</pubDate>
		<dc:creator>James Wilson</dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://ja.meswilson.com/blog/2007/04/18/pear-efficiency-crap/</guid>
		<description><![CDATA[I needed to convert times from different timezone. Now, I could hack together something, like I usually do, but I decided to try to make my life easier. First, I found some timezone PHP script that amount to nearly 800 lines + 75 entries into a database, which also happened to be easily SQL Injectable. [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://ja.meswilson.com/blog/wp-content/uploads/2007/04/pear.png" alt="pear logo" style="float:left;" />I needed to convert times from different timezone. Now, I could hack together something, like I usually do, but I decided to try to make my life easier.</p>
<p>First, I found some timezone PHP script that amount to nearly 800 lines + 75 entries into a database, which also happened to be easily SQL Injectable. Great, this wasn&#039;t going to work.</p>
<p>Next up, <a href="http://pear.php.net/">PEAR</a>. This <a href="http://pear.php.net/package/Date/">Date</a> package looks promising. Can convert times from timezones easily, and DST seems to work. It was all looking good. Even after a few hacks to get it to work right, everything was good, until I looked at the generating time.</p>
<p>It was at .085 seconds, up from .025 s. That&#039;s a <em>340</em>% increase. That&#039;s not going to work. I was just using it&#039;s my own timer using microtime and didn&#039;t try http_load, but the results were pretty damn consistent. You might think that it&#039;s only 60 ms, but I always think about security and efficiency when making something. If it ever happens to get a lot page views, hopefully I can operate with less server power or not face scalability problems <a href="http://www.codinghorror.com/blog/archives/000838.html">like Twitter</a>.</p>
<p>All of the added time is from including this big ass class. The Date.php and it&#039;s four sub files account to about 350 KB. All the files that are running my whole site are only 214 KB, which includes CSS, Javascript (with prototype.js), templates, and so on. Now, it does have a lot of documentation, but still, damn! </p>
<p>Another ridiculous thing, it decided to redefine the formating characters. Instead of following whats already used for <a href="http://www.php.net/date">date</a>, it decides to just go through the alphabet. I&#039;m sure there&#039;s some methodology going through it, but I sure as hell don&#039;t see it, except that M/m and H/h are minutes and hours respectively.</p>
<p>So now I&#039;ve wasted 30 minutes fangling with 2 scripts, and both suck. Plus I&#039;ve spent another probably 15 minutes writing my disgust with these 2 scripts. I could&#039;ve just written the damn thing myself already, probably by just slightly modifying <a href="http://www.php.net/manual/en/function.date.php#69167">this</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ja.meswilson.com/blog/2007/04/18/pear-efficiency-crap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
