Author Archives: John Herren

About John Herren

John Herren is a developer and technical consultant with focus on web applications. He currently serves as Director of Development for Primetime US, the company behind the hit movie and book The Secet. John was formerly staff writer and developer community evangelist for Zend Technologies. Along with founding neat experiments like TagCloud.com, John is an active member in the mashup community, working with API providers and speaking at conferences. He is a published author of Linux certification study material. John enjoys using open source software like PHP and Ruby on Rails to bend the web into exciting new chimeras of hyperlinked goodness.

Liz at the Inauguration

Liz and her mom Audrey made the long haul to D.C. for the swearing in, leaving me at home for a week of bachelorhood/debauchery/lonelyness.

They decided to go for the cheap seats and watch from the Lincoln Memorial, and grabbed a nice spot on the steps. When we spoke yesterday through the saturated cellphone tubes, she told me she had done an interview with the Washington Post. While her interview was not published (that we know of), she and Audrey, and Audrey’s friend Dixie can be spotted in the background. Liz is the upper left in the blue coat, sending a Twitter message from her pink-clad iPhone.

LizAtInauguration

(click for fullsize)

The screencap is from 2:11 in the video, which is the one titled “The Swearing In”.


Mashup Sighting

Via the Hype Machine blog, I just found one of my mashups, Gblinker, mentioned in a textbook called Business Driven Technology. Chapter 14 has a section on mashups, and here’s a photo of the page. Judging by the other entries on the page, it looks like this section was lifted from the speek geeking page from the Mashup Camp III in Boston.

The idea for Gblinker was simple. At some of the conferences I attended, Google handed out some fun blinky LED pins as swag. I thought it would be a cool idea to rig one up to a computer and have it blink whenever I received a Gmail message. So to be lazy I decided to reuse what I could find instead of writing a program from scratch. I knew there was a Gmail widget for the Yahoo widget engine (formerly Konfabulator), so I started there. In the documentation, I discoveded that Yahoo widgets could make COM calls–what luck! So I wrote a simple dll in C# to flip on and off the serial port’s RTS bit, and modified the Gmail widget to call the dll. That’s all there was to it. The fun hack ended up winning 5th or 6th place at Mashup Camp in Boston, and as far as I know, was the first hardware mashup from any of the camps. The prize: a copy of Visual Studio :)

It’s always fun to see things you’ve done pop up out of nowhere, especially in dead-tree version. My favorite surprise was when my TagCloud prototype ended up in the book Yahoo Hacks. Coincidentally, the free sample chapter (PDF link) just happens to be the one on TagCloud.


Laura Ann’s Music Debut

My niece, Laura Ann, spent some time with us over the weekend. Since I was recovering from the flu, we decided to have some relaxed playtime–a nice departure from the normal high-energy entertainment.

Laura Ann, 7, LOVES to play with PhotoBooth on the Mac, but finally grew tired of it after a while, so I though we would give Garage Band a try.  And boy, fun was had! Coming from the days of early PC based multitracking (ah, Cool Edit Pro, how I loved thee), I was quite impressed with the ease of Garage Band as well as the internal mic on the macbook. Here’s the result of some of the songs she recorded. She picked out the instrument arrangements from the included song catalog all by herself, and improvised all the lyrics in a bunch of one-takes. There’s no punch-in’s; all I did was bump her vocal track a tad and added some cheezy Garage Band effects. I absolutely loved the results and I’m sure we’ll be doing this some more in the future. 

The first song is one she’s doing with her school for Halloween. I’d heard her singing it randomly–she sings all the time–so i figured we might as well lay it down. Here’s “Five Little Pumpkins”

The next one is my favorite, “Funky Baby”. I had her list some funky stuff to be the lyrics and she came up with “Funky Baby, Turnip Greens, Funky Monkey, Cole Slaw, Cereal Box”. 

Next up is the roots ballad “I Love” which is destined to be a classic. She just sang about stuff she loves. No doubt the zoo tops that list, but I’m glad to be on it eventually. I especially like her lyric “I want to see what’s up there, in the serious beyond. I don’t know what to see with my eyes, it’s so special” And more howling.. she’s into wolves right now.

Laura Ann Herren

Finally is the way-over-the-top “I Have the Blues”. Pretty much speaks for itself.


Google Adsense for Feeds

Looks like Google is now supporting Adsense ads for RSS feeds.

I remember the good ol’ days of Adsense. Now it’s about as ubiquitous as hit counters were in the 90′s. Still, I sure don’t mind seeing those Google checks in the mail, although they are fewer and further between these days.

The lack of Adsense support for feeds has been a pain point for bloggers and sploggers alike. Several startups exist solely to plug that hole. I guess we should get ready to start seeing ads in our feeds as often they appear on sites.

