Topic: Blog Business

Welcome to Movable Type 3.2b3

So I spent the last couple days upgrading (that’s why the blog has been unreachable at times). It was difficult getting everything working, but I think it was worth it since TBOTCOTW looks so great with the new Vicksburg stylesheet.

Most of my troubles were with the new templates, they changed the entire structure of them a lot, so I had to translate all my old stuff into the new language. But MT now defaults to two columns for every index, and that’s really nice, because I like having the sidebar on the individual archives. Before I had to hack it in myself, with mixed results. Oddly, pulling an archive tag in dynamic publishing is much slower in this release (it was slow in the last one, but not this bad), so I had to drop the “previous - current - next” links that used to appear at the top of each post. Not only did they made loading a page take an intolerably long time, it was also stressful enough to crash my server under a pretty light load (hence the downtime). Hopefully they get that worked out in the final release.

I was using dynamic publishing before, but with the new release they made creating multiple archive mappings much easier (or they just made it clearer what mappings do). If you look at the permalinks now they go to files named after the entry title in a year/month directory structure. This is cool because new inbound links to a post will make more sense, rather than just going to 000314.php, yet old links floating around out there aren’t broken.

If I’d done this before, with static publishing, MT would have created each file twice which would obviously take up twice the disk space and nearly double the time to rebuild the blog. Even your wait time after hitting submit on a comment would have nearly doubled! But now none of the files or even the directories really exist at all, they’re just links in the database that are sussed out whenever someone requests a post. Sweet!

I haven’t seen any major bugs (a couple of interface things that I need to submit) so I’m really enjoying the beta. I’m not, however, looking forward to the final release. It’s such a pain to migrate template changes that I’m hoping they don’t change anything. I do hope that sometime in the future (3.3?) we see comment notification built-in, like Expression Engine has, especially since MT-Notifier has been broken by the new release and its developer has lost some of his desire to continue developing it for free. Who can blame him for that? Maybe he can get hired by Six Apart, it’s a really great plugin that would benefit greatly by being even more tightly integrated into the code.

Popularity: 3% [?]

Pageview counts for Movable Type in PHP

I decided it was a bit too ambitious to try to turn my pageview functions into a plugin right now. It will be much easier to just describe it in a post.

First, create a new table called mt_ext_pageview in your Movable Type database. It needs to have three integer fields: entry_id, blog_id, and pageviews. I use PHPMyAdmin for database tasks, and it’s pretty self-explanatory so I won’t go into it here. If you need help leave a comment or email me.

Now create a module template called Pageview Header. This will load all the defaults for accessing the database; you’ll obviously need to edit in your info.

<?php
$host = 'localhost';  // database server hostname
$user = 'matt';  // database username
$password = 'password';  //  database password
$database = 'mt3';  // MT database
mysql_connect( $host, $user, $password );
mysql_select_db( $database );
?>

Next create another module template called Pageview Record. This one increments the number of pageviews and then prints it. You’ll link to this one in your individual archive template later. For the IPs you can enter addresses that you (the weblog author) use, then the script won’t count your own hits. If you don’t have three IPs you need to filter just use ‘0.0.0.0′ for the others.

<?php
$remote_ip = "{$_SERVER['REMOTE_ADDR']}";
$my_ip1 = '10.1.1.1';
$my_ip2 = '67.165.220.202';
$my_ip3 = '127.0.0.1';
$pageviews = 0;
$entry_id = $this->tag('MTEntryID');
$blog_id = $this->tag('MTBlogID');
$rs = mysql_query( "SELECT pageviews FROM mt_ext_pageview WHERE entry_id = $entry_id" );
$num = mysql_numrows( $rs );
if ($num > 0) {
   $pageviews = mysql_result( $rs, 0 );
} else {
   mysql_query( "INSERT INTO mt_ext_pageview (entry_id, blog_id, pageviews) VALUES ($entry_id, $blog_id, 0)" ); }
