Countdown Timer v1.95 Technical Preview

09 Oct 2007
mid-afternoon

Okay folks, this is a technical preview of version 2.0 of the Countdown Timer.

The biggest change is that timers can now countdown automagically with JavaScript. Now, a word on the JS. This is the first version and there are only two modes: on and off. That means that you can’t change the format of the Javascript countdown (it will always display the years, months, days, hours, minutes, and seconds). I’m working on an elegant solution to this problem and would welcome any code, comments, suggestions, feedback, etc.

Other updates include:

  • Tabbed $afdnOptions array to make it more readable
  • Fixed strtotime typo
  • Brought time display inline with current WordPress practice. This fixes the dreaded timezone glitch.
  • Strip non-sig zeros option added
  • Fixed bug where “No dates present” would _not_ show if the data was returned instead of echo’d

In terms of stability, everything seems fine; I am currently using this Technical Preview on AFdN.

Download the file and try the goodness




Countdown Timer v1.91

05 Dec 2007
mid-morning

Technically, this is a step back because I already released 1.95 as a Technical Preview. However, I wanted to fix a bug without having to release the incomplete features included in the 1.95 Technical Release. So this is a special release. This release fixes a bug where the widget wouldn’t save data. Baring any catastrophic bug discovery, this will be the last release before version 2.0 (which I hope to release over Christmas Break).

Read more or download it!




Google Chart API

10 Dec 2007
in the early morning

I typically don’t blog about new Google stuff, especially APIs (application programming interfaces). However, this one is particularly cool because it allowed me to easily finish up a project that I had shelved for several months (maybe years? I’ll just call it ‘a while back’).

A while back, I had this idea to chart monthly blog frequency. I had found some code that did a pretty bang up job of making graphs using just PHP. However, it wasn’t the sleek looking graph I was hoping for. I had bookmarked a few sites that had Macromedia Flash applications that you could just drop the data into, but I never got around to playing with them.

Finally, Google introduced the Google Chart API. In a nut shell, I can easily create graphs such as:

Blog posts for Nov. 2007

This chart shows my blogging frequency for the month of November. The code I’m using on the back end is pretty crappy (I literally just patched some code I already had) and it can only handle a single month at a time.

Technical details to follow…
Read the rest of this entry »




Countdown Timer v1.97 Technical Preview 2

28 Dec 2007
terribly early in the morning

It’s been many moons since I released the last technical preview of Countdown Timer 2.0. Honestly, things were stalled for a bit because I was busy with school and trying to figure out how I wanted to do what I wanted to do with the program.

The semester is over and I got it all figured out. So welcome to Countdown Timer version 1.97, better known as version 2.0 technical preview 2.

The Javascript that handles the updating of the countdown has been completely rewritten. I ended up scrapping what I had and then taking the PHP code I was already using and converted it to Javascript. This is the “elegant solution” I mentioned I was looking for earlier.

In terms of stability, everything seems fine; I am currently using this Technical Preview on AFdN. There are a couple known bugs that deal with stripping non significant digits and I haven’t fully tested the upgrade process. Other then that, everything is complete. I’m hoping to have 2.0 shipped before the New Year.

Go download it!




Countdown Timer v2.0, Now with v2.01 goodness!

29 Dec 2007
in the early evening

Update: There was a bug in the initial 2.0 version that required the plugin to have PHP5 or greater. This has now been fixed and it works with PHP4 and PHP5. Thanks to Jim Lynch for bug report.

Well, I finally managed to push Countdown Timer v2.0 out the door. It’s a bit later then I wanted, but it’s out and that’s all that matters for now. The biggest update for v2.0 is the ability to have the time automatically update using some Javascript. The idea for this has actually been around for a while and credit for it goes to Tobias (see: Ultimate Countdown Timer; 1-Up’d by a 14 Year Old). I was hoping I could use a lot of Tobias’ code, however I had changed a lot between then and now.

