Significant change to the Database Class

Getting a demo up and running on a new host has been very enlightening.  I have used the PEAR DB class for years because it works well and is usually available.  The host which is being used for the demo site doesn’t appear to have the PEAR DB class installed so this has motivated me to migrate the SwimTeamDBI class to make use of the builtin WordPress database access class instead of depending on PEAR.  I have considered doing this for a while but have put it off but it looks like it is time to deal with it.

My intial impression is it should not be to much of a change as my current database class abstracts the PEAR aspect away from the rest of wp-SwimTeam.  The bigger concern is the phpHtmlLib widgets which also depend on PEAR.   Those will need attention and I suspect I will end up implementing a new database abstraction class for WordPress as part of phpHtmlLib.

I have been doing a lot of work on phpHtmlLib over the last week and for the most part, it appears to be done.  All of the changes allow phpHtmlLib to now be loaded as a WordPress plugin which is much easier to support.

The trickle down effect

While trying to get a demo site up and running I ran into an issue that has taken me down a path I didn’t expect to head down at this time.  But now that I have run into it, I have decided to fix it correctly.

The wp-SwimTeam plugin depends on phpHtmlLib and the 2.x version of the library requires that it be installed in the web site’s root directory.  This typically isn’t a big deal but in some cases can be inconvenient.  It also requires the library be named phphtmllib as the path is (was) encoded into quite a few of the widgets.

When I uploaded the library to the new demo site, it didn’t run correctly.  The demo site is running PHP5 which I immediately suspected as the problem.  So I loaded PHP5 and phpHtmlLib into a new virtual machine (I love VMware, it is wonderful for configuring different environments) and all the examples ran just fine.  Odd, very odd.  Digging into it further, it looks like the hosting provider’s PHP virtual directory support setting is different than what I had locally and affects how include files are handled.

A couple of tests confirmed my suspicions.  Since this hosting provider is large, I suspect this PHP configuration is pretty typical and it provided sufficient motivation to go back and fix phpHtmlLib 2.x so it can be loaded with appropriate configured PHP define() statements.  If you look through the phpHtmlLib forums you’ll find this is a fairly regularly requested item (including by me) and phpHtmlLib 3 (which requires PHP5) is configured this way.

Over the last couple days I have been updating the phpHtmlLib 2.x branch to support this configuration method and now have it all running correctly in my development area.  Before I commit all the changes, and there are a lot of them, I need to verify it all works in the suspect hosting environment.

The trickle down of setting up a demo site resulted in an overhaul to phpHtmlLib.  It needed to be done anyway and doing it will allow phpHtmlLib to be loaded as a WordPress plugin eventually.

Standard Event functionality completed

This afternoon I committed a bunch of changes which complete (I hope) the standard event functionality.  Standard Events are the events a team would typically run at every meet.  I envision them being set up for a team’s home pool so the course should be set to match the home pool but it is up to the end user.  Once defined, the meets can be reordered to match the typical order of events.

The next phase will allow creating of meet specific meets and the standard events can be used to initialize the events for a meet.  When creating meet events, the the course for the pool is different than the standard events, the meet events will be adjusted acordingly.  This will allow a team with a home pool in meters to easily set up a meet at yards pool – if the same events are used in the same order, it will be a simple task.

Once the events are created for meet, the order can be changed on a per meet basis and other events can be added or deleted.

Started Adding Event Functionality

In order to keep a history of swim times (aka results), the events the times are associated with need to be defined.  I guess technically that isn’t true, a simple time history could be kept but as long as I am going to import times and keep them as a history, might as well associate them with a meet too.

To do this I started working on defining the events for each meet.  Since most teams swim the same events in the same order at most of their meets, I have established a “default” set of events.  I have this new functionality working now.  What is left to do is to elegantly re-order the events (since re-ordering them is inevitable) and to use them as a basis for populating the events for an actual meet.

This functionality is also the basis of Opt-in/Opt-out because I have decided to let swimmers opt in or out of individual events and as well as entire meets.  This is a need for the MacDolphins because we many of our swimmers are in year round school and since our league swims on Tuesday nigths, for some portion of our team, it is a school night.  We have a fair number of swimmers who opt out of the later events because of it being a school night.

Short Code improvement and other minor changes

Last night I committed a bunch of changes to clean up the Meet Schedule Short Code.  Previously it only worked for the current season, the optional seasonid argument was ignored.  It is now working – if the seasonid argument is not included in the short code then the active season will be used.

I also added a column for the Id in the Admin view of the seasons, swim clubs, and meets since the Id is used in the short codes.  By putting the Id in the list, there isn’t a need to drill down into the item detail to see what the Id is in order to use it in a short code.

More on Opt-in and Opt-out

As the season comes to a close we are seeing a lot of scratches for our last couple meets. For this week we will be missing about 40% of our swimmers. Previously I had written about the pros and cons of Opt-in and Opt-out for swim meets and after watching this season unfold, I believe my thinking still holds.

Originally I had thought that opting in or out from a meet as a binary decision:  A swimmer was either participating or not.  It turns out it isn’t that simple.  Year round school is pretty popular here in Wake County, North Carolina and roughly 1/3 to 1/2 of our swimmers are in school for either all or part of the summer swimming season.  Since our meets are held on Tuesday nights, they tend to run pretty late and some parents are taking their kids out of the late events (e.g. Butterfly and/or Freestyle Relay).

