<?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://www.firsttube.com/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.firsttube.com</link>
	<description>crunchy nuggets, served semi-daily</description>
	<lastBuildDate>Tue, 03 Jan 2012 00:14:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Creating a JSON API</title>
		<link>http://www.firsttube.com/read/creating-a-json-api/</link>
		<comments>http://www.firsttube.com/read/creating-a-json-api/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 19:22:37 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[Phish]]></category>
		<category><![CDATA[Social Networking]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web 2.0]]></category>

		<guid isPermaLink="false">http://firsttube.com/?p=1887</guid>
		<description><![CDATA[I was assisting someone recently in building an API for their website and it occurred to me that while the current trend is generally using XML/REST/SOAP for APIs, there is quite a bit of benefit to using plain old Javascript &#8230; <a href="http://www.firsttube.com/read/creating-a-json-api/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was assisting someone recently in building an API for their website and it occurred to me that while the current trend is generally using XML/REST/SOAP for APIs, there is quite a bit of benefit to using plain old Javascript and JSON.  Most users won&#8217;t venture into API territory, so if your goal is to make your API accessible &#8211; and this goes double if your primary purpose is embedding content in a third party site &#8211; it&#8217;s hard to argue with Javascript.</p>
<p>The <a href="http://api.phish.net">Phish.net API</a>, for example, is a simple HTTP request to an endpoint that returns JSON.  If you provide a callback function name as an argument, and then pre-define that function, it will return the contents wrapped in a function call.  In short, if you define a function called &#8220;example()&#8221; that accepts JSON an array/object as an argument, then by requesting the API with a callback of &#8220;example&#8221;, the response will be returned like so:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">example<span style="color: #009900;">&#40;</span>json response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The benefit, of course, is that it allows a user to embed your code easily.  If you host your own callback functions, you can very easily walk a user through a data embed.  For example, on Phish.net, we offer the band&#8217;s latest setlist.  So we host a callback called pnet3setlist().  Then we offer the API response.  Embedding the setlist is literally as easy as this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://api.phish.net/callbacks/pnet3-setlist.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;https://api.phish.net/api.json?method=pnet.shows.setlist.recent&amp;amp;amp;callback=pnet3setlist&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>I&#8217;m going to dig more into this later, but the gist of this is that the API can be constructed in a way that allows novice users to interact with it in their WordPress- or Blogger-blogs with little to no modification, it allows semi-skilled users to modify it slightly and tweak it for display purposes, and it allows advanced users to control virtually all aspects.  Since virtually every major web language can encode and decode JSON (Javascript, PHP, Ruby, ASP, etc), it&#8217;s a near-universal way to exchange data.  It doesn&#8217;t carry the overhead or complexity of XML, nor does it have the limited scope of something like serialized PHP.</p>
<p>Javascript-based APIs may not be the ultimate solution to a fully interconnected web, but they&#8217;re certainly going to be one of the best and simplest methods of data exchange for the foreseeable future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/creating-a-json-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Guide to Base Changing For Short URLs</title>
		<link>http://www.firsttube.com/read/a-guide-to-base-changing-for-short-urls/</link>
		<comments>http://www.firsttube.com/read/a-guide-to-base-changing-for-short-urls/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 19:09:56 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Nerd]]></category>

		<guid isPermaLink="false">http://firsttube.com/?p=1670</guid>
		<description><![CDATA[Some time ago, I developed a VERY simple way to fake a bit.ly-style short URL. On any server that uses any form of an integer to identify an article (either in the database or the URL), on an Apache server &#8230; <a href="http://www.firsttube.com/read/a-guide-to-base-changing-for-short-urls/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Some time ago, I developed a VERY simple way to fake a bit.ly-style short URL.  On any server that uses any form of an integer to identify an article (either in the database or the URL), on an Apache server that supports mod_rewrite, you edit your .htaccess file like so:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">RewriteEngine Off
<span style="color: #000000; font-weight: bold;">&lt;</span>ifmodule mod_rewrite.c<span style="color: #000000; font-weight: bold;">&gt;</span>
RewriteEngine On
RewriteBase <span style="color: #000000; font-weight: bold;">/</span>
RewriteCond <span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>REQUEST_FILENAME<span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #000000; font-weight: bold;">!</span>-f
RewriteCond <span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>REQUEST_FILENAME<span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #000000; font-weight: bold;">!</span>-d
RewriteCond <span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>REQUEST_URI<span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #000000; font-weight: bold;">!</span>^index.php$
RewriteRule . index.php <span style="color: #7a0874; font-weight: bold;">&#91;</span>NC,L<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>ifmodule<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>This essentially tells your server to redirect anything that isn&#8217;t a file or directory to index.php.</p>
<p>Then index.php looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">base_convert</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">36</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//this is where you either query your database for a slug or build the URL</span>
<span style="color: #000088;">$uri</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://your-site-goes-here.com/path/to/article'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uri</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;">'HTTP/1.1 301 Moved Permanently'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Link: &lt; '</span><span style="color: #339933;">.</span><span style="color: #000088;">$uri</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&gt;; rel=shortlink&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$uri</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: http://your-site-goes-here.com/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>How do you get your short links? That&#8217;s easy.  Just run this function:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$shorturl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">base_convert</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">36</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>However, this isn&#8217;t the most compact way to condense.  Obviously, this is base36, the highest PHP can go.  But what about uppercase letters? And other characters?</p>
<p>So I set out, for some reason, to build a better condenser.</p>
<p>This is the result of several hours of work, mostly wasted, on some intellectual pursuit that was more a case of simply not letting it defeat me.  A few notes: I&#8217;m quite confident that given enough time, and if I cared, I could make the code cleaner and more efficient in some places. I&#8217;m also aware that on 32 bit machines, it maxes out at the integer limit. I does support signed integers though, from min to max.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ft_str</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'0123456789abcdefghijklmnopqrstuvqwxyzABCDEFGHIJKLMNOPQRSTUVQWXYZ'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;"># uncomment the next line if you prefer to use potentially non-URL-safe base96
</span><span style="color: #666666; font-style: italic;"># $ft_str .= '0123456789abcdefghijklmnopqrstuvqwxyzABCDEFGHIJKLMNOPQRSTUVQWXYZ_@$!#%^&amp;*()=+\|}{][,;:~'; }
</span>
<span style="color: #000088;">$powers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$p</span><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span><span style="color: #000088;">$p</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$powers</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ft_str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> ft_unconvert<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</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;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'-'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$pfx</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: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$pfx</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: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$ft_str</span><span style="color: #339933;">,</span><span style="color: #000088;">$powers</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$base</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ft_str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_split</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strrev</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$len</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</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;">$s</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;">$sp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ft_str</span><span style="color: #339933;">,</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$decimal</span> <span style="color: #339933;">+=</span> <span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$base</span><span style="color: #339933;">,</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #000088;">$sp</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$pfx</span><span style="color: #339933;">.</span><span style="color: #000088;">$decimal</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> ft_converter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$int</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$int</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$pfx</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">;</span> <span style="color: #000088;">$int</span><span style="color: #339933;">=</span><span style="color: #990000;">abs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$int</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$pfx</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: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$ft_str</span><span style="color: #339933;">,</span><span style="color: #000088;">$powers</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$base</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ft_str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_split</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">krsort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$powers</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;">$powers</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: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$int</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;">$timesinto</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$int</span><span style="color: #339933;">/</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$digit</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$ft_str</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$timesinto</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$int</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$int</span> <span style="color: #339933;">%</span> <span style="color: #000088;">$v</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;">$int</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$k</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$digit</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$ft_str</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$int</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$int</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$int</span> <span style="color: #339933;">%</span> <span style="color: #000088;">$v</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$pfx</span><span style="color: #339933;">.</span><span style="color: #000088;">$digit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> ft_convert_demo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$ft_str</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ftc</span> <span style="color: #339933;">=</span> ft_converter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;Converting &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$num</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; into base &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ft_str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ftc</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;br /&gt;Unconverting &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ftc</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; to base 10: &quot;</span><span style="color: #339933;">.</span>ft_unconvert<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ftc</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> ft_convert_demo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'50687'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/a-guide-to-base-changing-for-short-urls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;ve Been Hacked! WP-Lytebox Sucks</title>
		<link>http://www.firsttube.com/read/ive-been-hacked-wp-lytebox-sucks/</link>
		<comments>http://www.firsttube.com/read/ive-been-hacked-wp-lytebox-sucks/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 21:36:16 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://firsttube.com/?p=1600</guid>
		<description><![CDATA[This is the third time I&#8217;ve had to spent serious time &#8220;fixing&#8221; WordPress.  Say what you will about my old &#8220;Small Axe&#8221; or &#8220;Flip&#8221; solutions, but I never had a problem.  With WordPress, I have found regular issues. This time, &#8230; <a href="http://www.firsttube.com/read/ive-been-hacked-wp-lytebox-sucks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img style="width: 150px; height: 150px; padding: 5px; float: right;" src="http://firsttube.com/uploads/2010/04/wordpress-hack-150x150.jpg" alt="Hacking WordPress" />This is the third time I&#8217;ve had to spent serious time &#8220;fixing&#8221; WordPress.  Say what you will about my old &#8220;Small Axe&#8221; or &#8220;Flip&#8221; solutions, but I never had a problem.  With WordPress, I have found regular issues.</p>
<p>This time, I traced the problem back to wp-lytebox, and I&#8217;m ashamed to say I&#8217;ve had to fix the same problem before.  It all started when I couldn&#8217;t load the post page in the backend of <a href='http://firsttube.com'>firsttube.com</a>.  Digging in, I eventually found a file called sys.php in the root of the site, and it listed the contents of my site and had a form that allowed someone to add a page, chmod a page, or delete a page.  Killer!</p>
<p>I found that it was defaulting to <em>/path/to/WP/wp-includes/plugins/wp-lytebo</em>x, and sure enough, digging into that directory revealed several other fun scripts, all of which gave someone the ability to access all the files on my site.  Fun!</p>
<p>I found that I already had replaced this plugin before, so I decided to get rid of it altogether, this now proving it wasn&#8217;t a misconfiguration, but rather, <a href="http://www.f-secure.com/vulnerabilities/SA200902421">a problem with the wp-lytebox itself</a>.</p>
<p>In this process, however, I was unable to fix my issue.  Visiting <em>/wp-admin/post-new.php</em> still rendered only a page footer, and nothing more.</p>
<p>So I starting fooling around in my directories looking for files that had been modified more recently than when I did my 2.9.2 upgrade.  One of the files? My <em>.htaccess</em> file.</p>
<p>&#8220;<em>This be odd,</em>&#8221; I thought to myself, &#8220;<em>I&#8217;ve changed this not, methinks.</em>&#8221;</p>
<p>Sure enough, there was a rogue line within: RewriteCond ^/default/$ /wp-admin/includes Huh?</p>
<p>I dug into that folder, and the .htaccess file there was recent too? It&#8217;s contents? <em>DefaultIndex users.php</em></p>
<p>Of course, I immediately opened users.php and found, as you might have guessed, a bunch of Russian crap. Savvy WP hackers will know, it&#8217;s not a real file, there is no users.php in the real wp-admin/includes directory.</p>
<p>I also found a folder that had two large files, both named core.XXXX where XXXX was a 4 digit number, and a massive 40 MB error_log.  Yikes.</p>
<p>I thought I had everything cleaned out, and I truly believed that the way in was wp-lytebox.  Then <a href="http://wordpress.org/support/topic/379659">I found this</a>.  And sure enough, all of the listed files were compromised.  So I nuked all the files, and replaced them all.  D&#8217;oh!</p>
<p>So, if you&#8217;re arriving via Google or Bing or Yahoo!, do NOT use wp-lytebox.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/ive-been-hacked-wp-lytebox-sucks/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Javascript Ninja!</title>
		<link>http://www.firsttube.com/read/javascript-ninja/</link>
		<comments>http://www.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 &#8230; <a href="http://www.firsttube.com/read/javascript-ninja/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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://www.firsttube.com/read/javascript-ninja/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Behind the Scenes at OSNews</title>
		<link>http://www.firsttube.com/read/behind-the-scenes-at-osnews/</link>
		<comments>http://www.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 &#8230; <a href="http://www.firsttube.com/read/behind-the-scenes-at-osnews/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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://www.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://www.firsttube.com/read/flip-301/</link>
		<comments>http://www.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, &#8230; <a href="http://www.firsttube.com/read/flip-301/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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://www.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://www.firsttube.com/read/posting-your-latest-tweet-in-wordpress/</link>
		<comments>http://www.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, &#8230; <a href="http://www.firsttube.com/read/posting-your-latest-tweet-in-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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://www.firsttube.com/read/posting-your-latest-tweet-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to Add Latest Tweet to WordPress (Without a Plugin)</title>
		<link>http://www.firsttube.com/read/how-to-add-latest-tweet-to-wordpress/</link>
		<comments>http://www.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 &#8230; <a href="http://www.firsttube.com/read/how-to-add-latest-tweet-to-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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://www.firsttube.com/read/how-to-add-latest-tweet-to-wordpress/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>WordPress &#8220;Press This&#8221; 404 Problem</title>
		<link>http://www.firsttube.com/read/wordpress-press-this-404-problem/</link>
		<comments>http://www.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://www.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://www.firsttube.com/read/sorting-a-multi-dimensional-array-with-php/</link>
		<comments>http://www.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; &#8230; <a href="http://www.firsttube.com/read/sorting-a-multi-dimensional-array-with-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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://www.firsttube.com/read/sorting-a-multi-dimensional-array-with-php/feed/</wfw:commentRss>
		<slash:comments>76</slash:comments>
		</item>
		<item>
		<title>firsttube.com Upgraded To WordPress 2.7</title>
		<link>http://www.firsttube.com/read/firsttubecom-upgraded-to-wordpress-27/</link>
		<comments>http://www.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 &#8230; <a href="http://www.firsttube.com/read/firsttubecom-upgraded-to-wordpress-27/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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://www.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://www.firsttube.com/read/using-the-abbr-tag/</link>
		<comments>http://www.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 &#8230; <a href="http://www.firsttube.com/read/using-the-abbr-tag/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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://www.firsttube.com/read/using-the-abbr-tag/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My First Plugin</title>
		<link>http://www.firsttube.com/read/my-first-plugin/</link>
		<comments>http://www.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 &#8230; <a href="http://www.firsttube.com/read/my-first-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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://www.firsttube.com/read/my-first-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Weirdness</title>
		<link>http://www.firsttube.com/read/php-weirdness/</link>
		<comments>http://www.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 &#8230; <a href="http://www.firsttube.com/read/php-weirdness/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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://www.firsttube.com/read/php-weirdness/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>OSNews vs. WordPress</title>
		<link>http://www.firsttube.com/read/osnews-vs-wordpress/</link>
		<comments>http://www.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 &#8230; <a href="http://www.firsttube.com/read/osnews-vs-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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://www.firsttube.com/read/osnews-vs-wordpress/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