During the development phase, I wrote some code that basically took a look at what value the timer was at and then subtracted one second from that. Unfortunately, it quickly became clear that this method would not work. Because there are a variety of options in what units of time are displayed, screen scraping and then recalculating would have been pretty cumbersome. It also meant that I had two ways of calculating the time (the first way was the PHP-based fuzzyDate function I wrote, the second would have been this monstrosity). So I did what any code programmer does and copied myself. I converted the PHP-based fuzzyDate function into Javascript and then passed the needed values to the JS function. Voila!

In any event, here’s the changelog:

  • Updated plugin description line
  • Rearranged text in the installation notes to emphasize using the widget rather then the code
  • Fixed a bug that crashed the plugin if no dates were present (a PHP 5 problem??)
  • Implemented the ‘register_activation_hook’ function rather then the old way
  • Changed the way DB updates are handeled. Instead of having a specific update regimine for each version, the plugin will only update an option field if it doesn’t exist (if it exists, but is blank, it will NOT update…as it shouldn’t).
  • Updated fergcorp_countdownTimer_fuzzyDate with another variable so that the real target date is always known.
  • Removed code dealing with updates since WP 2.3 now does this automatically
  • Bug fix. Widget title isn’t saveable due to a programming error. Thanks to Michael Small for the catch.
  • Renamed some functions from afdn to fergcorp
  • Added JavaScript function for JS countdown
  • Tabbed $afdnOptions array to make it more readable
  • Fixed strtotime typo
  • Brought time display inline with current WordPress practice. This fixes the dreaded timezone glitch.
  • Strip non-sig zeros option added
  • Fixed bug where “No dates present” would _not_ show if the data was returned instead of echo’d
  • Renamed to $getOptions to $fergcorp_countdownTimer_getOptions to avoid clashing

Read more or download version 2.01!

Note: Comments moved and closed. Please leave future comments, questions, pleads for help, etc on the Countdown Timer page.




Making HTML XHTML Compliant with PHP

17 Jan 2008
mid-morning

This is function I found on php.net that changes all HTML tags to lower case. You need this to make your HTML XHTML 1.0 Trans compliant.


function reformat ($content){
	$content = preg_replace("#(<\/?)(\w+)([^>]*>)#e", "'‘\1'.strtolower(’\2').’\3'", $content);

	return $content;
}

Note: This was code that I originally had in a ‘Code’ page, but I’m moving it to a post now. This code is probably really old (years and years old). I enjoy laughing at myself and so should you.




Handling Links

17 Jan 2008
just before lunchtime

This is some code that I cooked up for handling links in my website. I was tired of prefacing every link with “”. This takes care of that and ensures that it will open in a new window. Easy as pie. I’m sure there is probably a better way to do it, but this is the way I figured out how to do it.


function redirect ($url)
{
    $url = preg_replace("#<a href.?=.?("|')http://(www.)?andrew\.fergcorp\.com\/link\.php\?site=(.+?)("|')#is", "<a href = "$3" target = \"_blank\"", $url);
    $url = preg_replace("#<a href.?=.?("|')http://(www.)?andrewferguson\.net\/link\.php\?site=(.+?)("|')#is", "<a href = “$3" target = \"_blank\"", $url);
    if(!ereg("andrewferguson", $url))
    {
        $url = preg_replace("#<a href.?=.?("|')http://(.+?)("|')#is", "<a href = "http://$2" target = \"_blank\"", $url);
    }

    return $url;

    # Example:
    # $string = redirect($string);
    # $string is parsed for url’s and returned back to you…yea!!! Who’s good?? Who’s good? Andrew’s good…that’s who’s good…
} 

Note: This was code that I originally had in a ‘Code’ page, but I’m moving it to a post now. This code is probably really old (years and years old). I enjoy laughing at myself and so should you.




SAAS Problem of the Week Quiz Decoder

17 Jan 2008
around lunchtime

Script that figures out the answers to SAAS POTW Quiz’s. As a note, this is only the processing end. In order for the script to work, you will need to build a front end.