One more reason to love the keyboard shortcuts in Google Reader.

The announcement (if you must):

Inside AdSense: I feel the need… the need for feeds


Getting the number of posts per category in WordPress

This morning JTk presented me a WordPress riddle:

What I would like to be able to do is ask the MySQL if a category has any posts in it or if it is empty.  So I can do one thing if there are posts there and another if that category is empty.  And try as I might, no matter how hard I beat my head against it, all I get is a bruised head.  And, yes, I have to do this conditional because WP is flawed and will break if I try and do certain things with empty categories…..

Here is the schema ( maybe it helps )
http://blog.kapish.co.in/wp-content/uploads/2008/01/wp_db.png

And the worst part of this, is – I know this is trivial so I hate to even ask, but I guess I don’t hate enough not to ask :)  I asked the “community” and got told that there is not a WP function for this ( um, yeah, thanks…. ) that I shouldn’t make straight db calls ( arrrggg ), and that there are plugins that accomplish similar things….  But no real help, so I decided to ask a ninja….

So we want to get the number of posts per category. JTk, you’re in luck! A quick look at the schema (if that diagram is current) tells me we could query the wp_post2cat table and do a COUNT and a GROUP BY query on the category of interest. Even better, if wp_categories.category_count is what I think it is, that’s a simpler query. But let’s see what the code gives us already. In category.php, there are some tasty sounding functions like get_categories(), get_category(), get_category_by_path(), get_category_by_slug() and so on. I installed a clean version of WordPress, added some categories and assigned some fake posts to them. Then I tried some of these functions to see what’s up.

<?php var_dump(get_categories()); ?>

Output:

array(3) {
  [1]=>
  object(stdClass)#68 (15) {
    ["term_id"]=>
    &string(1) "3"
    ["name"]=>
    &string(14) "First Category"
    ["slug"]=>
    &string(14) "first-category"
    ["term_group"]=>
    string(1) "0"
    ["term_taxonomy_id"]=>
    string(1) "3"
    ["taxonomy"]=>
    string(8) "category"
    ["description"]=>
    &string(0) ""
    ["parent"]=>
    &string(1) "0"
    ["count"]=>
    &string(1) "4"
    ["cat_ID"]=>
    &string(1) "3"
    ["category_count"]=>
    &string(1) "4"
    ["category_description"]=>
    &string(0) ""
    ["cat_name"]=>
    &string(14) "First Category"
    ["category_nicename"]=>
    &string(14) "first-category"
    ["category_parent"]=>
    &string(1) "0"
  }
  [2]=>
  object(stdClass)#69 (15) {
    ["term_id"]=>
    &string(1) "4"
    ["name"]=>
    &string(15) "Second Category"
    ["slug"]=>
    &string(15) "second-category"
    ["term_group"]=>
    string(1) "0"
    ["term_taxonomy_id"]=>
    string(1) "4"
    ["taxonomy"]=>
    string(8) "category"
    ["description"]=>
    &string(0) ""
    ["parent"]=>
    &string(1) "0"
    ["count"]=>
    &string(1) "2"
    ["cat_ID"]=>
    &string(1) "4"
    ["category_count"]=>
    &string(1) "2"
    ["category_description"]=>
    &string(0) ""
    ["cat_name"]=>
    &string(15) "Second Category"
    ["category_nicename"]=>
    &string(15) "second-category"
    ["category_parent"]=>
    &string(1) "0"
  }
  [3]=>
  object(stdClass)#90 (15) {
    ["term_id"]=>
    &string(1) "1"
    ["name"]=>
    &string(13) "Uncategorized"
    ["slug"]=>
    &string(13) "uncategorized"
    ["term_group"]=>
    string(1) "0"
    ["term_taxonomy_id"]=>
    string(1) "1"
    ["taxonomy"]=>
    string(8) "category"
    ["description"]=>
    &string(0) ""
    ["parent"]=>
    &string(1) "0"
    ["count"]=>
    &string(1) "1"
    ["cat_ID"]=>
    &string(1) "1"
    ["category_count"]=>
    &string(1) "1"
    ["category_description"]=>
    &string(0) ""
    ["cat_name"]=>
    &string(13) "Uncategorized"
    ["category_nicename"]=>
    &string(13) "uncategorized"
    ["category_parent"]=>
    &string(1) "0"
  }
}

OK, so it sounds like the person who told JTk there were no built-in WordPress functions for this was lying :)  This function tells us exactly what we need. A couple of interesting observations, though. I had a category named “Empty Category” with no posts, which does not show up here. The documentation page tells me that I can pass a parameter to include the empty ones easily enough:

<?php var_dump(get_categories(array(‘hide_empty’=>false))); ?>

