Matt's Blog

Archive for the ‘Programming’ Category

Plugin: Twitter Links

Sunday, November 16th, 2008

A couple of days ago, I released another WordPress plugin called Twitter Links. What this plugin does is search comments of posts for any mentions of Twitter usernames (in the form of “@mattfreedman”) and then replaces them with a link to the mentioned username’s profile page. It will first check to see if the user actually exists on Twitter.

As this plugin checks Twitter for every username it finds, I strongly recommend using a caching plugin (such as WP Super Cache) with this plugin. Which will both help ease the load on Twitter’s servers, and also speed up your page load times.

This plugin requires cURL to be installed on your server, and has only been tested with PHP 5.2.x. It is available to download here.

Plugin: Comment Approval Notification

Wednesday, November 12th, 2008

Two days ago, I released a plugin called Comment Approval Notification and yesterday I released a WordPress version 2.6 compatible version (it previously required WordPress 2.7, which is still in beta).

The Comment Approval Notification plugin will send comment authors an email when their comment gets approved (if it was held for moderation, of course). The email sent to the comment author is fully customizable using “shortcodes”. Shortcodes are special placeholders (in the form of [shortcode_name]) which allow you to add dynamic information to the email (such as the name of the comment author), and have it replaced with the actual information. A full list of the available shortcodes is available here.

This plugin will be useful for people who require comments to be moderated before being shown, to not leave comment author in the dark as to when their comment will appear.

You can find more information about this plugin, and where to download it, over at it’s plugin page.

Update (November 16, 2008): It turns out this plugin wasn’t quite WordPress 2.6 compatible. I have fixed this and released version 1.1.1, which can be downloaded from here. Thanks to Ricky Buchanan for bringing this to my attention.

Twitter Bot: Magic 8 Ball

Tuesday, April 22nd, 2008

On the Weekend, Gary Jones from BlueFur (Twitter: bluefur) came up with the idea of a Twitter robot that would act as a Magic 8 Ball. He asked me if I wanted to help make it, I accepted, and development began.

What we came up with was a small script that would automatically reply with a Magic 8 Ball-type answer when it was “replied” to. To use it, all you have to do is write a “tweet” replying to magic_8ball with a yes or no question. Which would look like this “@magic_8ball <yes or no question>”.

This little “Twitter Bot” uses the Twitter API to receive the replies to it, and then send out replies with a randomly selected answer. We quickly found out that the Twitter API is quite restrictive. As outlined in Gary’s post, Twitter only allows 70 authenticated API requests an hour, which not only inconveniences developers while testing their Apps, but also users using Twitter Apps. Also, Twitter restricts API calls for replies and such to the latest 20, which can create quite a few problems.

We’ve decided to make this application Open Source, so that other developers looking to develop with the Twitter API can hopefully learn from our code. Feel feel to use, modify, hack and learn from this code to create your own Twitter Applications. The code is release under the GNU General Public License version 3 (or, at your option, any later version). You can get the code here (or in txt format here).

If you have any questions about the code, feel free to let me know.

I’m on Twitter under mattfreedman, feel free to follow me.

Speed Up Your Blog Using ZLIB

Monday, April 7th, 2008

With the release of WordPress 2.5, there is no longer an option to enable GZIP compression. This option was axed for the reason that it’s better to enable compression on the server, rather than through WordPress. GZIP is basically a compression “tool” that compresses files before sending them to the browser, if the browser states that it can handle GZIP compression. All modern browsers support GZIP compression, and send the appropriate header to the server to tell it that it can handle compression.

However, there is another compression library that is generally preferred over GZIP, called ZLIB. It’s essentially the same as GZIP, and is initiated by the same gzip header that browsers send.

We’ll be using ZLIB to speed up your blog. We’re using ZLIB because using GZIP causing TinyMCE (in WordPress) to be double compressed, and to stop working properly, using ZLIB works around the issue. Also, since ZLIB is preferred, we might as well use it.

Before enabling ZLIB compression, you’ll want to check with your host to ensure that PHP has been compiled with ZLIB support. I can confirm that BlueFur has it enabled on most (if not all) of their servers.

Now that you’ve made sure that your host can support ZLIB compression, let’s actually enable it. First of all, open your blog’s root .htaccess file. Then, you’ll want to add the following line to the file, above the WordPress code (# BEGIN WordPress):

php_flag zlib.output_compression On

Save the file, and reupload it. You should now notice improved speed in the execution time of your blog. On my blog, page execution has, on average, been reduced by 50%. However, your results may vary.

It’s important to note that, if you’re currently using any other compression or caching systems, you cannot use this in conjunction with them; you’ll have to choose between them or ZLIB compression.

This compression method will also work on any fairly dynamic site, it’s not limited to blogs.

Looking for PHP Project

Sunday, October 14th, 2007

Right now I’m looking for a PHP project for myself that I can just code at whenever I feel like it. I want to use it to further develop my coding skills. Although the project should be useful, there shouldn’t be any rush to get it done.

Anyone got any ideas?