<?
error_reporting  (E_ERROR | E_WARNING | E_PARSE);
$httpfile = $_POST['httpfile'];
$userfile = $_POST['userfile'];
if($httpfile != NULL){
$textarea = file_get_contents($httpfile);
}
else{
$textarea = file_get_contents($_FILES['userfile']['tmp_name']);
}
    echo "1. ";
    $t = 2;
    $length = strlen($textarea);
    for($i = 0; $i < $length; $i++){
        if(($textarea[$i-1].$textarea[$i]) == "l["){
            while($textarea[$i+1].$textarea[$i+2] != ",#"){
                $i++;
                echo $textarea[$i];
            }
            $i++;
            if($t > 10){
            die();
            }
            echo "$t. ";
            $t++;
        }
    }
?>

Note: This was code that I originally had in a ‘Code’ page, but I’m moving it to a post now. This code is probably really old (years and years old). I enjoy laughing at myself and so should you.




Countdown Timer v2.1.1

20 Feb 2008
mid-afternoon

After dilly dallying around for a couple months, I finally got serious about pushing the 2.1 version out the door. A couple of reasons for this actually.

First, the Wordpress 2.5 is coming out end of March/beginning of April and I wanted to get out one more release (this one) before the next version of Wordpress hits the streets.

Second, it’s fits with my development flow; releasing every few months when I can.

Here are the list of updates in Countdown Timer v2.1.1:

  • Fixed i18n translation issues where mo file would sometimes not be loaded
  • Updated UI (note: Based on UI code from Google XML Sitemaps)
  • Removed code dealing with recurring events (which has not been included for a few versions now)
  • Added js countdown ability to admin example (which doesn’t have wp_footer hook?)
  • Updated the link to the JS file to make it dynamic in case a folder gets renamed
  • Fixed a bug in the JS file that caused dates to be calculated incorrectly
  • Append a letter to the beginning of the unique id (as per XHTML requirement)…who knew?
  • Added two language files: Swedish (thanks to Mattias Tengblad) and Spanish (thanks to Google Translator)

The biggest change user will notice is the new UI. It’s based off the code from Google XML Sitemaps which I’m assuming is based off the code from Wordpress itself. The great thing about the new design is that you can collapse, expand and move around the boxes to fit your work flow.

All the other changes are ‘under the hood’ and deal with code changes to make things work better in a larger variety of situations.

The Countdown Timer plugin is about three months shy of its third anniversary of public release! I’ve basically been maintaining it since the end of freshman year in college, which is when I switched to Wordpress.

The first public version was v0.6. It had about 50 lines of code and used a text file to store the data. There was also no UI at all.

Version 2.1 is about 950 lines of code. Storing data in a text file is gone, instead using the WPDB. There are also several support files, including the javascript port of the countdown mechanism which is another 150 LoC.

Since the beginning of last March, there have been over 8700 downloads, which would almost pay for a semester of college if everyone gave a $1 (wink wink)!

Read more or download version 2.1.1!

Update: Had to increment the plugin to version 2.1.1 because of the way that WordPress does version numbers. In short, v2.01 is the same as v2.1. So I had to release this as 2.1.1.




phPo Translator - Online PO Translator

21 Mar 2008
mid-afternoon

One of the great things about being a programmer is that when I have a problem, it’s pretty easy to solve it myself1.

I recently began to seriously support i18n (internationalization) in the Countdown Timer. It’s actually a pretty slick system. Everywhere I have some text that’s output in the plugin, I wrap it in a WordPress defined function that handles the translation. Then I generate a PO file using poEdit and make a MO (which is just a binary/machine object file of the PO file, which is human readable).

The issue is, if someone wanted to translate the PO file, they’d have to download poEdit, figure out how to use it, grab the PO file, translate it, make the MO file, and then send the MO file to me. This works pretty well if the users is a computer guru. But that’s not often the case.

I was hoping there would be an online PO translator, but I couldn’t find one. So I decided to make my own. Thus I present, in the form of clever titles that mash two words together, phPo Translator (or just phPo for short).

I basically wrote the code over lunch today and then decided that I should version control it. So I threw it up on Google Code, which I knew about but had never, up until this point, actually used.

Google Code is simply amazing. It took less then a minute to register and it uses SVN, which I already have installed on my computer. So I upload the code, create the tag, and away we go!

In any event, you can:

See it in action: Translate afdn_countdownTimer.po
Download phPo Translator v0.1.1
View phPo Translator Google Code page

1 Granted, most of my problems are probably caused because I am a programmer