Archive for April, 2010

April 29th, 2010

Flash and Apple from my perspective.

Steve Jobs recently wrote a letter addressing his Thoughts on Flash for iPhone/iPod/iPad. You can read it here:

Following Jobs posting there were numerous responses, a great one coming from Adam Banks in a post titled Thoughts on Thoughts on Flash. After reading it, I actually had mixed feelings on an issue where I have been pretty black and white to this point. Color me intrigued. I still feel after having used HTML5 on some small projects that as a cost effective mass market consumer ready technology, HTML5 is a ways off (2-3 years). It’ll be interesting to see how this plays out from a consumer perspective. As a developer this just means I have another technology to learn (w00t for me) and another content delivery mechanism to develop for.

Personally I enjoy the challenge of learning new technology, but it definitely isn’t the most efficient way to do business. I learned this when I made a switch from Flash to Silverlight. A project that I could quickly and accurately budget out resource wise became a shot in the dark. I would grossly under or over estimate the time needed because I wasn’t familiar with the technology. That’s what companies, like PBJS, will have to do if they want to adopt HTML5 in favor of proprietary, but familiar, plugins (Flash/Silverlight).  That also means that developers will have to support that choice both with time invested in learning it, and optimizing it to create the best possible user experience.

Content is still king. If your content generates the traffic you can easily justify any expense to make the user experience better whether that is open standards (HTML5), mobile apps (iPhone), or web plugin. It’s when you are building your business that these multiple distribution technologies can hinder progress. Delivering your content via HTML5 right now you won’t have the same rich experience that it would inside a plugin. Also, I’d be surprised if your agency has HTML5 experts on staff. Plus, they can be hard to find in the freelance market. Today the question is; do you deliver your content using a more costly (resources & time) and a sub-standard user experience using the technology “of the future” or do you choose the “dead technology” that can provide a cost effective and engaging user experience?

Apple may be forward thinking, but not everyone has pockets as deep as Apple. I’ll continue to look into techniques using HTML5/CSS3/JavaScript but it’s likely that I’ll continue to get paid to create plugin based experiences, at least for another year. As for those clients that want to do it the Apple way, I’ll get paid double for developing using two different workflows. Looks like I’ll be busy.

April 28th, 2010

Simple PHP Twitter script

UPDATE: The new Twitter API v1.1 no longer supports this code. You will need to authenticate before using it. Here is a little tutorial on how to do that

I broke out this useful little PHP Twitter script from the WordPress theme jessica-fletcher-redux, which happens to be the theme I used as a template for this blog. There were a few issues I needed to overcome in order to make this work. I’m hosting this WordPress blog on Windows Server running IIS7. By default many PHP functions are disabled for security so you have to implement a work around.

The get_url_contents($url) function was added to overcome a security problem on IIS where file_get_contents() is not allowed. The other issues to is to make sure you grant write permission to PHP so it can write to your twittercache.xml file. These two changes make for a very clean twitter readout that can easily be styled using CSS.


function get_url_contents($url){
        $crl = curl_init();
        $timeout = 5;
        curl_setopt ($crl, CURLOPT_URL,$url);
        curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
        $ret = curl_exec($crl);
        return $ret;

function generatetwitter($twittername){

	$username = $twittername; // Your twitter username.
	if ($username == ""){
		$username = "discorax";
	$limit = "15"; // Number of tweets to pull in.
	/* These prefixes and suffixes will display before and after the entire block of tweets. */
	$prefix = ""; // Prefix - some text you want displayed before all your tweets.
	$suffix = ""; // Suffix - some text you want displayed after all your tweets.
	$tweetprefix = "<li>"; // Tweet Prefix - some text you want displayed before each tweet.
	$tweetsuffix = "</li> \r"; // Tweet Suffix - some text you want displayed after each tweet.
	$feed_string = "" . $username . "&rpp=" . $limit;  

 function parse_feed($feed, $prefix, $tweetprefix, $tweetsuffix, $suffix, $username) {
		$feed = str_replace("<", "<", $feed);   		$feed = str_replace(">", ">", $feed);
		$clean = explode("<content type=\"html\">", $feed);
		$link = explode(",2005:", $feed);
		$amount = count($clean) - 1;
		echo $prefix;
			for ($i = 1; $i <= $amount; $i++) {   				$cleaner = explode("</content>", $clean[$i]);
				$linker = explode("</id>", $link[$i+1]);
				$this_tweets = str_replace("&apos;", "'", $cleaner[0]);
				$this_tweets = str_replace("&gt;", ">", $this_tweets);
				$this_tweets = preg_replace('!<a href.*?>!', '', $this_tweets);
				$this_tweets = preg_replace('!</a>!', '', $this_tweets);
				echo $tweetprefix.'<a href="'.$username.'/status/';
				echo $linker[0];
				echo '" target="_blank">'.$this_tweets.'</a>';
				echo $tweetsuffix;
		echo $suffix;

	$twitter_cache_file = 'twittercache.xml';

	$mtime= null;

	if($mtime== null ||(time()-$mtime)>(9*60)){// 9 minutes or older?

	if (!@file_get_contents($twitter_cache_file)){
		  echo __('Oops, something went wrong. Did you rename the cache folder? The cache file? You shouldn\'t have done that...', 'jfr_theme');
	}else {
		  $twitterFeed = file_get_contents($twitter_cache_file);

	parse_feed($twitterFeed, $prefix, $tweetprefix, $tweetsuffix, $suffix, $username);  


Setup is easy. You simply need to call the generatetwitter() function like so.

echo "<div>";
echo "<ul>";
echo "</ul></div>";

When you’re uploading the files to your server make sure to include a blank twittercache.xml file in the same directory as the script. You can change this location by changing the value of the $twitter_cache_file variable (line 48 above) to a path where you keep the twittercache.xml file (make sure you grant write permission to that folder).

That’s it. It’s a clean little code snippit for pulling a user’s twitter feed which you can easily extend using a simple form to select your twitter account. Happy coding.