array(4) {
  [0]=>
  object(stdClass)#67 (15) {
    ["term_id"]=>
    &string(1) "5"
    ["name"]=>
    &string(14) "Empty Category"
    ["slug"]=>
    &string(14) "empty-category"
    ["term_group"]=>
    string(1) "0"
    ["term_taxonomy_id"]=>
    string(1) "5"
    ["taxonomy"]=>
    string(8) "category"
    ["description"]=>
    &string(0) ""
    ["parent"]=>
    &string(1) "0"
    ["count"]=>
    &string(1) "0"
    ["cat_ID"]=>
    &string(1) "5"
    ["category_count"]=>
    &string(1) "0"
    ["category_description"]=>
    &string(0) ""
    ["cat_name"]=>
    &string(14) "Empty Category"
    ["category_nicename"]=>
    &string(14) "empty-category"
    ["category_parent"]=>
    &string(1) "0"
  }
  [1]=>
  object(stdClass)#68 (15) {
    ["term_id"]=>
    &string(1) "3"
    ["name"]=>
    &string(14) "First Category"
    ["slug"]=>
    &string(14) "first-category"
    ["term_group"]=>
    string(1) "0"
    ["term_taxonomy_id"]=>
    string(1) "3"
    ["taxonomy"]=>
    string(8) "category"
    ["description"]=>
    &string(0) ""
    ["parent"]=>
    &string(1) "0"
    ["count"]=>
    &string(1) "4"
    ["cat_ID"]=>
    &string(1) "3"
    ["category_count"]=>
    &string(1) "4"
    ["category_description"]=>
    &string(0) ""
    ["cat_name"]=>
    &string(14) "First Category"
    ["category_nicename"]=>
    &string(14) "first-category"
    ["category_parent"]=>
    &string(1) "0"
  }
  [2]=>
  object(stdClass)#69 (15) {
    ["term_id"]=>
    &string(1) "4"
    ["name"]=>
    &string(15) "Second Category"
    ["slug"]=>
    &string(15) "second-category"
    ["term_group"]=>
    string(1) "0"
    ["term_taxonomy_id"]=>
    string(1) "4"
    ["taxonomy"]=>
    string(8) "category"
    ["description"]=>
    &string(0) ""
    ["parent"]=>
    &string(1) "0"
    ["count"]=>
    &string(1) "2"
    ["cat_ID"]=>
    &string(1) "4"
    ["category_count"]=>
    &string(1) "2"
    ["category_description"]=>
    &string(0) ""
    ["cat_name"]=>
    &string(15) "Second Category"
    ["category_nicename"]=>
    &string(15) "second-category"
    ["category_parent"]=>
    &string(1) "0"
  }
  [3]=>
  object(stdClass)#90 (15) {
    ["term_id"]=>
    &string(1) "1"
    ["name"]=>
    &string(13) "Uncategorized"
    ["slug"]=>
    &string(13) "uncategorized"
    ["term_group"]=>
    string(1) "0"
    ["term_taxonomy_id"]=>
    string(1) "1"
    ["taxonomy"]=>
    string(8) "category"
    ["description"]=>
    &string(0) ""
    ["parent"]=>
    &string(1) "0"
    ["count"]=>
    &string(1) "1"
    ["cat_ID"]=>
    &string(1) "1"
    ["category_count"]=>
    &string(1) "1"
    ["category_description"]=>
    &string(0) ""
    ["cat_name"]=>
    &string(13) "Uncategorized"
    ["category_nicename"]=>
    &string(13) "uncategorized"
    ["category_parent"]=>
    &string(1) "0"
  }
}

Sure enough,there is the empty category. I also noticed that the article count appears in both ->count and ->category_count. I’ll just assume the cached version, ->category_count, will remain correct through the code, but I’m just guessing it doesn’t matter which member we use.

So, that’s fine if we want the whole collection, but what about individual categories? Fortunately, we can extract this same data for both the category ID as well as the name of the category. Here’s an example of each, querying my “First Category” category:

Using ->category_count

<?php var_dump( (int) get_category(’3′)->category_count); ?>