if1 {
   $pageviews++;
   mysql_query( "UPDATE mt_ext_pageview SET pageviews = $pageviews WHERE entry_id = $entry_id LIMIT 1;" );
}
if ($pageviews > 0) { echo "| $pageviews pageview"; }
if ($pageviews > 1) { echo "s"; }
?>

Next is Pageview Display. This one will print the number of pageviews an entry has without incrementing the number. It’s what you’ll link to in your indexes where you want to see how popular entries are without adding a pageview.

<?php
$entry_id = $this->tag('MTEntryID');
$rs = mysql_query( "SELECT pageviews FROM mt_ext_pageview WHERE entry_id = $entryID" );
$num = mysql_numrows( $rs );
if ($num > 0) {
   $pageviews = mysql_result( $rs, 0 );
   if ($pageviews > 0) { echo "| $pageviews pageview"; }
   if ($pageviews > 1) { echo "s"; }
}
?>

Now comes the tricky part. At the beginning of the last two snippets of code you’ll see I set the $entry_id and $blog_id variables with these lines.

$entry_id = $this->tag('MTEntryID');
$blog_id = $this->tag('MTBlogID');

Those lines will work in dynamically built templates, but it will have to be changed for static templates to this.

$entry_id = <$MTEntryID$>;
$blog_id = <$MTBlogID$>;

This has something to do with the PHP nature of dynamically generated pages, versus the perl code that static pages are run through. I don’t really want to digress now (I don’t understand it well, anyway) but suffice to say it took me a while to figure it out and I couldn’t have done it without the fine support people at Six Apart. Once MT3.2 comes out of beta I’ll rewrite this whole thing using the new <MTIfDynamic> and <MTIfStatic> tags, but until then it just has to be kludgy. If, like me, you have both dynamic and static index pages just make one version called Pageview Display for the static templates and another called Pageview Dynamic for the dynamic ones.

This code also doesn’t work if you’re caching your dynamic pages. The counter won’t increment after the first hit unless you update the entry, causing it to recache, and then it will just pick up one more hit until the next update. When MT caches a file it preprocesses the PHP code and outputs straight HTML. Then it serves up that HTML to everyone that views the page later, so the PHP code doesn’t get hit again. Even if you set your individual posts to static so the counter increments the displayed counts on your dynamic indexes will be incorrect and jump up in fits and starts. I’m trying to come up with a way around this, but I think it will be complicated and/or in javascript (and I don’t much like javascript). Besides, on a blog the size of mine purely dynamic publishing works just fine.

Now we just have to include the modules in the templates. Put “<MTInclude module=’Pageview Header’>” before the </head> in each of your index templates. Then put “<MTInclude module=’Pageview Record’>” wherever you want the number to print in your individual archive template, and “<MTInclude module=’Pageview Display’>” in all your other templates. Now you’ll be able to see the count from any page and every time someone reads the post all by its lonesome the number will increment.

