<?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>firsttube.com &#187; Code</title>
	<atom:link href="http://firsttube.com/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://firsttube.com</link>
	<description>crunchy nuggets, served semi-daily</description>
	<lastBuildDate>Wed, 10 Mar 2010 03:38:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<atom:link rel='hub' href='http://firsttube.com/?pushpress=hub'/>
		<item>
		<title>Javascript Ninja!</title>
		<link>http://firsttube.com/read/javascript-ninja/</link>
		<comments>http://firsttube.com/read/javascript-ninja/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 18:48:56 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://firsttube.com/?p=1531</guid>
		<description><![CDATA[Thank you, John Resig. Because of you, I&#8217;m learning about Javascript the way Andy Gadiel taught me HTML. In the days before server-side scripting, I learned my first bits of HTML largely by viewing the source of Andy Gadiel&#8217;s Phish page (which, for some reason, remains largely unchanged since ~1997).  By reading Gadiel&#8217;s HTML, I [...]]]></description>
			<content:encoded><![CDATA[<p>Thank you, <a href="http://ejohn.org">John Resig</a>. Because of you, I&#8217;m learning about Javascript the way <a href="http://gadiel.com">Andy Gadiel</a> taught me HTML. In the days before server-side scripting, I learned my first bits of HTML largely by viewing the source of <a href="http://gadiel.com/phish">Andy Gadiel&#8217;s Phish page</a> (which, for some reason, remains largely unchanged since ~1997).  By reading Gadiel&#8217;s HTML, I slowly pieced together my own understanding of HTML.  It was <a href="http://www.amazon.com/gp/product/0789720248?ie=UTF8&amp;tag=firsttubecom-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0789720248">Joe Burns&#8217; fantastic Javascript Goodies</a> that first had me dipping my n00b fingers into client side active scripting.  I picked up CSS all over the web.</p>
<p>Resig&#8217;s jQuery is so powerful and so easy that even with basic knowledge of CSS and Javascript, anyone can be a virtual scripting master.  It&#8217;s so easy, that I&#8217;ve slacked on learning about javascript objects, inheritance, closures, anonymous functions, prototypes, and scores of  other Javascript staples that I should&#8217;ve long since mastered.   I just discovered John&#8217;s new web app, cleverly titled &#8220;<a href="http://ejohn.org/apps/learn/">Learning Advanced Javascript</a>&#8220;, and so far, so good!</p>
<p>I wrote this myself and understand why it works, which is much more than I could say yesterday.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> ninja <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	walk<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>steps<span style="color: #339933;">,</span>turn<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		toDo <span style="color: #339933;">=</span> <span style="color: #3366CC;">'Walking '</span><span style="color: #339933;">+</span>steps<span style="color: #339933;">+</span><span style="color: #3366CC;">' steps forward, then turning '</span><span style="color: #339933;">+</span>turn<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
	  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	star<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>action<span style="color: #339933;">,</span>distance<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		toDo <span style="color: #339933;">=</span> toDo<span style="color: #339933;">+</span><span style="color: #3366CC;">' '</span><span style="color: #339933;">+</span>action<span style="color: #339933;">+</span><span style="color: #3366CC;">'ing star '</span><span style="color: #339933;">+</span>distance<span style="color: #339933;">+</span><span style="color: #3366CC;">' feet'</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
	  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	then<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		toDo <span style="color: #339933;">=</span> toDo<span style="color: #339933;">+</span><span style="color: #3366CC;">', then '</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	doIt<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		log<span style="color: #009900;">&#40;</span>toDo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
ninja.<span style="color: #660066;">walk</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'7'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'south'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">then</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">star</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'throw'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'50'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">doIt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Output:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&gt; Walking 7 steps forward, then turning south, then throwing star 50 feet</pre></div></div>

<p>It&#8217;s clear to me &#8211; and has been for some time &#8211; that the future of the web, for better or for worse, rests heavily on the mighty shoulders of client side scripting.   Building on powerful, extensible frameworks like <a href="http://jquery.com">jQuery</a> and <a href="http://mootools.net">MooTools</a>, the next generation of web apps is sure to compete with the desktop.  The ability to understand how to utilize the frameworks when necessary and hack together powerful scriptlets for other purposes seems essential to success in the future web. I know I&#8217;ll be investing in &#8220;<a href="http://www.amazon.com/gp/product/193398869X?ie=UTF8&amp;tag=firsttubecom-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=193398869X" target="_blank">Secrets of a Javascript Ninja</a>&#8221; just as a result of this tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://firsttube.com/read/javascript-ninja/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Behind the Scenes at OSNews</title>
		<link>http://firsttube.com/read/behind-the-scenes-at-osnews/</link>
		<comments>http://firsttube.com/read/behind-the-scenes-at-osnews/#comments</comments>
		<pubDate>Mon, 04 May 2009 22:55:57 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[OSNews]]></category>

		<guid isPermaLink="false">http://firsttube.com/?p=1279</guid>
		<description><![CDATA[I just started putting together a series of articles I will be publishing on OSNews.  I&#8217;ve only roughly sketched it out, but in short, it&#8217;s going to discuss how OSNews works, how the PHP is structured, why we made certain architectural decisions, why we don&#8217;t use tried-and-true CMSes like WordPress, Slash, or Joomla!, and how, [...]]]></description>
			<content:encoded><![CDATA[<p>I just started putting together a series of articles I will be publishing on OSNews.  I&#8217;ve only roughly sketched it out, but in short, it&#8217;s going to discuss how <a href='http://osnews.com'>OSNews</a> works, how the PHP is structured, why we made certain architectural decisions, why we don&#8217;t use tried-and-true CMSes like WordPress, Slash, or Joomla!, and how, during peak traffic times, we have survived 30,000 unique visitors per hour on a single server.  <a href='http://osnews.com'>OSNews</a> didn&#8217;t happen by mistake: over a series of months, arguably years, we took a constant read of performance, hits, server load, and usability with the mission to continually improve load time, performance, and <abbr title="user experience">UX</abbr>.  We&#8217;ve just recently begun testing some new data presentation methods that I intend to include in my little exposé.</p>
<p>If you&#8217;re interested in some revealing behind-the-scenes info, feel free to ask questions now.</p>
]]></content:encoded>
			<wfw:commentRss>http://firsttube.com/read/behind-the-scenes-at-osnews/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Flip 3.0.1</title>
		<link>http://firsttube.com/read/flip-301/</link>
		<comments>http://firsttube.com/read/flip-301/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 20:52:05 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Flip]]></category>

		<guid isPermaLink="false">http://firsttube.com/?p=1229</guid>
		<description><![CDATA[I never expected to release another version of my old weblog project Flip, but while searching my own name in a new search engine, I came upon several vulnerability reports for Flip 3.0.  I&#8217;ve known about them for awhile now, but having dropped Flip in favor of another project (which I&#8217;ve since abandoned, for [...]]]></description>
			<content:encoded><![CDATA[<p>I never expected to release another version of my old weblog project <a href="http://firsttube.com/tag/flip">Flip</a>, but while searching my own name in a new search engine, I came upon several vulnerability reports for Flip 3.0.  I&#8217;ve known about them for awhile now, but having dropped Flip in favor of another project (which I&#8217;ve since abandoned, for the most part, in favor of WordPress), it seemed pointless to bother.  However, since there is an active exploit, I thought I&#8217;d release an update and a patch.</p>
<p>I don&#8217;t believe anyone out there is still using Flip, but if there is, this is how to defeat the script: simple add this line at line 102 of account.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strstr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'em'</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;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Fail'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>and this at line 162:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strstr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nem'</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;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Fail'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Alternatively, you can download the modified file <a href="http://releases.smallaxesolutions.com/account.phps">here</a> or <a href="http://releases.smallaxesolutions.com/flip-3.0.1.zip">download Flip 3.0.1 here</a>.</p>
<p>It may sound odd, but I would highly recommend that you do *not* use this code.  It&#8217;s now 7 years old and the web is a much different place.  The code here is really not suited for running a website today.  That said, it was odd to unzip and install it and see that it actually works.  The rendering of most of the &#8220;themes&#8221; is weird (Fudge works great), but otherwise, everything worked.</p>
<p>If you are still a Flip user, I recommend you update your account.php page immediately, and if you have the time and inclination, upgrade to 3.0.1.  The following files have some minor changes:</p>
<ul class="list">
<li>account.php</li>
<li>index.php</li>
<li>inc/config.php</li>
<li>README.html</li>
</ul>
<p>Once again, this code is aged not particularly well suited for today&#8217;s web.  If you want a simple weblog, I recommend <a href="http://wordpress.org">WordPress</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://firsttube.com/read/flip-301/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Posting Your Latest Tweet in Wordpress</title>
		<link>http://firsttube.com/read/posting-your-latest-tweet-in-wordpress/</link>
		<comments>http://firsttube.com/read/posting-your-latest-tweet-in-wordpress/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 16:48:31 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Social Networking]]></category>

		<guid isPermaLink="false">http://firsttube.com/?p=1118</guid>
		<description><![CDATA[Although I posted yesterday how to add your latest tweet to Wordpress without a plugin, I made several changes to the script before I posted it to make it more &#8220;generic&#8221; and re-usable. Since I&#8217;ve changed it quite a bit, I decided to repost it.  This new script also autolinks @usernames and #hash tags.
Directions [...]]]></description>
			<content:encoded><![CDATA[<p>Although I posted yesterday how to add your latest tweet to Wordpress without a plugin, I made several changes to the script before I posted it to make it more &#8220;generic&#8221; and re-usable. Since I&#8217;ve changed it quite a bit, I decided to repost it.  This new script also autolinks @usernames and <a href="http://www.google.com/search?q=twitter+hash+tags">#hash tags</a>.</p>
<p>Directions are this easy: set the path of $tw_File with a static, writable file.  Set $tw_userid to your Twitter user id.  Done. </p>
<p>Download <a href="http://firsttube.com/s/latest-tweet"><strong>firsttube.com &#8220;get latest tweet&#8221; php snippet</strong></a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://firsttube.com/read/posting-your-latest-tweet-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Add Latest Tweet to Wordpress (Without a Plugin)</title>
		<link>http://firsttube.com/read/how-to-add-latest-tweet-to-wordpress/</link>
		<comments>http://firsttube.com/read/how-to-add-latest-tweet-to-wordpress/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 20:18:07 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[Social Networking]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Web 2.0]]></category>

		<guid isPermaLink="false">http://firsttube.com/?p=1101</guid>
		<description><![CDATA[I decided to add my latest &#8220;tweet&#8221; from Twitter to the sidebar of my Wordpress blog.  Rather than use yet another plugin that adds yet another hook &#8211; and there are many that do this with lots of code, I decided to use a homegrown solution, dependant only on PHP4+ and cURL  (most webhosts [...]]]></description>
			<content:encoded><![CDATA[<p>I decided to add my latest &#8220;tweet&#8221; from Twitter to the sidebar of my Wordpress blog.  Rather than use yet another plugin that adds yet another hook &#8211; and there are many that do this with lots of code, I decided to use a homegrown solution, dependant only on PHP4+ and cURL  (most webhosts already have cURL compiled in, if not, you should request it).  Adding the following to any of the files in your Wordpress theme will print out your current Twitter status and cache the results so you don&#8217;t hammer their system.</p>
<p>First, <a href="http://help.twitter.com/forums/23786/entries/15360">snag your Twitter user id</a>.  Then, open up your theme file.  I put mine in sidebar.php found in <em>/wp-content/themes/&lt;THEMENAME&gt;/</em>.    Use the below code.  If you want the output wrapped in a list, you would need to put &lt;ul&gt; and &lt;li&gt; tags around this code.</p>
<p>Carefully set your variables.  The cache file should be writable.  Note that you can use a decimal value for $tw_BlankAfter and $tw_Minutes if necessary.   That&#8217;s it.</p>
<p><em>Due to what must be a bug in Wordpress, please ignore the closing &#8220;&lt;/text&gt;&lt;/created_at&gt;&#8221; at the end of this post.  It&#8217;s trying be smart and &#8220;fix&#8221; broken tags, but the code is right. </em></p>
<p><strong>NOTE (2/20/09): I have updated the below code.  The new version can be found at &#8220;<a href="http://firsttube.com/read/posting-your-latest-tweet-in-wordpress/">Posting Your Latest Tweet in Wordpress</a>&#8220;. </strong><em><br />
</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* ~~~~ Custom Twitter Bit ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */</span>
<span style="color: #666666; font-style: italic;">/* ~~~~ Adam S, firsttube.com, twitter @sethadam1 ~~~~~~~~~~~~~~~~~~~~ */</span>
&nbsp;
<span style="color: #000088;">$tw_File</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/path/to/a/static/writable/file/twitter.html'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tw_Userid</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'XXXXXXX'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//set to your Twitter user id</span>
<span style="color: #000088;">$tw_BlankAfter</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//blank out status if it's older than this many days</span>
<span style="color: #000088;">$tw_Minutes</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//minutes between reloads</span>
&nbsp;
<span style="color: #000088;">$tw_Offset</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;">//leave as is</span>
<span style="color: #666666; font-style: italic;">// uncomment below time if you want to allow a manual reset via ?twitter-reset</span>
<span style="color: #666666; font-style: italic;">// if($_SERVER['QUERY_STRING']=='twitter-reset') { $tw_Offset=0; } </span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Do not edit below this line */</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">filemtime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tw_File</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>time<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #990000;">floatval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tw_Offset</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">include</span> <span style="color: #000088;">$tw_File</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;">is_writable</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tw_File</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$tw_iswritable</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;">$tw_time</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">86400</span><span style="color: #339933;">*</span><span style="color: #990000;">floatval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tw_BlankAfter</span><span style="color: #009900;">&#41;</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;">$tw_Offset</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$tw_time</span><span style="color: #339933;">=</span><span style="color: #000088;">$tw_Offset</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$tw_hyperlinks</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$tw_c</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tw_c</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span>
		<span style="color: #0000ff;">&quot;http://twitter.com/statuses/user_timeline/&quot;</span>
		<span style="color: #339933;">.</span><span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tw_Userid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tw_c</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$tw_src</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tw_c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tw_c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(.*)&amp;lt; \/created_at&amp;gt;/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tw_src</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tw_d</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;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tw_d</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<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;">$tw_time</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(.*)&amp;lt; \/text&amp;gt;/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tw_src</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tw_m</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$tw_status</span> <span style="color: #339933;">=</span> <span style="color: #990000;">htmlentities</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;&amp;amp;&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;">$tw_m</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$tw_hyperlinks</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$tw_status</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ereg_replace</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">&quot;[[:alpha:]]+://[^&amp;lt;&amp;gt;[:space:]]+[[:alnum:]/]&quot;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">&quot;&lt;a href=&quot;</span>\<span style="color: #0000ff;">&quot;&gt;<span style="color: #000099; font-weight: bold;">\\</span>0&lt;/a&gt;&quot;</span><span style="color: #339933;">,</span>
			<span style="color: #000088;">$tw_status</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$tw_output</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tw_status</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: #000088;">$tw_iswritable</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;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tw_File</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</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: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tw_iswritable</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;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tw_File</span><span style="color: #339933;">,</span><span style="color: #000088;">$tw_output</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: #000088;">$tw_output</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">/* ~~~ /Custom Twitter Bit ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */</span></pre></div></div>

<p><small>Please note that portions of this code come from the twtter_status() function that was not written by me, but is available from <a href="http://www.google.com/search?q=function+twitter_status()">various sources online</a>.</small></p>
<p><strong>Update</strong>: Removed function and put code inline.</p>
]]></content:encoded>
			<wfw:commentRss>http://firsttube.com/read/how-to-add-latest-tweet-to-wordpress/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Wordpress &#8220;Press This&#8221; 404 Problem</title>
		<link>http://firsttube.com/read/wordpress-press-this-404-problem/</link>
		<comments>http://firsttube.com/read/wordpress-press-this-404-problem/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 15:41:50 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://firsttube.com/?p=1062</guid>
		<description><![CDATA[WordPress › Support » Press This 404 issue.
&#8220;Press This&#8221; hasn&#8217;t worked for me for ages.  I am so happy to have it back!
]]></description>
			<content:encoded><![CDATA[<p><a href="http://wordpress.org/support/topic/190089">WordPress › Support » Press This 404 issue</a>.</p>
<p>&#8220;Press This&#8221; hasn&#8217;t worked for me for ages.  I am so happy to have it back!</p>
]]></content:encoded>
			<wfw:commentRss>http://firsttube.com/read/wordpress-press-this-404-problem/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Sorting a Multi-Dimensional Array with PHP</title>
		<link>http://firsttube.com/read/sorting-a-multi-dimensional-array-with-php/</link>
		<comments>http://firsttube.com/read/sorting-a-multi-dimensional-array-with-php/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 18:52:48 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://firsttubecom/?p=1044</guid>
		<description><![CDATA[Every so often I find myself with a multidimensional array that I want to sort by a value in a sub-array.  I have an array that might look like this:

//an array of some songs I like
$songs =  array&#40;
		'1' =&#62; array&#40;'artist'=&#62;'The Smashing Pumpkins', 'songname'=&#62;'Soma'&#41;,
		'2' =&#62; array&#40;'artist'=&#62;'The Decemberists', 'songname'=&#62;'The Island'&#41;,
		'3' =&#62; array&#40;'artist'=&#62;'Fleetwood Mac', 'songname' =&#62;'Second-hand [...]]]></description>
			<content:encoded><![CDATA[<p>Every so often I find myself with a multidimensional array that I want to sort by a value in a sub-array.  I have an array that might look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//an array of some songs I like</span>
<span style="color: #000088;">$songs</span> <span style="color: #339933;">=</span>  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'1'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'artist'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'The Smashing Pumpkins'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'songname'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Soma'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'2'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'artist'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'The Decemberists'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'songname'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'The Island'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'3'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'artist'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Fleetwood Mac'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'songname'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Second-hand News'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The problem is thus: I&#8217;d like to echo out the songs I like in the format &#8220;<em>Songname</em> (<em>Artist</em>),&#8221; and I&#8217;d like to do it alphabetically by artist.  PHP provides many functions for sorting arrays, but none will work here.  <em>ksort()</em> will allow me to sort by key, but the keys in the <em>$songs</em> array are irrelevant.  <em>asort()</em> allows me to sort and preserves keys, but it will sort $songs by the value of each element, which is also useless, since the value of each is &#8220;array()&#8221;.  <em>usort()</em> is another possible candidate and can do multi-dimensional sorting, but it involves building a callback function and is often pretty long-winded.  Even the examples in the PHP docs references specific keys. </p>
<p>So I developed a quick function to sort by the value of a key in a sub-array.  Please note this version does a case-insensitive sort. See subval_sort() below.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> subval_sort<span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span><span style="color: #000088;">$subkey</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$b</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$subkey</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #990000;">asort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$b</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;">$b</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$c</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>To use it on the above, I would simply type:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$songs</span> <span style="color: #339933;">=</span> subval_sort<span style="color: #009900;">&#40;</span><span style="color: #000088;">$songs</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'artist'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$songs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This is what you should expect see:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">Array</span>
<span style="color: #009900;">&#40;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span>artist<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Fleetwood Mac
            <span style="color: #009900;">&#91;</span>song<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Second<span style="color: #339933;">-</span>hand News
        <span style="color: #009900;">&#41;</span>
&nbsp;
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span>artist<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> The Decemberists
            <span style="color: #009900;">&#91;</span>song<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> The Island
        <span style="color: #009900;">&#41;</span>
&nbsp;
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span>artist<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> The Smashing Pumpkins
            <span style="color: #009900;">&#91;</span>song<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Cherub Rock
        <span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #009900;">&#41;</span></pre></div></div>

<p>The songs, sorted by artist. </p>
]]></content:encoded>
			<wfw:commentRss>http://firsttube.com/read/sorting-a-multi-dimensional-array-with-php/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>firsttube.com Upgraded To Wordpress 2.7</title>
		<link>http://firsttube.com/read/firsttubecom-upgraded-to-wordpress-27/</link>
		<comments>http://firsttube.com/read/firsttubecom-upgraded-to-wordpress-27/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 20:28:56 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[Meta]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scoble]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://firsttubecom/?p=997</guid>
		<description><![CDATA[So far, one problem, two gripes.  My problem is that I can&#8217;t seem to get posts with dots in the slug title to work right, even though I once solved this problem before.  What&#8217;s worse is that it won&#8217;t fetch those posts anymore, which really sucks.
Onto my gripes. I can&#8217;t get inline replying/threading to work. [...]]]></description>
			<content:encoded><![CDATA[<p>So far, one problem, two gripes.  My problem is that I can&#8217;t seem to get posts with dots in the slug title to work right, even though I once <a href="http://firsttube.com/read/hacking-wordpress-day-two/">solved this problem before</a>.  What&#8217;s worse is that it won&#8217;t fetch those posts anymore, which really sucks.</p>
<p>Onto my gripes. I can&#8217;t get inline replying/threading to work.  There is very little documentation on it so far.  The functions are called comment_reply_link() and get_comment_reply_link(), and there&#8217;s nothing anywhere in the codex that helps, there&#8217;s little on the internet, the only place to get any real detail is the code itself, which explains:</p>
<p><em><small>from wp-includes/comment-template.php starting at line 949 on WP 2.7.0</small></em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #339933;">*</span> Retrieve HTML content <span style="color: #b1b100;">for</span> reply to comment <span style="color: #990000;">link</span><span style="color: #339933;">.</span>
 <span style="color: #339933;">*</span>
 <span style="color: #339933;">*</span> The <span style="color: #b1b100;">default</span> arguments that can be override are <span style="color: #0000ff;">'add_below'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'respond_id'</span><span style="color: #339933;">,</span>
 <span style="color: #339933;">*</span> <span style="color: #0000ff;">'reply_text'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'login_text'</span><span style="color: #339933;">,</span> and <span style="color: #0000ff;">'depth'</span><span style="color: #339933;">.</span> The <span style="color: #0000ff;">'login_text'</span> argument will be
 <span style="color: #339933;">*</span> used<span style="color: #339933;">,</span> <span style="color: #b1b100;">if</span> the user must <span style="color: #990000;">log</span> in or register first before posting a comment<span style="color: #339933;">.</span> The
 <span style="color: #339933;">*</span> <span style="color: #0000ff;">'reply_text'</span> will be used<span style="color: #339933;">,</span> <span style="color: #b1b100;">if</span> they can post a reply<span style="color: #339933;">.</span> The <span style="color: #0000ff;">'add_below'</span> and
 <span style="color: #339933;">*</span> <span style="color: #0000ff;">'respond_id'</span> arguments are <span style="color: #b1b100;">for</span> the JavaScript moveAddCommentForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">function</span>
 <span style="color: #339933;">*</span> parameters<span style="color: #339933;">.</span>
 <span style="color: #339933;">*</span>
 <span style="color: #339933;">*</span> <span style="color: #339933;">@</span>since 2<span style="color: #339933;">.</span>7<span style="color: #339933;">.</span>0
 <span style="color: #339933;">*</span>
 <span style="color: #339933;">*</span> <span style="color: #339933;">@</span>param <span style="color: #990000;">array</span> <span style="color: #000088;">$args</span> Optional<span style="color: #339933;">.</span> Override <span style="color: #b1b100;">default</span> options<span style="color: #339933;">.</span>
 <span style="color: #339933;">*</span> <span style="color: #339933;">@</span>param int <span style="color: #000088;">$comment</span> Optional<span style="color: #339933;">.</span> Comment being replied to<span style="color: #339933;">.</span>
 <span style="color: #339933;">*</span> <span style="color: #339933;">@</span>param int <span style="color: #000088;">$post</span> Optional<span style="color: #339933;">.</span> Post that the comment is going to be displayed on<span style="color: #339933;">.</span>
 <span style="color: #339933;">*</span> <span style="color: #339933;">@</span><span style="color: #b1b100;">return</span> string<span style="color: #339933;">|</span>bool<span style="color: #339933;">|</span>null <span style="color: #990000;">Link</span> to show comment form<span style="color: #339933;">,</span> <span style="color: #b1b100;">if</span> successful<span style="color: #339933;">.</span> <span style="color: #009900; font-weight: bold;">False</span><span style="color: #339933;">,</span> <span style="color: #b1b100;">if</span> comments are closed<span style="color: #339933;">.</span></pre></div></div>

<p>It doesn&#8217;t matter much, because it doesn&#8217;t work, period, even though I&#8217;ve followed the instruction here to a t.  So I&#8217;ll have to fix that in time.</p>
<p>My last gripe is with the new wp_list_comments() routine.  I understand this is all new, but the idea that templating comments requires a callback function as a wrapper to all comments, pings, and trackbacks is <strong>clumsy</strong> at best.  <a href="http://codex.wordpress.org/Template_Tags/wp_list_comments">The codex on wp_list_comments()  have nothing</a> to explain it to people, so while I&#8217;ve dug in and gotten things working, it&#8217;s not for the feint of heart just yet, since you need to build a PHP function in your theme in your <em>functions.php</em> file (or create one if it doesn&#8217;t exist, which cannot be done via the Dashboard).  I&#8217;m a little sad, since the theme system is so flexible and the new plugin system is just incredible, to see the new comment loop be so <em>manual</em> compared to the single file approach used so successfully in the past.</p>
<p>I know that <a href="http://scobleizer.com/2008/12/12/wordpress-27/">Scoble says Wordpress 2.7 rocks</a>, and it does.  Scoble doesn&#8217;t realize the shortcomings because he hasn&#8217;t tried to play with the new features, and fortunately, it very gracefully degrades.  But it&#8217;s got some work to do to be perfect, for me at least.</p>
]]></content:encoded>
			<wfw:commentRss>http://firsttube.com/read/firsttubecom-upgraded-to-wordpress-27/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the abbr tag</title>
		<link>http://firsttube.com/read/using-the-abbr-tag/</link>
		<comments>http://firsttube.com/read/using-the-abbr-tag/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 14:55:16 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Nerd]]></category>
		<category><![CDATA[Review]]></category>

		<guid isPermaLink="false">http://firsttubecom/?p=901</guid>
		<description><![CDATA[Kroc Camen, long time OSNews reader and frequent IM buddy of mine, has an interesting piece examining the use of the &#60;abbr&#62; HTML tag.  Kroc is one of those people who is very serious about the presentation and efficiency of his code, a trait I do not share, at least in practice, at least, to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://camendesign.co.uk">Kroc Camen</a>, long time <a href='http://osnews.com'>OSNews</a> reader and frequent IM buddy of mine, has <a href="http://camendesign.co.uk/code/using-abbr">an interesting piece examining the use of the &lt;abbr&gt; HTML tag</a>.  Kroc is one of those people who is very serious about the presentation and efficiency of his code, a trait I do not share, at least in practice, at least, to the same degree that he does, and it makes us good companions.  My focus is typically on clean, fast, scalable code that forsakes beauty in favor of performance.  My code, in the form of OSNews, has sustained a simultaneous <a href="http://digg.com">Digg</a>ing and <a href="http://slashdot.org">Slashdot</a>ting, something of which I&#8217;m very proud.</p>
<p>But my CSS isn&#8217;t going to win any awards, my javascript could be collapsed a lot and made much more efficient, and my HTML often suffers from &#8220;<a href="http://csscreator.com/?q=divitis">div-itis</a>&#8221; and &#8220;class-itis.&#8221; Enter Mr Camen, whose motto, &#8220;code is art,&#8221; is evident upon initial inspection.  Kroc&#8217;s code is not only well written, the source itself is actually beautiful.  We have collaborated on both CSS and PHP in the past and both are the better for it.  </p>
<p>That said, we have strikingly different positions about publshing on the web.  Kroc writes his website for himself, and as a result, publishes in HTML 5; his site doesn&#8217;t work in IE, his mindset being &#8220;if you choose to use a subpar browser, you will have a subpar experience. &#8221;  Indeed, his site is a complete mess in IE 7, the fault only of IE and its abysmal CSS support, not the code itself.   I, conversely, attempt to code with a much more conservative bend, coding to the masses, at the expense of using several great tricks.   </p>
<p>Getting back on track, when it came to discussing the &lt;abbr&gt; tag, both of us found ourselves remarkably on the same page.  Although one can get into the nitty-gritty details and find the whole conversation trivial, I think there&#8217;s something to be said for using tags properly and getting your information properly parsed.  After all, screen readers exist with regularity today, XML is very popular (most commonly in the form of RSS), and search engines spider the majority of popular websites several times times a day if not every hour.   Using tags, and using them properly, should be important to content publishers and republishers.  </p>
<p>I also agree with Kroc&#8217;s point that it&#8217;s not your job to educate your reader like an encyclopedia.  The &lt;abbr&gt; tag is not so much about education as it is about properly marking up your  code.  </p>
<p>As the second wave of the browser war heats up &#8211; as Tracemonkey, Squirrelfish Extreme, and V8 start really setting themselves apart from IE in even larger ways, coding to standards will become even more important.  Understading lesser used tags is elemental in writing the best, most concise code and ranking well in search engines.</p>
]]></content:encoded>
			<wfw:commentRss>http://firsttube.com/read/using-the-abbr-tag/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My First Plugin</title>
		<link>http://firsttube.com/read/my-first-plugin/</link>
		<comments>http://firsttube.com/read/my-first-plugin/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 00:29:25 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[Meta]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://firsttubecom/?p=672</guid>
		<description><![CDATA[I recognize that I&#8217;ve been a little wordy about WordPress lately &#8211; no pun intended &#8211; but I&#8217;m afraid that it&#8217;s really interesting to me, and probably will be for the next few days.  So, if you&#8217;re growing weary of the WordPress related posts, I&#8217;m sorry.  
Today I took my first stab at [...]]]></description>
			<content:encoded><![CDATA[<p>I recognize that I&#8217;ve been a little wordy about WordPress lately &#8211; no pun intended &#8211; but I&#8217;m afraid that it&#8217;s really interesting to me, and probably will be for the next few days.  So, if you&#8217;re growing weary of the WordPress related posts, I&#8217;m sorry.  </p>
<p>Today I took my first stab at writing a WordPress plugin.  Turns out, it&#8217;s really easy.  I&#8217;m mean <strong>really</strong> easy.  The plugin is pretty simple: it just searches through every post and turns the unlinked words <a href='http://firsttube.com'>firsttube.com</a> into a hyperlink.  However, it seems like it might be a useful plugin for some, even just as a text-replacement plugin.  So we&#8217;ll see if I publish it.   In the meantime, though, it took me about 15 minutes to write and then it was recognized by WordPress, which was very cool.  </p>
<p>I have a few ideas for more involved plugins too that I may write, one day.  But in the meantime, this one is pretty cool.  </p>
]]></content:encoded>
			<wfw:commentRss>http://firsttube.com/read/my-first-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Weirdness</title>
		<link>http://firsttube.com/read/php-weirdness/</link>
		<comments>http://firsttube.com/read/php-weirdness/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 19:46:03 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Nerd]]></category>
		<category><![CDATA[Yahoo!]]></category>

		<guid isPermaLink="false">http://firsttubecom/?p=660</guid>
		<description><![CDATA[Beware: this post is definitely not for the feint of heart.  It includes a lot of code.  You have been warned.
I wrote an application some time ago for my company that looks up the longitude and latitude of an address for use in our geocoding initiative.  It relied on yahoo_geo(), a function [...]]]></description>
			<content:encoded><![CDATA[<p>Beware: this post is definitely not for the feint of heart.  It includes a lot of code.  You have been warned.</p>
<p>I wrote an application some time ago for my company that looks up the longitude and latitude of an address for use in our geocoding initiative.  It relied on yahoo_geo(), <a href="http://toys.lerdorf.com/archives/2005/11.html">a function written by PHP creator Rasmus Lerdorf</a> and the Yahoo Maps API.  It was largely dependent on this function:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> yahoo_geo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$location</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://api.local.yahoo.com/MapsService/V1/geocode?appid=rlerdorf&amp;amp;location='</span>
		<span style="color: #339933;">.</span><span style="color: #990000;">rawurlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$location</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$tmp</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/tmp/yws_geo_'</span><span style="color: #339933;">.</span><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	request_cache<span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tmp</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">43200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">libxml_use_internal_errors</span><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: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'precision'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>Result<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'precision'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>Result<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>children<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$val</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</p>
<p>This function worked for over two years for us with no problems at all.  Then suddenly, in the last month, it started getting spotty.  I fixed things by commenting out the caching parts of the function and forcing each execution to run again.  Then I got errors about the libxml_use_internal_errors() function, so I commented that out.  But today, the function just flat out failed, every single time returning the same error: </p>
<p><strong>Warning: file_get_contents(http://XXXXXXXXXX/XXX) [function.file-get-contents]: failed to open stream: HTTP request failed! in /home/intranet/html/fetch.php on line X</strong></p>
<p>What the heck? This code is all over the web.  I&#8217;ve tried a million permutations of this function, including using fopen() and ob_get_contents(), and none have worked.  And most frustratingly, I could load the URL successfully in Lynx and eLinks, so the machine could quickly and easily fetch the URL.</p>
<p>So I ventured into a sandbox I&#8217;ve never really played before: <a href="http://us2.php.net/manual/en/ref.curl.php">cURL</a>.   cURL is an interesting animal.  But the interesting thing is, once I got it working, it worked faster than ever! So, without further ado, here is the new and improved yahoo_geo() function: </p>
<p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> yahoo_geo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$location</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://api.local.yahoo.com/MapsService/V1/geocode?appid=rlerdorf&amp;#038;location='</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$location</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$stream</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ob_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">ob_end_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stream</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stream</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'precision'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'precision'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$val</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</p>
<p><small><strong>Note:</strong> If you&#8217;re reproducing these functions elsewhere, be careful &#8211; WordPress may have converted the quotes into smart quotes that will need to be fixed before this script will run properly. </small></p>
]]></content:encoded>
			<wfw:commentRss>http://firsttube.com/read/php-weirdness/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>OSNews vs. WordPress</title>
		<link>http://firsttube.com/read/osnews-vs-wordpress/</link>
		<comments>http://firsttube.com/read/osnews-vs-wordpress/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 00:35:20 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Nerd]]></category>
		<category><![CDATA[OSNews]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://firsttubecom/?p=656</guid>
		<description><![CDATA[I&#8217;ve spent quite a bit of time, over the last 5 or 6 days, diving into WordPress and learning what makes it tick.  Parts of WordPress are really impressive &#8211; just flat out cool. The way some of it works is fairly complex and deciphering it sometimes means reading page after page after page to understand an [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent quite a bit of time, over the last 5 or 6 days, diving into WordPress and learning what makes it tick.  Parts of WordPress are <em>really</em> impressive &#8211; just flat out <em><strong>cool</strong></em>. The way some of it works is fairly complex and deciphering it sometimes means reading page after page after page to understand an entire routine.  But sometimes, when you finally see, end to end, how something in WordPress works &#8211;  I mean really see individual bits of the engine &#8211; you have to admit it teaches you a little about PHP.  WordPress, underneath it all, is a pretty big beast and its strength and ubiquitous presence comes largely, I think, from the fact that it can do virtually anything.  The really sweet plugin system, the ways hooks work, &#8220;The Loop,&#8221; the dynamic options panel &#8211; it&#8217;s all very educational.  </p>
<p>The interesting thing here is that I&#8217;ve browsed the source of <a href="http://slashcode.com">Slash</a>, <a href="http://scoop.kuro5hin.org">Scoop</a>, <a href="http://phpnuke.org">phpNuke</a>, and now <a href="http://wordpress.org">WordPress</a>, and all of them are <strong>definitively</strong> more complex and much heavier than the entire <a href='http://osnews.com'>OSNews</a> codebase. Now, before you jump all over me &#8211; firstly, Slash and Scoop are Perl, and I don&#8217;t really read Perl, so I can&#8217;t speak as an expert there.  Secondly, WordPress and Nuke both are very portable and dynamic, whereas <a href='http://osnews.com'>OSNews</a> has a narrow focus and, location-wise, is very static.  But that aside, <a href='http://osnews.com'>OSNews</a> has withstood simultaneous link bombs from <a href="http://slashdot.org">Slashdot</a> and <a href="http://digg.com">Digg</a>.  As amazing as WordPress is, it&#8217;s mostly amazing that it functions at all and loads in less than 2 minutes per page with as much going on as I can see behind the scenes.   That&#8217;s not a cut on WordPress, by the way.</p>
<p>In fact, if anything , what is really impressed upon me is how smooth and simple <a href='http://osnews.com'>OSNews</a> code is, if I may be so bold.  OSNews runs superfast due, in part, to lots of creative caching, some on-demand, some via cron.  But it also does so because of highly efficient queries that are measured for speed on their JOINs, meaning in some cases, it&#8217;s faster to do 20 simple queries than one complex one, or build a long and scary chain of &#8220;OR x=a OR x=b OR x=c OR x=d&#8230;&#8221;  Watching WordPress code in action is really fun for me, but watching <a href='http://osnews.com'>OSNews</a> work knowing what I now know about how much work PHP can cram into its threads is even more fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://firsttube.com/read/osnews-vs-wordpress/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Hacking Wordpress, Day Two</title>
		<link>http://firsttube.com/read/hacking-wordpress-day-two/</link>
		<comments>http://firsttube.com/read/hacking-wordpress-day-two/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 01:17:25 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[Meta]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Nerd]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://firsttubecom/?p=621</guid>
		<description><![CDATA[Thus far, my move to Wordpress has been an adventure.  Here&#8217;s a few lessons learned.
First off, I was very excited about the features of Wordpress.  I was really excited, most specifically, about the API, and about the rich text WYSIWYG of the backend.  I&#8217;ve done a lot of work on Small Axe&#8217;s backend, but it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Thus far, my move to Wordpress has been an adventure.  Here&#8217;s a few lessons learned.</p>
<p>First off, I was very excited about the features of Wordpress.  I was really excited, most specifically, about the API, and about the rich text WYSIWYG of the backend.  I&#8217;ve done a lot of work on Small Axe&#8217;s backend, but it&#8217;s still nothing compared to Wordpress.</p>
<p>When I imported my stuff, it worked well, but the &#8220;slugs&#8221; &#8212; or URL-friendly post titles &#8212; did not convert properly.  They converted as Wordpress friendly, properly escaped slugs.  The problem was, my slugs needed to stay intact, because I didn&#8217;t want all old links to break.</p>
<p>Understanding the way Wordpress functions is really tough for a WP newbie, because the code is so spread out, yet compact, voluminous, yet digestible.  Start with index.php, onto wp-blog-header.php, into wp-settings.php, and then you find the <strong>massive</strong> list of files in the wp-includes directory.  You&#8217;ll dig all over trying to find files to find includes in includes in includes.  I finally found a great article that tries to explain <a href="http://www.bernzilla.com/item.php?id=1007">the Wordpress slug architecture.</a> It&#8217;s fairly complex.   Much of it lives in<em>/wp-includes/query.ph</em>p.  However, my problem was very specific.</p>
<p>Many of my post slugs had periods in them.  The period does not interfere with the URL, but Wordpress doesn&#8217;t like them, and somewhere in the massive beast.     So I had to find the page that &#8220;gets&#8221; posts.  Lo and behold, there is a function called &#8220;get_posts&#8221; that lives in <em>/wp-includes/query.php</em>.  I kept poking around.  Like anyone who keeps digging, eventually, you&#8217;ll find yourself in <em>wp-includes/formatting.php</em>.  And there it is.</p>
<p>Slug posts get sanitized &#8211; like everything, virtually all input is strictly sanitized &#8211; by a function called sanitize_title_with_dashes().  This function generates the slug.  In order to include dots in your slug titles, just replace lines 366 and 267 (on Wordpress 2.6.0) with this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&amp;amp;+?;/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// kill entities</span>
<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/[^%a-z0-9 _.-]/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Then your slug titles will not strip periods.  Of course, I don&#8217;t recommend you actually use periods, I just wanted them to work when fetching old posts created before I knew any better.</p>
<p>After that adventure, I have to tell you, I&#8217;m really loving Wordpress.  There are some incredible plugins that have done some amazing functionality extension for me.  So far, so good.</p>
]]></content:encoded>
			<wfw:commentRss>http://firsttube.com/read/hacking-wordpress-day-two/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Dope Wars for the iPhone</title>
		<link>http://firsttube.com/read/Dope-Wars-for-the-iPhone/</link>
		<comments>http://firsttube.com/read/Dope-Wars-for-the-iPhone/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 10:40:15 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Nerd]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://firsttubecom/read/Dope-Wars-for-the-iPhone</guid>
		<description><![CDATA[I love my jailbroken iPhone, and I am always looking for a new &#8220;game of the week.&#8221;  I&#8217;ve been through several, at first, it was LightsOff, but that ends at 225 levels or so.  Then it was Five Dice.  Then 4 Balls, Domino, and finally PuzzleManiak.  I was so happy recently [...]]]></description>
			<content:encoded><![CDATA[<p>I love my jailbroken iPhone, and I am always looking for a new &#8220;game of the week.&#8221;  I&#8217;ve been through several, at first, it was LightsOff, but that ends at 225 levels or so.  Then it was Five Dice.  Then 4 Balls, Domino, and finally PuzzleManiak.  I was so happy recently when someone decided to port <a href="http://en.wikipedia.org/wiki/Dope_Wars">Dope Wars</a> to the iPhone in the form of &#8220;<a href="http://www.modmyifone.com/forums/showthread.php?t=112711">iDope</a>.&#8221;</p>
<p><img src="http://firsttube.com/uploads/iDope.jpg" alt="iDope" align="right" /> iDope currently has a lot of bugs.  Mainly, your jacket storage is irrelevant, you can actually store unlimited items, you just can&#8217;t buy unlimited items unless you hit &#8220;buy all.&#8221;  You can&#8217;t store money in a bank.  It never ends until you die.  You are mugged or fight the cops maybe 80% of the time you travel.  But most importantly, this: </p>
<p>Notice my dollars? That&#8217;s right, I have $2,147,483,647. Two billion, one hundred forty seven million, four hundred eighty three thousand, six hundred forty seven dollars.  Recognize that number? If you read my blog regularly, you might.  After all, it&#8217;s the <a href="http://firsttube.com/read/Integers-on-the-Intertubes">upper limit of signed integers</a>. The game is officially boring &#8211; no matter what I do, I&#8217;m always capped at that number, I can never get more money.  I wonder if the iPhone can support BIGINT.  </p>
<p>Anyway, I really hope to see iDope get some love and attention, because Dope Wars is a fabulous and addictive game, but as is, I eventually get to the upper limit and have to start over&#8230; and over&#8230; and over.</p>
]]></content:encoded>
			<wfw:commentRss>http://firsttube.com/read/Dope-Wars-for-the-iPhone/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How To REALLY Survive Digg on a Shared Host</title>
		<link>http://firsttube.com/read/how-to-really-survive-digg-on-a-shared-host/</link>
		<comments>http://firsttube.com/read/how-to-really-survive-digg-on-a-shared-host/#comments</comments>
		<pubDate>Wed, 02 Jan 2008 22:48:29 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Digg]]></category>
		<category><![CDATA[High Performance]]></category>

		<guid isPermaLink="false">http://firsttubecom/read/How-To-REALLY-Survive-Digg-on-a-Shared-Host</guid>
		<description><![CDATA[After reading a ridiculous post on &#8220;surviving the Digg effect on a shared host,&#8221; (and then laughing ridiculously at it), I decided to write a real tutorial on real-live ways not only to survive the Digg effect, but also a simple but powerful way to improve your site&#8217;s performance.  Read more within.

The fact is, [...]]]></description>
			<content:encoded><![CDATA[<p>After reading a ridiculous post on &#8220;<a href="http://digg.com/programming/How_to_Survive_Digg_on_a_Shared_Host">surviving the Digg effect on a shared host</a>,&#8221; (and then laughing ridiculously at it), I decided to write a <i>real</i> tutorial on real-live ways not only to survive the Digg effect, but also a simple but powerful way to improve your site&#8217;s performance.  Read more within.</p>
<p><span id="more-92"></span><br />
The fact is, it&#8217;s rarely PHP that crashes a website.  It&#8217;s usually overloading MySQL and/or bandwidth limitations.  Obviously, we can&#8217;t do much about bandwidth.  If you&#8217;re on a really cool host, they may be psyched for your Digging or Slashdotting, but most are not particularly keen on you using too much processor, too much bandwidth, or too many MySQL connections.  Although MySQL is capable of amazing scaling, rarely do web hosts leverage it properly, and even if they did, rarely do most programmers know how to read into slow queries, find inefficient code like loops within loops, and debug a site performance before it&#8217;s too late.  </p>
<p>The site linked from Digg shares a very lame trick, let&#8217;s examine:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//put this code at the very beginning of your page, before anything else</span>
<span style="color: #000088;">$randomdigg</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</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;">$randomdigg</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;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Thanks for visiting, but the site is under a great deal of 
stress due to being on the front page of Digg. 
Please try back in a few moments. Thanks!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ok, so essentially, approximately 25% of the time, the page will work, the other 75% of the time, the user will get the message and be asked to refresh later.  That&#8217;s really lame.  First off, unless you want your website to be functional only 25% of the time, you have to be there babysitting it when it hits front page.  Also, you need to remove this code.  But what if you wanted everything to happen automagically? What if your site could withstand a digging, a slashdotting, a redditing, an OSNews&#8217;ing, a Farking, whatever&#8230;. all at once, without being forewarned?   </p>
<p>Although there are lots of [[http://www.danga.com/memcached/|tools that can do magic for you]], you can leverage plain old PHP to do this  dirty work for you, and it&#8217;s easy to integrate into your site.  </p>
<p>Here&#8217;s the premise, we examine the referrer of the page, and if the page is from one or many domains that you specify, you build a cache ON REQUEST.  Then, you serve the cached version.  When the cache stales, say after minute or two, you refresh it, as needed, again, on request. And the best part is, it&#8217;s easy to do. </p>
<p>So, let&#8217;s review the code.  First, at the top of the page, let&#8217;s do this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$rfr</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_REFERER'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//get the referring site</span>
<span style="color: #000088;">$op</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strstr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rfr</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'digg.com'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$op</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;do-cache&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> 
<span style="color: #000088;">$cache</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/path/to/mysite/cache/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$postid</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.html&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Let&#8217;s take it line by line.  First, we get the referring site.  If it is digg.com, we&#8217;re going to turn the cache on by setting $op to &#8220;do-cache.&#8221; Note that we preset the $op variable to null to prevent abuse.  Next, we define the file we&#8217;re going to use as the cache.  Since we might want to do this for any entry/page, we&#8217;ll give it a unique address.  Remember that you do not have to use .html as an extension, since it&#8217;s static code anyway. I&#8217;ve seen &#8220;id.cache&#8221;, &#8220;id.txt&#8221;, and even just &#8220;id&#8221;.  It doesn&#8217;t matter, it will be included in a PHP page and spit out as X/HTML anyway.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$fmt</span> <span style="color: #339933;">=</span> <span style="color: #990000;">filemtime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</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;">$fmt</span> <span style="color: #339933;">&gt;</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;">180</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;Location: http://mysite.com/cache/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.html&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #990000;">exit</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;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fmt</span> <span style="color: #339933;">&gt;</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;">1800</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
         <span style="color: #666666; font-style: italic;">//cache will reload if it's been reloaded </span>
         <span style="color: #666666; font-style: italic;">//in the last half hour</span>
	   <span style="color: #000088;">$op</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;do-cache&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;">$op</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This might seem overwhelming, but it&#8217;s really not.  Check it out.  If the cache exists, regardless of referrer, we&#8217;re going to check it.  The filemtime() function will tell us when the cache was last refreshed.  If it reports a time in the last 180 seconds (you can change that number), it will redirect you to the cache.  PHP will barely have to do any work, Apache will barely have to do any work, and MySQL will not be touched at all.  Almost any host can hang in there to serve static traffic like this.  </p>
<p>But what about if the cache is old?  Once your site is no longer getting hits every three minutes, for the next 27 minutes, it will blindly reload the cache.  It will keep the cache going as long as the page has been hit in the last 30 minutes.  After no one hits the cache for 30 minutes, it will go back to fully dynamic.  When someone hits the page from digg again, it will start the caching process again.  In this case, we&#8217;re going to let the cache rebuild.  Enter the next part of the code.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$op</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;do-cache&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">ob_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If the $op variable is set to &#8220;do-cache&#8221;, our mission is&#8230; uh&#8230; to build or rebuild the cache. So, we begin with two simple PHP standard functions, <i>ob_clean()</i> and <i>ob_start()</i>.  The &#8220;ob&#8221; in these functions stands for &#8220;output buffering.&#8221;  When you buffer your output, nothing is echoed by the script, but rather written to a buffer.  In short, it&#8217;s all stored up in memory for eventual dumping later.  Now we stop the caching scripts and just write our normal HTML via PHP and MySQL.    </p>
<p>At the end of the page &#8211; the very end, after your html element is closed, you&#8217;ll need this last bit.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$op</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;do-cache&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ob_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</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: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span><span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
	<span style="color: #339933;">@</span><span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #990000;">ob_get_flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  	
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>What&#8217;s up with this? Again, if we&#8217;re building the cache, we&#8217;re getting the contents of the buffer, which contains all of our page.  Then we&#8217;re opening the cache file we specified above, and lastly, dumping the contents of the buffer into the cache file.  Our final action is to clear the buffer, which is unnecessary to us now anyway.  </p>
<p>That&#8217;s it.  Your cache is reloaded, and will be served for the next three minutes, after which it will reload the cache every 3 minutes until no one hits the site for 30 minutes.  Then it will go back to dynamic.  If another digg visitor comes, it will recache and serve the cache.  Having written several types of caching mechanisms for large sites myself, I can tell you this &#8220;cache on demand&#8221; method works.  On <a href="http://www4.osnews.com">OSNews v4</a>, we use this for things like user-specific RSS files, which aren&#8217;t plausibly built via cron jobs and, frankly, we don&#8217;t want to allow access to MySQL without limit.  They reload every 60 minutes, regardless of referer.  </p>
<p>If you maintain a site and have any concern about being Dugg, I encourage you to research some sort of caching mechanism.  Your web host will thank you, and you will be thankful for the maintained uptime and high hit count.  </p>
]]></content:encoded>
			<wfw:commentRss>http://firsttube.com/read/how-to-really-survive-digg-on-a-shared-host/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
