Archive for the ‘Movable Type’ Category

Edit this entry - right now!

Sunday, May 18th, 2003

This was an item cooked up by Lynda of digitalwoe.com but her original entry appears to be lost and this hack is so handy, I wanted to make sure it was readily available to anyone who wants it. You need to be using PHP to use this - just insert the code in your MT index template after inserting your IP iformation:

<?
$ip = $REMOTE_ADDR;
if ($ip == “IP #1” || $ip == “IP #2“) {
print “<a href=\”<$MTCGIPath$>mt.cgi?__mode=view&_type=entry&id=<$MTEntryID$>&blog_id=<$MTBlogID$>\” target=\”edit\” title=\”For me, not you\”>[edit]</a>”;
}
?>

(replace “IP #1″ and “IP #2″ with your IP address(s) that you want to be able to edit posts from)

Guest authored by:
Donna - deliriouscool.org

Converting entry dates to UTC in Movable Type with the PerlScript plugin

Saturday, May 17th, 2003

I was recently frustrated by Movable Type’s basic support of time zones. You can select a time zone as a number of hour plus or minus UTC, but there’s no adjustment for Daylight Savings Time, and entry dates and times are saved in whatever localtime was at the time. The default RSS 1.0 template just tacks on the +/- hours, a global setting. If you ware exporting a year’s worth of entries, there’s no way to get the correct time for both summer and winter entries.

I then remembered some perl functions that can convert times from local time to UTC and then to whatever timezone you want. A Unix system can keep track of DST, even from the past, so the new UTC times will be correct. With Brad Choate’s PerlScript plugin, you can put perl code right in your template. With 4 lines of code, I was able to print out a UTC date and time suitable for RSS.

<dc:date><MTPerlScript>
use Time::Local;
my $mytime = timelocal(<$MTEntryDate format=
“(’%S’, ‘%M’, ‘%H’, ‘%e’, ‘%m’-1, ‘%Y’-1900)”$>);
my ($sec,$min,$hour,$mday,$mon,$year,
$wday,$yday,$isdst)=gmtime($mytime);
printf(’%d-%02d-%02dT%02d:%02d:%02dZ’,
$year+1900,$mon+1,$mday,$hour,$min,$sec);
</MTPerlScript></dc:date>

A couple of notes. The arguments to timelocal are in quotes, since the values may have a leading 0 that will confuse perl. If your time zone is different from your server, you’ll have to adjust the %H parameter by the difference. Also, in perl months are numbered 0 to 11, and years are numbered from 1900, so we have to adjust accordingly. We then have a Unix timestamp in $mytime, and can obtain the individual components in UTC. I’m using printf for the output since the format for dc:date in RSS is so strict. Each %02d formats the output of an integer to two places padded with a 0 if necessary.

(This code was originally posted www.papascott.de/2003/05/17/2256.php)

Guest authored by:
Scott Hanson - papascott.de

Trackback ping fix

Sunday, April 27th, 2003

Samuel and I were talking the other night. We both use the SimpleComments plugin (combines Comments & Trackbacks in the same area).

We’d both noticed that pings don’t show up immediately unless you re-save the entry, so Samuel wrote a patch for it. The patch is written for MT 2.63 and is very easy to install (see his post for instructions).

prevent duplicate comments

Monday, April 14th, 2003

Here’s an MT hack that will prevent double comment posts.
[saw it at Lisa's]

(You can see the comment thread in the last post, but that Javascript method of disabling the button will not work - so this is rather timely!) :D

Comment Leaders and UPDATE statements

Friday, March 21st, 2003

Brenna released a new version (0.3) of the CommentLeaders plugin and so while I was up last night, I did some tweaking to make my list work a bit better. This tip would also be helpful if you are using the version from this site: Scripts: Show recent comments WITH total comments from that comment author (which is based on Comment Leader Board with PHP and MySQL).

See, when you’ve been blogging for as long as me, your blogging friends tend to have changing email addresses over the years and so it makes it hard to tally the top commenters! And besides, I have blogger and greymatter posts in there, and the GM posts didn’t require email address, so I have a lot of empty posts.

So I did some UPDATE statements in my MySQL database to make the newest addresses apply to all posts by that author. It took a little browsing through the database to see which ones needed changing, but I think I’ve got most of it. I didn’t bother changing any other information about the authors, just the email address for grouping correctly in the plugin output.

Here’s some examples in case you’d like to do some condensing too…
(more…)

Extra field in comments

Friday, March 14th, 2003

As requested by Chris, here’s a hack that will give you an extra field for your comments, and have the contents of that field included in your email notification.

(note: what this will NOT do is show those contents back on your site. I can think of a way to do that with php and mySQL (with a slight detour on the comment form submission - similar to the way comment subscribe works) and I can write up a second tutorial on that one if there’s interest. OR 10 points to the person that can figure out how to hack that directly into MT.)

(another note: if/when you do upgrades to MT - you will need to do this hack again (or one similar depending on how much changes in the version of MT you’re working with). This tutorial assumes you’re using MT 2.63 - although it also applies to 2.62)
(more…)

Archive Redirects made (more) simple

Tuesday, February 25th, 2003

A few weeks ago, Kristine posted about Redirects in MT, and this got me thinking. I had already looked at an archive mapping solution which was recently updated, but it required that I have access to the server config files (not just a .htaccess file) because a RewriteMap can only be defined in the server config files.

So tonight when I decided, after a great deal of pondering (about 10 minutes), to change my archiving format to something that didn’t produce 1000+ numerically named directories I needed a way to map the archive numbers to their new named location. Here is the solution I came up with, based on some modifications of the pre-existing code.

First download mt-archivefinder.cgi and rename it to mt-archivefinder.cgi (or any other name that suits your purposes). Put it in the MT directory.

You will need to change a couple of the lines at the top of the file to match your server’s configuration. Make sure to chmod the file 755.

Next you will need to do some mod_rewrite mojo with a .htaccess file. Create a .htaccess file or edit the existing file in the root of your archives directory. To that file add:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/archive/[0-9]{6}.html
RewriteRule ^(.*).html$ /mt/mt-archivefinder.cgi?$1

You will need to change it to reflect your path structure. If all goes well, you will be automagically redirected from any numbered file like /archives/000001.html to whatever new archiving scheme you enter into the individual archive template in the Weblog Config panel in MT.

For example, I was using

<$MTEntryID pad=”1″>/index.php

and now I’m using

<$MTArchiveDate format=”%Y”$>/<$MTArchiveDate format=”%m”$>/<$MTEntryTitle dirify=”1″$>/index.php

I used the following mod_rewrite rule to automatically forward all links to the old archive style to the new archive style.

RewriteCond %{REQUEST_URI} ^/history/[0-9]{6}/
RewriteRule ^(.*)/$ /mt/mt-archivefinder.cgi?$1

That’s all it takes!

Many thanks to Alex for the inspiration and the code.

Redirects in MT

Wednesday, February 12th, 2003

Earlier today, I saw a lazy web post about using mod_rewrite to redirect pages if you change your MT URLs. Check out Generating MT Entry Redirects.

Another thought that I had today — if you are moving a blog from one location to another (think changing domains), you could use a redirect right in the Individual Archives on the old server through MT before deleting the old blog.
Example: (in the head of an Individual Archive template)

<meta http-equiv=”Refresh” content=”1;url=http://your-new-site.com/archives/<$MTEntryID pad="1"$>.html”>

As long as you are using the same naming scheme with the MTEntryID (which is the default), your old entries will point directly to the new site.

After a while, once people have stopped linking to the old domain, then you could just delete the individual archive files from the old server.

A Variety of MT Things

Sunday, February 9th, 2003

From my travels for today:

:: Want to convert from LiveJournal to MT? Meredith has information on how to do it here and is working on a full tutorial.

:: SimpleComments from Kalsey Consulting Group will allow you to display your comments and your trackback pings all together in one spot. The logic being that trackbacks are really just comments left on someone else’s site. (found at RevJim)

Plugin Directory

Wednesday, December 4th, 2002

There’s been so many great plugins developed for Movable Type since that functionality was added. To keep track of them all, and to help me in answering questions on the forums, I put together a Plugin Directory (powered by MT, of course!) It actually uses some of the plugins that I hadn’t tried out yet (Columnize and Key Values are most notable).

So if you’ve been looking for a solution but don’t have PHP, some of these perl-based plugins may help you out.