Jan 16, 2007 12:57 am
My first battle with Textpattern
Well, I guess I shouldn't call it a battle... it wasn't all that bad. I'm sure that if i knew PHP, it would have been a breeze.
I wasn't totally happy with Textpattern's default date format options, and I could not find a plugin, tutorial, or forum discussion on the topic. All the options in Admin>Preferences>Date Format displayed a 24-hour clock, which was annoying the shit out of me. I just wanted a simple 12 hour format... something like 'Jan 16 2007, 4:36 pm'.
I guess I could explain exactly the process I went through to fix this, but that would be rather boring. Besides, if you're reading this, you may want to actually do this, and are looking for a simple explanation.
To make a long story short, I guess my server's (dreamhost) C library does not support the '%p' format when used in a date-format-string and then passed to the strftime() function. On my server, strftime('%p') was returning an empty string. That caused Textpattern to use the 24 hour clock for all date formats.
To solve this, I found the dateformats function located in textpattern/include/txp_prefs.php. At the end of the function, just before the return, I added a key to the array $vals. That displayed antother option in the drop down list in Textpattern's preferences. This is the line I added:
$vals['12 hour'] = 'Custom 12 hour';
Then I had to build my custom format. I found a function, safe_strftime located in textpattern/lib/txplib_misc.php that actually built the dates from the selection in the prefs. Near the end of that function, before the UTF check and charset jazz, I added a conditional block:
if ($format == '12 hour')
{
$str = date('M j, Y g:i a', $time + tz_offset());
}
And that did it. I uploaded those two files, set the preferences, and it worked like a charm.
Now, if I could just get IE7 to stop f'in up my layout.....