Howdy! Thanks for coming and enjoy your stay! Take a look at the sitemap and don't forget to chirp!

Dave Winer’s Commenting Proposal

September 1st, 2010

Based on a recent post by Dave Winer (RSS pioneer) called Proposal: A new kind of blog comment system. And a follow up has been posted here: Why I like comments. Briefly, the idea behind the new commenting system it is the following:

  1. Disable commenting on posts older than 24 hours
  2. Comments are invisible to other commenters until the 24 hour period expires
  3. Commenters can edit their comments during the period
  4. Length limit of 1000 characters

So jumping back to my mail inbox and the comments folder with over a 100 unread and unresponded (and spam) messages, I decided to give it a go, starting from point one. I fully agree with Dave about the reasoning behind all the points, but personally think that 24 hours is too harsh, so I started off with 7 days, keeping in mind that this has to be decreased.

This means that when a post is published, you (my readers) have 7 days to comment. Don’t worry, commenting on support pages for my WordPress plugins has not been switched off.

I’ll hopefully be implementing the rest of the features throughout September, and will keep you posted on Twitter (@kovshenin). Cheers!

WordPress and Magic Quotes

August 30th, 2010

This is crazy, and based on a post called WordPress and PHP magic quotes: you want to run me crazy! by Stefano Lissa. I’m writing a plugin prototype for WordPress that uses the new Facebook Graph API to post stuff to my wall on Facebook (upcoming blog post). The original Facebook PHP SDK comes in very handy when working with the Facebook API, and I had quite some fun using it, but..

How to Kill the get_magic_quotes_gpc Function

How to Kill the get_magic_quotes_gpc Function

I’ve been trying to figure this out for hours! I had code working outside WordPress and once I pumped it into a plugin it suddenly stopped authorizing me. I had to dig through the facebook.php code to figure out what’s happening, and here it is. The getSession() method uses the get_magic_quotes_gpc function and strips the slashes from the $_COOKIE superglobal if it’s switched on. Of course, that’s the correct logic supporting both php 5 and php 6, but not WordPress.

I looked through the latest (3.0.1) WordPress core code and was quite surprised to see a function called wp_magic_quotes(). Oh my god, thought I! Commented as:

Add magic quotes and set up $_REQUEST ( $_GET + $_POST )

What the hell is that? Okay, let’s see:

$_GET = add_magic_quotes($_GET);
$_POST = add_magic_quotes($_POST);
$_COOKIE = add_magic_quotes($_COOKIE);
$_SERVER = add_magic_quotes($_SERVER);

How does that sound? So all my apps, plugins, external libraries working with server variables (like Facebook does with cookies) are not allowed to use the magic quotes function? This means that working with WordPress, we must initially assume that all these are quoted, no matter what the php settings are. I don’t even know what question to ask here, perhaps: Is this the way things are done? Why?

To be honest this is getting me a little frustrated. Not by the fact that they’re slashing the whole input (although I don’t see a reason to) but, heh, I’ve been coding based on WordPress for over two years now, and never came across anything like this. Did I miss something in the Getting Started guide? ;) Anyways, the easiest way to get this working is to replace your get_matic_quotes_gpc function with 1, which says it is always switched on.

Eh, Monday morning disappointment ;) Cheers, and thanks for retweeting the post!

Trends: WordPress vs Drupal vs Joomla

August 26th, 2010

The battle’s been going on since 2004-2005, the three open platforms (WordPress, Drupal and Joomla) have been competing for ages. Which is the most popular? Of course you could search for reviews, votes, researches. I even came across a commercial research document about content management systems, their pros, cons and popularity. It still is difficult to convince clients (especially the bigger ones) to use open platforms for their websites. Tonnes of questions are asked about security, performance, etc.

This article will not review any of the platforms mentioned above, nor will it give pros and cons to certain properties of such platforms. We’ve seen enough reviews, tests, benchmarks and even competitions to figure out which the best platform is. In my opinion, there’s no best platform, each is good, and which ever to use is a decision the developer should make.

Anyways, I had my coffee this morning and decided to check out what Google is up to, so I browsed to the Labs. The list is quite big but suddenly I spotted Google Trends, which has been around since 2006. Haven’t used that for a while ;) Sticking in “wordpress, drupal, joomla” into the trend search, I came up with the following results:

Trends: WordPress vs Drupal vs Joomla

Quite interesting isn’t it? Joomla (orange) was in a leading position from 2006 to late 2008, and in late 2009 WordPress (blue) took the lead. Drupal (red) heh, wha? There’s also a ranks by regions, cities and languages which give even more interesting results. For instance, Joomla still leads in Russian, Italian and German languages, and Drupal is very popular in India.

These stats are good when comparing the open platforms, they also show that open platforms are growing overall. But does this convince our clients to pick an open source platform for their website? I recall or three latest clients who calimed that they’d love .NET websites and an ASP (seriously) website. Let’s see:

WordPress vs .NET vs ASP

So Microsoft’s technologies are not as popular as they were in 2004, at least based on Google searches. There’s much more fun stuff you can do with Google Trends, but the question remains. Is this information useful when speaking with clients? Does the global trend mean that pictures in regions will change over time? And why is .NET losing popularity? Just thinking out loud ;) Cheers, and don’t forget to tweet this post if you like it.

Counting Facebook Fans in PHP: The Graph API Way

August 24th, 2010

In a previous blog post called How to Count Facebook Fans in PHP I’ve shown a code snippet of how to count the number of fans on a fan page using PHP. Times have changed, the Graph API has been introduced, and due to some responses I introduce here the new way of retrieving your fans count using the new Graph API and php.

Graph API: Literally Two Lines of Code!

Graph API: Literally Two Lines of Code!

Before you copy and paste, flush my comments with ‘my code is not working’ posts, I’d like to get your attention to versioning of the Facebook PHP SDK which we’ve been using all this time. The SDK has changed and of course the old method doesn’t work with the new SDK which is mostly tuned to Graph API, therefore, my previous code still works on a dozen on websites, because I have the old SDK installed back there. So please, be careful to what you download and use, read release notes and change logs, it will save you hours of googling.

The following snippet is based on the Facebook PHP SDK version 2.1.1 (use the Switch Tags option on github to browse through different tags). So get a fresh copy of facebook.php and have it somewhere nearby.

Unlike the old FBQL way, the new Graph API is much easier to work with, and retrieving the fans count is literally two lines of code (initialization doesn’t count). Here’s the snippet to retrieve the fans count for Mashable (don’t forget to replace your application ID and API secret):

require('facebook.php');

$facebook = new Facebook(array(
	'appId' => 'your-app-id',
	'secret' => 'your-api-secret',
));

$mashable = $facebook->api('/mashable');
echo 'Mashable has ' . $mashable['fan_count'] . ' fans';

Easy as that! I was also surprised to see that the Graph API is doing so well. Yeah, the documentation is not very rich, but whenever you need to retrieve something from Facebook, you can always print_r the results, which gives you the full picture. Sending data into Facebook is a little trickier and I’ll show you how in a later blog post.

Cheers! Thanks for your attention and don’t hasitate to retweet this post ;)

How to Generate Quality Data for MySQL

August 19th, 2010

We all had fun with the World Database, Sakila and the others when learning MySQL (see Example Databases), but it sometimes isn’t enough to run certain experiments, benchmarks within your own schema. Of course you could write a script that would generate junk data based on your column types and populate your database with a few thousand entries, but as it turns out, Benjamin Keen already did.

Meet Generate Data – a free and open source script written in php, generates quality data for your databases. Works with MySQL and, well, pretty much with any SQL compliant database I guess. What I liked about Generate Data is that you get to pick your columns, their types, and the sample data like names, last names, integer between two values, lorem ipsum (my favorite) and a bunch of others. This is why I said “quality data”.

There are a few issues I encountered, like trying to get 5000 rows gave me only 200, but such issues could easily be solved by downloading the source code and launching it locally with a few fixing (I wonder why Benjamin did such a bad job at documenting the whole thing). It took me a few minutes to fill up 30,000 rows of sample data, so who needs the World database anyway?

The script is being updated from time to time and new features are being added, not too fast, but they are. Let’s see where Benjamin takes this by the end of this year ;)