Popularity: 3% [?]

  1. $my_ip1 !== $remote_ip) && ($my_ip2 !== $remote_ip) && ($my_ip3 !== $remote_ip []

Improving import/export

When I was upgrading from movabletype 2.661 to 3.17 I wanted to start fresh but have the archives of all my old posts, too. I’d messed up my installation so much I couldn’t just run the upgrade program. I had to install fresh and then import all my entries.

There’s one big problem with that. MT assigns posts a number in order of date of posting and that’s what it uses for filenames. That number is globally sequential, so if there are multiple blogs on a system their post numbers are interspersed. MT also doesn’t reuse numbers if a post is deleted so, either way, you end up with a lot of “holes” in your posts’ numbers. The export function doesn’t bother associating the number with the post and import just assigns each successive post the next number, starting from one. You end up with a perfectly numbered blog, with no “holes.”

So if you export and then import all your entries get renumbered, their filenames change, and old links to your site get broken and start going either nowhere or to the wrong post.

I thought up a surprisingly easy fix after I got sick of renumbering the entries by hand. If you’ve installed a new copy of MT in parallel with your old version you have two copies of /lib/MT/App/CMS.pm on your system, one for 2.661 and the other for 3.17. Pull both of them up in your favorite editor. Then insert “ID: <$MTEntryID$>” at line 3633 of the 2.661 version and the following code at line 4504 of your 3.17 version:

} elsif ($key eq ‘ID’) {
$entry->id($val);

Now your export will include an ID field and your import will recognize it and none of your permalinks will change.

Popularity: 2% [?]

Upgrade to MT3.1

I realized that trackbacks weren’t working when a couple of blogs linked to my last post. I couldn’t figure out how to get them to work and I’d hacked up the code so much that I couldn’t just reload all the 2.661 files without basically starting from scratch. I’d already considered upgrading to MT3.1 for various reasons (dynamic publishing, the new version of MT-Blacklist, and the desire to give the MT people some money) and this pushed me over the edge.

Anyway, I’ve got most things working and looking ok now, but I’ll be working out a few more kinks (like a blogroll) over the next week. Please email me or leave a comment if anything is broken or if there’s a feature from the old blog you miss.

Once everything is up and running I’ll finally get around to writing a howto for the pageviews counter. I never did before, even though some have requested it, because that code was originally designed to display a list of referrers for each page and was therefore very complicated. But now I’ve rewritten the whole shebang as a lean, mean pageview counter (some people complained about the referrer stuff, it was possibly fucking up Google searches) and it’s much easier to understand. I might even write it into a plugin to make it super easy to use.

Popularity: 2% [?]

You’re invited to the RMBB 4.0

It’s time for the Rocky Mountain Blogger Bash 4.0! This will probably be the best blogger bash ever, just look at this partial list of attendees. Plus, we’re renting out the Denver Press Club, so it’ll be a classy affair with no civilians for Goldstein to antagonize. But wait, there’s more! Steve Green has promised to buy blog readers he’s never met before one free drink. I’ll make a similar promise: If I’ve never met you before, Steve will buy you one free drink.

Click the image for more details, and we’ll see you Saturday at 7.

Popularity: 2% [?]

A new anti-spam tool

This is pretty cool. It’s a movabletype plugin that makes sure actual keys were pressed in the text field. So real comments get through, but spambots are rejected. It’s a Turing test that the user doesn’t even know they’re taking! The only real problem I see is that it might stop some blind readers from commenting if they’re using a non-javascript braille browser. But most of the anti-spam tests (of the “type this word into the box” type) defeat the blind; at least this one has a chance of letting them comment.

I wish there was a 2.661 version. I should probably upgrade to MT 3.0 anyway.

Popularity: 2% [?]

The power of the bleg

Look at that, I bleg, I get results. Two commenters clued me into what Dick’s Sporting Goods is doing. They bought Galyans and have closed at least one down. Whether for remodelling as a Dick’s or a money saving measure (the rent at Flatirons must be horrendous) we’ll have to see.

I love blogging. Maybe I won’t quit again for a while.

Popularity: 2% [?]

Be back soon

Sorry about the downtime and lack of posts. I’m busy moving in and starting work. I’ll probably post again next week.

Popularity: 2% [?]

Moving to 1and1

Thanks go to Ryan for pointing out 1and1’s free hosting offer. 500 meg of web space, 100 meg of MySQL space, and five gigs a month of bandwidth, free! For three years!

Since I’m gonna have to move the ‘puters in the next two weeks I figured I’d move TBOTCOTW there, at least temporarily. I got all my info into the database, installed MovableType, and then tried to build the blog and hit a snag. This error popped up when an entry using the MTAmazon plugin was being built: MT::App::CMS=HASH(0×837bc34) could not find ParserDetails.ini in /usr/share/perl5/XML/SAX. I looked around, and it seems that the makefile for Perl’s XML parser has a bug, and it fails to create ParserDetails.ini in some cases. So I emailed tech support, and hopefully they reinstall the parser soon.

Popularity: 3% [?]

Explanation

I’m sorry I was absent from the Colorado blog round-up. My only excuse is a sheer lack of decent posts for January.

Like I said, I’m sorry. I’ll try to do better next month.

Popularity: 2% [?]