This has resulted in what my wife is referring to as a “partial scratch”.  In addition to kids needing to leave early, we have also had some kids come late due to other commitments so they are missing one or two events early in the meet.

So as I sit down to implement opt-in and opt-out, I have concluded I need to account for partial participation in a swim meet.

Google Maps short code implemented

I have been using the Inline Google Maps plugin on the MacDolphins site but lately it has been flaky to say the least.  Sometimes the Google Map is displayed and sometimes it isn’t.  There isn’t any real rhyme or reason as to when it displays and when it doesn’t that I could find AND the plugin is actually hard to use, particularly for the casual author.

So I implemented a new short code for Google Maps called wpst_google_map which will take an address as an argument and display a Google Map.  The plugin uses this as part of the Club Profile to map a swim club for directions and such.  The short code is based on a Google Maps class called Phoogle Maps which has been extended to work with the plugin.  Phoogle Maps works pretty much as advertised.  I wish it didn’t echo it’s output directly to the output buffer but fortunately PHP can control the output buffer so it can be captured and used in the context of the plugin.

[wpst_google_map address="1600 Pennsylvania Ave, Washington DC, 20006" align="center"]

The short code syntax above will display a map similar to this:

New Shortcode – wpst_club_profile

I implemented a new shortcode to show club profile detail.  You can see the short code in action on the MacDolphins web site.

[wpst_club_profile clubid=1 googlemap=’y’ mapquestmap=’yes’ link=’yes’]

This short code can optionally display a Google Map but in order to do so, the Google Inline Maps plugin must be installed.  For the short code to display anything meaningful the club profile data must be enterted for the club of interest.

FireBug: Indepensible for theme development

I have yet to code a WordPress theme from scratch.  I have found something I like and started from there.  For the MacDolphins web site, I had found something simple a while back and it served it’s intended purpose but it wasn’t without issues.

As the site has grown, the need to tweak the side bar in particular has increased.  I found an extension to FireFox called FireBug which has made this process significantly easier.  I am using FireBug to chase down CSS conflicts and oddities but it does much more than I realized.

My theme now works correctly even if it isn’t visually very exciting.  The mouse overs no longer overflow the sidebar for 3rd and 4th level deep menus.  I was able to resize the sidebar and the overall content area without things ending up in the wrong spot.  If you dink with themes, FireBug is really helpful.

More on Short Codes

I had posted a question on Short Codes to the wp-hackers mailing list and got a pointed to an article on the Codex which explained the process of coding up a short code.  I expected it to be more involved than it was and I was pleasantly surprised to find it was really straight forward.  I have already implemented one short code for the wp-SwimTeam plugin and expect I’ll have half a dozen more done by the end of the week.

What I implemented for Flickr was pretty simple – it allows the insertion of a Flickr slideshow in a post or page using the Flickr UserId value (which is different than the username) and the Set Id.  Here is the snippet of code:

/**
 * wpst_flickr_slideshow shortcode handler
 *
 * Build a short code handler to display a Flickr slide show.
 *
 * [wpst_flickr_slideshow userid="id" slideshowid="id"
 *     frameborder="pixels" *     width="pixels" height="pixels"
 *     scrolling="yes|no" align="left|center|right" view="yes|y"]
 *
 * To show this Flickr slide show:
 *
 * http://www.flickr.com/photos/27604893@N04/sets/72157605764227907/show
 *
 * Use this shortcode:
 *
 * [wpst_flickr_slideshow userid="27604893@N04" slideshowid="72157605764227907"]
 *
 * This is the resulting IFRAME tag which is returned to the caller.
 *
 * <iframe align=center src=http://www.flickr.com/slideShow/index.gne?
 *     user_id=27604893@N04&set_id=72157605761943480 frameBorder=0
 *     width=500 scrolling=no height=500></iframe>
 *
 * If the 'view="yes"' or 'view="y"' attribute is include, a linl to the
 * Flickr slideshow will be placed under the IFRAME.
 *    
 * @param array - shortcode attributes
 * @return string -  HTML code
 */
function wpst_flickr_slideshow_sc_handler($atts)
{
    $c = container() ;
    //  Parse the shortcode
 
    extract(shortcode_atts(array(
        'userid' => '',
        'slideshowid' => '',
        'frameborder' => 'default 0',
        'width' => '500',
        'height' => '500',
        'scrolling' => 'no',
        'align' => 'center',
        'view' => 'no',
    ), $atts)) ;
    //  If either the userid or slideshowid are missing then
    //  we have a problem and can't do anything meaningful.
    if (empty($userid) || empty($slideshowid))
    {
        $c->add(html_br(),
            html_b("wpst_flickr_slideshow::Invalid Shortcode Syntax"),
            html_br(2)) ;
        return $c->render() ;
    }
    $if_src = "http://www.flickr.com/slideShow/index.gne?" .
        sprintf("user_id=%s&set_id=%s frameBorder=%s align=%s",
            $userid, $slideshowid, $frameborder, $align) ;
    $c->add(html_iframe($if_src, $width, $height, $scrolling)) ;
    if (($view == 'yes') || ($view == 'y'))
    {
        $link = "http://www.flickr.com/slideShow/index.gne?" .
        sprintf("user_id=%s&set_id=%s", $userid, $slideshowid) ;
        $c->add(html_br(2), html_a($link, "View this slideshow on Flickr."), html_br(2)) ;
    }
 return $c->render() ;
}

The code above makes use of the phpHtmlLib to generate HTML code but the general intent should be pretty obvious.