<?php var_dump( (int) get_category_by_slug(‘First Category’)->category_count; ?>

<?php var_dump( (int) get_category_by_slug(‘first-category’)->category_count); ?>

Using ->count

<?php var_dump( (int) get_category(’3′)->count); ?>

<?php var_dump( (int) get_category_by_slug(‘First Category’)->count; ?>

<?php var_dump( (int) get_category_by_slug(‘first-category’)->count); ?>

All of these return the correct result, int(4). Good on ya, WordPress.

Now let’s see how robust the function is. Will it choke on a non-existent category, or return a zero like it should?

<?php var_dump( (int) get_category(’6969′)->category_count); ?>

<?php var_dump( (int) get_category_by_slug(‘This Damn Category’)->category_count); ?>

Both of these do indeed return zero, which is nice and correct.

In practical terms, you can use this code stub to do something will all categories depending on whether or not there are posts:

foreach (get_categories(array('hide_empty'=>false)) as $category){
	if ($category->count > 0){
		//has posts, do something
	}else{
		//no posts, do something else
	}
}

That’s all there is to it!  There’s definitely a built in function to inspect categories, and even some nice examples to go with. Happy WordPress hacking, and don’t forget that now’s the time to upgrade to PHP 5 if you haven’t already :)


The beginning of the end of PHP’s popularity?

“there will be no more PHP 4 releases, regardless of whether there are security issues found in PHP 4.”

Whoa. Is PHP shooting itself in the foot here?

Despite recent hating and negativity of PHP as a programming language, there’s no debate that PHP still rules as the most popularly deployed scripting language for the web. If you separate PHP developers from those just running PHP applications, that gap widens even further. Ease of deployment for PHP apps plays a huge role in its popularity versus other languages like Python and Ruby, despite the fact there are very capable web frameworks for both. It doesn’t get much easier than purchasing a $5/mo. shared hosting account, slapping WordPress on it and having a website. But could today’s last release of PHP version 4 bring about the beginning of the end of the language’s widespread popularity as a clear leader?

Today Derick Rethans, the release manager for PHP announced version 4.4.9, which is to be the last release of version 4:

“Now, more than 3 years after the last major PHP 4 release, it is time to die down. With hardly any support for OO, sub-standard XML support and generally lots of other suckyness as well, it’s time to focus on the future: PHP 6. So please die PHP 4 – and quickly. Today, August 7th, 2008 is the last release of PHP 4 – PHP 4.4.9. After today there will be no more PHP 4 releases, regardless of whether there are security issues found in PHP 4. It’s time to upgrade now.” [link]

Now, there are reasons that popular software for PHP is to this very day still written for PHP 4. A large number of hosting providers have not made the jump to version 5. While both versions can be run simultaneously, the solution is not optimal, and a bit of a hack. A little over a year ago, Matt Mullenweg of WordPress stated his reason for not abandoning version 4. I personally disagree with his apparent “if it ain’t broke don’t fix it” attitude:

WordPress works just as well with PHP 5 as 4, and there are no features on the roadmap (including ones on your list) that would require PHP 5. The only reason for us to break PHP 4 compatibility would be political, and our users without the ability to upgrade their server would be the ones who lose. WordPress doesn’t make PHP 4 interesting or not, it’s agnostic.” [link]

I certainly agree that Matt should have his user base in mind, and that yes, WordPress as an application is not novel because of the language it is written in, but to say there is no advantage to using the PHP 5 features in the development is a bit dubious.

But now there’s a new dilemma facing both the hosting providers and application developers such as WordPress; namely, the “vendor” of PHP 4 is closing shop. As far as official PHP releases are concerned, there will be no bug fixes, security updates, feature additions, or optimizations. What will happen if a serious security hole is found? I’m not preaching FUD, but being realistic based on history. At what point will hosting providers have to upgrade? Will the application developers follow suit and take advantage of the PHP 5 features and benefits? More importantly, will the ease of use of frameworks like Rails and Django bring about the “killer apps” for the world’s blogging, e-commerce, mailing list management, classified ads, and other applications that put PHP where it is today? Is Typo indeed the next WordPress?

It’s no secret I’m a fan of PHP, warts and all. PHP will do fabulous things for you as the glue language that it is. There are plenty times when I don’t need a full-stack MVC that would just be wasteful. I wholeheartedly agree that Rails is a joy to develop with, even if it’s a pain to deploy, but I would challenge anyone to a pure Ruby vs. pure PHP hackathon to prove you can write “cowboy code” in any language.

As far as my predictions for PHP’s popularity ranking, I’m really not worried. The upgrade is not bad, the building and configuring of the software across versions follows the same conventions. Porting applications, if they need it at all, is a modest task. For PHP to lose its foothold among hosting providers, better app solutions from other languages would have to exist, become wildly popular, and have good community support for updates. Simultaneously, the frameworks and server libraries would have to be stable enough for hosting providers to support and provision. So really the choice is: modest upgrade to PHP 5, or complete overhaul to trendier languages and frameworks? Of course, we talking open source here, so I guess there’s always a possibility of a grassroots PHP 4 maintainence posse.


A couple new APIs

Work’s been busy, so I haven’t had a chance to do a lot of mashup stuff lately. Via Chad, here’s some  APIs I just found out about that could make for some interesting mashing:

NPR API – “over 250,000 stories that are grouped into more than 5,000 different aggregations.”

Crunchbase API


Follow

Get every new post delivered to your Inbox.