Topic: MT Hacks and Tips

Fixing <MTEntryModifiedDate> in dynamic templates

According to the Movable Type support desk it’s a known bug that <MTEntryModifiedDate> sometimes returns the original publishing date rather than the modification date when used in a dynamic template. I think this must be a regression of the same bug from 2.661 mentioned here, but now it only affects dynamic publishing.

Luckily, the fix is much easier to implement this time. Simply backup /path/to/mt/php/lib/function.MTEntryModifiedDate.php and then edit it so the file looks like this (or download the whole file):

<?php
function smarty_function_MTEntryModifiedDate($args, &$ctx) {
    $e = $ctx->stash('entry');
    $args['ts'] = $e['entry_modified_on'];
    return $ctx->_hdlr_date($args, $ctx);
}
?>

I should probably understand this sort of stuff better (you did backup your current file, right?) before I go hacking around, but I figured that my <MTEntryDate> tags were working correctly in my dynamic templates. Why not just copy the code out of that PHP file (function.MTEntryDate.php), change ‘entry_created_on’ to ‘entry_modified_on’ and see what happens?

Whadaya know, it worked! (With no ill effects, knock on wood.) Now my dynamic Atom feeds have the correct date in the updated field.

Popularity: 2% [?]

Fixing <MTSimpleCommentCount> so it works outside <MTSimpleComments> in dynamic templates

Like my last post this is a small fix to a problem with the PHP implementation of the SimpleComments plugin. The original perl code allowed the use of the <MTSimpleCommentCount> outside of SimpleComments tags. This is really useful if you want to output info on comments or trackbacks based on how many there are. In my case I want the updated timestamp on my individual Atom feeds to match that of the most recent comment or trackback, but if there isn’t any feedback yet, the timestamp should match the modified date of the entry itself.

For some reason (and I don’t know enough about writing PHP plugins for Movable Type to tell you why) the “official” PHP version of SimpleComments returns null if you try to do this. Luckily kate at geekmum noticed the same problem and figured out that installing one file from Rad Geek’s PHP port fixes the issue. So download that package, and copy function.MTSimpleCommentCount.php to /path/to/mt/cgi-bin/php/plugins/ (make a backup of your original function.MTSimpleCommentCount.php, first). Now you can find the total comment and trackback count in dynamic templates to your heart’s content.

One caveat: I believe the official PHP port allows comment counts to be accessed outside the context of a single entry, but Rad Geek wrote his port before that was a feature. So if you’re using SimpleComments to pull a blog or category-wide comment count in a dynamic template, this “fix” will probably break that.

Popularity: 2% [?]

Making SimpleComments aware of TrackBack junk status

Adam Kalsey’s SimpleComments plugin for Movable Type was written long before MT allowed comments and trackbacks to be marked as unpublished, so in its original version it will output junked and moderated feedback. It was also written before MT had dynamic publishing, so of course it didn’t support that, either.

Luckily Brad Choate quickly added dynamic support to the plugin, and recently Joe D’Andrea released a patch that made the static half recognize junk status. So all I had to do was combine the two fixes to make SimpleComments compatible with dynamic templates and junk status aware. Directions follow.

1. Download and install the original SimpleComments package (this includes Brad’s code for dynamic publishing).

2. Apply Joe’s patch to SimpleComments.pl.

3. Apply the following patch to /path/to/mt/php/plugins/block.MTSimpleComments.php:

147a148,149
>     if (isset($args['visible']))
>         $moderation_filter = "and tbping_visible = 1";
153a156
>                $moderation_filter

Or you can just download the patched file and copy it over the original.

Now your combined lists of trackbacks and comments won’t show junk, even if the list is part of a dynamic template. This will be important if you want to follow my directions (post coming soon) for creating dynamic Atom feeds for individual entries.

Popularity: 2% [?]

The easiest Amazon Associate links yet

You’re an Amazon Associate, maybe you make a few dollars a month by linking to products you like, but you know you could make more if only it was easier to build the links. Or you’ve already found an easy way to automagically add your associate ID, but then you upgraded your blog or moved servers and broke all your links. I think I’ve got a great solution to both of those problems.

I like Brad Choate’s method, and I used a slightly modified version of that before I upgraded to 3.2. But during the upgrade I accidentally deleted my macros, and all my <amazon> tags became useless. At the time I was running TBOTCOTW as a dynamic blog, as well, and Brad’s code uses plugins that don’t work on dynamic pages (yet). On top of that, MTAmazon hasn’t been actively developed in years, and I wasn’t sure it would work with 3.2 at all. So I gave up and changed all my tags back to regular links to Amazon.com.

Then I switched back to static publishing found out that Byrne Reese developed MTAmazon32, so I wanted to start doing some macros again. I didn’t feel like changing all those links back to <amazon> tags by hand, so I decided to see if I could make things even easier. Could I take Brad Choate’s macros and make them interface with MTAmazon32 to add my associate tags to a vanilla HTML link to Amazon.com?

After banging at it for a couple of hours, I came up with a solution. First, you need the MTAmazon32, MTMacros, MTIfEmpty, and MTRegex plugins. Install them all according to directions (if you have issues with this step, just ask for help in comments).
Continue »

Popularity: 1% [?]