toc

Team LiB
Next Section

Movable Type 3.0 Bible, Desktop Edition
Movable Type 3.0 Bible, Desktop Edition
by Rogers Cadenhead ISBN:0764573888
John Wiley & Sons © 2005 (410 pages)

From exploring Movable Type's template-driven publishing system to developing your own plug-ins, this indispensable guide will teach you what you need to know to create and maintain dynamic Web sites.

Table of Contents
 | Movable Type 3.0 Bible, Desktop Edition
 | Preface
 | Chapter 1 | - | Publishing with Movable Type
 | Chapter 2 | - | Preparing a Web Server for Movable Type
 | Chapter 3 | - | Installing Movable Type
 | Chapter 4 | - | Configuring a Weblog
 | Chapter 5 | - | Writing a Weblog Entry
 | Chapter 6 | - | Organizing a Weblog
 | Chapter 7 | - | Publishing Photographs and Other Files
 | Chapter 8 | - | Producing Web Pages with Template Tags
 | Chapter 9 | - | Designing a Weblog with Templates
 | Chapter 10 | - | Offering Comments
 | Chapter 11 | - | Sharing Trackback Links
 | Chapter 12 | - | Backing Up a Weblog
 | Chapter 13 | - | Adding Search Capabilities to a Weblog
 | Chapter 14 | - | Importing Entries from Another Weblog
 | Chapter 15 | - | Connecting to Movable Type with XML-RPC
 | Chapter 16 | - | Enhancing Movable Type with Plug-Ins
 | Chapter 17 | - | Presenting External Web Content with Plug-Ins
 | Chapter 18 | - | Publishing RSS Syndication Files
 | Chapter 19 | - | Supporting the Atom Syndication Format and API
 | Chapter 20 | - | Developing New Plug-Ins with Perl
 | Chapter 21 | - | Hooking into Movable Type with Plug-Ins
 | Appendix | - | Using Movable Type 3.1
 | Index
 | List of Figures
 | List of Tables
 | List of Listings
 | List of Sidebars

Team LiB
Next Section


backcover

Team LiB

Back Cover

If Movable Type can do it, you can do it too…

By its very nature, the Web encourages change at a frenetic pace. Movable Type helps you manage that pace, and this is your indispensable guide to installing and using the most popular server-based personal publishing tool. From exploring Movable Type's template-driven publishing system to developing your own plug-ins, here's what you need to know to create and maintain sites as adaptable as the Web itself.

Inside, you'll find what you need to know about Movable Type

  • Prepare your Web server and install Movable Type
  • Set up and configure a weblog, using archives and categories to create a more sophisticated site
  • Add visual elements with photos and graphics
  • Design a weblog with templates and use template tags
  • Establish communication among sites using trackback pings
  • Add search capabilities and import content from other blogs
  • Develop Perl-based plug-ins to enhance Movable Type
  • Configure Movable Type to receive and manage comments from site visitors
  • See what's new in Movable Type 3.1 in a bonus Movable Type 3.1 appendix

About the Author

Rogers Cadenhead is a Web developer, RSS Advisory Board member, and host of more than 3,000 webloggers on Buzzword.Com. He has written 19 books on Internet-related topics, including Radio UserLand Kick Start and Teach Yourself Java 2 in 21 Days. He’s also a Web publisher whose sites receive more than 10 million visits a year.

Team LiB


Movable Type 3.0Bible, Desktop Edition

Rogers Cadenhead

Published by Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com

Copyright © 2005 by Wiley Publishing

Published by Wiley Publishing, Inc., Indianapolis, Indiana

Published simultaneously in Canada

Library of Congress Control Number: 2004020829

ISBN: 0-7645-7388-8

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

1B/SQ/RQ/QU/IN

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, E-Mail: brandreview@wiley.com.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Website is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Website may provide or recommendations it may make. Further, readers should be aware that Internet Websites listed in this work may have changed or disappeared between when this work was written and when it is read.

For general information on our other products and services or to obtain technical support, please contact our Customer Care Department within the U.S. at (800) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.

Trademarks: Wiley, the Wiley Publishing logo and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.

About the Author

Rogers Cadenhead is a Web developer, RSS Advisory Board member, and host of more than 3,000 webloggers on Buzzword.Com. He has written 19 books on Internet-related topics, including Radio UserLand Kick Start and Teach Yourself Java 2 in 21 Days. He’s also a Web publisher whose sites receive more than 10 million visits a year. He maintains this book’s official World Wide Web site at http://www.cadenhead.org/movable.

Credits

Acquisitions Editor
Jim Minatel

Development Editors
Kezia Endsley

Production Editor
William A. Barton

Technical Editor
Wiley-Dreamtech India Pvt Ltd

Copy Editor
Luann Rouff

Editorial Manager
Mary Beth Wakefield

Vice President & Executive Group Publisher
Richard Swadley

Vice President and Executive Publisher
Bob Ipsen

Vice President and Publisher
Joseph B. Wikert

Executive Editorial Director
Mary Bednarek

Project Coordinator
Erin Smith

Graphics and Production Specialists
Beth Brooks
Lauren Goddard
Joyce Haughey
Jennifer Heleine

Quality Control Technicians
John Greenough
Susan Moritz
Carl William Pierce
Brian H. Walls

Media Development Specialist
Angela Denny

Proofreading and Indexing
TECHBOOKS Production Services

To the Moewes: Laura, Michael, Joey, Julia, and Jordan. Thanks for being family; for raising a family of Brawl champions; for sweeping into our home like a whirlwind at least once a year; and, most notably, for losing the documentary I filmed at one of your parties under the influence of Molson Golden in 1993.

—Rogers

Acknowledgments

I’d like to thank each of the following people:

The team at Wiley Publishing, including Kezia Endsley, Bill Barton, Luann Rouff, Erin Smith, and, of course, Jim Minatel. As a long admirer of Wiley books, I’m gratified to have the opportunity to produce one of my own. This proved to be one of those challenging and enriching life experiences from which real personal growth can be achieved. Though I try to avoid that sort of thing, working with each of you has been a real pleasure, and I’m proud of the work we’ve done.

The people at Six Apart who most assisted me during the preparation of this manuscript, Mie Kennedy and Anil Dash. Finding the time to answer my pestersome e-mail had to be difficult during the build up to the release of Movable Type 3, so I greatly appreciate the fact that you did.

My tireless agent at Studio B, Laura Lewin.

The weblog publishers I read regularly who provide me with inspiration in hourly installments: Danny Ayers, Andrew Bayer, David Bayly, Greg Beato, Rebecca Blood, Steve Bogart, Julian Bond, Jeremy Bowers, Brian Carnell, David Carr, Nicholas Chase, Rafe Colburn, Gael Fashingbauer Cooper, Matt Croydon, Christian Crumlish, Derek Dahlsad, Anil Dash, Scott Erickson, Richard Eriksson, Mark Evanier, Wes Felter, Michael Fioritto, Alison Fish, Jim Flowers, Jimi Gooding, Brian Graf, N. David Griffin, Elliotte Rusty Harold, Matt Haughey, J. H. Haviland, Rob Henerey, Matt Hinrichs, Meg Hourihan, Tim Jarrett, Joe Jennett, David Knighton, Jason Kottke, William Lazar, Jason Levine, Richard MacManus, Mikel Maron, Lindsay Marshall, Mike Masnick, Edward Miller, Dave Mitchell, L. M. Orchard, Mark Paschal, Phillip Pearson, Steve Pilgrim, Jim Roepcke, Dave Rogers, Anita Rowland, Dwight Shih, Todd Smith, Kevin Story, Melissa Story, Erik Thauvin, Donovan Watts, Sandor Weisz, and Wendell Wittler.

My wife, Mary, and sons, Max, Eli, and Sam. It has to be difficult, on both a personal and genetic level, to share a life with someone who spends enough time in front of a computer to qualify as a plug-and-play device. I am heartened beyond words for the love and support I have received for our first decade of familyhood.


Preface

Developments move so quickly on the World Wide Web that a phrase was coined to describe the sensation: Internet time. At the height of the dot-com boom, so many innovations were introduced that it was difficult for even the most plugged-in, overzealous Internet geek to keep up with it all (and believe me, I tried). Today, now that boom has given way to bust, the Internet has become a ubiquitous part of our lives, ingratiating itself into how we work, shop, learn, and communicate. Approaching adulthood is an entire generation that has grown up with the Web and e-mail, never knowing what life was like without the opportunity to publish for a worldwide audience at little to no cost.

Although the Web has settled down, some things still hearken back to the time when revolutionary new sites, software, and services launched regularly. One of those throwbacks is Movable Type, the amazing weblog publishing software from Six Apart. Movable Type, originally developed by childhood sweethearts Ben and Mena Trott as a labor of love, has become one of the rare success stories in the post-boom Silicon Valley. Downloaded more than half a million times and installed on 30,000 servers, Movable Type ranks as the most popular server-based tool for webloggers.

In this book, you’ll learn why, adopting Movable Type to publish the personal publishing sites that have come to be known as weblogs. You’ll work with some of the most innovative publishing tools available on the Web, using templates to create pages and other files using the same style of markup as HTML. You will share your work with the RSS and Atom syndication formats, communicate with the software over the XML-RPC Web services standard, and extend the capabilities of the product with your own plug-in scripts.

By the time you finish, you’ll be a part of the second Web publishing revolution, using content-management software and databases to create and update your sites in a faster and more creatively satisfying way.

When you have harnessed the capabilities of Movable Type, you can share content on the Web easier than ever before, whether you’re interested in authoring a weblog, publishing your digital photographs in a moblog (or mobile blog), or developing something so new that it doesn’t even have a name yet.

Who Should Read This Book?

If you have been publishing a weblog with Movable Type or any other software, this book will help you discover why Movable Type has become one of the leaders in its category.

If you are a Web designer who wants to get away from editing pages manually with software such as Microsoft FrontPage or Macromedia Dreamweaver, this book will help you get started with content-management software, a process that’s likely to relegate your old HTML editors to the Recycle Bin.

If you are a programmer who wants a framework you can extend to create a publishing tool that meets your precise needs, this book will help you develop your own plug-ins, customizing the software to the point that it’s practically a new product. This book covers the full breadth of the product, beginning with a full exploration of the Web publishing and site-creation capabilities of the browser-based interface and Movable Type’s template-driven publishing system. Next, special emphasis has been placed on the most need-to-know aspects of the software such as RSS and Atom syndication, and XML-RPC Web services. Finally, the software’s killer app is covered in precise detail: how to add plug-ins created by other developers to your software, take advantage of their functionality, and develop plug-ins of your own.

Users of Movable Type 2.6 and earlier versions can master all of the great new features introduced in version 3, including the comment-management features, the plug-in manager, and support for the Atom syndication format and application programming interface (API).


What Hardware and Software Do You Need?

If you have a Windows, Linux, or Mac computer with a Web server that runs CGI programs written in Perl, you can run Movable Type. The software runs at its best with a relational database — most notably, the open-source programs MySQL and Berkeley DB.

Because of Movable Type’s popularity, some Web hosting services have pre-installed everything that’s necessary to get the software running.

Download a free personal version of the software from the Web site http://www.movabletype.org. You can dive into the software with this book while evaluating whether to upgrade to a commercial license.


How This Book Is Organized

This book has been organized so that you can make the most of your time as you are progressing through its pages. You can read it in order and establish broad expertise in the software or pick and choose the subjects most important to you, reading it in any order.

Chapters 1–3: Getting Started with Movable Type

As a program that requires special installation on a Web server, Movable Type can be challenging to set up for the first time, especially if you have never set up a server-based program before. Chapter 1, “Publishing with Movable Type,” describes what the product does and why you should be glad to have bought a 500-page book documenting its features in loving detail. Chapter 2, “Preparing a Web Server for Movable Type,” does exactly that, helping you get a server ready for its introduction. This section ends with Chapter 3, “Installing Movable Type,” the point at which you’re ready to begin your mastery of the software in earnest.

Chapters 4–7: Publishing Your Weblog

This section of the book provides a well-rounded tutorial on the care and feeding of Movable Type’s user interface, which runs in a Web browser.

Chapter 4, “Configuring a Weblog,” steps through the process of setting up a new weblog and customizing it to suit your publishing goals. Chapter 5, “Writing a Weblog Entry,” puts Movable Type in motion, showing how to write entries and configure the editing environment as desired. Chapter 6, “Organizing a Weblog,” explains how to make use of archives and categories to create a more sophisticated site. The last chapter of this section is Chapter 7, “Publishing Photographs and Other Files,” which offers you a chance to add some visual pizzazz to your weblogs.

Chapters 8–14: Moving Forward into Advanced Features

The next seven chapters of the book cover topics that will enhance your skills as a weblogger and make your sites more compelling for your audience. Chapters 8–9, “Producing Web Pages with Template Tags” and “Designing a Weblog with Templates,” shine the spotlight on one of the most exciting and innovative elements of the software, the template-based publishing system that merges HTML-style page markup with dynamic Web content generated by Perl scripts. Next, you can turn your one-way medium into a thriving community by reading Chapters 10 and 11, “Offering Comments” and “Sharing TrackBack Links.” The latter chapter details TrackBack pings, a form of communication between different Web sites that was created by Movable Type’s founders, Ben and Mena Trott. The final three chapters of the section are more specialized: Chapter 12, “Backing Up a Weblog;” Chapter 13, “Adding Search Capabilities to a Weblog;” and Chapter 14, “Importing Entries from Another Weblog.” These come in handy when you need their capabilities.

Chapters 15–21: Becoming a Movable Type Expert

This final section of seven chapters provides highly detailed coverage of Movable Type’s advanced features.

Interested in running Movable Type from another program? Read Chapter 15, “Connecting to Movable Type with XML-RPC”. Looking for plug-ins that add cool new features to the program? Read Chapter 16, “Enhancing Movable Type with Plug-Ins” and Chapter 17, “Presenting External Web Content with Plug-Ins.” Eager to participate in the XML-based syndication movement sweeping through the Web? Chapter 18, “Publishing RSS and Atom Syndication Files,” and Chapter 19, “Supporting the Atom Syndication Format and API,” explore these subjects.

The most exciting topic in the book may have been saved for last. Chapter 20, “Developing New Plug-Ins with Perl,” and Chapter 21, “Hooking into Movable Type with Plug-Ins,” are hands-on tutorials for creating your own plug-ins. Plug-ins are enhancement scripts that build on the object-oriented framework of classes developed by Six Apart.


Navigating This Book

Various icons are scattered throughout the Movable Type Bible, Desktop Edition for your assistance. Each chapter begins with an overview of its information and ends with a quick summary.

Icons appear in the text to indicate important or especially helpful items. Here’s a list of the icons and their functions

Tip

Tips indicate important advice that helps you make the most of the software.

Note

Notes offer additional advice or point out details to help you better understand the current topic.

Cross-Reference

This icon indicates other chapters in the book where you can find more information on a particular topic.

Caution

Cautions provide critical and often overlooked information that will help you avoid disasters.

Web Site Download

These notes refer you to Web sites that provide updated information or discussions of topics that go beyond the scope of this book.

Gotcha

Gotchas provide important warnings about potential issues you might run into and ways to avoid the problems.

New Feature

The New Feature icon outlines new features related to Movable Type 3, such as support for the Atom syndication format.


The Companion Web Site

The official Web site for this book can be found on the author’s Web site at http://www.cadenhead.org/movable. The site includes official updates, errata, a weblog that covers Movable Type plug-ins and other enhancements, and details about new book versions.


Further Information

As you might expect, the author of such a weighty book on weblog publishing is the author of his own. On Workbench, I write regularly on Movable Type and other tools and technology of note in online publishing. I also provide updates as needed to the material in this book. Visit the site to read more and use my feedback page to contact me via e-mail: http://www.cadenhead.org/workbench.


Chapter 1: Publishing with MovableType

In This Chapter

  • Keeping Web pages current

  • Relying on a content-management system

  • Running an application on a Web server

  • Choosing Movable Type

  • Publishing a weblog

  • Reaching an audience

  • Finding a suitable hosting service

  • Preparing to install the software

The World Wide Web is a dynamic medium, but you wouldn’t know it from looking at millions of Web sites. Most Web pages are published once and never touched again, static documents that can remain online in their unchanged form for years, like a digital version of a fly caught in amber.

In Internet time, a Web site that hasn’t changed in months is already a fossil. Once the site has been found and indexed by search engines such as Google, it will attract some visitors and may even be saved occasionally as a browser bookmark, but it won’t become popular. A good Web site must be habit-forming to find an audience, but the only way to cultivate that habit is to reward repeat visitors with new material.

The biggest reason a Web site never changes is because the process of changing it is too hard. Most Web publishers create their work in a manner similar to writing a letter in a word processor. Pages are created, formatting is applied, and they are published to a Web server. When a change needs to be made, it must be done by hand one page at a time, a task that gets exponentially more difficult as a Web site grows in size.

Even the hardest-working or best-intentioned Web publisher leaves behind a pile of static Web pages that desperately need to be updated. I fall into neither of those virtuous categories—at least 1,000 of the 3,800 pages on my personal Web site contain outdated information, an old version of my site design that needs to be freshened up, bad formatting, or some other stale content that deeply aggravates my inner pedant.

The way to solve the aging-page problem forever is to stop editing Web pages by hand and start using a content-management system (CMS), software that simplifies and automates as much of the Web publishing process as possible. A good CMS speeds up the creation, publication, and maintenance of Web sites and can often make the process vastly more enjoyable. Some of these programs even can produce Web pages on their own with no help from you—such as a discussion forum where visitors can post public messages to each other.

One of the most promising content-management systems to come along in recent years is Movable Type.


Joining the Content-Management Revolution

For most of the Web’s existence, content-management systems were strictly for big businesses and other large enterprises. They had price tags with three, four, or even five zeroes and were too complex for any mom-and-pop publisher to even think about using.

Today, a Web publisher can choose from dozens of affordably priced or even free content-management systems that are designed for everyday users.

Movable Type is a content-management system that streamlines the process of publishing a weblog, an online journal that is updated frequently and organized by date. It’s also well suited for other forms of Web content such as digital photos and news articles.

The software’s developer, Six Apart Ltd., calls its flagship product a “personal publishing system,” offering it for download at the software’s official Web site (http://www.movabletype.org).

Delivering Web Content with Movable Type

Even if you are actively using Movable Type and are comfortable with its basic features, there are undoubtedly some things you don’t know about it yet. The software hides a lot of capabilities underneath a deceptively simple user interface.

This chapter takes a comprehensive look at what Movable Type is, how you can use it to manage your creative output on the Web, and why you should be glad you bought a 500-page book that documents the program in obsessive detail.

Movable Type was developed by the husband-and-wife team of Ben and Mena Trott, a pair of high-school sweethearts in their mid-20s whose Six Apart company takes its name from the number of days between their birthdates. I share this piece of trivia because I can’t help myself—the story of how the Trotts created and popularized their software is one of the most charming human-interest stories in Web publishing. Movable Type users speak of “Ben and Mena” as if they were Brad and Jennifer, Ashton and Demi, or some other celebrity couple so impossibly famous that no last names are necessary.

The software that Ben and Mena created is distinguished from other weblog publishing programs primarily in two ways:

  • Movable Type can run on your own Web server or Web hosting account, unlike a centrally hosted service such as Blogger or Manila. Because it operates on a server under your control, your Web site data is available to you at all times in any form you need. You can easily back everything up on a regular basis (always a good idea) and import or export weblog entries and other Web content.

  • Movable Type doesn’t require special authoring software, unlike a desktop-based publishing tool such as Radio UserLand or CityDesk. You can use any Web browser to work on your site, even over the Internet. No particular operating system is required—as long as you have an Internet-connected computer and can load your site in a Web browser, you can work on it from anywhere.

The two halves of Movable Type combine to form a client/server Web application.

On the server side, the software is implemented as a set of Perl scripts and supporting Perl libraries that can be run by any Web server that supports the Common Gateway Interface (in other words, just about every Web server in existence).

On the client side, the software can be used with any Web browser that has JavaScript capabilities. All of the popular browsers support this scripting language, including Microsoft Internet Explorer, Mozilla Firefox, Opera, and Safari, although some people turn the feature off to avoid pop-up ads, security exploits, and other grief.

This JavaScript requirement also applies to visitors to your Web site. Some of the features you can offer on your weblog, such as visitor comments, are implemented with the scripting language and cannot function without it.

Requirements to use Movable Type are pretty slim: a Web server with Perl version 5.004_04 or later, an FTP server, a database, and at least 27 megabytes of hard disk space (2 for the software and another 25 to leave room for your weblog data, photos, and other content).

Movable Type employs Structured Query Language (SQL) to store and retrieve content in a database for presentation on the Web. The software is designed to work equally well with different database programs. At the time of this writing, several relational databases can be used for storage: Berkeley DB, MySQL, PostgreSQL, and SQLite. For version 3.0 of the software, Six Apart officially recommends either Berkeley DB or MySQL.

Web Site Download

This book focuses entirely on Movable Type, so if you don’t have these other programs running, you might need to find supplementary help elsewhere. These Web sites are the places to start.

Web browsers:

http://www.microsoft.com/ie

http://www.mozilla.org/products/firefox

http://www.apple.com/safari

http://www.opera.com

Database programs:

http://www.sleepycat.com (Berkeley DB)

http://www.mysql.com

http://www.postgresql.org

http://www.sqlite.org

Other software:

http://www.perl.com

Acquiring the Software

Six Apart prices Movable Type from $70 to $100 for noncommercial use and from $200 to $1,300 for commercial use, which depends on how many users work on your weblogs. The company’s Web site provides the software, online documentation, a directory of Movable Type resources, and an active user support community (http://www.movabletype.org).

Ben and Mena Trott began developing Movable Type in 2001 with the modest goal of creating a content-management system solely for Mena’s personal weblog. At the time, weblogging was still a relatively new phenomenon. Most publishers created their sites by hand or by using one of the first weblog-specific publishing programs that became available: Blogger, created by Pyra Labs, now a part of Google; Manila, from UserLand Software; and Greymatter, an open-source program by Noah Grey.

The Trotts quickly decided that Movable Type should turn pro, releasing it publicly for the first time on Oct. 8, 2001. Since then, their company and its flagship product have become one of the rarest creatures in post-boom Silicon Valley: a successful Internet startup.

Table 1-1 presents the most popular weblog publishing software that runs on an individual Web server, according to a June 2004 weblog census conducted by the National Institute for Technology and Liberal Education.

Table 1-1: Most Widely Used Standalone Weblog Tools†
Software | Installed Servers | Percentage
Movable Type | 42,311 | 74.83
b2 | 4,035 | 7.14
PHP-Nuke | 3,105 | 5.49
Microsoft Visual Studio | 2,067 | 3.66
Postnuke | 1,913 | 3.38
PMachine | 1,318 | 2.33
Greymatter | 754 | 1.33
Nucleus | 489 | 0.86
Pivot | 348 | 0.62
Others | 205 | 0.36
† Source: National Institute for Technology and Liberal Education, http://www.blogcensus.net.

As the numbers in Table 1-1 attest, Movable Type has become the most successful weblog publishing software in its category. In addition to the 42,000 Movable Type users who showed up in the weblog census, the software has been downloaded more than 500,000 times.

In April 2003, the Japanese venture capital firm Neoteny invested in Six Apart, enabling the five-person startup to hire more employees and launch a hosting service called TypePad (http://www.typepad.com).

TypePad offers Movable Type publishing to people who want Six Apart to take care of the server side of the software, freeing themselves from the need to install the program, keep up with upgrades, or find suitable Web hosting. Some features for advanced users are absent, such as plug-ins and custom server configuration, and a few new things have been added. All that’s required to begin publishing with TypePad are a Web browser and a monthly subscription priced from $5 to $15.


Exploring the Movable Type Software

Because Movable Type runs on a Web server and functions like a Web site, you might think of it strictly in those terms. You don’t have to install anything on your personal computer to use the software (assuming you already have a browser, of course).

On the server, you must either install Movable Type or join the TypePad commercial hosting service. When Movable Type is installed on a Web server, the software can be accessed like any other Web site hosted by that server. Figure 1-1 shows a Movable Type installation being put to work in the Mozilla Firefox browser.

Click To expand
Figure 1-1: Editing a weblog with Movable Type.

The page shown in Figure 1-1 is a weblog’s main editing page, which includes links to edit recent entries. You can get around the software by using the sidebar menu buttons and the Main Menu link, which appear on every page in the software’s browser-based interface.

Movable Type can be controlled with any JavaScript-enabled Web browser, as long as its scripting feature has not been turned off. To double-check this setting in your browser:

  • On Mozilla and Netscape Navigator, choose Edit ® Preferences. Expand the Advanced category, and then choose Scripts & Plug-ins. An Enable JavaScript checkbox appears.

  • On Internet Explorer, choose Tools ® Options, bring the Security tab to the front, click Custom Level, and then look for the Scripting heading in the Settings list box. The Active Scripting checkbox tops the list.

  • On Opera, choose File ® Preferences, and select Multimedia from the list box. You’ll see the Enable JavaScript checkbox.

A single installation of Movable Type can support multiple weblogs written by one or more authors. Although you have full access to the software and all of its features, your collaborators can be given much more restricted capabilities through a system of permissions.

Sharing the Workload with Other Authors

Movable Type was designed to support collaboration. Any Web site published with the software can be a team effort, regardless of whether you’re working with people separated by an office or an ocean.

The software’s collaborative features are highly configurable. Authors of your weblogs operate entirely under your control—they can’t do anything to a site without permission.

After you create a user account and password for an author, you can add the user to one or more weblogs and define the specific tasks he or she is allowed to perform. Figure 1-2 shows permissions being set up for a new user.

Click To expand
Figure 1-2: Defining what a user is permitted to do in Movable Type.

Each user can be assigned two big general permissions and 10 smaller ones for each weblog. The biggies are the capability to create new weblogs and view the software’s activity log, two capabilities that you might want to keep strictly for yourself.

The other permissions apply to a specific weblog. They determine whether the author can contribute weblog entries and files, edit posts written by other authors, change the site’s design, and make other changes. In Figure 1-2, my father-in-law Clint Moewe is being permitted to add new entries to the Orlando Vacationer weblog, upload files such as digital photos, and republish the entire site. We belong to a family of Disney World fiends, so I wanted to give him an opportunity to contribute to the site.

These permissions can vary from weblog to weblog—an author can have the full range of capabilities on one weblog and be a more limited contributor to another.

Once authors have been set up for a weblog, they can write and edit weblog entries with an editing form on a Web page. Because this page and all other parts of the Movable Type user interface are accessible over the Web, an author must provide the correct username and password before accessing any of its pages.

Writing for a Weblog

Although it can be adapted for other uses, Movable Type is designed for the creation of weblogs and other content that is updated frequently and arranged by date.

The part of the program you’ll use most often is the weblog entry form, which collects the information that constitutes a single entry. The following three fields are the most important:

  • Title: A headline for the weblog entry, which can be used to display a list of recent entries

  • Entry: The text of the entry

  • Category: The category in which to place the entry

The weblog entry form can be customized to collect other kinds of information. In Figure 1-3, the form is being used to draft a new entry.

Click To expand
Figure 1-3: Composing a new entry in a weblog.

As a general rule, there are no rules governing the length and composition of weblog entries. The structure of your site’s content is entirely up to you: Some webloggers pen short news-style links offered as headlines with little or no descriptive text. Others write longer, diary-style creations or magazine-length articles.

Movable Type handles this variety of approach through the use of two optional fields on the editing form:

  • Extended Entry: A place for the rest of a particularly long entry

  • Excerpt: A short excerpt of the entry

The Entry and Extended Entry fields are intended to work in tandem with each other. When they are used, the first part of the entry should be put in the Entry field and the remaining text belongs in the Extended Entry field.

The decision of when an entry is long enough to merit using both of these fields is up to its author. Splitting an entry into two fields provides more flexibility in how it can be presented on a weblog, because you can display the introductory part of the entry separately from the full text and format it differently on a Web page. Keeping the entry in a single field gives you less to think about.

The Excerpt field offers a place for a succinct summary of the entry, such as its first paragraph. If the field is left blank, it defaults to the first 40 words of an entry.

Filing Weblog Entries in Categories

Entries in a Movable Type weblog can be organized into one or more user-created categories, a feature that makes it easy to create a topic-based archive of the site.

Using categories, a weblog can be subdivided into smaller weblogs, organized around different subjects, and arranged in other inventive ways. One popular use among Movable Type webloggers is to create a category that contains short, headline-only links and present it as a sidebar to a larger weblog.

Each weblog entry can have one primary category, which is selected from a drop-down menu atop the weblog editing form (refer to Figure 1-3), and one or more additional categories. Filing an entry in multiple categories causes it to show up in several places on the weblog. A subsequent change to the entry will be reflected in all of those places.

Publishing with Movable Type

As stated in the introduction to this chapter, a content-management system makes it easier and more enjoyable to produce Web content by letting a computer handle all of the grunt work. The power of managing content with software becomes apparent when your first weblog entry is published with Movable Type.

When an entry is published, Movable Type saves it in a database and plugs its data into one or more templates, producing output files that can be viewed immediately on the Web.

Templates establish the appearance and layout of the Web pages and other files that make up a site.

Movable Type templates can be used to produce any kind of text-based data. The software’s 16 built-in templates produce HTML Web pages, Cascading Style Sheets (CSS), and several useful XML formats.

Each template holds two kinds of content:

  • Static text that will appear without modification in the output file

  • Movable Type tags that will be replaced with some kind of dynamically generated content

Each Movable Type tag looks like an HTML or XML tag—a name placed within a less-than character (<) and greater-than character (>), as in this simple example from a Web page template:

<h1><MTBlogName></h1>

MTBlogName is a Movable Type tag that represents a weblog’s name. When it appears in a template, it will be replaced by the name in the file produced from that template. For example, on a weblog named Orlando Vacationer, the following HTML is produced as output:

<h1>Orlando Vacationer</h1>

Like HTML and XML tags, a Movable Type tag can contain one or more attributes. Each attribute is a name followed by an equals sign (=) and a value. Multiple attributes are separated by spaces. Each attribute customizes the behavior of a tag in some way. Here’s a tag that appears on an HTML page and makes use of an attribute named format:

<p>Posted on <MTEntryDate format=”%B %e, %Y %I:%M %p”>

The MTEntryDate tag holds the date an entry was written. This date can be displayed in hundreds of ways by using the format attribute with a set of format specifiers. The preceding example produces the following output:

<p>Posted on July 02, 2004 04:39 PM

The format specifiers indicate the placement and style of each part of a date and time. In the example, %B stands for the full month name, %e for the day of the month, %Y for the four-digit year, and so on. The syntax is borrowed from strftime, a popular utility for displaying dates.

A template can make use of more than 130 tags in a standard installation of Movable Type. If you download and install any plug-ins that enhance the functionality of the software, even more tags become available to you.

Listing 1-1 contains a Web page template that displays the last three entries from a weblog on a plain Web page with no graphics and no frills. This kind of template can be used to offer a version of your weblog that’s tailored toward people using a cell phone or personal digital assistant.

Listing 1-1: A Web Page Template
Start example
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title><MTBlogName></title>
</head>
<body>
<h1><MTBlogName></h1>
<MTEntries lastn="3">
<div>
  <h3 class="title"><MTEntryTitle></h3>
  <MTEntryBody>
  <MTEntryIfExtended>
    <span class="extended">
      <a href="<MTEntryPermalink>#more">Continue reading
            "<MTEntryTitle>"</a>
    </span><br>
  </MTEntryIfExtended>
  <a href="<MTEntryPermalink>"><MTEntryDate format="%X"></a>
</div>
</MTEntries>
</body>
</html>
End example

In Listing 1-1, the Movable Type tags have names that begin with MT. All other tags are ordinary HTML tags.

When the template is used to create a Web page, the Movable Type tags are replaced with the output they produce. Everything else will appear exactly as it does in the listing.

A Web page produced with this template is shown in Listing 1-2.

Listing 1-2: A Web Page Produced from a Template
Start example
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>Orlando Vacationer</title>
</head>
<body>
<h1>Orlando Vacationer</h1>
<div>
  <h3 class="title">Disney takes on Muppets, Bear</h3>
  Disney has purchased the Muppets and Bear in the Big Blue House
from Jim Henson Productions after years of effort to acquire them,
according to <a href="http://www.eonline.com/News/Items/0,1,13516,00. html?tnews">E! Online</a>.

  <a href="http://orlandovacationer.com/archives/000098.html">February
20, 2004 11:21 AM</a>
</div>
<div>
  <h3 class="title">Killer whale born at SeaWorld Orlando</h3>
  Kalina, an 18-year-old killer whale at SeaWorld Orlando, gave birth
to her fourth calf Monday at the park’s research and breeding
facility, Shamu Stadium.

  <a href="http://orlandovacationer.com/archives/
      000097.html">February 11, 2004 09:39 AM</a>

</div>
<div>
  <h3 class="title">Disney cuts pass program for disabled</h3>
  Disney World, along with other Disney theme parks, has <a href= "http://www.snopes.com/inboxer/petition/linejump.asp">curtailed
a "special needs pass" program</a> that allowed guests with
disabilities to skip to the head of lines at each ride.

  <a href="http://orlandovacationer.com/archives/
     000095.html">February 7, 2004 08:04 AM</a>
</div>

</body>
</html>
End example

Comparing the two listings provides a taste of how templates and static text come together to form a Web page, which brings us to Figure 1-4, a view of the example page in a Web browser.

Click To expand
Figure 1-4: Generating a Web page from a template.

Once you have created a page or file template in Movable Type, it will produce rendered output each time you write an entry or rebuild an entire weblog.

A template-driven Web design makes the static elements of each page stand out from the material that will change—weblog entries, headlines, and data pulled from software settings and the database.

You can create a template for each different way you want to present entries from your weblog. In addition to HTML, XHTML, and CSS, templates can produce output in any XML format. Movable Type supports RSS 1.0, RSS 2.0, and Atom, three syndication formats that enable a weblog to be read with client software called a newsreader.

Listing 1-3 contains a template that contains the last 15 weblog entries formatted as an RSS 2.0 file.

Listing 1-3: An RSS 2.0 Template
Start example
<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title><MTBlogName remove_html="1" encode_xml="1"></title>
  <link><MTBlogURL></link>
  <description><MTBlogDescription remove_html="1"
encode_xml="1"></description>
  <MTEntries lastn="15">
  <item>
    <title><MTEntryTitle remove_html="1" encode_xml="1"></title>
    <link><MTEntryLink encode_xml="1"></link>
    <description><MTEntryBody remove_html="1"
encode_xml="1"></description>
  </item>
</MTEntries>
</channel>
</rss>
End example

The template in Listing 1-3 includes some of the same Movable Type tags used earlier in the Web page template. As new presentation and data formats come into vogue, supporting them with Movable Type requires only a template for each new format.

Earlier, I described the dilemma of keeping a large Web site current and error-free when it is being maintained by hand. If Web publishers were rated on a scale from Goofus (always does wrong) to Gallant (always does right), most of us would be much closer to Goofus, producing pages that grow staler by the day. Movable Type makes it easy to be Gallant. Changing the design of an entire site requires only that a few templates be edited, whether the site contains a dozen pages or a thousand, and republishing the entire site can be accomplished with a single click of the mouse.

Movable Type’s template feature supports a clear division of labor between Web designers and programmers working on the same site. Designers work with the formats they know—HTML, CSS, XHTML. Programmers deliver their work as custom Movable Type tags supported by plug-ins, and then tell designers how to use the tags.

Publishing Photos, Graphics, and Other Files

Movable Type weblogs can incorporate digital photos, graphics, audio, and video files. Some users are making use of this functionality to create moblogs, multimedia weblogs that incorporate photos, video, and text prepared on cell phones and other mobile devices.

Using the Upload File feature of the software’s browser-based interface, files on your computer can be uploaded to the Web server hosting the weblog and then stored in the weblog’s root directory, archives directory, or any of their subdirectories.

Once a file has been uploaded, Movable Type can route it to a weblog entry by providing the HTML formatting necessary to present the file. This makes the most sense for digital photos and other images, but will work for any file format. Images can be displayed as part of a weblog entry or in a separate pop-up window.

A weblog or one of its categories can consist of text, images, or a mixture of both.

Gotcha

Although you can upload files with Movable Type’s Web browser interface, there’s no way to use it to delete files later. Instead, to get rid of files that are no longer needed, you must connect to the Web server hosting the weblog with an FTP client or a shell account using telnet or SSH, and then delete the file manually. This applies only to Movable Type; TypePad offers file deletion.

Writing for an Audience

One of the best ways to build a following for a weblog is to spark conversation between author and audience. Movable Type sites are equipped to do this through the comments and trackback features.

Each weblog entry can receive public comments written by visitors, a feature that turns a popular weblog into a boisterous online community. This is at your discretion: You can specify that entries take no comments or be closed to new comments when a discussion is winding down. This preference is set for each entry using the Allow Comments drop-down menu at the bottom of the editing form, as shown in Figure 1-5.

Click To expand
Figure 1-5: Deciding whether to allow comments for a weblog entry.

Movable Type’s popularity and the comments feature result in a particularly attractive target for net abuse. Some spammers have written software that finds open comment links in Movable Type weblogs and automatically posts links to their sites, product ads, and other unwanted junk.

To address this issue, Movable Type 3.0 includes improved comment-management capabilities and user registration through a central service called TypeKey (http://www.typekey.com).

New Feature

TypeKey is a free user authentication service that can be used by any Movable Type 3.0 weblog. Users register for a TypeKey account and verify their e-mail address, replying to a confirmation message. When they want to make a comment on any participating weblog, they must sign in to TypeKey first.

Weblogs can require TypeKey or make it optional, allowing users who want to make use of the service to sign in. They also can be configured not to use it at all, thereby accepting public comments from all visitors without restriction.

Another feature for collecting feedback to your work is trackback, a way of discovering weblog entries on different sites that link to each other. trackback, a framework for data exchange between Web sites, was pioneered by Six Apart as a means of fostering communication between weblogs. It supplements comments, providing notification when another site is referring to one of your weblog entries (and vice versa).

You might be familiar with the referrer tracking capability of Web servers, which lets you know what incoming links on other Web sites are bringing people to your site. This sounds a lot like trackback, but a referrer requires two things in order for you to find out about a link:

  • A visitor must use that link to arrive at a page of your site.

  • The visitor’s Web browser must not be configured to keep this information private.

Trackback, on the other hand, is an immediate notification when someone else links to your weblog.

There are many uses for trackback. The most common is to make it easier for weblog publishers to communicate with each other. Instead of visiting someone else’s site to leave a comment, you can offer your response in your weblog for the benefit of your own audience. Your correspondents will find out about your response when they view their trackback count for that entry, which appears alongside the comment count.

When a weblog entry is published, Movable Type looks at the hyperlinks in the entry and sends what is known as a trackback ping in response to each one. A ping, in network communication parlance, is a short message to determine whether another machine is online and ready to accept requests.

If there’s a trackback server on the receiving end of the ping, it stores the link to the weblog entry and some (or all) of its text. There’s also a way to specify other links to ping for trackback purposes.

Like comments, trackback can be enabled or disabled on a per-entry basis. The Allow Pings checkbox at the bottom of the entry editing form controls this feature.

Connecting Movable Type to Other Software

Although Movable Type stands alone as a complete publishing system, it can work with external programs that either complement or replace some of its features.

Weblog entries and related data can be imported from other weblog publishing software into a Movable Type weblog. The first step is to export this data in a simple plain-text format.

Six Apart has documented how to create export data for the Blogger, Greymatter, and Newspro programs, and it works with other publishing tools such as Manila and Radio UserLand.

The exported data must be uploaded to the server by using an FTP client or similar means and placed in the directory where Movable Type expects to find it: an import subdirectory under the software’s main directory.

If the old weblog supported categories and comments, these can be imported with the text, title, and link for each of the entries. If categories were not supported by the old tool, they can be specified quickly using Movable Type’s power-editing feature, a means of working on 20 or more weblog entries using the same form (see Figure 1-6).

Click To expand
Figure 1-6: Working on multiple weblog entries in power-editing mode.

As shown in Figure 1-6, the title, category, author, and publication status of several weblog entries can be changed without leaving the form. The power-editing form can hold from 5 to 125 entries, or even the entire weblog.

In addition to importing weblog entries, Movable Type can receive data from weblog entries using XML-RPC, an XML format that enables programs to call each other’s procedures over the Internet and other networks.

The software supports several application programming interfaces (APIs) that make use of XML-RPC: Blogger, MetaWeblog, and Movable Type’s own API. These APIs enable client software to be used to read and write weblog entries, comments, and trackback information.

The most common use for these XML-RPC interfaces is to offer weblog text-editing capabilities that are more sophisticated than the software’s browser-based interface.

New Feature

Movable Type 3.0 adds support for the Atom API, a new application programming interface designed in concert with the Atom syndication format. The Atom API can be used in a similar manner to XML-RPC APIs, reading and writing weblog data from any software that supports the API. Find out more in Chapter 19, “Supporting the Atom Syndication Format and API.”

Installing Movable Type

In order to install Movable Type on a Web server, your account must have permission to set up and run custom CGI scripts. This is a deal-killer with many Web hosting services—many server administrators prohibit this functionality to keep users from opening a security hole, either intentionally or by accident. Therefore, if you are selecting a service specifically for use with Movable Type, check it out thoroughly before joining.

Installing Movable Type’s Perl scripts is straightforward, but you also might need to install several Perl modules that are used by the software, as described in the Chapter 2.

Start Sidebar
Finding a Host That’s Your Type

Six Apart has drafted an e-mail message that Movable Type users can send to a Web hosting service provider:

I am interested in running a weblogging content-management system called Movable Type (http://www.movabletype.org/) on my account. This system has the following requirements:

  • The ability to run custom CGI scripts

  • Perl, version 5.004_04 or later

And either of the following:

Support for the DB_File Perl module *OR* MySQL & the DBD::mysql module

Does my account on your service meet these three requirements?

End Sidebar


Summary

Without fail, Web publishers who begin to use a content-management system kick themselves for not doing so sooner. Smart software takes the pain out of publishing in this dynamic medium, making it easy to produce new content and keep old content fresh. The compulsion to create Web pages by hand in a text editor becomes one of those quaint labor-intensive chores of a bygone era, like the creation of illustrated manuscripts by monks.

Like the printing technique of the same name that was invented by Johann Gutenberg in the 15th century, Movable Type replaces the need for a lot of drudge work, freeing writers to spend more time communicating with their audience.

The personal publishing system created by Ben and Mena—there I go again with their names—provides a solid foundation for one-person publishers and teams to collaborate on weblogs. The software is also well suited for other sites that present fast-changing information organized by date, magazine-style sites, and similar efforts.

This chapter described the general reasons why and how Movable Type has become the most popular server-based software for creating weblogs. The rest of this book delves into the specifics of the software—setting it up, mastering its features, extending its functionality with plug-ins, and building your own software enhancements that make it better.


Chapter 2: Preparing a Web Server forMovable Type

In This Chapter

  • Finding Perl on your server

  • Telling scripts where to find Perl

  • Selecting a database program

  • Creating a MySQL database for Movable Type

  • Installing Perl modules

  • Using the CPAN archive

  • Running CGI scripts more securely

  • Installing the CGIWrap script

Before you begin installing Movable Type, you must ensure that your Web server can handle the software.

Movable Type consists of a set of Perl scripts that are run by a Web server, accessing a database that holds several kinds of information for each of your weblogs: entries, templates, visitor comments, trackback pings, and more. Although the software most commonly runs on Linux systems, that’s not a requirement—a Web server on Windows equipped with Perl and MySQL can be used, as can a Mac OS X box.

If this is your first experience running a Web application, you might find it challenging to set the software up on a server.

If you make the task easier by using the full installation of Movable Type and your server has the software that it requires, however, you can set up the program yourself and learn more about how it functions.


Meeting the Conditions for the Software

Although Movable Type runs most commonly on Linux or UNIX systems, the software neither favors nor requires those operating systems. You can run its Perl scripts and access a database with any OS as long as it supports Perl and the database you select for storage.

The first requirement to use the software is the capability to use the command-line environment of your own operating system, whether a command shell on Linux, UNIX, and Mac OS X computers or an MS-DOS command prompt on Windows.

Although commands vary in the subsequent sections of this chapter, their purpose remains the same regardless of your chosen OS. Windows users will encounter differences in how directories and files are specified, and do not use the same commands as a Linux shell in the Command Prompt window. Instead, Windows offers a command-line environment that mimics MS-DOS, the operating system that preceded Windows, rather than one of the Linux shells.

The same tasks must be accomplished on any operating system:

  • Make sure that Perl has been installed and that Movable Type scripts know where to find it.

  • Choose a database program.

  • Set up required Perl modules along with any optional modules that you want to use.

  • Install CGIWrap so that Movable Type and other CGI scripts can be run more securely.

When you have met all of these conditions (or at least the first three if you decide not to use CGIWrap), you can begin installing Movable Type.


Checking for a Perl 5 Installation

All of the code that drives Movable Type has been written in the Perl language and requires version 5.004_04 or later of the Perl interpreter. To see which version has been installed on your server, type the following commands.

Linux (and similar command shells):

$ /usr/bin/perl -v

Windows with ActivePerl:

C:\> perl -v

If the command doesn’t work, your Perl interpreter has not been installed in the /usr/bin directory. On Linux, you should be able to find it by typing the following command:

$ whereis perl

Files matching the name perl will be listed, and at least one of them should be the interpreter.

The recommended Perl distribution for Windows is ActivePerl. To determine whether it’s present on the server, open the Control Panel and click Add or Remove Programs.

Web Site Download

ActivePerl, which also can be installed on Linux and Solaris systems, can be downloaded as a trial version from the ActiveState Web site:

http://www.activestate.com/Products/ActivePerl

As described in the next chapter, “Installing Movable Type,” after you have downloaded Movable Type, you’ll need to know where Perl can be found on your system.


Setting Up a Database for Your Weblog

Movable Type requires a database to hold the contents of your weblogs and the files required to publish them. Four databases can be used for this purpose: the simpler, file-based programs Berkeley DB and SQLite, and the more robust relational databases MySQL and PostgreSQL.

Because all four are either open source or public domain, there’s no additional financial expenditure required to use any of them as the back end for your Movable Type installation. With version 3.0 of the software, Six Apart recommends using either Berkeley DB or MySQL as your database. You might already have one or more of these programs installed on your Web server, so check before choosing your database.

Movable Type works with each of these databases entirely behind the scenes, accessing the programs through Perl modules that function as drivers, providing an interface between the weblogging tool and the database program.

The main factors to consider when selecting the database are ease of configuration and performance delivering data. All four can be set up to work with Movable Type in minutes. The Berkeley DB and SQLite programs install easily and require little configuration, but they do not perform as well on large, high-traffic weblogs as MySQL and PostgreSQL, database programs that require more work to install and set up correctly.

Berkeley DB, arguably the simplest of the four, is the only one that does not make use of Structured Query Language (SQL), a standard for reading and writing database information.

The open-source software stores weblog data in a single database file, which you will identify during configuration (as covered in the next chapter, “Installing Movable Type”).

Web Site Download

You can download Berkeley DB from Sleepycat Software at http://www.sleepycat.com.

The SQLite database also stores a database in a single file, but makes use of SQL.

The software, which requires little to no configuration, has been released into the public domain, removing all copyright claims to the work, but continues to be actively supported.

Web Site Download

Download SQLite from its official Web site at http://www.sqlite.org.

Berkeley DB and SQLite require a directory in which the database can be stored. The directory must be outside of the directories that can be accessed by your Web server. You can use the server’s main CGI directory for this purpose, assuming that your server has been configured correctly and will not serve any files located there, or any other suitable directory.

The last two database programs, PostgreSQL and MySQL, are robust relational databases with more extensive requirements to install and maintain.

Web Site Download

PostgreSQL and MySQL are highly sophisticated open-source programs available from http://www.postgresql.org and http://www. mysql.com, respectively.

MySQL, the storage software recommended by Six Apart, uses the tables indicated in Table 2-1.

Table 2-1: Movable Type’s Database Tables in MySQL
Name | Description
mt_author | User accounts for weblog editors and TypeKey users who sign in to post comments
mt_blog | Information about each weblog
mt_category | Categories available on all weblogs
mt_comment | Comments posted by weblog visitors
mt_entry | Weblog entries
mt_ipbanlist | IP addresses banned from posting comments or trackback
mt_log | Activity log tracking use of the software by editors
mt_notification | Users requesting e-mail when a weblog has been updated
mt_permission | Tasks a weblog editor has permission to perform
mt_placement | Category assignments for weblog entries
mt_plugindata | Information about installed plug-ins
mt_session | User-tracking sessions
mt_tbping | Trackback pings received by weblogs (along with mt_trackback)
mt_template | Templates stored in the database
mt_templatemap | Map determining how templates are used
mt_trackback | Trackback pings received by weblogs (with mt_tbping)

The MySQL and PostgreSQL databases require installation and configuration that must take place before you begin setting up Movable Type.

After that has taken place (or you have chosen a Web hosting service with a pre-installed database prepared for your use), a database must be prepared, along with a user account that can access it.

You can make use of an existing MySQL or PostgreSQL database with Movable Type or create a new one solely for the use of the software. The latter option provides more security, preventing Movable Type data from being overwritten by another program and vice versa.

The database doesn’t need to be set up with tables. Movable Type takes care of this during installation.

The following commands, when entered while running MySQL in interactive mode, create a suitable user and database:

create database movable;
grant all on movable.* to mtuser@localhost identified by "password";
grant all on movable.* to mtuser@"%" identified by "password";

The last two commands identify the same user, mtuser, so the password you choose in place of password should match. These commands create a database named movable and give a new user named mtuser access to it from the local server or any other server in the world.

Gotcha

Giving the world access to a MySQL database exposes the database to considerable security risk, so you can opt to omit the second command and limit access to localhost only (the machine on which the database is running). The database will be more secure, but you won’t be able to access it or transfer data to and from other Internet servers running MySQL. In addition, you might have trouble accessing the database on some versions of Red Hat Linux due to longstanding issues with the way they identify the localhost machine.


Setting Up Perl Modules

Movable Type’s Perl scripts make use of external Perl modules that deliver different aspects of the software’s functionality. Many of these are included with the software, working immediately, but others must be downloaded and installed separately.

These modules are described in Table 2-2.

Table 2-2: Perl Modules Required by Movable Type
Name | Job | Status
CGI::Cookie | Read and write Web browser cookies for user personalization | Required
Crypt::DSA | Verify cryptographic signatures with the Digital Signature Algorithm (DSA) | Optional
DB_File | Access the Berkeley DB database | †Optional
DBD::mysql | Access the MySQL database | †Optional
DBD::Pg | Access the PostgreSQL database | †Optional
DBD::SQLite | Access the SQLite database | †Optional
File::Spec | Work with filenames and directory paths | Required
File::Temp | Read and write temporary files | Optional
HTML::Entities | Encode and decode HTML markup with entity codes | Optional
HTML::Template | Produce pages, syndicated feeds, and other files from templates | Required
Image::Magick | Create thumbnails of uploaded images | Optional
Image::Size | Determine the height and width of graphics files | Required
LWP::UserAgent | Send requests and responses to Internet servers over HTTP | Optional
MIME::Base64 | Encode and decode strings using Base64 encoding | Optional
SOAP::Lite | Exchange weblog data with other software using the XML-RPC APIs | Optional
Storable | Store data persistently to files | Optional
XML::Atom | Exchange weblog data with other software using the Atom API | Optional
† At least one of the four database modules must be installed.

When you install the full version of Movable Type as either a ZIP archive (.zip) or a GZIP tarball archive (.tar.gz), it should include all but five of these modules:
DB_File, DBD::mysql,
DBD::Pg, DBD::sqlite, and
Image::Magick.

During the installation of Movable Type, a system check script determines which of these modules are present on the server, organizing them into three sections: required modules that must be installed for the software to function, optional modules that support non-essential features, and database modules that support a particular database.

You only need one database module: the one that supports the database program you’ll be using with Movable Type. The others can be disregarded.

The system check script is shown running in a Web browser in Figure 2-1.

Click To expand
Figure 2-1: Determining which Perl modules are present on a server.

Most, if not all, of the absent Perl modules can be installed easily using the Comprehensive Perl Archive Network (CPAN), a tool that automates the process of finding, downloading, and setting up modules.

Two of the modules employed by Movable Type have additional prerequisites before they can be installed with CPAN.

The XML::Atom module requires either the XML::LibXML or XML::Parser modules to process XML data. Normally, when Movable Type’s installation script indicates that XML::Atom cannot be found (a topic discussed in the next chapter), the real source of the problem is that neither XML::LibXML nor XML::Parser has been installed on the server.

Web Site Download

The Image::Magick module requires something that can’t be installed as a Perl module: ImageMagick, a set of image manipulation tools available for download from http://www.imagemagick.org. The software has been offered for distribution as source code, which must be compiled, and as a Linux RPM package.

If you use the rpm tool to install and upgrade packages on a Linux system, you can install a downloaded copy of the ImageMagick RPM with the following command:

rpm -Fvh ImageMagick-6.0.2-7.i386.rpm

Change the version number to match the one downloaded from the ImageMagick Web site.

CPAN represents a globally distributed archive of Perl documentation and modules. This resource has been documented on the Web at http://www.cpan.org.

You can access this archive in interactive mode by running Perl with the -MCPAN --e shell command-line arguments.

Linux-style shells:

$ /usr/bin/perl -MCPAN -e shell

Windows command prompt:

C:\> perl -MCPAN -e shell

The archive opens, displaying a command line from which you can install modules and perform other tasks. Type help for a list of commands.

You can attempt to install a module by typing the install command followed by its name (as identified in the first column of Table 2-2):

cpan> install File::Temp

The preceding command prompts CPAN to find and download File::Temp, compile the software, and install it.

When a Perl module requires another module, as in the case of XML::Atom, CPAN asks whether it should be installed first. This can set into motion a chain of prerequisite installations in which a large number of modules are being downloaded, built, and installed.

As CPAN functions, a large number of messages are displayed that are likely to make little sense to you. The software displays a lot of information that is only of benefit to experienced Perl programmers and others who routinely build their own software.

The only messages that you must pay attention to are questions and the final messages shown, which indicate whether the installation of the module was a success or a failure.

CPAN can be a great boon when it works successfully—type one command, answer a question or two about other modules to install, and boom, you’re done. When it doesn’t, you might need to find other means to install the module or set up programs that were required to build it.

The CPAN archive also can be accessed in non-interactive mode by specifying the package to install, as in the following example:

perl -MCPAN -e ‘install Weather::Underground’


Using CGIWrap to Improve Security

Like any publicly accessible service on the Internet, a Web server must be aggressively protected to deal with current and future security vulnerabilities. Computer administrators patch their systems frequently to prepare for new exploits that take advantage of software bugs to break into servers, spread viruses, and commit other forms of virtual mayhem.

People who attempt to access servers without permission are called crackers. Although some crackers are motivated by curiosity rather than a desire to cause harm to a compromised server, even a non-malicious cracker can read data that should be private and cause damage unintentionally.

From the moment it goes online, a Web server will be subjected to frequent break-in attempts, even if the server is newly launched and has not been publicized.

Note

My own servers attract particular interest from crackers all over the world on U.S. holidays, presumably because I’m less likely to be around to observe the attempts.

CGI scripts such as the programs that deliver Movable Type’s functionality represent one of the main points of vulnerability on a Web server. A poorly executed or misused script could be attacked, executing cracker-authored code that runs as the user running the server (or, even worse, in some cases as the root superuser).

Although Movable Type’s scripts have been tested and improved for several years, there’s always a chance with any software that new vulnerabilities will be discovered and exploited.

You can reduce the vulnerability of CGI scripts by running them with CGIWrap, an open-source program created by Nathan Neulinger that runs these scripts in a more secure manner.

Web Site Download

The software can be downloaded from the CGIWrap Web site at http:// cgiwrap.unixtools.org. This site also contains documentation for the software and a frequently asked questions list.

CGIWrap works with several Linux and UNIX Web servers—most notably, the Apache Web server.

CGIWrap, which is itself a CGI script, performs several security checks on a program that it is asked to run. The script primarily ensures that each CGI script executes as the user and group that own it rather than as the Web server.

By design, the CGIWrap script runs CGI scripts from each user’s public_html/cgi-bin folder (for instance, mine run from /home/rcade/public_html/cgi_bin). If a script does not belong to the right user and group, it won’t run.

The CGIWrap program can be downloaded as an archive file prepared with the tar and gzip utilities (in other words, a .tar.gz file). The following commands expand the archive:

$ gzip -d cgiwrap-3.9.tar.gz
$ tar xf cgiwrap-3.9.tar

A directory is created that’s named for the file (for instance, the preceding commands for CGIWrap 3.9 produced a directory called cgiwrap-3.9).

The script includes documentation in the README file in its main directory and in several Web pages in the htdocs directory.

You must configure and build the software using command-line options that customize it to work on your server. To see the configuration commands that can be used, type the following command in the program’s main directory:

$ ./configure --help

At a minimum, you should specify the following arguments:

  • --with-httpd-user=username: The user account that runs the Web server

  • --with-install-dir=path: The directory in which CGIWrap should be installed

You also might want to consider using these arguments:

  • --with-multiuser-cgi-dir=path: The directory in which common CGI scripts are located

  • --with-perl=path: The directory and filename of the Perl executable (such as /usr/bin/perl)

  • --with-php=path: The directory and filename of PHP (often /usr/bin/php)

After configuring the software, build and deploy it using the make and make install commands. Here’s a complete example from my installation:

$ ./configure --with-php=/usr/bin/php --with-perl=/usr/bin/perl \
--with-httpd-user=apache --with-multiuser-cgi-dir=/var/www/cgi-bin \
--with-install-dir=/var/www/cgiwrap
$ make
$ make install

To use the script with Movable Type, all scripts and files associated with the software must be installed in the public_html/cgi-bin subdirectory of the user who should run them.

On my server, Movable Type runs as user account rcade and has been installed in /home/rcade/public_html/cgi_bin. I ensured that the account was the owner and group for the scripts with the following commands:

$ chown rcade mt*cgi
$ chgrp rcade mt*cgi

Once CGIWrap has been installed, CGI scripts always should be run through this program, rather than being directly executed.

On a Web server where the cgiwrap script is stored in the server’s main cgi-bin directory, a CGI script can be run using the URL /cgi-bin/cgiwrap/ username/scriptname, as in this example:

http://orlandovacationer.com/cgi-bin/cgiwrap/rcade/mt-check.cgi
Start Sidebar
Double-Checking the Installation

The cgiwrap script must be owned only by root. Other groups and users should only be able to read and execute the script.

Also, three symbolic links should be created to cgiwrap in the same directory: cgiwrapd, nph-cgiwrap, and nph-cgiwrapd.

According to the documentation for CGIWrap, running make install sets the cgiwrap script to the proper permissions and creates links to several other versions of the program as needed.

This wasn’t happening with version 3.9 of the software. The following commands, when run from the directory in which CGIWrap files have been installed, ensure that the program is set up correctly:

$ chown root cgiwrap
$ chmod 4755 cgiwrap
$ ln -s cgiwrap cgiwrapd
$ ln -s cgiwrap nph-cgiwrap
$ ln -s cgiwrap nph-cgiwrapd
End Sidebar

The mt-check.cgi script, which is part of Movable Type, checks whether the software has been configured correctly and is ready to run. When you have installed Movable Type, the check script will attempt to detect CGIWrap, displaying the message “(Probably) Running under cgiwrap or suexec” when successful.


Summary

Preparing for the installation of Movable Type can be easy or difficult, depending on whether the necessary software is present on the server where you will be running the software.

The best way to simplify the installation is to choose the full version of Movable Type with its included Perl modules, reducing the number of modules you must install using CPAN or other means.

If you have reached this point without setting up one or more optional Perl modules, continue to the next chapter and install Movable Type. You might find that you can get by without the features supported by the module, such as the graphics thumbnail creation capabilities of the Image::Magick module and ImageMagick software.

Once a database has been chosen and you set up Movable Type to access it correctly, it will do its work behind the scenes and require no direct maintenance.


Chapter 3: Installing MovableType

In This Chapter

  • Getting a copy of Movable Type

  • Downloading and unpacking the software

  • Setting up the software’s Perl scripts

  • Selecting a database

  • Creating a database and a user

  • Making the necessary software directories

  • Examining the configuration file

  • Using setting commands

  • Uploading the software to a Web server

  • Making the program secure

  • Testing the installation

The installation of Movable Type amounts to a good-news, bad-news scenario.

The bad news: Setting up a server-based program like Movable Type can be a difficult challenge for many Web publishers. There’s no installation wizard or helper program that makes it easy to set the program up on a Web server.

The good news: By the time you’ve completed the steps necessary to download, configure, upload, and run the software, you’ll have a stronger understanding of its capabilities.

Web publishers who are comfortable with the operation of a Web server should be able to set up Movable Type quickly. The software runs through the Common Gateway Interface as a set of Perl scripts.

In addition to setting up the software and a configuration file, you must prepare a database such as MySQL or PostgreSQL before running Movable Type for the first time.


Downloading the Software

You can download Movable Type from the Six Apart Web site at http://www.movabletype.org. Three versions can be downloaded:

  • A full version, with libraries

  • A full version, without libraries

  • An upgrade version

A new Movable Type user must choose one of the full versions, deciding whether to include Perl module libraries that support all of the software’s functionality.

If you’re comfortable with Perl module installation or know that your server offers all the modules required by Movable Type, you can save yourself a longer download and some disk space by downloading the full version without libraries.

Otherwise, you’re better off with the full version that includes the module libraries. They take up more disk space but make installation significantly easier.

The upgrade version includes only the files necessary to bring an existing Movable Type installation up-to-date.

All three versions are available in two archive formats: ZIP, the preferred archival format on Windows, and GZIP TAR, the most common format on Linux systems. Regardless of the installation version that you choose, you can complete these steps to download and install Movable Type:

  1. Download a version of the software from Six Apart.

  2. Extract all of the files to a directory on your computer.

  3. Prepare the files for use on the server and edit the configuration file mt.cfg.

  4. Upload the files and directories to the proper places on the server.

  5. Set the proper file permissions and create any directories required by the software.

  6. Run Movable Type’s check script, mt-check.cgi, which determines whether the software has been configured correctly and is ready to run.

  7. Run the system loader script, mt-load.cgi, which initializes the software’s database.

  8. Delete mt-load.cgi.

These steps are described fully in the following sections of this chapter. If you have full access to the Web server on which Movable Type will be run, you can download the software directly to that server and work with it there.

Six Apart puts no restrictions on the functionality of the software; it isn’t a trial download that only works for a short time. Personal and non-commercial users can use the program for three weblogs with only one author under a free license.

Personal users who require more authors and weblogs can purchase a five-author, unlimited-weblog $69.95 license or a $99.95 license with unlimited authors and weblogs. Commercial users can buy licenses ranging from $199.95 to $1,299.95.

Web Site Download

More details on personal and commercial licenses can be found on the Web at http://www.movabletype.org on the Get Movable Type link.

License purchasers for any personal or commercial edition receive tech support and weblog promotion in the “Recently updated” site list on the Movable Type Web site, as well as other perks.


Setting Up Movable Type to Use Perl 5

The Movable Type application consists of a set of Perl scripts, Perl module libraries, and Web pages delivered by a Web browser.

After you download the software and extract its files to a temporary directory, you might need to make a minor change to the first line of the scripts.

All of Movable Type’s scripts are located in the main installation directory and have names that end with the file extension .cgi. These 12 Perl scripts are run by a Web server using the Common Gateway Interface (CGI), a standard protocol governing how Web servers and software exchange information.

Perl scripts are text files that can be opened and edited with any editor that can handle simple text with no formatting or fonts.

The first line of each Movable Type script identifies where the Perl interpreter can be found on the server:

#!/usr/bin/perl –w

If Perl exists in the /usr/bin directory on the server, you don’t need to edit any of the scripts.

If your interpreter has not been stored at /usr/bin/perl or you are running on Windows, you must edit Movable Type’s Perl scripts to indicate the proper location of the interpreter.

If necessary, open each of the scripts and replace /usr/bin/ with the correct directory containing the perl interpreter. On a Linux system, you can search for the interpreter with the whereis command:

$ whereis perl

For example, if the interpreter was found in /usr/local/bin/perl, the first line of each Movable Type script should become the following:

#!/usr/local/bin/perl –w
Caution

Although it is named like a script, the file mt-db-pass.cgi is not one of Movable Type’s scripts and does not need to be edited to indicate the location of the Perl interpreter. Don’t edit this file—you’ll find out what to do with it later in this chapter.

Verify that each script has the proper location of the Perl interpreter in its first line, but don’t attempt to run any of them yet.


Preparing a Database

Movable Type works with four database programs. Two of them, PostgreSQL and MySQL, require some minor preparation to work with the software:

  1. Create a new database that can be used by Movable Type.

  2. Create a new user account that Movable Type will use to access the database.

  3. Grant that account the privileges to read, write, and delete tables and records in the database.

Although an existing database and database user can be employed by Movable Type, this practice should be avoided so that you don’t allow other users to make changes to your weblog data. The converse also is true: Movable Type shouldn’t have access to other databases.

In MySQL, a database can be created by following the create database command with the desired name:

create database movable;

Like all MySQL shell commands, create database should be followed by a semicolon. The preceding command creates a new database named movable.

You can use the grant all command to create a user account and give it access to the new database:

grant all on movable.* to dbuser5@localhost
identified by “swordfish”;

This MySQL command creates a new account named dbuser5 with the password swordfish, giving the account full privileges to do anything in the movable database.

The reference to localhost in the username limits dbuser5 to access only from the same machine hosting Movable Type and the database. This can be replaced with any host name or % to allow access from any Internet-connected machine:

grant all on movable.* to dbuser5@”%”
identified by “swordfish”;

Because of the security implications of allowing MySQL access from anywhere on the net, choose a good password, preferably one that includes letters, numbers, and punctuation, and isn’t a dictionary word like swordfish.

Gotcha

On some versions of Red Hat Linux and perhaps other Linux distributions, you might have trouble accessing a MySQL database from Movable Type if you limit connections to localhost. Use both of the preceding commands to ensure that a successful database connection can take place.


Editing the Configuration File

Before you can run any of the Perl scripts that comprise the functionality of Movable Type, you must edit the software’s configuration file, a text file named mt.cfg found in the main installation directory.

You can open this file using almost any simple text editor, as long as it can handle Linux-style line separators without running all of the lines together. One editor that has problems with the file is Windows Notepad; use Wordpad instead on Windows operating systems.

The configuration file contains settings that apply to all weblogs administered by your installation of Movable Type. The file consists of more than a dozen single-line setting commands, preceded by documentation that explains the aspect of the program they control. Here’s an excerpt from the file:

# Movable Type uses the CGIPath setting to construct links
# back to CGI scripts; for example, the MT tag
# <$MTCGIPath$> is substituted with the value of the
# CGIPath setting. You will need to change this value
# when you first install MT; instructions for doing so are
# in the Installation Instructions, in INSTALLING THE
# MOVABLE TYPE APPLICATION CODE, Step 3.

CGIPath http://WWW.YOUR-SITE.COM/PATH/TO/MT/

In the file, blank lines and lines preceded with a pound sign (#) are ignored. They’re in the file for your benefit, showing how to work with Movable Type’s settings.

Setting commands consist of the setting’s name followed by a space and its value, as in the CGIPath line in the example, which assigns that setting the value http://WWW.YOUR-SITE.COM/PATH/TO/MT/.

Some setting commands are preceded by a pound sign (#), which causes them to be recognized as comments and ignored by the software, as shown in the following line:

# EmailAddressMain YOUR.OTHER.ADDRESS@SOMEDOMAIN.COM

The purpose of ignoring a setting command like this is to use the default value. When you decide not to use the default, you delete the # character and edit the value as desired.

Movable Type’s configuration settings specify where to find files, how to access a database, and many other aspects of its performance.

The configuration file contains more than 60 setting commands, but you don’t need to work with all of them as you begin using Movable Type. Many have default values that should be acceptable on most installations of the software; others are described in subsequent chapters when they become useful.

The next four sections cover seven settings that you must edit and 10 others that you might need to change as you begin using the software.

Choosing the Software’s Directories

Movable Type’s browser-based user interface makes use of two Web addresses:

  • The CGI path, which is the address of the directory that contains the configuration file and all of the software’s Perl scripts

  • The static Web path, which is the address of the directory that holds the software’s online manual and the user interface’s graphics and files

These addresses, which can be full URLs such as http://example.com/ or relative URLs such as /weblog/resources/, are established by the CGIPath and StaticWebPath settings in the configuration file.

Set CGIPath to the address of the directory from which Movable Type’s Perl scripts are run. The directory must be one that can be used for CGI scripts—for security reasons, the Apache Web server and other servers can be configured to run CGI programs only from certain directories.

Using Apache, one place to put Movable Type scripts is the Web server’s main CGI directory, which on many Linux systems is located in the directory /etc/httpd/cgi-bin and has the URL /cgi-bin/. Here’s a command that sets this up in the configuration file:

CGIPath http://example.com/cgi-bin/

If you have installed CGIWrap to run scripts more securely, the CGIPath setting should refer to the user directory, as in this example from my own Web server:

CGIPath http://www.prefect.com/cgi-bin/cgiwrap/rcade/

The StaticWebPath setting must correspond to the directory in which the browser interface’s support files and the images and docs subdirectories are stored. Here’s an example that uses a relative URL:

StaticWebPath /movable/static/

On prefect.com, this path corresponds to the URL http://prefect.com/ movable/static/.

When you begin editing the configuration file, the StaticWebPath setting command is a comment, which causes the default to be used: the same directory as the CGI path. This does not work when the CGI path is a Web server’s main /cgi-bin directory, because that directory cannot serve graphics and other non-executable files.

If they don’t exist yet, create directories on the Web server for the CGI path and static Web path. You’ll be uploading files to these directories after the configuration file has been edited.

Setting Up Database Access

Seven configuration settings determine how Movable Type accesses the database that holds weblog entries, templates, and other data.

You can use four programs—Berkeley DB, MySQL, PostgreSQL, and SQLite—and several are configured in different ways.

If you are using either Berkeley DB or SQLite, you must create a directory on the server for the storage of database files. The DataSource setting chooses this directory. The following command places it in the CGI path directory in a subdirectory named db:

DataSource ./db

On a Windows system, the same setting uses a different separator character:

DataSource .\db
Caution

On some Windows servers, you might have better luck using a full directory and filename reference as the DataSource setting, including the drive letter. Here’s an example:

DataSource E:\weblog\db

If your CGI path is a server’s main /cgi-bin directory, this default setting puts the directory in a place where it can be used by Movable Type but can’t be accessed over the Web.

This fulfills an important security consideration for the database files—visitors to your Web site should be prevented from viewing these files with their browsers. The directory chosen as DataSource must not be one that contains Web-accessible files.

Once you have set up the data source directory, that’s all you need to do if Berkeley DB is your database.

A Movable Type installation that uses anything else must set up several additional configuration settings, which can include a database driver (ObjectDriver), a database name (Database), a user (DBUser), and a server (DBHost).

The ObjectDriver setting should be DBI::mysql (for MySQL), DBI::postgres (for PostgreSQL), or DBI::sqlite (for SQLite). These names correspond to Perl modules that serve as an interface between Movable Type and the chosen database.

The Database setting provides the name of the database in which Movable Type will create its tables and records. When using MySQL or PostgreSQL, this database must already exist, because Movable Type cannot create it.

For an SQLite database, the name refers to a file and should be preceded by the name of the directory chosen as the DataSource setting. For example, if you’re storing the database on a Linux system in ./db, a suitable Database setting would be db/mvdata or db/blog-database.

The DBHost setting provides the host name of the database’s server, which can be localhost if it’s on the same machine as Movable Type.

On a MySQL or PostgreSQL database, a user must be specified with the DBUser setting. This user should already exist and have the privileges to read and write tables in the database. These databases also require a password, which is specified in a file outside of the Movable Type configuration.

Here’s where that mt-db-pass.cgi file becomes important. Open the file and replace the existing line with the password associated with the database user.

The last two database settings in the configuration file, DBSocket and DBPort, become necessary only on a database that requires a nonstandard socket file or port number.

The following settings set up Movable Type to work with a MySQL database named movable accessed by the user dbuser5:

ObjectDriver DBI::mysql
Database movable
DBUser dbuser5
DBHost localhost

Configuring E-Mail Servers

Several features offered by Movable Type make use of e-mail. The default configuration for the software, which often requires no modifications, sends e-mail with the Sendmail program, looking for it at /usr/lib/sendmail, /usr/sbin/sendmail, or /usr/ucblib/sendmail (which, as you probably noted, assumes the software has been installed on Linux or UNIX).

The SendMailPath setting can be used to specify a different location for the program, as needed:

SendMailPath /usr/bin/sendmail

To use an SMTP server instead of Sendmail, use the MailTransfer setting smtp and an SMTPServer set to the name of the server, like so:

MailTransfer smtp
SMTPServer smtp.example.com

The last tweak that can be made to e-mail is EmailAddressMain, a setting that chooses the “From” address of mail sent by Movable Type. The following command makes it weblog@example.com:

EmailAddressMain weblog@example.com

Because all of these setting commands normally use default values, be sure to remove the # character that precedes each command.

Changing Script Names

The last settings that can affect your ability to run Movable Type for the first time involve the Perl scripts that deliver the software’s functionality. Movable Type scripts end in the file extension .cgi, as in mt.cgi, mt-view.cgi, and mt-xmlrpc.cgi. If you have changed the names of these scripts to make them run successfully—or you want to rename them to enhance system security—six setting commands can be used.

The scripts provide the correct names of the main script (AdminScript) and the scripts that support comments (CommentScript), dynamic pages (ViewScript), search (SearchScript), trackback pings (TrackbackScript), and the XML-RPC interface (XMLRPCScript).

You use the following commands if all of your scripts have been renamed to use the .pl filename extension:

AdminScript mt.pl
CommentScript mt-comments.pl
SearchScript mt-search.pl
TrackbackScript mt-tb.pl
ViewScript mt-view.pl
XMLRPCScript mt-xmlrpc.pl

Movable Type’s configuration file includes documentation describing each of the settings, so you can read the comments and find other settings that can be modified to suit your particular installation.

When you save the file, Movable Type scripts immediately make use of the newly altered configuration settings.


Uploading the Software to Your Web Server

After you have set up and saved the configuration file, you’re ready to upload the Movable Type files to the proper places on your Web server.

A full Movable Type installation consists of a main directory and eight subdirectories. You will be copying files and directories from this installation to two separate locations established in the software’s configuration—the CGI path, also referred to as the main directory, and the static Web path.

The static Web path holds the Web pages and other files needed by the Movable Type user interface (in other words, the Web site you’ll use to create and manage your weblogs).

Upload four things to the directory chosen as your static path:

  • The docs directory, which contains Movable Type’s user manual

  • The images directory, which holds user interface graphics

  • The file styles.css, a Cascading Style Sheet used by the interface

  • The file mt.js, JavaScript functions for the interface

The docs and images directories will become subdirectories of the static path.

When uploading files, make sure that your FTP client has been set to upload graphics as binary files and everything else as text. With most clients, this requires only that an auto-detect or auto mode be selected for the transfer.

If you have to choose binary or text uploads yourself, transfer the images directory in binary mode and everything else as text.

The remaining files and directories should be uploaded to the CGI path directory in which Movable Type’s scripts will be run.

When the transfer completes, you should have 16 scripts and the subdirectories extlib, lib, plugins, schemas, search_templates, and tmpl.

Finally, create a subdirectory named import—you will need it if you ever import entries and other data into a Movable Type weblog.


Setting Up Security Permissions

The scripts in Movable Type’s main directory must be given the proper permissions so that a Web server can run them. Three categories of file permissions—read, write, and execute—apply to three kinds of users: the owner (the creator of the file), a group (associates of the owner), and the world (everyone else).

All of the Movable Type scripts, the files included with Movable Type that end with the file extension .cgi, should have read, write, and execute permission for the owner; read and write permission for the group; and read and write permission for the world.

At a command-line shell on Linux, you can accomplish this in the Movable Type directory with the following command:

$ chmod 755 mt*.cgi

Using the chmod program, this command changes file access permissions for all of the scripts to the required settings. The argument 755 specifies three permission levels: 7 to make the owner read, write, and execute; 5 to make the group read and write; and another 5 for the world.

Most graphical FTP clients also offer a way to set file access permissions. Often, you can view and change a file’s permissions with a client by using a Properties dialog box.

On the Windows FTP client WS_FTP Pro, for instance, you can edit file permissions in two ways:

  • Select the file and choose File ® Properties.

  • Right-click the file and choose Properties from the context menu that appears.

With either command, the Properties dialog box opens, as shown in Figure 3-1.

Click To expand
Figure 3-1: Setting file permissions with an FTP client.

Checkboxes turn a specific file permission on or off for each user group. WS_FTP also enables number-based permission values such as 755 to be used.

After setting the proper permissions for scripts, you must do the same for the directories that will be used by Movable Type.

If you are using Berkley DB or SQLite, the configuration setting DataSource designates a directory in which database files are stored. The default setting uses a db subdirectory of the main directory.

This directory should have read, write, and execute permissions for all three user groups, which can be set individually with an FTP client or by using the numeric code 777.

When you set up a Movable Type weblog, the first thing you must do is designate directories in which the weblog and its archive pages are stored. Each weblog is configured to use two directories: the local site path, which holds the home page, XML syndication feeds, and other files; and the local archive path. The same directory can be used for both purposes.

The site and archive path directories should be created now on your server for use in the next chapter, “Configuring a Weblog.” They must have the same read, write, and execute permissions as the database directory.

These directories can be part of the same directory tree as other Web sites on the server or they can be placed anywhere else that the Web server can access. The only thing to watch for is whether any other software creates files in the same directories.

On one of my Linux servers, a Movable Type weblog is stored in two subdirectories of /usr/local/web/cadenhead/, the directory that holds the server’s home page. The local site path is /usr/local/web/cadenhead/movable/ and the local archive path is /usr/local/web/cadenhead/movable/archives/.

The following commands set up the directories and the proper permissions:

$ mkdir /usr/local/web/cadenhead/movable
$ mkdir /usr/local/web/cadenhead/movable/archives
$ cd /usr/local/web/cadenhead
$ chmod 777 movable movable/archives

With the scripts and directories set up, you’re ready to run two scripts that test your installation and initialize the Movable Type database.


Checking for the Availability of Perl Modules

Once Movable Type scripts are in the correct place and permissions have been set, you can check to see whether the software can find the Perl modules that it needs.

The system check program mt-check.cgi determines whether the modules are present on the server and functioning properly.

Like all Movable Type scripts, the program runs from the software’s CGI path address. To run it, tack the name of the program on the end of the address—my path address is http://cadenhead.org/mt-cgi/, so the following URL executes the system check script:

http://cadenhead.org/mt-cgi/mt-check.cgi

The script runs on the Web server and returns its output to your browser, as shown in Figure 3-2.

Click To expand
Figure 3-2: Looking for Perl modules used by Movable Type.

The script verifies the existence of four modules that Movable Type requires in order to function: CGI::Cookie, File::Spec, HTML::Template, and Image::Size. Two required modules must be specific versions (or later): File::Spec 0.8 and HTML::Template 2.0.

Next, the script looks for database modules. Only one needs to be present—the program that corresponds to the database you’re using with Movable Type. A Berkeley DB database requires DB_File, MySQL needs DBD::mysql, PostgreSQL uses DBD::Pg, and SQLite uses DBD::SQLite. More than one can be present; there’s no need to remove a module that isn’t being used.

Cross-Reference

If the check script can’t find one of the required modules or the database module matching your installation, you must correct this problem by installing the missing module, as described in Chapter 2, “Preparing a Web Server for Movable Type.” Rerun the system check script afterwards to verify the module’s successful installation.

The last module check performed by the script accounts for optional modules that are useful to have around but do not impede the software from working correctly.

Movable Type employs nine optional modules: Crypt::DSA,
File::Temp, HTML::Entities, Image::Magick, LWP::UserAgent,
MIME::Base64, SOAP::Lite,
Storable, and XML::Atom.

When an optional module is not present or can’t be found, some functionality of the software might not be available. For instance, the Image::Magick module creates thumbnail graphics of uploaded graphics files. If your installation of Movable Type lacks this module, you won’t be offered a chance to create thumbnails during an upload.

New Feature

The XML::Atom module, written by Movable Type developer Ben Trott, adds support for the Atom Application Programming Interface (API), enabling the software to be controlled externally by software such as weblog editors and Web services. You’ll get a chance to put this functionality under the microscope in Chapter 19, “Supporting the Atom Syndication Format and API.”


Initializing the Software

Now that Movable Type is ready to go, the next script to load in the browser is the system loader program, mt-load.cgi, which initializes the software. Add the script name to your CGI path and load the URL with your browser.

This script sets up the software’s database with 16 tables, creating default records, establishing an initial weblog called First Weblog, creating a sample user, and filling it with 16 Web page and file templates.

The status of database initialization appears on the page as each step in the process completes, ending with a System Initialization Complete message that indicates success (see Figure 3-3).

Click To expand
Figure 3-3: Setting up database records for a new Movable Type installation.

If the script cannot run successfully because it cannot access the database or some other problem occurs, you’ll see an error message. Fix the error and reload the page to run the script again.

After you have run the script successfully, you should immediately delete mt-load.cgi. You won’t need it again, and leaving the script online poses significant security vulnerability. (An older version of Movable Type was exploited using this script and had to be patched.)

With the initialization complete and the database set up with your first weblog, Movable Type is fully installed and ready to go.


Summary

Reaching this point in a Movable Type installation represents a significant accomplishment, especially if this is your first server-based application.

Movable Type consists of Perl scripts and module libraries, Web pages, graphics, Cascading Style Sheets, and JavaScript functions—none of which can be installed in the kind of user-friendly manner most of us have come to rely on in our graphical Windows, Linux, and Mac OS computers.

If you were able to run Movable Type’s system loader script in your Web browser and see a System Initialization Complete message, you’ve finished installing the software and it functions correctly.

Once the software has been installed and verified, you’re ready to begin working on your first weblog, changing the default settings that were created by Movable Type during the software’s installation.

Most of the fine-tuning you’ll be doing in Movable Type beyond this point will take place in a Web browser. You might occasionally make changes to the configuration file mt.cfg as you work with advanced features of the software in upcoming chapters.


Chapter 4: Configuring aWeblog

In This Chapter

  • Running Movable Type’s main script

  • Making graphics display correctly

  • Logging in for the first time

  • Changing your username and password

  • Choosing a home page URL

  • Setting up the site directories

  • Buying a software license

  • Sharing your content under a copyright license

  • Creating accounts for your co-authors

  • Tracking usage of the software

Now that all of the preliminary work has been completed, there’s a functioning Movable Type installation on your Web server that’s itching to be run for the first time.

One of the strengths of a server-based publishing tool is that you can work on it anywhere your server can be reached. With Movable Type on a publicly available Web site, you can update your weblogs from any computer with an Internet connection and a browser, even down to the nitty-gritty work of designing templates, rebuilding pages, and changing your configuration.

Although this availability can be a curse as well as a blessing—a May 27, 2004, New York Times article described a zealous weblogger who offered new updates while vacationing on the beach—Movable Type follows you around.

Before you run Movable Type for the first time, there’s already an author and weblog in the database. A user named Melody has a site called, imaginatively enough, First Weblog, with a default design that you can adopt as you are learning how to work with the software.

This user and weblog can be customized quickly so you can begin publishing your first site. They should be customized quickly, because Melody has a password that’s known to every other Movable Type user on the planet.


Running Movable Type for the First Time

Movable Type runs by loading the main script, mt.cgi, with a Web browser that has JavaScript functionality turned on.

To run mt.cgi, tack the script’s name to the end of your CGI path, as in http://cadenhead.org/cgi-bin/mt.cgi, and fire up the software. You should see a login screen with a graphical Movable Type logo (see Figure 4-1).

Click To expand
Figure 4-1: Logging in to Movable Type.

If you don’t see the logo graphic, your static Web path probably has not been set correctly. Edit your configuration file and make sure that the StaticWebPath setting refers to the directory that holds the docs and images subdirectories and the file mt.js. A common error when editing this file is to omit a trailing slash mark. Here’s the setting on my server:

StaticWebPath /movable/static/
Start Sidebar
Who Is Melody Nelson?

One of the first things a new Movable Type user wants to know: Who is Melody Nelson, and why does this woman have an account on my software?

In 1971, the French pop singer Serge Gainsbourg released Histoire du Melody Nelson, an album written from the perspective of a man obsessed with a young woman named Melody Nelson. She becomes his lover and muse, and then dies tragically in the grand tradition of rock opera.

Ben and Mena Trott are Gainsbourg fans who originally planned to call their software Serge. Although the name changed, they kept the muse around as their new user account and christened the company’s main Internet server serge.sixapart.com.

Melody’s not the only fictional person hanging around popular weblogging software. Radio UserLand and Manila contain references to Bull Mancuso, a tough-talking private investigator who solves difficult software problems.

End Sidebar

When you change this setting and save the file, you can reload the main Movable Type script in your browser to see whether the logo appears. Fix this problem before proceeding; the software’s graphical menu icons and other parts of the interface require a proper static path.

Once you see the graphics, you can log in using an account that has been set up for you: Use the username Melody and the password Nelson. A page displays First Weblog, a new weblog you can set up to your exact specifications.


Setting Up Your Account

The Melody account has full access to all features of the software. You can create and delete weblogs, add users and grant them capabilities to work on your sites, and handle all other tasks required to publish.

Movable Type presents newly logged in users with the Main Menu page, which contains a list of weblogs to edit, news announcements from Six Apart, and shortcuts to frequently used features. This page appears in Figure 4-2.

Click To expand
Figure 4-2: Browsing the software’s Main Menu.

The first thing you should do is change the username and password of your account. Until you do, anyone who runs Movable Type will be able to log in to your installation of the program.

To make changes to your user account, click the Melody link, which can be found at the upper-right and is circled in Figure 4-2. This opens a form page containing your username and other settings.

Four of these settings can be displayed on your weblog in Web pages and syndication files: the account’s username, nickname (or full name), e-mail address, and home page URL.

Choose a new password, typing it in both the Password and Password Confirm text fields. Because anyone using the Internet can attempt to log in to your Movable Type installation, it’s important to choose a good password that can’t be guessed or discovered by password-cracking software. Ideally, your password should be at least eight characters and contain letters, numbers, and punctuation. You can achieve even better security by mixing uppercase and lowercase letters and avoiding dictionary words.

Cross-Reference

The Remote Authentication section of the form looks for Atom and TypeKey authentication tokens. You don’t need to set these now; they’ll become important later as you work with visitor comments and Atom publishing formats (topics covered in Chapter 10, “Offering Comments,” and Chapter 19, “Supporting the Atom Syndication Format and API”).

Scroll to the bottom of the page and click Save to commit your changes to the database. The link to your username at the upper-right will change from Melody to your newly chosen name. Click that link at any time to make changes to your account.

The Main Menu link atop the page returns you to that page. From now on, log in with your newly chosen username and password.


Creating Your First Weblog

Movable Type can be used to publish multiple weblogs authored by yourself and other people to whom you’ve given accounts. The weblogs will be listed on the Main Menu page.

You can click a weblog’s name to load its main editing page or use the accompanying list linking to common tasks.

Assuming that you don’t like the name “First Weblog,” you can make immediate changes to the new site from the Main Menu: In the link list along the right edge of the First Weblog section, click the Edit Configuration link. The Core Setup page appears (see Figure 4-3).

Click To expand
Figure 4-3: Configuring a weblog.

Title your site in the Weblog Name field. You can change it at any time without hassle—Movable Type’s template-based publishing system grabs the name automatically, reflecting any change immediately upon the next publication of the site.

The next four settings, which you must configure in order for the weblog to work as desired, are some important directories and URLs:

  • Site URL: The address of the weblog’s home page (without a filename)

  • Archive URL: The address of the weblog’s main archive page (also without a filename)

  • Local Site Path: The directory on the Web server where the home page and other important documents should be stored

  • Local Archive Path: The directory on the server where archive pages should be stored

A weblog can use the same address for the site and archive URL and the same directory for both local paths or different settings for each.

The default settings are based on the server hosting Movable Type and how the software was configured in the mt.cfg file. You don’t have to use any of these suggestions.

I used the following four settings for Orlando Vacationer, a travel and tourism weblog that appears in examples throughout the remainder of this book:

  • Site URL: http://www.orlandovacationer.com/

  • Archive URL: http://www.orlandoavacationer.com/archives/

  • Local Site Path: /var/www/orlandovacationer.com/html

  • Local Archive Path: /var/www/orlandovacationer.com/html/archives

Start Sidebar
Setting Up Path Directories

Movable Type does not create and set up the site and archive path directories; you must do this yourself through a command shell, FTP client, or some other means of connecting to your Web server.

These directories can be part of the same directory tree as other Web sites on the server, but you should give Movable Type weblogs their own subdirectories to avoid overwriting files created by other software (or vice versa).

The site and archive path directories should allow full read, write, and execute permissions.

Using my own Orlando Vacationer site as an example, the following commands set up the directories and the proper permissions:

$ mkdir /var/www/orlandovacationer.com/html

$ mkdir /var/www/orlandovacationer.com/html/archives

$ cd /var/www/orlandovacationer.com

$ chmod 777 html html/archives

End Sidebar

Note that both URLs end with a trailing slash character (/) and the local paths do not. The paths are on a Linux server; a Movable Type installation running on Windows will reference directories differently.

The last setting to select on the Core Setup page is the time zone that will be used on all timestamps on the site. Select the desired zone and click Save Changes.

The page reloads with a yellow message box stating that you can rebuild the site to see your changes reflected on the weblog. There’s no reason to do this yet; your weblog is empty so there’s nothing useful to publish.

You can return to the Core Setup page by clicking the Weblog Config button on Movable Type’s sidebar menu.

Although you don’t need to make any more changes to begin working on your weblog, there’s one more setting on another configuration page that ought to be set up at this time. In the list of links atop the Core Setup page, click the Preferences link to open that page.

The Description text box provides a place for a tagline or slogan that succinctly explains the content or purpose of the weblog. This description can be displayed with the title, presented in a sidebar, and promoted in other ways.

When you’ve set a suitable description, scroll to the bottom of the page and click Save Changes.


Licensing Your Software

Six Apart offers a variety of licenses for Movable Type, including a limited personal version that can be used at no cost.

Which license you choose depends on whether you use the software for commercial or personal projects, how many weblogs you publish, and the number of co-authors who work on those sites.

For a full list of licenses and pricing, visit the Six Apart Web site at http://secure.sixapart.com.

Table 4-1 describes the licenses, user privileges, and current prices.

Table 4-1: Movable Type Licensing Options
License Type | Maximum Authors | Maximum Weblogs | Price
Personal | 1 | 3 | Free
Personal | 5 | Unlimited | $69.95
Personal | Unlimited | Unlimited | $99.95
Commercial | 5 | Unlimited | $199.95
Commercial | 10 | Unlimited | $349.95
Commercial | 20 | Unlimited | $599.95
Commercial | 35 | Unlimited | $999.95
Commercial | 50 | Unlimited | $1,299.95

Individuals using Movable Type for noncommercial purposes qualify for a personal license. Companies, organizations, and individuals setting up Movable Type for clients require a commercial license instead.

With the exception of the free version, all Movable Type licenses come with the following perks:

  • Downloads of Movable Type versions 3.0 and 2.661

  • Customer support from Six Apart

  • Promotion on the Six Apart site’s Recently Updated list of weblogs

Free users can still get customer support from other Movable Type users on the support forums at the Six Apart site.

When you buy a license for Movable Type, you are asked whether you wish to download the full version or upgrade version of the software. This isn’t necessary if you already have a functioning installation of the current version, as the download is identical to the one you’ve already set up. Otherwise, you can snag the upgrade to bring the software up to date.

Web Site Download

After you have paid for a license via an online credit card payment, you can visit your Movable Type account page at https://secure.sixapart. com/t/account.

This page offers customer support, software downloads, and your Update Key, an alphanumeric code that includes your weblog on Six Apart’s list of recently updated weblogs.

The Update Key should be stored in the configuration of one weblog that you want to promote. When you’re ready to start calling attention to your site, here’s how to set up the key:

  1. Copy the Update Key from your Movable Type account page.

  2. On the Main Menu page, click the weblog’s Edit Configuration link. The Core Setup page appears.

  3. Click the Preferences link to open that page.

  4. Click the Publicity / Remote Interfaces / Trackback link. The page jumps down to that section.

  5. Enter the key in the Recently Updated Key field.

  6. While you’re here, two other configuration settings cause your site to appear on an update list. In the Notify the Following Sites When I Update My Blog section, enable the blo.gs and weblogs.com checkboxes.

  7. Scroll to the bottom of the page and click Save Changes.

Each time you publish a new entry, the weblog should show up in the Recently Updated section of the Movable Type home page at http://www.movabletype.org. Because Six Apart has thousands of paying customers, your link is likely to scroll off the list after a few minutes.


Adopting a Creative Commons License

Movable Type generates weblog content in a wide variety of formats (and can easily support more). A newly created weblog publishes entries as Web pages and three other kinds of files: Atom, RSS 1.0, and RSS 2.0 newsfeeds. You can see the templates and names of these files by clicking the Templates button on the software’s sidebar menu.

Newsfeeds are structured XML data in a form easily parsed by software. These feeds make it possible for your work to be read outside of a Web browser using client software called a newsreader, a highly popular way to follow weblogs, news headlines, and other regularly updated sites.

This process has come to be known as site syndication because of another use for newsfeeds: sharing content from your site so that it can be republished in whole or in part elsewhere on the Web.

This practice is extremely commonplace today. Because you’re making newsfeeds available, you ought to decide as soon as possible what kind of publishing and redistribution you are willing to permit.

The Creative Commons organization was formed in 2001 to encourage publishers, artists, and others to share their copyrighted work under licenses that safeguard their interests while encouraging others to make use of the material. You can read about its licenses on the Web at http://creativecommons.org/learn/licenses.

To encourage sharing, the group offers several Creative Commons licenses that indicate how much, or how little, you want to share. These licenses have been adapted for use in syndication feeds and are supported in Movable Type. You can choose a license in your site configuration settings, which is then applied to your weblog’s pages and syndicated newsfeeds.

Caution

Creative Commons has resulted in a lot of innovative collaboration that wouldn’t be possible otherwise, but you shouldn’t jump into it too quickly. Before adopting a license, take the time to understand the ramifications of a Creative Commons license. Once you make your work available under a license and someone begins re-using it under your terms, you cannot revoke the license for that material. The most you can do, if you experience a subsequent change of heart, is choose another license for anything you create from that point forward.

When choosing a Creative Commons license, the first thing to decide is whether to permit others to reuse your work for commercial purposes or limit it to noncommercial use.

If you impose a noncommercial restriction, the following term applies to the license: “The licensor permits others to copy, distribute, display, and perform the work. In return, licensees may not use the work for commercial purposes—unless they get the licensor’s permission.”

Next, you must decide whether to allow others to make their own changes to the work and redistribute them. You can allow this, disallow this, or allow it only if they make their new work available under the same terms that you did.

This last term, described as a ShareAlike policy, is worded as follows: “The licensor permits others to distribute derivative works only under a license identical to the one that governs the licensor’s work.”

The licensor permits others to copy, distribute, display, and perform the work. In return, licensees cannot use the work for commercial purposes—unless they get the licensor’s permission.

If you don’t apply a license to your weblog, normal copyright law applies. In the U.S. and many other nations, you don’t even need to put a copyright statement on your site or in syndication feeds; your work is copyrighted automatically upon creation.

If you want to adopt a Creative Commons license in your weblog, follow these steps:

  1. Click the Edit Configuration button on the Main Menu page (or the Weblog Config button on the sidebar menu).

  2. Click the Preferences link.

  3. Scroll down to the Creative Commons License section and click the Create a License Now link. A pop-up window asks for the terms of the license you have chosen.

  4. Answer the licensing questions, and then click the Select a License button.

  5. The name of the Creative Commons license you have selected is displayed along with the address of a Web page containing the license. Click Proceed.

  6. The Preferences page is redisplayed with your choice of license in the Creative Commons License section.

  7. To save your configuration, scroll to the bottom of the page and click Save Changes.

By returning to the Creative Commons License section of this page, you can change or remove the license. The license you have chosen will be reflected in the Web page and RSS 1.0 newsfeed.

Hidden text is added to the home page, taking the following form:

<!--
<rdf:RDF xmlns="http://web.resource.org/cc/"
         xmlns:dc="http://purl.org/dc/elements/1.1/"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<Work rdf:about="http://www.orlandovacationer.com/">
<dc:title>Orlando Vacationer</dc:title>
<dc:description>Disney discounts, park perks, tourist
tips</dc:description>
<license rdf:resource="http://creativecommons.org/licenses/by-
     sa/1.0/" />
</Work>
<License rdf:about="http://creativecommons.org/licenses/by-sa/1.0/">
<requires rdf:resource="http://web.resource.org/cc/Attribution" />
<requires rdf:resource="http://web.resource.org/cc/Notice" />
<requires rdf:resource="http://web.resource.org/cc/ShareAlike" />
<permits rdf:resource="http://web.resource.org/cc/Reproduction" />
<permits rdf:resource="http://web.resource.org/cc/Distribution" />
<permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
</License>
</rdf:RDF>
-->

This text is formatted as RDF, an XML dialect used to provide reference information about Internet content such as the author and copyright.

The following line appears in the RSS 1.0 newsfeed, which also makes use of RDF:

<cc:license rdf:resource=”http://creativecommons.org/licenses
   /by-sa/1.0/”/>
Cross-Reference

You can learn how to add Creative Commons licensing to RSS 2.0 and Atom files in Chapter 18, “Publishing RSS and Atom Syndication Files,” and Chapter 19, “Supporting the Atom Syndication Format and API.”


Adding Other Authors to a Weblog

Although a Movable Type installation begins as a solitary project, it doesn’t have to stay that way.

As the software’s licensing indicates, a single installation of Movable Type supports multiple weblogs and authors. Any of the paid personal or commercial licenses can be used for collaboration, from the five-author personal license up to the 50-author commercial license.

Each Movable Type weblog can be assigned a different author or combination of authors. A role-based permissions system dictates the specific tasks an author can perform on a per-weblog basis, making a wide range of access possible—from highly trusted users who can do everything you can do with the software, even to the point of adding new weblogs and user accounts, to more limited users who can edit only their own entries.

When setting up an author’s contact information, consider the fact that the person’s e-mail address and home page will be shared with the public in the weblog’s Atom newsfeed and might appear elsewhere on the site.

Sharing an e-mail address publicly on a Web site brings an increase in unsolicited junk mail as spam-harvesting software finds the site and saves all addresses that it detects. If your co-authors are concerned about this, they should set up a free e-mail account on a service such as Yahoo, Google Gmail, or Microsoft Hotmail and use that instead of their regular address.

There are two permissions you can grant a user that apply to the entire installation: the capability to create new weblogs and view the activity log, a list that tracks how the software is being used.

The remaining permissions are granted on a per-weblog basis. The following roles can be permitted or denied to each author:

  • Configure Weblog: Modify any of the weblog’s settings.

  • Edit Address Book: Add and remove e-mail addresses from the site’s notification list.

  • Edit All Posts: Revise weblog entries, even if other authors wrote them.

  • Edit Authors & Permissions: Set permissions for any author of the weblog.

  • Edit Categories: Add and remove weblog entry categories.

  • Edit Templates: Add, remove, and change the templates used to generate all weblog pages and other files.

  • Post: Write entries and edit them as needed.

  • Rebuild Files: Republish all of the files that comprise the weblog.

  • Send Notifications: Send e-mail about a new entry to the site’s notification list.

  • Upload File: Transfer graphics and other files to the server.

As you’re starting out with Movable Type’s collaboration features, one safe approach is to enable new authors with just the Post and Rebuild Files roles. They’ll be able to contribute entries to the weblog and make changes to them as needed, but the rest of the weblog’s functionality will be your domain.

The Edit roles should be granted only to authors who are comfortable with Movable Type and can be trusted completely. These roles could be used to wipe out the entire weblog and the templates that create all of your content, leaving no way to restore the site unless you back up the data regularly (as described in Chapter 12, “Backing Up a Weblog”).

When you’re ready to add an author, perform these steps:

  1. If you aren’t there already, click the Main Menu link atop any page.

  2. In the Shortcuts section, click the Add/Edit Weblog Authors link. The Authors & Permissions page opens in the browser.

  3. Choose a username, password, and e-mail address for the user. Although you can provide a URL, your co-author can just as easily set that up later (or decide to omit it).

  4. Click Save. The user’s permissions page opens, as shown in Figure 4-4.

    Click To expand
    Figure 4-4: Setting an author’s permissions.

  5. The General Permissions section applies to all weblogs. Enable the checkboxes of the roles the author can perform.

  6. The rest of the permissions are organized by weblog. Enable the checkboxes for the desired roles on that site.

  7. To add an author to a weblog, select it in the Add User to an Additional Weblog drop-down menu at the bottom of the form and click the Add button (not shown in Figure 4-4).

  8. Make these changes permanent: Click Save.


Keeping an Eye on the Software's Activity Logs

Team LiB

Keeping an Eye on the Software’s Activity Logs

Movable Type Web sites are published as static Web pages and other files, so the use of your weblogs can be tracked with the same log analysis programs you use on other sites. If you have a program such as Urchin, Webalizer, or WebTrends, you can continue to use it to find out how your weblogs are being accessed.

There’s also an activity log in Movable Type that tracks how the software is being used, as you can see in Figure 4-5.

Click To expand
Figure 4-5: Monitoring Movable Type usage.

To check the software’s log, on the Main Menu page, click the View Activity Log link in the Shortcuts section.

The log tracks five kinds of information:

  • Users logging in and logging out

  • The publication of new entries

  • Comments rejected because users post too quickly

  • Errors sending messages to other sites

  • Site searches

Movable Type has a message-throttle feature that prevents someone from flooding your weblog with comments, either intentionally or accidentally.

The ThrottleSeconds setting in the software’s configuration file, mt.cfg, controls how often a comment can be submitted from the same IP address. The default is to reject a comment if fewer than 20 seconds have elapsed since the last comment was posted from that address. This shows up as a “Throttled comment attempt” in the activity log.

Ping messages in the log relate to failed efforts to contact weblogs.com, blo.gs, or some other site that tracks recently updated weblogs. You can notify these sites each time you publish an entry.

The ping errors require no corrective action on your part. The most common cause is a “read timeout” when one of the servers can’t be contacted, which happens from time to time because they are extremely popular.

Cross-Reference

Web servers collect a lot more information on site usage than the small amount of data presented in Movable Type’s activity log. You can find out which pages are requested most often, what sites send the most visitors through hyperlinks, what browsers are most popular, and what errors have taken place (such as missing pages, broken links, and the like).

Server analysis software must be run independently of Movable Type and might require special configuration in your Web server. Use the following links to find out more about some of the leading Web server analysis programs:

Analog: http://www.analog.cx

Urchin: http://www.urchin.com

Webalizer: http://www.mrunix.net/webalizer

WebTrends: http://www.netiq.com/webtrends


Summary

The introduction to this chapter mentioned an extremely dedicated weblogger who composed new entries from the beach. That sunbathing blogger is Richard Wiggins, who writes Wigblog on technical topics such as search engines and weblogging software at http://wigblog.blogspot.com. The New York Times photographed him working wirelessly from a beach chair in Key West, Florida, alongside a line of swimsuit-clad vacationers.

“It seems as if his laptop is glued to his legs 24/7,” his wife, Judy Matthews, told a reporter.

Although Wiggins uses another server-based publishing tool, Movable Type could just as easily be a source of curiosity and exasperation to your loved ones. If you can get an Internet connection and your installation of the software runs on a public server, you can take your personal or professional weblog anywhere you go.

In the next chapter, “Writing a Weblog Entry,” you’ll begin creating content for your new site. Whether it becomes as habit-forming as Wigblog and hundreds of other zealously updated weblogs is up to you.

Or, as I tell myself when I spend an extra hour at the computer updating my own weblog, I can quit at any time.


Chapter 5: Writing a WeblogEntry

In This Chapter

  • Simplifying the weblog editing form

  • Composing a new entry

  • Using excerpts and keywords

  • Publishing the site

  • Writing article-length weblog entries

  • Adding fields to the editing form

  • Choosing default settings for new entries

  • Receiving comments and trackback pings

  • Creating a QuickPost link

Depending on who you ask, weblogs are either a full-fledged revolution in how people get information on the Internet or the latest in a long line of dreadfully overhyped dot-com fads.

As the author of several books on weblog software and an active weblogger, my vote leans heavily toward revolution, which can’t be much of a shock.

The format of weblogs was not novel when Michael Sippey, Harold Check, Dave Winer, and other pioneers began publishing these sites in the late ’90s and a new term was coined to describe their work. Since the beginning of the Web, many sites have presented lists of links, online journals, and other chronologically ordered content, with the newest material presented first.

However, as this style of heavily linked, spontaneous communication became popular and was supported by software like Movable Type, a community of webloggers that originally numbered in the dozens became a horde of thousands, publishing frequently, linking to each other, collecting information on the Web, and sharing their findings.

The resulting network of webloggers, perhaps as large as a million today, dramatically changed the dissemination of news and other timely information.

In the July 3, 2002, Wall Street Journal, Peggy Noonan called weblogs the “most thoughtful, most strange” form of free speech. “Thousands of independent information entrepreneurs are informing, arguing, adding information. . . Blogs may one day become clearinghouses for civil support and information when other lines, under new pressure, break down.”

You become a part of that strange network when you pen your first weblog entry in Movable Type.


Using the Weblog Entry Form

All weblog content that you create with Movable Type can be written in a JavaScript-enabled Web browser over any Internet connection. Run Movable Type’s main script by loading its URL, log in with your username and password, and publish your site from anywhere in the world.

Movable Type collects 11 kinds of information for each weblog entry on the entry-editing form, most of which relates to the text of the entry in some manner. As you begin using the software, you might find it easier to switch to a simpler form that contains the most important fields:

  1. Click the New Entry button in the sidebar menu. The entry-editing form appears.

  2. At the bottom of the form, click the Customize the Display of This Page link. A Field Configuration page opens in a separate browser window.

  3. Choose the Basic configuration option, and then click Save.

The editing form reopens with only four fields (see Figure 5-1).

Click To expand
Figure 5-1: Using a simplified entry-editing form.

In Movable Type, a weblog entry at its simplest consists of a title and entry body. The title, succinct text with no links or other HTML formatting, appears as the heading for the entry on the weblog’s home page and in the page title for the entry’s individual archive. You can change how and where the title appears by editing the weblog’s templates.

The entry body can be one or more paragraphs of text separated by blank lines. Buttons along the top edge of the Entry Body text box insert hyperlinks into the text and apply three formatting styles to selected text: boldface, italics, and underlining.

When you’re composing an entry, you see the HTML markup used to present the text. If you are comfortable writing your own HTML tags, you don’t have to use the formatting buttons found on the top edge of the Entry Body text area (indicated in Figure 5.1).

As you compose an entry, you don’t need to mark up paragraphs with p tags, the HTML markup tag functioning as paragraph separators. Movable Type’s text formatter adds these tags automatically, using blank lines to determine where paragraphs begin and end.

When you have finished composing an entry and are ready to publish it on your weblog, change the Post Status drop-down menu from Draft to Publish and click the Save button.

Movable Type publishes the weblog entry in several places:

  • The weblog home page (index.html)

  • Three XML syndication files in Atom (atom.xml), RSS 1.0 (index.rdf), and RSS 2.0 (index.xml) formats

  • An individual archive page containing the entry

  • A monthly archive page containing all entries from the current month

The weblog entry composed in Figure 5-1 can be seen in published form in Figure 5-2. The default weblog templates determine the actual appearance of the page.

Click To expand
Figure 5-2: Presenting a weblog entry on a Web page.

Listing 5-1 shows how the entry appears in the weblog’s RSS 2.0 feed, a file structured as XML so that it can be read easily by software.

Listing 5-1: A Weblog Entry in RSS 2.0
Start example
<item>
  <title>Mission: Space Hard to Stomach</title>
  <link>http://orlandovacationer.com/archives/2004/06/mission_space.
html</link>
  <description>Airsick bags have been added to Mission: Space at
Epcot, solidifying its reputation as the Disney World attraction
most likely to make people lose their lunch. As Theme Park Insider
writes: Many within the company felt the thrill ride
was...</description>
  <guid>http://orlandovacationer.com/archives/2004/06/mission_space.
html</guid>
  <category></category>
  <pubDate>Wed, 09 Jun 2004 07:57:39 -0500</pubDate>
</item>
End example

Movable Type can represent a weblog entry in an unlimited number of formats, making it possible to offer different versions of your Web site for different audiences. You can offer a graphically rich site for viewing by Web users on desktop computers with fast Internet connections, a simpler text site for mobile phones and other wireless devices, and syndicated Atom and RSS feeds for people who use news aggregators to check their favorite sites for updates.

The weblog home page and syndication files are produced from index templates, a set of templates that produce content in the weblog’s main directory.

Cross-Reference

You learn how to make changes to these files in Chapter 8, “Producing Web Pages with Template Tags.”

After an entry has been published, you can make changes or delete it as needed:

  1. Click the Entries button in the sidebar menu. The List & Edit Entries page opens.

  2. Click the title of the entry to edit. The entry-editing form opens, filled out with the text entered previously.

  3. To pull the entry off the weblog for more editing, change the Post Status drop-down menu to Draft.

  4. Click Save to finalize your changes.

Movable Type produces Web content by rendering static Web pages and other files from an external database. The software calls this rendering process rebuilding the site, and it happens automatically when a new entry is written or an entry is edited.

Some changes require that the weblog be explicitly rebuilt:

  1. Click the Rebuild Site button in the sidebar menu. A pop-up window asks which pages should be rebuilt, as shown in Figure 5-3.

    Click To expand
    Figure 5-3: Publishing a site by rebuilding files from templates.

  2. To republish the entire site, a process that can take 5–15 minutes or longer on a large weblog, choose Rebuild All Files from the drop-down menu.

  3. To republish index templates, choose Rebuild Indexes Only.

  4. To republish the weblog’s archive pages, choose Rebuild Individual Archives Only or Rebuild Monthly Archives Only.

  5. Click Rebuild.

Movable Type provides progress messages as a weblog is being rebuilt.

Every aspect of the editorial process in Movable Type can be customized. You can change the fields that appear on an entry-editing form, making the form simpler or more complex based on the kinds of information you want to collect, and alter the presentation of the entry by editing the index and archive templates.

The net result is a content-management tool that goes beyond simple weblog editing, enabling other kinds of Web sites to be produced.

New Feature

Movable Type 3.0 adds a new feature for plug-in developers that makes the software even more extensible. With object callbacks, you can create Perl scripts that are notified when something is loaded, stored, or deleted from the database. Chapter 21, “Hooking into Movable Type with Callbacks,” provides the full details.


Writing an Entry

The entry-editing form’s basic configuration serves a useful purpose, enabling new and technically inexperienced weblog authors to begin creating their own entries quickly.

As you become comfortable with the software, you can accomplish a lot more with an editing form that contains all of the options:

  1. Click the New Entry sidebar menu button to open the entry-editing form.

  2. Scroll to the bottom and click the Customize the Display of This Page link. A Field Configuration page opens in a separate browser window.

  3. Choose the Custom configuration option. This section includes a checkbox for each field that can be added to the editing form.

  4. Enable all of the checkboxes in the Custom section, and then click Save.

The significantly larger editing form reopens. (Figure 5-4 shows the options on the bottom half of the form.)

Click To expand
Figure 5-4: Using the full entry-editing form.

This entry-editing form includes three additional fields that can be used to customize the content of a weblog entry: Excerpt, Extended Entry, and Keywords.

The Excerpt field defines a summary or excerpt, which can be as long or as short as necessary. When left blank, the excerpt becomes the first 40 words of the entry body followed by an ellipsis (...).

The Keywords field provides a place where you can define a comma-separated list of terms that apply to the entry or use any other means to describe the content of the entry. This text isn’t presented in any files produced by Movable Type’s default templates. Instead, it helps people using the site’s search feature—keywords will be searched along with the other text of the entry.

The weblog entry composed in Figure 5-4 does not contain the words “thrill rides.” Because they appear in the list of keywords, a search query for that term will produce a link to the entry.

The Authored On field, one of the advanced editing settings shown at the bottom of the form in Figure 5-4, contains a timestamp representing the time the entry was first published. By editing this value, you can create entries for the past or the future.

To set up an entry that won’t be published until a set date and time, change the Authored On date to that future timestamp. The first time the site is rebuilt after that time, the entry will be published.

Change Authored On to a past date and time to store it in the weblog at that timestamp. Movable Type organizes entries in reverse chronological order, so after you save the changed entry, it will move from the top of the Edit Entries list to the position established by the new timestamp.

The Authored On date must have the format YYYY-MM-DD HH:MM:SS. In order, the letters represent a four-digit year and a two-digit month, day of the month, hour, minute, and second. For example: 2004-07-10 12:20:00.

The Primary Category field is covered during the next chapter, “Organizing a Weblog.”

Gotcha

Movable Type doesn’t provide an entry field for an external link, which is a hyperlink leading off the weblog to another Web site. There’s an entry called a permalink that can be presented in templates, but it’s associated with individual archive pages for each entry. You can work around this situation by using the Keywords field for this purpose, as long as you’re willing to forego the use of search keywords.

Dividing Entries into Two Fields

The Extended Entry field makes it possible to split an entry over two fields instead of putting it in the Entry Body field, thus creating weblog entries that consist of two parts: a body and an extended body.

An entry can be split over two fields at your discretion. You could designate the first paragraph of an entry as the body and the rest as the extended body, put up to 500 words in the body and the rest in the extended body, or any other technique that suits your needs.

When an entry has been divided in this manner, the entry body appears on the home page and most archive pages, followed by a “Continue reading...” link that can be used to read the rest, as shown in Figure 5-5.

Click To expand
Figure 5-5: Reading a divided weblog entry.

The “Continue reading...” link opens the individual archive page for the entry, which contains the entry body followed by the extended entry, presented as a seamless whole. All other archive pages divide entries in the same manner as the home page.

Because there’s no limit on the size of the Entry Body field, you might view it as needless work to split an entry over two fields.

For a weblog with entries that never run more than a few paragraphs, this division probably is more work than necessary. If you’re comfortable with running the full text of all weblog entries on a site’s home page and archive pages, you can use the Entry Body field and remove the Extended Entry field from the editor:

  1. On any entry-editing form, click the Customize the Display of This Page link below the form. The Field Configuration page pops up in its own window.

  2. With the Custom option selected, remove the check next to the Extended Entry field and click Save.

Removing a field from the entry-editing form does not delete any existing weblog content that appears in that field—it just takes away the capability to view or change that part of an entry. On existing entries that contain extended entries, the text still appears on the entry’s individual archive page when the site is republished.

Movable Type’s separation of entries into two fields comes into its own when you want to break out of the weblog mold and create other kinds of articles, essays, and pages with the software.

Although Movable Type is accurately described as a weblog editing tool, you can employ the software to publish any Web content that makes sense to organize chronologically, such as newspapers, online magazines, family photo albums, and sites for teams collaborating on a project.

When you are using the software to create articles and other work longer than a few paragraphs, the entry-editing form can be used in the following manner (see Figure 5-6):

  • Title defines the headline.

  • Entry Body holds the lead paragraph (or paragraphs).

  • Extended Entry contains the rest of the body text.

  • Excerpt holds a summary, which can be the lead or something even more succinct.

  • Keywords lists search terms that apply to the piece.

    Click To expand
    Figure 5-6: Publishing articles and other longer text.

With support for multiple authors and the organization of a weblog into categories, Movable Type can be an effective content-management system for sites that aren’t weblogs by any stretch of the definition.

Setting Default Values for the Editing Form

The remaining fields on a full entry-editing form specify how an entry is published, whether it accepts feedback, and sites that should be notified to publicize your work.

These fields, shown earlier in Figure 5-4, are all part of the weblog configuration, which you can edit with the software’s browser interface. When one of these fields is removed from the editing form, the configuration setting is used by default.

For example, the post status of a newly written entry can be either Draft, which stores the entry in the database without publishing it, or Publish, which stores and publishes it at the same time.

If you set the configuration to a default status of Publish and remove the Post Status field from the editing form, all new entries are published automatically when they are saved.

The Comments and Accept Trackback Pings fields determine whether feedback is accepted for an entry.

A Movable Type weblog can accept visitor comments and trackback pings in response to each entry, publishing them after the entry on its individual archive page.

You can decide whether to offer these features for an entire weblog or set them on an entry-by-entry basis.

An entry’s Comments field can be set to Open (accept comments), None (do not accept them), or Closed (stop accepting comments). The third setting is used to conclude discussion of an entry at some point.

Cross-Reference

Trackback pings are a form of feedback between different weblogs, a novel technique developed by Six Apart that’s explored fully in Chapter 11, “Sharing Trackback Links.”

When another weblog contains a reference to an entry on your site, Movable Type can be notified about this event through the use of a trackback ping—a message transmitted from one weblogging software tool to another.

Movable Type can accept trackback pings for each entry. The Accept Trackback Pings checkbox can be either enabled to take pings or disabled to ignore them.

The URLs to Ping text box makes use of trackback pings in the opposite direction. If you know the Web address (URL) of a server that should receive a ping related to your entry, you can place it in the box. For more than one ping, put each URL on its own line.

When the entry is published, trackback pings are sent to each URL. As you learn in Chapter 11, pings also can be sent automatically to any weblog that you link to in an entry.

Formatting Text for Publication

A weblog entry’s Text Formatting setting determines whether a text formatter converts the entry text. A text formatter is a Movable Type module that transforms text for presentation on the Web.

Earlier in this chapter, you learned that it isn’t necessary to put HTML p tags around each paragraph when you’re writing an entry. You can omit these because the software’s default text formatter, Convert Line Breaks, adds paragraph tags and line breaks.

In a Movable Type entry, text separated by blank lines is converted into paragraphs with opening p and closing p tags. Other blocks of text have br tags as line breaks.

To see the Convert Line Breaks formatter in action, compare the text composed in the Entry Body field of Figure 5-7 to the XHTML output in Listing 5-2.

Click To expand
Figure 5-7: Creating a new weblog entry.
Listing 5-2: Formatted Entry Text
Start example
<p>JetBlue is offering $69 one-way flights from Boston to Orlando and
other Florida cities.</p>

<p>Tickets must be purchased by Feb. 10 for trips ending no later
than May 25.</p>

<p>Restrictions:<br />
Seats are limited and may not be available on all flights.<br />
Sale fares are most often found on midweek travel dates.<br />
All fares are one-way and nonrefundable.</p>
End example

The entry in Figure 5-7 contains three paragraphs, separated by blank lines instead of indentation. The third paragraph, which lists ticket restrictions, contains a list of items that are not separated by blank lines. This causes br tags to be inserted at those positions.

Tip

In text presented on a Web page, paragraph breaks result in much more readable text than line breaks. You can see this in visitor comments on a weblog entry, because many people post them without placing a blank line between each paragraph. To make the text in Figure 5-7 more readable, I would put the ticket restrictions in a list using the ul and li HTML tags or combine them into a single paragraph.

Entry text also can be unformatted: Choose None from the Text Formatting drop-down menu.

Choosing Default Editing Settings

If you know you won’t be changing some of the advanced fields at the bottom of an entry-editing form, you can set their default values in your weblog configuration and remove them from the form:

  1. Click the Weblog Config button in the sidebar menu. The Core Setup page appears.

  2. Click the Preferences link to open the Preferences page. Several settings on this form relate to the composition of weblog entries.

  3. Use the Default Text Formatting for New Entries drop-down menu to choose the Convert Line Breaks formatter or None for no formatter at all.

  4. Choose a post status in the Default Post Status drop-down menu: Draft or Publish.

  5. Scroll down to the Allow Trackback Pings On by Default setting. Enable this box to allow incoming pings.

  6. In the Allow Comments Default setting, choose Open, None, or Closed.

  7. After choosing the settings you want to change, click Save Changes to make them permanent.

Movable Type suggests that you rebuild the site, but this isn’t necessary for these particular settings. They take effect immediately.

If you remove any of these fields from the editing form, the configuration setting you just made is always used on new entries. Comments and trackback configuration are covered in depth in Chapter 10, “Offering Comments,” and Chapter 11.


Setting Up a QuickPost Window

Although weblogs vary greatly in style, one characteristic many share in common is immediacy. A weblog author can dash off entries as casually as writing an e-mail or instant message, employing the informal language and conversational shorthand you expect to hear among longtime friends.

Movable Type shortens the time from inspiration to entry with the QuickPost form, a pop-up window that can be used to add entries to any of your weblogs. With a QuickPost bookmark on your favorite browser, you can begin a new entry while looking at a Web page you want to cover. The page’s link and title appear automatically in the text of your entry, saving you the hassle of copying and pasting the link and creating a tag.

The QuickPost page offers a simpler version of the New Entry form, designed exactly to your specifications. You build the form by choosing the fields that will appear on it.

The form always contains four fields that collect the weblog, entry title, body text, and status (Draft or Publish), as shown in Figure 5-8.

Click To expand
Figure 5-8: Writing an entry with QuickPost.

You can launch QuickPost by clicking a link on a browser’s Links toolbar (called the Bookmarks toolbar in Netscape Navigator and Mozilla). The page you’re on at the time becomes a link in the Entry Body text area, as shown in Figure 5-8.

You can choose additional fields from the entry-editing form that will appear in the QuickPost window. Eight extra fields can be placed on the page: Allow Comments, Allow Pings, Category, Excerpt, Extended Entry, Keywords, Text Formatting, and Trackback.

QuickPost must be set up before you can use it:

  1. If you aren’t on the main menu, click the Main Menu link atop a page.

  2. In the Shortcuts section, click the Set Up QuickPost link. The QuickPost page displays a list of fields you can add to the form.

  3. Enable the checkboxes for each field you want to add, and then click the Create button. A QuickPost instruction page appears.

  4. In your browser, make the toolbar for links visible (choose View ® Toolbars ® Links in Internet Explorer and choose View ® Toolbars ® Navigation Toolbar in Navigator or Mozilla).

  5. In Internet Explorer, the Links bar might not be given enough space to the right of the browser’s Address bar (and the Go button). Drag the handle to the left of the word Links to the left, expanding the toolbar and shrinking the Address bar.

  6. The QuickPost link on the page should be dragged to the Links toolbar, which is illustrated in Figure 5-9. When you release the link atop the toolbar, a QuickPost link appears at that position.

    Click To expand
    Figure 5-9: Creating a QuickPost link in a Web browser.

  7. Internet Explorer might display a security dialog box warning that the link “may not be safe.” There are no security risks from the QuickPost link, so click Yes to continue.

The QuickPost link uses JavaScript to open the pop-up window, which is what prompts the security warning.

When you’re on a Web page about which you want to write a weblog entry, click the link. The pop-up window appears with the page’s title and link in the Entry Body.


Summary

Movable Type’s content-management system can be put to use on weblogs and any other kind of Web sites that are updated frequently.

The entry-editing form, which can be as simple or complex as needed, collects information used to publish weblog entries, archives, articles, and syndication feeds. The software publishes files as static Web pages and files when entries are written, edits are made, or a rebuild of the site is explicitly requested.

As you begin publishing a weblog, you might not realize the peculiarities of communicating over a medium in which thousands of authors form ties with each other through an odd, transitory currency of exchange: the hyperlink. One of the pleasures of sharing information in this manner is watching as something you’ve written gains the attention of other publishers and is heavily linked.

Although some weblogs are published to reach a mass audience, most of these sites reach a more intimate group that consists primarily of friends, relatives, colleagues, and random Google users who chanced upon its pages during a search. Most webloggers weather an early period during which traffic is low, feedback is next to nonexistent, and you question whether it’s an effective use of your time.

As your weblog’s audience grows and you become more accustomed to expressing yourself regularly in virtual newsprint, you’re likely to find that a community of similar weblogs has sprung up, and your own site is somewhere in its membership.

Whether weblogs are a communications revolution or a link list with delusions of grandeur, you can benefit from placing yourself in this intensely linked network of Web sites.


Chapter 6: Organizing a Weblog

In This Chapter

  • Publishing weblog files

  • Editing entries

  • Finding an entry quickly

  • Creating entry categories

  • Moving entries to a new category

  • Using power edit mode

Movable Type’s browser-based interface is deceptively simple. Without as much as a glance at documentation, you probably began writing entries, publishing your site, and weblogging like a pro (believe it or not, there are professional webloggers).

You might have even created some categories, chosen your preferred format for weblog archives, and tried the power editing form—one of my favorite features of the software.

Knowing these aspects of Movable Type well enough to use them takes a little hands-on experimentation.

Knowing how to use them well takes some knowledge of what the software is doing behind the scenes.

In this chapter, you learn how the software creates Web pages and other files through a process called rebuilding the site. You also begin to use archives to organize your weblog content, create categories that track the subjects that you cover most often, and use the entry-editing and power edit forms to make changes.


Publishing a Weblog

Although Movable Type stores weblog entries and other content in a database, the software does not generate your Web pages dynamically in response to browser requests. With limited exceptions, the software uses the data to create static Web pages, a process called rebuilding the site.

By publishing Web pages statically, Movable Type lets your Web server handle the work of taking user requests and serving files. This approach works well on servers where a more dynamic content-management system would be too resource intensive or slow.

As you create weblog entries and work on your site, the software will rebuild some pages as needed. Each time you write a new entry, for example, Movable Type rebuilds several files:

  • The main pages of the site, such as the home page

  • The pages that hold an archived copy of the entry

  • Syndication files in RSS and Atom formats

This process occurs automatically. Although there’s a Rebuild Site button in the sidebar menu of the main browser interface, it isn’t required just to bring a new entry online so that your audience can read it.

When a change prompts an immediate rebuild, Movable Type displays a status message in a yellow box alerting you to this fact. You can see one, absent the yellow part, in Figure 6-1.

Click To expand
Figure 6-1: Observing Movable Type as it rebuilds pages.

You do not need to rebuild the site yourself after writing a new weblog entry or making edits to an existing one. Once you click the Save button, committing the entry to the database, Movable Type rebuilds the affected parts of the site.

In addition, when you receive feedback from your visitors in the form of comments or trackback pings, the pages receiving the feedback are rebuilt automatically.

When the software requires you to rebuild pages, you will see a different yellow status message containing a Rebuild button (see Figure 6-2).

Click To expand
Figure 6-2: Noting the need for a site rebuild.

The status message in Figure 6-2 was delivered in response to a change to the weblog’s configuration settings.

When you see that your weblog needs to be rebuilt, or you want to make sure that all content has been brought up-to-date, click a Rebuild button like the one shown in Figure 6-2 or the Rebuild Site sidebar menu button.

A pop-up window opens, asking which parts of the site should be rebuilt, as indicated in Figure 6-3.

Click To expand
Figure 6-3: Rebuilding a weblog.

You can rebuild the entire site and the archive sections that are in effect for the site (probably individual and monthly archives if you’re just starting out).

You also can limit a rebuild to a group of files called the indexes:

  • index.html, the home page

  • archives.html, a page linking to site archive pages

  • styles-site.css, a cascading style sheet used throughout the site

  • Syndication feeds in the XML formats RSS 1.0, RSS 2.0, and Atom

  • rsd.xml, an XML file that helps weblog editing tools discover how they can connect to Movable Type

Like a directory index, the index pages of a Movable Type site serve as a guide to the contents of the site. They’re the primary entry points through which visitors will use a weblog.

You can speed a rebuild process by limiting it to indexes only, but some content of your site might be out of sync with these pages.

On a new weblog with a small number of entries, rebuilding the entire site takes place quickly, so it’s easy to get into the habit of choosing this option every time. As the site grows and you add entries, new archive types, and other features, you might find that a full rebuild takes several minutes, or even longer.

New Feature

Movable Type 3.0 improves the software’s rebuilding process, publishing more parts of a Web site automatically in response to changes. You can save a lot of time working on your weblogs merely by knowing when you don’t need to rebuild anything.

When you publish a new entry or save an existing entry after making a change, Movable Type rebuilds the index and archive pages on its own. It isn’t necessary to rebuild after a visitor posts a new comment.

In general, you only need to rebuild when Movable Type tells you that it’s necessary (see Figure 6-3). Even then, you can wait until you want the site to reflect the changes that you’ve made to templates or the weblog configuration.


Editing Weblog Entries

The entries that comprise a weblog can be edited and deleted from the List & Edit Entries page, available with a click of the Edit Entries button on the sidebar menu.

This page displays the 20 most recent entries. You can use a pull-down menu below the list of entries to view 5, 75, 125, or even all of a weblog’s entries on a single page. Make your selection and click the adjacent Next button to reload the page.

To narrow the display of entries to more quickly find something, you can filter the entries on the form, displaying the entries that match a specified author, category, or publication status:

  1. Using the Filter Options at the top of the form, in the first drop-down menu, choose Category, Author, or Post Status. The adjacent drop-down menu changes to contain the possible values associated with that choice (as shown in Figure 6-4).

    Click To expand
    Figure 6-4: Using the entry filter.

  2. In the drop-down menu, choose a value for the filter.

  3. Click the Go button.

The form is then reloaded to display only the entries matching the filtering criteria you have chosen.

Click the title of an entry to load it in the editing form. The form looks like the same entry-editing page used to draft a new entry, but it has several additional features worth noting:

  • An Assign Multiple Categories link that can be used to pick more than one category for a single entry

  • Sections to view, edit, and delete visitor comments and trackback pings received for the entry

  • A Notification feature that enables a mailing to be sent to people who want to receive e-mail when you add new content to your site

You can modify any aspect of the entry, including the time and date of its publication in the Authored On text field. If you change this value, the entry will move accordingly on the list of entries, which always is presented in reverse chronological order.

The Save button stores your changes and the Delete Entry button removes the entry. You also can delete an entry while viewing the list of entries—enable its Delete checkbox, and then click the Delete button at the bottom of the list.

When you delete an entry, you must rebuild the site to remove it from archive pages and the home page.

Gotcha

Deleting an entry does not affect its individual archive page. The page will remain online, even though it disappears from all other indexes and archive pages. This can be a big gotcha, because the page might still be found and viewed by people using search engines such as Google (or by loading the page from a link or bookmark). The only way to remove the content from the individual page archive is to edit it, changing the Entry Body and other fields that you want to remove from publication.


Saving Archives of Weblog Entries

A new Movable Type weblog begins with two kinds of archives: individual archive pages for each entry and monthly archives holding all of the entries for that period in reverse chronological order.

An archive page is created for each entry in the weblog using a directory hierarchy named for the year and month it was written. The page itself has a name based on the entry’s title.

Here’s an example: An entry published on June 9, 2004, with the title “JetBlue Offers Discount Flights to Orlando” was stored in the 2004/06/jetblue_offers_1.html directory inside the weblog’s local archive path.

On my server, the archive path for Orlando Vacationer is /var/www/orlandovacationer.com/html/archives, so this entry was saved in /var/www/orlandovacationer.com/html/archives/2004/06/jetblue_offers_1.html.

Naming pages based on entry titles boosts their position in search engines and provides more descriptive information in links leading to the page.

Caution

Prior to Movable Type 3.0, individual archives were stored in the local archive path and named for the entry’s ID number (005329.html for entry 5329, 005330.html for entry 5330, and so on). If you’ve upgraded the software and want to keep this naming method for archives so that links to those pages will continue to work, check your weblog configuration and make sure that the Use Old-Style Archive Links setting, part of the Preferences form, has been enabled. Movable Type should have taken care of this automatically when you upgraded the software.

One of the first decisions you should make regarding archives is your weblog’s preferred archive type. This decision determines the archive pages that are used in each entry’s permanent link, the URL where the entry can be found.

The most common choice for a preferred archive type is the individual archive, which presents the entry text followed by comments and trackback pings (if those features are supported).

A new weblog makes use of individual archive pages by preference. You can change this in your configuration settings:

  1. Click the Weblog Config sidebar menu button. The Core Setup page loads.

  2. Click the Preferences link to open the page of the same name.

  3. Click the Archiving Preferences link to skip right to that section of the page.

  4. Choose a Preferred Archive Type from the drop-down menu. The options will be the archives currently supported on your site.

  5. Click Save Changes at the bottom of the form.

You should rebuild the site after making this change to see it reflected on the weblog.

Cross-Reference

In addition to individual and monthly archives, a weblog also can offer daily, weekly, and category archives, as you will see when you begin working with archive templates in Chapter 9, “Designing a Weblog with Templates.”

The number of archives offered by a weblog determines how quickly it can be rebuilt. A site with all five archives in use takes considerably longer to be republished each time you write a new entry or make changes to an existing entry.


Categorizing a Weblog

Weblog entries in Movable Type can be assigned to one or more user-created categories, making it possible to present category-specific archives, pages, and files.

Using categories, which have their own descriptions and archive pages, you can divide a site into separate sections. Category entries can be presented on a separate page, as in the case of an archive, or incorporated into other pages. This functionality isn’t limited to Web pages: You can create a syndication feed in RSS or Atom format that only includes entries from a specific category.

One common use of categories is to create a distinct section that’s separate from the main weblog. For example, a category can hold the content for a sidebar that contains links, announcements related to the site, and other content subsidiary to the site as a whole. Another possibility is to devote a category to a regularly maintained reading list linking to books.

Cross-Reference

There’s also an application for categories that’s less common: They can be set up as a holding place for trackback pings received from other sites, a feature of the software that Six Apart calls a content aggregator. You can read about it in Chapter 11, “Sharing Trackback Links.”

Categories can be added and deleted at any time as a weblog’s focus changes or you get a better handle on how you want to organize your entries. When you delete a category, each of its entries remains in the weblog but is assigned no category.

To help you cope with category changes to existing entries and other cumbersome editing tasks, Movable Type has a power edit mode that makes it possible to edit 20 or more entries on a single form.

Creating a New Category

The easiest way to work with categories is to create them in advance.

There’s no limit on the number of categories a weblog can contain, although you might find it difficult to work with more than a few dozen—a pull-down menu is used to assign an entry to a category, so you will be scrolling through all categories to select the one that you want.

A newly created category must have a name and can be given a description that serves the same purpose as a weblog’s description.

To create new categories, follow these steps:

  1. Click the Categories button in the sidebar menu. The Categories page displays five empty text fields (see Figure 6-5).

    Click To expand
    Figure 6-5: Creating new entry categories.

  2. Type the names for new categories in these fields, and then click Save. The page reloads with the categories you entered above five more empty fields, in case you need to create more.

  3. You can add a description by editing a category: Click the Category Attributes link next to its name.

  4. Use the Category Description text box to provide a short description or tagline for the category.

  5. Scroll to the bottom of the form, bypassing the trackback functionality, and click the Save button.

Categories appear in the Primary Category drop-down menu on the entry-editing form.

Entries can be assigned a primary category when they are created. Select the category from the Primary Category drop-down menu as you write a new entry, as shown in Figure 6-6.

Click To expand
Figure 6-6: Assigning the primary category to an entry.

Entries also can be assigned additional categories when they are edited:

  1. Click the Entries sidebar menu button. The List & Edit Entries page lists the most recent entries, along with a Next button that can be clicked to view more.

  2. Click the title of the entry to edit. The entry’s data loads in an entry-editing form.

  3. Click the Assign Multiple Categories link below the Primary Category field. A pop-up window appears (see Figure 6-7).

    Click To expand
    Figure 6-7: Assigning additional entry categories.

  4. To add one or more categories, select them in the Categories in Your Weblog list and click the right arrow button, adding the items to the Secondary Categories list.

  5. Click Save to assign the categories and close the window.

    Gotcha

    There’s no way to assign more than one category to an entry as it is being created—the Assign Multiple Categories link only appears when an existing entry is being edited. Although the entry-editing form can be customized, there’s no way to add this link to the form for new entries.

Using Power Edit Mode

Unless you’re extremely well organized, it’s highly likely that you will be adding and removing categories on your weblog over time. Weblogs are always a work in progress—as you practice the craft and get a better idea of your own goals and those of your audience, you’ll find categories that fall into disuse and new categories you want to add.

Deleting a category causes all of its entries to be assigned to no category at all, the default in Movable Type.

As you add or remove categories, you might want to review your existing entries, changing categories as needed.

Because this process would be cumbersome to undertake by editing individual entries, Movable Type offers power edit mode, a way to work on 20 or more entries within a single Web form (see Figure 6-8).

Click To expand
Figure 6-8: Working on a weblog in power edit mode.

Power edit mode, one of the features of Movable Type that excels over other weblog publishing tools, makes it easy to change your mind about category assignments and other aspects of a weblog’s entries.

To enter this mode, click the Entries button in the sidebar menu, and then click the Open Power-Editing Mode link atop the List & Edit Entries page.

The power edit form displays 20 entries at a time but can be adjusted to display more: Scroll to the bottom of the form, change the value in the Entries drop-down menu, and click the Next button.

You also can filter entries on this form in the same manner that you do on the main entry-editing page: Choose the desired values in the filter pull-down menus atop the form, and then click Go to reload the page according to that criteria.

Use the form’s Category column to choose or change the primary category for entries on the form.

When you’re done making changes, click the Save button below the form.


Summary

As you’re beginning a new weblog with Movable Type, you might decide that the cost-to-benefit ratio of organizing the site with categories and archives is too high. If you’re publishing a site for a broad audience and want to build traffic, these features can be highly beneficial.

The audience for any weblog can be divided into two groups: people who visit regularly through a bookmark or link and newcomers who show up as the result of a Web search.

The first group primarily arrives through the pages and files produced from indexes, the home page, and syndication feed files.

The second group finds your site through search engines such as Google, and you’ll see a lot more of them by using Movable Type’s archival and category capabilities.

These features provide a lot more useful content for first-time visitors from a search engine, packaging your content in ways that provide a better experience. An active weblog spread out over several categories and archive types can grow quickly to hundreds, or even thousands, of pages.


Chapter 7: Publishing Photographs andOther Files

In This Chapter

  • Creating graphics for the World Wide Web

  • Choosing the graphics format to use

  • Working with digital photos

  • Publishing a graphic on a weblog

  • Uploading graphics and other files

  • Displaying graphics in a pop-up window

  • Creating a thumbnail image

  • Changing the maximum file size for file uploads

Because webloggers are by nature a technically astute and wordy bunch, new words are being coined all the time on their frenetic online journals. Some of this jargon describes weblogs that depart from the established format of the medium in some manner.

Some of the most popular weblog jargon describes online journals that emphasize visuals over text.

A photoblog is a weblog that presents photos in weblog entries, either in complement to text or as a complete substitute. Many of these graphics-intensive sites are devoted to photography, pursued as a profession or a hobby, or a particular locale. The publisher of the 17,000-member community weblog MetaFilter, Matt Haughey, also publishes an intriguing photoblog called Ten Years of My Life. On the site, he plans to publish 3,650 of his own digital photos, one picture a day (http://tenyearsofmylife.com).

A moblog is a weblog for photos taken with mobile devices such as cell phones, camera phones, and personal digital assistants. The TextAmerica portal at http://www.textamerica.com hosts hundreds of these sites.

If you belong to the picture-worth-a-thousand-words crowd, you’ve made a good choice in weblogging software. Movable Type simplifies the process of uploading and publishing photos and other files, whether you’re offering a photoblog, moblog, or some other form of multimedia publishing so revolutionary no word yet exists to describe what you’re doing.


Preparing Graphics for the Web

If you want some inspiration on what can be accomplished with the killer combination of Movable Type and a digital camera, Dawn Mikulich publishes the Chicago Uncommon weblog, a visual exploration of the city, with the software at http://chicagouncommon.com. One of its city sections appears in Figure 7-1.

Click To expand
Figure 7-1: Using Movable Type to publish a photoblog.

Movable Type makes it easy to incorporate digital photos and other graphics in your weblog, but it doesn’t offer any guidance on how they should be created or edited for presentation on the World Wide Web.

If you have never published a Web site before you began using Movable Type, you might have some questions about the process. What format should graphics be saved in? How big should the files be? What’s the right way to present a large digital photo?

Before you put graphics on a Web site, you must compose them for presentation in a format and size that can be viewed in each of the popular Web browsers. Visual images can be represented on a computer in dozens of formats, but as a general rule, a Web publisher only needs to be familiar with three: GIF, JPEG, and PNG.

You probably have some of these files on your computer already: Look for files with the extensions .gif, .jpeg, .jpg, or .png.

Most graphics on the World Wide Web are in either Graphics Interchange Format (GIF) or Joint Photographic Experts Group (JPEG) format. A format of more recent vintage that’s beginning to show up more often is Portable Network Graphics (PNG).

Using GIF Graphics

The GIF format holds images containing up to 256 colors, a palette that’s ideal for simple images with lots of solid color such as menu buttons, small graphics (banner ads and icons), and other images that don’t require fine detail.

Digital photos often make poor GIF files because they must be reduced from thousands of colors to a maximum of 256.

GIF files can become prohibitive in size, as far as the Web is concerned, when an image is large, colorful, or complex. Even if a photo has been reduced to 256 colors, it might still be too large for use on the Web. Visitors don’t always stick around when a page loads slowly, especially when they are logged in to the Internet with a 56.6 Kbps or slower dial-up connection. Large graphics are the main cause of slow-loading pages.

The GIF format supports two special effects: animation and transparency.

GIF graphics are animated by displaying a group of GIF images in quick succession. All of the images are stored in a single file that also contains information on how long to display each image, the order in which to display them, and the number of times to loop through the entire sequence. Images can be shown a fixed number of times or can loop continuously.

Animated GIF graphics appear often on the Web as banner ads and other forms of online advertising.

The GIF transparency technique makes a portion of a graphic blend in with the background of a Web page, whether it’s a solid color or a background graphic. In a transparent GIF graphic, one color has been designated as the transparent color. This color appears when the graphic is edited in a touch-up program such as Adobe Photoshop or GIMP, but it isn’t displayed when the graphic appears on a Web page.

Figure 7-2 contains a Web page with two graphics on a striped Web page. These graphics are identical in every respect but one: The graphic on the left has a transparent color, whereas the one on the right does not.

Click To expand
Figure 7-2: Displaying transparent (left) and nontransparent (right) graphics.

In Figure 7-2, the vulture on the right does not have a transparent color, so you see the entire graphic, including a gray square around the drawing. The scavenger on the left has been created with that shade of gray designated as the transparent color, which causes the page’s stripes to be visible around the drawing.

Using JPEG Graphics

The JPEG format holds sophisticated photo-quality graphics that can contain thousands of colors, a great increase over the 256 colors possible with GIF. To reduce file size, making the graphics faster to load over the Internet, JPEG relies on a data-compression technique that compresses files at the expense of image quality.

A JPEG file can be produced by a digital camera, a scanner, or software. The level of compression in the format can be adjusted to hit the desired balance between image size and image quality. A file grows as its color depth and clarity increase.

The use of compression makes JPEG the best choice on the Web for complex images that contain a large number of colors, especially photographs.

There’s one exception: When an image has large areas of a single color, JPEG can be a poor choice because of how compression alters the image. Jagged, wavy lines appear at the edges of any solid blocks of color, making the image appear sloppy and less distinct.

Caution

Never work on JPEG graphics without keeping the original source file. When you save a JPEG, compression reduces the quality of the image. Each successive edit of the file reduces it further. If you decide later that the graphic has been compressed too much, the only way to get a better-quality version is to scrap the graphic and go back to the original.

Using PNG Graphics

The PNG format, introduced as an enhancement to the preceding two formats, can display images with 256 or fewer colors like a GIF (using PNG-8 format) and images with thousands of colors like a JPEG (PNG-24 format). PNG graphics also can support transparency and other visual effects.

Many Web publishers were slow to adopt PNG because early versions of the popular Internet Explorer and Netscape Navigator Web browsers did not include built-in support for the format. The browsers required a plug-in to display PNG graphics.

Today, more than 95 percent of all Web browser users are running browsers that support PNG, including the current versions of Internet Explorer, Mozilla, Netscape Navigator, Opera, and Safari. PNG support is not complete, however—browser developers have been slow to adopt some of its image-manipulation features such as opacity, the capability to make an image semi-transparent.

Selecting the Right Format

As you create your own graphics and make use of others, you need to choose the right format to maximize appearance quality and minimize file size for speedy loading on the World Wide Web.

In general, GIF graphics are the best choice for menu buttons, drawings, line art, and other simple images with a limited number of colors.

JPEG graphics should be employed on digital photos, large complex images, and anything that ought to be displayed using more than 256 colors.

My rule of thumb is to use JPEG on digital photos and either GIF or PNG for everything else. When a GIF graphic would be so complex or large that its file size exceeds 30 KB, you can usually simplify or replace the graphic. You won’t encounter many circumstances in which a GIF needs to exceed that size.


Uploading Photos and Other Files

Movable Type can be used to upload graphics and other files to your weblog, taking advantage of the support for file transfer in Web browsers. There’s no requirement to make files available in this manner—you can use an FTP client instead—but it’s a convenient way to publish files on the Web.

If you’re uploading a graphic so that it can be included in a weblog entry, Movable Type makes this task easier by drafting the HTML formatting required to present the graphic.

Movable Type limits the maximum size of an uploaded file to 1 MB, although you can change this setting by editing the software’s configuration file (as described later in this chapter).

To transfer a file to the server, click the Upload File sidebar menu button. The Choose a File pop-up window opens, as shown in Figure 7-3.

Click To expand
Figure 7-3: Choosing a file to upload.

You can upload any file stored on your computer or local area network. To select the file, click the Browse button. A File Open dialog box particular to your operating system appears. Use this dialog box to find and select the file, and then click the Open button.

The selected file’s path and name appear in the File text field.

The easiest way to upload files is to store them in either the local site path or local archive path.

These options refer to some of your weblog configuration settings, which can be viewed and changed by clicking the Weblog Config menu button. The local site path refers to the directory that holds your weblog’s home page and the other index files. The local archive path contains individual, daily, and monthly archive pages.

To store the uploaded file in one of these two directories, choose its radio button in the Upload Into section and leave the text field next to that option blank.

Movable Type also can store files in subdirectories of the local or archive paths. Choose one of the two paths by selecting its radio button and provide the rest of the subdirectory’s path in the adjacent text field.

When filling out the text field, start with the name of the subdirectory in the local site path or local archive path. Don’t begin with a slash character (/).

For example, my Orlando Vacationer weblog has a local site path of /usr/ web/orlandoVacationer. The site has an images subdirectory which itself holds 2002, 2003, and 2004 subdirectories.

I can upload pictures to the 2004 subdirectory by choosing the local site path radio button and images/2004 in the adjacent text field, as shown in Figure 7-4.

Click To expand
Figure 7-4: Uploading a file to a specified subdirectory.

After choosing a path (and directory, if desired), click the Upload button. Movable Type transfers the file to its destination. This process might take some time, depending on the size of the file and the speed of your connection. Unfortunately, there’s no feedback letting you know that the transfer is taking place or how long it might take. (On Windows, there’s one subtle hint: An hourglass appears on the cursor when the mouse hovers over the Upload button, letting you know not to click it again.)

If the transfer fails, you’ll see an error message such as “The file you uploaded is too large.” Click Go Back to return to the Choose a File window.

If a file matching the same path and name exists on the server, you’ll be asked to confirm that it should be replaced with the new file.

When the transfer completes, a page opens letting you know the size of the uploaded file. This page also makes it possible to do something with the newly uploaded file.

Uploading a Graphic

The appearance of the page depends on the kind of file being transferred. If the file is a graphic, you are asked how to display it (see Figure 7-5).

Click To expand
Figure 7-5: Publishing photos and other graphics.

The Image Thumbnail section appears only if the ImageMagick software and the accompanying Image::Magick Perl module have been installed on the server hosting Movable Type.

Web Site Download

The installation of ImageMagick, a set of image-editing tools and supporting libraries available for download from http://www.imagemagick. org, was one of the options covered in Chapter 2, “Preparing a Web Server for Movable Type.” If you want Movable Type to support image thumbnail creation, download and install the software and it will begin working immediately. No other configuration is necessary.

You can do two things with a graphic:

  • Create a new weblog entry that displays the graphic.

  • View the HTML formatting required to present the graphic on a Web page.

Thumbnails, smaller versions of a graphic suitable for preview purposes, can be created with this pop-up window.

When Movable Type finds this module on the server, it presents an Image Thumbnail section in the Upload File window, as shown in Figure 7-5.

Thumbnails can be created by specifying the height and width of the graphic in one of two ways: by defining the exact pixels or choosing a percentage value from 1 to 99 percent.

To create a thumbnail version of a graphic, follow these steps:

  1. Enable the checkbox Create a Thumbnail for This Image.

  2. If you’re specifying thumbnail size as a percentage, change the two drop-down menus from Pixels to Percent.

  3. If you don’t want the thumbnail to have the same proportions as the original graphic, remove the check mark from the Constrain Proportions checkbox.

  4. Enter a value in the Width or Height text field.

  5. If you have unchecked Constrain Proportions, enter a value in the other text field. (There’s no need to do this if proportions are constrained; Movable Type calculates the other value based on what you entered in Step 4.)

A graphic can be displayed as part of an entry or in its own pop-up window, which a weblog visitor can see by clicking a link. Click the Embedded Image button to make the graphic part of an entry or the Popup Image button to present it in a pop-up.

If you start a new weblog entry for the file, Movable Type’s entry-editing form opens with starting text in the Entry Body field: the XHTML formatting necessary to present the graphic. This is shown in Figure 7-6.

Click To expand
Figure 7-6: Editing an entry containing a graphic.

You can add more text to the entry—taking care not to edit the existing formatting—or leave it as is.

A weblog entry that includes a graphic within its Entry Body field can be edited like any other entry. You can even remove this formatting if you decide not to use the graphic. Movable Type simply provides the XHTML formatting as a convenience.

In order to present a graphic in a pop-up window, Movable Type will create a Web page with the same filename and path as the graphic and the .html file extension. You don’t have to edit this page; Movable Type provides the XHTML formatting required to open the page in its own window.

Uploading Other Kinds of Files

There’s no restriction on the kinds of files that can be uploaded to a Movable Type weblog. You can offer music in formats such as MP3 and WAV, interactive Macromedia Shockwave games and Java applets, and files of any other type that your Web server supports.

When you upload a file that is not a graphic, you’ll be presented with a simpler set of options (see Figure 7-7).

Click To expand
Figure 7-7: Publishing nongraphical files.

Movable Type assumes that you intend to link to the uploaded file, offering two ways to do it:

  • Create a new weblog entry that contains the link.

  • See the HTML required for a link.

Click the Link button to take the desired action.

Changing the Maximum File Size for Uploads

Movable Type’s default configuration rejects uploaded files larger than 1 MB, a limit that’s expansive enough for most Web graphics you might use on a Web site.

You’ll find it much more limiting if you publish audio files and interactive games because they often take up more than 1 MB (and sometimes much more).

The maximum upload size is set by a line in mt.cfg, the Movable Type configuration file:

# CGIMaxUpload 500000

This file, located in Movable Type’s main installation directory, contains a series of settings, blank lines, and documentation for each of the settings.

All blank lines and lines preceded by a pound sign (#) are ignored by Movable Type.

To set the CGIMaxUpload setting, remove the # sign at the start of the line, and then change 500000 to the desired size, in bytes. A 1 MB limit is 1048576, 2 MB is 2097152, and 5 MB is 5242880.

Although you can set this as high as desired, transferring extremely large files tends to be problematic in Web browsers. You might want to keep the limit under 15–20 MB and use other means to transfer larger files.

Gotcha

There’s no way in Movable Type to use the program’s browser interface to delete files, which can become a problem if you’re using a Web host that limits users to a finite amount of disk space. You must use an FTP client or shell access on the Web server to remove files. If you must yank a particular file off the Web and cannot get to the server by FTP or other means, you can use Movable Type’s Upload File feature to transfer another file to the same directory with the same name. Movable Type will delete the old file to make room for the new one.


Summary

Although it pains me to say this, as a writer with absolutely no photographic aptitude, there’s no better way to enliven the appearance of a text-laden weblog than to incorporate photos into the site.

Movable Type’s browser interface makes it easy to upload a graphic and present it in a weblog entry. You can put the photo directly in the entry, aligning it with text, or put it in a pop-up window.

If you have the Image::Magick Perl module and ImageMagick software on your Web server, Movable Type can automatically create a thumbnail image—a smaller version of the graphic—which will be linked to a separate page containing the full image.

Because of Movable Type’s strong support for graphics, some of the best photoblogs are published with the software.


Chapter 8: Producing Web Pages withTemplate Tags

In This Chapter

  • Discovering how templates create files

  • Viewing Movable Type templates

  • Creating a new template

  • Producing output files from a template

  • Using global template tags

  • Formatting dates and times with tag attributes

  • Displaying weblog entries

  • Designing category and archive templates

Most Web publishers create sites in the same manner that they author other documents on a computer: fire up an editor, open a file, and begin typing. Whether this toil takes place in a simple text editor or a sophisticated Web publishing tool such as Microsoft FrontPage or Macromedia Dreamweaver, the fundamental task is to create text and apply formatting to it.

Web publishers who are comfortable creating sites by directly working with HTML, XHTML, and CSS have all the skills they need to develop sites in Movable Type.

Using the software, Web publishers create Web pages and other online files from templates, master documents that combine static text and formatting with dynamic content drawn from a relational database.

Although this sounds much more intimidating than editing a text file, Movable Type simplifies the task by making it look as much like HTML as possible. Dynamic content such as weblog entries and search forms are placed on Web pages using custom template tags that are structured exactly like HTML tags.

If you know how to put an img tag on a Web page and use tag attributes such as src, width, and height, you can author templates in Movable Type.


Creating a Template-Driven Weblog

All content in Movable Type begins as a template, a file used to create other files. A new weblog starts out with 15 templates, which you can examine by clicking the Templates button in the sidebar menu. The Templates page opens, as shown in Figure 8-1.

Click To expand
Figure 8-1: Editing templates in Movable Type.

The main templates in a weblog are index templates, which create files in the main directory of a weblog. You can refer to each template by a descriptive name or the output file that it produces, both of which are shown in Figure 8-1.

A newly created Movable Type weblog begins with seven index templates:

  • The Main Index template (index.html), which is the site’s home page

  • The Master Archive Index (archives.html), a Web page containing a full list of weblog entries

  • The Stylesheet (styles-site.css), a cascading style sheet formatting file used by the Main and Master Archive templates

  • Three XML syndication files: Atom Index (atom.xml), RSS 1.0 Index (index.rdf), and RSS 2.0 Index (index.xml)

  • An RSD file (rsd.xml), a simple XML file that makes it easier to work on a Movable Type weblog with editing software outside of a Web browser

These template files include three kinds of content: Web pages in XHTML format, a CSS style sheet, and four XML formats. Although a Movable Type weblog consists primarily of Web pages, the software’s templates can produce any text format.

Click a template’s name to view and edit the index template. Because the default templates are pretty sophisticated in their use of XHTML, JavaScript, and CSS, you might find it easier to start by creating an index template from scratch:

  1. Click the Templates button in the sidebar menu. The Templates page opens.

  2. Click the Create New Index Template hyperlink atop the list of index templates. The Edit Template page loads (see Figure 8-2).

    Click To expand
    Figure 8-2: Creating a new index template.

  3. Type a short descriptive name for the template in the Template Name field.

  4. In the Output File field, select a name for the file that ends in .html, one of the file extensions used by HTML Web pages. Don’t choose index.html or archives.html, which already are being used by index templates.

  5. Keep the check mark in the Rebuild This Template Automatically box.

  6. Scroll to the bottom of the form and click the Save button.

This starts off a new index template, which you can finish by filling out the Template Body text box and clicking the Save button at the bottom of the form.

A Movable Type template consists of two kinds of content:

  • Static text and markup formatting that goes into a file without modification.

  • Dynamic content produced by Movable Type template tags.

With your newly created template open for editing, enter the text in Listing 8-1 into the Template Body box.

Listing 8-1: A Simple Index Template
Start example
<html>

<head>
<title><MTBlogName> View</title>
</head>

<body>
<h1><MTBlogName></h1>

<MTEntries lastn="7">
<h2><a href="<MTEntryLink>"><MTEntryTitle></a></h2>

<p><MTEntryBody>

<p align="right"><MTEntryDate></p>
</MTEntries>

</body>
</html>
End example

After you’re done, click the Save button below the text box. The page reloads with a suggestion to rebuild your site and view the changes you’ve made. Click the Rebuild This Template button, and then click Rebuild on the confirmation pop-up window to rebuild your entire site.

The Movable Type template tags in Listing 8-1 look like HTML tags and begin with the letters MT (for example, MTBlogName). When Movable Type builds a file from a template, these tags will be replaced with output produced by the tag. The tag <MTBlogName> is replaced with the weblog’s name in both places the tag appears in the template.

Everything else is static text that will appear in the output file exactly as it appears in the listing. Figure 8-3 shows a page produced from this template. In the figure, template tags used to produce different sections of the page are identified.

Click To expand
Figure 8-3: Viewing a template-created Web page.

For the rest of this chapter, you’ll learn about dozens of Movable Type template tags and how to use them in index templates of your own creation.

In the next chapter, you put these tags to work on more kinds of templates, including category and date-based archive templates.


Working with Movable Type Tags

Movable Type templates deliver dynamic content through the use of template tags, which are special markup tags that look and function like HTML tags. When the software creates a file from a template during a weblog rebuild, template tags are replaced with output produced by that tag.

All template tags are distinguished from other tags by a name that begins with MT, such as MTBlogURL and MTBlogName. They can be used inside other tags, as in the following HTML example:

<a href=”<MTBlogURL>”><MTBlogName></a>

The preceding line can be used in a Web page template. When the page is rebuilt, the Movable Type tags are replaced with output, producing HTML of the following form:

<a href=”http://orlandovacationer.com/”>Orlando
Vacationer</a>

Like HTML tags, template tags can contain attributes in name=”value” pairs, as in this example:

<MTBlogName><br>
<MTBlogDescription remove_html=”1”>

The MTBlogDescription tag displays the weblog’s description, one of the settings in a weblog’s configuration. Using a remove_html attribute with a value of 1 causes any HTML formatting in the description to be omitted in the tag’s output.

There are two kinds of template tags: containers and simple tags.

Simple tags, such as the ones you’ve seen up to this point, produce output of some kind.

Container tags hold simple tags and static text, producing output in a manner similar to a template. They have an opening tag and a closing tag that represent the boundaries of the container, as shown in the following example:

<ul>
<MTEntries lastn=”7”>
    <li><MTEntryTitle></li>
</MTEntries>
</ul>

The MTEntries container tag serves the purpose of presenting multiple weblog entries one at a time. Everything inside the opening and closing MTEntries tags is displayed once for each entry. The number of entries can be established in several ways. One is to use the lastn attribute to specify the number of recent entries to present.

Within this container, numerous simple tags can be used to display different elements of a weblog entry: MTEntryTitle for the title, MTEntryBody for the body, MTEntryAuthor for the author, and more.

The preceding code produces HTML output listing the titles of the seven most recent weblog entries, which are shown here:

<ul>
    <li>FantasyLand to add 3-D movie attraction</li>
    <li>Disney pulls Janet’s Mickey statue</li>
    <li>Killer whale born at SeaWorld Orlando</li>
    <li>Disney cuts pass program for disabled</li>
    <li>Guests question Disney’s no-Segway policy</li>
    <li>Dining in Orlando’s Rainforest Cafes</li>
    <li>Disney World’s Animal resort is a zoo</li>
</ul>

Because the <ul> and </ul> tags are outside of the MTEntries container, they appear only once in the output. The <li><MTEntryTitle></li> line inside the container is repeated seven times, once for each weblog entry.

You can also use a container tag to produce output only when a specific condition is met:

<MTEntryIfAllowComments>
  <a href=”/cgi-bin/mt-
comments.cgi?entry_id=<MTEntryID>”>Post a
comment</a>
</MTEntryIfAllowComments>

When presenting data for a specific weblog entry, the MTEntryIfAllowComments container tag takes one of two actions:

  • If the entry allows comments, the contents of the container are displayed.

  • If the entry disallows comments, the contents are ignored.

If you’re a programmer, you should be familiar with the functionality of these containers, because they serve the same purpose as two common programming constructs: loops and conditional statements.

You’ll work with these containers more in the rest of this chapter.

Displaying Text Produced by a Tag

Most simple Movable Type tags produce text. Because templates can generate files in so many formats—HTML, XHTML, CSS, RSS, XML and more—you can use more than a dozen attributes to manipulate the format of text produced by a tag.

These global attributes, as they are called, are listed in Table 8-1. Almost all of the attributes take Boolean values that must be equal to 1 (true) in order for tag output to be converted. There’s no reason to include them in a tag with a value of 0, because that causes no text conversion to take place, which is accomplished by omitting the attribute.

Table 8-1: Global Tag Attributes
Attribute | Value | Description | Example Text | Output
decode_html | boolean | Decode HTML entities to characters (when equal to 1) | &lt;hr&gt; | <hr>
decode_xml | boolean | Decode XML entities to characters (1) | A &amp; P | A & P
dirify | boolean | Convert text to a form suitable for use as a directory name (1) | Park News! | park_news
encode_html | boolean | Encode text so that HTML tags can be displayed as text (1) | <hr> | &lt;hr&gt;
encode_js | boolean | Encode text for use as a string value in a JavaScript statement (1) | “Eat at Joe’s” | \”Eat at Joe\’s\”
encode_php | Text | Encode text on a PHP Web page so that it can be used in single quotes (the value “q”), double quotes (the value “qq”), or in “<<<” heredoc syntax (the value “heredoc”) | “Eat at Joe’s” (with a value of q) | “Eat at Joe\’s”
encode_url | boolean | Encode text to a form suitable for use in a URL (1) | Java code | Java%20code
encode_xml | boolean | Encode text so that it can be used in XML data (1) | A & P | A &amp;
filters | Text | Apply one or more text-formatting filters to the text, which are specified as a list of filter names separated by commas | April (with a value of “__default__”) | <p>April</p>
lower_case | boolean | Convert all letters in the text to lowercase (1) | Castle Rock | Castle rock
remove_html | boolean | Remove all HTML tags from the text (1) | <b>Home</b> | Home
sanitize | Text | Run the sanitize filter on HTML tags using the default settings(a value of “1”) or by removing any tag that isn’t in a comma-separated list specified as the attribute value(for example, “a href, b, i”) | <b><i>Exit </I></b> (with a value of “a href b”) | <b>Exit</b>
space_pad | integer | Precede the text with spaces to make it the specified number of characters | XY (with a value of 4) | Two spaces followed by XY
sprintf | Text | Display the text using the specified sprintf format string | 13.829 (with a value of“%.2f”) | 13.83
trim_to | integer | Shorten the text to the specified number of characters | swordfish (with a value of 5) | sword
upper_case | boolean | Convert all letters in the text to uppercase (1) | Parker | PARKER
zero_pad | integer | Precede the text with zeroes to make it the specified number of characters | 13 (with a value of 6) | 000013

The attributes to use in a tag depend on what you’re trying to achieve with the output.

Four attributes, decode_html, encode_html, remove_html, and sanitize, manipulate text that can be interpreted as HTML.

The remove_html attribute strips all HTML formatting tags out of text before displaying it, whereas the sanitize attribute removes HTML more selectively.

As described in Chapter 10, “Offering Comments,” Movable Type can sanitize visitor comments as a security measure, removing any HTML tags that aren’t allowed to be used in the text. The default setting removes all tags other than b, blockquote, br, em, li, p, strong, ul, and a with the href attribute. All other tags and tag attributes are stripped by the sanitize filter.

You can apply the same filter to a template tag by using a sanitize attribute, which has a value listing the permissible HTML tags. Be sure to separate tags with commas—for example, here’s how to present a weblog entry body (the MTEntryBody) that allows only line breaks, italics, and paragraph breaks:

<MTEntryBody sanitize=”br, i, p”>

The decode_html and encode_html tags determine how to deal with two unusual circumstances:

  • A tag contains HTML, but you want to display its HTML tags rather than use them to format the text.

  • A tag contains text that could be displayed as HTML, if it were in the proper form.

The string “<i>Eureka</i>” contains HTML formatting tags. If a tag containing this text were displayed on a page, Eureka would appear in italicized type. If you want to display the actual string, you can use the encode_html attribute. It converts the < and > characters to the HTML entity codes &lt; (less than) and &gt; (greater than), causing them to be displayed on a Web page. This changes the text to “&lt;i&gt;Eureka&lt;/i&gt;”, which is displayed in a template-rendered file as “<i>Eureka</i>”.

The decode_html attribute achieves the opposite transformation, converting text containing &lt; and &gt; entities back to “<” and “>”, making it possible to use the text as HTML. For instance, a tag holding “&lt;i&gt;Eureka&lt;/ i&gt;” can have a decode_html attribute of 1 to produce the output “<i>Eureka</i>”, which displays as the italicized word “Eureka.”

These two attributes are most applicable when you’re working with HTML data that has been stored in an XML file (such as an RSS newsfeed). A lot of weblog editing tools store HTML in XML files by encoding it. You’re expected to decode it before displaying the text.

The decode_xml and encode_xml attributes achieve a similar decoding and encoding conversion. An encode_xml attribute converts three characters, <, >, and &, to the entity codes &lt;, &gt; and &amp;, whereas decode_xml does the opposite.

These attributes also become handy when using a template to create an XML file. When necessary, the encode_xml attribute also causes text to be surrounded by “ <![CDATA[“ and “]]>”, which indicates that it contains XML character data.

Two other attributes make it possible to use text in the names of files and directories or in a Web address: dirify and encode_url.

The dirify attribute transforms text into a form that’s suitable as a file or directory name. Four things happen: HTML tags and entity codes are stripped, text becomes lowercase, spaces are converted to underscore characters (_), and anything that isn’t a letter, number, or underscore is removed.

The encode_url attribute achieves a similar transformation, making text suitable for use as a Web address (URL). All characters that are not letters or numbers are converted to hexadecimal character codes—for example, a space becomes %20.

The last two text-encoding attributes, encode_js and encode_php, prepare text to be used in two programming languages: JavaScript and PHP. If you’re using template tags to create code in these languages, the attributes must be used to avoid syntax errors that prevent the code from functioning correctly.

The encode_js attribute ensures that a tag’s text can be used as a string literal in JavaScript, putting a backslash character (\) in front of single quotes and double quotes.

Gotcha

In version 3 of Movable Type, the encode_js attribute doesn’t encode backslash characters properly, which might cause JavaScript code to perform incorrectly when tag output includes a single backslash. As a workaround, change the backslash to \\, which is the proper encoding for a backslash character when used as a string value in JavaScript code.

The encode_php attribute prepares text for use in three ways in PHP code, depending on the attribute’s value. On servers that support PHP, the language will be executed by the server when the page is requested, producing HTML output sent to a Web browser in response to the request.

When using encode_php, use the value “q” if the text appears inside single-quotes in a PHP statement, “qq” if it appears in double quotes, and “heredoc” for text output that makes use of the <<< operator, as in this short example:

ECHO <<<END
<p>Welcome back, <MTBlogAuthor encode_php=”heredoc”>!
<p>Your last login was at $connectedDate.
END;

The remaining global attributes perform more general text conversions. The upper_case and lower_case attributes perform as you would expect, changing letters to the desired case. The space_pad and zero_pad attributes use space characters and zeroes, respectively, to make text the desired length. The padding character appears at the start of the text—for example, if a tag produces the output “1970” and zero_pad is used with a value of 7, the resulting text is “0001970.” Use “1970” with a zero_pad of 4 and “1970” is the output. The trim_to attribute limits tag output to a maximum number of characters, set by the attribute’s value, omitting the rest.

The filters attribute applies one or more text-processing filters to tag output. Specify the name of the filters to use in a list separated with commas.

The last global attribute, sprintf, applies formatting rules to output that make use of sprintf, a popular syntax for displaying numbers that takes its name from an indispensable function in C, PHP, and other languages.

The sprintf attribute formats integer and decimal-point numbers with the desired width, decimal places, and padding characters. A short code specifies the output format.

The full syntax of sprintf duplicates some of the functionality you can achieve with the space_pad and zero_pad attributes. For situations where it’s most useful in a Movable Type template, here are some handy sprintf format codes:

  • %02d: A two-digit integer padded with a 0 if necessary (examples: 02, 10)

  • %04d: A four-digit integer padded with 0s (such as 0001, 0025, and 0305)

  • %01.2f: A floating-point number with two decimal places (4.13, 14.56)

  • %08.3f: A floating-point number with three decimal places that will be eight digits long, including the decimal point (9025.750)

  • %x: A hexadecimal number with lowercase letters (64, fa0)

  • %X: A hexadecimal number with uppercase letters (32, FAC)

Formatting Date and Time Tags

Movable Type includes eight template tags that represent timestamps, including MTEntryDate to present the date and time an entry was first saved, and MTEntryModifiedDate for its most recent revision.

When used without an attribute, date tags produce dates that are structured as follows:

April 28, 2004 02:04 PM
April 26, 2004 09:39 AM
February 7, 2004 08:04 AM

Each of these timestamps consists of a month name, day of month, four-digit year, two-digit hour, two-digit minute, and AM or PM. All of these elements can be rearranged, omitted, or formatted differently using an strftime formatting string.

An strftime string specifies the order and structure of timestamp elements using a series of short codes that begin with the % character. The name comes from a popular command-line tool and programming language function that serves the same purpose.

A date tag’s format attribute transforms the output by the rules of strftime, as shown in the following example:

<MTEntryDate format=”%a, %d %b %Y %H:%M:%S”>

Date formatting changes the appearance of a timestamp without changing any of its values. Following are the same three dates with the new formatting applied to them:

Wed, 28 Apr 2004 14:04:04
Mon, 26 Apr 2004 09:39:51
Sat, 07 Feb 2004 08:04:48

Table 8-2 contains the strftime codes supported by Movable Type (other software might offer different codes—implementations of strftime vary).

Table 8-2: Date Format Attribute Strftime Codes
Code | Description | Example Output for April 30, 2004 04:03 PM
%a | An abbreviated weekday name | Fri
%A | A weekday name | Friday
%b | An abbreviated month name | Apr
%B | A month name | April
%d | A two-digit, zero-padded day of the month from 01 to 31 | 30
%e | A two-digit, space-padded day of the month | 30
%H | A two-digit, military-time hour time from 01 to 23 | 16
%I | A two-digit, zero-padded hour from 01 to 12 | 04
%j | A three-digit day of the year from 001 to 366 | 121
%k | A two-digit, military-time, space-padded hour from 1 to 23 | 16
%l | A two-digit space-padded hour from 1 to 12 | 4
%m | A two-digit, zero-padded month from 01 to 12 | 04
%M | A two-digit, zero padded minute from 00 to 59 | 03
%p | The time period (AM or PM for English-language weblogs) | PM
%S | A two-digit, zero-padded second from 00 to 59 | 03
%x | A complete date | April 30, 2004
%X | A complete time | 04:03 PM
%y | A two-digit, zero-padded year from 00 to 99 | 04
%Y | A four-digit, zero-padded year | 2004

Movable Type’s default format for timestamps is %B %e, %Y %I:%M %p. Some strftime codes that you might recall from other environments are not supported; most notably, the %Z code, which displays a time zone code or numeric offset.

A time zone offset can be included in a date with the MTBlogTimezone tag, which displays the numeric offset from UTC time as a value from -12:00 to +13:00.

The names of months, days, and time periods AM and PM are dependent on a weblog’s Date Display language setting. As a reader of this book, you’re presumably using English, but you can change to another language easily: Click the Weblog Config sidebar menu button to open the Configuration page, click the Preferences link atop the page, and then scroll to the Language for Date Display drop-down menu.

There’s also a language attribute on date tags that overrides a weblog’s chosen language. Codes that can be used as values are shown in Table 8-3.

Table 8-3: Date Language Attribute Values
Value | Language
cz | Czech
de | German
dk | Danish
en | English
es | Spanish
fi | Suomi
fr | French
is | Icelandic
it | Italian
jp | Japanese
nl | Dutch
no | Norwegian
pl | Polish
pt | Portuguese
se | Swedish
si | Slovenian
sk | Slovak

The dates produced by the %x and %X codes also are based on the designated language.

Using Global Tags

As you work with simple template tags, the most important thing to note is where they can be used. Some tags work inside a specific container tag, and others work in a container and on individual archive pages. The easiest to use are global tags, which can be used on any template at any position in the file.

More than a dozen useful global tags are listed in Table 8-4.

Table 8-4: Global Template Tags
Tag | Description
MTBlogArchiveURL | The address (URL) of the weblog’s archives section
MTBlogCCLicenseRDF | RDF data describing the weblog’s Creative Commons license
MTBlogCCLicenseURL | The address (URL) of a Web page describing the site’s Creative Commons license
MTBlogCommentCount | The number of comments the weblog has received
MTBlogDescription | The weblog’s description
MTBlogEntryCount | The number of entries in the weblog
MTBlogHost | The host name (and possibly port number) of the server hosting the weblog
MTBlogID | The username of the entry author
MTBlogName | The e-mail address of the author, which can be disguised by setting spam_protect equal to 1
MTBlogRelativeURL | The relative address (URL) of the weblog (the portion of its home page address that does not include the host name)
MTBlogSitePath | The folder on the Web server where the site’s home page is stored
MTBlogURL | The address (URL) of the weblog’s home page
MTCGIPath | The relative address (URL) of the folder where Movable Type’s CGI scripts are stored
MTCommentScript | The name of Movable Type’s comment script
MTPublishCharset | The character set used by Movable Type
MTStaticWebPath | The server folder in which Movable Type’s static files are stored
MTTrackbackScript | The name of Movable Type’s trackback script
MTVersion | A hyperlink associated with the author, which can be associated with a home page or e-mail link

The global tags in Table 8-4 deliver information about the weblog and Movable Type installation on which it runs.

The MTBlogID, MTBlogName, and MTBlogDescription tags provide the basics. You can change the name and description by editing your weblog configuration.

Several tags offer Web addresses for the site. The MTBlogURL and MTBlogArchiveURL tags identify the weblog’s home page and the base URL of all archive pages, respectively. These addresses are called the Site URL and Archive URL in the weblog’s configuration settings.

When set up correctly, they are full Web addresses that end with a trailing slash and do not include filenames (such as index.html). Keep this in mind as you use them to create URLs in a template, as shown in the following example:

<a href=”<MTBlogURL>bio.html”>Biography</a>

On a weblog with the Site URL http://orlandovacationer.com/, this example links to http://orlandovacationer.com/bio.html. The following template code would not work correctly because of the slash after the tag:

<a href=”<MTBlogURL>/bio.html”>Biography</a>

The MTBlogHost and MTBlogRelativeURL tags break up a Site URL into its two constituent parts: the server hosting the site and the directory (or directories) in the rest of the URL. The Site URL http://orlandovacationer.com/ has the host orlandovacationer.com and the relative URL / (a single slash character). A weblog at http://example.com/weblog would have an example.com host and /weblog relative address.

Seven global tags provide information about your Movable Type installation. The MTVersion tag displays the version number and the MTPublishCharset tag identifies the character set used by Movable Type on Web pages and other text files.

The character set is ISO-8859-1 on weblogs for which English has been designated as the preferred language. This set, also called the Latin-1 character set, defines 191 characters from the Latin alphabet. These characters can be used to communicate in English, Dutch, German, Portuguese, Spanish, and a dozen other languages.

The MTBlogSitePath tag indicates the directory on the Web server where a weblog’s home page and other index template-produced pages are stored, a setting called the Local Site Path in the weblog configuration.

The location of the files used by Movable Type’s browser interface can be incorporated into a template with the MTStaticWebPath tag. This tag, which is defined in the mt.cfg configuration file, can be a relative URL (such as /static) or a complete Web address (such as http://example.com/static).

The MTCGIPath tag provides a full or relative URL that indicates where Movable Type’s CGI scripts can be accessed from a Web browser. By combining this with the MTCommentScript and MTTrackbackScript tags that produce the names of these scripts, you can refer to Movable Type’s comment and trackback scripts in a flexible way.

This becomes important if you need to move Movable Type’s scripts or decide to rename the scripts, which can help reduce the amount of abuse they receive from spammers and others who flood a site with ads and other undesired responses.

Like many of the other global tags, these tags take their values from the mt.cfg configuration file in Movable Type’s installation directory. By default, these scripts are named mt-comments.cgi and mt.tb-cgi, respectively.

The following HTML code creates a form that is processed by Movable Type’s comment script:

<form action=”<MTCGIPath><MTCommentScript>”>
</form>

Three tags provide template support for Creative Commons licenses, the system of copyright sharing described in Chapter 4, “Configuring a Weblog.”

The MTBlogCCLicenseRDF tag contains RDF data specifying the Creative Commons license that applies to a weblog. This data, which uses the same XML format employed for trackback pings, can be hidden in the source code of the weblog home page and individual entry pages. Some weblog publishing tools read this data to determine whether weblog content can be republished elsewhere.

This tag should be used within the header section of an HTML or XHTML page (between the opening and closing head tags). An MTBlogCCLicenseRDF tag also can be used in the template for individual weblog entries, where it will contain information about the reuse of each particular entry.

For a public means of indicating a site’s licensing, employ the MTBlogCCLicenseURL tag, which contains the URL of a page on the Creative Commons Web site that describes your weblog’s particular license.

By design, a new weblog created with Movable Type does not offer a Creative Commons license—a publisher shouldn’t enter into an expansive licensing agreement without understanding the copyright implications.

The MTBlogIfCCLicense container tag makes it possible to present Creative Commons RDF data only when one of the licenses has been applied to a weblog:

<MTBlogIfCCLicense>
  <MTCCLicenseRDF>
</MTBlogIfCCLicense>

Another container that can be used with global tags is MTBlogs, a container that holds all weblogs offered on your Movable Type server. One use for the tag is to present a list of links to each site:

<p><MTBlogs>
<a href=”<MTBlogURL>”><MTBlogName></a><br>
</MTBlogs>

All weblogs on a Movable Type installation are included in this container, even if the person editing the template has no access to some of them.

Using Entry Tags

Weblog entries can be presented on a template inside an MTEntries tag, a container that represents entries retrieved from the database in a variety of ways. You also can work with entry tags on an individual entry template, which requires no MTEntries container.

MTEntries holds entries retrieved by date, category, author, and recently published visitor comments. Table 8-5 presents the attributes.

Table 8-5: MTEntries Tag Attributes
Attribute | Value | Description
Author | Text | Limit retrieved entries to the specified author
Category | Text | Limit retrieved entries to the specified category or categories
Days | Integer | Retrieve entries published within the specified number of days
Lastn | Integer | Retrieve the specified number of entries, beginning with the most recent and going backward
Offset | Integer | Start a lastn retrieval with earlier entries, counting backward the specified number of entries first
recently_commented_on | Integer | Retrieve the specified number of entries that have received recent comments, organized by date and time of the last comment
sort_by | Text | Sort entries by the specified entry field, which can be author_id, excerpt, modified_on, status, or title
sort_order | Text | Set the sort order of retrieved entries, which can be either ascend or descend (the default)

The MTEntries container often requires more than one attribute—an attribute that dictates the way to retrieve entries and one or more attributes that narrow the chosen entries or sort them in a new order.

Three MTEntries tag attributes specify the manner in which entries should be retrieved:

  • lastn collects X number of recent entries

  • days grabs all entries from the last X days

  • recently_commented_on collects X number of entries with recent comments

The value X refers to the attribute’s value. You can use
lastn=”5” to retrieve the last five weblog entries,
days=”7” for entries published the preceding week, and
recently_commented_on=”10” for the last 10 entries that received
visitor comments.

You can use the offset attribute to make lastn look further in the past. The offset value moves the starting place X entries backward. Therefore, on a weblog with 100 entries, an attribute of lastn=”3” pulls entries 100, 99, and 98; attributes of lastn=”3” offset=”3” pull entries 97, 96, and 95; and attributes of lastn=”3” offset=”6” pull entries 94, 93, and 92.

Note

Although you can place all the MTEntries attributes in a tag, in many cases some attributes will be ignored because they don’t work together. For instance, the days attribute cannot be used with lastn, category, or author. In addition, you can use offset to modify the performance of the lastn attribute only. It doesn’t work with recently_commented_on.

The following HTML code displays the title of all weblog entries published during the last three days:

<p>Recent Entries:</p>
<ul>
<MTEntries days=”3”>
<li><MTEntryTitle></li>
</MTEntries>
</ul>

This template produces HTML like the following:

<p>Recent Entries:</p>
<ul>
<li>FantasyLand to add 3-D movie attraction</li>
<li>Disney pulls Janet’s Mickey statue</li>
<li>Killer whale born at SeaWorld Orlando</li>
</ul>

Everything outside the MTEntries container appears only once—the Recent Entries paragraph, the opening ul tag that starts an unnumbered list, and the closing ul tag. Inside the container, a list item appears for each entry in the container.

When using the days attribute, the current day counts as one of the days. Therefore, if the template was published on April 28 with days=”3” in the MTEntries tag, entries from April 26, 27, and 28 would be shown.

The author and category attributes limit retrieved entries to a specific author, category, or categories.

When the category attribute has a category name as a value, all entries are collected from that category. You can specify more than one category by separating them with the OR keyword: For example, category=”Disney News OR Theme Parks” pulls entries from either the Disney News or Theme Parks categories of a weblog.

There’s also an AND keyword that identifies entries belonging to multiple categories: category=”Disney News AND Theme Parks” only retrieves entries that belong to both categories.

The following HTML code displays the last 25 entries from a weblog category named Travel and Hotels:

<h1>Travel News</h1>
<MTEntries lastn=”25” category=”Travel and Hotels”>
<h2><MTEntryTitle></h2>
<p><MTEntryBody>
<h5 align=”Right”><MTEntryDate></h5>
</MTEntries>

If there are no entries in that category, nothing contained within the opening and closing MTEntries tags is displayed.

The sort_by and sort_order attributes can be used to change the sorting order of entries and the key used to sort them.

The sort_by attribute identifies the element of a weblog entry that is sorted. You can sort by entry author (using the value author_id), excerpt (excerpt), the date the entry was last edited (modified_on), the entry status (status), or the title (title).

The sort_order attribute, which takes the value of ascend or descend, determines whether entries are listed from first-to-last or last-to-first order.

The default sort order for entries is set by the Order of Entries Displayed setting in the weblog configuration. (To see or change it, click the Weblog Config sidebar menu button and click the Preferences link atop the Configuration page.)

This setting determines the sort order unless the sort_order attribute appears in the MTEntries tag. In entries organized by date, ascending order goes forward in time. For entries organized by other keys, ascending order is alphabetical from A to Z. Here’s an example that sorts the 25 most recent entries alphabetically by title:

<ul>
<MTEntries sort_by=”title” lastn=”25” sort_order=”ascend”>
<li><MTEntryTitle></li>
</MTEntries>
</ul>

Displaying an Entry

Within an MTEntries container or on an individual entry page, you can use around three dozen tags to present elements of a weblog entry.

Most entry tags simply display text held by a field, such as this HTML code that displays the username of an entry’s author:

Written by <MTEntryAuthor>

Like all other tags, entry tags can employ global attributes such as encode_html and remove_html that affect their output. Entry element tags are shown in Table 8-6.

Table 8-6: MTEntries Element Tags
Tag | Attributes | Description
MTEntryAuthor |  | The username of the entry author
MTEntryAuthorEmail | Spam_protect | The e-mail address of the author, which can be disguised by setting spam_protect equal to 1
MTEntryAuthorLink | show_email, show_url, spam_protect | A hyperlink associated with the author, which can be associated with a home page or e-mail link
MTEntryAuthorNickname |  | The nickname of the entry author
MTEntryAuthorURL |  | The address (URL) of the author’s home page
MTEntryBody | words | The main body of the entry; the words attribute can shorten output to the specified number of words
MTEntryDate | format | The date and time the entry was first saved
MTEntryExcerpt | convert_breaks | The entry excerpt (or the first 20 words of the entry body, if no excerpt exists)
MTEntryFlag | Flag | The boolean value (1 or 0) of an entry identified by the flag attribute, which can be allow_comments or convert_breaks
MTEntryID | Pad | The entry’s id_number, which can be padded with one or more leading 0s using the pad attribute
MTEntryLink | archive_type | The address (URL) of an archive page containing the entry; the type of archive page can be chosen with the archive_type attribute
MTEntryModifiedDate | format | The date and time the entry was last revised
MTEntryMore | convert_breaks | The extended entry text
MTEntryPermalink | archive_type | The address (URL) of the entry in an archive
MTEntryStatus |  | The publication status of the entry, which can be Draft or Publish
MTEntryTitle | convert_breaks | The entry’s title

Five template tags credit the person who wrote an entry. Two provide a name: MTAuthor displays an author’s username and MTAuthorNickname presents the nickname provided by the author in his or her profile. Because this last field can be changed or removed by an author, the MTAuthor tag is likely to be more useful.

The MTAuthorURL and MTEntryAuthorEmail tags produce the author’s home page and e-mail addresses, if they have been provided. MTAuthorLink contains a hyperlink to the author’s name. The address of the link depends on the preceding two tags:

  1. If an author has a home page address, MTAuthorLink links to that page.

  2. If the author has an e-mail address and no home page, MTAuthorLink is a mailto link to that address. This behavior can be overridden by the tag’s show_email and show_url attributes. Set one of them to 1 and that address takes precedence.

  3. If neither a home page nor e-mail address is provided, MTAuthorLink is the author’s name, with no link.

Both e-mail tags use a spam_protect attribute to disguise e-mail addresses. When spam_protect equals 1, an address is changed to make it harder for address-collecting software to find it.

Spammers and other Internet abusers run software that scours Web pages looking for e-mail addresses that can be added to their databases. Because this can render an address unusable as more and more spammers hit it with junk mail, Web publishers often alter or disguise their address on Web pages.

Setting spam_protect to 1 changes the @ and . characters in an e-mail address to the numeric HTML entity codes &#64; and &#46, respectively. For example, the address rcade@example.com becomes rcade&#64;example&#46;com.

Gotcha

Although this technique will fool some spam-harvesting software, at this point it’s highly likely that spammers have figured out how to find and decode these addresses. Encourage your weblog authors to use a public e-mail address that they can abandon once it begins to be abused by spammers, rather than an address they want to keep private and hold onto for years.

Five tags present entry data collected on Movable Type’s editing form: title (MTEntryTitle), body (MTEntryBody), extended entry (MTEntryMore), excerpt (MTEntryExcerpt), and keywords (MTEntryKeywords).

With the exception of MTEntryKeywords, all of these tags offer a convert_ breaks attribute. When it’s equal to 1, tag output is processed with the Convert Line Breaks text filter, adding <p> and </p> tags around paragraphs and replacing line breaks with <br> tags. If the attribute is absent or equal to 0, the entry’s chosen text filter is applied instead.

MTEntryBody tag output can be shortened with its words attribute, which takes as a value the number of words to display. Therefore, if words=”12”, the first 12 words in the main body of the weblog entry are displayed.

The MTEntryID tag, which holds an entry’s unique ID number, can be padded with one or more zeroes using the pad attribute, which functions identically to the global attribute zeropad—the output is padded to the length specified by the attribute value, so if an entry numbered 132 has pad=”6”, the output is 000132.

Here’s an HTML index template that displays the last five entries published on a weblog, showing several entry fields with different formatting:

<MTEntries lastn=”5”>
<a name=”<MTEntryID>”></a>
 <h3><MTEntryTitle></h3>
<MTEntryBody>
<a name=”more”></a>
<MTEntryMore>
<h5 align=”right”>
Posted by <MTEntryAuthorLink> |
<a href=”<MTEntryPermalink>”>link</a>
</h5>
</MTEntries>

The template produces entries that take the following form:

<a name="79"></a>
 <h3>Killer whale born at SeaWorld Orlando</h3>
<p>Kalina, an 18-year-old killer whale at SeaWorld
Orlando, gave birth to her fourth calf
Monday at Shamu Stadium, the park’s research
and breeding facility.</p>

<a name="more"></a>

<h5 align="right">
Posted by <a target="_blank"
href="http://cadenhead.org/">rcade</a> |<a href="http://orlandovacationer.com/archives/
000079.html">link</a>
</h5>

Using this template, an HTML anchor named “more” shows up on the page even if there’s no extended entry text (in other words, the MTEntryMore tag is empty).

A container tag, MTEntryIfExtended, makes it possible to include or exclude part of a template depending on the value of MTEntryMore. Here’s how the preceding example can be rewritten to use this container:

<MTEntryIfExtended>
  <a name=”more”></a>
  <MTEntryMore>
</MTEntryIfExtended>

The two lines inside the MTEntryIfExtended container are displayed only when there’s text in an extended entry.

The MTEntryDate and MTEntryModifiedDate present timestamps identifying when the entry was created and revised. Their format attribute uses a strftime code to structure the date and time, as described earlier in this chapter.

Linking to Entry Archive Pages

Movable Type can archive weblog entries on category, date, and individual entry pages. The MTEntryLink tag contains a hyperlink with a value that depends on a weblog’s preferred archive type. You can override this choice by using the archive_type attribute, which can have the values Category, Daily, Individual, and Monthly.

Unlike MTEntryAuthorLink, this link tag produces a Web address, rather than a hyperlink. Following are examples of the four kinds of addresses the tag can produce:

http://orlandovacationer.com/archives/cat_disney.html (category)
http://orlandovacationer.com/archives/2004_04_28.html (daily)
http://orlandovacationer.com/archives/000132.html (individual)
http://orlandovacationer.com/archives/2004_04.html (monthly)

If an entry does not have an assigned category, using archive_type=”Category” will output an address that does not lead to a real Web page.

The MTEntryPermalink tag links to an entry more directly than MTEntryLink, using an anchor tag with its ID number, as shown in the following examples:

http://orlandovacationer.com/archives/cat_disney.html #000132 (category)
http://orlandovacationer.com/archives/2004_04_28.html #000132 (daily)
http://orlandovacationer.com/archives/000132.html #000132(individual)
http://orlandovacationer.com/archives/2004_04.html #000132 (monthly)

These links use anchor tags—the portion of the address that includes a pound sign (#) followed by a number—to open the page at the spot where the entry begins.

Because these addresses are different for each weblog entry, they can function as permalinks, which are unique Web addresses that refer directly to an entry and will not change over time. These permanent links can be useful even outside of a Web browser. You’ll use them in Chapter 18, “Publishing RSS and Atom Syndication Files.”

Gotcha

The MTEntryPermalink tag does not work as you might expect when a weblog’s preferred archive type has been set to individual entries. None of the links produced by the tag will include anchors; they’ll be the same links as MTEntryLink. To check your setting, click the Weblog Config sidebar menu button, click the Preferences link atop the Configuration page, and then look for the Preferred Archive Type field.

The variability of the links produced by MTEntryPermalink becomes a disadvantage when you don’t use individual entry pages and need to produce a unique permalink in all situations.

As an alternative, you can combine the output of the MTEntryLink and MTEntryID tags to create permalinks, as shown in this example:

<MTEntryLink archive_type=”Daily”>#<MTEntryID pad=”6”>

The preceding HTML code produces a URL of the following form:

http://orlandovacationer.com/archives/2004_04_28.html #000132

Using Entry Container Tags

The last group of entry tags includes the six containers that make it possible to achieve more control over how multiple entries are presented on the same page.

The MTDateHeader and MTDateFooter tags work with entries ordered by date (either chronologically or the reverse).

MTDateHeader contains text and template tags that are displayed only with a day’s first entry in an MTEntries container. The MTDateFooter does the opposite, presenting its contents only with the last entry. Here’s an example template that uses both:

<MTEntries lastn=”100”>
  <MTDateHeader>
    <h4><MTEntryDate format=”%B %e, %Y”></h4>
    <ul>
  </MTDateHeader>
  <li>
    <a href=”<MTEntryLink archive_type=”Individual”>”>
<MTEntryTitle></a>
  </li>
  <MTDateFooter>
    </ul>
    <hr>
  </MTDateFooter>
</MTEntries>

This index template displays links and titles to the 100 most recent posts, organizing them as unnumbered lists. A date header appears atop each day’s entries.

The MTEntryHeader and MTEntryFooter tags work in a similar manner, presenting their contents only with the first and last entry in an MTEntries container:

<MTEntries days=”21”>
<MTEntriesHeader>
  <table border=”1” width=”100%”>
</MTEntriesHeader>
    <tr>
      <td>
        <MTEntryDate format=”%Y/%m/%d”>
      </td>
      <td>
        <MTEntryTitle>
      </td>
      <td>
        <MTEntryAuthor>
      </td>
    </tr>
<MTEntriesFooter>
  </table>
</MTEntriesFooter>
</MTEntries>

The MTEntryPrevious and MTEntryNext containers enable information to be retrieved about adjacent entries in MTEntries or on an individual entry page.

Within these containers, all references to entry tags are to the previous or next entry instead of the current one. This will make more sense in context: Consider an MTEntries container that holds three entries in chronological order:

  • A movie review written on April 30, 2004

  • A news story written on May 2, 2004

  • A sports story written on May 3, 2004

On the individual page for the May 2 news story, you could use MTEntry Previous to retrieve the entry link and title for the movie review and MTEntryNext to get the same information about the sports story.

The following tags are used in Movable Type’s default XHTML template for individual weblog entries:

<div id=”menu”>
<MTEntryPrevious>
<a href=”<$MTEntryPermalink$>”>&laquo;
<$MTEntryTitle$></a> |
</MTEntryPrevious>
<a href=”<$MTBlogURL$>”>Main</a>
<MTEntryNext>
| <a href=”<$MTEntryPermalink$>”><$MTEntryTitle$>
&raquo;</a>
</MTEntryNext>
</div>

In this template, the &laquo; and &raquo; entity codes refer to double-arrow characters that point to the left and the right. The HTML produced by this template presents a linked title to the previous entry, a “Main” link to the weblog home page, and a linked title to the next entry, as shown in Figure 8-4.

Click To expand
Figure 8-4: Linking to adjacent weblog entries on a page.

When using these containers, you must make sure that anything referring to the current entry is placed outside of these containers (as is the “Main” link in the preceding example).

The next two sections present tags that you can use to present additional information related to entries: archive, category, comments, and trackback information.

Note

Two entry tags that haven’t been covered in this section, MTEntryFlag and MTEntryStatus, exist primarily for use in Movable Type’s weblog export format, which is covered in Chapter 12, “Backing Up a Weblog.” MTEntryStatus displays Publish or Draft, indicating the publication status of an entry. MTEntryFlag employs a flag attribute that equals allow_comments or convert_breaks, and then displays the boolean value of that setting.

Using Category and Archive Tags

You can organize Movable Type weblogs into categories and several kinds of archives. These features can be implemented on a template using more than a dozen category and archive tags.

The MTEntryCategory tag represents an entry’s primary category, when one has been assigned. MTEntryCategories holds all of an entry’s categories, including the primary category.

Both of these tags can be used only in an MTEntries container or on an individual entry page.

The MTCategories container tag represents all of a weblog’s categories that contain at least one entry. You can include all categories by using a show_empty attribute with a value of 1.

Table 8-7 shows the tags that can be used for each category in either of these containers.

Table 8-7: Weblog Category Tags
Tag | Description
MTCategoryArchiveLink | The address (URL) of the category’s main archive page
MTCategoryCount | The number of entries contained in the category
MTCategoryDescription | The description of the category
MTCategoryID | The category’s ID number
MTCategoryLabel | The category’s name
MTCategoryTrackbackLink | The category’s trackback ping address (URL)

All of these category tags also can be used on a category archive page, in which context they are associated with that page’s category.

The following HTML code displays the title and categories of the 10 most recent weblog entries:

<MTEntries lastn=”10”>
<p><MTEntryTitle>
<MTCategories><p>Categories: <a href=”<MTCategoryLink>”>
<MTCategoryLabel>
</a></MTCategories>
</MTEntries>

In pages produced from this template code, each category is presented as a link to that category’s archive page.

The link tags available for a category can be used only on weblogs that support those features. If you use the MTCategoryArchiveLink tag in a template and category archiving has not been enabled in your configuration, Movable Type will not rebuild pages with the template.

Cross-Reference

The MTCategoryTrackbackLink tag works on categories that have been configured to accept incoming pings in a trackback content aggregator, a feature described in Chapter 11, “Sharing Trackback Links.” This tag displays the URL that should be used to send trackback pings to the category.

Normally, this tag is used on the archive pages for a category that serves as a trackback aggregator. If used in an MTCategories container, the tag displays only a trackback link for categories set up to accept pings.

The MTEntryCategories container includes a glue attribute to present several categories together on the same line or in a similar grouping. Set the value of the attribute to text that should appear between each category—such as a comma to present a comma-separated list, as shown in the following example:

<MTEntries lastn=”3”>
<p><MTEntryTitle>
(<MTEntryCategories glue=”, “><MTCategoryLabel>
</MTEntryCategories>)
</MTEntries>

This code produces the following HTML:

<p>FantasyLand to add 3-D movie attraction
(Disney News, Disney World)
<p>JetBlue offers $69 fare to Orlando
(Travel and Hotels)
<p>OrlandoHotelsEye offers hotel discounts
(Travel and Hotels)

Each time a new entry is published, Movable Type creates archive pages automatically for each of the archive types that has an archive template.

A master index of archived pages can be created for each archive type using the MTArchiveList container tag.

An MTArchiveList container holds several archive tags and can make use of entry tags. Two attributes affect its contents: lastn, which retrieves the specified number of archive pages starting with the most recent, and archive_type, which specifies the kind of archive being presented.

The lastn attribute can be omitted, causing the list to contain all archive pages.

When the archive_type attribute is omitted, MTArchiveList uses the preferred archive type designated in your configuration. The attribute can have the value Category, Daily, Weekly, Monthly, or Individual, and it determines the pages that are included in the list.

Table 8-8 describes the archive tags that you can use for each archive page in the MTArchiveList container.

Table 8-8: Weblog Archive Tags
Tag | Attributes | Description
MTArchiveCategory |  | The address (URL) of the category’s main archive page
MTArchiveCount |  | The number of entries in the archive list container
MTArchiveDate | format | The first date in an archive list that represents a daily, weekly, or monthly archive
MTArchiveDateEnd | format | The last date in an archive list for a daily, weekly, or monthly archive
MTArchiveLink | archive_type | The full address (URL) to this archive’s main page on the weblog
MTArchiveTitle |  | The title of this archive, which takes different forms depending on the archive type

The MTArchiveTitle tag provides a title that can be used in links to each archive page. The title depends on the archive type represented by the archive list—it will be a category name for category archives, an entry title for individual archives, and dates for calendar-based archives. Here’s some HTML template code to use this tag:

<ul>
<MTArchiveList archive_type=”Daily”>
  <li><a href=”<MTArchiveLink>”><MTArchiveTitle></a></li>
</MTArchiveList>
</ul>

Because the MTArchiveTitle and MTArchiveLink tags adapt to suit each archive format, you can change the archive_type value and this code continues to present an index of archive pages.

Some tags work only for particular archive types: MTArchiveDate and MTArchiveDateEnd tags for date-based archives and MTArchiveCategory for category archives.

An archive list also can make use of MTArchiveNext and MTArchivePrevious containers that function exactly like the MTEntryNext and MTEntryPrevious tags, pulling information about adjacent elements in a container.


Summary

Movable Type’s template-driven design might be its strongest selling point, making it easy to incorporate static content such as HTML with dynamic content produced by custom template tags.

Because the tags so closely resemble HTML, Web designers comfortable with HTML and CSS can put those skills to good use developing templates.

All pages and other files produced by Movable Type are generated by templates. Index templates included with a newly created weblog produce three kinds of files: HTML and XHTML Web pages, CSS style sheets, and XML files that support syndication and weblog editing.

Two kinds of template tags can be used: simple tags that produce output, and container tags that function as a sort of template within a template.

Container tags can repeat the same content several times, as the MTEntries tag does when it displays multiple weblog entries. They also can display content only if a specific condition is met, which the MTEntryIfExtended tag does by producing output only when an entry makes use of the Extended Entry field.

There’s a lot more to learn about templates, as you’ll discover in the next chapter. You can create three kinds of templates in addition to index templates and use template tags to display comments, trackback pings, archive calendars, and other kinds of information.


Chapter 9: Designing a Weblog withTemplates

In This Chapter

  • Creating an index template

  • Rebuilding templates automatically

  • Working on templates outside of a browser

  • Choosing archive templates

  • Deciding which archives to publish

  • Customizing archive filenames

  • Creating calendar-based archive links

  • Using other template tags

The power of Movable Type becomes apparent when you become comfortable enough with the content-management software to dig into your weblog’s templates, the set of files that produces all of the Web pages, syndicated feeds, and other text files that comprise the site.

Movable Type’s template-driven system makes it easy to make changes to a weblog as it grows, incorporating the improvements throughout the site. This eliminates the problem of sites growing stale as hundreds, if not thousands, of hand-edited pages go out of date.

The templates contain a mixture of static content in HTML, XHTML, CSS, or another formatting language and dynamic content produced by more than 120 template tags. These tags, which resemble HTML markup tags in both appearance and function, make it easy for Web designers to adapt their skills directly to template creation.

Anyone who can design a Web page can work with templates and these HTML-like tags, once you learn the purpose of each of a weblog’s templates and how each produces Web content.


Generating Web Pages from a Template

Chapter 8, “Producing Web Pages with Template Tags,” introduced a simple index template and dozens of template tags.

You might find that a new, plain template serves as a better place to learn the ins and outs of Movable Type’s template-driven publishing system, because there’s no need to puzzle through the fairly sophisticated XHTML markup provided by default with each new weblog.

To work on a weblog’s templates, click the Templates button in the sidebar menu. The Templates page opens (see Figure 9-1).

Click To expand
Figure 9-1: Viewing and editing a weblog’s templates.

A Movable Type weblog begins with 16 templates:

  • Seven index templates, files that produce the primary content of the weblog, including the home page and syndication feeds

  • Three archive templates, files that determine the content of weblog entry archive pages

  • Six miscellaneous templates supporting comments, trackback pings, and image pop-up windows

As shown in Figure 9-1, each index template has two names, indicated by the Template Name and Output File columns.

The template name, usually described simply as its name, serves primarily to help you and other authors understand its purpose. The name isn’t displayed on Web pages.

The template’s filename determines the name of the file that results from the template.

Putting these together, the Main Index template in Figure 9-1 produces index.html, the weblog’s home page. The RSS 2.0 Index template creates index.xml, an RSS syndication file containing weblog entries formatted as XML.

Tip

Choose a good name for each template that you work on. You’ll be able to use the name later with MTInclude, a tag that includes one template inside another; and MTLink, a tag that produces a link to the page produced by a specific template.


Editing Movable Type Templates

The most important templates in any Movable Type weblog are its index templates, which produce the home page and other files in a weblog’s main directory.

You can rebuild index templates as a group, producing their output files with a single site rebuild, or rebuild them individually.

To rebuild all index templates or an entire weblog, undertake these steps:

  1. Click the Rebuild Site button in the sidebar menu. The Rebuilding pop-up window opens (see Figure 9-2).

    Click To expand
    Figure 9-2: Rebuilding weblog files from their templates.

  2. To save time and publish the index templates only, choose the Rebuild Indexes Only drop-down menu option.

  3. To publish the entire site, choose Rebuild All Files.

  4. Click Rebuild.

The pop-up window displays a series of status messages indicating the progress of the rebuilding process. One is shown in Figure 9-3.

Click To expand
Figure 9-3: Tracking the progress of a site rebuild.

After it has been completed, you can click the View Your Site link to see the results.

You can edit templates in Movable Type’s browser interface. Click the Templates sidebar menu button to view the Templates page, and then click a template’s name (for index and archive templates) or the Edit button (for miscellaneous templates). The Edit Template page opens (see Figure 9-4).

Click To expand
Figure 9-4: Editing a template.

Templates consist of two kinds of content: static text that’s copied without modification in the resulting file and dynamic output produced from template tags.

Most templates produce markup in either HTML or XHTML, the two formatting languages used to create Web pages. That’s not a necessity, however, as you can see by viewing the Atom or RSS index templates. They contain XML structured according to the rules of their formats.

You can use Movable Type to generate Web pages with the same languages and technology that you work with in any Web publishing environment. If you’re publishing on a server that includes a PHP interpreter, you can use templates to create PHP files. Produce ASP files for a Windows Internet Information Server, SHTML files that make use of server-side includes on Apache Web server, or any other desired format.

Because Movable Type rebuilds index templates as a group, you can easily create a weblog in multiple formats. Create one graphically intensive Web site for Web browsers running on desktop computers with high-speed Internet connections, a simpler text-based site for cell phone and PDA users, and syndication feeds in Atom and RSS formats to be read by feed aggregator software called newsreaders.

When you edit a template, use the Template Name field to give it a name. This can be used to create hyperlinks to the page and include the template inside other templates, so choose a short, descriptive name.

The Output File field determines the filename of the template. The output file is stored in the weblog’s main directory under that name.

You can include index templates in a group rebuild by enabling the checkbox Rebuild This Template Automatically When Rebuilding Index Templates. If this checkbox is not enabled, you can only rebuild the template individually: Open the template by clicking its link, and then scroll to the bottom of the Edit Template page and click the Rebuild button.

On a site that receives visitor comments and trackback pings, each of these messages prompts the software to rebuild index templates. They also are rebuilt when entries are published.

Gotcha

Turning off automatic rebuilds speeds up the process of publishing a weblog, so you should do it whenever possible, especially for index templates that produce a lot of output or change infrequently.

For one of my weblogs, I created a backup template that produced a file containing all weblog entries in Movable Type’s backup format (described in Chapter 12, “Backing Up a Weblog”), producing more than 200 KB of output, and set it to rebuild automatically. The site became so slow accepting new comments that the feature was unusable. Removing the backup index from the list of automatically rebuilt templates fixed the problem.

You can edit templates outside of the browser and store them in individual files, a feature that makes it easier to create templates with Web publishing software such as Macromedia Dreamweaver or Microsoft FrontPage.

As a security measure to prevent Movable Type’s scripts and configuration files from being overwritten, external template files cannot be given the file extensions .cfg, .cgi, .pl, or .pm.

The files can be stored anywhere on the Web server running Movable Type. If an external template file is stored in the weblog’s local site path directory, it can be referred to simply by its filename. Otherwise, references must include the full path and filename (such as /var/www/date_template.html).

To create external templates, follow these steps:

  1. Click the Templates sidebar menu button to open the Templates page.

  2. Open the template for editing by clicking its name.

  3. On the Edit Template page, enter the external file’s name in the Link This Template to a File field.

  4. Scroll to the bottom of the page and click Save.

The file will be kept in sync automatically by Movable Type, which copies changes from the file to its database and vice versa.

Caution

You can accidentally overwrite your work when associating a template with an external file for the first time. If there’s a template in the Template Body field and you provide a filename in the Link This Template to a File field, the file will be overwritten with that template. To avoid this problem, delete the text in the Template Body field before filling out the Link This Template to a File field.

Creating Archive Pages from Templates

The relationship between an index template and its output file is clear: The template produces the file.

Archive templates are not associated with individual files. Instead, they produce as many pages as needed to store weblog entries.

These templates appear in the Archive-Related Templates section of the Templates page. Three kinds of templates can be associated with an archive:

  • A Category Archive displays entries belonging to one of a weblog’s categories.

  • A Date-Based Archive contains entries written on a specific day, week, or month.

  • An Individual Archive presents a single weblog entry.

These archive templates can serve multiple purposes—as the Date-Based Archive does by representing daily, weekly, and monthly collections of entries.

You can define additional archive templates to represent entries in other ways. One possible use for this functionality would be to create one monthly date-based archive that displays the entries in full in chronological order and another that displays a list of entry titles and excerpts only.

The process of creating a new archive template and generating pages from that template requires Movable Type’s template editing and weblog configuration pages.

Follow these steps:

  1. Click the Templates sidebar menu button to open the Templates page.

  2. Scroll down to the Archive-Related Templates section and click the Create New Archive Template link. The Edit Template page opens.

  3. Use the Template Name field to give it a name that describes the archives that it will create.

  4. If the template has been defined in an external file uploaded to the server, put its name in the Link This Template to a File field.

  5. Otherwise, fill out the Template Body text area with the template.

  6. Click the Save button.

The template will be added to the Templates page, but archive files will not be created until you change the weblog’s archive settings:

  1. Click the Weblog Config sidebar menu button. The Core Setup page appears.

  2. Click the Archive Files link to open that configuration page (see Figure 9-5).

    Click To expand
    Figure 9-5: Creating archive pages from an archive template.

  3. In the Archive Type drop-down menu, choose the kind of archive pages to be created with the new template: Category, Daily, Individual, Monthly, or Weekly.

  4. In the Template drop-down menu (circled in Figure 9-5), choose the new template, which has been added to the available options.

  5. Click Add.

The new template appears in the Archives section of the page. Whenever you publish an entry or rebuild the site, archives are generated from all of the templates that have selected checkboxes next to their names (as shown in Figure 9-6). If you want to stop generating an archive, deselect its checkbox.

Click To expand
Figure 9-6: Generating archive pages from selected archive templates.

Choosing Customized Names for Archive Pages

Archive templates create multiple files with names that are based on the year, month, and title of the entries that they contain. For example, on Orlando Vacationer, a Jan. 13, 2004 entry titled “Take the Voyage of the Little Mermaid” was stored in an individual archive in the 2004/01 subdirectory in a file named take_the_voyage.html.

You can use some Movable Type template tags to establish your own naming convention for archive pages. Six Apart calls this feature archive file templates (although they’re more precisely described as filename templates).

An archive filename template is simply a one-line template that outputs the directory and filename of pages generated from the template. The file reference should be relative to a weblog’s local archive path.

Here’s an example that names daily archive pages based on the day of the year:

<MTArchiveDate format=”%Y”>/<MTArchiveDate format=”%j”>.html

A filename template is entered in the Archive File Template field on the Archive Files configuration page.

On Jan. 15, 2004 (the 15th day of the year), the example template stores the page at 2004/015.html. On Feb. 1, 2004 (the 32nd day), it’s 2004/032.html.

This template causes daily archive pages to be stored in a directory named for a year (the first MTArchiveDate tag) followed by a slash and the day of the year, which ranges from “001” to “365” or “366” for leap years (the second MTArchiveDate tag).

Any date-based archive can use the MTArchiveDate tag, which represents the first date in the chronological period covered by the archive in question. There’s also an MTArchiveDateEnd tag for the last date in the period.

Individual entry archives can use any entry template tag. The following archive filename template stores entries based on the date and time they were written:

<MTEntryDate format="%Y">/<MTEntryDate format="%m">/
<MTEntryDate format="%d">/<MTEntryDate format="%H%M%S">.html

The following three URLs contain entry links created from this template:

http://orlandovacationer.com/archives/2004/02/10/061603.html
http://orlandovacationer.com/archives/2004/02/11/093951.html
http://orlandovacationer.com/archives/2004/05/16/052826.html

The local archive path for Orlando Vacationer is the /archives directory, so the file template specifies the subdirectory and filename relative to it.


Displaying Images in a Pop-Up Window

When a digital photo or another graphic has been uploaded to a Movable Type weblog, you can present it in two ways:

  • In the body of the weblog entry, aligned to the right, left, or top of the text

  • In a pop-up window opened with a link in the entry

The Uploaded Image Popup Template dictates the appearance of the latter, using simple HTML markup similar to what is shown in Listing 9-1.

Listing 9-1: Displaying an Image Pop-Up Window
Start example
<html>
<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">
<img src="<MTImageURL>" width="<MTImageWidth>" height="<MTImageHeight>"
border="0" />
</body>
</html>
End example

To make changes to a weblog’s image pop-up window template, click the Templates sidebar menu button, scroll down to the Miscellaneous Templates section, and then click the Edit button alongside the label Uploaded Image Popup Template.

Three template tags can be used in the template: MTImageURL, the Web address (URL) of the graphic; MTImageWidth, the width of the graphic in pixels, and MTImageHeight, the pixel height.

Using Calendar Tags

A fixture of most Movable Type weblogs, thanks to its inclusion in the default index template, is a monthly calendar with links to archived weblog entries. The calendar presents links for the current month, or in the case of a less-active weblog, the last month in which an entry was published.

These calendars present a table of dates topped by the month and weekday names. Each date containing weblog entries has a hyperlink. Figure 9-7 shows the calendar created by Movable Type’s index template for a new weblog.

Click To expand
Figure 9-7: Displaying archive links as a monthly calendar.

All aspects of the calendar are achieved with template tags, making it possible to customize the presentation of the table and design other forms of calendars.

Listing 9-2 contains the HTML markup required to present the calendar shown in Figure 9-7.

Listing 9-2: Presenting Calendar Links
Start example
<table>

  <caption><MTDate format="%B %Y"></caption>
  <tr>
    <td abbr="Sunday">Sun</td>
    <td abbr="Monday">Mon</td>
    <td abbr="Tuesday">Tue</td>
    <td abbr="Wednesday">Wed</td>
    <td abbr="Thursday">Thu</td>
    <td abbr="Friday">Fri</td>
    <td abbr="Saturday">Sat</td>
  </tr>
<MTCalendar>
  <MTCalendarWeekHeader><tr></MTCalendarWeekHeader>
    <td>
      <MTCalendarIfEntries><MTEntries lastn="1">
        <a href="<MTEntryPermalink>"><MTCalendarDay></a>
      </MTEntries></MTCalendarIfEntries>
      <MTCalendarIfNoEntries><MTCalendarDay></MTCalendarIfNoEntries>
      <MTCalendarIfBlank>&nbsp;</MTCalendarIfBlank>
    </td>
  <MTCalendarWeekFooter></tr></MTCalendarWeekFooter>
</MTCalendar>

</table>
End example

Table 9-1 contains ten tags that work together to create calendars, including MTCalendar and five other container tags.

Table 9-1: Calendar Tags
Tag | Attributes | Description
MTCalendar | category, month | A container for a month of calendar links, which can be limited to a specific category or a designated month
MTCalendarCellNumber |  | The position of the current calendar cell
MTCalendarDate | format | The current date, expressed in the indicated format
MTCalendarDay |  | The day of the month, expressed as a number from 1 to 31
MTCalendarIfBlank |  | A container displayed when the cell does not represent a date
MTCalendarIfEntries |  | A container displayed when the current date has one or more entries
MTCalendarIfToday |  | A container displayed when the current date is today
MTCalendarIfNoEntries |  | A container displayed when the current date has no entries
MTCalendarWeekFooter |  | A container displayed when the current cell ends a week
MTCalendarWeekHeader |  | A container displayed when the current cell begins a week

The MTCalendar container holds one calendar month. When used without any attributes, the tag represents the current month.

The month attribute can be used to specify a month in YYYYMM format (such as “200407” for July 2004 or “200312” for December 2003). You also can use the value this to adopt the month and year of an archive page or last to refer to the preceding month.

The category attribute can be used to base calendar links on a specific category, as in these lines of template code:

<MTCalendar category=”Orlando”>
</MTCalendar>

Only three calendar tags are not containers: MTCalendarCellNumber, MTCalendarDate, and MTCalendarDay.

The MTCalendarDay tag presents the day of the month as a number from 1 to 31. Often, that’s all you need to present the calendar. The number will be linked on days that have weblog entries and be displayed as text otherwise.

For more sophistication, the MTCalendarDate tag represents the entire date, which can be formatted with the format attribute like other date template tags.

On a calendar date that includes weblog entries, the MTCalendarIfEntries container tag defines the content to display. Within this container, an MTEntries container will represent that calendar date, so you can present one or more entry titles and other elements.

Calendars in Movable Type are not limited to simple, text-based tables, as Six Apart cofounder Mena Trott demonstrated with a full-page calendar she created for her personal DollarShort weblog (see Figure 9-8).

Click To expand
Figure 9-8: Presenting full-page calendars.
Web Site Download

The calendar page can be viewed on DollarShort, Mena Trott’s personal weblog at http://www.dollarshort.org/days. The weblog itself has moved to TypePad, which is Six Apart’s Movable Type hosting service, at http://mena.typepad.com.

Using Other Tags

Movable Type’s remaining template tags include a few conditional container tags and two tags to pull content from files and other templates.

The MTElse container can be used with any other conditional container to provide something to display when the condition is not met. This container must be placed inside the other container, as in the following example that makes use of the MTEntryIfExtended tag:

<MTEntryIfExtended>
  <p><MTEntryMore></p>
<MTElse>
   <p align="center"><hr width="50%"></p>
</MTElse>
</MTEntryIfExtended>

On a weblog page produced from this template code, an entry’s extended text is displayed if the entry has been extended. If not, a horizontal rule created with the hr tag is shown instead.

Another conditional container tag, MTIfNonEmpty, makes sure that another template tag contains some text. The name of the tag must be specified with the tag attribute, omitting the < and > characters, like this:

<MTIfNonEmpty tag=”MTEntryKeywords”>
    <p>Keywords: <MTEntryKeywords>
</MTIfNonEmpty>

This code displays a weblog entry’s keywords, if they have been defined, and shows nothing if they haven’t.

The MTInclude template tag enables a template to include another file or template, making it easier to share common content such as a row of menu buttons or weblog links on several templates.

The tag’s module attribute specifies the template name, which should match its name in the Template Name column of the Templates page (accessible from the Templates sidebar menu button).

The following template code adds the Ad Tower template to another template:

<MTInclude module=”Ad Tower”>

On the Orlando Vacationer weblog, the preceding line appears on the index template and all archive page templates, adding the site’s Google AdSense HTML code to display text ads.

The MTInclude tag’s file attribute indicates a file that should be included in the page, which can be a Web page, a text file, or any other file that makes sense to incorporate into the template’s output. Here’s an example:

<MTInclude file=”adtower.html”>

The file can be specified with a full directory and filename or simply as a filename. In the latter case, the file must be in either the Local Site Path or Local Archive Path directories.

Caution

If you’re familiar with the server-side include feature of the Apache Web server or another server, you’ll find that the MTInclude tag doesn’t offer the same functionality. A server-side include will pull the included content into an enclosing Web page again with each request, so a change to the included page will be reflected automatically. The MTInclude tag only pulls content from the included page or template when the enclosing page is rebuilt. If you edit an included module, you won’t see the change on your weblog until you rebuild all templates that include it.

The MTLink tag generates hyperlinks to weblog pages generated by templates, using the template attribute to identify the source of the page.

The following XHTML example contains several link tags that identify a weblog’s syndicated Atom and RSS feeds:

<link rel=”alternate” type=”application/atom+xml” title=”Atom”
href=”<MTLink template=”Atom Index”>” />
<link rel=”alternate” type=”application/rss+xml” title=”RSS 1.0”
href=”<MTLink template=”RSS 1.0 Index”>” />
<link rel=”alternate” type=”application/rss+xml” title=”RSS 2.0”
href=”<MTLink template=”RSS 2.0 Index”>” />:

Here’s the resulting XHTML markup:

<link rel=”alternate” type=”application/atom+xml” title=”Atom”
href=”http://orlandovacationer.com/atom.xml” />
<link rel=”alternate” type=”application/rss+xml” title=”RSS 1.0”
href=”http://orlandovacationer.com/index.rdf” />
<link rel=”alternate” type=”application/rss+xml” title=”RSS 2.0”
href=”http://orlandovacationer.com/index.xml” />

The MTLink also has an entry_id attribute that provides archive links to weblog entries:

<a href=”<MTLink entry_id=”413”>413</a>

Entry links will refer to the individual archive link for the entry, which is based on either a date and entry ID number or a date and entry title, depending on the Use Old-Style Archive Links setting in your weblog’s configuration.

The MTDate tag presents the date and time that the template built the page. Like all other date tags in Movable Type, a format attribute can be used to dictate the presentation and order of date and time elements.

The MTSetVar and MTGetVar tags enable a template to set and retrieve variables, simple storage places for text.

To set a variable, use the MTSetVar tag with name and value attributes that describe its name and value, as in this example:

<MTSetVar name=”glue” value=”, “>

Once a variable has been set in this manner, it can be retrieved with the MTGetVar tag and its name attribute:

<MTGetVar name=”glue”>

These two tags become most handy as you work with the template tags provided by plug-ins, a topic that’s covered in Chapter 16, “Enhancing Movable Type with Plug-ins,” and Chapter 17, “Presenting External Web Content with Plug-ins.”

One use for the tags is to serve a similar purpose as the glue attribute of the MTEntryCategories tag, which causes a comma or another separator to appear in lists of category names (and similar presentations).

The following template code displays the last five weblog entry titles:

<MTSetVar name=”glue” value=””>
<MTEntries lastn=”5”>
<MTGetVar name=”glue”><MTEntryTitle><MTSetVar name=”glue” value=”, “>
</MTEntries>

On my Orlando Vacationer weblog, the preceding code produced the following title list:

Dining in Orlando’s Rainforest Cafes, Mission: Space Hard to Stomach,
A Whole New World, Killer whale born at SeaWorld Orlando, Disney
cuts pass program

Commas appear before each entry title in the list except for the first title, “Dining in Orlando’s Rainforest Cafes.” This occurs because the initial value of the glue variable is an empty string. After the first title is displayed, the MTSetVar tag changes its value to a comma and space (“, ”).


Summary

Although Movable Type was designed for weblogs, the software offers enough flexibility to produce any other kind of Web sites for which it makes sense to order content chronologically and publish over time, such as magazines, photo albums, press releases, and newspapers.

With the software’s robust template-driven publishing system, all aspects of the presentation can be customized, including the filenames for each entry.

The template tags covered in the last two chapters are supplemented by additional tags and templates that support other features, including visitor comments, trackback pings, and search pages.

Movable Type supports an unlimited number of additional template tags with plug-ins, Perl scripts that enhance the capabilities of the software. Every plug-in can support its own tags, which can be added to templates seamlessly, as if they were a built-in part of the software at its installation.

If this has been your first experience with template-based publishing, you’re going to find it difficult to return to editing static Web pages by hand again. Keeping Web sites up-to-date with fresh designs becomes a much more attainable goal when you can update an entire site by editing a few template files.


Chapter 10: Offering Comments

In This Chapter

  • Deciding whether to adopt TypeKey user authentication

  • Setting up a TypeKey account

  • Acquiring a TypeKey token

  • Hooking TypeKey to a weblog

  • Signing in to TypeKey

  • Blocking users based on IP addresses

  • Editing comments

  • Preventing comment abuse

  • Working with comment template tags

  • Presenting comments in an entry archive

  • Publishing comments in an index archive

Movable Type weblogs can accept public comments from site visitors, a seemingly innocuous feature that can turn your sedate corner of the Web into absolute bedlam. The term bedlam, referring to a state of confused uproar, comes from the Hospital of Saint Mary of Bethlehem, an infamous asylum for the mentally ill in London that dates back to the 13th century. Anyone who has offered an online discussion forum to the public will understand the comparison to an asylum.

When you configure a weblog to accept comments from the public, your site instantly becomes an online community, a gathering place for people attracted to your subject matter. Over time, you might find that they become just as interested, if not more, in each other.

A thriving comments section can be a terrific way to keep people coming back to your weblog, especially when your own contributions become less frequent.

As a weblog’s audience grows from a cozy group of acquaintances to a bustling crowd of regulars to a raucous horde of hundreds, managing the chaos becomes a real challenge for weblog publishers.

Comments require effort to weed out undesired contributions such as abusive personal attacks, libelous remarks, and the biggest problem of any Movable Type weblogger: comment spam.

Because of Movable Type’s status as the most popular server-based weblogging tool, it attracts the same kind of dollar-crazed twerps who flood e-mail inboxes with unsolicited junk solicitations.

New Feature

Because weblogs receive so much comment spam, the biggest improvements in Movable Type 3 address this problem: better comment-management features and a new user authentication system called TypeKey.

In this chapter, you learn how to offer comments, guard against abuse and spam, encourage visitors to contribute their thoughts, and prepare for the ensuing bedlam.


Receiving Comments from Site Visitors

Past versions of Movable Type accepted comments from site visitors without restriction. None of the fields on the comment form were verified: a user could claim any name or e-mail address, even one that belongs to another participant in the discussion.

With the release of Movable Type 3, a weblog can take advantage of TypeKey, a new user-registration service offered by Six Apart.

Web Site Download

TypeKey, offered from the Web site http://www.typekey.com, provides a central authentication service that’s comparable to Microsoft .NET Passport. A user who has registered for a free account from TypeKey can use it to log in and post comments on hundreds of Movable Type–published weblogs.

The TypeKey feature, off by default on a newly created weblog, can be enabled in a weblog’s configuration settings.

From a Web user’s perspective, the primary benefit of TypeKey is the capability to comment on multiple weblogs without setting up a different account on each site. Once users have signed up for TypeKey and confirmed the validity of their e-mail address, they can write comments on any site that accepts TypeKey accounts as a form of user registration.

From a Web publisher’s perspective, the primary benefit is the knowledge that a user coming from TypeKey has a verified e-mail address and is less likely to post inappropriate comments—the account could be banned from your weblog and never allowed to post there again.

If a user’s account is used for particularly egregious purposes, such as posting comment spam to hundreds of weblogs, it can even be banned from the entire TypeKey service.

Signing In to TypeKey

Using the default template for an individual archive, a weblog that has enabled TypeKey prompts users to sign in, as shown in Figure 10-1.

Click To expand
Figure 10-1: Encouraging users to log in to TypeKey.

The Sign In hyperlink shown in Figure 10-1 takes users to a login page on TypeKey.Com. Users who don’t have an account yet can find out more about the service and register for an account, as shown in Figure 10-2.

Click To expand
Figure 10-2: Signing in to TypeKey.

Signing up for TypeKey requires only a user-selected username and a valid e-mail address.

In spite of being billed as an identity authentication service, TypeKey does not attempt to verify anything other than a user’s e-mail address. Six Apart neither requires nor checks a user’s real name or other personal information.

Start Sidebar
Verifying a TypeKey Account

When you register for a TypeKey account, the service sends an account-verification e-mail like this one:

Hello, Rogers.

Thanks for signing up for a TypeKey account. To begin using your TypeKey to log in to weblogs and post comments, and to use the Movable Type Store, you need to validate your e-mail address. Simply click on this link:

<https://www.typekey.com/t/typekey/confirm?v=7c2&s=f1e>

Or copy the link and paste it into the address bar in your Web browser.

After validating your e-mail address, you can:

  • Use your TypeKey to log in to TypeKey-enabled weblogs and Web sites

  • Manage your TypeKey profile: http://www.typekey.com/

    Welcome!

End Sidebar

After creating a TypeKey account and confirming the validity of an e-mail address, a user can sign in to the service.

TypeKey users are taken back to a weblog’s comments page after signing in, as shown in Figure 10-3.

Click To expand
Figure 10-3: Making a comment after signing in to TypeKey.

TypeKey users are identified in comments by the small icon that’s shown in Figure 10-3. Clicking the icon loads the user’s public profile page on TypeKey’s Web site.

Users set up their own profiles, providing as much or as little information as desired. Users who want to tell more about themselves can provide one-line biographies and links to their home pages. A more private person can leave the profile empty, revealing only their TypeKey username, which appears next to their comments.

Acquiring a TypeKey Token

By design, TypeKey provides very little user information with participating weblogs.

When a user signs in to post a comment, TypeKey asks whether that person’s e-mail address should be revealed to the weblog. Weblogs can be configured to refuse users who do not agree to share their e-mail address during the authentication process.

Before you can enable TypeKey on a weblog that you publish, you must create your own account with the service, which you might have done already when downloading Movable Type.

Your account includes a unique TypeKey token that must be specified in the weblog configuration. To acquire your token and associate it with from one to five of your weblogs, follow these steps:

  1. Visit TypeKey with your Web browser at http://www.typekey.com and log in.

  2. On the Account Preferences page, scroll down to the Your Weblog Preferences section of the form (see Figure 10-4).

    Click To expand
    Figure 10-4: Choosing a weblog’s comments settings.

  3. Write down your TypeKey token or copy it for pasting; you’ll need this information later.

  4. Type the URL of your weblog’s home page in the first empty text field in this section.

    Gotcha

    Take care to avoid an extremely frustrating error you can make at this point: Be sure to include a trailing slash at the end of the URL (in other words, something like http://www.example.com/ instead of http:// www.example.com). If you don’t, when users try to sign in, they will be told that your weblog hasn’t been enabled to use TypeKey.

  5. Use the remaining text fields for the home page of any other weblog on which TypeKey will be employed.

  6. Click the Save Changes button.

When you configure a weblog’s comments policy, you must add your TypeKey token to its configuration if you will be using the service.

Deciding Whether to Use the Service

TypeKey’s introduction has received a mixed reaction from weblog publishers and readers. Many Web users have privacy concerns about centralized authentication services, and there’s also the open question of whether the service can support thousands of sites and their visitors.

One way to benefit from TypeKey is to allow your visitors to use the service without making it a requirement to post comments.

Visitors who want to demonstrate their own identities can sign in with TypeKey, preventing others from posting with their chosen username and contact information. Others can participate without signing in, filling out the name, e-mail address, and home page fields with information that isn’t verified in any manner.

I’ve adopted this approach on a weblog that received more than 20,000 comments in four months, including dozens of objectionable comments, spams, and a message-flooding attack by a user hoping to prevent a discussion from taking place.

On the site, several users complained about people masquerading as them by claiming the same name and e-mail address. TypeKey authentication provides a solution to that problem and helps registered users stand out in comments, making it easier to spot the more dedicated contributors to weblog discussions.


Setting a Comment Policy

A good weblog is a conversation between publisher and audience. The weblogging medium lends itself to an engrossing dialogue that grows stronger over time—like a regular newspaper columnist, a weblogger can inspire a loyal and dedicated following.

Often, this dialogue takes place via e-mail, which can be referenced in weblog entries but is ordinarily private. Many webloggers eschew comments or have turned the feature off after trying it out.

A more assertive way to encourage dialogue is to turn on comments, either as a standard policy for all of your weblog entries or on an entry-by-entry basis.

A new Movable Type weblog allows comments for each weblog entry, displays comments in chronological order, and does not make use of TypeKey.

To establish your weblog’s comment policy, follow these steps:

  1. Click the Weblog Config button in Movable Type’s sidebar menu. The Core Setup page loads.

  2. Click the Preferences link, and then click the Comment Configuration link to jump directly to that section, shown in Figure 10-5.

    Click To expand
    Figure 10-5: Refining the settings for a weblog’s comments.

  3. Use the Accept Comments from Unregistered Visitors checkbox to decide whether to require TypeKey.

  4. If you allow unregistered comments:

    1. Select the Require Name and Email Address Information checkbox if you want to require users to fill out both of these fields.

    2. Select the Enable Unregistered Comment Moderation checkbox if you like to hold newly submitted comments in a queue until you have reviewed and approved them.

  5. Use the Accept Comments from Registered Visitors checkbox to make use of TypeKey.

  6. If you allow TypeKey:

    1. Fill out the TypeKey Token field with your token.

    2. Select the Enable Auto-Approval checkbox to allow TypeKey users to post comments immediately upon signing in. Otherwise, their first comment must be approved.

    3. Select the Require Email Addresses From TypeKey checkbox to reject TypeKey users who do not share their e-mail address with you.

    With your comments policy set, you can customize the presentation of comments using the remaining options on the form, which are shown in Figure 10-6.

    Click To expand
    Figure 10-6: Customizing how comments are presented.

  7. In the “Allow Comments” Default drop-down menu, choose a default value for new entries: Open to accept comments or None to refuse comments. (You also can choose Closed, which stops accepting comments on an existing discussion, but that doesn’t apply here.)

  8. Use the Comment Listing Order drop-down menu to decide whether comments should be displayed in chronological order (Ascending) or the reverse (Descending).

  9. Select the Allow HTML in Comments checkbox to allow users to include selected HTML markup tags in their comments: a href, b, blockquote, br, em, li, p, strong, and ul.

  10. 10.If you are not allowing HTML, select the Auto-Link URLs checkbox to add hyperlinks to URLs that appear in comments.

  11. 11.To keep on top of comments by receiving an e-mail each time a new comment has been submitted, a feature that could quickly fill an inbox on a popular site, select the Email New Comments checkbox.

  12. 12. You’re done! Click the Save Changes button to finish setting up comments on the weblog.

The presentation order of comments applies only to a new weblog’s default templates. You can set up a different order and make other changes using comment template tags, which are covered later in this chapter.

The HTML tags allowed in comments are determined by the GlobalSanitizeSpec setting in mt.cfg, Movable Type’s main configuration file, which can be found in the same directory that holds mt.cgi and the software’s other scripts.

If you want to add or remove tags, open the file with a text editor and find the following line:

# GlobalSanitizeSpec br/,p

This setting contains a list of HTML and XHTML tags that can be included in comments, separated by commas. The pound character (#) that begins the line causes it to be treated as a comment and ignored, which indicates that Movable Type should use the default list.

The following setting allows five HTML tags:

GlobalSanitizeSpec a href, b, br, i, p

When a listed tag includes one or more attributes, as a href does, this indicates that the href attribute can be used with the a tag, which permits users to use HTML markup to indicate hyperlinks.


Managing Comments and Banning Users

The release of Movable Type 3 brings two new buttons to the sidebar menu—Comments and Commenters—the entry points to the software’s improved comment- and user-management capabilities.

The Comments button opens a comments page that’s similar to the entry-editing page, displaying the 20 most recent comments and information about their authors (see Figure 10-7).

Click To expand
Figure 10-7: The page for managing visitor comments.

Comments on the page can be filtered in several ways to find something more quickly:

  • Click a TypeKey user’s Filter icon to view comments by that user.

  • Click an unregistered user’s name to view comments submitted with that name.

  • Click an entry’s Filter icon to view all comments it has received.

  • Click an IP address’s Filter icon to view comments submitted from that address.

You also can use the drop-down menus and Filter button atop the table of comments to select comments associated with a specific name, e-mail address, or IP address.

The Status column of the comments page indicates whether a comment has been approved, awaits your approval, or was submitted by a banned user.

To view a comment, click its link in the Comment column. An Edit Comment page opens, as shown in Figure 10-8.

Click To expand
Figure 10-8: Viewing and editing visitor comments.

On a weblog configured to hold new comments in an approval queue, an Approve button lies alongside Delete and Save. Use it to make the comment public, (An Approve Comment button also appears on each queued item in the main comment page, as you can see by referring to Figure 10-7.)

Every field in an unregistered comment can be edited, including the author’s name and e-mail address. Fields cannot be edited on a registered TypeKey user’s comment.

Banning an IP Address from a Weblog

Comments submitted to Movable Type include the Internet Protocol (IP) address of the machine from which they were sent. The address, most commonly represented as a series of four bytes separated by commas, such as 66.216.96.146, serves as a unique numeric address for an Internet-connected device.

The domain-name system makes it unnecessary for most Internet users to deal with these addresses, because it maps them to more memorable host names. For example, the host sixapart.com corresponds with the IP address 66.216.96.146. Typing http://sixapart.com in a Web browser loads the home page of the Web server at that address.

You can filter comments based on an IP address and often—but not always—see what a single unregistered user has written on your weblog, even if that person signs different comments with different names.

On an Edit Comment page, click the View All Comments from This IP Address link to see how that address has been used on your weblog.

In some cases, you can deal with a comment spammer or another troublemaker by banning the IP address associated with that person. Before you begin doing this, however, you should be aware of the limitations of this approach.

Most Internet users have IP addresses that are assigned dynamically each time they connect. This is especially true of people using dial-up connections and large Internet service providers such as America Online and EarthLink.

This is less common among high-speed Internet users who are given a fixed IP address or one that does not change very often.

If you ban a meddlesome user’s IP address, in many cases that person will be able to submit comments the next time they connect to the Internet, because their IP address will be different.

A less likely scenario is also possible: You ban an IP address and an innocent user who happens to be assigned that address cannot post comments on your site.

When you have filtered comments by IP address, a Ban This IP button appears below the comments (see Figure 10-9).

Click To expand
Figure 10-9: Tracking the use of IP addresses by comment authors.

Click the Ban This IP button to make it impossible for comments to be submitted from that address in the future.

An IP Banning page displays banned addresses along with the date they were blocked. (To see this page later, click the Weblog Config sidebar menu button, and then click the IP Banning link atop the Preferences page.)

You can use this page to remove a banned address from the database later, accepting comments from that address again.

Tip

Because IP addresses are so commonly assigned to different users over time, you can minimize the chance of blocking innocent users by releasing banned addresses periodically. In most cases, a comment spammer or a user posting offensive content will move on to other sites after being banned, so there’s no reason to keep blocking a particular address for more than a few weeks.

Banning a TypeKey User

As you would expect from an authentication service, TypeKey identifies comment authors clearly, removing the need to puzzle through IP address information if you decide to boot them from your weblog.

When a TypeKey user signs in to a weblog for the first time, Movable Type adds that person to the weblog as a commenter, a user who has permission to post comments.

If you’re moderating new comments, you must approve a new user’s first comment before it will appear on your site. From that point on, comments will be approved automatically.

To see the TypeKey users who have joined your weblog, click the Commenters button in the sidebar menu. They’ll be listed on a page along with a link to their TypeKey profile page and a Ban User or Approve User link. Use these links to grant or deny access to that user.

You also can take these actions while viewing a comment by a TypeKey user. On the Edit Comment page, a red Ban User button appears next to the user’s name (see Figure 10-10).

Click To expand
Figure 10-10: Banning a TypeKey registered user from making comments.

Click the button to ban the user (which can be undone by clicking a green Approve User button taking its place).

Although TypeKey makes it easy to identify and ban a problem user, a determined person can circumvent a ban by setting up a new TypeKey account using a different e-mail address.

Movable Type’s new comment-management features help weblog publishers find and remove undesired comments and users, but they aren’t a cure-all. You will still need to keep an active hand in a popular weblog that allows public comments.

Settling on a Comment Policy

With so many new options for comment management in Movable Type 3, a publisher starting out with the software might have trouble choosing the right policy.

The most restrictive approach: Require all users to register with TypeKey and place comments in a moderation queue until they can be personally approved.

The least restrictive approach: Allow users to make comments without registering, even if they don’t provide a name and e-mail address.

The more restrictive your comments policy, the less feedback you will receive from your visitors. Because so many Movable Type weblogs have adopted TypeKey, you might be able to require that registration service without discouraging responses. Anyone who has registered for TypeKey can log in with a few clicks and write a comment on your weblog.

Comment moderation inhibits the spontaneity that most people have come to expect from weblogs. If you hold on to comments in this manner, visitors won’t see their contribution immediately published on your site and are less likely to contribute in the future.

On my weblog, I allow unregistered comments. I want as much reader feedback as possible and have the time to weed out abusive or inappropriate comments. In addition, on the occasions when I can’t remove an undesirable comment quickly, there’s little harm done because it’s just my personal site.

On a weblog that I set up for a successful e-commerce site, all visitors must register with TypeKey to submit comments, and they are placed in a moderation queue. Such a site can’t afford to appear unprofessional by allowing unfiltered comments.


Using Comment Template Tags

Comments are presented in a Movable Type template with MTComments, a container tag that can hold comments for an entire weblog or the responses to an individual weblog entry.

The lastn attribute limits the container to the specified number of comments. For example, using lastn=”10” causes the container to hold the last 10 comments.

The context in which the MTComments container appears determines the comments that it holds. On an individual archive template or comment template, it holds an entry’s comments. On an index template or anywhere else, it holds all of a weblog’s comments.

Comments in the container are ordered based on the Comment Listing Order setting in the weblog’s configuration. When set to ascending order, the first comment is the oldest and the order proceeds chronologically. When set in descending order, the newest comment starts the order.

This order can be overridden with the container tag’s sort_order attribute, which should be ascend or descend.

Within the MTComments container, the template tags in Table 10-1 present different aspects of each individual comment.

Table 10-1: Weblog Comment Tags
Tag | Attributes | Description
MTCommentAuthor | none | The author of the comment
MTCommentAuthorLink | show_email, show_url, spam_protect, no_redirect | A hyperlink associated with the author, which can be associated with a home page or e-mail link
MTCommentBody | convert_breaks | The text of the comment
MTCommentDate | format, language | The date and time the comment was submitted
MTCommentEmail | spam_protect | The e-mail address of the author, which can be disguised by setting spam_ protect equal to 1
MTCommentEntry | none | The entry to which the comment was made
MTCommentEntryID | none | The ID number of the comment’s entry
MTCommentID | Pad | The address (URL) of the category’s main archive page, which can be padded with zeroes (0s) using the pad attribute
MTCommentIP | none | The IP address from which the comment was submitted
MTCommentOrderNumber | none | The position of the comment relative to other comments in the container
MTCommentURL | none | The address (URL) of the author’s home page

The MTCommentURL and MTCommentEmail tags produce the comment author’s home page and e-mail address, as provided by the user (if unregistered) or by TypeKey.

The MTCommentAuthorLink tag contains a hyperlink on the text of the author’s name. The address of this link depends on the MTCommentURL and MTCommentEmail tags:

  1. For an author with a home page address, MTCommentAuthorLink links to that page.

  2. For an author with an e-mail address but no home page, MTCommentAuthorLink is a mailto link to that address. This behavior can be overridden by the tag’s show_email and show_url attributes, which each can be set to 1 for that address to take precedence.

  3. If neither a home page nor an e-mail address is provided, MTCommentAuthorLink is the author’s name with no link.

Both e-mail-related tags have a spam_protect attribute that disguises addresses, making them somewhat more difficult for a spammer’s address-collecting software to find.

When a comment author provides a URL, Movable Type hides it with a redirection script. This changes the link from the author’s URL to a link like the following:

http://prefect.com/cgi-bin/mt-comments.cgi?__mode=red;
id=40063

Clicking this link loads the mt-comments script, which immediately loads the author’s URL. This occurs to provide less incentive for spammers to post comments to Movable Type weblogs simply to boost their rankings in search engines such as Google.

The MTCommentURL tag’s no_redirect attribute, when set to 1, changes this behavior, displaying the comment author’s URL with no attempt to disguise it.

Cross-Reference

The MTCommentDate tag employs the same format and language attributes in place for all date and time template tags. They are described in Chapter 8, “Producing Web Pages with Template Tags,” in the section “Formatting Date and Time Tags.”


Presenting Comments in a Template

The most common place to put an MTComments container is within the Individual Entry Archive template that generates all of the entry pages for a weblog.

Comments stored within the container, which can be used with no attributes, will be all of the entry’s responses (or a maximum number determined by a lastn attribute).

Listing 10-1 contains template code to display all of an entry’s comments with HTML.

Listing 10-1: Displaying an Entry’s Comments
Start example
<h2><a id="comments"></a>Comments</h2>

<MTComments>
<a id="c<MTCommentID>"></a>
<MTCommentBody>
<p class="posted">Posted by: <MTCommentAuthorLink spam_protect="1">
<MTCommentAuthorIdentity> at <MTCommentDate></p>
</MTComments>
End example

Figure 10-11 shows a Web page produced from this template.

Click To expand
Figure 10-11: Displaying comments on an entry page.

Here’s a look at the HTML produced for the comment circled in Figure 10-11 for comparison to the template:

<h2><a id="comments"></a>Comments</h2>

<a id="c18798"></a>
<p>Don’t blame him, that’s one sexy Renault.</p>

<p class="posted">Posted by: <a href="mailto&#58;
yeah&#64;example&#46;com">yeah</a>
 at April 23, 2004 09:57 PM</p>

Each comment produced by the template has an anchor tag: the letter “c” followed by the comment’s ID number. This makes it possible to jump directly to the comment with a hyperlink.

The template in Listing 10-2 can be used as an index template, adding a Web page to the site devoted to comments.

Listing 10-2: Reviewing Recent Comments
Start example
<MTComments lastn="200" sort_order="descend">
<MTCommentEntry>
<div class="entryhead"><a href="<MTEntryLink>">
<MTEntryTitle></a></div>
<div class="comments-body">
<p><MTCommentBody></p>
</div>
<p><span class="entryfooter"><MTCommentAuthorLink spam_protect="1"> |
<a href="<MTCGIPath>mt.cgi?__mode=view&_type=comment&id=<MTCommentID>
&blog_id=<MTBlogID>">Edit</a> | <a href="<MTEntryLink>#reply">
Reply</a> |
</MTCommentEntry><MTCommentDate></span><br clear="all">
</MTComments>
End example

A page produced from this template presents the 200 most recently submitted comments to any of the weblog’s entries.

The template includes an Edit link in each comment that loads it for editing or deletion. The following HTML markup produces the link:

<MTCGIPath>mt.cgi?__mode=view&_type=comment&id=<MTCommentID>
&blog_id=<MTBlogID>

The MTCGIPath tag contains the path used to access Movable Type scripts. The MTCommentID and MTBlogID tags provide the numeric ID numbers for the comment and weblog, respectively.


Summary

If you read this chapter before deciding whether to open comments on a weblog, you might be understandably more hesitant to do so. As this weblogging tool became popular enough to bring spammers out from under their rocks, the software’s original comment-management capabilities sometimes proved insufficient. A popular weblog can receive hundreds of comments a day, bringing a raucous online community into existence. Add spam, message flood attacks, and other undesirable content, and comments become one of the more challenging aspects of a Movable Type weblog to handle, even as they define the site and keep visitors coming back.

Enter Movable Type 3.

The addition of TypeKey user authentication makes it possible to limit participation on Movable Type weblogs to users who have a central account with Six Apart’s new service. Members of that audience are more easily blocked from your site, if necessary, and presumably are less likely to behave abusively, because they could lose an account that covers hundreds of weblogs.

The software’s expanded comment-editing and user-maintenance capabilities make it considerably easier to review the user-contributed content on a site.

Although you might still think an actively commented weblog feels like an asylum, Movable Type’s comment features should at least ensure that you’re the one running the place.


Chapter 11: Sharing TrackbackLinks

In This Chapter

  • Communicating with other sites through trackback

  • Deciding whether to receive trackback pings

  • Displaying trackback entries on a page

  • Supporting trackback autodiscovery

  • Deleting unwanted trackback pings

  • Receiving e-mail when pings arrive

  • Setting up a trackback-aware bookmarklet

  • Sending a trackback ping

  • Creating a trackback aggregator

  • Using trackback template tags

Publishing a weblog is an act of membership. You might not have realized it at the time, but when you launched your weblog on the World Wide Web, you were joining a loosely organized, decentralized network of like-minded publishers that’s thousands of sites deep.

A big reason for the phenomenal success of weblogs is the medium’s viral nature. Every writer of weblogs begins as a reader of one. You like what you see, decide it would be a fun or easy or useful thing to do, and then take up the form yourself. By the time you recognize the implications of what you have done—the addictive nature of the form and the enjoyable rigors of writing regularly for an audience—it’s often too late. You’re hooked.

Webloggers gravitate to people who share their interests, outlook on life, or some other point of commonality. Like-minded webloggers become connected by linking to and talking about each other’s sites.

Some of these links are placed on blogrolls, lists of bookmarks to an author’s favorite weblogs and other sites. Other links might be more specific, such as when a weblogger writes an entry in response to something on another weblog, linking to it so his audience can hop from site to site following the conversation.

This distributed form of discussion is encouraged by trackback, an innovative protocol that enables a weblogger to let other webloggers know they are being discussed.

Movable Type can be used to send and receive trackback information, building real-time connections between weblogs and other sites.


Connecting Weblogs Together with Trackback

The developers of Movable Type invented trackback in 2002 and offered the protocol for unrestricted use by other weblog software developers, hoping to encourage its adoption as a standard.

The plan worked. Trackback is now supported by Radio UserLand, Manila, Blosxom, Nucleus, B2, Haloscan, and a host of other software and service providers.

However, the growth of trackback has been slowed by the difficulty its admirers face when trying to explain the feature to others. Telling someone what trackback is and how it works can be a daunting experience. “I don’t know what it is about trackback that makes it utterly impossible for anyone to explain it well,” laments Tom Coates on the Plasticbag weblog (http://www.plasticbag.org).

Here’s another attempt to explain trackback, made a little easier by the fact that you’ve already come this far in your study of Movable Type: In its simplest form, trackback is a means of sending a message that lets another weblogger know you’re writing about them.

A trackback message, which is called a trackback ping, conveys three pieces of information from its sender to another weblogger:

  • I have written an entry about something I read on your weblog.

  • Here’s a text excerpt of what I have written.

  • Here’s a link to my full weblog entry.

The information is sent with the expectation that the recipient will publish it on his or her weblog. The typical way to present trackbacks is to include them with the relevant entry in a manner similar to visitor comments, as shown in Figure 11-1.

Click To expand
Figure 11-1: Presenting trackback links on a weblog.

This process of collecting and publishing trackback links is usually, although not always, automatic.

Figure 11-1 shows how trackback links are presented on MovableBLOG, a weblog by Richard Eriksson (http://www.movableblog.com). His site is devoted to poking around Movable Type, and when he wrote an entry reviewing Six Apart’s TypePad hosting service, his review was discussed on six other weblogs. These weblogs sent trackback messages to Ericksson’s server that were received by Movable Type and saved to his weblog’s database.

As a means of receiving feedback on your work, trackback is comparable to receiving comments in response to an entry—but in this case the comments are hosted on someone else’s weblog. On MovableBLOG, Ericksson presents trackback links on the same page as comments, enabling his visitors to see the kind of feedback each of his entries has received. Mena and Ben Trott, the inventors of the protocol, call it a form of remote commenting.

A trackback message is delivered to a server hosting a weblogger’s site through the use of a trackback URL, the Web address of a script that understands trackback and can do something useful with the information. The trackback URL identifies the entry that is being discussed on another site.

In most cases, you don’t need to know the trackback URL of a weblog entry you are writing about on your site. Movable Type can determine it when you publish the entry. The software accomplishes this by loading every Web page you’ve linked, and then checking for code that indicates support for trackback.

When automatic support for trackback has been set up on two weblogs, they can exchange trackback links merely by writing about each other. No extra work is required on either end.

In other circumstances, trackback requires a bit more toil.


Receiving Trackback Pings from Other Weblogs

A Movable Type weblog accepts only trackback pings on entries that have been set up to receive them. Otherwise, incoming trackback attempts from other sites are ignored.

An entry’s trackback policy is established with the Accept trackback Pings checkbox on the entry-editing form, which can be found near the bottom of the form, as shown in Figure 11-2.

Click To expand
Figure 11-2: Setting a weblog entry’s trackback policy.

Enable the Accept Trackback Pings checkbox to receive pings from other sites for that individual entry. Disable the checkbox to ignore them.

When a trackback ping has been received for an entry that accepts them, Movable Type stores everything in the message in the weblog’s database: the title, link, text excerpt, and weblog name.

The default value for the Accept Trackback Pings checkbox can be either enabled or disabled, making it easier on authors who do the same thing with trackback most of the time.

To set this preference, follow these steps:

  1. Click the Weblog Config menu button. The Configuration page opens.

  2. Click the Preferences link. The Configuration Preferences page is displayed.

  3. Click the Publicity/Remote Interfaces/Trackback link. The page scrolls down to the section dealing with trackback, as shown in Figure 11-3.

    Click To expand
    Figure 11-3: Choosing a default trackback policy for new entries.

  4. Make a selection in the Allow Trackback Pings On by Default checkbox.

  5. Scroll to the bottom of the page and click the Save button.

The trackback policy for an entry can be changed at any time by editing the entry. This policy specifies whether new trackbacks will be accepted, but it doesn’t cause existing trackback links to be removed from the weblog’s database.

The presentation of trackback entries on a Movable Type weblog is determined by the site’s templates, the raw material used to create all the Web pages and other files that make up the site.

Templates are edited by choosing the Templates menu button. A weblog’s Main Index template dictates the appearance of the home page. The first trackback-related HTML code on this page is shown in Listing 11-1.

Listing 11-1: Trackback Pop-Up Window Script
Start example
<script language="javascript" type="text/javascript">
function OpenTrackback (c) {
  window.open(c,
    ‘trackback’,
    ‘width=480,height=480,scrollbars=yes,status=yes’);
}
</script>
End example

The code in Listing 11-1 contains a script written in JavaScript that opens a pop-up window 480 pixels wide and 480 pixels tall that includes scrollbars and a status bar. The script is called to display an entry’s trackbacks when a visitor clicks its trackback link.

As described in Chapter 9, “Designing a Weblog with Templates,” Movable Type templates mix static text such as HTML formatting, XML data, and CSS styles with special Movable Type tags. These tags, which look like ordinary HTML tags, all have names that begin with the letters MT. Some may also begin and end with the dollar sign ($) character to make them stand out from HTML tags (for example, <$MTBlogName$>, which can be referred to also as <MTBlogName>).

The job of Movable Type tags is to create content and make decisions when the template is rendered as an output file.

On the Main Index page, Movable Type entries are presented by placing them within opening and closing MTEntries tags, as shown in the following example:

<MTEntries lastn=”3”>
<div>
  <h3><MTEntryTitle></h3>
  <MTEntryBody>
</div>
</MTEntries>

This code can be used in a template to display the title and body of the last three weblog entries (the quantity is established by the lastn attribute of the MTEntries tag).

In a template, everything placed within the opening and closing MTEntries tags relates to an individual weblog entry. When a weblog supports trackback, one of the things that must be placed within these tags is an MTEntryTrackbackData tag.

The MTEntryTrackbackData tag produces RDF data that enables trackback software to determine how to send your weblog a trackback ping. An example of this data is shown in Listing 11-2.

RDF, which stands for Resource Description Framework, is an XML dialect that provides information about information. Here, RDF tells the software all it needs to know to send a trackback ping for a weblog entry entitled “Dining in Orlando’s Rainforest Cafes” on the Orlando Vacationer weblog.

Listing 11-2: A Trackback Entry’s RDF Data
Start example
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:trackback="http://madskills.com/public/xml/rss/module/
trackback/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<rdf:Description
    rdf:about="http://www.orlandovacationer.com/archives/000076.html"
    trackback:ping="http://www.cadenhead.org/cgi-bin/mt-tb.cgi/76"
    dc:title="Dining in Orlando&apos;s Rainforest Cafes"
    dc:identifier="http://orlandovacationer.com/archives/000076.html"
    dc:subject=""
    dc:description="Theme Park Insider reviews the Rainforest Cafe restaurants
at Disney World Animal Kingdom and Downtown Disney in Orlando: If
you’ve heard anything about the Rainforest Cafe, it’s likely been
the atmosphere, first and foremost. The entire restaurant is
themed to..."
    dc:creator="rcade"
    dc:date="2004-01-27T13:51:10-05:00" />
</rdf:RDF>
End example

You don’t need to know anything about RDF or this data format. Just put the MTEntryTrackbackData tag in the right place on a template and let Movable Type take care of the rest.

The last thing that a template requires to support trackback is a link to the pop-up window in which received trackbacks will be displayed. The default Main Index template presents this link with the word trackback, followed by the number of trackbacks in parentheses. The template employs five Movable Type tags and some HTML, as you can see in Listing 11-3.

Listing 11-3: Linking to an Entry’s Trackbacks
Start example
   <MTEntryIfAllowPings>
   | <a href="<$MTCGIPath$><$MTTrackbackScript$>?__mode=view&amp;
entry_id=<$MTEntryID$>" onclick="OpenTrackback(this.href);
return false">TrackBack (<$MTEntryTrackbackCount$>)</a>
   </MTEntryIfAllowPings>
End example

The MTEntryIfAllowPings tag makes a decision: If the entry allows trackback pings, everything within its opening and closing tags will be output when the template builds a file. Otherwise, everything inside the tags will be ignored. As you might have surmised, an entry’s Accept Trackback Pings preference drives this decision.

The other four tags provide information that’s used in the pop-up window link:

  • MtEntryTrackbackCount holds the number of trackbacks received about the entry.

  • MTCGIPath contains the Web address of the folder in which Movable Type’s scripts have been installed.

  • MTTrackbackScript contains the name of the trackback script.

  • MTEntryID holds the entry’s numeric ID.

All of the Movable Type and HTML tags work together to form a single TrackBack (x) link like this one:

| <a href=”http://www.cadenhead.org/cgi-bin/mt-tb.cgi?__mode=view&amp;
entry_id=76” onclick=”OpenTrackback(this.href);
return false”>TrackBack (0)</a>

When a visitor clicks the link, JavaScript code in the onclick attribute calls the OpenTrackBack() function, opening a pop-up window that displays all of the trackbacks.

Trackback functionality also must be included in each archive template used by a weblog. The Date-Based Archive and Category Archive require the same code described for the Main Index: a script to open a pop-up window, a tag inside MTEntries to produce RDF data, and tags to count trackback links and open the pop-up.

The Individual Entry Archive holds only a single weblog entry, so it doesn’t make use of the MTEntries tag.

On this archive template, the MTEntryTrackbackData tag can be placed anywhere. The default template puts it in the page’s header between the opening and closing HTML head tags.

Gotcha

Because the Accept Trackback Pings preference appears to turn trackback support on and off, it’s easy to reach the incorrect conclusion that this is all you must do to receive trackback pings. In reality, Movable Type templates must contain code that does something with those pings. If you remove that code or change to a template without trackback support, you won’t see any of your trackback links regardless of how Accept Trackback Pings is set.

Managing Trackback Pings

Like everything else on the Internet that accepts contributions from unknown sources, a trackback-enabled weblog poses a tempting point of attack for spammers, net abusers, and other creeps. The popularity of Movable Type has even prompted some malicious programmers to create software that targets its weblog’s trackback and comment features, posting unwanted commercial advertisements and other junk on hundreds of sites.

The current version of Movable Type provides only two ways to deal with unwanted trackback pings. You can delete the ping or ban the IP address of the sender, if you can determine that information.

To delete a trackback ping, you must edit the entry that received the ping:

  1. Click the Edit Entries menu button. The List & Edit Entries page opens, displaying a list of the most recently published entries.

  2. If you can’t find the entry, look for it by clicking the Next 20 button at the bottom of the page or the search box at the top.

  3. Click the entry’s link. The entry-editing form opens.

  4. Scroll down to the Manage Trackback Pings section (see Figure 11-4).

    Click To expand
    Figure 11-4: Deleting a trackback ping.

  5. To see a trackback ping, click its title.

  6. To remove a ping, check its Delete box, and then click the Delete Checked button. A confirmation dialog ensures that you really want to delete it.

After deleting a trackback ping, you must rebuild the site so that the modified index and archive pages are created.

Receiving E-Mail Notification

You might want to keep a particularly close eye on incoming trackback pings, especially if you’ve set the feature up recently or have been discovered by spammers.

You can receive e-mail each time a trackback ping arrives and is added to your weblog. This feature, which is off by default, can be enabled easily:

  1. Click the Weblog Config menu button. The Configuration page is displayed.

  2. Click the Preferences link. The Configuration Preferences page opens.

  3. Click the Publicity/Remote Interfaces/Trackback link. The page scrolls down to the section dealing with trackback, which was shown in Figure 11-3.

  4. Enable the Email New trackback Pings checkbox.

  5. At the bottom of the form, click the Save button.

The e-mail notification will be sent to the address in your user profile. You’ll receive an e-mail that contains the trackback text, link, and excerpt along with one piece of information that isn’t available from Movable Type’s browser-based interface: the IP address from which the ping arrived.

You can now reject future pings from that source.

Banning Trackback Pings from Specific IP Addresses

Trackback pings, like comments, can be rejected based on the Internet Protocol (IP) address of the sender. This technique has its limits, but in some situations it might help curb abuse of your weblog.

Although IP address banning has very little usefulness for comment abuse, as described in Chapter 10, it can be more effective in curtailing unwanted trackback pings.

Because these pings usually originate from Web sites, they’re more likely to come from an IP address that stays the same for an individual source of those pings. Most Web sites are hosted at the same IP address for months or even years (my own Linux server has been at the same one for at least three years). If you’ve identified a weblog from which you don’t want to accept trackback pings, you can ban the IP address that originates its pings. Future pings will still be sent, but they will be rejected automatically. The sender won’t receive a notification that this has occurred, but might take note of the fact that the trackback ping hasn’t shown up on your site.

Each of your weblogs has its own banned IP list, which starts out empty when the site is created.

Here’s how to add and remove IP addresses from banishment:

  1. Click the Weblog Config button. The Preferences page appears.

  2. Click the IP Banning link. A list of banned addresses is displayed below a form in which you can add more, as shown in Figure 11-5.

    Click To expand
    Figure 11-5: Managing a weblog’s banned IP list.

  3. To ban an address, enter it in the IP Address text field and click the Add button.

  4. To release an address from the banned list, enable the Delete checkbox next to it, and then click the Delete button.

The banned IP list works only on senders who stick to the same address, a group that primarily consists of Web sites that run trackback software and the small number of individuals who use fixed IP addresses provided by jobs, schools, and some high-speed Internet services.

Unfortunately, some of the worst trackback abuse comes from software run by people on their own computers. This crowd is likely to be connecting from dial-up Internet services and other accounts that provide a different IP address upon each connection. By the time you have banned an address, the person who used it could have reconnected to the Internet using another address.

Another drawback to banning by IP address is the possibility that an innocent user might be stopped from sending a trackback ping. Internet service providers reuse IP addresses among their customers, so an address that you have banned might be given to a legitimate user.


Sending Trackback Pings for Each Entry

Where trackback is concerned, it’s easier to give than to receive.

Sending a trackback ping to another site often requires no work at all, thanks to Movable Type’s trackback autodiscovery feature.

Autodiscovery works like it sounds—when you publish a new entry, the software checks each link in the entry, determining whether the linked site supports trackback. If it does, a trackback ping is sent to that site automatically.

This process slows down the publishing process a little, because Movable Type must download each linked page and inspect it for the same kind of RDF data you put on the pages of your weblog (as illustrated in Listing 11-2). You must turn the feature on for each weblog that will use autodiscovery:

  1. Click the Weblog Config menu button.

  2. Click the Preferences link.

  3. Click the Publicity/Remote Interfaces/Trackback link. The last item in this section is the Enable Trackback Auto-Discovery preference.

  4. Enable the checkbox, and then scroll to the bottom of the page and click the Save button.

With autodiscovery enabled, you’ll see a Pinging Sites page after publishing an entry like the one shown in Figure 11-6. Movable Type lists all of the pings that are sent out for trackback and other kinds of notification.

Click To expand
Figure 11-6: Watching as trackback pings are sent.

If the trackback ping succeeds, you often will find it reflected immediately on the receiving site, as Movable Type does with incoming trackbacks. Other weblog publishing software might handle them differently.

Tip

There’s a link at the bottom of the entry-editing form that can be used to verify successful ping attempts. Open the entry for editing, and then scroll to the bottom of the form and click the Previous Pings Sent link. A pop-up window displays all pings that were acknowledged by the receiving site.

When a trackback ping fails, it is noted in Movable Type’s activity log. To check the log, click the Menu button, and then click the View Activity Log link.

Setting Up Manual Trackback Pings

When autodiscovery determines whether a linked page supports trackback, Movable Type collects several kinds of information from the RDF data it finds on a page. The most important is the trackback URL, a special Web address that identifies the reason a ping is being sent.

On a trackback-enabled Web site, everything that can be pinged is identified by a unique trackback URL. Often, you’ll see these URLs as you browse a site—Movable Type’s default templates display them in the pop-up window listing trackbacks received by each entry.

Figure 11-7 shows how trackback URLs are displayed on Richard Eriksson’s MovableBlog.

Click To expand
Figure 11-7: Displaying an entry’s trackback URL.

Once you know a trackback URL, you can use it to send a trackback ping manually when you write a new entry. Although this isn’t needed often because of autodiscovery, there are special uses of trackback for which it becomes useful, as you’ll see in the next section.

A trackback URL can be specified manually in the URLs to Ping field at the bottom of the entry-editing form (see Figure 11-8).

Click To expand
Figure 11-8: Specifying trackback URLs with an entry.

Enter one or more trackback URLs in the URLs to Ping field, placing each one on its own line. When the entry is published, each of these URLs will be used to make a ping attempt.


Contributing to a Trackback Content Aggregator

Trackback has become the most popular form of link exchange and site-to-site discussion among weblog publishers, but that’s only one kind of interchange the protocol makes possible.

Ironically, when trackback was devised by Mena and Ben Trott, they had an entirely different use in mind. As they state in their documentation for the protocol, trackback was envisioned as a way to gather related Web content together, no matter where it is published.

“This was actually the original intended use of trackback—the remote commenting grew out of a special case of a topic-based repository, the ‘topic’ being a single weblog post,” they write. “Content aggregation sites collect content about a particular topic.”

What they describe as a content aggregator is a Web site or service that monitors one or more topics through the use of trackback. Each topic has its own trackback URL, enabling any software that sends trackback pings to contribute to that topic.

The Internet Topic Exchange, a Web site at http://topicexchange.com, is a trackback-powered content aggregator. The site collects weblog entries about hundreds of topics, accepting new ones created by its registered users.

One such topic is Google, which has been designated the trackback URL http://topicexchange.com/t/google/ (the trailing slash is important).

If you write a weblog entry about Google and you want it to be included in the Exchange’s Google topic, put that trackback URL in the URLs to Ping field of the entry-editing form (shown in Figure 11-8). If you want to include your entry in several topics, put each of their trackback URLs in the field, one to a line.

When your entry is published, the Exchange receives the trackback ping and adds your post to the topic. More than 500 entries have been added to the Google topic, which is presented like a weblog, as you can see in Figure 11-9.

Click To expand
Figure 11-9: Collecting weblog content from multiple sites by means of trackback.

Other content aggregators are more specialized than the Internet Topic Exchange. The Web site BlogRoots, a weblog devoted to weblogging at http://www.blogroots.com, accepts submissions offered through trackback. If you write something on your weblog that’s on topic for BlogRoots, you can submit it simultaneously to BlogRoots by pinging the trackback URL http:// www.blogroots.com/tb_populi.blog?id=1.

Collecting Trackback Pings in a Category

If you want to emulate the functionality of BlogRoots or the Internet Topic Exchange, Movable Type can serve as a trackback-based content aggregator.

Any category of your weblog will collect trackback pings if designated for that purpose. All you have to do is configure the category, share its trackback URL with the public, and persuade people to contribute.

You can achieve more control over the process by requiring a password with incoming pings. Any trackback attempts that do not include the password are ignored.

Here’s how to turn a category into a content aggregator:

  1. Click the Categories link. The Categories page opens.

  2. If the category doesn’t exist yet, create it. Type a name for the category in an empty Categories text field, and then click the Save button. The page reloads with your newly created category at the top of the list.

  3. Click the Edit link next to the category. A page opens in which you can add a description and configure the category in other ways.

  4. Scroll down to the Incoming Pings section at the bottom of the form.

  5. Enable the Accept Incoming Trackback Pings checkbox and click the Save button at the bottom of the form. The page reloads with more options in the Incoming Pings section, as shown in Figure 11-10.

    Click To expand
    Figure 11-10: Setting up a category as a content aggregator.

  6. Take note of the category’s trackback URL. This must be shared with any prospective contributor to the content aggregator, just as BlogRoots shares its trackback URL for weblog-related pings.

  7. If the category will be password-protected, type it in the Passphrase Protection text field.

  8. Click Save.

The category will now accept trackback pings. Doing something with this information requires that a template be edited to include the MTPings tag, a Movable Type tag that presents information collected by each trackback ping.

The following HTML code, when placed on a template, presents the last 10 trackback pings received by a category named “Disney World”:

<MTPings category=”Disney World” lastn=”10”>
    <a href=”<MTPingURL>”><MTPingTitle></a>:
    <MTPingExcerpt><br>
</MTPings>

Each ping’s URL, title, and excerpt are presented.

Routing a Category to a Content Aggregator

A category in a Movable Type weblog serves a similar purpose to a topic in a content aggregator, providing a place where related weblog entries can be grouped together.

If you plan to contribute often to a topic on a content aggregator, you can map one of your weblog categories to that topic. Every entry you place in the category is submitted automatically to the aggregator.

In order to do this, you must know the aggregator’s trackback URL and its password, if one is required.

Note

A password will be specified as part of the trackback URL. Content aggregators created with Movable Type receive a password as the last part of the URL. For example, the following trackback URL specifies a password of swordfish:

http://www.cadenhead.org/cgi-bin/mt-tb.cgi/92/ swordfish

If no password were required, the trackback URL would be as follows:

http://www.cadenhead.org/cgi-bin/mt-tb.cgi/92

To route a category to an aggregator, follow these steps:

  1. Click the Categories link. The Categories page appears.

  2. Click the category’s Edit link, which will open a page on which you can configure it.

  3. Scroll down to the Outgoing Pings section.

  4. Fill out the trackback URLs to Ping text field with the trackback URL (see Figure 11-11).

    Click To expand
    Figure 11-11: Sending a category to a content aggregator.

  5. If the trackback URL requires a password, make sure that it is specified as part of the URL.

  6. If you’re routing the category to more than one aggregator topic, type the additional trackback URLs in the same field, placing each one on its own line.

  7. Click Save.


Using Trackback Template Tags

Trackback pings are presented in a Movable Type template in a manner similar to comments. The MTPings container tag holds pings for an entire weblog, category, or individual weblog entry.

The lastn attribute limits the container to the specified number of pings, so lastn=”15” creates a container with the last 10 pings.

The context in which the container appears determines the pings that it holds. The container holds an entry’s pings on an individual archive template, a category’s pings on a category archive template, and all pings in any other context.

The order of pings can be set with the container tag’s sort_order attribute, which should be ascend or descend.

Within the MTPings container, the template tags in Table 11-1 present different aspects of each individual trackback ping.

Table 11-1: Weblog Trackback Tags
Tag | Attributes | Description
MTPingBlogName | none | The weblog that sent the ping
MTPingDate | format, language | The date and time the ping was submitted
MTPingExcerpt | none | The text of the ping message
MTPingID | none | The ping’s ID number
MTPingIP | none | The IP address from which the ping was submitted
MTPingTitle | none | The title of the ping message
MTPingURL | none | The address (URL) of the weblog that sent the ping
MTPingsSent | none | A container holding all ping URLs associated with a weblog entry
MTPingsSentURL | none | A ping URL (must be used within MTPingsSent)

One way to employ an MTPings container is to place it on an Individual Entry Archive template to present all of the entry’s trackback pings (or a finite number set by the lastn attribute).

Listing 11-4 contains HTML template code to display all of an entry’s pings.

Listing 11-4: Displaying an Entry’s Trackback Pings
Start example
<h2><a id="trackback"></a>Pings</h2>

<MTPings>
<a id="tb<MTPingID>"></a>
<MTPingExcerpt>
<p class="weblog">Received from:
<a href="<MTPingURL>"><MTPingBlogName></a>
at <MTPingDate>
</p>
</MTPings>
End example


Summary

Links are the primary units of currency on the Web, providing a means for publishers to direct an audience to noteworthy sites. Whether a site has been launched on the Web to earn money, respect, or notoriety, links that bring people to that site are greatly prized. The importance of links ranks especially high among the peculiar class of publishers known as webloggers.

The richest form of link exchange among weblogs uses trackback, the protocol created by the developers of Movable Type. As you might expect, the software provides the most sophisticated implementation of the trackback protocol available in any weblogging software.

Trackback’s primary application is for one weblogger to let another know that he or she is being discussed, which is made possible by way of a message called a trackback ping. Pings contain a link and excerpt for a weblog entry.

Movable Type weblogs can collect pings received from other weblogs, presenting them in a manner similar to comments. They also can send pings to other weblogs. These links create a novel form of online conversation that can be followed from site to site.

The trackback protocol also can be used to build a content aggregator, which is a site or service that collects related content from other sites. trackback pings serve as the submission mechanism for these aggregators.

A Movable Type category can be used to aggregate content in this manner or route its own entries to another aggregator.

Regardless of how you use trackback, the trackback protocol creates a rich network of connections between your weblog and the sites of other publishers who share your interests.


Chapter 12: Backing Up a Weblog

In This Chapter

  • Exporting weblog entries and other data

  • Using Movable Type’s custom export format

  • Displaying export data in a Web browser

  • Catching errors in Internet Explorer and Opera

  • Saving export data to your computer

  • Exporting comments and trackback pings

  • Backing up your weblog data regularly

  • Creating an export template

Most webloggers go through phases of development reminiscent of the classroom “stages of evolution” posters. As you might recall, they show a bunch of prehistoric primates walking in line, beginning with a short long-armed ape, reaching a wary looking Neanderthal somewhere in the middle, and ending with hairless Charlton Heston, strolling confidently in the nude.

In the long-armed ape stage of weblogging, newbie publishers adopt the first software that makes it possible to publish. The main considerations are novelty and the addictive creative freedom offered by the format. Little else matters.

By the time they evolve into Neanderthals, they’ve become more discriminating about the tools they use, learning about other weblogging software and features that they’d like to have.

Finally, they become weblogger sapiens, a stage that’s reached when the following question has been asked: How do I get my data out of my weblogging tool for use somewhere else?

Although Movable Type stores weblog data in a database, you’re not stuck with the software or the database at any time.

In this chapter, you’ll learn about the software’s data export format, which makes it easy to back up your weblog and take control of how and where it is used.


Exporting Data from a Movable Type Weblog

With a single command in Movable Type, you can extract all of a weblog’s data to a text file. This makes it easy to create a backup of your weblog, move the data to another content-management system, or transfer a weblog from one Movable Type installation to another.

To export all of the data associated with a single weblog, follow these steps:

  1. Open the weblog for editing, and then click the Import/Export button on the sidebar menu. The Import & Export Entries page appears.

  2. Scroll down to the Export Entries section.

  3. Click the Export Entries From hyperlink. Movable Type creates the export data, which can take a few minutes or more for a sizeable weblog. When it’s done, the data appears as a text page in the Web browser, as shown in Figure 12-1.

    Click To expand
    Figure 12-1: Exporting data from a Movable Type weblog.

  4. Save the data, making sure to store it as a text file rather than HTML: Choose File ® Save As (Internet Explorer and Opera) or File ® Save Page As (Mozilla browsers), and then choose Text File in the Save as Type drop-down menu.

  5. Click Save.

    Cross-Reference

    This text file can be imported back into Movable Type using the Import feature on the same page of the browser-based interface, a process described in Chapter 14, “Importing Entries from Another Weblog.”

When creating the exported data, note that some Web browsers—including Internet Explorer and Opera—might erroneously display the page as HTML rather than as text.

When this happens, you’ll see all of the lines running together, with different parts of the weblog on the same line. Figure 12-2 shows how this looks in Opera, using the data of the same weblog shown in Figure 12-1.

Click To expand
Figure 12-2: Spotting incorrectly exported data in a Web browser.

This problem can be fixed by saving the file without displaying it in the browser: Right-click the link, choose Save Target As (Internet Explorer) or Save File As (Opera), use the Save As dialog box to set the file type as text, and then save the data.

Movable Type’s data import and export format, which is unique to the software, consists of single- and multiple-line fields that define weblog entries, comments, and trackback pings. The file can be viewed with a Web browser or text editor.

Listing 12-1 contains an exported weblog entry with two comments and one trackback ping. Fields can contain HTML formatting or plain text.

Listing 12-1: Movable Type Export File
Start example
AUTHOR: rcade
TITLE: Pundit razzes Franken show
STATUS: Publish
ALLOW COMMENTS: 1
CONVERT BREAKS: __default__
ALLOW PINGS: 1
PRIMARY CATEGORY: Comment
CATEGORY: Comment

DATE: 04/12/2004 08:55:36 AM
-----
BODY:
In a column for today’s <i>Washington Post</i>, William
Raspberry pans Al Franken’s new talk show on Air America
Radio while acknowledging that "I haven’t been able to
find it on my radio yet":
-----
EXTENDED BODY:
<blockquote>
<p>Franken is a funny enough guy, I suppose, as an
entertainer. But to the extent he sees his role as
countering right-wing misrepresentations with left-wing
misrepresentations, my response is: Who needs him?</p>
</blockquote>
-----
EXCERPT:
William Raspberry pans Al Franken’s new talk show on Air
America Radio.
-----
KEYWORDS:

-----
COMMENT:
AUTHOR: arthur
EMAIL: arthur@example.com
IP: 192.0.34.166
URL: http://www.example.com
DATE: 04/12/2004 09:25:08 AM
Franken’s show has its moments. He has great guests and
some hilarious bits.

However, I wonder if a show that sounds so tweedy -- with
a former NPR
cohost no less -- can succeed in talk radio.
-----
COMMENT:
AUTHOR: Amy
EMAIL: @aol.com
IP: 205.160.212.222
URL:
DATE: 04/12/2004 09:42:25 AM
Air America can be heard coast to coast on XM Satellite
Radio.
-----

PING:
TITLE: Raspberrys to Al Franken
URL: http://example.com/~blog
IP: 140.147.249.9
BLOG NAME: News Blog
DATE: 04/08/2004 04:35:36 PM
William Raspberry reviews the O’Franken Factor, Al
Franken’s new talk show on Air America Radio, without
listening to it first. His review...
-----c
End example

Entries appear in chronological order in a weblog export file, with each entry’s data grouped together. Within a single entry, all single-line fields are defined first, multi-line fields follow, and then a seven-dash separator indicates that the end of an entry has been reached.

A single- or multi-line field that has a name followed by no text indicates that the field has no value. The example in Listing 12-1 does not use entry keywords, so the KEYWORD field is followed by a blank line.

Exporting Single-Line Entry Fields

In exported weblog data, single-line entries can contain three kinds of values: text, Boolean values of either 1 (for true) or 0 (for false), or a date/time timestamp.

Timestamps take the format MM/DD/YYYY HH:MM:SS xM, as in the example value 4/21/2004 12:01:33 PM. The elements of the timestamp, in order, are as follows:

  • The month, which can be one or two digits

  • The day of month, also one or two digits

  • The year as four digits

  • The hour as one or two digits

  • The minute as two digits

  • The second as two digits

  • Either AM or PM

The DATE field serves as a unique identifier for weblog entries, determining the order of entries on both a Web page and the List & Edit Entries page of the browser interface. When you edit a date, it will be moved to the proper place in the order and published in the correct daily archive.

Unlike other timestamps you work with in Movable Type, there’s no way to specify an entry’s time zone in export data. It will be the same time zone as the weblog itself, a setting that you can change before exporting data: Click the Weblog Config menu button to open the Configuration page, and then scroll to the Timezone setting at the bottom of the page.

Table 12-1 contains the nine single-line fields that define aspects of an entry.

Table 12-1: Single-Line Export Fields
Field | Data Type | Usage | Default
ALLOW COMMENTS | Boolean | Whether the entry allows comments (1) or disallows them (0) | Allow comments
ALLOW PINGS | Boolean | Whether the entry allows trackback pings (1) or disallows them (0) | Allow pings
AUTHOR | Text | The entry’s author | None
CATEGORY | Text | A category for the entry (appears once for each category) | None
CONVERT BREAKS | Text | The name of the text filter to use on entries | __default__
DATE | Date/time | The date and time the entry was created | None
PRIMARY CATEGORY | Text | The entry’s main category | None
STATUS | Text | The publication status, which is either Publish or Draft | Publish
TITLE | Text | The entry’s title | The first five words of the entry

In the export file, single-line fields are structured as a one-word field name followed by a colon and whatever text defines the value of the field, as in this example:

TITLE: New e-mail worm hits thousands of Internet users

The preceding line sets “New e-mail worm hits thousands of Internet users” as the title of a weblog entry. Everything between “TITLE: “ and the end of the line is considered part of the title.

All of the fields in Table 12-1 will be present in an exported weblog entry except for CATEGORY, which will be absent when an entry has not been assigned any categories. In that instance, the PRIMARY CATEGORY field will be present but have no value.

One CATEGORY field will be present for each entry category. The PRIMARY CATEGORY field designates the main category, duplicating one of the CATEGORY fields.

The CONVERT BREAKS field identifies the text filter that was applied to an entry, which will be either the Convert Line Breaks filter or no filter at all—unless additional filters have been installed. The value of this field is either __default__ for the Convert Line Breaks filter, 0 for no filter, or another string that identifies a filter that has been added to your Movable Type installation.

Exporting Multi-Line Fields

Multi-line fields take the following form in exported data: a five-dash separator, followed by a line containing a field name and a colon, followed by one or more lines defining the field value.

Here’s a multi-line field that defines an entry body:

-----
BODY:
Mieskuoro Huutajat, otherwise known as the shouting
men of Finland, is more than a bunch of Finns getting
things off their chests by upping their decibels.
It is a new art form, and it is taking parts of the world
by arctic storm.

Not including comments and trackback pings, four multi-line fields can be defined in an entry, as listed in Table 12-2.

Table 12-2: Multi-Line Import Fields
Field | Usage | Default
BODY | The main text of the entry. | None
EXCERPT | An excerpt describing the entry. | The first 20 words of the entry
EXTENDED BODY | The extended text of longer entries that have been split into two fields. | None
KEYWORDS | A comma-separated list of keywords assigned to the entry. | No keywords

The text of a multi-line field begins on the line after the field’s name and does not end until the next separator. This enables a field to include line and paragraph breaks. All multi-line fields are optional and should not appear more than once in an entry.

Comments and Trackback fields are multi-line fields that hold some of their own single-line fields. They are described in the next two sections.

Exporting Comments and Trackback Pings

If your weblog allows visitors to submit comments in response to each weblog entry, they will be present in exported data through the use of the COMMENT field.

This field begins with a five-dash separator followed by several single-line fields and the text of the comment, which can take up multiple lines. Here’s an example:

-----
COMMENT:
AUTHOR: A.G.
EMAIL: agbaseball@sportsfilter.com
IP: 216.74.142.10
URL: http://www.sportsfilter.com
DATE: 04/18/2004 09:25:20 PM
Moneyball’s a great read. It’s tough not to root for the
Oakland A’s after reading the book, even though
they are in the same division as my
favorite team, the Texas Rangers.

An entry’s comments are grouped together in chronological order. Comment fields are described in Table 12-3.

Table 12-3: Comment Export Fields
Field | Data Type | Usage
AUTHOR | Text | The name provided by the comment’s author
DATE | Date/time | The date and time the comment was written
EMAIL | Text | The comment author’s e-mail address
IP | Text | The IP address from which the comment was submitted
URL | Text | The address of the comment author’s Web site

All of the fields in Table 12-3 are present for each comment, although some will be blank when a visitor has not provided that piece of information.

Trackback pings appear after comments in chronological order and have the same structure: a field name followed by several single-line fields and the text of the weblog entry associated with the ping:

-----
PING:
TITLE: Bonds passes Mays
URL: http://sports.example.com
IP: 198.41.0.6
BLOG NAME: Sports News
DATE: 04/09/2004 07:19:49 AM
San Francisco Giants slugger Barry Bonds
hit his 661st homer Tuesday night, passing
Willie Mays to take sole possession of third place on
baseball’s career list ...

Trackback pings are listed in Table 12-4.

Table 12-4: Trackback Export Fields
Field | Data Type | Usage
BLOG NAME | Text | The name of the Web site that sent the ping
DATE | Date/time | The date and time the ping was received
IP | Text | The IP address from which the ping was sent
TITLE | Text | The title of the weblog entry associated with the ping
URL | Text | The address of the Web site that sent the ping

After all entry data, comments, and trackback pings, a seven-dash separator signifies the end of the entry.


Automating Regular Backups of Your Data

Backing up your data frequently is critical with any content-management system, especially one that’s running on a Web server that isn’t under your direct control. Movable Type’s export feature works best when you’re doing a one-time task such as moving from one server to another. Running it on a daily or even weekly basis is such a chore that you’re not likely to keep doing it regularly.

Cross-Reference

Recall that in Chapter 9, “Designing a Weblog with Templates,” you learned how to create and edit templates, the source files used to produce all Web content with Movable Type.

Although templates most commonly are employed to create Web pages and XML files such as syndicated newsfeeds in RSS and Atom formats, you can use them to create files in any text-based format.

Listing 12-2 contains a template that creates a file in Movable Type’s export format. When created, this file contains the data for every weblog entry published in the last 9,999 days—in other words, every entry—along with its comments and trackback pings.

Listing 12-2: A Weblog Export Template
Start example
<MTEntries days="9999" sort_order="ascend">
AUTHOR: <MTEntryAuthor>
TITLE: <MTEntryTitle>
STATUS: <MTEntryStatus>
<MTEntryIfAllowComments>ALLOW COMMENTS: 1</MTEntryIfAllowComments>
CONVERT BREAKS: __default__
<MTEntryIfAllowPings>ALLOW PINGS: 1</MTEntryIfAllowPings>
PRIMARY CATEGORY: <MTEntryCategory>
<MTEntryCategories>CATEGORY: <MTCategoryLabel></MTEntryCategories>

DATE: <MTEntryDate format="%m/%d/%Y %I:%M:%S %p">
-----
BODY:
<MTEntryBody>
-----
EXTENDED BODY:
<MTEntryMore>
-----
EXCERPT:
<MTEntryExcerpt>
-----
KEYWORDS:
<MTEntryKeywords>
<MTComments>-----
COMMENT:
AUTHOR: <MTCommentAuthor>
EMAIL: <MTCommentEmail>
IP: <MTCommentIP>
URL: <MTCommentURL>
DATE: <MTCommentDate format="%m/%d/%Y %I:%M:%S %p">
<MTCommentBody>
</MTComments>
<MTPings>-----
PING:
TITLE: <MTPingTitle>
URL: <MTPingURL>
IP: <MTPingID>
BLOG NAME: <MTPingBlogName>
DATE: <MTPingDate format="%m/%d/%Y %I:%M:%S %p">
<MTPingExcerpt>
</MTPings>
--------
</MTEntries>
End example

Templates combine static text that never changes with information produced by Movable Type template tags, which look and function similarly to HTML markup tags. The following line recreates a weblog entry’s AUTHOR field in exported data:

AUTHOR: <MTEntryAuthor>

When a file is created from the template, an entry’s author is plugged in to this line, producing output like the following:

AUTHOR: rcade

In Movable Type, the main templates used to produce a weblog’s pages and other files are called index templates. By creating an export index template using Listing 12-2, you produce a full backup of your weblog every time you rebuild the site.

Here’s how to set up the template and get it running:

  1. In Movable Type’s browser interface, click the Templates button in the sidebar menu. The Templates page displays all of the templates currently in use on the weblog.

  2. Click the Create New Index Template hyperlink. The Create New Template page appears with fields where you can enter a template name, filename, and template body (see Figure 12-3).

    Click To expand
    Figure 12-3: Creating a weblog export template.

  3. In the Template Name text field, enter a succinct, descriptive name for the new template (“Weblog Export” has a nice ring to it).

  4. In the Output File field, give the template a filename that ends with .txt, such as export.txt.

  5. Enable the checkbox Rebuild This Template Automatically When Rebuilding Index Templates. (It might already be enabled.)

  6. Skip the Link This Template to a File field.

  7. Enter the text of Listing 12-2 in the Template Body text box.

  8. Click the Save button at the bottom of the page.

After the template has been saved, it will be included on the list of index templates on the Templates page. Whenever you rebuild the weblog, the export.txt file is created in the same directory as the home page.

Caution

Building an export file that contains all of your weblog entries will be the most time-consuming part of a site rebuild. On a weblog with a large number of entries or visitor comments, you might find that it slows your site down noticeably to rebuild the export file every time index templates are republished.

To turn off automatic builds of this file, edit the export template, disable the checkbox Rebuild This Template Automatically When Rebuilding Index Templates, and then click Save. After making this change, to rebuild the export file, open the template, scroll to the bottom and click Rebuild. A pop-up window confirms that you want to republish the file.


Summary

When Movable Type was created, one of the goals driving its development was the desire of designers Mena and Ben Trott to put weblog data in the hands of its creators.

Relying on a central Web-based service has many advantages, but if the service goes out of business or experiences technical problems, you run the risk of losing your work.

Movable Type’s simple text-based data format ensures that you have full access to your own weblog entries, visitor comments, and trackback pings at all times.

Exported weblog data makes it possible to move from one Web server’s Movable Type installation to another, regularly back up your data, and quit the software to adopt another content-management system.

Although the last option probably doesn’t interest you at the moment, as you read this book and monkey around with all of the features in the software, it ought to provide some reassurance. If your publishing needs and goals evolve, Six Apart can either keep up with you or experience a little survival of the fittest.


Chapter 13: Adding Search Capabilitiesto a Weblog

In This Chapter

  • Searching a Movable Type weblog

  • Creating a search template

  • Changing the search script’s settings

  • Working with search tags

  • Putting a search form on a Web page

  • Presenting Google searches on your weblog

  • Using Google tags

Now that weblogs have graduated from an obscure hobby to a genuine media phenomenon, weblog publishing tools are engaged in a pitched battle for users. One of the advantages Movable Type has over many of its competitors is its strong search feature.

Movable Type weblogs can offer visitors the capability to search through weblog entries and comments. The results of a search are presented with template-created Web pages that are as customizable as any of the software’s other templates.

A search can be as simple as looking for a word or phrase on a single weblog or as complex as a hunt spanning multiple weblogs over a specific date range using regular expressions, a syntax for locating patterns in text that’s as sophisticated as some programming languages.

Interestingly enough, this popular feature of the software didn’t originate at Six Apart. Jay Allen, a long-time user and the winner of the company’s $20,000 contest for developers of plug-ins that work with Movable Type 3, offered search capabilities with his MT-Search plug-in. This enhancement became an official part of the software in 2002.


Searching a Movable Type Weblog

Every Movable Type weblog begins its life with a simple search box in the sidebar of its home page.

Search results are displayed on a new page in reverse chronological order. Figure 13-1 displays what turned up on a weblog when I looked for the text “Orlando Sentinel.”

Click To expand
Figure 13-1: Viewing results from a weblog search.

This search, which is performed by the Movable Type script mt-search.cgi, looks through all of your weblogs for matching text in weblog entries, and supports the following features:

  • Finding one or more words (weblog RSS feed)

  • Finding at least one word in a group with the OR keyword (Ben OR Mena)

  • Narrowing a search with the NOT keyword (Trackback server NOT Linux)

  • Finding an exact phrase placed within quotation marks (“who is Melody Nelson?”)

Movable Type’s search script also can look through visitor comments and individual weblogs. You can configure searches to offer as much or as little functionality as desired.

Search capabilities are set up by making changes to the software’s configuration file mt.cfg, editing search result templates or creating new ones, and creating forms to collect input using HTML or XHTML.


Putting a Search Form on a Web Page

When you create a new Movable Type weblog, the Main Index template includes a form that visitors can use to conduct simple searches (see Figure 13-2).

Click To expand
Figure 13-2: Offering search capabilities on a weblog.

Like the rest of the templates in Movable Type, this form uses XHTML, the XML-based version of the HTML markup language.

Listing 13-1 contains the XHTML code that’s used in the template to present this form.

Listing 13-1: A Simple Search Form in XHTML
Start example
<div class="side">
<form method="get" action="<MTCGIPath><MTSearchScript>">
<input type="hidden" name="IncludeBlogs" value="<MTBlogID>" />
<label for="search" accesskey="4">Search this site:</label><br />
<input id="search" name="search" size="20" /><br />
<input type="submit" value="Search" />
</form>
</div>
End example

This search form uses the MT search tag MTSearchScript, which identifies the name of the Perl script that conducts a search and presents matching results. The SearchScript setting, found in the mt.cfg configuration file, determines this name. The default is mt-search.cgi.

With a few simple changes, the same form can be converted to HTML, as demonstrated in Listing 13-2.

Listing 13-2: The Same Search Form in HTML
Start example
<div class="side">
<form method="get" action="<MTCGIPath><MTSearchScript>">
<input type="hidden" name="IncludeBlogs" value="<MTBlogID>">
<label for="search" accesskey="4">Search this site:</label><br>
<input id="search" name="search" size="20"><br>
<input type="submit" value="Search">
</form>
</div>
End example
Tip

If you’re more comfortable with HTML than with XHTML, converting one of the default Movable Type templates from XHTML to your preferred markup language is easy using a text editor that offers search and replace capability. Replace the text “ />” (a space followed by a forward slash and the > character) with the > character. You’ll catch most, or perhaps all, of the differences between XHTML and HTML in the template. After looking for anything you might have missed, change the first line of the file from an XHTML tag to an HTML tag.

Forms on a Web page collect input through a variety of fields such as buttons, single-line text fields, multiple-line text boxes, and drop-down menus. Although a full accounting of XHTML and HTML form design is beyond the scope of this book, here’s a quick rundown of how the form fields are employed in Listing 13-2:

  • The form element contains the form. It has an action attribute that identifies the program that will be called to receive form input and do something in response. The method attribute indicates how the form transmits information—it can have the values get or post. Everything on a form must be placed within the form element’s opening and closing tags.

  • Each input element represents a form field whose appearance is dictated by the type attribute. The submit attribute represents a click button and the hidden attribute creates a nonvisible field that holds pre-defined information. An input element with no type attribute is a text field.

  • The label element identifies the purpose of another field. The label’s for attribute matches the id attribute of the field it labels. In Listing 13-2, the label is associated with a text field named search.

Movable Type’s search script collects user input using the name assigned to each form element. These names are significant; if an element’s name is changed, the search script can’t collect user input from it.

The hidden element IncludeBlogs identifies the weblog that will be searched, using the MTBlogID tag to specify its ID.

This demonstrates an important aspect of search template design: The template applies to all weblogs, but tags can be used such that when the template produces a file, tag output can be linked to a specific weblog.

A form can include text and HTML and XHTML markup that make it more attractive. The form in Listing 13-2 includes the text Search this site: and a few BR tags to insert line breaks between form elements.

Offering an Enhanced Search Form

The simple search form might be sufficient for most Movable Type weblogs, especially ones that cater to a general, nontechnical audience. Typing something in a box and pressing a search button passes the grandma test—always a good metric when deciding whether a user interface has become so complex it scares off normal people who don’t dream in pixels and binary numbers.

Because some of us do go to bed counting pixelated sheep (0, 1, 10, 11, 100, 101, zzz ...), there’s a lot more you can do on a search form. Listing 13-3 contains the HTML code for a form with all of the available options supported by Movable Type’s search script.

Listing 13-3: A Full Search Form
Start example
<form method="post" action="<MTCGIPath><MTSearchScript>">
  <b>Look for:</b>
  <input size="30" name="search" value="<MTSearchString>"><br>
  <b>Options:</b>
  <input type="checkbox" name="CaseSearch"> Match case
  <input type="checkbox" name="RegexSearch"> Regex search<br>
  <b>Search:</b>
  <input type="radio" name="SearchElement" value="entries"> Entries
  <input type="radio" name="SearchElement" value="comments"> Comments
  <input type="radio" name="SearchElement" value="both"> Both<br>
  <b>Sort By:</b>
  <select name="SearchSortBy">
    <option value="created_on">Date Authored</option>
    <option value="title">Title</option>
  </select><br>
  <b>Sort Order:</b>
  <select name="ResultDisplay">
    <option value="ascend">last to first</option>
    <option value="descend">first to last</option>
  </select><br>
  <b>Exclude Weblogs:</b>
<MTBlogs>
  <input type="checkbox" name="ExcludeBlogs" value="<MTBlogID>">
<MTBlogName>
</MTBlogs><br>
  <b>Dates to search:</b>
  <select name="SearchCutoff">
    <option value="7">last week</option>
    <option value="14">last two weeks</option>
    <option value="30">last 30 days</option>
    <option value="60">last 60 days</option>
    <option value="90">last 90 days</option>
    <option value="365">last year</option>
    <option value="9999999">all</option>
  </select><br>
  <b>Results to display on a page:</b>
  <select name="MaxResults">
    <option value="5">5</option>
    <option value="10">10</option>
    <option value="25">25</option>
    <option value="50">50</option>
    <option value="100">100</option>
    <option value="9999999">all</option>
  </select><br>
   <input type="submit" value="Search"><br>
</form>
End example

This form is shown in Figure 13-3.

Click To expand
Figure 13-3: Conducting an extended search.

The enhanced form contains three search-specific MT tags that weren’t used in the simpler interface: MTSearchStrings, the MTBlogs container tag, and the MTBlogName tag.

The MTSearchString tag contains the text of the visitor’s search query, which can be used to put a search form on a results page. When no search has been conducted, this tag is empty. In Listing 13-3, the search field has been assigned MTSearchString as a value. This makes it possible for a visitor to modify the last search and keep hunting around your site.

As you learned in Chapter 9, “Designing a Weblog with Templates,” the MTBlogs tag contains information about all of your weblogs. Here’s how the form puts this tag to work:

<b>Exclude Weblogs:</b>
<MTBlogs>
  <input type=”checkbox” name=”ExcludeBlogs” value=”<MTBlogID>”>
<MTBlogName>
</MTBlogs><br>

Container tags cause their contents to be repeated for each item in a group. The MTBlogs tag holds a checkbox form field named ExcludeBlogs with a value of MTBlogID, a weblog’s ID number. The input element’s type attribute makes it a checkbox, a square box that can be checked or unchecked.

ExcludeBlogs serves the opposite purpose of IncludeBlogs, identifying a specific weblog that should be excluded from search results. Placing this form field inside MTBlogs causes one checkbox to appear for each weblog, enabling users to ignore one or more sites.

The enhanced form contains checkboxes to indicate whether the search should be case-sensitive (the CaseSearch element) and use regular expressions (the RegEx element).

Also available is a form field that consists of three related radio buttons, a group of circular on-off buttons from which only one button can be selected at any time (just like their namesake—buttons on a car radio). The SearchElement field determines whether entries, comments, or both will be part of a search.

The select and option form elements work together to define a pull-down menu. The field’s name is set by the name attribute of the select element. Each of its possible values comes from the value attribute of an option tag.

An option element’s value attribute holds the value that will be collected by the search script. A more user-friendly answer can be provided between the opening and closing option tags, like so:

<b>Sort Order:</b>
<select name="ResultDisplay">
  <option value="ascend">last to first</option>
  <option value="descend">first to last</option>
</select>

This HTML code presents a pull-down menu that asks a user to determine the order in which results will be presented. The search script requires the ResultDisplay field to be either ascend or descend. Visitors are presented with easily understood options: “first to last” to see results in chronological order and “last to first” for the opposite.

Of course, you’re not required to offer an enhanced search form with every possible field the search script supports. In fact, you might want to take some of them away as a means of preventing visitors from seeing things you don’t want to offer in a search.

To limit the search to the weblog on which the form appears, drop the entire MTBlogs section from its opening tag to its closing tag. Replace it with the hidden tag used in the simple form:

<input type=”hidden” name=”IncludeBlogs”
value=”<MTBlogID>”>

You also can limit the options offered in a checkbox, radio button, or pull-down menu by leaving some of them, or even all of them, off the form.

Perhaps you don’t want visitors to conduct regular expression–based searches (a feature that I love as a programmer that miserably fails the grandma test). You can accomplish this by taking its input element and accompanying text off the form:

<input type=”checkbox” name=”RegexSearch”> Regex search<br>


Creating a Search Template

Like all other forms of Web content in Movable Type, search results are template-driven and can be fully customized to suit your goals. One important difference is that search templates apply to all of your Movable Type weblogs and are not created on a per-weblog basis.

There’s no way to create and edit search templates using Movable Type’s browser interface. You must either edit the files directly on the server or edit them on your computer and upload the templates with an FTP client.

The software includes two search templates: a weblog template named default.tmpl and the comment template called comments.tmpl. These files are stored in the search_templates subdirectory inside the directory where Movable Type scripts are installed. You can edit these templates and create your own, storing them in this directory so the script can find them.

Using Search Tags

Search templates can use most Movable Type tags in the same manner they’re employed in other templates. The tags that make the most sense to include are general weblog tags such as MTBlogName and all of the tags that relate to an individual weblog entry.

Movable Type’s installed version of default.tmpl uses four general weblog tags: MTBlogName, MTBlogURL, MTPublishCharset, and MTCGIPath.

Five entry tags pull information from weblog entries found in the search: MTEntryDate, MTEntryEditLink, MTEntryExcerpt, MTEntryPermalink, and MTEntryTitle.

These tags are placed within the MTSearchResults container tag, which serves the same purpose as MTEntries on a non-search template. Any tag related to an individual weblog entry can be used within this container.

When search results come from more than one weblog, the search script groups results by weblog. The MTBlogResultHeader container tag can be used to present a weblog’s header along with the first entry from that weblog. It should be placed within a MTSearchResults container.

The MTSearchResultCount tag holds the number of results returned from a search.

Listing 13-4 contains HTML code that presents search results with a header atop the matching entries from each weblog.

Listing 13-4: Formatted Search Results
Start example
<p>Results found: <MTSearchResultCount>
<MTSearchResults>
  <MTBlogResultHeader>
    <p><a href="<$MTBlogURL$>"><$MTBlogName$></a> entries:
  </MTBlogResultHeader>
  <p><a href="<MTEntryLink>#<MTEntryID pad="1">"><MTEntryTitle></a>
  <p><MTEntryExcerpt>
  <p>Posted in <$MTBlogName$> on <$MTEntryDate$>
</MTSearchResults>
End example

Figure 13-4 shows how this code looks in action. The weblog name Orlando Vacationer links to the site’s home page. Each weblog entry title links to that entry’s archive page.

Click To expand
Figure 13-4: Presenting search results.

A MTNoSearchResults container tag determines what will be displayed when a search turns up no results matching a term. The MTSearchString tag, which holds the text the user was looking for, can be used in this container, as in this simple example:

<MTNoSearchResults>
  <p>Could not find anything matching “<MTSearchString>”</p>
</MTNoSearchResults>

A MTNoSearch container provides a way to help users who clicked a search button without entering any text to look for. This container can be used to provide instructions on how to use the search feature or to simply alert users to the error, as shown in the following HTML excerpt:

<MTNoSearch>
  <p>You must enter a word or words to search for. Use your browser’s
back button to try again.</p>
</MTNoSearch>

Setting Up the Search Script

An earlier section described how to limit the capabilities of a search by omitting elements from a Web form. This works but affects only how a particular template is used to conduct a search and present results. You can create other templates that offer more options.

This generally is a good thing, but there’s one situation in which it could be disastrous. If you offer some private weblogs in addition to public ones, the multiple-search capabilities enable any search template to be used to search a private weblog. Entries and comments intended for a private audience can find their way to public sites on your server.

The foolproof way to prevent this is to edit the search script’s settings in the mt.cfg configuration file, limiting the weblogs that can be searched and the features your search script will support (and the ones it will ignore).

The Movable Type configuration file is a text file with several dozen settings that are placed below documentation explaining how to use them. The search settings are in their own section below the other configuration options.

Here’s one of the search settings in the file:

# The sort order for the search results. Using ‘ascend’ will list the
# entries in chronological order (oldest entry at the top); using
# ‘descend’ will list the entries in reverse chronological
# order (newest entry at the top). The default is ‘descend’.
#
# ResultDisplay ascend

Lines that begin with a pound character (#) are ignored by Movable Type. They’re in the file to describe how to use a setting. Below each description, a setting is shown—here, ResultDisplay would be set to the value ascend, but a # begins the line, causing it to be ignored.

If a search setting is not found in the file because it begins with a #, the default will be used. Removing the # preceding ResultDisplay assigns that setting the value ascend, causing search results to be presented in chronological order.

After changing a setting in the configuration file, save and exit the file. The search script begins using the new settings immediately.

Table 13-1 contains information about the search settings under your control.

Table 13-1: Search Script Configuration Settings
Setting | Description | Default
SearchScript | The name of the script that conducts searches and returns a results page | mt-search.cgi
SearchTemplatePath | The subdirectory under the main Movable Type directory in which search templates are stored | ./search_templates/
DefaultTemplate | The filename of the search template that will be used when no other template has been specified on a form | default.tmpl
AltTemplate | The name and filename of additional search templates. Movable Type includes one named comment stored in comments.tmpl, and more can be added. | Not applicable
IncludeBlogs | The ID numbers of weblogs included in a search, presented as a comma-separated list | Include all weblogs in a search
ExcludeBlogs | The ID numbers of weblogs excluded from a search, also in a comma-separated list. This setting is ignored if IncludeBlogs is set. | Do not exclude any weblogs
RegexSearch | A bit setting that indicates whether a search uses regular expressions (1) or does not (0) | 0
CaseSearch | A bit setting that determines whether the search is case-sensitive (1) or not (0) | 0
SearchCutOff | The number of days to go back through weblog entries during a search | All days
CommentCutOff | The number of days to go back through visitor comments during a search | 30 days
MaxResults | The maximum number of search results to display from each weblog included in that search. For comments, the maximum number of weblog entries that will be presented with results. | All
ResultDisplay | The chronological order of search results, which can be ascend for first-to-last order and descend for the opposite | ascend
ExcerptWords | The number of words to use from a weblog entry’s excerpt when the MTEntryExcerpt tag appears on a search results template | 40
SearchElement | The weblog data to examine in a search, which can be entries for weblog entries, comments for weblog comments, or both | entries
NoOverride | Search settings that cannot be overridden in search templates or user input on a search form. The names match those in column 1 of the table. They should be a comma-separated list when more than one setting is off-limits. For example, IncludeBlogs, RegexSearch forces the search script to ignore attempts to set included blogs or use regular expressions in any search. | None

Only one of these settings appears in the configuration file without a # preceding it:

AltTemplate comments comments.tmpl

This indicates that the template file comments.tmpl in the search_templates directory has the name comments. There should be an AltTemplate setting for every search template you want to use, with the exception of the default template default.tmpl.

Once you have added a template to the configuration, a form element should be added to any form that uses the template to display results. This element should be hidden and have the name Template. Here’s one that associates a form with the comments.tmpl file:

<input type=”hidden” name=”Template” value=”comments”>

When designing your own template, it’s a good idea to avoid Movable Type tags that are server-intensive, either because they pull a lot of information from the weblog’s database or take some time to create from a template. Six Apart recommends that you keep calendar tags and archive lists off a search results page for this reason.


Presenting Google Searches on Your Weblog

The Google search engine offers an application programming interface (API) that can be used by the software to conduct searches of its database. The interface conducts normal Google searches using the same rules as the Google Web site and related-site searches, which respond with the sites most similar to a specified URL. Up to 10 results are returned for each query.

Movable Type hooks into this interface with the MTGoogleSearch tag, which can be placed in a template to incorporate Google results on a Web page.

Before you can take advantage of this cool functionality, you must acquire a license key from Google and set up Movable Type to use it:

  1. Visit the Google Web APIs site: http://www.google.com/apis.

  2. Follow the instructions on the site to set up a Google account, review the terms of service, and receive a key.

  3. Return to your Movable Type browser interface and open the weblog that will pull search results from Google. Click the Weblog Config menu button. The Configuration page appears.

  4. Click the Preferences link. A form containing weblog preferences is displayed.

  5. Click the Publicity/Remote Interfaces/Trackback link to scroll down to that section of the form.

  6. Enter your license key in the Google API Key field.

  7. Scroll to the bottom of the page and click Save.

Google’s license permits up to 1,000 queries per day and can be used only for noncommercial purposes.

Using Google Tags

In order to incorporate Google content on your weblog, you plunk down a MTGoogleSearch container tag to hold the results and a MTGoogleSearchResult tag to present parts of each individual result.

Here’s a simple use of Google to find results matching the word “Orlando”:

<MTGoogleSearch query=”Orlando”>
  <p><a href=”<MTGoogleSearchResult property=”URL”>”>
  <MTGoogleSearchResult></a>
</MTGoogleSearch>

You can define six attributes for the MTGoogleSearch tag, as listed in Table 13-2. All of them are optional.

Table 13-2: MTGoogleSearch Tag Attributes
Attribute | Description | Default
Query | The search query, which can be a word or words using the same syntax as a search conducted on the Google Web site (http://www.google.com) | None
Results | The number of results to receive, which has a maximum of 10 | 10
Excerpt | A flag that can be set to 1 to indicate that the excerpt of the current weblog entry should be used as the search query | 0
Keywords | A flag set to 1 to make an entry’s keywords the search query | 0
Title | A flag set to 1 to make an entry’s title the search query | 0
Related | The URL to use for a related-sites search. If this equals 1 instead of a URL, sites related to the weblog’s home page are received. | None

Most of these attributes cannot be effectively used in the same MTGoogleSearch tag. Only one query can be defined for a search, so it wouldn’t make sense to put both “query=baseball” and “title=1” in the same tag.

Within this container, a MTGoogleSearchResult tag presents items included in a search result. This tag has a property attribute that identifies the item to display. If the tag is used without any attributes, a search result’s title is displayed.

Table 13-3 presents the possible values for property. Each relates to a Web page that was found during the search.

Table 13-3: MTGoogleSearchResult Property Attribute Values
Property | Description | Format
DirectoryTitle | The title of the page from the Open Directory Project, if that page exists in that database | Text
Snippet | A portion of the page most relevant to the search, which might not include words in the search query | Encoded HTML
Summary | The summary of the page from the Open Directory Project database, if one exists | Text
Title | The title of the page | Encoded HTML
URL | The URL of the page | Text

Before encoded HTML can be presented on a Web page, it must be decoded, the process that converts the &lt; and &gt; entities to the proper less-than and greater-than signs (< and >).

In the MTGoogleSearchResult tag, set the universal tag attribute decode_html to 1 to convert the HTML to publishable form. You also can remove the HTML entirely by setting the remove_html attribute to 1.

Listing 13-5 contains HTML code that searches Google for results matching a weblog entry’s title. An unnumbered list is displayed with the title of each search result linking to the Web site.

Listing 13-5: Publishing Google Search Results
Start example
<p><ul><MTGoogleSearch title="1">
    <li><a href="<MTGoogleSearchResult property="URL">">
<MTGoogleSearchResult decode_html="1" remove_html="1"></a></li>
</MTGoogleSearch>
</ul></p>
End example

You should experiment with Google tags to see what impact they have on the publication of your weblog. Putting Google results on individual archive pages slows the rebuild process considerably and can cause you to max out your 1,000 daily requests quickly, even on a moderately trafficked site.


Summary

Even the best-designed Web site benefits from a good search feature. Movable Type sites can be navigated in many ways. You can offer a calendar linking to daily archives, links to individual weblog entries, and title links for recent entries.

Despite all of these links, some visitors will skip every one for the simplicity and convenience of a search form.

Movable Type’s search script, mt-search.cgi, can scan through weblog entries and visitor comments, presenting anything that matches a search query on a page created by a search template.

Searches can be simple or complex, depending on the Web form that collects a search request from a user. The search script supports case-matching, regular expressions, and sorting results by date.

Unlike other templates, search templates exist in a subdirectory of the software’s main installation directory. They must be edited outside of the software’s browser interface and apply to all of your weblogs.

Search templates have their own container tags. Within those containers, they can present results using the same tags as other templates.

By offering a form that provides searchable access to your weblog data, you can offer visitors one less reason to look elsewhere.


Chapter 14: Importing Entries fromAnother Weblog

In This Chapter

  • Retrieving weblog data, comments, and trackback pings

  • Working with Movable Type’s custom import format

  • Importing titles, authors, and other data

  • Importing multiple-line text such as weblog entries

  • Creating a Blogger template to export data

  • Writing a Radio UserLand export script

  • Using Movable Type’s import feature

  • Setting a default category and publish status

As an incentive to encourage weblog publishers to use Movable Type, the software can import weblog entries, comments, and trackback pings that were created using other content-management systems.

Movable Type takes in weblog data using a simple text format devised for this purpose by Six Apart. The software’s importation feature includes support for categories, keywords, excerpts, and the other elements of a weblog entry. You can even set comments and trackbacks on or off and choose whether to publish an entry upon import or save it as a draft.

Weblog data can be imported to an empty weblog, added to an existing weblog, and filed in a category.

This feature can be exploited with any weblog- or content-management software that can produce text in user-defined formats using templates or scripts. In this chapter, you’ll learn how to export weblog data from some of the most popular weblogging tools and create data in this format using other software.


Moving Weblog Data into a Movable Type Weblog

The Movable Type import format consists of single-line and multiple-line fields that define weblog entries, comments, and trackback pings.

Single-line fields consist of a field name followed by a colon and the value for the field. Here’s one that sets an entry title:

TITLE: FantasyLand to add 3-D movie attraction

Multi-line fields consist of a five-dash separator followed by a line containing a field name followed by a colon, and then one or more lines defining the field value. The following example defines an entry excerpt:

-----
EXCERPT:
Magic Kingdom will be adding a 3-D movie attraction on
Oct. 8. The movie features Donald Duck stealing Mickey’s
sorcerer hat.

In an entry, single-line fields are defined first, followed by multi-line fields. A seven-dash separator indicates that the end of an entry has been reached.

Listing 14-1 contains an import file for two weblog entries. The first makes use of multi-line fields to define an extended entry, excerpt, and keywords. The second uses only one field to define the text of an entry.

Listing 14-1: A Weblog Import File
Start example
TITLE: FantasyLand to add 3-D movie attraction
DATE: 3/22/2004 2:04:04 PM
AUTHOR: rcade
CATEGORY: Disney World
CATEGORY: Disney News
PRIMARY CATEGORY: Disney World
STATUS: draft
ALLOW PINGS: 1
ALLOW COMMENTS: 1
CONVERT BREAKS: __default__
-----
BODY:
The Magic Kingdom is getting its own 3-D movie
attraction on Oct. 8, according to
<a href="http://mouseplanet.com/wdw030721.htm">
MousePlanet</a>:
-----
EXTENDED BODY:
<blockquote><p>With all of the attention focused on
Mission: Space, Mickey’s PhilharMagic has been
overlooked by many. This attraction, scheduled to open
on Wednesday, October 8 in the Magic Kingdom, completes
the addition of 3-D movies to all of the Florida theme
parks.
Apparently, the storyline has Donald Duck stealing
Mickey’s sorcerer hat (no word on how Mickey came into
permanent possession of it from the sorcerer
 Yensid), and
stirs up much trouble, as he usually
does.</p></blockquote>
-----
EXCERPT:
Magic Kingdom will be adding a 3-D movie attraction on
Oct. 8. The movie features Donald Duck stealing Mickey’s
sorcerer hat.
-----
KEYWORDS:
Disney World, Disney, Magic Kingdom, 3-D movie,
MousePlanet
--------
TITLE: Mickey Mouse is the new black
DATE: 3/22/2004 2:17:40 PM
AUTHOR: rcade
CATEGORY: Disney World
CATEGORY: Local Color
PRIMARY CATEGORY: Disney News
STATUS: publish
ALLOW PINGS: 1
ALLOW COMMENTS: 1
-----
BODY:
The <a href="http://orlandosentinel.com/orl-
asecmickey23072303jul23,0,3482784.story">Orlando
Sentinel</a> reports that Disney is celebrating Mickey
Mouse’s 75th birthday by hawking merchandise featuring
decades-old imagery of the character:

<blockquote><p>... some shoppers are paying top dollar
for silk pants (costing $250), belt buckles and purses
adorned with Mickey’s retro image from the 1920s and
‘30s. It was enough to make the host of NBC’s
<i>Today</i> show, Katie Couric, ask earlier this month:
"Is it true that Mickey is the new black?" while
interviewing the fashion editor of <i>People
Magazine</i>.</p></blockquote>
--------
End example

Single-line entries can contain three kinds of values: Boolean values of 1 (true) or 0 (false), a date/time timestamp, or text.

Timestamps take the format MM/DD/YYYY HH:MM:SS xM, as in 3/22/2004 2:17:40 PM. They break down as follows:

  • The month and day of the month can be one or two digits.

  • The year must be four digits.

  • The hour can be one or two digits.

  • The minute and second must be two digits.

  • The last two characters must be AM or PM.

There’s no way to specify the time zone of an entry. Movable Type assumes that the time of imported entries will be in the weblog’s time zone, a setting that can be specified using the Weblog Config button on the software’s browser interface.

Note

Some programming languages and software support strftime, a standard technique for defining the format of date and time values based on a command-line program of the same name. An acceptable strftime code for creating timestamps that can be imported to Movable Type is %m/%d/%Y %I:%M:%S %p.

The nine single-line fields that define aspects of an entry are described in Table 14-1.

Table 14-1: Single-Line Import Fields
Field | Data Type | Usage | Default
ALLOW COMMENTS | Boolean | Whether the entry should allow comments (1) or disallow them (0) | Allow comments
ALLOW PINGS | Boolean | Whether to allow trackback pings (1) or disallow them (0) | Allow pings
AUTHOR | Text | The entry’s author | None
CATEGORY | Text | A category to which the entry belongs | None
CONVERT BREAKS | Text | The text filter to use on entries | __default__
DATE | Date/time | The date and time the entry was created | None
PRIMARY CATEGORY | Text | The entry’s main category | None
STATUS | Text | The publication status, which can be either publish or draft | publish
TITLE | Text | The entry’s title | The first five words of the entry

All of these fields are optional, aside from the DATE field, which always must be present in an entry, and the AUTHOR field, which must be present when importing entries from more than one author to a weblog.

Movable Type uses the DATE field to uniquely identify weblog entries, publish them in date-based archives, and sort them on the List & Edit Entries page of the software’s browser interface.

Each of these fields should appear only once or not at all in an entry, with the exception of CATEGORY. One CATEGORY field can appear for each of the entry’s categories. If a category named in this field does not exist, one will be created as the import takes place.

When an entry includes more than one category, the PRIMARY CATEGORY field identifies the one of most importance. If this is not present, the first category defined in the entry is used.

Entries that are not categorized are imported without a category or routed to a designated category of the weblog, a decision that can be made when entries are being imported.

The AUTHOR field should identify the username of the author on that weblog in Movable Type. If no user account exists for that person, one is created during an import.

The CONVERT BREAKS field establishes the text filter that is applied to entries. Movable Type’s default installation supports two options: no filtering and the Convert Line Breaks filter, which encloses paragraphs between opening and closing P tags and turns line breaks into BR tags. Additional filters can be added.

The value of this field should be the unique string that identifies the filter, not the more human-readable name. The Convert Line Breaks filter has the identifier __default__, which also is the default filter when the CONVERT BREAKS field is absent from an entry.

Five multi-line fields can be defined in an entry, as described in Table 14-2.

Table 14-2: Multi-Line Import Fields
Field | Usage | Default
BODY | The text of the entry | None
EXCERPT | A succinct excerpt describing the entry | The first 20 words of the entry
EXTENDED BODY | The extended text of longer entries, split into two fields | None
KEYWORDS | A list of keywords assigned to the entry, separated by commas | No keywords
NO ENTRY | Whether the entry exists in the weblog already (1) or needs to be imported (0) | Entry does not exist and must be imported (0)

All of the multi-line fields are optional and should not appear more than once in an entry.

The text of a multi-line field, which begins on the line after the field’s name, does not end until the next separator. Because line breaks are included in the field when it is imported, they only should be used at the end of paragraphs. Using them at other positions in the text will cause them to be formatted incorrectly when the entry is edited or published.

The NO ENTRY field becomes useful when comments and trackback pings are being imported, as you’ll see in the next section.


Importing Comments and Trackback Pings

Movable Type can import comments and trackback pings created with other weblog publishing tools and services. They can be imported along with the entries to which they belong or imported separately. The latter technique can be more convenient when you have used different tools to publish your weblog and offer comments or trackback.

Comments are defined by a COMMENT field followed by several single-line fields that define aspects of the comment, such as the author’s name and e-mail address, as shown in the following example:

-----
COMMENT:
AUTHOR: Jim S.
EMAIL: jims@example.com
DATE: 2/20/2004 12:22:17 PM
Have you ridden Mission Space yet?

The COMMENT field is followed by one or more single-line fields and the text of the comment, which is not preceded by a field name. In the preceding example, a user named Jim S. has written the comment “Have you ridden Mission Space yet?”

The text of a comment can span multiple lines, just like weblog entry text and other multi-line fields. A separator marks the end of a comment.

Table 14-3 describes all of the comment fields.

Table 14-3: Comment Import Fields
Field | Data Type | Usage | Default
AUTHOR | Text | The name of the person making the comment | None
DATE | Date/time | The date and time the comment was saved | None
EMAIL | Text | The person’s e-mail address | None
IP | Text | The Internet Protocol (IP) address from which the comment was made | None
URL | Text | The person’s home page | None

All of these fields are optional and should appear only once per comment.

An entry can include more than one comment, each beginning with a five-dash separator and grouped with the entry’s other multi-line fields.

Listing 14-2 contains a weblog entry with two comments. The entry and comments are imported to Movable Type simultaneously.

Listing 14-2: Weblog Entry with Comments
Start example
TITLE: FantasyLand to add 3-D movie attraction
AUTHOR: rcade
DATE: 3/22/2004 2:04:04 PM
-----
BODY:
The Magic Kingdom is getting its own 3-D movie
attraction on Oct. 8, according to
<a href="http://mouseplanet.com/wdw030721.htm">
MousePlanet</a>:
-----
COMMENT:
AUTHOR: Jim S.
DATE: 3/23/2004 2:05:54 AM
EMAIL: jims@example.com
URL: http://example.com/~jims
We just got to see a preview of this movie. It’s great;
the best of the 3-D movies at Disney World’s parks.
-----
COMMENT:
AUTHOR: Dave
DATE: 3/27/2004 4:22:01 PM
I’m going to the parks in May while I’m in town for an
<a href="http://www.ala.org">ALA</a> conference. Should
we hit all of the 3-D movies?
--------
End example

If an entry has a comment, Movable Type ignores its ALLOW COMMENTS field, if one is present, and sets the entry to accept new comments.

As described earlier, comments can be imported separately from weblog entries through the use of the NO ENTRY field.

When comments and entries are separate, Movable Type’s import format uses a weblog entry’s DATE field to indicate where a comment belongs once it has been added to the weblog database.

When prepared in this manner, the only fields that must be present for an entry are DATE, NO ENTRY, and the fields of the comment.

Any software that prepares comments for this kind of import must know the date and time of the entry associated with the comment. Without it, there’s no way to bring the entry and comment together.

Listing 14-3 rewrites the last example to import comments for an existing entry.

Listing 14-3: Comments for an Existing Weblog Entry
Start example
DATE: 3/22/2004 2:04:04 PM
NO ENTRY: 1
-----
COMMENT:
AUTHOR: Jim S.
DATE: 3/23/2004 2:05:54 AM
EMAIL: jims@example.com
URL: http://example.com/~jims
We just got to see a preview of this movie. It’s great;
the best of the 3-D movies at Disney World’s parks.
-----
COMMENT:
AUTHOR: Dave
DATE: 3/27/2004 4:22:01 PM
I’m going to the parks in May while I’m in town for an
<a href="http://www.ala.org">ALA</a> conference. Should
we hit all of the 3-D movies?
--------
End example

Movable Type will import comments to entries that have been closed to new comments, but it won’t change the setting to begin accepting comments.

A weblog entry also can include trackback pings, defined in a manner similar to comments.

Pings are imported with a PING field and single-line fields that define the constituent parts of the ping message, like this:

-----
PING:
TITLE: Coaster makes you cry ‘Mummy!’
URL: http://www.cadenhead.org/hype/archives/000087.html
IP: 64.81.250.253
BLOG NAME: Movable Hype
DATE: 03/05/2004 06:09:00 PM
Universal Studios Orlando, the best theme park in the
city for thrill-ride enthusiasts, will be adding a new
coaster based on Revenge of the Mummy....

Table 14-4 describes the five fields that can be present in an imported trackback ping.

Table 14-4: Trackback Import Fields
Field | Data Type | Usage | Default
BLOG NAME | Text | The name of the weblog sending the trackback ping | None
DATE | Date/time | The date and time the ping was received | None
TITLE | Text | The title of the weblog entry associated with the ping | None
IP | Text | The Internet Protocol (IP) address that sent the ping | None
URL | Text | The URL of the weblog entry | None

All trackback ping fields are optional except for the IP field—Movable Type will dutifully add pings that only contain this bit of information.

However, as you might recall from Chapter 11, “Sharing Trackback Links,” there’s nothing in the trackback protocol that allows a ping message to be missing any of these fields. All five should be present in any imported file that seeks to carry trackback information successfully into Movable Type.

Trackback pings are placed in an import file just like comments. They can be added simultaneously with entries or separately with a NO ENTRY field, and they cause an entry’s ALLOW PINGS field to be set to 1 (true).

Any software that can create weblog data in Movable Type’s text format can be used to import entries, comments, and trackback pings. The next several sections describe how this can be done with several weblogging tools.

The last section of this chapter, “Importing to Movable Type,” describes how to import the data after it has been created.


Exporting Weblog Entries from Blogger

Weblog entries can be exported from the Blogger service by replacing your Main Template on a Blogger weblog with one formatted in Movable Type’s import format.

Because this wipes out the existing template, be sure to save a copy unless you’re deleting the Blogger weblog after the move.

Entries in a Blogger site can have titles, authors, a publication date, and entry text, although most don’t offer titles because that feature was only added to its free service recently. There are no categories, comments, or trackback pings.

The information you want to pull from the Blogger site can be found in four template tags: BlogItemAuthor, BlogItemBody, BlogItemDateTime, and BlogItemSubject.

To change your template, open the weblog for editing on Blogger and click the Template tab. The Template page opens with the Main Template tab on top.

Enter the text of Listing 14-4 in the Main Template editing window, omitting the TITLE line if your Blogger weblog did not include entry titles.

Listing 14-4: Creating Import Data in Blogger
Start example
<Blogger>
TITLE: <PostSubject><$BlogItemSubject$></PostSubject>
AUTHOR: <$BlogItemAuthor$>
DATE: <$BlogItemDateTime$>
-----
BODY:
<$BlogItemBody$>
--------
</Blogger>
End example

Additional fields in Movable Type’s import format can be added to this template simply by typing them in at the right positions. For example, to turn off comments on imported entries and route them to a category named OldBlog, add these lines:

ALLOW COMMENTS: 0
CATEGORY: OldBlog

Make sure that each added field appears on its own line.

After saving the template, you can avoid overwriting the weblog’s existing Web pages with this new format by editing your publishing settings. In the Blog Filename text field, give the file a different name. When you publish the site, Blogger will produce that file in Movable Type’s import format.

The last section of this chapter, “Importing to Movable Type,” describes what to do after the import file has been created.


Exporting Weblog Entries from Radio UserLand

Radio UserLand, an Internet content-management system that includes a weblog editor, can export entries in Movable Type format using the program’s built-in scripting language, UserTalk.

The program stores weblog entries in a database file called weblogData.root. Scripts written in UserTalk can read and write entries from that database, producing output as HTML, XML, and text.

The UserTalk script in Listing 14-5 reads all of the entries in weblogData.root, producing an output file in Movable Type format named radioExport.txt.

Listing 14-5: Creating Import Data in Radio UserLand
Start example
on exportToMovableType() {
    on add(line) {
        text = text + line + "\r\n"};
    on clean(line) {
        line = string.replaceAll(line, "-----", "- - - - -");
        line = string.replaceAll(line, "--------",
"- - - - - - - -")};
    local(text = "", outFile = file.folderFromPath(Frontier.getProgramPath())
+ "radioExport.txt");
    adrblog = radio.weblog.init();
    for adr in @adrblog^.posts {
        «Output an entry’s single-line fields
        if defined (adr^.when) {
            add("DATE: " + string.replaceAll(adr^.when, "; ", " "))};
        if defined (adr^.title) {
            add("TITLE: " + clean(adr^.title))};
        if defined (adr^.categories) {
            for adrcat in @adr^.categories {
                if nameOf(adrcat^) != "item #1" {
                    add("CATEGORY: " + nameOf(adrcat^))}}};
        add("STATUS: publish");
        add("ALLOW COMMENTS: 1");
        add("ALLOW PINGS: 1");
        «Output an entry’s multi-line fields
        if defined(adr^.text) {
            add("-----");
            add("BODY:");
            add(clean(string(adr^.text)))};
        add("--------")};
    file.writeTextFile(outFile, text)};
exportToMovableType()
End example

This script saves the file radioExport.txt in the directory where Radio UserLand was installed. No changes are made to the data, files, or Web pages that comprise the weblog—the script merely reads the database, making copies of entry data in a new text file.

The script must be created in Radio UserLand’s desktop application. To open the application in Windows, right-click the Radio icon in the System Tray and choose Open Radio from the context menu that appears.

With the application open, you can enter and run the UserTalk script. Choose Tools ® Developers ® Workspace. A workspace window opens in which you can work on the new script, as shown in Figure 14-1.

Click To expand
Figure 14-1: Creating a workspace for an export script.

This window displays a database table to which you can add scripts or data. To add a new script, choose Table ® New Script. A dialog box will ask for a name for the script. Call it exportToMovableType and click OK.

A script-editing window will appear with some UserTalk code already present (see Figure 14-2).

Click To expand
Figure 14-2: Writing a new script.

Enter the text of Listing 14-5, indenting lines as shown by using the Ctrl+L (Windows) or Cmd+L (Macs) key combination to move a line farther to the left, and the Ctrl+R or Cmd+R key combination to move it farther right.

When you’re done, click the Compile button to compile the file. If you have made a typo, an Error Info dialog box indicates the problem. Click the Go To button on this dialog box to return to the script at the line that triggered the error.

Once the script compiles successfully, click the Run button to execute the script, creating the radioExport.txt file.

Web Site Download

To save yourself some typing, a version of the exportToMovableType() script can be downloaded from my Web site and installed in Radio UserLand. Visit this Web page and download the Workbench.root tool: http://cadenhead.org/workbench/code.

The next section details how to bring this weblog data into Movable Type.


Importing Weblog Data to Movable Type

After weblog data has been stored in Movable Type’s import format, it must be uploaded to a specific directory on the Web server on which the software has been installed.

When the file or files are in the right place, they can be added to a weblog using the software’s Import Entries form, shown in Figure 14-3.

Click To expand
Figure 14-3: Importing weblog data using Movable Type’s browser interface.

One of the options on this form enables you to make yourself the author of every imported entry. The Import Entries as Me checkbox, when enabled, makes you the author of every incoming entry regardless of its AUTHOR field.

Otherwise, entries are credited to their authors using the username designated by that field. As Movable Type loads entries, it creates accounts for authors who do not have one yet, using a starting password entered in the Password field. (For this reason, you must provide a password when loading entries from multiple authors.)

You also can specify a default category and post a status for entries that do not define these settings with the CATEGORY or STATUS fields. Use the form’s Default pull-down menus to make these selections.

Note

If you do not select a default category, imported entries are not assigned a category if they do not contain a CATEGORY or PRIMARY CATEGORY field.

The lack of a selection in the Default Post Status for Entries checkbox causes Movable Type to use the weblog’s setting for new entries (click the Weblog Config menu button, click the Preferences link, and then scroll down to the Default Post Status text field).

The Start Title HTML and End Title HTML fields provide a means to extract title information from weblog tools that do not support titles. This technique only works when something in each weblog entry contains a title and is formatted in the same manner in each entry.

The following HTML code formats three weblog entries in a consistent manner:

<h3>Veterans Stadium imploded</h3>

<p>The three-decade home of the Phillies and Eagles was
demolished Sunday morning.
<a href=”http://sportsfilter.com/page.cfm/300”>link</a>

<h3>Rockets sign Oakley</h3>

<p>The Houston Rockets bring in Charles Oakley for 10-day
contract to “toughen up team.”
<a href=”http://sportsfilter.com/page.cfm/299”>link</a>

<h3>Mark Cuban starts weblog</h3>

<p>The Dallas Mavericks owner has launched an online site
to talk directly to the public.
<a href=”http://sportsfilter.com/page.cfm/298”>link</a>

In this code, each entry has a headline enclosed within opening and closing H3 tags. This could be designated as the entry’s title by putting <h3> in the Start Title HTML field and </h3> in the End Title HTML field.

When this technique isn’t necessary or when a weblog does not have anything that can be used as a title, leave those fields blank. Movable Type will use the first five words of the entry as a makeshift title.

Weblog data files you have created can be imported by following these steps:

  1. With an FTP client or a command-line shell, open the directory in which Movable Type’s scripts are installed.

  2. Create a new subdirectory named import if one doesn’t exist already.

  3. Place all files containing data to import in this new directory.

  4. In Movable Type’s browser interface, open the weblog that will be receiving the imported data.

  5. Click the Import/Export button on the sidebar menu. The Import/Export page opens, as shown in Figure 14-3.

  6. If you should be the author of all imported entries, check the Import Entries as Me checkbox and leave the Password field blank.

  7. Otherwise, leave the checkbox unchecked and enter a password of your choosing in the Password field. All newly created author accounts will use this password (although they should be encouraged to change it, for obvious security reasons).

  8. Use the Default Category and Default Post Status drop-down menus to select these settings, if desired.

  9. When extracting titles from weblog entry text, provide the proper HTML in the Start Title HTML and End Title HTML fields.

  10. Click the Import Entries button.

Movable Type loads the weblog data, reporting the success or failure of each entry.

Gotcha

Avoid the following bang-your-head-against-the-keyboard mistake I’ve made several times with Movable Type: leaving the imported weblog data in the import directory after it has been brought into the weblog. Importing the same entries twice can be a huge hassle to fix; you must hunt for and delete the entries manually, one at a time. To avoid this problem, remember to delete files immediately from the import directory after you’re done using them.


Summary

When Movable Type was originally released, developers Ben and Mena Trott stated that one of their motivations was to give webloggers unfettered access to their own data.

This promise has been kept with the software’s export feature, the XML-RPC interface; and the subject of this chapter, the weblog import feature.

Movable Type eagerly devours weblog data produced by Blogger, Radio UserLand, and other tools. If you have weblog entries, comments, and even trackback pings that were created elsewhere, you often can bring them with you.

Weblog data must be imported using a simple text format devised by Six Apart that has single- and multi-line fields to define each entry. You can start a new weblog with imported entries, add them to an existing weblog, or file them in a specific category.

Movable Type’s import feature supports all of the options available on the entry-editing form, including the capability to publish or draft entries and allow or disallow comments and trackback.


Chapter 15: Connecting to Movable Typewith XML-RPC

In This Chapter

  • Using XML-RPC

  • Handling the protocol’s data types

  • Sending an XML-RPC request

  • Receiving an XML-RPC response

  • Choosing a client implementation

  • Connecting to movable type’s XML-RPC server

  • Calling methods of the Movable Type API

  • Calling methods of the Blogger API

  • Calling methods of the MetaWeblog API

Movable Type adopts a Web browser–based user interface, a trade-off that makes the software easier for novices but sacrifices the power and flexibility of desktop software.

Users don’t need to make that trade. The software offers an interface that can be controlled from other programs, putting Movable Type to work in the background. The interface can be used to read and write weblog entries, retrieve category and trackback information, and more.

Three application programming interfaces (APIs) are supported: Blogger, MetaWeblog, and Movable Type’s own interface. A fourth, Atom, has been added in version 3 of the software.

These APIs enable software to call methods of Movable Type and receive a response in return. With the exception of Atom, they employ XML-RPC, a protocol that enables programs to work together whether they are located in the same room or on opposite sides of the world.

Using XML-RPC, programs can run on your desktop and offer a graphical user interface, publish data from one weblogging tool to another, exchange files, and perform other tasks.

Cross-Reference

Atom consists of an XML syndication format and an API that sends and receives data in that format over HTTP, the protocol used by Web servers and browsers to exchange information. For more on the effort, read Chapter 19, “Supporting the Atom Syndication Format and API.”


Using XML-RPC

XML-RPC was developed in 1998 by a weblogger, Dave Winer of UserLand Software, in cooperation with Microsoft. The protocol’s simplicity struck a chord with developers looking for an easy way to call procedures remotely over networks such as the Internet. Microsoft and developers in the UserLand and Python communities embraced the new protocol.

XML-RPC is a remote procedure call protocol tailor-made for programming over a network. The protocol has become one of the key elements of Web services implemented by software developers on Linux, Macintosh, UNIX, and Windows systems.

One prominent adopter of XML-RPC is Red Hat, which employs it on contemporary versions of the Red Hat Linux operating system. The Red Hat Network, a remote administration service that enables computers to be maintained and updated over the Internet, uses XML-RPC heavily.

Client/server implementations of XML-RPC are available for most platforms and programming languages. UserLand Software offers a directory of implementations on its XML-RPC.Com Web site at http://www.xmlrpc.com.

Eighty implementations of the protocol are available for a variety of languages and platforms, including C++, Java, Perk, PHP, and Python.

XML-RPC exchanges information using the tandem of HTTP, the protocol of the World Wide Web, and XML, a format for organizing data independent of the software used to produce it.

The following data types are supported by XML-RPC:

  • base64: Binary data encoded in Base 64 format

  • boolean: True-false values that are either 1 (true) or 0 (false)

  • dateTime.iso8601: A string containing the date and time in ISO 8601 format (such as 20040317T13:31:19 for 1:31 PM and 19 seconds on March 17, 2004)

  • double: Eight-byte signed floating-point numbers

  • int: Signed integers ranging in value from -2.14 billion to 2.14 billion (also called i4)

  • string: Text

  • struct: Name-value pairs of data for which the name is a string and the value can be any of the other data types

  • array: A data structure that holds multiple elements of any of the other data types, including arrays

Although this range of data types is slim pickings compared with most programming languages, you can represent complex data through the combination of array and struct data types.

Web Site Download

The full XML-RPC specification is available on XML-RPC.Com:

http://www.xmlrpc.com/spec

After the release of XML-RPC, the specification was extended by Microsoft, IBM, Lotus, and others to create another remote protocol called SOAP, the Simple Object Access Protocol.

Although SOAP shares some design objectives with XML-RPC, it has been expanded to support objects, user-defined data types, and other advanced features. Backed by Microsoft and other developers, SOAP also has become popular for Web services and other network programming.

Web Site Download

Because SOAP is appreciably more complex than XML-RPC, an argument can be made for using either one, depending on the needs of a software project.
Note

To find out more about SOAP, visit the XMethods Web site:

http://www.xmethods.com

XML-RPC is a protocol transmitted using Hypertext Transfer Protocol (HTTP), the standard for data exchange between Web servers and Web browsers. The information that it transmits is not Web content, but XML data encoded in a specific way.

All XML-RPC data exchanges consist of a client request followed by a server response. The client and server can be located on different machines and developed using different programming languages. As long as both sides speak XML-RPC, they can work together.

Sending an XML-RPC Request

An XML-RPC request consists of XML data sent to a Web server in an HTTP post request.

A post request transmits data from a Web browser to a Web server—Common Gateway Interface scripts and other software collect the data from a post request and send HTML back in response. When you fill out an e-mail form on a Web page or take an online survey, you’re using either post or a similar HTTP request called get.

XML-RPC uses HTTP as a convenient protocol for communicating with a server and receiving a response.

The request consists of HTTP headers required by the post transmission and the XML-RPC request, which is expressed as XML.

Listing 15-1 contains a sample XML-RPC request.

Listing 15-1: An XML-RPC Request
Start example
POST /cgi-bin/mt-xmlrpc.cgi HTTP/1.0
Host: www.cadenhead.org
Connection: Close
Content-Type: text/xml
Content-Length: 160
User-Agent: OSE/XML-RPC

<?xml version="1.0"?>
  <methodCall>
    <methodName>mt.getTrackbackPings</methodName>
    <params>
      <param>
        <value>
          <int>61</int>
        </value>
      </param>
    </params>
</methodCall>
End example

This request asks for a list of trackback pings associated with entry number 61 on a Movable Type installation.

Listing 15-1 is divided into two halves separated by a blank line. The first half consists of HTTP headers that request a Web server resource from a script, indicating the format and length of the request. The second half consists of the request formatted as XML.

Looking at this request reveals the following information:

  • The XML-RPC server is at http://www.cadenhead.org/cgi-bin/mt-xmlrpc.cgi.

  • The remote method being called is mt.getTrackbackPings.

  • The method is being called with one argument, an integer with a value of 61.

Contrary to what you might expect, method names in an XML-RPC request do not include parentheses. They consist of the name of a method, which can be preceded by a period and a group identifier.

The naming convention for XML-RPC methods depends on the server offering them. The methods offered by Movable Type consist of an interface identifier (blogger, metaWeblog, or mt) followed by a period and a method name.

Receiving an XML-RPC Response

An XML-RPC response is XML data sent back from a Web server like any other HTTP response. The protocol rides piggyback atop an established process—a Web server returning data via HTTP to a Web browser—and uses it differently.

Like the request, the response consists of HTTP headers and a response in XML format, separated by a blank line.

Listing 15-2 contains a response to the previous request for a weblog entry’s trackback pings.

Listing 15-2: An XML-RPC Response
Start example
 HTTP/1.0 200 OK
Date: Thu, 18 Mar 2004 22:09:08 GMT
Server: Apache/1.3.27 (Unix)  (Red-Hat/Linux) mod_gzip/1.3.26.1a
mod_ssl/2.8.12
OpenSSL/0.9.6 DAV/1.0.2 PHP/4.1.2 mod_perl/1.24_01 mod_throttle/3.1.2
SOAPServer: SOAP::Lite/Perl/0.52
Vary: *
Content-Length: 788
Connection: close
Content-Type: text/xml

<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
  <param>
    <value>
      <array>
        <data>
           <value>
             <struct>
               <member>
                 <name>pingTitle</name>
                 <value>
                   <string>Coaster makes you cry ‘Mummy!’</string>
                 </value>
               </member>
               <member>
                 <name>pingURL</name>
                 <value>
                   <string>http://example.com/000087.html</string>
                  </value>
                </member>
                <member>
                  <name>pingIP</name>
                  <value>
                    <string>192.0.34.166</string>
                  </value>
                </member>
              </struct>
            </value>
          </data>
        </array>
      </value>
    </param>
  </params>
</methodResponse>
End example

The response reveals the following details:

  • The response is 788 bytes in size and in XML format.

  • The entry has one trackback ping with the title “Coaster makes you cry ‘Mummy!’,” the IP address 192.0.34.166, and the URL http:// www.example.com/000087.html.

Although an XML-RPC request can contain 0, 1, or many parameters, an XML-RPC response always consists of a single value, which can be any of the XML-RPC data types. Because this value can be an array, a struct, or even an array of structs, a lot of information can be packaged in that single value.

The response in Listing 15-2 sends back trackback ping information in an array of structs, one per ping. The beginning and end of the array are established by the data tag. Each struct is stored within opening and closing struct tags.

Web Site Download

Although you don’t have to see raw XML-RPC requests and responses, it helps considerably when you’re testing an implementation.

Dumpleton Software offers an excellent XML-RPC debugger on the Web that can be used to call remote methods and see the full XML-RPC request and response, which makes it much easier to determine whether a client or server is working correctly:

http://www.dscpl.com.au/xmlrpc-debugger.php

When an XML-RPC request is unsuccessful, failure is indicated by a struct that holds faultString, a string holding an error message, and faultCode, a numeric error code.


Connecting to Movable Type with Client Software

The robust application programming interfaces for Movable Type have inspired several developers to create weblog editing tools that can be used with the software.

Figure 15-1 shows w.bloggar (see http://wbloggar.com), one of the better clients that has been offered for Movable Type users.

Click To expand
Figure 15-1: Editing a Movable Type weblog entry with desktop software.

In Figure 15-1, an entry created with Movable Type’s browser interface has been loaded for editing in w.bloggar. The software, released as freeware by Brazilian programmer Marcelo L. L. Cabral, can be used to write, edit, and delete weblog entries.

With features similar to word processing software, w.bloggar offers spell-check, file upload, HTML formatting toolbars and menus, and a text import feature. Setting it up to work with an existing Movable Type installation takes under five minutes.

Because so many weblogging tools use the same XML-RPC interfaces, the w.bloggar software works with more programs than Movable Type. You can use it as an authoring tool for Blogger, LiveJournal, Drupal, Blosjom, and more than a dozen other server-based weblogging tools.

Table 15-1 contains information about software that works with Movable Type using XML-RPC.

Table 15-1: Movable Type XML-RPC Clients
Software | Description | Platform | Home Page
BloGTK | Weblog editor for Movable Type and other server-based weblogging tools | Linux | http://blogtk.sourceforge.net
Ecto | Weblog editing client for Movable Type and many other tools | MacOS | http://www.kung-foo.tv/ecto
Footbridge | Tool that adds Movable Type publishing support to Radio UserLand | Windows, MacOS | http://markpasc.org/code/radio
Kablog | Tool to publish weblog entries from a mobile phone or PDA to Movable Type and others | J2ME, PalmOS, Symbian | http://www.rawthought.com
Slug | Simple weblog editing client for Movable Type | Windows | http://www.3e.org/slug
w.blogger | Weblog editing client for Movable Type and others | Windows | http://wbloggar.com
Zempt | Movable Type weblog editing client for Windows | Windows | http://www.zempt.com


Using Movable Type's XML-RPC Server

Team LiB

Using Movable Type’s XML-RPC Server

Movable Type’s XML-RPC server has been implemented as mt-xmlrpc.cgi, one of the Perl scripts in the software’s main installation folder.

Any software that calls the server must know the server’s URL, which is Movable Type’s CGI path followed by the name of the script. For example, the XML-RPC server on the domain cadenhead.org is at this URL:

http://cadenhead.org/cgi-bin/mt-xmlrpc.cgi

This script requires two Perl libraries that are part of the Movable Type installation: LWP::UserAgent and SOAP::Lite. The latter library includes XMLRPC::Lite, a client/server implementation of the XML-RPC protocol.

The only purpose of the mt-xmlrpc.cgi script is to handle XML-RPC requests. If you decide not to offer any XML-RPC services or need to temporarily disable the functionality for some reason, you can rename or remove the script.

Movable Type’s implementation of XML-RPC supports three weblog publishing APIs released in the following chronological order: Blogger, MetaWeblog, and Movable Type’s own interface. Although developed separately, these three interfaces build on each other and can be used in a complementary fashion.

Each of the APIs contains methods that fill in a gap of its predecessor. MetaWeblog expanded Blogger’s support for entry text to add titles, links, and other types of information. Movable Type extended MetaWeblog with methods to support trackback pings, text filters, and other features specific to the software.

You can use these APIs using one of the XML-RPC libraries described on the XML-RPC Web site:

http://www.xmlrpc.com/directory/1568/implementations

Some of the implementations worth a look are SOAP::Lite, the Perl library used by Movable Type; Apache XML-RPC, an open-source Java class library; and xmlrpclib, a Python library developed by Fredrik Lundh that was the first to offer support for XML-RPC after UserLand.

Gotcha

The biggest obstacle to using XML-RPC in any language is mapping XML-RPC data types to the ways in which data is represented in the language. Learn that first when evaluating an implementation, because it’s a good indicator of whether you’ve found the right tool for the job.

After developing Java applications that used Apache XML-RPC, I learned the hard way that I should’ve begun with the following page on mapping data types:

http://ws.apache.org/xmlrpc/types.html


Calling Methods of the Blogger API

Blogger, server-based publishing software that helped spark the weblog phenomenon, was the first weblogging tool that offered an XML-RPC interface. The Blogger API has been supported by dozens of client tools and several servers, including Movable Type.

Web Site Download

The Blogger API, which has been frozen at version 1.0, is documented on the Web at http://www.blogger.com/developers/api/1_docs.

The API includes methods to read, write, edit, and delete weblog entries; methods to read and write site templates; and two methods to retrieve information about a user.

Movable Type supports all of the Blogger API methods except for Blogger.getTemplate and Blogger.setTemplate. Blogger templates vary substantially from the template system in Movable Type, so there’s no way to use them interchangeably.

A limitation of this API is its lack of support for all of the fields that can be used to author a weblog entry in Movable Type. The only field supported is the text of an entry. The other parts of Movable Type’s entry-editing form—the title, extended entry, excerpt, categories, and keywords—cannot be accessed in any manner using Blogger methods.

The Blogger API was designed to work with an appkey, a string that uniquely identifies the application making the request. Pyra, the division of Google that develops Blogger, will issue free appkeys to software developers, as described later in this section.

The value of an appkey is ignored by Movable Type, so you don’t need to receive an appkey to make use of the Blogger API’s methods. You can use an empty string or anything else in place of a key.

The next six sections describe Blogger API methods supported by Movable Type.

blogger.newPost

Create a new weblog entry that can be stored as a draft or immediately published. This method returns the ID number of the entry if successful.

Its parameters are as follows:

  • appkey (string), the Blogger application key, which is ignored by Movable Type

  • blogid (int), the blog ID of the weblog receiving the entry

  • username (string), the username of the author

  • password (string), the password of the author

  • content (string), the content of the entry

  • publish (boolean), a flag indicating whether to publish the entry (1) or save it as a draft (0)

Because the Blogger API does not support titles, the first several words of the entry are used as a title.

blogger.editPost

Replace an existing weblog entry and either publish it immediately or store it as a draft. This method returns 1 (boolean true) if the entry was replaced successfully.

Its parameters are as follows:

  • appkey (string), the Blogger application key

  • postid (int), the ID number of the weblog entry to replace

  • username (string), the author’s username

  • password (string), the author’s password

  • content (string), the new content of the entry

  • publish (boolean), a flag indicating whether to publish the entry (1) or save it as a draft (0)

blogger.deletePost

Delete an entry. This method returns 1 (boolean true) if the entry was replaced successfully.

Its parameters are as follows:

  • appkey (string), the Blogger application key

  • postid (int), the ID number of the weblog entry to delete

  • username (string), the author’s username

  • password (string), the author’s password

  • publish (boolean), a flag indicating whether to rebuild the site after deletion of the entry (1) or not (0)

Because this API lacks a method to rebuild the weblog, if you delete a post with a publish parameter of 0, you’ll be left without a convenient way to make the site reflect the deletion. The deleted entry won’t vanish until the site is rebuilt after an entry is added or edited (or Movable Type’s browser interface is used to rebuild it).

blogger.getRecentPosts

Retrieve one or more recent entries from a weblog. This method returns an array of structs, each of which holds the following values about an individual entry:

  • content (string), the text of the entry

  • dateCreated (dateTime.iso8601), the date and time when the entry was first saved

  • postid (string), the ID number of the entry

  • userid (string), the author’s ID number

The dateCreated value uses the same time zone as the weblog containing the entry.

Its parameters are as follows:

  • appkey (string), the Blogger application key

  • blogid (int), the weblog’s ID number

  • username (string), the author’s username

  • password (string), the author’s password

  • numberOfPosts (int), the number of entries to retrieve

To retrieve all of a weblog’s entries using this method, use a numberOfPosts parameter of 0.

Caution

In the course of preparing this chapter, I found a bug in Movable Type’s implementation of this method. If you try to retrieve an entry containing curly-quote characters (also called smart quotes) or curly apostrophes, the method call fails with an error of the following form: “xmllib.Error: Syntax error at line x: illegal character in content.” This occurs because Movable Type doesn’t encode the character properly in the XML-RPC response. To fix the problem, find and edit the weblog entries that contain these characters, replacing the smart quotes and curly apostrophes with straight quotes and apostrophes.

blogger.getUsersBlogs

Retrieve a list of weblogs to which an author can post entries. This method returns an array of structs upon a successful call. Each struct holds three values about a particular weblog:

  • blogid (string), the blog ID of the weblog

  • blogName (string), the weblog’s name

  • url (string), the home page of the weblog

There’s no limit to the number of structs that can be present in the array.

Its parameters are as follows:

  • appkey (string), the Blogger application key

  • username (string), the author’s username

  • password (string), the author’s password

blogger.getUserInfo

Retrieve a weblog author’s account information in the Movable Type database. This method returns a struct that holds six values:

  • email (string), the user’s e-mail address

  • firstname (string), the user’s first name

  • lastname (string), the user’s last name

  • nickname (string), the user’s nickname

  • url (string), the user’s home page

  • userid (string), the user’s ID number in your Movable Type installation

The e-mail address, home page, and nickname are taken directly from your profile in Movable Type. The userid value comes from an ID number that the software uses internally to manage weblog authors. There’s nothing you can do with this information in any of the XML-RPC methods described in this chapter.

Before making use of the firstname and lastname values, take note that both are rough guesses based only on the username. There’s no guarantee that either one is actually a first or last name—the firstname value contains everything up to the first space in the username, and lastname contains everything after that space. When a username has no spaces, firstname is the same as username and lastname is an empty string.

Its parameters are as follows:

  • appkey (string), the Blogger application key

  • username (string), the author’s username

  • password (string), the author’s password

Acquiring a Blogger Application Key

Although the appkey is ignored by Movable Type, Blogger and other software that support the Blogger API aren’t so permissive. You can easily acquire one of these keys by filling out a request on the Blogger Web site:

http://www.blogger.com/developers/api/1_docs/register.html

You must provide your name and e-mail address along with the name and home page of your software. An appkey will be sent immediately in response.


Calling Methods of the MetaWeblog API

A drawback to the Blogger API becomes apparent on any weblog that makes use of entry titles. The representation of entries has became more sophisticated with the introduction of titles, links, permanent links, and other elements that are now commonplace.

The MetaWeblog API, released by Dave Winer of UserLand Software, supports a more complex representation of weblog entries than the Blogger API. The original impetus for the new interface was to support the authoring capabilities of Manila and Radio UserLand, two popular weblogging tools for Microsoft Windows, Mac Classic, and Mac OS X offered by UserLand.

This API is documented on the Web:

http://www.xmlrpc.com/metaWeblogApi

By design, in the MetaWeblog API, each entry can hold anything that can be represented in RSS 2.0, a popular XML format for site syndication.

RSS files, which are called newsfeeds or feeds, include an item element with subelements for a weblog entry’s title, link, and description, as well as many other kinds of information. You can read the RSS 2.0 specification on the Web:

http://blogs.law.harvard.edu/tech/rss

Because RSS 2.0 files can be extended to support new kinds of information, the API provides a way to send and receive an entry no matter what values it contains.

Cross-Reference

Two RSS formats, RSS 1.0 and RSS 2.0, are both copiously documented in Chapter 18, “Publishing RSS and Atom Syndication Files.”

Movable Type supports all of the MetaWeblog API methods except for metaWeblog.getCategories, which provides the name, URL, and RSS feed URL for all of a weblog’s categories.

The Movable Type implementation extends the interface to support the information collected on the software’s entry-editing form.

Several methods of this API employ a struct named content that represents a weblog entry. The struct serves as a parameter to the metaWeblog.newPost and metaWeblog.editPost methods and is returned by metaWeblog.getPost and metaWeblog.getRecentPost.

In Movable Type’s implementation, the content struct holds the following values:

  • title (string), the title of the entry

  • description (string), the text of the entry

  • dateCreated (dateTime.iso8601), the date and time when the entry was first saved

  • mt_allow_comments (boolean), a flag indicating whether comments are allowed (1) or disallowed (0)

  • mt_allow_pings (boolean), a flag indicating whether trackback pings are allowed (1) or disallowed (0)

  • mt_convert_breaks (string), the key that identifies the text formatting filter used to format the entry

  • mt_text_more (string), the extended entry text

  • mt_excerpt (string), the entry’s excerpt

  • mt_keywords (string), the keywords associated with the entry

The struct does not include flNotOnHomePage, a boolean flag specified in the MetaWeblog API, or anything else that could be defined in an RSS 2.0 newsfeed. Some methods in Movable Type’s implementation add additional values to the content struct.

Cross-Reference

Later in this chapter, you learn about a method of the Movable Type XML-RPC API, mt.supportedTextFilters, that provides the keys that can be used as the value for mt_convert_breaks.

The following five sections document the API methods supported by Movable Type.

metaWeblog.newPost

Create a new weblog entry, storing it as a draft or publishing it immediately. This method returns an int containing the ID number of the entry, if it was saved successfully.

One of the specified parameters must be the content struct, defined in the preceding section. The struct also can contain mt_tb_ping_urls, an array of URLs for trackback pings sent with the entry.

Its parameters are as follows:

  • blogid (int), the ID number of the weblog

  • username (string), the entry author’s username

  • password (string), the author’s password

  • content (struct), a struct defining the entry’s content

  • publish (boolean), a flag indicating whether to publish the entry (1) or save it as a draft (0)

metaWeblog.editPost

Replace a weblog entry, either in published form or as a draft. This method returns 1 (boolean true) if the entry was replaced successfully.

The content struct is employed in the method call.

Its parameters are as follows:

  • postid (int), the entry’s ID number

  • username (string), the author

  • password (string), the author’s password

  • content (struct), the content of the entry

  • publish (boolean), a flag indicating whether to publish the entry (1) or just store it (0)

metaWeblog.getPost

Retrieve a weblog entry. When it is called successfully, this method returns a content struct with a few additional values:

  • link (string), the URL of the weblog entry

  • permalink (string), the permanent link of the entry (which is often the same thing as the link)

  • postid (string), the entry’s ID number

  • userid (string), the entry author’s username

Its parameters are as follows:

  • postid (int), the entry’s ID number

  • username (string), the entry’s author

  • password (string), the author’s password

Although Movable Type’s user manual states that this method also returns an mt_tb_ping_urls value in the content struct, this does not appear to be the case in the current version of the software.

metaWeblog.getRecentPosts

Retrieve one or more recent entries from a weblog. Because the number of entries is configurable and has no maximum, this method can be used to export an entire weblog over XML-RPC.

This method returns an array holding a content struct for each entry. This struct contains the following additional values:

  • link (string), the URL of the weblog entry

  • permalink (string), the permanent link of the entry (which is often the same thing as the link)

  • postid (string), the entry’s ID number

  • userid (string), the entry author’s username

Its parameters are as follows:

  • blogid (int), the weblog’s ID number

  • username (string), the author

  • password (string), the author’s password

  • numberOfPosts (int), the number of entries to retrieve, or 0 for all entries

This method does not include an mt_tb_ping_urls value in the content struct.

metaWeblog.newMediaObject

Upload a file to the Web server hosting Movable Type. Because XML-RPC delivers information over the text-based protocols XML and HTTP, file data must be converted from its binary form before it can be transferred.

The file must be encoded using Base 64, a technique for transmitting binary data through text-only media such as electronic mail.

This method returns a string containing the URL where the file can be viewed on the Web. One of the parameters is a struct named file that holds two values:

  • bits (string), the Base 64–encoded text of the file

  • name (string), the name of the file

Its parameters are as follows:

  • blogid (int), the weblog’s ID number

  • username (string), the entry author

  • password (string), the author’s password

  • file (struct), the file

The MetaWeblog API dictates that the file struct also should contain a string named type that identifies the MIME type of the file. Movable Type does not support this parameter, so it will be ignored if present.


Calling Methods of the Movable Type API

Although the XML-RPC methods supported by the Blogger and MetaWeblog APIs are useful, they don’t support some popular capabilities of Movable Type.

Therefore, Movable Type has created its own API to complement the functionality of the other APIs. Six methods are available for working on a weblog, storing and retrieving entry categories, reading titles and trackback pings, and rebuilding a weblog.

Also available are two methods for providing information about an installation of Movable Type: mt.supportedMethods, to see which XML-RPC methods it supports; and mt.supportedTextFilters, to learn which text formatting options are available.

The next eight sections describe these methods.

mt.publishPost

Rebuild all of the files associated with a weblog entry. This method can be used to publish an entry that has been saved as a draft. It returns 1 (boolean true) if the files were rebuilt successfully.

Its parameters are as follows:

  • postid (int), the ID number of the entry

  • username (string), the author’s username

  • password (string), the author’s password

This method does not send any pings to weblogs.com, blo.gs, or trackback-enabled sites linked in the entry.

mt.getCategoryList

Retrieve the categories defined for a weblog. This method returns an array of structs, each of which holds the following values about an individual entry:

  • categoryId (string), the ID number of the category, which is specific to that weblog

  • categoryName (string), the category’s name

If a weblog does not use categories, the method returns an empty array.

Its parameters are as follows:

  • blogid (int), the weblog’s ID number

  • username (string), the author’s username

  • password (string), the author’s password

mt.getPostCategories

Retrieve the categories assigned to a weblog entry.

When an entry has at least one category, this method returns an array of structs that identify each category associated with the entry:

  • categoryId (string), the category’s ID number, which is specific to an individual weblog

  • categoryName (string), the category’s name

  • isPrimary (boolean), a flag that equals 1 (boolean true) for an entry’s primary category, or 0 (boolean false) otherwise

The method returns an empty array when an entry has no assigned categories.

Its parameters are as follows:

  • postid (int), the ID number of the entry

  • username (string), the author’s username

  • password (string), the author’s password

mt.setPostCategories

Set the categories for a weblog entry or remove all categories. This method returns 1 (boolean true) if the call was successful.

Its parameters are as follows:

  • postid (string), the ID number of the entry

  • username (string), the author’s username

  • password (string), the author’s password

  • categories (array), an array of structs for each category

Each struct in the categories array can contain three values:

  • categoryId (int), the category’s ID number

  • categoryName (string), the category’s name

  • isPrimary (boolean), a flag that equals 1 (boolean true) for an entry’s primary category, and 0 otherwise

The isPrimary value can be omitted from each struct. When it is not present, the first category in the categories array will be designated as the primary.

Call this method with an empty array as the categories parameter to remove all categories from the entry.

mt.getTrackbackPings

Retrieve information about trackback pings associated with an entry.

This method returns an array of structs, each of which holds the following values about a trackback ping:

  • pingIP (string), the IP address from which the ping was received

  • pingTitle (string), the title of the weblog entry associated with the trackback ping

  • pingURL (string), the ping’s URL

If the entry has not received any pings, the method returns an empty array.

Its parameter is as follows:

  • postid (int), the entry’s ID number

mt.getRecentPostTitles

Retrieve one or more entry titles from a particular weblog. This method returns an array of structs, each holding the following values about an individual entry:

  • dateCreated (dateTime.iso8601), the date and time when the entry was originally saved

  • postid (string), the ID number of the entry

  • title (string), the entry’s title

  • userid (string), the ID number of the entry’s author

The dateCreated value uses the same time zone as the weblog containing the entry.

Its parameters are as follows:

  • blogid (int), the weblog’s ID number

  • username (string), the author’s username

  • password (string), the author’s password

  • numberOfPosts (int), the number of entries to retrieve

To retrieve all of a weblog’s entries using this method, use a numberOfPosts parameter of 0.

mt.supportedTextFilters

Find out what text filters are supported by this particular installation of Movable Type. Filters process the text of entries as they are published, making changes to the HTML formatting to support validation and other purposes.

On Movable Type’s entry-editing form, the Text Formatting field selects the filter that applies to the entry. By default, the Convert Line Breaks filter places all paragraphs between opening and closing P tags and converts line breaks to BR tags.

This method returns an array of structs, each holding two values about an individual entry:

  • key (string), a unique string identifier for the text formatting plug-in

  • label (string), the name of the plug-in

This method does not require any parameters. The key can be used with the MetaWeblog.newPost and MetaWeblog.editPost methods described earlier in this chapter.

mt.supportedMethods

Find out what XML-RPC methods the Movable Type installation supports. This method returns an array of strings containing the names of each supported method, including methods of the Blogger and MetaWeblog APIs. One method is omitted: mt.supportedMethods itself.

No parameters are required to call this method, which can be used to ensure that a Movable Type installation has up-to-date support for XML-RPC methods as they are added to the software.


Summary

Movable Type’s browser-based interface is among its most well-regarded features, praised by users and technology journalists alike. One of the company’s advantages has been the work of Six Apart co-founder Mena Trott, who worked as a Web designer for a Silicon Valley Internet company before starting her new life as weblogging mogul.

For this reason, it’s a little ironic that Movable Type makes it so easy to avoid using the interface. By supporting XML-RPC interfaces, Movable Type can serve a weblog in the background for a client that takes user input.

Movable Type supports four application programming interfaces (APIs), including the three described in this chapter and the Atom API, which is covered in Chapter 19.

XML-RPC, a protocol for exchanging XML data over HTTP, makes it simple for one program to call another program’s method over the Internet, receiving a response in the same format.

With 80 implementations of XML-RPC available for Perl, Python, Java, and many other languages, computers can author Movable Type content as easily as humans can.


Chapter 16: Enhancing Movable Type withPlug-Ins

In This Chapter

  • Finding plug-ins

  • Downloading and installing programs

  • Using the plug-ins directory

  • Copying modules to the proper extlib directory

  • Placing plug-in tags in a template

  • Using additional category tags

  • Retrieving data from a MySQL database

  • Working with Movable Type’s database tables

  • Putting Perl code on a template

Movable Type’s template-driven publishing system offers more than 100 template tags that present weblog data and other kinds of content. These tags, which are structured in a format identical to HTML, produce output that’s incorporated into files as they are rebuilt.

The net result of this process is a terrific content-management system that feels like HTML but delivers customized functionality.

This process succeeds because the duties of Web designers and programmers become more distinct. Designers work with HTML and template tags similar to HTML, concentrating on the end result—the content produced by tags. Six Apart delivers the functionality for those tags behind the scenes, using Perl code to efficiently collect and publish information.

The same relationship has been taken further with plug-ins, which are add-on enhancement programs that enable programmers to graft new functionality onto Movable Type.

Plug-ins, which also are written in the Perl language, work so seamlessly with Six Apart’s template tags that you won’t be able to tell them apart. Once you’ve downloaded a plug-in, Movable Type treats it just like one of its own template tags.


Extending the Capabilities of Movable Type

Anyone who can write Perl programs can extend the functionality of Movable Type by designing a plug-in, a process that has been documented by Six Apart to encourage the growth of a development community around the software.

Movable Type’s plug-in framework turns a nicely designed weblog publishing tool into a more ambitious platform for a wide range of publishing and information-gathering applications.

Web Site Download

The place to begin experiencing this aspect of the software is the Movable Type Plugins directory at http://mt-plugins.org. This Web site, compiled by users independently of Six Apart, catalogs dozens of plug-ins offered for free download on the Web, many under an Open Source license that permits modifications to the code.

Cross-Reference

Plug-in programming is described in Chapter 20, “Developing New Plug-Ins with Perl,” and Chapter 21, “Hooking into Movable Type with Callbacks.”

This chapter looks at plug-ins from a user’s perspective, describing how you can install and use a collection of useful plug-ins.

There are far more plug-ins available for the software than can be covered in this book, but once you have connected a few to your Movable Type installation, the process of adding more on your own should be fairly straightforward.

The plug-ins covered in this chapter were developed by Brad Choate, an inventive programmer who has been publishing with Movable Type since the first public release of the software in October 2001.

Web Site Download

Brad Choate, whose site is found at http://www.bradchoate.com, has developed 16 plug-ins at the time of this writing. You’re already using one of them—Sanitize, a program that strips undesired HTML out of comments, was incorporated into Movable Type with version 2.6. He also wrote the code to support the MTElse tag.


Linking to Previous Years

Often, some of the most useful Movable Type plug-ins are also the simplest.

Brad Choate’s MTOnThisDay plug-in offers an easy-to-implement tag that adds an “on this day” feature to your weblog archives that looks back one, two, or more years ago for entries written on the same calendar date. You can see an example circled in Figure 16-1.

Click To expand
Figure 16-1: Viewing content produced with the MTOnThisDay plug-in.

This plug-in adds an MTOnThisDay container tag that can be incorporated into templates. Listing 16-1 contains the HTML code that produced the “On This Day” section of the Web page in Figure 16-1.

Listing 16-1: Adding On This Day Archive Links to a Page
Start example
<MTOnThisDay>
<h2>On This Day</h2>
<ul>
<MTEntries>
<MTDateHeader>
<li><MTEntryDate format="%Y">:
<a href="<MTEntryPermalink>"><MTEntryTitle></a></li>
</MTDateHeader>
</MTEntries>
</ul>
</MTOnThisDay>
End example

As you can see from Listing 16-1, plug-in template tags can be used in relationship to built-in template tags offered in Movable Type. They often work cooperatively.

In this example, the MTOnThisDay container tag selects entries for the MTEntries tag inside the container, limiting it to entries published on the same calendar day and month. (You also can use the author and category attributes in the MTEntries tag to further limit the selection of entries.)

The MTOnThisDay tag also can be used on individual entry pages, selecting entries from the same day and month in preceding years.

Before you can use the MTOnThisDay tag in a template, you must download and install the plug-in that supports its functionality. Trying to use a plug-in’s tag without the plug-in results in an error during site rebuilds.

Web Site Download

The MTOnThisDay plug-in can be downloaded as a ZIP archive from Choate’s Web site: http://bradchoate.com/weblog/2002/07/03/mtonthisday.

A Movable Type plug-in consists of a single Perl program that represents the plug-in and possibly one or more Perl modules required by the program. Often included are additional files and documentation—Choate’s programs include readme.txt, a text file explaining how to use the plug-in, and license.txt, the software’s license.

The license for this plug-in permits redistribution and modification of the program, as long as his copyright notice has been reproduced fully in the derivative work. Some of his other programs have similar licensing.

The MTOnThisDay plug-in can be installed as a single file: onthisday.pl.

Plug-ins must be stored in the software’s plugins subdirectory. If you have installed Movable Type in the /etc/httpd/cgi-bin directory, a plug-in program should be saved in /etc/httpd/cgi-bin/plugins. Create a plugins subdirectory if it doesn’t exist.

Once onthisday.pl has been stored in the plug-ins directory, you’re done. Movable Type detects the plug-in automatically. From this point, you can use the MTOnThisDay template tag as if it were a built-in part of the Movable Type software.


Managing Weblog Authors

The next offering from Brad Choate, the MTAuthors plug-in, adds a set of tags to credit authors who work on a particular weblog, displaying their names, e-mail addresses, and other details.

The plug-in offers an MTAuthors container tag that holds eight tags providing information about a particular author.

When placed in a template, the following code displays all of a weblog’s authors in an unnumbered list, linking their names to their home pages:

<ul>
<MTAuthors>
  <li><a href="<MTAuthorLink>"><MTAuthorName></a></li>
</MTAuthors>
</ul>
Web Site Download

MTAuthors can be downloaded as a ZIP archive from Choate’s Web site: http://bradchoate.com/weblog/2002/08/01/mtauthors.

The software includes the plug-in file, author.pl, and a Perl module, author.pm, which is used by the plug-in and must be present on the server.

When a plug-in includes a Perl module, it should be installed in Movable Type’s extlib directory or one of its subdirectories. The specific location is provided by the plug-in author.

Choate’s Perl modules are placed in the extlib/bradchoate subdirectory, which should be created if it doesn’t already exist.

To install the MTAuthors plug-in, follow these steps:

  1. Place the author.pl Perl script in Movable Type’s plugins directory.

  2. In the extlib directory, create a subdirectory named bradchoate.

  3. Store the author.pm Perl module in this new subdirectory.

The tags supported by the plug-in are listed in Table 16-1.

Table 16-1: MTAuthors Plug-in Tags
Tag | Description | Attributes
MTAuthorBlogCount | The number of weblogs to which the author can contribute |
MTAuthorEmail | The author’s e-mail address | spam_protect
MTAuthorEntryCount | The number of entries written by the author |
MTAuthorID | The author’s ID number |
MTAuthorName | The author’s username |
MTAuthorNickname | The author’s nickname |
MTAuthorLink | The author’s home page or e-mail address | spam_protect
MTAuthors | The container tag holding all authors on a Movable Type installation | permissions
MTAuthorURL | The template module that contains the source text |

Normally, the MTAuthors container holds all authors who have been added to a weblog, whether or not they have been assigned any specific privileges through Movable Type’s system of permissions.

The container tag filters authors based on assigned permissions through the use of the aptly named permissions attribute, which contains one or more of the following permissions: edit_all_posts, edit_authors, edit_categories, edit_config, edit_notifications, edit_templates, rebuild, send_notifications, post, and upload.

Authors with any of the listed permissions are included within the container. Multiple permissions can be included in the permissions attribute’s value by separating them with commas.

The following code displays a list of authors who can post weblog entries and rebuild the site:

<MTAuthors permissions=”post, rebuild”>
  <p><MTAuthorName></p>
</MTAuthors>

The MTAuthors plug-in provides access to part of Movable Type’s database that isn’t supported by existing tags. You can take advantage of it with another enhancement program described later in this chapter: the SQL plug-in.


Enhancing Category Tags

The Supplemental Category Tags plug-in adds seven new template tags for presenting information about weblog categories.

Web Site Download

The plug-in can be downloaded as a ZIP archive from Choate’s Web site at http://bradchoate.com/weblog/2002/10/31/ supplemental-category-tags.

To install this plug-in, follow these steps:

  1. Place the catx.pl Perl script in Movable Type’s plugins directory.

  2. If this is the first plug-in by Choate that you have installed, create a subdirectory named bradchoate in the extlib directory.

  3. Store the catx.pm Perl module in this subdirectory.

With the installation of these files, you can begin using the following tags: MTCategoryPrevious, MTCategoryNext, MTIfCategory, MTIfPrimaryCategory, MTIfNotCategory, MTIfNotPrimaryCategory, and MTEntryAdditionalCategories.

The MTCategoryPrevious and MTCategoryNext container tags hold information about categories that are adjacent to the present category, either on a category archive page or an individual entry.

One use of these tags is to provide a link on each category archive to other categories. Visitors can click the links to jump from category to category, skimming the topical organization of the weblog. Here’s a demonstration:

<MTCategoryPrevious>
<a href=”<MTCategoryArchiveLink>”><MTCategoryLabel></a>
</MTCategoryPrevious> |
<MTCategoryNext>
<a href=”<MTCategoryArchiveLink>”><MTCategoryLabel></a>
</MTCategoryNext>

The MTCategoryPrevious and MTCategoryNext tags skip categories that do not have any weblog entries assigned to them. This behavior can be overridden by using a show_empty attribute on either tag, with a value of 1.

If you are using these tags to link to category archive pages with the MTCategoryArchiveLink tag, using show_empty=”1” will result in broken links. Movable Type creates archive pages only for categories that contain at least one entry.

The MTAdditionalCategories tag functions like the MTEntryCategories template tag with one important exception: the primary category is omitted. The glue attribute provides a separator that will be displayed between listed categories.

The following code displays the additional categories assigned to a weblog entry:

<p>Also in: <MTEntryAdditionalCategories glue=”, “>
    <MTCategoryLabel>
</MTEntryAdditionalCategories>

The final four tags provide category-aware containers that display content only if the value of their name attribute matches the current category (on a category archive page) or a weblog entry’s selected categories.

The following template code displays an icon graphic only if a weblog entry belongs to a category named Disney:

<MTIfCategory name=”Disney”>
    <img src=”wd_icon.gif” height=”80” width=”80”>
</MTIfCategory>

This could appear in the category archive template, displaying the icon only for the Disney category’s archive page. It also could be placed within an MTEntries container, displaying the icon when an entry belongs to the Disney category.

The MTIfCategory and MTIfNotCategory containers test for any category. MTIfPrimaryCategory and MTIfNotPrimaryCategory are more specific, checking only the primary category for entries.


Retrieving Weblog Data Using MySQL

A Movable Type installation that uses MySQL as its database can take advantage of the SQL plug-in, a set of tags that retrieve entries, comments, and other weblog data from the database using Structured Query Language (SQL).

Web Site Download

The plug-in can be downloaded as a ZIP archive from Brad Choate’s Web site at http://bradchoate.com/weblog/2002/07/11/sql-plugin.

Use the following steps to set up this plug-in to work:

  1. Place the sql.pl Perl script in Movable Type’s plugins directory.

  2. In the extlib directory, create a subdirectory named bradchoate if one does not already exist.

  3. Store the sql.pm Perl module in this new subdirectory.

Once the plug-in has been installed, you can use the nine template tags listed in Table 16-2.

Table 16-2: MTAuthors Plug-in Tags
Tag | Attributes | Description
MTSQL | default, query | A container tag that executes the specified SQL query, looping through the matching rows
MTSQLAuthors | default, query, unfiltered | A container tag that uses the query to select weblog editors
MTSQLCategories | default, query, unfiltered | A container tag that uses the query to select weblog categories
MTSQLColumn | column, default, format | Display the row column identified by the column attribute formatted according to the format attribute
MTSQLComments | default, query, unfiltered | A container tag that uses the query to select comments
MTSQLEntries | default, query, unfiltered | A container tag that uses the query to select weblog entries
MTSQLFooter |  | Display this tag’s contents only in the container’s last row
MTSQLHeader |  | Display this tag’s contents only in the container’s first row
MTSQLPings | default, query, unfiltered | A container tag that uses the query to select trackback pings

The MTSQL plug-in requires familiarity with MySQL, SQL, and the database tables adopted by Movable Type.

Several tags share attributes in common: default, which assigns a value that will be returned when an SQL query finds no matching rows, and unfiltered=”1”, which suspends Movable Type’s normal filtering rules.

When unfiltered is not present or has a value of 0, Movable Type may take some rows out of the result returned from an SQL query. For example, a category that doesn’t belong to the weblog will be omitted whenever MTSQLCategories is used to retrieve category data.

All of the plug-in’s container tags have a query tag to define the SQL query that retrieves rows from the database.

The following template code displays a weblog’s trackback pings grouped by the name of the weblog that sent the pings:

<MTSQLPings query=”SELECT tbping_id FROM mt_tbping ORDER BY
tbping_blog_name, tbping_created_on desc”
default=”No pings found”>
<div class=”entryhead”><a href=”<MTPingURL>”>
<MTPingTitle></a></div>
<div class=”comments-body”>
<MTPingExcerpt>
<p align=”right”></p>
</div>
<p><span class=”entryfooter”><MTPingBlogName> |
<MTPingDate></span><br clear=”all”>
</MTSQLPings>

The default attribute contains a message, “No pings found,” which is displayed only when the database does not contain any trackback pings. trackback pings presented with this code are shown in Figure 16-2.

Click To expand
Figure 16-2: Pulling trackback pings directly from a MySQL database.

Attribute values for any container tag can include the output of Movable Type template tags. The tags should be surrounded by [ and ] brackets instead of < and > characters, as in this revised trackback ping example:

<MTSQLPings query=”SELECT tbping_id FROM mt_tbping ORDER BY
tbping_title, tbping_created_on desc”
default=”No pings found in [MTBlogName]”>
    <a href=”<MTPingURL>”><MTPingTitle></a><br>
    <MTPingExcerpt><br>
    From <MTPingBlogName>, <MTPingDate>
</MTSQLPings>

The reference to [MTBlogName] will be replaced with the output of the MTBlogName template tag, displaying the title of the weblog.

Working with Existing Template Tags

The easiest way to take advantage of the SQL plug-in is to work with container tags that represent specific database tables in MySQL, such as MTSQLCategories or MTSQLEntries.

A query constructed for these tags must return an ID number as the first column. Often, that’s all you need from the database, because you can use Movable Type in conjunction with the plug-in.

Listing 16-2 demonstrates this capability, using an MTSQLEntries tag to select entries that make use of the Extended Entry field.

Listing 16-2: Retrieving Entries from the Database
Start example
<MTSQLEntries query="SELECT entry_id FROM mt_entry
WHERE entry_text_more != ‘’ ORDER BY entry_id DESC">
<MTEntryTrackbackData>

<MTDateHeader>
<h2><MTEntryDate format="%x"></h2>
</MTDateHeader>

<a id="<MTEntryID pad="1">"></a>
<h3><MTEntryTitle></h3>

<MTEntryBody>

<MTEntryMore>

<p class="posted">Posted by <$MTEntryAuthor$> at
<a href="<MTEntryPermalink>"><MTEntryDate format="%X"></a>
<MTEntryIfAllowComments>
| <a href="<MTEntryPermalink>#comments">Comments
(<MTEntryCommentCount>)</a>
</MTEntryIfAllowComments>
<MTEntryIfAllowPings>
| <a href="<MTEntryPermalink>#trackbacks">Trackback
(<MTEntryTrackbackCount>)</a>
</MTEntryIfAllowPings>
</p>
</MTSQLEntries>
End example

Everything within the opening and closing MTSQLEntries tags is a normal Movable Type template tag, formatted in a manner similar to how the Main Index template displays entries.

Retrieving Other Movable Type Data

As you will discover in the next section of this chapter, most of Movable Type’s database tables include fields that are not associated with any template tags.

You can get your hands on this data by using the last two template tags offered by the SQL plug-in, MTSQL and MTSQLColumn.

The MTSQL container tag represents any kind of data you can collect from a Movable Type database table using an SQL query. You can retrieve as much or as little from the table as desired, and there’s no requirement to make an ID number the first row or column that’s returned from a query.

The MTSQLColumn tag presents one of the fields that has been returned, using a column attribute that represents the position of the field. The first field returned has column=”1”, the second column=”2”, and so on.

Listing 16-3 makes use of these tags to retrieve a list of banned IP addresses from mt_ipbanlist, a table that’s used to keep unwanted guests from using your visitor comment and trackback ping features.

Listing 16-3: Viewing Comments from Banned IP Addresses
Start example
<table border="0" cellpadding="2">
<MTSQL query="SELECT ipbanlist_ip, ipbanlist_created_on
FROM mt_ipbanlist ORDER BY ipbanlist_created_on desc">
   <tr>
       <td><a href="<MTSQLColumn column="1">">
<MTSQLColumn column="1"></a></td>
       <td><MTSQLColumn column="2"></td>
    </tr>
</MTSQL>
</table>

<MTSQLComments query="SELECT comment_id from mt_comment
ORDER BY comment_ip">
      <MTSQLHeader>
          <a name="<MTCommentIP>"><p><MTCommentIP>
      </MTSQLHeader>
      <p>Author: <MTCommentAuthor><br>
      E-mail: <MTCommentEmail><br>
      URL: <MTCommentURL>
      <p>Comment: <MTCommentBody>
</MTSQLComments>
End example

This list is followed by all weblog comments grouped by IP address. Click an IP address to see comments posted from that machine.

Making full use of the SQL plug-in requires knowledge of MySQL and Movable Type’s database format. The next several sections document all of the table fields.

Retrieving Author Data

The mt_author database table contains accounts for each editor with an account created on your Movable Type server. If you have installed the MTAuthors plug-in, you can use it to display rows retrieved from this table.

The fields in this table are described in Table 16-3.

Table 16-3: mt_author Database Fields
Tag | Data Type | Default | Description
author_id | Int | None | The database’s primary key
author_name | varchar(50) | “” | Username
author_type | Tinyint | 0 | Type: 1 (editor), 2 (commenter)
author_nickname | varchar(50) | NULL | Nickname
author_password | varchar(50) | “” | Password
author_email | varchar(75) | “” | E-mail address
author_url | varchar(255) | NULL | Home page address
author_can_create_blog | Tinyint | NULL | Create new weblog? 1 (yes), 0 (no)
author_can_view_log | Tinyint | NULL | View activity log? 1 (yes), 0 (no)
author_hint | varchar(75) | NULL | Password reminder
author_created_by | Int | NULL | ID of editor who created this author
author_public_key | Text | NULL | Reserved for future use
author_preferred_language | varchar(50) | NULL | Language preference
author_remote_auth_username | varchar(50) | NULL | TypeKey username
author_remote_auth_token | varchar(50) | NULL | TypeKey token

Retrieving Weblog Data

The mt_blog database table holds information about each weblog on the server. Many of its fields can be presented using tags that can be used within an MTBlogs container.

The fields in this database table are described in Table 16-4.

Table 16-4: mt_blog Database Fields
Tag | Data Type | Default | Description
blog_id | Int | None | The database’s primary key
blog_name | varchar(255) | “” | Name
blog_description | Text | NULL | Description
blog_site_path | varchar(255) | NULL | Main directory
blog_site_url | varchar(255) | NULL | Home page URL
blog_archive_path | varchar(255) | NULL | Archive directory
blog_archive_url | varchar(255) | NULL | Archive URL
blog_archive_type | varchar(255) | NULL | List of archive types in use (example: “Individual,Monthly”)
blog_archive_ type_preferred | varchar(25) | NULL | Preferred archive type
blog_days_ on_index | smallint | NULL | Days to display on home page
blog_language | varchar(5) | NULL | Language for date and time display
blog_file_ extension | varchar(10) | NULL | Archive file extension
blog_email_ new_comments | Tinyint | NULL | E-mail new comments? 1 (yes), 0 (no)
blog_email_ new_pings | Tinyint | NULL | E-mail new trackback pings? 1 (yes), 0 (no)
blog_allow_comment_html | Tinyint | NULL | Allow HTML in comments? 1 (yes), 0 (no)
blog_autolink_urls | Tinyint | NULL | Add links to URLS in comments? 1 (yes), 0 (no)
blog_sort_order_posts | varchar(8) | NULL | Entry sort order (ascend or descend)
blog_sort_order_comments | varchar(8) | NULL | Comment sort order (ascend or descend)
blog_allow_comments_default | Tinyint | NULL | Allow comments? 1 (yes), 0 (no)
blog_allow_pings_default | Tinyint | NULL | Allow trackback pings? 1 (yes), 0 (no)
blog_server_offset | Float | NULL | Server time zone offset from UTC
blog_convert_paras | varchar(30) | NULL | Entry formatting plug-in
blog_convert_paras_comments | varchar(30) | NULL | Comment formatting plug-in
blog_status_default | Tinyint | NULL | Publication status: 1 (draft), 2 (publish)
blog_allow_anon_comments | Tinyint | NULL | Allow anonymous comments? 1 (yes), 0 (no)
blog_allow_reg_comments | Tinyint | NULL | Allow TypeKey registered comments? 1 (yes), 0 (no)
blog_allow_unreg_comments | Tinyint | NULL | Allow non-TypeKey comments? 1 (yes), 0 (no)
blog_moderate_unreg_comments | Tinyint | NULL | Moderate unregistered comments? 1 (yes), 0 (no)
blog_require_comment_emails | Tinyint | NULL | Require e-mail addresses in comments? 1 (yes), 0 (no)
blog_manual_approve_commenters | Tinyint | NULL | Manually approve commenters? 1 (yes), 0 (no)
blog_words_in_excerpt | smallint | NULL | Words in entry excerpts
blog_ping_weblogs | Tinyint | NULL | Notify weblogs.com of new entries? 1 (yes), 0 (no)
blog_ping_blogs | Tinyint | NULL | Notify blo.gs of new entries? 1 (yes), 0 (no)
blog_ping_others | Text | NULL | URLs of other services to notify, one per line
blog_mt_update_key | varchar(30) | NULL | Recently updated key
blog_autodiscover_links | Tinyint | NULL | Use trackback autodiscovery? 1 (yes), 0 (no)
blog_welcome_msg | Text | NULL | Welcome message
blog_old_style_archive_links | Tinyint | NULL | Use pre-version 3 style archive links? 1 (yes), 0 (no)
blog_archive_tmpl_monthly | varchar(255) | NULL | Monthly archive template filename
blog_archive_tmpl_weekly | varchar(255) | NULL | Weekly archive template filename
blog_archive_tmpl_daily | varchar(255) | NULL | Daily archive template filename
blog_archive_tmpl_individual | varchar(255) | NULL | Individual archive template filename
blog_archive_tmpl_category | varchar(255) | NULL | Category archive template filename
blog_google_api_key | varchar(32) | NULL | Google API key
blog_sanitize_spec | varchar(255) | NULL | HTML tags and attributes to allow in comments (separated by commas)
blog_cc_license | varchar(255) | NULL | Creative Commons license
blog_is_dynamic | Tinyint | NULL | Reserved for future use
blog_remote_auth_token | varchar(50) | “” | TypeKey token

Retrieving Category Data

Category information in Movable Type requires two database tables: mt_category, which contains categories that have been created for any weblog on the server, and mt_placement, which represents categories assigned to weblog entries.

Fields from the mt_category table can be presented using tags that can be employed within an MTCategories container. Table fields are described in Table 16-5.

Table 16-5: mt_category Database Fields
Tag | Data Type | Default | Description
category_id | Int | None | The database’s primary key
category_blog_id | int | 0 | ID of category’s weblog
category_allow_pings | tinyint | NULL | Accept trackback pings? 1 (yes), 0 (no)
category_label | varchar(100) | NULL | Name
category_description | text | NULL | Description
category_author_id | int | NULL | ID of editor who created this category
category_ping_urls | text | NULL | URLs of trackback pings to send with each new entry, one per line

Fields in the mt_placement category can be displayed by using the template that would appear in an MTEntryCategories tag.

Table fields for mt_placement are described in Table 16-6.

Table 16-6: mt_placement Database Fields
Tag | Data Type | Default | Description
placement_id | Int | None | The database’s primary key
placement_entry_id | Int | 0 | ID of weblog entry
placement_blog_id | Int | 0 | ID of weblog
placement_category_id | Int | 0 | ID of weblog category
placement_is_primary | Tinyint | 0 | Is this an entry’s primary category? 1 (yes), 0 (no)

Retrieving Comment Data

The mt_comment database table holds comments submitted by visitors to any of your weblogs, whether they have been submitted anonymously, signed with an e-mail address, or authenticated by Six Apart’s TypeKey service. Tags within an MTComments container can be used to display fields from this table.

The fields in this table are listed in Table 16-7.

Table 16-7: mt_comment Database Fields
Tag | Data Type | Default | Description
comment_id | int | None | The database’s primary key
comment_blog_id | int | 0 | ID of comment’s weblog
comment_entry_id | int | 0 | ID of comment’s weblog entry
comment_ip | varchar(16) | NULL | IP address
comment_author | varchar(100) | NULL | Author’s nickname
comment_email | varchar(75) | NULL | Author’s e-mail address
comment_url | varchar(255) | NULL | Author’s home page
comment_commenter_id | int | NULL | ID of TypeKey registered comment author
comment_visible | tinyint | NULL | Display comment? 1 (yes), 0 (no)
comment_text | text | NULL | Text
comment_created_on | datetime | 0000-00-00 00:00:00 | Creation date/time
comment_modified_on | timestamp | NULL | Last modification date/time
comment_created_by | int | NULL | Reserved for future use
comment_modified_by | int | NULL | Reserved for future use

Retrieving Weblog Entry Data

The mt_entry database table holds the most important part of your Movable Type database: the entries that comprise the primary content of each weblog. Most of these table fields, which are documented in Table 16-8, can be presented using the tags that work within an MTEntries container or in the individual archive template.

Table 16-8: mt_entry Database Fields
Tag | Data Type | Default | Description
entry_id | int | None | The database’s primary key
entry_blog_id | int | 0 | ID of entry’s weblog
entry_status | tinyint | 0 | Publication status: 1 (draft), 2 (publish)
entry_author_id | int | 0 | ID of entry’s author
entry_allow_comments | tinyint | NULL | Allow comments? 1 (yes), 0 (no)
entry_allow_pings | tinyint | NULL | Allow trackback pings? 1 (yes), 0 (no)
entry_convert_breaks | varchar(30) | NULL | Entry formatting plug-in
entry_category_id | int | NULL | ID of entry’s primary category
entry_title | varchar(255) | NULL | Title
entry_excerpt | text | NULL | Excerpt
entry_text_more | text | NULL | Extended entry
entry_to_ping_urls | text | NULL | URLs of trackback pings to send, one per line
entry_pinged_urls | text | NULL | URLs of previously sent trackback pings, one per line
entry_keywords | text | NULL | Keywords
entry_tangent_cache | text | NULL | Reserved for future use
entry_created_on | datetime | 0000-00-00 00:00:00 | Creation date/time
entry_modified_on | timestamp | NULL | Modification date/time
entry_basename | varchar(50) | NULL | Unique 15-character text identifier based on entry title

Retrieving Banned IP Address Data

The mt_ipbanlist database table contains a list of IP addresses that are banned from sending visitor comments or trackback pings to a weblog on your Movable Type installation. An IP address is a set of four byte values (0 to 255) separated by dot characters, such as 192.0.34.166. Everything connected to the Internet must have a unique IP address—the domain-name system maps easy-to-remember names like example.com to the IP address associated with that name.

Banning IP addresses in Movable Type works well only when a sender keeps the same address over a period of time, which makes it more effective for blocking unwanted trackback pings than visitor comments, because most Internet users connect using accounts that assign different IP addresses each time they log on.

No Movable Type template tags are associated with the fields in this table. You can display them using the MTSQL container and MTColumn tag.

The fields in the mt_ipbanlist table are listed in Table 16-9.

Table 16-9: mt_ipbanlist Database Fields
Tag | Data Type | Default | Description
ipbanlist_id | int | None | The database’s primary key
ipbanlist_blog_id | int | 0 | ID of banned weblog
ipbanlist_ip | varchar(15) | “” | IP address
ipbanlist_created_on | datetime | 0000-00-00 00:00:00 | Creation date/time
ipbanlist_modified_on | timestamp | NULL | Last modification date/time
ipbanlist_created_by | int | NULL | ID of banning author
ipbanlist_modified_by | int | NULL | ID of modifying author

Retrieving Activity Log Data

The mt_log database table stores entries in Movable Type’s activity log, the file that tracks usage of the server by editors and other events such as unsuccessful trackback pings. There are no template tags to present this information, so the MTSQL and MTSQLColumn tags are required to display them.

Table fields in this database are delineated in Table 16-10.

Table 16-10: mt_log Database Fields
Tag | Data Type | Default | Description
log_id | Int | None | The database’s primary key
log_message | varchar(255) | NULL | Message
log_ip | varchar(16) | NULL | IP address associated with the event
log_created_on | datetime | 0000-00-00 00:00:00 | Creation date/time
log_modified_on | timestamp | NULL | Modification date/time
log_created_by | int | NULL | Reserved for future use
log_modified_by | int | NULL | Reserved for future use

Retrieving E-Mail Notification Data

The mt_notification database table serves as a mailing list for a Movable Type weblog, holding the users who have requested an e-mail when a new entry has been published.

Because no Movable Type template tags are associated with this table, you can collect and present the fields in Table 16-11 with the MTSQL and MTColumn tags.

Table 16-11: mt_notification Database Fields
Tag | Data Type | Default | Description
notification_id | Int | None | The database’s primary key
notification_blog_id | int | 0 | ID of weblog
notification_name | varchar(50) | NULL | Name
notification_email | varchar(75) | NULL | E-mail address
notification_url | varchar(255) | NULL | Home page URL
notification_created_on | datetime | 0000-00-00 00:00:00 | Subscription creation date
notification_modified_on | timestamp | NULL | Subscription last modification date
notification_created_by | int | NULL | Reserved for future use
notification_modified_by | int | NULL | Reserved for future use

Retrieving Author Permissions

The mt_permission database holds the role-based permissions for editors assigned to your weblogs, which can be incorporated into templates with the MTSQL and MTColumn tags.

Table fields for the mt_permission database appear in Table 16-12.

Table 16-12: mt_permission Database Fields
Tag | Data Type | Default | Description
permission_id | Int | None | The database’s primary key
permission_author_id | Int | 0 | ID of author
permission_blog_id | Int | 0 | ID of weblog
permission_role_mask | smallint | NULL | Permission bitmask
permission_entry_prefs | varchar(255) | NULL | List of permissions (separated by commas)

Retrieving Plug-In Data

The mt_plugin database table offers a place for plug-ins that need to store data persistently. A plugindata_plugin field serves as a unique identifier for the plug-in, such as its name, whereas the plugindata_key and plugindata_data fields can be used as storage places.

Rows in this table are used for different purposes in different plug-ins, so as you might expect, there are no Movable Type template tags to present this information. Use the MTSQL and MTSQLColumn tags to collect and publish these fields in a template.

Table fields are shown in Table 16-13.

Table 16-13: mt_plugin Database Fields
Tag | Data Type | Default | Description
plugin_id | int | None | The database’s primary key
plugindata_plugin | varchar(50) | “” | Text identifier for the plug-in
plugindata_key | varchar(255) | “” | Plug-in text data, up to 255 characters
plugindata_data | mediumtext | NULL | Longer plug-in data

Retrieving Session Data

The mt_session database, a new addition in Movable Type 3, supports session management.

This information is highly transitory and there’s little reason to present its data on a static Web page built from a template. You can, however, use the SQL plug-in’s tags to publish fields from this table. They are shown in Table 16-14.

Table 16-14: mt_session Database Fields
Tag | Data Type | Default | Description
session_id | int | None | The database’s primary key
session_data | text | NULL | Session data
session_email | varchar(255) | NULL | E-mail address associated with the session (if any)
session_name | varchar(255) | NULL | Short identifier for the session
session_start | int | 0 | Time the session was created as a UNIX time value
session_kind | char(2) | NULL | Two-letter code identifying the purpose of the session

Retrieving Trackback Ping Data

The mt_tbping and mt_trackback database tables contain trackback pings, which are incoming messages sent to your Movable Type weblogs by other sites using the trackback protocol.

Tags that would ordinarily be used inside an MTPings container can display fields from this table.

The table fields are described in Tables 16-15 and 16-16.

Table 16-15: mt_tbping Database Fields
Tag | Data Type | Default | Description
tbping_id | Int | None | The database’s primary key
tbping_blog_id | Int | 0 | ID of trackback ping’s weblog
tbping_tb_id | Int | 0 | ID of trackback ping’s weblog entry
tbping_title | varchar(255) | NULL | Title
tbping_excerpt | Text | NULL | Excerpt
tbping_source_url | varchar(255) | NULL | Sender’s home page URL
tbping_ip | varchar(15) | NULL | IP address
tbping_blog_name | varchar(255) | NULL | Sender’s weblog name
tbping_created_on | Datetime | 0000-00-00 00:00:00 | Creation date/time
tbping_modified_on | Timestamp | NULL | Last modification date/time
tbping_created_by | Int | NULL | Reserved for future use
tbping_modified_by | Int | NULL | Reserved for future use
Table 16-16: mt_trackback Database Fields
Tag | Data Type | Default | Description
trackback_id | Int | None | The database’s primary key
trackback_blog_id | Int | 0 | ID of weblog
trackback_title | varchar(255) | NULL | Title
trackback_description | Text | NULL | Description
trackback_rss_file | varchar(255) | NULL | Reserved for future use
trackback_url | varchar(255) | NULL | Incoming trackback URL
trackback_entry_id | Int | 0 | ID of weblog entry
trackback_category_id | Int | 0 | ID of weblog category
trackback_passphrase | varchar(30) | NULL | Password required to send trackback pings
trackback_is_disabled | Tinyint | 0 | Accept no more trackback pings? 1 (yes), 0 (on)
trackback_created_on | datetime | 0000-00-00 00:00:00 | Aggregator creation date/time
trackback_modified_on | timestamp | NULL | Aggregator modification date/time
trackback_created_by | Int | NULL | Reserved for future use
trackback_modified_by | Int | NULL | Reserved for future use

Retrieving Template Data

The mt_template and mt_templatemap database tables manage templates and linked template files for each weblog on a Movable Type installation.

The mt_template table provides information about each template, such as its name, output filename, and whether to rebuild it whenever index templates are generated.

The mt_templatemap table associates archive templates with particular archive types. The archive type must be one of the following five values, capitalized as indicated: Category, Daily, Individual, Monthly, or Weekly.

Presenting this data in a template requires SQL plug-in tags. Table fields are shown in Tables 16-17 and 16-18.

Table 16-17: mt_template Database Fields
Tag | Data Type | Default | Description
template_id | int | None | The database’s primary key
template_blog_id | int | 0 | ID of template’s weblog
template_name | varchar(50) | “” | Name
template_type | varchar(25) | “” | Template type (a string such as index or category)
template_outfile | varchar(255) | NULL | Filename of rendered page
template_rebuild_me | tinyint | 1 | Rebuild with index templates? 1 (yes), 0 (no)
template_text | text | NULL | Full text of template
template_linked_file | varchar(255) | NULL | Linked filename
template_linked_file_mtime | varchar(10) | NULL | Linked file’s last modification date/time
template_linked_file_size | mediumint | NULL | Linked file’s size
Table 16-18: mt_templatemap Database Fields
Tag | Data Type | Default | Description
templatemap_id | int | None | The database’s primary key
templatemap_blog_id | int | 0 | ID of weblog
templatemap_template_id | int | 0 | ID of template
templatemap_archive_type | varchar(25) | NULL | Template type (a string such as Daily or Category)
templatemap_file_template | varchar(255) | NULL | Filename of rendered page
templatemap_is_preferred | tinyint | 0 | Preferred template among those belonging to its archive type on this weblog? 1 (yes), 0 (no)

Retrieving Trackback Aggregator Data

Weblog entries and categories in a Movable Type weblog can serve as trackback content aggregators, collecting incoming trackback pings. On an individual weblog entry, these trackback pings serve as a form of feedback comparable in some ways to visitor comments. On a category, they facilitate collaboration between different weblogs, a style of publishing that Six Apart calls a trackback content aggregator.

Tags that would ordinarily be used inside an MTPings container can display fields from this table.


Programming Templates with Scripting Tags

If you can’t accomplish something with any other Movable Type plug-in, you can get it done with PerlScript, a plug-in by Brad Choate that enables Perl commands to be executed in a template. The output of the script appears on the rendered page as if it were produced by template tags.

Anything that the Perl programming language can handle can also be handled by an opening and closing MTPerlScript tag, making it the most powerful plug-in available for Movable Type.

Gotcha

This plug-in also has the largest security implications of any plug-in, because it enables arbitrary Perl code to be executed on your server by anyone with template-editing privileges on one of your weblogs.

To pick one of many possible disasters that could happen through unintentional or malicious use of this plug-in: A typo in a Perl command recursively deletes every file in your Movable Type directory and its subdirectories.

As any fan of Spiderman could tell you, with great power comes great responsibility. For this reason, PerlScript should be limited to environments where all template-editing weblog editors can be fully trusted.

Take a look at a short example that uses the plug-in to identify the Web server on which the software runs:

<MTPerlScript>
    print “<p>Powered by $ENV{‘SERVER_SOFTWARE’}</p>”;
</MTPerlScript>

Everything within the opening and closing MTPerlScript tags is interpreted as Perl code. When a template containing this tag is rebuilt, it displays a string with the name and version number of the server, retrieving them from the Common Gateway Interface environment variable SERVER_SOFTWARE. On my server, the following string is displayed: “Powered by Apache/2.0.46 (Red Hat)”.

Web Site Download

The PerlScript plug-in can be downloaded as a ZIP archive from Choate’s Web site at http://bradchoate.com/weblog/2002/07/27/perl script-plugin. Two files deliver its functionality: a Perl script (the plug-in) and a Perl module that it requires.

To install the plug-in, follow these steps:

  1. Place the perlscript.pl Perl script in Movable Type’s plugins directory.

  2. In the extlib directory, create a subdirectory named bradchoate as needed.

  3. Store the perlscript.pm Perl module in this new subdirectory.

After the plug-in has been installed, you can write one or more Perl scripts in a template, putting each one within its own MTPerlScript tags.

These scripts can interact with Movable Type’s template processor, making use of data produced by template tags. They also can access information from the container that encloses the script—to pick one possible use among many, a MTPerlScript tag can be placed within an MTEntries container, retrieving the ID number of each entry in turn and incorporating that information in Perl commands.

Template tags referenced in the Perl script are evaluated before the script runs, producing output that becomes part of the script, as shown in the following example:

<MTCategories>
  <MTPerlScript>
    print “<p>” . ucfirst(“<MTCategoryLabel>”);
  </MTPerlScript>
</MTCategories>

This code displays each category name for a weblog, using the Perl ucfirst() function to display the first letter of the name as an uppercase letter.

Template tags also are evaluated after the script has been run.

The preprocess=”1” attribute of the MTPerlScript tag prevents processing before the Perl script runs. The reprocess=”1” attribute does the same thing afterward.

A script can define one or more subroutines by placing them within their own enclosing MTPerlScript tags and using two attributes, once and package.

The package attribute designates a Perl namespace for the subroutines within a script, enabling the routines to be called from within other MTPerlScript tags in the same template. The once attribute, with a value of 1, causes the code to be evaluated one time only.

Here’s an example that uses a subroutine and two MTPerlScript tags:

<MTPerlScript package=”julian” once=”1”>
  sub day {
    use Time::JulianDay;
    my($in_time) = @_;
    return local_julian_day($in_time);
  }
</MTPerlScript>

<MTPerlScript>
  print “<p>” . julian::day(time);
</MTPerlScript>

These two scripts produce the numeric Julian value for the current date, such as 2453218 on July 31, 2004.

When a template contains more than one Perl script, you can use a package name to refer to subroutines in that package. The once attribute can be used for only one script in each package.

The cache=”1” attribute speeds up processing by caching the Perl code in a script, making it execute much more quickly within Movable Type containers that loop. Any Movable Type template tags within the script are evaluated only once, so you cannot cache Perl code that relies on tags with changing values (such as an MTEntryTitle tag within an MTEntries container).

The MTPerlScript opening tag also can contain one or more user-defined attributes as name-value pairs, as in this example:

<MTPerlScript greeting=”Saluton, Mondo!”>
  <p>$args{greeting}!
</MTPerlScript>

The %args hash holds the tag arguments, so the preceding code produces the following HTML output:

<p>Saluton, Mondo!

Listing 16-4 contains a script that downloads stock quote data from Yahoo! Finance for a specific ticker symbol, displaying the current price, change, date, and time in the following format:

<p><b>RHAT</b>: 22.09 (+0.09)  at 6/24/2004 4:00pm</p>

This script makes use of LWP::UserAgent, one of the optional modules that you can install to support the functionality of Movable Type.

Listing 16-4: Displaying a Yahoo! Stock Quote
Start example
<MTPerlScript symbol="RHAT">
  # collect stock data from Yahoo Finance
  require LWP::UserAgent;
  $host = "http://finance.yahoo.com";
  $path = "/d/quotes.csv?s=$args{symbol}&f=sl1d1t1c1ohgv
     &e=.csv";
  $ua = LWP::UserAgent->new;
  $request = HTTP::Request->new(‘GET’, $host . $path);
  $response = $u,nfa->request($request);

  # process data, stripping quote marks
  if ($response->is_success) {
    @stock_data = split(/,/, $response->content);
    ($symbol, $price, $s_date, $s_time, $change, $open, $high, $low, $volume) = @stock_data;
    $symbol =~ s/\"//g;
    $s_date =~ s/\"//g;
    $s_time =~ s/\"//g;

    # display data
    print "<p><b>" . $symbol . "</b>: " . $price . " (" .
$change . ") ";
    print "at " . $s_date . " " . $s_time . "</p>";
  }
</MTPerlScript>
End example

On a stock’s quote summary page, Yahoo! Finance includes a Download Data link to a single-line file that holds the most recent day’s price data, formatted as a series of comma-separated values:

“RHAT”,22.09,”6/24/2004”,”4:00pm”,+0.09,22.03,22.64,21.85,
5493987

The values in this file, in order, are the symbol, price quote, date, time, price change, opening price, daily high, daily low, and daily volume.

The Perl script in Listing 16-5 uses LWP::UserAgent to request this file for a stock specified with the MTPerlScript tag’s symbol attribute. If the request is successful, the quote data is stored in an array and then assigned to nine variables.

You can customize the last two lines of the script to alter the display of the stock quote data. The tag displays nothing if the data cannot be downloaded successfully from Yahoo!.

Another variable that’s available within an MTPerlScript tag is $dbh, an active handle to the database containing Movable Type weblog data.

With this handle and the methods of the Perl DBI module, which is a database-independent interface that works for all of the database programs supported by Movable Type, you can read and write database records.

Listing 16-5 makes use of this feature to retrieve records from mt_comment, the table containing visitor comments. This Perl script displays comments that contain at least one hyperlink, providing an editing link that can be used to open and delete spam.

Listing 16-5: Displaying Database Entries
Start example
<MTPerlScript>
  my $sql = "select tbping_id, tbping_ip, tbping_author,
tbping_email, tbping_url, tbping_text, tbping_created_on
from mt_comment where tbping_text like ‘%href%’ order by
tbping_id desc";
  my $sth = $dbh->prepare($sql);
  $sth->execute or die "Oops: ".$sth->errstr."\n";
  while (@row=$sth->fetchrow_array) {
    ($id, $ip, $author, $email, $url, $text,
$created) = @row;
    print "<p>" . $text;
    print "<p><a href=\"" . $url . "\">" . $author . " " .
$email . "</a>" . $ip;
    print "<p>" . $created;
    print "<p><a href=\"/cgi-bin/mt.cgi?__mode=view&_type=comment&id=" . $id .
"&blog_id=3\">Edit</a>";
  }
$sth->finish;
</MTPerlScript>
End example

The PerlScript plug-in also offers another built-in variable, %stash, which holds the Movable Type stash, a hash that holds context variables from parent tags. You’ll work with it in Chapter 20, “Developing New Plug-Ins with Perl.”

Gotcha

Plug-in author Brad Choate warns in his documentation about the security risks of installing this on a shared Movable Type server: “Anyone who can edit templates on your server can basically control your Web site with this plug-in under the hood. The Perl code contained within your PerlScript tags is not sandboxed at all: file and database operations can be performed, infinite loops can tie up your server—any number of things can go wrong.”

Because Movable Type plug-ins are also authored in Perl, you can create plug-in tags that deliver the desired functionality and are inherently more secure. This topic is explored in Chapters 20 and 21.


Summary

The Movable Type plug-ins presented in this chapter are representative of the variety of programs available to enhance the software.

Since plug-in support was introduced in June 2002 for version 2.2 of Movable Type, dozens of plug-ins have been released for purposes big and small. Many have found their way into the Movable Type Plug-In Directory at http://mt-plugins.org.

Plug-in quality varies widely. Anyone who can write simple scripts in Perl can try their hand at Movable Type plug-in development. Some programs you might find in the plug-in directory and other Web sites will be incomplete, never fully released, or buggy.

At this point, though, there are enough excellent plug-ins available that the time spent looking for them is well worth spending.

A well-designed plug-in integrates fully with Movable Type, performing as if it were part of the software’s standard installation, and works in conjunction with existing template tags. Plug-ins often require no configuration other than saving a few files in the software’s plugins and extlib directories (or a subdirectory of extlib).

Now that Movable Type 3 offers even stronger integration with plug-ins, there’s likely to be even more reason to exploit this feature of the software.


Chapter 17: Presenting External WebContent with Plug-Ins

In This Chapter

  • Retrieving data from another Web site

  • Tracking weather conditions with a plug-in

  • Presenting plug-in data in a template

  • Presenting random text and HTML

  • Joining the Amazon Affiliates program

  • Becoming a registered Amazon developer

  • Searching Amazon’s product database

  • Retrieving product lists prepared by Amazon

  • Reading lists created by customers

Chapter 16, “Enhancing Movable Type with Plug-Ins,” demonstrated how the software’s large number of add-on programs can present information from your Web site in novel and useful ways.

Plug-ins are just as effective for presenting information from other Web sites. They can retrieve data from other sites and Internet servers, storing it in Movable Type template tags and publishing it when pages are rebuilt.

In this chapter, you learn about several useful data-grabbing site enhancements:

  • The Weather Underground plug-in contacts the Web site of the same name, collecting the current weather conditions, temperature, and humidity for a city, state, or country of your choosing.

  • The MT-QOTD plug-in connects to a quote-of-the-day server, an old-school Internet service that offers a random quotation when contacted by a client.

  • Another plug-in, RandomLine, provides an alternative way to offer the same feature.

  • The MT-Amazon plug-in pulls an amazing amount of product data from the giant e-commerce site, enabling your weblog to promote and sell products. You also can participate in Amazon’s Affiliates program and get paid for referring customers.

These plug-ins and others like them represent a one-of-a-kind opportunity for Web publishers: a chance to improve your site while someone else does most of the work.


Presenting Weather Data

You can publish local weather information for more than 60,000 cities on your Movable Type weblog with the Weather Underground plug-in by Gavin Estey:

http://www.estey.com/mt

This plug-in requires the Perl module Weather::Underground, which retrieves temperature, humidity, and other weather condition data from the Weather Underground Web site:

http://www.wunderground.com

Chapter 2, “Preparing a Web Server for Movable Type,” describes how to download and install Perl modules using the Central Perl Archive Network (CPAN). In many cases, installing Weather::Underground can be accomplished with a single command in this manner:

/usr/bin/perl -MCPAN -e ‘install Weather::Underground’

The reference to /usr/bin/perl might need to be changed, depending on where Perl is found on your server and your operating system.

The Weather Underground plug-in introduces Movable Type tags that display simple weather information on a page, much like the example shown in Figure 17-1.

Click To expand
Figure 17-1: Displaying weather data on a page.

The weather sidebar in Figure 17-1 was produced with the following HTML code:

<div class=”side”>
Orlando:<br>
  <MTWeatherUnderground place=”Orlando, FL”>
     <MTWeatherUConditions>: <MTWeatherUFahrenheit>°F
     (<MTWeatherUCelsius>°C)<br>
    <MTWeatherUHumidity>% humidity
  </MTWeatherUnderground>
</div>

The container tag MTWeatherUnderground holds weather data for a location identified in its place attribute, which takes the same queries as the Weather Underground Web site—specify a city and state, zip code, airport code, or country.

Within the container, the MTWeatherUCelsius and MTWeatherUFahrenheit tags display the current temperature in those scales, and MTWeatherUHumidity reports the humidity. The MTWeatherConditions tag contains a short description of the present conditions, such as “Mostly cloudy,” “Scattered clouds,” “Heavy thunderstorms,” “Smoke,” and “Widespread dust.”

The last tag you can use, MTWeatherUPlace, identifies the place. This can be helpful when presenting weather data by zip code, as shown in the following example:

<MTWeatherUnderground place=”02134”>
  <MTWeatherUPlace>:<br>
  <MTWeatherUConditions>: <MTWeatherUFahrenheit>°F
  (<MTWeatherUCelsius>°C)<br>
  <MTWeatherUHumidity>% humidity
</MTWeatherUnderground>

Weather data is updated each time the page containing the tag rebuilds.

Gotcha

When you rebuild pages of a site that uses the Weather Underground plug-in, you might see an error message about an “uninitialized value” in the file Underground.pm. The cause appears to be a bug in the Weather::Underground Perl module, but it doesn’t affect the performance of the plug-in, so it can safely be ignored.


Publishing Random Quotes and Other Text

Since the early days of the Internet, port 17 on a server has been reserved for use by qotd (quote of the day), a service that displays a randomly selected quote whenever a client makes a connection.

This obscure network service can be used to test network connectivity, but that high-minded purpose makes it sound more important than it really is—a quote server is just a fun thing to have around.

If you know the address of a server that offers qotd, you can try it by making a telnet connection to port 17, as demonstrated by this command and the resulting output:

$ telnet quote.cbk.net 17

“The secret of being miserable is to have leisure to
 bother about whether you are happy or not. The cure
 for it is occupation.”
 George Bernard Shaw (1856-1950)

Neil Sedley offers MT-QOTD, a Movable Type plug-in that pulls a quote from a designated qotd server, displaying it on a Web page:

http://neil.sedley.org/qotd.htm

You can install this free plug-in by copying the Perl script mt-qotd.pl into Movable Type’s plugins subdirectory.

After it has been installed, add the MTQotd tag to a template in which you want the quote to appear.

This tag has one attribute, host, which identifies the qotd server from which to pull quotes. Sedley recommends using the standard attribute encode_html with a value of 1 (true) so that HTML formatting in quotes is displayed correctly.

The following HTML code centers a randomly selected quote from the server at quote.cbk.net:

<p align=”center”><MTQotd host=”quote.cbk.net”
encode_html=”1”></p>

A fresh quote is displayed each time a page is rebuilt from the template. If a connection cannot be made to the qotd server, you can’t publish pages using that template.

Another way to display random quotes and other kinds of text is provided by RandomLine, a plug-in by Martin Sutherland:

http://www.sunpig.com/martin/projects/mt/randomline

RandomLine presents one or more lines of text from a file or Movable Type module. The plug-in supports one new tag, MTRandomLine, which includes up to six attributes (see Table 17-1).

Table 17-1: MTRandomLine Tag Attributes
Attribute | Value | Description | Default
allowblanks | boolean | Whether to ignore blank links in the text source (1) or consider them (0) | Ignore blank lines
allowduplicates | boolean | Whether to choose lines more than once in the same output (1) or not (0) | Do not allow duplicates
file | text | The file that contains the source text | None
glue | text | Text or HTML that should be displayed between lines | None
module | text | The template module that contains the source text | None
num | integer | The number of random lines to display | 1

The RandomLine plug-in can pick one or more lines at random from any text file or HTML code. Anything that can be structured as discrete, individual lines can be culled by the tag, enabling the creation of a quote-of-the-day feature, randomly selected link or image, and other kinds of variable content.

The following HTML snippet displays one line from a file:

Random Link:<br>
<MTRandomLine file=”/etc/randomlinks”>

The file attribute should include the full path to the file, not just the filename.

The plug-in also can pull lines from a template module, which makes it possible to create and edit the source in Movable Type’s browser interface:

  1. Click the Templates button in the sidebar menu. The Templates page displays a weblog’s templates.

  2. In the Template Modules section at the bottom of the page, click the Create New Template Module link.

  3. On the Edit Template form, give the template a short, descriptive name in the Template Name field.

  4. In the Module Body text area, enter the text that will be used as source material for the MTRandomLine tag. Organize the file so that each line can be randomly displayed, as in the list of links shown in Figure 17-2.

    Click To expand
    Figure 17-2: Creating a template module for use by MTRandomLine.

  5. Click the Save button.

The tag will choose a line or lines from the module, depending on the value of the num attribute.

Random Link:<br>
<MTRandomLine module=”RandomLinks”>

When presenting more than one line from the source, the glue attribute holds text that should be inserted between lines. Any HTML in the text must be encoded so that the < and > characters are represented by the entities &lt; and &gt;, as shown in the following example:

<MTRandomLine module=”Images” num=”5” glue=”&lt;br&gt;>

The text &lt;br&gt; renders as <br>, a line break, on a page. When five images are displayed by selecting lines from the Images module, a line break separates each one. This only applies between random lines—a line break won’t appear before the first line or after the last one.

The file and module attributes should not be used at the same time. If they are, file is ignored.

Like other plug-ins, RandomLine freshens content only when Web pages are rebuilt.


Linking to Amazon.Com Content

A wealth of data from the online merchant Amazon.Com can be presented by the MTAmazon plug-in, an extensive add-on that uses Amazon Web services to pull product information from the company’s database:

http://mtamazon.sourceforge.net

This free plug-in, developed by the Kalsey Consulting Group, ranks as one of Movable Type’s most popular enhancements.

MTAmazon supports Amazon Associates, a marketing program that pays a referral fee to Web publishers who send customers to the site. When you publish links to Amazon that include a special affiliate code, you receive a small percentage of any sales that result from people using that link. You can find out more information and sign up on the Associates site:

http://associates.amazon.com

You don’t need to be an Associates member to use the MTAmazon plug-in, but you’ll be missing an opportunity to make money with your site.

The plug-in does require one thing from Amazon: a developer’s token for Amazon Web services. This free code can be requested using an Associates account or by registering for an Amazon account:

http://www.amazon.com/webservices

Where Movable Type is concerned, the MTAmazon plug-in requires the Perl module XML::Simple, which can be installed using the CPAN service described in Chapter 2.

Once you have your developer’s token and Associates ID (if you joined), you’re ready to configure the plug-in. MTAmazon’s configuration file works like other Movable Type configuration files: Blank lines and comments, which are lines preceded with a pound sign (#), are ignored by the software. The other lines consist of setting names followed by values, as in this line:

DevToken XXXXXXXXXXXX

To configure the MTAmazon plug-in:

  1. Download its archive from the MTAmazon Web site and extract all files to your computer.

  2. Open the file .mtamazon.config with a text editor.

  3. On the DevToken line, delete all of the X’s and enter your developer’s token in their place.

  4. If you have joined Amazon Associates, remove the pound sign on the line that reads # AssociateId kalsey-20”. AssociateId. By uncommenting the line in this manner, you cause the plug-in to stop ignoring it.

  5. On the same line, change kalsey-20 to your Associates ID.

  6. Save the file.

The MTAmazon plug-in consists of the configuration file, a Perl script named amazon.pl, a Perl module named MTAmazon.pm, and a cache directory.

These files and folders must be uploaded to the server:

  1. Save the files amazon.pl and .mtamazon.config in Movable Type’s plugins directory.

  2. Save the entire MTPlugins directory in the extlib directory.

  3. In the main Movable Type directory where mt.cgi and the other scripts are stored, create a new subdirectory named cache if one does not already exist.

  4. Change the file access permissions for the cache directory so that all users can read and write files. On Linux, this can be accomplished with the command chmod 666. FTP clients often can set this: Look for a Properties or Permissions command, and then assign the owner, group, and world read and write access.

On some systems, you might need to set the cache directory so that all users can read, write, and execute files (chmod 777). Do this if you encounter errors writing files to the directory when you rebuild a site.

Sharing Content from Amazon.Com

The MTAmazon plug-in displays information about products found in five places: a keyword search, a wish list, a best-seller list, a featured product list, and a related-products query. In Figure 17-3, the plug-in presents three best-selling books with “Disney” in their titles on a Web page.

On the Web page shown in Figure 17-3, the title and picture of each book link to its product page on Amazon.Com.

Click To expand
Figure 17-3: Presenting Amazon products on a weblog.

Amazon product details can be presented on pages built from any template, including a weblog’s main index and archives. When used on a weblog page, the plug-in can conduct a special search driven by something in the weblog entry. For example, if you assign keywords to your entries, MTAmazon can display products matching an entry’s keywords.

Searches also can key on text that you specify, such as “asparagus” to find products with the vegetable in their name or “Rogers Cadenhead” to find books by the computer book author of great renown, underappreciated genius, and understated humility.

The plug-in supports an impressive array of 20 tags based on the MTAmazon container tag, which executes a search and organizes results. All product-related tags must be placed within this container.

The MTAmazon tag has seven attributes, described in Table 17-2.

Table 17-2: MTAmazon Tag Attributes
Attribute | Value | Description | Default
Associateid | Text | An Amazon Associates ID to use instead of the one defined in .mtamazon.config | Use the regular ID
Devtoken | Text | A developer’s token to use instead of the one in .mtamazon.config | Use the regular token
Lastn | integer | The number of results to return, which should be no higher than 30 | 10
line | Text | The product line to search | Books
method | Text | The kind of search to conduct | Keyword search
related | Text | For searches presented with weblog entries, an entry field that provides the search query | Not applicable
search | Text | The search query | 1

The search attribute provides a word or words to use as a search query. The related attribute indicates a weblog entry field whose value should drive a search. Possible values are category, excerpt, extended, or title. These two attributes are mutually exclusive—use one or the other in an MTAmazon tag but not both.

Searches will comb through books on Amazon.Com unless another product line is chosen.

At this writing, searchable Amazon product lines are baby, books, classical (for that style of music), DVD, electronics, garden, kitchen, magazines, music, PC-hardware, photo, software, toys, universal (for hardware), VHS, video (DVDs and VHS tapes) and video games. Use one of these names as the value of the line attribute to search that part of Amazon.Com.

Product tags are placed inside an MTAmazon tag to present information culled from a search, as shown in Listing 17-1.

Listing 17-1: Displaying Book Data on a Web Page
Start example
<MTAmazon method="Keyword" search="disney" lastn="12">
    <p><a href="<MTAmazonLink>">
    <img src="<MTAmazonMediumImage>" align="left"
border="0" vspace="5">
    <MTAmazonTitle>
    </a><br>
    <MTAmazonReleaseDate format="%B %e, %Y"><br>
    Price: <MTAmazonSalePrice>
    (<MTAmazonUsedPrice> used)</p>
    <br clear="all">
</MTAmazon>
End example

The following tags can be employed:

  • MTAmazonTitle: The product’s name or title

  • MTAmazonASIN: The product’s code

  • MTAmazonCatalog: The product line

  • MTAmazonManufacturer: The product’s manufacturer, producer, or publisher

  • MTAmazonAuthor: The product’s author (books only)

  • MTAmazonArtist: The product’s creator (music only)

  • MTAmazonMediumImage: A picture of the product, which is generally no bigger than 150 pixels wide or 130 pixels tall; there’s also an MTAmazonSmallImage tag for thumbnail images, and an MTAmazonLargeImage tag for large page-filling product shots

  • MTAmazonSalePrice: The product’s current price, which can be compared to the manufacturer’s suggested price with the MTAmazonListPrice tag and the cost of available, used copies shown by MTAmazonUsedPrice

  • MTAmazonReleaseDate: The day the product began to be sold

  • MTAmazonLink: A link to the product’s page

The MTAmazonAuthor and MTAmazonArtist tags both have a glue attribute to choose text that separates the names of multiple creators on the same book or recording. The default separator is a comma.

Gotcha

The documentation for the MTAmazon plug-in also describes an MTAmazonField that serves as a catch-all for any other information Amazon provides in XML data that isn’t represented by the preceding tags. This does not appear to work at present, however, presumably because of some changes in Amazon Web services.

The MTAmazonReleaseDate tag contains the date of release, presented in the same format as “27 March, 2004.” A format attribute can be used to present the date in a different format.

This attribute contains a set of formatting strings that use the same rules as strftime, a popular program for presenting date and time values in any desired order and style. In the MTAmazonReleaseDate tag, the format attribute could be used to reformat the preceding date as “March 27, 2004” (format string “%B %d, %Y”), “03/27/2004” (format string “%m/%d/%Y”), “03-27-04” (“%m-%d-%y”), and countless other variations.

The MTAmazon plug-in also supports three tags that aren’t product-related: MTAmazonAssociateID holds your affiliate code (if you have joined), MTAmazonDevToken specifies your developer’s token, and MTAmazon CacheDateTime displays the last date and time that data was collected from Amazon for presentation on your site.

Performing Custom Searches

MTAmazon does a lot more than search for products matching keywords. You can use the plug-in to grab almost every kind of information that’s presented on the giant e-commerce site.

The method attribute of the MTAmazon tag selects the information being collected from Amazon. Most search methods retrieve products based on a search, such as “Artist” to find a musician’s work and “Director” to find a film director’s credits. Others pull up lists—“Wishlist” can present your wish list, or someone else’s, on a page.

The most popular Amazon search capabilities are represented by a method attribute of “Keyword” and “Power.”

The “Keyword” method conducts a simple search of one or more words. Because this is the default method, you can choose it by omitting the method attribute entirely.

The “Power” method, which works on books only, makes use of Amazon’s advanced search features.

Finding Your Favorite Performers

In an MTAmazon tag, a method attribute of “Actor” searches Amazon for films and TV shows starring an actor or actress, pulling them from one of three product lines that you can specify with the line attribute: dvd for DVDs, vhs for videos, or video for both.

In Figure 17-4, the MTAmazon plug-in employs this method to present Peter Lawford films that are currently available in DVD format.

Click To expand
Figure 17-4: Presenting an actor’s credits.

Listing 17-2 shows the Web page that creates this page.

Listing 17-2: An Actor’s Credit Page
Start example
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>Peter Lawford Films</title>
</head>

<body>
<table border="0" cellpadding="5">
<MTAmazon method="Actor" search="Peter Lawford" line="dvd"
lastn="10">
<tr valign="top">
<td>
    <a href="<MTAmazonLink>">
    <img src="<MTAmazonMediumImage>" align="left"
border="0">
    </a>
</td>
<td>
    <h3><a href="<MTAmazonLink>"><MTAmazonTitle></a></h3>
    <p>Released by <MTAmazonManufacturer> on
    <MTAmazonReleaseDate format="%B %d, %Y"></p>
    <p>Price: <MTAmazonSalePrice> (<MTAmazonUsedPrice>
used)</p>
</td>
</tr>
</MTAmazon>
</table>

<p>Last updated: <MTAmazonCacheDateTime>
</body>
</html>
End example

Similar searches can be produced with the “Artist” method, which looks for a musician’s work; the “Author” method, which finds books by a particular author; and the “Director” method, which finds a director’s work in DVD, VHS, or both (the video product line). All of these searches require that the line attribute identifies one of the relevant product lines for that method.

Another specialized search requires the “Manufacturer” method, which discovers a company’s products. This appears to work with all of Amazon’s product lines.

Presenting Products by Number

Amazon uniquely identifies each of its products with one of three numbers:

  • An International Standard Book Number (ISBN) for books

  • A Uniform Product Code (UPC) for music

  • An Amazon Standard Item Number (ASIN) for every product it sells

The ASIN code for a book is identical to its ISBN, so you can see them used interchangeably on Amazon and elsewhere. UPC numbers also can be used as an alternative means of identifying popular and classical music.

The “Asin” method of an MTAmazon tag can retrieve one or more products by their ASIN (or ISBN) codes. The search attribute should be the code (for a single product) or a series of codes separated by commas (for multiple products), as shown in Listing 17-3.

Listing 17-3: A Product Information Page
Start example
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>Weblog Books</title>
</head>

<body>
<ul>
<MTAmazon method="Asin"
search="073820756X,0738207411,0764549626">

<li>
    <a href="<MTAmazonLink>"><MTAmazonTitle></a>,
    <MTAmazonManufacturer>,
    <MTAmazonReleaseDate format="%m-%d-%y">,
    <MTAmazonSalePrice>
</li>
</MTAmazon>
</ul>
</body>
</html>
End example

Figure 17-5 displays this Web page.

Click To expand
Figure 17-5: Displaying a list of products.

The “Upc” method works in the same manner for UPC numbers, as demonstrated in Listing 17-4.

Listing 17-4: A Product Picture Page
Start example
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">
<MTAmazon method="Upc" search="090266882328"
line="classical">
<html>
<head>
  <title><MTAmazonTitle></title>
</head>

<body>
<div align="center">
<a href="<MTAmazonLink>">
<img src="<MTAmazonLargeImage>" border="0"><br>
<h5><MTAmazonTitle></h5></a>
</div>
</body>
</html>
</MTAmazon>
End example

In the Web page created by Listing 17-4, the MTAmazon container tag has been placed outside the entire Web page. This enables Amazon product information to be used in the page headers and the body of the page, which is employed to make the product title double as the page’s title in the HTML title tag. Figure 17-6 displays the results.

Click To expand
Figure 17-6: Using product information throughout a Web page.

This approach works only because the MTAmazon tag retrieves only a single product. Everything inside this container tag is repeated once for each result (twice for two results, three times for three, and so on). A Web page must be enclosed within one set of html tags.

Because these searches refer to each product’s unique ASIN, ISBN, or UPC number, there’s no need to designate a product line with the line attribute. In addition, no lastn attribute is needed—all products that turn up in the search will be displayed.

The “Similarity” method finds products that Amazon considers to be similar to a specific product, which the e-commerce vendor bases on customer buying patterns. The following example finds 10 books similar to Joseph Heller’s Catch-22 (ISBN 0-684-83339-5):

<ul>
<MTAmazon method=”Similarity” search=”0684833395”>
<li><a href=”<MTAmazonLink>”><MTAmazonTitle></a></li>
</MTAmazon>
</ul>

Ten books are displayed because no lastn attribute has been specified and 10 is its default value. Although you can specify a product line with the line attribute, it will be ignored.

Sharing Wish Lists and Other Product Lists

The final three methods of this remarkably versatile plug-in collect products that were grouped together as a list by Amazon or one of its customers.

Amazon produces lists of its own that you can browse, and enables customers to create wish lists for products they want to receive and ListMania collections for products they want to recommend, mock, or comment on in some other manner.

In many places on Amazon’s Web site, you can browse a directory of products, looking through a highly categorized hierarchy of merchandise. These pages have the word “browse” as part of their URL, as in this example:

http://www.amazon.com/exec/obidos/tg/browse/-/3608

Any of these pages can be retrieved with the MTAmazon plug-in using the search method BrowseNode and the page’s browse ID, the first number that follows the word browse (3608 in the preceding example).

Customer wish lists can be shown using two styles of URL, with either wishlist or registry in the address, as shown in the following examples:

http://amazon.com/o/wishlist/3FOF79BIVB2XX
http://www.amazon.com/gp/registry/BUWBWH9K2H77

Retrieving these lists requires the method “Wishlist” and an ID, which in both of these cases is the long string of letters and numbers that follows the word “wishlist” or “registry.”

Product lists also can be compiled by customers for other reasons, a feature Amazon calls ListMania. These pages have the text “list-browse” in the address, as in the following example:

http://amazon.com/exec/obidos/tg/listmania/list-browse/-/1N4J4EHD7GW42

The contents of these lists are accessed with the “ListMania” search method. The ID for these lists, as you might have guessed by this point, is that inscrutable alphanumeric code 1N4J4EHD7GW42.

The partial Web page shown in Listing 17-5 contains a table that displays all three kinds of lists.

Listing 17-5: Displaying Product Lists
Start example
<table border="0" cellpadding="5">
<tr valign="top">
<td>
<p>Java best-sellers:</p>
<ul>
<MTAmazon method="BrowseNode" search="3611" lastn="20">
    <li><a href="<MTAmazonLink>"><MTAmazonTitle></a>
    <MTAmazonSalePrice></li>
</MTAmazon>
</li>
</td>
<td>
<p>Wish list:</p>
<ul>
<MTAmazon method="Wishlist" search="3FOF79BIVB2XX"
lastn="20">
    <li><a href="<MTAmazonLink>"><MTAmazonTitle></a>
    <MTAmazonSalePrice></li>
</MTAmazon>
</li>
</td>
<td>
<p>Odd products:</p>
<ul>
<MTAmazon method="ListMania" search="1N4J4EHD7GW42"
lastn="20">
    <li><a href="<MTAmazonLink>"><MTAmazonTitle></a>
    <MTAmazonSalePrice></li>
</MTAmazon>
</li>
</td>
</tr>
</MTAmazon>
</table>
End example

These lists are shown in Figure 17-7. From left to right, they are Amazon’s Java subjects page, writer and Web developer Paul Bausch’s wish list, and one of the more amusing ListMania lists that I’ve read: Joseph Goldberg’s “silly stuff” compilation.

Click To expand
Figure 17-7: Displaying three lists in a table.
Gotcha

The method attribute of the MTAmazon tag also supports the values Exchange and Seller, but these do not appear to be supported (or are not working) in release 2.22 of the plug-in.


Summary

The term plug-in normally refers to how a smaller program can be “plugged in” to a larger one, enhancing its functionality in a specific way.

In this chapter, you learned about Perl scripts that are plug-ins in another way. The Mt-Amazon, MT-QOTD, and Weather Underground scripts plug a Movable Type weblog into a wealth of useful data offered by other Web sites.

Movable Type’s architecture enables programs to exploit these kinds of information-sharing relationships with external Web sites and other software designed to exchange data over the Internet.

Additionally, the software’s template-driven design makes it easy to present this information. The same techniques you learned about for designing Web pages apply: Drop a tag on a page inside HTML, XHTML, or XML-formatted text, use its attributes to control the output in some manner, and then rebuild your site.


Chapter 18: Publishing RSS SyndicationFiles

In This Chapter

  • Offering fresh content on a regular basis

  • Sharing content in XML form

  • Offering weblog entries for syndication

  • Choosing a syndication format

  • Developing index templates in XML

  • Creating an RSS 2.0 newsfeed

  • Designing an RSS 1.0 feed

  • Publishing Web content in multiple forms

During the flush days of the dot-com boom, a term heard often in the media was that of “Internet years,” a unit of measurement that suggested things were moving so fast in the digital world that the fuddy-duddy, centuries-old Gregorian calendar couldn’t keep up.

In recognition of the furious rate at which hot Internet start-ups and software developers released products and press releases, 10 Internet years passed during each ordinary year.

By that standard, the World Wide Web has grown up, matured, and now qualifies for senior citizen discounts at movies and cafeterias. More than 100 Internet years have passed since the first graphical Web browser was released, turning a little-known playground for scientists and students into a mass medium for millions.

Perhaps some wisdom has been accumulated over the passage of all that Internet time, because Web publishing has outgrown the era of hand-coded HTML sites.

Today’s publishers know how to exploit this medium: We use a weblog structure that takes advantage of the dynamic nature of the Web, content-management systems like Movable Type that ease the process of site design, and a multiplicity of publishing formats that tailor our work to different audiences.

Several of these publishing formats use XML, a language inspired in part by the success of HTML, as a means of exchanging data independently of the software used to create it.

As the Web has grown in sophistication, several XML formats have become popular for sharing site content outside of a Web browser: RSS 1.0, RSS 2.0, and Atom.

Using Movable Type’s support for these formats, you can take advantage of an effective new method of site promotion and reach a zealous audience who wants to read everything new that you publish.


Sharing Content with XML Syndication

Most Web content produced by Movable Type takes the form of a Web page structured as either an HTML or XHTML file, but the software isn’t limited to those two formats. You can use Movable Type to create any text-based format, including Cascading Style Sheets (CSS), XML dialects, or even formats of your own devising.

Weblogs use XML primarily to offer syndicated newsfeeds, files that contain full or partial weblog entries optimized for retrieval by XML processing software.

Newsfeeds, also called feeds, provide a means for Web sites to make content available for republication on other sites. The original inspiration behind site syndication was to enable a site to offer headlines for publication elsewhere, just as a newspaper service such as King Features syndicates its comic strips in papers all over the world.

Listing 18-1 contains part of a syndication file created by Movable Type to share weblog entries from Orlando Vacationer, an example site I’ve puttered around with throughout this book. The file uses RSS 2.0 format, one of three XML syndication formats supported by the software.

Listing 18-1: Syndicated Weblog Entries in RSS 2.0
Start example
<item>
  <title>Dining in Orlando’s Rainforest Cafes</title>
  <link>http://orlandovacationer.com/archives/000076.html</link>
  <description> <![CDATA[ Theme Park Insider reviews the
<a href="http://www.themeparkinsider.com/news/response.cfm?ID=1480">
Rainforest
Cafe restaurants</a> at Disney World Animal Kingdom
and Downtown Disney in
Orlando:<blockquote><p>If you’ve heard
anything about the Rainforest Cafe, it’s
likely been the atmosphere,
first and foremost. The entire restaurant is themed to
look like a tropical rainforest--from the leafy canopy to the
animatronic animals
placed throughout.</p></blockquote>]]>
</description>
  <guid>http://orlandovacationer.com/archives/000076.html</guid>
  <pubDate>Tue, 27 Jan 2004 13:51:10 -0500</pubDate>
</item>
<item>
  <title>Disney World’s Animal resort is a zoo</title>
  <link>http://orlandovacationer.com/archives/000001.html</link>
  <description><![CDATA[ Tony Conboy III reviews his family’s recent
stay at
<a href="http://orlando.about.com/cs/hotels/wdwakl.htm">
Animal Kingdom
Lodge</a> for About Orlando.]]></description>
  <guid>http://orlandovacationer.com/archives/000001.html</guid>
  <pubDate>Tue, 27 Jan 2004 10:18:01 -0500</pubDate>
</item>
End example

As you can see, an XML file looks a lot like HTML and contains a set of named elements that can hold text or other elements. Within each item tag in Listing 18-1, a title, link, and description are provided for a weblog entry. The title and link match the entry’s title and link. The description holds the entry text.

Although content sharing between sites might have been the spark, syndication has become enormously popular as a result of another use: Newsfeeds make it possible to keep up with Web sites without using a Web browser.

With a new kind of software called a newsreader, you can monitor the newsfeeds of your favorite weblogs and other syndicated Web sites. Once you subscribe to a feed, the newsreader checks that feed for updates as often as once per hour, presenting new items for you to read (or skim). It’s a great way to read the Web—instead of loading sites in a browser just to see if they’ve been updated, you let the newsreader find and gather anything new as it appears.

Figure 18-1 shows how the weblog entries from Orlando Vacationer in Listing 18-1 are presented in SmartManila, a newsreader and weblog publishing tool for Windows.

Click To expand
Figure 18-1: Reading a syndicated XML newsfeed in a newsreader.

Newsreaders collect and present feeds in a variety of ways. SmartManila and many others resemble an e-mail client. You choose one of the newsfeeds in the View pane to read newly arrived items. Other readers work in a Web browser, presenting items from numerous sources on a single page that’s ideal for skimming.

Thousands of people are using newsreaders as the primary means of reading weblogs, newspapers, and other online publications. For this reason, it’s a good idea to familiarize yourself with the XML newsfeeds Movable Type produces and how they can be customized.

A newly created Movable Type weblog includes three index templates that produce syndicated newsfeeds:

  • Atom Index (filename atom.xml): Recent weblog entries in the Atom 0.3 syndication format

  • RSS 1.0 Index (index.rdf): Recent entries in the RSS 1.0 syndication format

  • RSS 2.0 Index (index.rss): Recent entries in the RSS 2.0 format

All three of these files are published in the same directory as the weblog’s home page. When you rebuild a weblog’s index files or publish a new entry, these files are republished.

These three templates work as-is, so you’re already supporting syndication the moment you create a new weblog.

The home page template, Main Index, includes a sidebar link to index.rdf, the RSS 1.0 newsfeed, in this part of the page:

<div class=”syndicate”>
<a href=”<$MTBlogURL$>index.rdf”>Syndicate this site (XML)</a>
</div>

To let visitors know that several formats are supported, you can replace this section with the following XHTML code:

<div class=”syndicate”>
  <a href=”<MTBlogURL>atom.xml”>Syndicate this site (Atom)</a>
  <a href=”<MTBlogURL>index.rdf”>Syndicate this site (RSS 1.0)</a>
  <a href=”<MTBlogURL>index.xml”>Syndicate this site (RSS 2.0)</a>
</div>

The template also includes two lines in the header section of the page that indicate that newsfeeds are present:

<link rel=”alternate” type=”application/rss+xml” title=”RSS”
href=”http://orlandovacationer.com/index.rdf” />
<link rel=”alternate” type=”application/atom+xml” title=”Atom”
href=”http://orlandovacationer.com/atom.xml” />

These lines of XHTML code indicate that the page’s contents are available in two alternative formats: RSS (in this example, RSS 1.0) and Atom. This information can be used by browsers and other software to make it easier for people to find and subscribe to newsfeeds. Several newsreaders offer an autosubscribe feature that makes use of these link tags.

In the Main Index template, the following lines can be substituted to indicate that RSS 2.0 also is supported:

<link rel=”alternate” type=”application/rss+xml” title=”RSS 1.0”
href=”http://orlandovacationer.com/index.rdf” />
<link rel=”alternate” type=”application/rss+xml” title=”RSS 2.0”
href=”http://orlandovacationer.com/index.xml” />
<link rel=”alternate” type=”application/atom+xml” title=”Atom”
href=”http://orlandovacationer.com/atom.xml” />
Gotcha

For the most part, the Atom, RSS 1.0, and RSS 2.0 newsfeeds serve the same purpose and contain most of the same information, so it might seem redundant to offer all three in a weblog. There’s a good reason to be redundant: Different newsreaders support different formats, so by offering all three, you can reach the widest possible audience of newsreader users and other syndication consumers.

The next two sections describe the RSS 1.0 and 2.0 syndication formats. You find out about Atom in Chapter 19, “Supporting the Atom Syndication Format and API.”

Creating an RSS 2.0 Newsfeed

The simplest of the three syndication formats is RSS 2.0, created by Netscape and UserLand Software and managed by the RSS Advisory Board at Harvard’s Berkman Center for Internet and Society. I’m a member of that board, so my opinion of the format borders on the parental.

The technical specification describing RSS 2.0 can be viewed on the Web at http://blogs.law.harvard.edu/tech/rss.

RSS 2.0 claims that the acronym stands for Really Simple Syndication, and for the most part it lives up to that promise. Listing 18-2 contains an RSS 2.0 template that can be used to present the last 15 entries of a Movable Type weblog. Even if you’re unfamiliar with RSS 2.0, you should be able to learn a lot about the format simply by looking over the listing.

Listing 18-2: RSS 2.0 Index Template (index.xml)
Start example
<?xml version="1.0" encoding="<MTPublishCharset>"?>
<rss version="2.0">
  <channel>
  <title><MTBlogName remove_html="1" encode_xml="1"></title>
  <link><MTBlogURL encode_xml="1"></link>
  <description><MTBlogDescription remove_html="1"
encode_xml="1"></description>
  <language>en-us</language>
  <lastBuildDate><MTEntries lastn="1"><MTEntryDate
format="%a, %d %b %Y %H:%M:%S ">
<MTBlogTimezone no_colon="1"></MTEntries></lastBuildDate>
  <generator>Movable Type <MTVersion></generator>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
<MTEntries lastn="15">
  <item>
    <title><MTEntryTitle remove_html="1" encode_xml="1"></title>
    <link><MTEntryLink encode_xml="1"></link>
    <description><MTEntryBody encode_html="1"
encode_xml="1"></description>
    <guid><MTEntryLink encode_xml="1"></guid>
    <pubDate><MTEntryDate format="%a, %d %b %Y %H:%M:%S ">
<MTBlogTimezone no_colon="1"></pubDate>
<MTEntryCategories>
    <category><MTCategoryLabel remove_html="1"
encode_xml="1"></category>
</MTEntryCategories>
  </item>
</MTEntries>
</channel>
</rss>
End example

When this template is used to create the file index.xml during a rebuild, its XML data will be combined with the output produced by Movable Type template tags such as MTBlogName and MTVersion.

Like all XML data, this file begins with a processing instruction:

<?xml version=”1.0” encoding=”<MTPublishCharset>”?>

This instruction indicates that the file contains XML 1.0, with a character set identified by the MTPublishCharset tag. The set used by Movable Type is ISO 8859-1 unless the PublishCharset setting has been changed in the mt.cfg configuration file.

All of the data in an RSS 2.0 newsfeed is enclosed with an rss tag with a version attribute of “2.0”. The rss element can contain one channel element for information about the newsfeed.

Inside the channel element, the template in Listing 18-2 makes use of the following elements:

  • title: The name of the site providing the feed

  • link: The URL of the site’s home page

  • description: A succinct description of the site

  • language: A code indicating the language used in the text (“en-us” stands for English-United States)

  • lastBuildDate: The date and time the feed was last published

  • generator: The software that created the feed

  • docs: The URL of the RSS 2.0 specification

Within the opening and closing tags of these elements, values are defined using text and template tags. The MTBlogName tag provides the title, MTBlogURL the link, MTBlogDescription the description, and MTVersion the software’s version number.

Several of these tags make use of the tag attributes remove_html and encode_xml.

When the remove_html attribute has the value 1 (true), HTML formatting will be stripped from the tag’s output, producing unformatted text. For example, if a Web site’s description were <b>Disney discounts</b>, <b>park perks</b>, <b>tourist tips</b>, remove_html=”1” converts it to “Disney discounts, park perks, tourist tips.”

An encode_xml attribute set to 1 converts three characters to entity codes: an ampersand (&) becomes &amp;, a less-than sign (<) becomes &lt;, and a greater-than sign (>) becomes &gt;. This technique should be used with any template tag that might contain one of these characters so that the tag won’t produce invalid XML data.

Gotcha

The encode_xml attribute causes the text produced by a template tag to be enclosed within <![CDATA[ and ]]> tags in XML. These tags indicate that the enclosed text should be considered character data.

This works for RSS (and Atom) elements produced from a single Movable Type tag such as MTEntryBody, but causes problems for some newsreaders and other software when an element contains more than one tag. To avoid the problem, omit the encode_xml=”1” from those elements and put your own <![CDATA[ and ]]> tags around the entire element, as in this example:

<description>
  <![CDATA[<MTEntryBody encode_html="1">
  <p><MTEntryMore encode_html="1">]]>
</description>

If you want to include HTML produced by a template tag, omit the remove_html attribute. You can convert HTML into an encoded form by adding an encode_html attribute of 1, which replaces &, <, >, and other characters with entity codes.

The lastBuildDate element uses several template tags and a plug-in:

<lastBuildDate><MTEntries lastn=”1”><MTEntryDate
format=”%a, %d %b %Y %H:%M:%S “>
<MTBlogTimezone no_colon=”1”> </MTEntries></lastBuildDate>

When using this element in a template, be sure to leave a space at the end of the format attribute of the MTEntryDate tag.

Because no template tag holds the date and time that a weblog was last updated, this information must be collected from the most recently authored weblog entry, which can be retrieved using an MTEntries tag with a lastn value of 1. Within the MTEntries container, you can use any of an entry’s template tags.

Dates in an RSS 2.0 feed must be formatted according to the rules of RFC 822, an Internet standard governing the structure of an e-mail message, with one exception: a year can be two digits or four. Here’s an example of two correctly formatted RFC 822 timestamps:

Sat, 17 Apr 2004 19:23:04 -0500
Mon, 12 Apr 2004 02:51:52 GMT

The MTEntryDate tag presents the date and time of an entry according to the guidelines established in its format attribute. In this attribute, the order and format of each part of a timestamp are specified by strftime codes, as described in Chapter 9, “Designing a Weblog with Templates.”

MTEntryDate produces everything needed for an RFC 822 date but the last part, the name or time offset that identifies the time zone used by your weblog. The preceding examples use a numeric offset of -500 (Eastern time in the U.S. and Canada) and the name GMT, respectively.

A weblog’s time zone is determined by the Timezone configuration setting. To see the current value, in the browser interface, click the Weblog Config sidebar menu button, and then scroll to the bottom of the Core Setup page.

In an RSS 2.0 template, you can specify the time zone manually by using one of the codes or offset values in Table 18-1. You also can use any other offset from -1200 to +1300 and single-letter military time zone codes (A through I and K through Z).

Table 18-1: RFC 822 Time Zone Codes
Code | Time Zone | Numeric Offset
CDT | Central Daylight Time | -0500
CST | Central Standard Time | -0600
EDT | Eastern Daylight Time | -0400
EST | Eastern Standard Time | -0500
GMT | Greenwich Mean Time | None
MDT | Mountain Daylight Time | -0600
MST | Mountain Standard Time | -0700
PDT | Pacific Daylight Time | -0700
PST | Pacific Standard Time | -0800
UT | Universal Time | None

The disadvantage of putting a specific time zone in a template is that it only works for your own weblog and will be incorrect if you switch time zones later.

A more robust way to create RFC 822–compliant timestamps is to use the MTBlogTimezone tag with a no_colon attribute that has the value 1. The template in Listing 18-2 makes use of this new tag.

An RSS 2.0 newsfeed contains one or more item elements that contain headlines, weblog entries, or some other kind of information, usually in reverse chronological order.

The RSS 2.0 template uses 15 item elements to present the 15 most recent weblog entries. This tag contains six elements:

  • title: The entry’s title

  • link: The link to the entry’s Web page

  • description: The body of the entry

  • guid: A unique string that’s associated only with the entry

  • pubDate: The date and time the entry was created

  • category: A category to which the entry belongs

Most of the tags employ the encode_xml attribute to ensure that XML data produced by the tag is formatted correctly. The title and category tags strip out HTML and the entry body includes encoded HTML.

The pubDate element contains an RFC 822–complaint timestamp just like the one used in the channel’s lastBuildDate element.

The link and guid elements contain the same thing—the URL of the entry’s Web page—used in two different ways. The link element provides a hyperlink that can be visited to read more about the entry, driving traffic from the RSS 2.0 newsfeed to your weblog. The guid element serves as a unique identifier for the entry, which newsreaders and other RSS 2.0 software can use to avoid presenting the same entry twice.

The last element, category, appears once for each of the entry’s categories.

The RSS 2.0 format includes more than a dozen other tags that can be placed in a channel or item element. It also can be extended with additional tags through a namespaces feature that is covered in the next section.

The simplicity and popularity of RSS 2.0 make it a good starting place for syndication efforts, but it often makes sense to support more than one of the formats. As you’ll learn by reading the RSS 2.0 specification, some of its elements are defined more vaguely than the corresponding elements of an RSS 1.0 or Atom feed. For example, there’s no guidance regarding whether an item’s title element can acceptably contain HTML, leaving Web publishers and software developers to decide whether to allow or disallow it.

Creating an RSS 1.0 Newsfeed

Although you might have read elsewhere about “the RSS format,” there’s no such thing as a single RSS format.

Much to the chagrin of anyone who deals with the subject, two rival formats call themselves RSS: RSS 2.0, the format that claims the initials stand for “Really Simple Syndication,” and RSS 1.0, a more complex format that calls it “RDF Site Summary.” Both formats are in wide use today.

The name of RSS 1.0 comes from Resource Description Framework (RDF), a specification for describing information about the information published on the Internet, a definition that tends to confuse as many people as it enlightens.

To put it in more concrete terms, one popular application of RDF is the Dublin Core Metadata Initiative, a set of tags that identify authorship information such as the creator, language, copyright, and publisher of a document such as a Web page.

RDF strives to make Internet content more understandable to computers so that search engines and other software can handle it more intelligently. Movable Type supports trackback through the use of RDF, embedding data in Web pages to let software know how to send and receive trackback pings related to each entry.

The RSS 1.0 format was developed by the RSS-DEV Working Group, around a dozen programmers and publishers who used the rss-dev public mailing list on Yahoo! Groups to collaborate. The specification for the format can be found on http://web.resource.org/rss/1.0.

Listing 18-3 contains an RSS 1.0 template suitable for use as a Movable Type index file.

Listing 18-3: RSS 1.0 Index Template (index.rdf)
Start example
<?xml version="1.0" encoding="<MTPublishCharset>"?>

<rdf:RDF
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:admin="http://webns.net/mvcb/"
  xmlns:cc="http://web.resource.org/cc/"
  xmlns="http://purl.org/rss/1.0/">

  <channel rdf:about="<MTBlogURL>">
    <title><MTBlogName encode_xml="1"></title>
    <link><MTBlogURL encode_xml="1"></link>
    <description><MTBlogDescription encode_xml="1">
</description>
    <dc:language>en-us</dc:language>
    <dc:date><MTEntries lastn="1"><MTEntryDate
format="%Y-%m-%dT%H:%M:%S" language="en">
<MTBlogTimezone></MTEntries></dc:date>
    <admin:generatorAgent rdf:resource=
"http://www.movabletype.org/?v=<MTVersion>"/>
    <MTBlogIfCCLicense>
    <cc:license rdf:resource="<MTBlogCCLicenseURL>"/>
    </MTBlogIfCCLicense>
    <items>
      <rdf:Seq><MTEntries lastn="15">
        <rdf:li rdf:resource="<MTEntryPermalink
encode_xml="1">"/>
      </MTEntries></rdf:Seq>
    </items>
  </channel>
  <MTEntries lastn="15">
  <item rdf:about="<MTEntryPermalink encode_xml="1">">
    <title><MTEntryTitle remove_html="1"
encode_xml="1"></title>
    <link><MTEntryPermalink encode_xml="1"></link>
    <description><MTEntryBody encode_html="1"
encode_xml="1"></description>
    <dc:subject><MTEntryCategory
encode_xml="1"></dc:subject>
    <dc:creator><MTEntryAuthor encode_xml="1"></dc:creator>
    <dc:date><MTEntryDate format="%Y-%m-%dT%H:%M:%S"
language="en"><MTBlogTimezone></dc:date>
  </item>
  </MTEntries>
</rdf:RDF>
End example

An RSS 1.0 file is XML 1.0 data that begins with this processing instruction:

<?xml version=”1.0” encoding=”<MTPublishCharset>”?>

An rdf:RDF tag encloses the contents of the newsfeed: one channel element and one or more item elements.

These elements serve the same purpose in both flavors of RSS, as do the channel tags title, link, and description; and the item tags title, link, and description.

Everything else in the template makes use of RDF and a feature of XML called namespaces.

Namespaces enable XML data to include elements drawn from several different specifications. The RSS 1.0 newsfeed in Listing 18-3 employs five namespaces: RDF, Dublin Core, Creative Commons, MetaVocab, and RSS 1.0 itself. They are declared as attributes of rdf:RDF, the root element of the newsfeed:

<rdf:RDF
  xmlns:rdf=”http://www.w3.org/1999/02/22-rdf-syntax-ns#”
  xmlns:dc=”http://purl.org/dc/elements/1.1/”
  xmlns:sy=”http://purl.org/rss/1.0/modules/syndication/”
  xmlns:admin=”http://webns.net/mvcb/”
  xmlns:cc=”http://web.resource.org/cc/”
  xmlns=”http://purl.org/rss/1.0/”>

Each xmlns attribute declares a namespace using a unique identifier, which in most cases is the URL of a Web site describing the elements available in that namespace.

The last xmlns attribute refers to the RSS 1.0 specification. The other five include a suffix after the attribute name: admin for MetaVocab, cc for Creative Commons, dc for Dublin Core, and rdf for RDF. These identifiers are used in element names to indicate the namespace from which the element was drawn.

An element or element attribute that uses an external namespace has a two-part name: a namespace identifier followed by a colon (:) and the element name. For example, the rdf:RDF element and rdf:about attribute come from the RDF namespace.

The channel element of an RSS 1.0 newsfeed includes an rdf:about attribute that contains the URL of your weblog:

<channel rdf:about=”<MTBlogURL>”>

An rdf:about attribute explains what an element describes—here, it shows that the channel describes a particular Web site.

In the RSS 1.0 template in Listing 18-3, two channel elements come from the Dublin Core:

  • dc:date: The date and time the site was last updated

  • dc:language: A short code for the language used in the newsfeed

The dc:date timestamp can take several forms, one of which matches these examples:

2004-04-18T14:56:04-05:00
2004-04-12T18:47:26-08:00

These timestamps contain a date; the letter T; the time in hours, minutes, and seconds; and a time zone offset value. The offset values differ slightly from the ones appearing in an RSS 2.0 newsfeed: They contain a semicolon dividing hours and minutes.

The following line of the RSS 1.0 template defines this element:

<dc:date><MTEntries lastn=”1”><MTEntryDate
format=”%Y-%m-%dT%H:%M:%S” language=”en”>
<MTBlogTimezone></MTEntries></dc:date>

The MTEntryDate tag, structured using the strftime value “%Y-%m-%dT%H:%M:%S”, produces everything needed in the timestamp up to the time zone offset. That last part can be provided by the MTBlogTimeZone tag (no plug-in is needed). Do not put a blank space between these two tags—the time zone immediately follows the date and time.

One channel element, admin:generatorAgent, comes from the MetaVocab namespace. The element’s rdf:resource attribute identifies the software that created the newsfeed.

The cc:license element tells publishers whether they have the right to republish the contents of your newsfeed or create derivative works based on it. If you have associated a Creative Commons license with your weblog, as described in Chapter 4, “Configuring a Weblog,” the MTBlogCCLicenseURL tag contains a URL that indicates the particulars of your chosen license. This URL can be placed in the rdf:resource attribute of the cc:license element:

<MTBlogIfCCLicense>
  <cc:license rdf:resource=”<MTBlogCCLicenseURL>”/>
</MTBlogIfCCLicense>

The MTBlogIfCCLicense container causes the Creative Common license element to appear in the newsfeed only when a license has been chosen. Weblogs that do not offer licensing will omit the cc:license tag when index templates are rebuilt.

The last channel element, items, holds an rdf:Seq element that establishes the sequence in which newsfeed items should be presented. An rdf:li element must be present, using the rdf:resource attribute to identify the item. (To help you remember these names, Seq is short for “sequence” and li is short for “list.”)

Here’s how the RSS 1.0 template sets the order of items:

<items>
      <rdf:Seq><MTEntries lastn=”15”>
        <rdf:li rdf:resource=”<MTEntryPermalink
encode_xml=”1”>”/>
      </MTEntries></rdf:Seq>
    </items>

The MTEntries container holds the 15 most recent weblog entries, going backward from the most current.

The last element to appear in the RSS 1.0 template is item, which appears once for each weblog entry to include in the feed. Fifteen entries are presented in the example newsfeed template.

Each item element must have an rdf:about attribute that matches the rdf:resource attribute of an rdf:li element. This association establishes the proper order of items; if an rdf:about value cannot be found in any rdf:li tag, the item might be ignored by software that reads RSS 1.0 data.

An item has three elements—title, link, and description—that match the same elements in RSS 2.0. Three other elements come from Dublin Core:

  • dc:creator: The author of the weblog entry

  • dc:date: The date and time the entry was created

  • dc:subject: A classification for the entry, which can be a category, a topic, or keywords

The dc:date element uses the same MTEntryDate and MTBlogTimeZone tags as the channel’s timestamp, dc:creator takes the entry author’s username, and dc:subject uses the entry’s primary category.

Although namespaces have been introduced in relation to RSS 1.0, they work with both RSS formats. Declare a namespace in the root-level rss element the same way it is declared in RSS 1.0.


Summary

Because most of the files produced by Movable Type templates are HTML or XHTML pages, it’s easy to get the wrong idea about the software. Movable Type doesn’t limit you to Web pages. The software will publish weblog content in any text-based format you desire, including plain text, HTML, XHTML, CSS, and the growing number of XML site syndication formats.

By using index templates, you can create XML versions of your weblog entries in Atom, RSS 1.0, and RSS 2.0 formats, three popular specifications for sharing content in a form that’s ideally suited to be read by software.

Files created in these formats are called newsfeeds and can be read by a newsreader, an Internet client program that methodically checks a user’s favorite newsfeeds as often as once per hour. New content discovered in these feeds is presented for easy reading, eliminating the drudgery associated with repeatedly checking browser bookmarks in the often fruitless hunt for something new.

Syndicated newsfeeds also can be published on other Web sites, a promotional vehicle that you can adopt to expand your audience and drive traffic to your weblog.

The growing popularity of XML-structured Web publishing formats demonstrates that we’ve managed to learn something after creating sites for more than a decade (or more than a century, for readers still running on Internet time).

XML syndication formats take Internet publishing to a new level, organizing content so that it can be adapted easily to a wide range of uses. Although some graphically inspired Web designers might blanch at the prospect of their work being ignored by the audience of RSS and Atom users, many publishers are coming around to the notion that these formats bring more users of all kinds to your Web site, including visitors who arrive by browser.


Chapter 19: Supporting the AtomSyndication Format and API

In This Chapter

  • Syndicating Web content with XML

  • Creating an Atom feed

  • Sharing weblog entries in Atom

  • Creating an Atom index template

  • Working with constructs

  • Storing information in feed elements

  • Publishing weblog entries in the feed

  • Using the Atom API

  • Connecting Web content with link elements

  • Calling Atom API commands

  • Sending and receiving

  • API requests

Under one definition of the term, a weblog is merely a regularly published Web site organized chronologically so that the most timely material appears first.

There’s nothing particularly novel about that, aside from the name, which was coined by the Internet writer Jorn Barger. Chronological lists are as old as NCSA Mosaic What’s New, a popular directory of new sites published first in 1993 (more than 77 years ago in Internet time).

In another respect, weblogs deserve a loftier definition: the spark for a dramatic reinvention of how Web content is created and shared with an audience.

A large network of tightly-linked sites updated at a frenzied pace, weblogs bring the Web closer to an original goal of its inventor—to serve as a medium for two-way communication with no distinction between author and audience. Anyone can create content for a global audience on the Web.

Part of this reinvention has been the growth of RSS syndication formats and weblog APIs, new methods of sharing information with XML that were documented earlier in this book.

This chapter covers an ambitious effort to take Web site syndication and publishing further by developing a common protocol for both: the Atom syndication format and application programming interface.

Creating an Atom Newsfeed

As this book is being written, Six Apart and other developers of weblog publishing software are working on the Atom syndication format, a new XML format that addresses perceived limitations in the two RSS formats described in Chapter 18, “Publishing RSS Syndication Files.”

Atom comprises a syndication format for delivering site content to an audience and a publishing interface for authoring new content.

Web Site Download

Atom’s syndication format has been released as a “pre-draft” version from a development Web site: http://atomenabled.org/developers/syndication.
Gotcha

You might wonder why a “pre-draft” of Atom has been implemented in Movable Type, because it sounds like a specification that will change greatly upon the full release of the format. The term “pre-draft” refers to a step in the standardization process for Internet protocols—the authors of the format do not believe that the Atom format will change dramatically in future drafts.

Listing 19-1 contains a sample Atom index template for Movable Type that produces an Atom version 0.3 feed.

Listing 19-1: A Sample Atom Index Template (atom.xml)
Start example
<?xml version="1.0" encoding="<MTPublishCharset>"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xml:lang="en">
  <title><MTBlogName remove_html="1" encode_xml="1"></title>
  <link rel="alternate" type="text/html"
href="<MTBlogURL encode_xml="1">" />
  <modified><MTEntries lastn="1"><MTEntryModifiedDate utc="1"
format="%Y-%m-%dT%H:%M:%SZ"></MTEntries></modified>
  <tagline><MTBlogDescription remove_html="1" encode_xml="1"></tagline>
  <id>tag:orlandovacationer.com,2004-05-17:weblog</id>
  <generator url="http://movabletype.org"
version="<MTVersion>">Movable
Type</generator>
<MTEntries lastn="15">
  <entry>
    <title><MTEntryTitle remove_html="1" encode_xml="1"></title>
    <link rel="alternate" type="text/html" href="<MTEntryPermalink
encode_xml="1">" />
    <modified><MTEntryModifiedDate utc="1"
format="%Y-%m-%dT%H:%M:%SZ"></modified>
    <issued><MTEntryDate utc="1" format="%Y-%m-%dT%H:%M:%SZ">
</issued>
    <id>tag:orlandovacationer.com,2004-05-17:weblog.<MTEntryID></id>
    <created><MTEntryDate utc="1" format="%Y-%m-%dT%H:%M:%SZ">
</created>
    <summary><MTEntryExcerpt remove_html="1" encode_xml="1">
</summary>
    <author>
      <name><MTEntryAuthor encode_xml="1"></name>
<MTIfNonEmpty tag="MTEntryAuthorURL">    <url><MTEntryAuthorURL
encode_xml="1"></url></MTIfNonEmpty>
<MTIfNonEmpty tag="MTEntryAuthorEmail">    <email><MTEntryAuthorEmail
encode_xml="1"></email></MTIfNonEmpty>
    </author>
    <content type="text/html" mode="escaped" xml:lang="en" xml:base="
<MTBlogURL encode_xml="1">">
      <MTEntryBody encode_xml="1">
      <MTEntryMore encode_xml="1">
    </content>
  </entry>
</MTEntries>
</feed>
End example

For the most part, an Atom newsfeed contains the same information as an RSS 1.0 or 2.0 file, with different element names. The major difference between Atom and the two RSS formats is that Atom is more rigid about the kinds of information that can be contained in an element.

In an Atom file, a root-level feed element holds a bunch of elements that describe the newsfeed, such as title (weblog title), tagline (weblog description), and modified (date and time of publication). Each entry in the feed, which can be a weblog entry or some other kind of information delivered in sequence, has an entry container element with its own subelements to define the entry, including created (date and time of first publication), and title (entry title).

Atom feeds can make use of namespaces but do not employ RDF. The strongest difference between the new format and its predecessors lies in its support for multiple content types for each entry. If you want to syndicate your weblog entries as text, HTML, and another format, each can have its own content element within an entry container.

Working with Atom Feed Elements

Although the Atom syndication format works well with weblog entries, news headlines, and similar Web sites, it was developed for representing any list of items that should be syndicated from publisher to audience.

An Atom newsfeed consists of XML data, which can be established with the first line of the index template in Listing 19-1:

<?xml version="1.0" encoding="<MTPublishCharset>"?>

Although an Atom feed does not have to employ XML 1.0, that’s the only version that you can use to produce the application/x.atom+xml MIME type that Web browsers and other clients look for when handling Atom files.

The MTPublishCharset template tag identifies the character set that Movable Type has been configured to use.

An Atom feed can contain comments and a document type declaration that defines the validity of the file’s XML markup.

An Atom feed has a single feed element that holds the rest of its data. This element must have a version attribute identifying the Atom specification used to create the feed, which at present is “0.3”. Another required attribute, xml:lang, indicates the language used in the feed (en is the two-letter code for English). The xmlns attribute describes the default XML namespace to which elements of the feed belong.

Atom elements can be one of four types of information, which are described as constructs in the format specification:

  • A content construct that holds site content as one or more child elements

  • A date construct that holds a timestamp value as a child element

  • A link construct that represents a Web URL and has no child elements

  • A person construct for the author and contributors involved in producing the feed or its entries

These constructs are not elements that can be placed in an Atom template under those names. Instead, they’re just a handy way to group elements that share the same attributes and serve similar purposes.

For instance, all date-and-time elements in Atom are date constructs. When you learn how to work with this construct’s attributes, you’ll be able to work with any timestamp in Atom.

The next four sections describe the four constructs. When specific Atom elements are described later in this chapter, the construct group to which they belong is identified.

Using Content Constructs

Listing 19-2 contains an example of a content construct, the aptly named content element.

Listing 19-2: A Content Construct
Start example
<content type="text/html" mode="escaped">
      <![CDATA[<p>Disney World is offering a "Play 4 Days" promotion
for
Florida residents, as described on
<a href="http://wdwcentral.com/index/P303/">WDW
Central</a>:
Four-day park-hopping tickets for $109 per person. The tickets cover
the
first half of the year (through July 4) and are blocked from use
April 3-15.<br />]]>
    </content>
End example

A content construct holds one or more child elements that taken as a whole represent the element’s data. Most of these elements contain only a single element: text defined within the element’s opening and closing tags, as shown in Listing 19-2.

A content construct has two optional attributes, type and mode. The type attribute identifies the MIME type that the element holds, which is assumed to be text/plain when the attribute is not present. Common values for this attribute are text/html for HTML formatted text and application/xhtml+xml for XHTML.

When present, the mode attribute takes one of three values:

  • base64 when the element holds text encoded in base-64 format

  • escaped when the element text has been stored using escape codes or a CDATA block

  • xml when the element holds well-formed XML

A content construct with no mode attribute is assumed to be XML.

Using escape codes in XML data enables text to contain characters that have meaning in XML: <, >, and &. They are replaced with the entity codes &lt; for <, &gt; for >, and &amp; for &.

A CDATA block begins with the text <![CDATA[“ and ends with ]]>. Everything within these markers is character data, rather than valid XML. This tag is a feature of XML itself, not specific to the Atom format, and the primary purpose is to enable the same three characters—<, >, and &—to appear as text in XML data.

In the content element in Listing 19-2, the text “<a href=”http://wdwcentral. com/index/P303/”>WDW Central</a>” could be escaped to “&lt;a href= ”http://wdwcentral.com/index/P303/”&gt;WDW Central&lt;/a&gt;”.

The default templates in Movable Type use escape codes instead of CDATA blocks to place HTML markup inside an Atom or RSS element. The tag attribute encode_xml=”1” converts the three characters to their escape equivalents, as shown in this example:

<MTEntryTitle encode_xml=”1”>

The use of escaped text in syndication formats, whether defined with entity codes or a CDATA block, has become controversial among XML experts because XML parsing software can’t interpret the character data in a meaningful way. All it can do is pass the data from the source—in this case, an Atom feed—to a client such as a syndicated feed reader.

To avoid this lack of clarity, the most precise way to define data in a content construct is to use mode=”xml” and ensure that the element holds only proper XML such as XHTML.

Because this places more of a burden on weblog authors—writing well-formed XHTML by hand takes diligence—few Web publishers use non-escaped data in their syndication feeds.

Using Date Constructs

A date construct contains a single child element, a timestamp value that expresses a date and time in the World Wide Web Consortium’s date-time format. Here’s an example defined in Atom’s modified tag:

<modified>2004-05-24T15:07:42-05:00</modified>

This timestamp represents 5/24/2004 at 3:07:42 PM in the time zone five hours behind UTC (Coordinated Universal Time).

A date-time represented in UTC can use a Z in place of the numeric time zone offset:

<modified>2004-05-24T20:07:42Z</modified>

This represents the same time as the preceding example, because 8:07:42 PM in the UTC time zone is five hours ahead of 3:07:42 PM.

A date-time also can omit the time or the day of month, as in the following two examples:

<modified>2004-05</modified>
<modified>2004</modified>

You can create a timestamp in this format by using one of Movable Type’s date template tags with format and utc attributes with the following values:

<MTEntryModifiedDate utc="1" format="%Y-%m-%dT%H:%M:%SZ">
Web Site Download

The full specification for the date-time format is described on the consortium’s Web site at http://www.w3.org/TR/NOTE-datetime.

Using Link Constructs

A link construct represents a relationship between an element in an Atom feed and some other resource on the Internet.

One example of such a construct is the link element contained within an Atom file’s top-level feed element, which represents the URL of the Web site providing the feed.

Link constructs have no child elements and must include the following three attributes:

  • href: The address of the linked resource, which must be specified as a Uniform Resource Identifier (URI)

  • type: The MIME type of the linked resource

  • rel: A short descriptor that explains the relationship between the feed element and the linked resource

A link construct also can have an optional title attribute that provides a short description of the resource.

Here’s an example:

<feed version=”0.3” xmlns=”http://purl.org/atom/ns#” xml:lang=”en”>
   <link rel=”alternate” type=”text/html”
href=”http://example.com/blog”/>
</feed>

This portion of an Atom feed has a link construct, link, providing the URL of the feed’s home page: http://example.com/blog. Presumably, this means that the same items in the feed can be found on a Web page at that address and loaded with a browser.

Links provide alternative representations of a parent element or additional Web content associated with the feed in some manner. There can be more than one link construct within the same parent, as long as each has a different type value.

A link construct with a rel value of alternate is the main alternative to the feed. On a weblog, the Atom feed and its home page are different representations of the same information, so a construct with link=”rel” is the weblog’s home page.

The following example, taken from Six Apart founder Ben Trott’s Atom feed, has two link elements:

<feed version=”0.3” xmlns=”http://purl.org/atom/ns#”
xml:lang=”en”>
   <link rel=”alternate” type=”text/html”
href=”http://btrott.typepad.com/typepad/” />
   <link rel=”service.post” type=”application/x.atom+xml”
href=”http://www.typepad.com/t/atom/weblog/blog_id=8”
title=”Stupidfool.org” />
</feed>

The first link construct indicates that the feed provides an XML representation of a Web site at http://btrott.typepad.com/typepad/ (his weblog on TypePad). The second provides a URL that can be used to publish weblog entries using the Atom API, a topic that is covered later in this chapter. A link element with the rel attribute of “service.post” always serves this purpose.

Any link construct can have an xml:base attribute that provides the base URI of the resource indicated by the href attribute, transforming a relative address into a full address. For example, consider the following link:

<link rel=”alternate” type=”text/html” href=”workbench/”
xml:base=”http://cadenhead.org/” />

The xml:base and href attributes are combined to form the full URI http://cadenhead.org/workbench. In Atom, the xml:base attribute is optional and is used only on specified members of the link construct group, as described subsequently. On other elements, it is ignored even when present.

Using Person Constructs

The last Atom construct that represents a group of similar elements is the person construct, devoted to elements that identify a specific author associated in some manner with part (or all) of the feed.

This author can be an individual person or some other entity in the case of group authorship.

A person construct can have three child elements, each of which can appear only once within the same parent:

  • name: The person’s name

  • email: The person’s e-mail address

  • url: A URI associated with the person, such as a home page URL

The name element must be present; the other two elements are optional. When xml:base attributes are present in the url element, its parent, or higher up the hierarchy, it must be applied to transform the URL.

Authoring an Atom Feed

Atom data consists of a single feed element that contains child elements defining the feed and a series of items:

<feed version=”0.3” xmlns=”http://purl.org/atom/ns#”
xml:lang=”en”>

Movable Type weblogs include an Atom index template that holds an XML representation of the 15 most recent weblog entries in Atom 0.3 format.

The xmlns attribute indicates the default namespace for the feed, which applies to any element whose name is not preceded with a namespace identifier. Additional namespaces and their elements can appear in the feed as long as they are declared using additional namespace declarations, as in this example:

<feed version=”0.3” xmlns=”http://purl.org/atom/ns#”
xmlns:dc=”http://purl.org/dc/elements/1.1/”>

The feed element must include a version attribute specifying the version of the Atom specification employed by the feed. To create a feed compliant with the rules described in this chapter, use version=”0.3”.

An optional xml:lang attribute can be used to identify the feed’s language, using an identifier such as the two-letter codes defined by the ISO 639 standard (en for English, ru for Russian, eo for Esperanto, and so on).

The preceding example defines a feed that uses three namespaces:

  • The xml namespace (for elements such as xml:lang and xml:base)

  • The default namespace, identified by the xmlns attribute

  • A namespace with the identifier dc, as established by the xmlns:dc attribute

The third namespace is Dublin Core 1.1, a set of elements that provide basic information about a resource on the Internet, such as its creator, publisher, and title.

In the feed, any element belonging to a namespace outside of the default will have a namespace identifier followed by a colon and the element name. Here’s one for the Dublin Core’s Language element:

<dc:Language>en</dc:Language>

This element and the other parts of Dublin Core 1.1, defined on the Web at http://dublincore.org/documents/dces, can appear in any XML data with a top-level element that includes the namespace declaration xmlns:dc= ”http://purl.org/dc/elements/1.1/”.

Table 19-1 contains child elements that might be present within a feed element. Some are optional, whereas others must be defined.

Table 19-1: Atom Feed Elements
Name | Description | Construct Type | Quantity | Required
author | The author of the feed | person | One | Varies
contributor | A contributor to the feed | person | One or more | No
copyright | A copyright statement for the feed | content | One | No
generator | The name of the software generating the feed | none | One | No
id | A URI that functions as a globally unique identifier for the feed and never changes | none | One | No
info | A short description of the Atom format | content | One | No
link | A URI associated with the feed | link | One or more | Varies
modified | The date and time the feed was last edited | date | One | Yes
tagline | A short description of the feed | content | One | No
title | A short descriptive title for the feed | content | One | Yes

The construct type for each of the elements in Table 19-1 indicates the kind of content it must contain. An attribute that has no construct type is simply a string of characters.

Many of the elements are optional and can be omitted from a feed, whereas a few are required.

A feed element also contains one or more entry elements that define individual items from the feed.

An author element must be present unless you define one inside each entry element.

There must be one link element with a rel attribute of alternate (and no more than one). As with any link construct, multiple link elements can be present as long as they have different rel values.

The generator element, which identifies the software that produced the feed, can have two optional attributes: url, a URI that has significance to that software, and version, the software’s version number. Movable Type uses this tag in the following manner:

<generator url=”http://movabletype.org”
version=”<MTVersion>”>Movable
Type</generator>

The modified element follows the rules of timestamp formatting required of any date construct. The Atom specification recommends that the time be expressed as UTC, using a Z character in place of a time zone offset.

The feed’s title, which is set by the title element, should be the same as the Web resource associated with the Atom feed.

Defining Globally Unique Identifiers

An Atom feed’s id element holds a globally unique, never-changing identifier for a feed, which can be used by syndication readers when internally tracking the feeds that they monitor. The element must be a URI.

A useful application of this identifier is to make syndication clients smarter about syndication feeds that change URLs: If a client finds a feed at a new URL with an identifier that it recognizes, the software can stop looking for the feed at the old URL.

In Movable Type templates, an Atom feed’s identifier uses a new naming scheme called the Tag URI that can be adopted for any purpose by anyone who owns or controls an Internet domain name or e-mail address.

This scheme, explained in detail on the Web at http://www.taguri.org, serves as a simple method for devising unique identifiers.

To create one, follow the text “tag:” with the following:

  • The domain or e-mail address you control

  • A comma

  • A date that you controlled the address, in YYYY-MM-DD format (such as 2004-05-24)

  • A semicolon

  • A short name you haven’t already used in an identifier on that date

This scheme can be used on anything that benefits from unique identification. In an article about the Tag URI system, I declared that my globally unique identifier was tag:cadenhead.org,2004-05-17:Rogers. I owned the domain cadenhead.org on May 17, 2004, so no one else would be giving out identifiers based on it with the same date. Although there might be someone else named “Rogers Cadenhead” in the world, no one else will have the Tag URI tag:cadenhead.org,2004-05-17:Rogers.

If you use Movable Type’s default Atom template, you’ll have an id element in the following form:

<id>tag:<MTBlogHost exclude_port=”1” encode_xml=”1”>,
<MTDate format=”%Y”>:<MTBlogRelativeURL encode_xml=”1”>/
<MTBlogID></id>

This produces identifiers of this form:

tag:orlandovacationer.com,2004:///2

The implementation of this feature in Movable Type’s Atom template is incorrect because all three elements of the identifier might change (and the date changes each year). A Tag URI must not change once it has been created.

For this reason, the Atom template in Listing 19-1 defines its own Tag URI without using any Movable Type template tags:

<id>tag:orlandovacationer.com,2004-05-17:weblog</id>

When adapting this for your own weblog, change the domain, date, and identifier based on the specifics of your own site. Make sure that the same identifier is not used on more than one weblog.

There’s no requirement in Atom that an id element must use the Tag URI’s naming scheme. Any arbitrarily imposed system can work, as long as there’s a means to ensure that different publishers don’t use the same identifiers for their feeds or individual entries.

Linking Web Resources Together

Atom feeds establish relationships with other kinds of Internet resources through the use of link constructs. One of these is a feed’s link element, which can be used to associate an entire feed with another resource.

Link constructs define the relationship with three attributes that relate to the other resource: href (its URL), type (its media type), and rel (a short descriptor).

The most common relationship occurs between an Atom feed and the Web site that presents the same information. All Movable Type weblogs begin with a home page and an Atom feed, both of which present the most recent entries from the weblog. This relationship is codified into Atom with the following line in a feed:

<link rel=”alternate” type=”text/html”
href=”http://orlandovacationer.com/”/>

The link element in Atom mirrors the functionality of the link element in HTML and serves the same purpose. In the template code for a weblog’s Main Index template, you can find this element:

<link rel=”alternate”
type=”application/x.atom+xml”
title=”Atom”
href=”http://orlandovacationer.com/atom.xml” />

Both links signify the relationship from the perspective of the document. One tells Web browsers about an Atom feed and the other tells Atom readers about a Web site.

An Atom feed can contain additional link elements that present a sequence of related feeds. A rel value of start identifies the first feed in the sequence, next offers the next, and prev offers a way to go backward.

Putting this into practice, consider a site that has weblog entries numbered from 1 to 60 and Atom feeds that present 15 entries at a time. The main feed for the site could present the 15 most recent entries, which are numbered from 46 to 60. This feed could contain two link elements:

<link rel=”next” type=”application/x.atom+xml”
href=”http://example.com/atom.php?highest=45”><link rel= ”start” type=”application/x.atom+xml”
href=”http://example.com/atom.php?view=start”>

The next link provides a URL that will present 15 more entries from 45 down to 31. The start link URL begins at the first entry.

Table 19-2 summarizes these relationships.

Table 19-2: Atom Link Relationships
Rel | Type | Parent Element | Links To
alternate | application/x.atom+xml | Feed | The Web page represented by the feed
next | application/x.atom+xml | Feed | The feed containing the next entries in a sequence
prev | application/x.atom+xml | Feed | The feed containing the previous entries in a sequence
start | application/x.atom+xml | Feed | The feed containing the first entries in a sequence

Publishing Feed Items

The Atom elements defined up to this point describe aspects of a feed. The feed element also can contain one or more entry elements, items from the list that the feed was intended to represent, such as the latest headlines from a news site or the most recent entries on a weblog.

The order in which entry elements appear in an Atom feed is not significant. Although most syndication feeds are presented in reverse chronological order, you can’t count on this in Atom. There are timestamp elements for each entry that can be used for sorting purposes.

Each entry element can contain one or more child elements, many of which have the same purpose as feed elements with the same name. They’re listed in Table 19-3.

Table 19-3: Atom Entry Elements
Name | Description | Construct Type | Quantity | Required
author | The author of the entry | person | One | No
content | The content of the entry | content | One or more | No
contributor | A contributor to the entry | person | One or more | No
created | The date and time the entry was created | date | One | No
id | A URI that functions as a globally unique identifier for the entry | none | One | No
issued | The date and time the entry was published | date | One | Yes
link | A URI associated with the entry | link | One or more | Varies
modified | The date and time the entry was last edited | date | One | Yes
summary | An excerpt or summary of the entry | content | One | No
title | A short descriptive title for the entry | content | One | Yes

An entry has three timestamp elements that represent stages in its publication: the first time it was stored (issued), the first publication (created), and the most recent revision (modified). All three should be expressed as UTC time, with no time zone offset (if possible). When the created element is not present, its value is assumed to be the same date and time as the issued element.

Entries also have their own id element for a unique identifier. If you’re using a Tag URI for this purpose, you can base it on the feed’s identifier. In a Movable Type template, add a period and the entry’s ID number to the end, as in the following code:

<id>tag:orlandovacationer.com,2004-05-17:weblog.
<MTEntryID></id>

On an entry with the ID number of 72 in the Movable Type database, this produces the following XML:

<id>tag:orlandovacationer.com,2004-05-17:weblog.
72<MTEntryID></id>

If an entry appears in more than one Atom feed, its id element should be the same in every feed.

An entry can contain one or more content elements presenting the content of the entry. Because they are content constructs, type and mode attributes identify the kind of content that each element holds.

Here’s a complete entry produced by the Atom template in Listing 19-1:

<entry>
    <title>Killer whale born at SeaWorld Orlando</title>
    <link rel="alternate" type="text/html"
href="http://orlandovacationer.com/archives/2004/02/
killer_whale.html" />
    <modified>2004-05-18T02:31:58Z</modified>
    <issued>2004-02-11T14:39:51Z</issued>
    <id>tag:orlandovacationer.com,2004-05-17:weblog.79</id>
    <created>2004-02-11T14:39:51Z</created>
    <summary>Kalina, an 18-year-old killer whale at
SeaWorld Orlando, gave birth
to her fourth calf Monday at
the park&apos;s research and breeding facility,Shamu Stadium: Kalina gave birth to the 7-foot-long,
350-pound calf in Shamu
Stadium&apos;s main pool
following a seven-hour...</summary>
    <author>
      <name>rcade</name>
      <url>http://www.cadenhead.org/workbench/</url>
      <email>rcade@example.com</email>
    </author>
    <content type="text/html" mode="escaped" xml:lang="en"
xml:base="http://orlandovacationer.com/">
      <![CDATA[<p>Kalina, an 18-year-old killer whale at
SeaWorld Orlando, gave
birth to her fourth calf Monday
at the park’s research and breeding facility, Shamu
Stadium.</p>]]>
    </content>
  </entry>

An entry can contain more than one content element that presents the information under a different media type.

The content should be structured as a parent content element with type=”multipart/alternative” and no mode that holds several child content elements with their own type and mode, as in this example:

<content type=”multipart/alternative”>
   <content type=”text/html” mode=”escaped” xml:lang=”en”
xml:base=”http://orlandovacationer.com/”>
      <![CDATA[<p>Kalina, an 18-year-old killer whale at
SeaWorld Orlando, gave
birth to her fourth calf Monday
at the park’s research and breeding facility, ShamuStadium.</p>]]>
   </content>
   <content type=”application/xhtml+xml” mode=”xml”
xml:lang=”en”
xml:base=”http://orlandovacationer.com/”>
      <p>Kalina, an 18-year-old killer whale at SeaWorld
Orlando, gave
birth to her fourth calf Monday at
the park’s research and breeding facility, ShamuStadium.</p>
   </content>
</content>

Client software reading the feed could choose the format best suited for its audience.


Editing a Weblog with the Atom API

The Atom syndication format was developed alongside an Application Programming Interface (API) for publishing weblogs and other Web content.

Web Site Download

The draft specification for this interface can be found on the Web at http://www.atomenabled.org/developers/api. The current version at the time of this writing is Revision 9.

The Atom API serves the same purpose as the APIs described in Chapter 15, “Connecting to Movable Type with XML-RPC,” but they use a different technique for sending and receiving information.

Using the API, an Atom client communicates with a Web server script over HTTP, the protocol of the World Wide Web. Special URLs call the script using the same four commands that can be used by a browser:

  • delete removes content from the server

  • get reads content from the server

  • post publishes new content on the server

  • put updates existing content on the server

Using the commands, a new weblog entry can be published for the first time with post, revised to fix a typo with put, read with get, and removed with delete.

An Atom-equipped server makes three URLs available for these commands, each of which is identified with a link element in Web pages and Atom syndication feeds. These addresses are called the EditURI, FeedURI, and PostURI.

These URLs can be discovered by examining Web pages and Atom feeds for link elements with rel attributes that begin with the identifier “service.” such as “service.edit”, “service.feed”, and “service.post”.

In a Web document, the elements are found within the head element of the file. Within an Atom feed, they are found in the top-level feed element.

The FeedURI accepts get commands and is identified in an Atom feed or Web page with the following link element:

<link rel="service.feed" type="application/x.atom+xml"
href="feedAddress" title="siteName" />

PostURI handles post commands and can be found with this link element:

<link rel="service.post" type="application/x.atom+xml"
href="postAddress" title="siteName" />

The EditURI takes delete, get, and put commands through the “service.edit” element:

<link rel="service.edit" type="application/x.atom+xml"
href="editAddress" title="siteName" />

In Movable Type, a new script introduced in version 3 functions as an Atom server: mt-atom.cgi. The address of this script can be used for all three Atom URIs and plugged into templates with the MTCGIPath tag, as in this example:

<link rel="service.feed" type="application/x.atom+xml"href= "<MTCGIPath>mt-atom.cgi" title="<MTBlogName>" />

All information is exchanged over the Atom API using either an entire Atom feed or an individual Atom entry element. These elements follow different rules than in a syndication feed, as described in Table 19-4.

Table 19-4: Atom API Rules
Element | EditURI Rule | FeedURI Rule | PostURI Rule
author | No rule | No rule | No rule
content | No rule | No rule | No rule
contributor | No rule | No rule | No rule
created | No rule | No rule | No rule
generator | Must not be present | Must not be present | Must be present
id | Must be present | Must be present | Must not be present
issued | Must be present | Must be present | Must be present
link | Must be present | Must be present | No rule
modified | No rule | No rule | Must not be present
summary | No rule | No rule | No rule
title | Must be present | Must be present | Must be present

Atom server commands use HTTP requests, which are structured as a set of headers followed by the body of the request. The server receives Atom data in the body of a request and sends it back in response, so all data exchanged over the commands of the Atom API represents valid Atom syndication data.

A FeedURI is called using a get command with an empty body. The server responds with an Atom feed representing the requested entries. The feed holds more information than a normal syndication feed, such as link elements for the server’s EditURI and PostURI and entry link elements identifying the EditURI to use when editing the entry.

An EditURI can be called with a get command and an empty body to return an entry element containing the requested entry. After the entry has been edited in some manner, it can be resubmitted to the server using a put command with the entry as the body of the request. The entry can be removed using a delete command with no body.

The PostURI can be called with the post command and the body of an entry, publishing it on the server as a new entry.


Summary

One of the earliest groups to lend its support to the Atom syndication format and API was Six Apart, the developer of Movable Type.

This decision might seem like a curious one, because Movable Type’s browser interface rates among its most highly regarded features. Weblogs can be created and edited entirely within the browser.

Atom makes it possible to do most of this work outside of the browser. An Atom client program such as a weblog editor can use the HTTP commands specified in the API to publish new entries, retrieve existing entries so that changes can be made, and delete them.

Atom also enables a weblog to be read outside of a browser. A syndication reader makes regular checks of Atom feeds—and often RSS 1.0 and RSS 2.0 feeds as well—presenting new items for quick perusal.

The Atom project’s work has yet to be submitted to a standards body and is likely to undergo changes from the early drafts of the syndication format and API.

Because Six Apart and other developers of weblogging tools already offer extensive Atom support, the project has begun to find a significant audience on the Web.


Chapter 20: Developing New Plug-Inswith Perl

In This Chapter

  • Creating a new plug-in script with Perl

  • Writing object-oriented Perl scripts

  • Using existing Perl classes

  • Creating new template tags

  • Handling tag attributes

  • Developing container and conditional tags

  • Filtering tag output with a plug-in

  • Sending an error message

Although Movable Type ranks among the most popular weblog publishing tools, the program offers content-management capabilities that extend far beyond the presentation of weblog entries, articles, and photographs.

Movable Type can be used as a platform upon which new kinds of information can be published, keeping pace with the Web’s amazing knack for introducing innovative ways for people around the world to communicate with each other.

The software’s flexibility comes from an extensive, robust, and open framework for developing plug-ins.

Plug-ins, which are implemented as Perl scripts and modules, hook directly into the software’s template-rendering capabilities, enabling you to make changes and add elements that affect the output.

Movable Type plug-ins are implemented as template tags identical in appearance and function to the tags included as a built-in element of the software.

You can write your own output-producing tags as well as container and conditional tags. There’s also a special kind of plug-in called a global filter that provides a means of adding your own tag attributes, intercepting and modifying tag output as a template is being rebuilt.

By coding your own plug-ins, you can seamlessly extend the functionality of Movable Type and enhance the Web sites that you produce with the software.


Designing Your First Plug-In

A Movable Type plug-in should be a Perl script written using the language’s support for object-oriented programming. Using Perl modules and Movable Type’s own collection of classes, you can achieve sophisticated effects in your plug-ins with a small amount of code.

The MT::Template::Context class serves as the entry point into Movable Type’s plug-in framework, providing the behavior necessary to add new tags to the software and the methods called when they are found in a template.

You make this class (and any others you need) available in the script with use statements:

use MT::Template::Context;

Next, you register the simple tags that the plug-in supports by calling methods taking this form:

MT::Template::Context->add_tag(name, \&subroutine);

The first argument names the tag. Movable Type prefixes the name with MT, so calling the method with the name RandomWebLink registers a tag named MTRandomWebLink.

The second argument identifies the method to call when the tag appears in a template. The string returned by the method will appear in files rendered from the template.

The following statement associates the MTRandomWebLink tag with a method called get_random_link:

MT::Template::Context->add_tag(RandomWebLink => \&get_random_link);

A template tag supported by a plug-in is indistinguishable from a built-in tag. You can add both simple tags and containers with all of the features offered by their Six Apart–created counterparts.

Listing 20-1 contains randomweblink.pl, a simple plug-in script that displays a randomly selected Web address. Save the script in Movable Type’s plugins directory to add a new template tag, MTRandomWebLink, which you can use in the following manner:

Go <a href=”<MTRandomWebLink>”>someplace else</a>

The tag is replaced with a random link, as shown in the following sample output:

Go <a href="http://www.eod.com/">someplace else</a>

This plug-in requires LWP::UserAgent, one of the Perl modules that’s employed by Movable Type. You can run the System Check script mt-check.cgi to determine whether this particular module has been installed on your server.

Cross-Reference

Can’t find it? Return to Chapter 2, “Preparing a Web Server for Movable Type,” for information on how to download and install LWP::UserAgent and other Perl modules.

No special configuration is necessary to use the plug-in’s spiffy new tag. Simply save randomweblink.pl in the plugins directory, and then pretend that the tag has always been a part of Movable Type and plunk it down in a template.

Listing 20-1: Linking to a Random Web Page
Start example
# declare a class name
package MT::Plugin::RandomWebLink;

# make classes available in this script
use MT::Template::Context;
use LWP::UserAgent;

# register tags
MT::Template::Context->add_tag(RandomWebLink => \&get_random_link);

# produce output for the MTRandomWebLink tag
sub get_random_link {
    $ua = LWP::UserAgent->new;
    my $request = HTTP::Request->new(GET => ‘http://www.uroulette.com/visit.php’);
    my $response = $ua->simple_request($request);
    my $location = $response->header(‘Location’);
    return $location;
}
1;
End example

The first line of the script uses a package statement to declare that it belongs to the namespace MT::Plugin::RandomWebLink. Although this isn’t required, it minimizes the possibility of a namespace collision with other plug-ins.

The get_random_link method carries the workload of the randomweblink.pl plug-in, grabbing a random link from the URouLette Web site.

A template tag’s method must return a string representing the output that will be rendered in place of the tag (or an empty string if nothing should be displayed). In this script, get_random_link returns a URL culled from URouLette.

There’s no limit to what you can undertake in a tag’s method, but it ought to be something that can be accomplished quickly, because a time-consuming plug-in tag can slow down the rebuilding process for an entire weblog to a crawl.

This method makes use of three objects: the Web client LWP::UserAgent, and two objects that represent a Web request and response—HTTP::Request and HTTP::Response.

If you visit the URL http://www.uroulette.com/visit.php with a Web browser, you’ll be taken automatically to a randomly selected Web page from the URouLette database. This occurs because the page returns a Location header that tells the browser to redirect from URouLette to another URL, as shown in this example:

Location: http://www.eod.com/

This plug-in requests the URL with LWP::UserAgent, storing the response in an HTTP::Response object. The object’s header(‘Location’) method returns the desired header as a string, which is subsequently returned by the method.

Any plug-in that implements a simple template tag with no attributes can reuse the bulk of Listing 20-1.

Web Site Download

You can visit the URouLette Web site, published by the author of this book, at http://www.uroulette.com. The site presents links chosen at random from the Open Directory Project Web directory, giving preference to sites that have received at least one “cool” rating from project editors.


Handling Tag Attributes

The random link project demonstrates the basics of Movable Type’s plug-in framework but does little to take advantage of its capabilities. A well-designed plug-in should interact with the software and be configurable by the user.

Users working with simple tags offered by plug-ins can use tag attributes to customize their performance.

When plug-in tag methods are called, the @_ array holds two references that can be retrieved with the shift command:

  • The MT::Template::Context object representing the current state of the template

  • A hash that contains a name-value pair for all of the tag’s attributes

These references can be stored in variables with the following two statements:

my $ctx = shift;
my $args = shift;

The next project, detailed in Listing 20-2, rewrites an example from another chapter. Chapter 16, “Enhancing Movable Type with Plug-Ins,” used Brad Choate’s MTPerlScript plug-in to execute a Perl script that displayed a stock quote from Yahoo! Finance. This plug-in script accomplishes the same feat with a custom plug-in.

Store the contents of Listing 20-2 in yahooquote.pl, saving it in the software’s plugins directory.

Listing 20-2: Displaying Stock Quotes from Yahoo!
Start example
package MT::Plugin::YahooQuote;

use MT::Template::Context;
use LWP::UserAgent;

MT::Template::Context->add_tag(YahooQuote => \&get_quote);

sub get_quote {
    # collect stock data from Yahoo Finance
    my $ctx = shift;
    my $args = shift;
    $host = "http://finance.yahoo.com";
    $ticker = defined($args->{symbol})?$args->{symbol}:’YHOO’;
    $path = "/d/quotes.csv?s=$ticker&f=sl1d1t1c1ohgv&e=.csv";
    $ua = LWP::UserAgent->new;
    $request = HTTP::Request->new(‘GET’, $host . $path);
    $response = $ua->request($request);

    # process data, stripping quote marks
    if ($response->is_success) {
        @stock_data = split(/,/, $response->content);
        ($symbol, $price, $s_date, $s_time, $change, $open, $high,
$low, $volume) = @stock_data;
        $symbol =~ s/\"//g;
        $s_date =~ s/\"//g;
        $s_time =~ s/\"//g;

        # display data
        return "<p><b>" . $symbol . "</b>: " . $price . " (" . $change . ") " . "at " . $s_date . " " . $s_time . "</p>";
    }
}
1;
End example

This script implements a MTYahooQuote plug-in tag that presents stock quote information for any publicly traded company covered by Yahoo! Finance. The ticker symbol for the security should be specified with a symbol attribute, as in this example:

<div align=”center”>
  <p>Red Hat Check</p>
  <p><MTYahooQuote symbol=”RHAT”></p>
</div>

When the tag has been rendered in a rebuild, the plug-in produces the current price, change, date, and time as output. Here’s the result for the preceding template code example:

<div align=”center”>
    <p>Red Hat Check</p>
    <p><b>RHAT</b>: 16.15 (+1.25)  at 7/21/2004 4:00pm</p>
</div>

The LWP::UserAgent and MT::Template::Context classes are required by the script.

This custom plug-in offers a better solution than the MTPerlScript plug-in described in Chapter 16 because it controls the user interaction through a Perl script that cannot be viewed or edited by weblog authors.

The MTPerlScript plug-in places Perl programming directly in the hands of anyone who can edit a template on any of your weblogs. As you might expect, that’s a lot more power than most Movable Type users would be comfortable resting in the hands of their authors.

Using a custom plug-in also makes it much simpler for a nontechnical site author to display stock quotes. All that’s necessary is the skill to place a tag in a template and define an attribute, talents that are well within the comfort zone of any Web designer who can author pages using HTML markup.

Movable Type plug-ins can include their own Perl classes, which should be stored in a subdirectory of the software’s extlib directory. The use statement can be used in the plug-in script to make these classes available.


Creating a Container Tag

Although the MTYahooQuote plug-in adds some useful functionality to Movable Type, the script assumes that weblog authors will always be presenting stock quote information in exactly the same way: a ticker symbol in boldface followed by a price, price change, and timestamp:

<b>RHAT</b>: 22.09 (+0.09)  at 6/24/2004 4:00pm

This omits information offered by Yahoo! Finance and provides no flexibility in the presentation of the quote data.

You can provide a much more capable plug-in by offering a container tag that represents one company’s quote data and a set of subsidiary template tags for each data field. Listing 20-3 rewrites the script to provide this functionality, implementing an MTStockQuote container and nine tags for fields in the quote data, including MTStockQuotePrice, MTStockQuoteHigh, and MTStockQuoteLow.

Save this script as stockquote.pl in Movable Type’s plugins directory.

Listing 20-3: Displaying Customized Stock Quotes
Start example
package MT::Plugin::StockQuote;

use MT::Template::Context;
use LWP::UserAgent;

# register container tag and eight simple tags
MT::Template::Context->add_container_tag(StockQuote => \&get_quote);
MT::Template::Context->add_tag(StockQuoteSymbol => \&get_symbol);
MT::Template::Context->add_tag(StockQuotePrice => \&get_price);
MT::Template::Context->add_tag(StockQuoteDate => \&get_date);
MT::Template::Context->add_tag(StockQuoteTime => \&get_time);
MT::Template::Context->add_tag(StockQuoteChange => \&get_change);
MT::Template::Context->add_tag(StockQuoteOpen => \&get_open);
MT::Template::Context->add_tag(StockQuoteHigh => \&get_high);
MT::Template::Context->add_tag(StockQuoteLow => \&get_low);
MT::Template::Context->add_tag(StockQuoteVolume => \&get_volume);

sub get_quote {
    # collect stock data from Yahoo Finance
    my $ctx = shift;
    my $args = shift;
    my $output = ‘’;
    my $builder = $ctx->stash(‘builder’);
    my $tokens = $ctx->stash(‘tokens’);
    $host = "http://finance.yahoo.com";
    $ticker = defined($args->{symbol})?$args->{symbol}:’YHOO’;
    $path = "/d/quotes.csv?s=$ticker&f=sl1d1t1c1ohgv&e=.csv";
    $ua = LWP::UserAgent->new;
    $request = HTTP::Request->new(‘GET’, $host . $path);
    $response = $ua->request($request);

    # process data, stripping quote marks
    if ($response->is_success) {
        @stock_data = split(/,/, $response->content);
        ($symbol, $price, $s_date, $s_time, $change, $open, $high,
$low, $volume) = @stock_data;
        $symbol =~ s/\"//g;
        $s_date =~ s/\"//g;
        $s_time =~ s/\"//g;
        # store data in the stash
        $ctx->stash(‘symbol’, $symbol);
        $ctx->stash(‘price’, $price);
        $ctx->stash(‘date’, $s_date);
        $ctx->stash(‘time’, $s_time);
        $ctx->stash(‘change’, $change);
        $ctx->stash(‘open’, $open);
        $ctx->stash(‘high’, $high);
        $ctx->stash(‘low’, $low);
        $ctx->stash(‘volume’, $volume);
        # pass processing back to template builder
        my $out = $builder->build($ctx, $tokens);
        $output .= $out;
    }
    return $output;
}

sub get_symbol {
    my $ctx = shift;
    return $ctx->stash(‘symbol’);
}

sub get_price {
    my $ctx = shift;
    return $ctx->stash(‘price’);
}

sub get_date {
    my $ctx = shift;
    return $ctx->stash(‘date’);
}

sub get_time {
    my $ctx = shift;
    return $ctx->stash(‘time’);
}

sub get_change {
    my $ctx = shift;
    return $ctx->stash(‘change’);
}

sub get_open {
    my $ctx = shift;
    return $ctx->stash(‘open’);
}

sub get_high {
    my $ctx = shift;
    return $ctx->stash(‘high’);
}

sub get_low {
    my $ctx = shift;
    return $ctx->stash(‘low’);
}

sub get_volume {
    my $ctx = shift;
    return $ctx->stash(‘volume’);
}
1;
End example

Container tags in Movable Type serve as subtemplates, using their opening and closing tags to enclose template tags and static text such as HTML markup.

The add_container_tag() method of the MT::Template::Context class registers the container:

MT::Template::Context->add_container_tag(StockQuote => \&get_quote);

Plug-in scripts insert themselves into the middle of the site rebuild process, retrieving a hash that holds information about a template, making changes to it and adding new information, and then indicating that Movable Type can pick up where it left off.

The information maintained by Movable Type is held in a stash, a data structure that will be manipulated throughout the template rebuilding process.

Two methods of the MT::Template::Context class retrieve and set stash values. Call stash() with a key to retrieve the object associated with the key. The following statement retrieves the object associated with the builder key:

my $builder = $ctx->stash(‘builder’);

Call stash() with a value as a second argument to store that value in the stash, associating it with the specified key. This statement stores the contents of the $symbol variable in the stash with the symbol key:

$ctx->stash(‘symbol’, $symbol);

Two objects in the stash help a script make sense of the template in which its tags have been placed: an MT::Builder object that builds an output page from a template and an array of tokens that represent the page.

The stockquote.pl script retrieves nine stock quote data fields for a user-designated ticker symbol, storing them in the stash.

When that’s done, template processing is handed back to the MT::Builder object with a call to its build() method in the following statement:

my $out = $builder->build($ctx, $tokens);

The index template in Listing 20-4 displays all of these tags in a table-based HTML layout.

Listing 20-4: A Stock Quote Web Page Template
Start example
<html>
<head>
  <title>Disney Stock</title>
</head>
<body>
<h1>Disney Stock</h1>
<p>
<MTStockQuote symbol="DIS">
<table border="0" cellpadding="5">
<tr valign="top">
<td>Symbol</td>
<td>Price</td>
<td>Date</td>
<td>Time</td>
<td>Change</td>
<td>Open</td>
<td>High</td>
<td>Low</td>
<td>Volume</td>
</tr>
<tr valign="top">
<td><MTStockQuoteSymbol></td>
<td><MTStockQuotePrice></td>
<td><MTStockQuoteDate></td>
<td><MTStockQuoteTime></td>
<td><MTStockQuoteChange></td>
<td><MTStockQuoteOpen></td>
<td><MTStockQuoteHigh></td>
<td><MTStockQuoteLow></td>
<td><MTStockQuoteVolume></td>
</tr>
</table>
</MTStockQuote>
</body>
</html>
End example

Figure 20-1 contains a Web page produced from this template.

Click To expand
Figure 20-1: Presenting stock quotes with plug-in tags.


Working with Other Template Tags

The stash, a data structure made available to Movable Type plug-ins through the MT::Template::Context object’s stash() methods, contains several values that provide details about the context in which a script tag has been placed.

In programming terms, context refers to the environment in which an object finds itself. The context for a template tag can encompass several levels: the container that encloses the tag, any container that encloses that tag, and so on up to the template itself.

Table 20-1 lists the keys that can be retrieved from the stash and the objects that they represent.

Table 20-1: Useful Stash Objects and Values
Key | Type or Class | Value
Blog | MT::Blog | The weblog
blog_id | integer | The weblog’s ID number
Category | MT::Placement | An object
Comment | MT::Comment | The current comment
Entries | MT::Entry array | All weblog entries in a container, such as MTEntries
Entry | MT::Entry | The current weblog entry
Ping | MT::Ping | The current trackback ping
Tag | string | The name of the current template tag
Uncompiled | string | The template before any processing has been applied to it

Movable Type has been developed using Perl’s support for object-oriented programming. If you look in the software’s lib/MT directory, you’ll find more than 50 classes that deliver its functionality, much of which you can use in your own plug-in scripts.

The source code of these scripts can be viewed (and even modified), although Six Apart does not license the source code for redistribution in any manner. There’s also extensive documentation for these classes within the class files themselves.

Web Site Download

The most useful Movable Type Perl classes have documentation on the Web at http://www.movabletype.org/docs/mtapi_index.html.

You also can learn from the code in plug-in scripts and accompanying Perl modules offered by other Movable Type users.


Enhancing Plug-In Scripts

By making use of Movable Type’s Perl classes and the many modules available for the language, you can create powerful plug-in scripts with remarkably small programs.

The requirement to use Perl will be a challenge for programmers who are unfamiliar with the language, but you can benefit from literally thousands of Perl scripts offered by programmers on the Web.

The next several sections detail some additional techniques to enhance your plug-in scripts.

Reporting Errors in Tag Usage

Many template tags must be used in a specific situation or they will not function correctly, such as entry tags that can appear only within an MTEntries container or on an individual archive page.

When a tag has not been used correctly, plug-in scripts can notify Movable Type by calling the error() method of the script’s MT::Template::Context object, as in the following example:

$ctx->error(“error using tag”);

The error brings the rebuilding process to a halt, displaying an error message in the pop-up window describing its progress (see Figure 20-2).

Click To expand
Figure 20-2: Stopping a template rebuild with an error.

Earlier in this chapter, the stock quote plug-in used a symbol attribute to select a stock, looking up “YHOO” if this attribute was not specified in the MTStockQuote tag.

The following statement handles that circumstance differently, halting with an error if no symbol attribute can be found in the $args array holding method arguments:

$ticker = $args->{symbol} or return $ctx->error(
    “a symbol attribute is required”);

The error message is preceded by the template name and tag associated with the error, as in Figure 20-2.

Creating a Global Filter Plug-In

Movable Type supports global tag attributes that apply to all simple template tags that produce output. Many of these are used to encode or decode text for presentation as HTML, XML, and other formats.

You can create your own global filter as a plug-in, making it available to all template tags as an attribute.

Your filter plug-in will be processed right before the tag’s output is processed, providing an opportunity to make some kind of change to the text.

The MT::Template::Context class supports global filters with the add_global_filter() method, which takes an attribute name and subroutine as arguments, as in the following statement:

MT::Template::Context->add_global_filter(remove_asp => \&remove_asp);

This statement adds a remove_asp attribute that can be added to any non-container template tag, as in this HTML markup:

<p><MTEntryBody remove_asp=”1”>

Three values are passed to the filter’s method: the output text to filter, the attribute value, and the context. The method returns the output after modification.

Simple to develop, global filters can provide some much-desired functionality for Movable Type. Listing 20-5 contains remove_excessive_links, a filter that counts the number of hyperlinks in tag output, stripping the links if they exceed a specified maximum.

The tag’s purpose: preventing link spammers from taking advantage of your weblog’s comments feature.

Listing 20-5: Filtering Excessive Links
Start example
# declare a class name
package MT::Plugin::RemoveExcessiveLinks;

# make classes available to this script
use MT::Template::Context;
use MT::Blog;
use MT::Sanitize;

# register a global filter
MT::Template::Context->add_global_filter(
    remove_excessive_links => \&remove);

# define the remove_excessive_links filter method
sub remove {
    my $text = shift;
    my $att_value = shift;
    my $ctx = shift;
    my $blog = $ctx->stash(‘blog’);
    my $good_html = $blog->sanitize_spec ||
       "b,br,p,strong,em,ul,li,blockquote";
    $good_html =~ s/a href,//i;
    my $count = 0;
    $count++ while $text =~ /a href/gi;
    if ($count >= $att_value) {
        $text = MT::Sanitize->sanitize($text, $good_html);
    }
    return $text;
}
1;
End example

The remove_excessive_links attribute can be used with any simple template tag, but it makes the most sense to associate it with MTCommentBody, the comment tag that presents the text of a visitor-submitted comment. The attribute value should be the number of links to trigger the filter—to prevent a user from posting more than four links in a comment, for instance, use this tag:

<MTCommentBody remove_excessive_links=”4”>

When the script encounters tag text that reaches or exceeds the maximum count, it uses Movable Type’s HTML sanitize feature to strip out all hyperlinks from the text.

In order to use sanitize, the script first determines whether the weblog has its own sanitize_spec configuration setting, which holds a comma-separated list of HTML tags and attributes that are permitted in comments:

my $blog = $ctx->stash(‘blog’);
my $good_html = $blog->sanitize_spec ||
    “b,br,p,strong,em,ul,li,blockquote”;
$good_html =~ s/a href,//i;

The default list of acceptable tags in Movable Type is a href, b, br, p, strong, em, ul, li, and blockquote. The HTML sanitizer removes all tags and attributes that aren’t in that list.

The excessive links filter adopts the weblog’s custom sanitize_spec list or the default, removing a href if it appears in the list so that hyperlinks will be removed.

A call to the sanitize() method of the MT::Sanitize object removes all links from the text:

MT::Sanitize->sanitize($text, $good_html);

The arguments to the method are the tag output and the list of acceptable tags.

This filter deters slimy Internet marketers who post fake comments in Movable Type weblogs to sites they are touting, an abuse that has become commonplace. Often, they’ll use software to post text that includes links to a dozen products or sites, hoping that it will improve their ranking in Google and other search engines.

By removing all links from comments that contain a suspicious number of hyperlinks, you can reduce their perceived benefit from this activity.

Creating a Conditional Tag

Some Movable Type container tags display their contents when a condition has been met and ignore them otherwise. These conditional tags, as they are called, can be implemented as plug-ins with the add_conditional_tag() method of the MT::Template::Context class.

The method takes the same form as the other tag addition methods: a tag name (minus the starting MT) followed by a subroutine reference, as in this example:

MT::Template::Context->add_conditional_tag(IfMonday => \&monday_show);

The method that implements the tag works for the most part like any other container tag’s method. You can receive the script’s context and attributes and make use of the stash.

The one area in which it strays is in the method’s return value. A conditional tag method should return a Boolean value: 1 if the condition has been met and 0 otherwise.

When a conditional tag returns 1, its contents are processed further and can be displayed. When the tag returns 0, all of its contents are ignored.

Listing 20-6 demonstrates the creation of two conditional tags, IfBusinessDay and IfNotBusinessDay, which check whether the current day falls within the normal work week (Monday through Friday).

Listing 20-6: Displaying Output on Business Days
Start example
# declare a class name
package MT::Plugin::BusinessDay;

# make classes available to this script
use MT::Template::Context;

# register a global filter
MT::Template::Context->add_conditional_tag(
    IfBusinessDay => \&check_day);
MT::Template::Context->add_conditional_tag(
    IfNotBusinessDay => \&check_day);

# define the tag method
sub check_day {
    my $ctx = shift;
    my $args = shift;
    my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday,
        $isdst) = localtime(time);
    my $tag = $ctx->stash(‘tag’);
    my $not_flag = $tag =~ m/Not/;
    my $biz_day = 0;
    if (($wday == 0) || ($wday == 6)) {
        $biz_day = 1;
    }
    return ($not_flag) ? $biz_day : !$biz_day;
}
1;
End example

This script demonstrates a new technique for plug-in programming—sharing the same method for more than one tag. This can be done by checking the name of the current tag, which has been stored by Movable Type’s template builder object in the stash with a key of tag.

The script looks at the tag and determines whether it contains the word not in the following two statements:

my $tag = $ctx->stash(‘tag’);
my $not_flag = $tag =~ m/Not/;

The call to the Perl function localtime(time) returns a nine-element list representing the current time. The seventh element of the list, the day of the week, numbers from 0 on Sunday to 6 on Saturday.


Summary

Movable Type’s plug-in framework has inspired the development of more than 100 scripts by developers, as you can discover by visiting the MT Plug-in Directory Web site at http://mt-plugins.org.

Plug-ins integrate seamlessly into Movable Type, delivering their functionality as new template tags and tag attributes.

The framework achieves a division of work responsibilities between Web designers and programmers that promotes collaboration.

A programmer can extend the capabilities of Movable Type by developing a Perl script that registers a new tag or tag attribute and implements the code necessary to handle the tag when the software turns templates into output files.

Web designers receive these tags and tag attributes, working with them exactly as they would with the hundreds of template tags that are included as a built-in part of the software.

As you’ll discover in Chapter 21, Movable Type 3.0 extends plug-ins into the software’s browser-based interface, making it possible to collect new kinds of information to be presented on your Web sites.


Chapter 21: Hooking into Movable Typewith Plug-Ins

In This Chapter

  • Adding plug-ins with the browser interface

  • Linking scripts to editing forms

  • Writing a Web application

  • Using the software’s Perl classes

  • Receiving CGI parameters

  • Working with Perl modules

  • Reading author information in a script

  • Working with weblog configuration settings

  • Reading and writing weblog entries

  • Creating your own plug-ins

  • Enhancing Movable Type

In July 2004, Six Apart awarded $20,000 in prizes to six developers who created plug-ins for Movable Type 3.0.

Jay Allen, the creator of the MT-Blacklist plug-in, turned a well-crafted tool to fight comment and trackback abuse into a grand prize that inspires considerable geek envy: an Apple G5 system with dual 2GHz, a 23-inch Apple Cinema HD Display, and Adobe Creative Suite Premium with GoLive CS. Retail value: $7,000.

Web Site Download

You can find out about Jay’s work on MT-Blacklist and many other Movable Type enhancements by visiting his weblog at http://www.jayallen.org.

Second place went to Andrew Sutherland’s KoalaRainbow, a tool for turning the software into a graphical visualization lab, publishing information visually using highly configurable template tags.

Web Site Download

Andrew Sutherland describes the product on his Only the Wind weblog at http://www.onlythe wind.org/mt, offering graphical examples that do it much better justice.

Movable Type has attracted excellent coders such as Allen and Sutherland because of the software’s extensible object-oriented design.

Although the software functions primarily as a weblog publishing tool, Movable Type has been designed as an open framework for gathering and publishing Web content of much wider scope.

In addition to the plug-in tags covered in Chapter 20, you can create Perl classes that integrate with the software in many other ways.

In this final chapter of the book, you’ll learn how to turn the software you’ve come to know so well over the past 20 chapters into a program that does so many new things that it’s practically unrecognizable.


Managing Plug-Ins with a Browser

Movable Type 3.0 adds support for plug-in management to the software’s browser-based interface. Prior versions of the software did not provide any information, within the browser, about which plug-ins are installed on a server or how they can be configured.

The MT::Plugin class represents the information required for the software to recognize plug-in scripts. A plug-in must register with Movable Type to indicate its presence. Although plug-ins will continue to work correctly without being manageable in this manner, registering a plug-in makes things easier for the script’s users.

An MT::Plugin object carries the script’s name and description along with hyperlinks to its home page and a configuration page (when one is available). In a plug-in, you create the object and call its methods to set the following pieces of information:

$plugin = new MT::Plugin();
$plugin->name(“Site Map”);
$plugin->description(“Presents links to all pages of a weblog”);
$plugin->doc_link(“http://example.com/sitemap/”);
$plugin->config_link(“config_sitemap.pl”);

After the MT::Plugin object has been created and its values have been established, a method of the MT class can be used to inform Movable Type about the script:

MT->add_plugin($plugin);

Registered plug-ins appear in the software’s Main Menu page in a new Configure Active Plugins section. Figure 21-1 shows how plug-ins are presented on this part of the software’s browser interface.

Click To expand
Figure 21-1: Managing plug-ins with a Web browser.


Adding Plug-In Action Links to the Interface

Another new feature of Movable Type 3.0 enables Perl scripts to be called from editing pages in the software’s browser interface. These action links, as they have been dubbed, can appear at the bottom of editing forms for authors, categories, comments, and templates.

You can view a script link added with this technique at the bottom of a comment editing page in Figure 21-2.

Click To expand
Figure 21-2: Calling scripts from an editing page in the browser.

The script called from an action link will be executed using a GET request over the Common Gateway Interface (CGI). In this respect, it’s more like the scripts that power Movable Type (such as mt.cgi and mt-check.cgi) than a plug-in that adds a tag, filters text, or serves a similar purpose.

However, you must implement a plug-in to cause the action link to appear on the desired page.

To make the link appear, the add_plugin_action() method of the MT class is called with three arguments:

  1. The page on which to place the link, identified by a key

  2. The script to call, which can be in the plugins directory or a subdirectory

  3. The text of the link

The key can be one of the following values for editing pages: author, category, comment, entry, or template.

Action links also can be added to pages that list weblog elements for editing: list_commenters, list_comments, and list_entries.

Listing 21-1 contains CheckSamSpade.pl, a plug-in script that adds the Check IP with Sam Spade link to comment editing pages. When you store it in Movable Type’s plugins directory, the link appears immediately on all comment editing pages like the one shown earlier in Figure 21-2.

Listing 21-1: Adding a Plug-In Action
Start example
# declare a class name
package MT::Plugin::CheckSamSpade;

# register classes
use MT;

# register plug-in action
MT->add_plugin_action(‘comment’, ‘check_sam_spade.cgi’,
    ‘Check IP with Sam Spade’);
End example

Plug-in action links are called with several parameters.

The from parameter indicates the originating page, such as edit_comment for the comment editing form and edit_category for the category editor.

The id parameter contains the ID number of the weblog element being edited (author, category, comment, entry, or template), which can be used to retrieve it from the Movable Type database.

Listing 21-2 contains check-sam-spade.cgi, a Perl script that redirects visitors to a Sam Spade page reporting information about the IP address.

Listing 21-2: Redirecting Visitors to Another URL
Start example
#!/usr/bin/perl -w

# set the script’s version number
use vars qw( $VERSION );
$VERSION = ‘1.0’;

# add the MT directory to @INC for this script
my($MT_DIR);
BEGIN {
   if ($0 =~ m!(.*[/\\])!) {
       $MT_DIR = $1;
   } else {
       $MT_DIR = ‘./’;
   }
   unshift @INC, $MT_DIR . ‘lib’;
   unshift @INC, $MT_DIR . ‘extlib’;
}

# make classes available
use CGI;
use MT;
use MT::Comment;

my $mt = MT->new(Config => $MT_DIR . ‘mt.cfg’,
    Directory => $MT_DIR) || die MT->errstr;

# retrieve the CGI parameter id (the comment ID)
my $query = new CGI;
my $comment_id = $query->param(‘id’);

# load Sam Spade page
my $comment = MT::Comment->load($comment_id);
my $url = "http://www.samspade.org/t/lookat?a=" . $comment->ip;
print "Location: $url\n\n";
exit;
End example

Although CGI scripts that redirect URLs can be written in a large number of programming languages, the advantage to sticking to Perl for action-related scripts is the capability to make use of Movable Type’s classes.

The check-sam-spade.cgi script employs the MT::Comment class to load the comment associated with an ID number passed to the script as a parameter.

The BEGIN block in the script ensures that Movable Type’s CGI path can be found by the script. This wouldn’t be necessary if the program didn’t need any of the software’s classes.


Programming with Movable Type Classes

With version 3.0 of the software, Movable Type has accumulated a sizeable library of Perl classes that can be employed in your own plug-in scripts, text filters, and CGI Web applications.

Each of these classes contains its own documentation, which you can view by typing the perldoc command followed by a classname, like so:

# perldoc MT::Comment

The documentation for the class is displayed in a text-based interface (see Figure 21-3).

Click To expand
Figure 21-3: Reading Movable Type’s Perl class documentation.

Perldoc pauses when the window fills up with a screen of text, displaying a “:” command prompt at the lower-left corner of the window, as identified in Figure 21-3. When the end of the documentation has been reached, an (END) prompt is shown.

Use the following keys to browse documentation with the Perldoc tool:

  • Press the spacebar or Page Down key to continue to the next screen.

  • Press the Page Up key to move upwards.

  • Press the q key to quit reading.

The Movable Type library has 24 classes led by MT, a top-level class that rebuilds weblogs and transmits ping messages.

MT::App serves as the base class for all Web applications that take advantage of the Movable Type framework. These programs can be executed as CGI scripts or run under Apache::Registry and mod_perl. Applications should be created as subclasses; the MT::App class is not directly instantiated.

One of the advantages of creating applications under MT::App is the capability to make use of Movable Type’s user authentication system. You don’t have to write code to log in users or recognize account cookies.

All objects saved persistently to a database or file are subclasses of MT::Object, inheriting common methods to get and set their fields. Storage has been dealt with abstractly—an object does not have any way of knowing how it is being stored in permanent form.

An object can be loaded by calling the load() method of its class with an ID number as the only argument. Some objects can be retrieved using other criteria.

Working with Weblog Authors

The MT::Author class represents a user with weblog authoring privileges. The set_password(string) and is_valid_password(string) methods can be used to establish a password and check whether a prospective password will pass muster with the software, respectively.

The fields in this class are listed in Table 21-1.

Table 21-1: Fields of the MT::Author Class
Field | Type | Template Tag | Description
can_create_blog | Boolean | none | Whether the author can (1) or cannot (0) create a new weblog
can_view_log | Boolean | none | Whether the author can (1) or cannot (0) view the software’s activity log
created_by | integer | none | Author ID number of user who created this account
email | string | MTEntryAuthorEmail |
hint | string | None | Author’s birthplace, which will be requested for password recovery purposes
id | integer | None | Author’s ID number
name | string | MTEntryAuthor | Author’s username
nickname | string | MTEntryAuthorNickname | Author’s nickname
password | string | None | Author’s password
public_key | string | None | Reserved for future use
url | string | MTEntryAuthorURL | Author’s homepage URL

The actual privileges for an author are held in MT::Permission objects.

Handling Weblog Objects

The MT::Blog class contains a weblog published on the server and all of its configuration settings. This class has a filemgr() method that returns a MT::FileMgr object representing the weblog’s file manager.

Class fields appear in Table 21-2.

Table 21-2: Fields of the MT::Blog Class
Field | Type | Template Tag | Description
allow_anon_comments | Boolean | none | Whether visitors can submit comments anonymously (1) or cannot (0)
allow_comments_default | string |  |
allow_comment_html | Boolean | none | Whether visitors can use HTML in comments (1) or cannot (0)
allow_unreg_comments | Boolean | none | Whether visitor comments must come from TypePad users (1) or others are allowed (0)
archive_path | string | none | Weblog’s local archive path directory
archive_type | string | none | Chosen archive types (Category, Daily, Individual, Monthly, Weekly) as a comma-separated list
archive_type_preferred | string | none | Preferred archive type (one of the five above)
archive_url | string | MTBlogArchiveURL | Archive home page
auto_link_urls | Boolean | none | Whether links in visitor comments should be autolinked (1) or not (0)
convert_paras | string | none | Text filters to apply to entries (as a comma-separated list)
convert_paras_comments | string | none | Text filters to apply to visitor comments (as above)
days_on_index | integer | none | Number of days’ entries to display on home page
Description | string | MTBlogDescription | The weblog’s description
email_new_comments | Boolean | none | Whether authors receive new comment notifications in e-mail 1) or not (0)
file_extension | string | none | (Filename extension to use on archive pages
Id | integer | MTBlogID | ID number
Language | string | none | Language for date and time display
mt_update_key | string | none | The registration key that qualifies a weblog for the “Recently Updated” list on the Movable Type Web site
Name | string | MTBlogName | Name
server_offset | integer | MTBlogTimezone | Weblog’s chosen time zone, represented as the offset in hours from UTC time
site_path | string | MTBlogSitePath | Weblog’s local site path directory
site_url | string | MTBlogURL | Home page
sort_order_comments | string | None | The default sort order for visitor comments (“ascend” or “descend”)
sort_order_posts | string | None | The default sort order for entries (“ascend” or “descend”)
status_default | string | None |
welcome_message | string | None | Welcome message to display on Movable Type’s editing menu
words_in_excerpt | integer | None | Number of words to include in entry excerpts

Manipulating Weblog Entries

The MT::Entry class, perhaps the most useful class in MT’s hierarchy of objects, carries an individual weblog entry’s data and methods that provide

access to other useful objects, such as comments (MT::Comment) and categories (MT::Category).

An entry object’s previous() and next() method return an adjacent MT::Entry object.

The author() method produces the MT::Author object of the user who penned the entry, whereas the category() method does the same for its category. The categories() and comments() methods return arrays of the objects.

The comment_count() and ping_count() methods tally the number of visitor comments and trackback pings that the entry has attracted.

Table 21-3 describes the fields of an MT::Entry object.

Table 21-3: Fields of the MT::Entry Class
Field | Type | Template Tag | Description
allow_comments | Boolean | MTEntryFlag | Whether the entry allows (1) or disallows (0) comments
author_id | integer | None | The ID number of the entry author
blog_id | integer | MTBlogID | The ID number of the weblog in which this entry appears
convert_breaks | Boolean | MTEntryFlag | Whether line and paragraph breaks should be added (1) or not (0)
created_on | timestamp | MTEntryDate | The date and time the entry was first saved
Excerpt | string | MTEntryExcerpt | A short excerpt or summary
Id | integer | MTEntryID | The entry’s ID number
modified_on | timestamp | MTEntryModifiedDate | The date and time the entry was last edited
Status | integer | MTEntryStatus | The publication status, which is either Publish (2) or Draft (1)
Text | string | MTEntryBody | The entry text
text_more | string | MTEntryMore | Additional entry text
Title | string | MTEntryTitle | The entry title


Summary

Movable Type has been developed using object-oriented programming, a style of software design touted as the best way to deliver reliable, reusable, and extensible code.

Telling a programmer to employ objects and classes often is received as warmly as an admonition to “eat your vegetables.”

Now that you’ve had the opportunity to work with the objects that work in concert to operate Movable Type, you can attest to Six Apart’s strong commitment to the methodology.

Movable Type makes all of its functionality available in the form of well-designed, well-documented Perl classes.

You can create your own objects that work in cooperation with the software, adding new functionality in the form of tags and text filters, running in complement as Web applications, and extending the content-management system in countless new ways.

Because Six Apart did such a good job on the underlying framework that drives the company’s flagship product, Movable Type becomes less recognizable with each new release.

A technology magazine review of Movable Type 3.0 would probably summarize it as follows: a template-driven, extensible weblog publishing tool that supports comments, trackback, multiple authors and sites, image uploads, HTML, XHTML, XML, RSS, Atom, XML-RPC, Berkeley DB, MySQL, PostgreSQL, and SQLite.

As impressive as that sounds, the buzzword-laden definition leaves off the software’s biggest selling point: a killer publishing framework that can be extended to deliver any kind of Web content, separating the work of Web designers and programmers in a manner that gives both groups the opportunity to do their best work in strong cooperation.

Now that you’ve explored the software over the course of several hundred pages, I look forward to discovering where you take your installation of the program using plug-ins, filters, action links, and other software hooks.

The opportunities that Movable Type offers as an information-gathering and publishing tool are limitless.

So stop reading, start coding, and get moving!


Appendix: Using MovableType 3.1

Following the release of Movable Type 3.0, Six Apart announced a shift toward a more frequent software release schedule. New releases would appear as often as quarterly, according to an announcement on the company’s Web site.

The first release under this new plan, version 3.1, extends the software’s publishing and weblog categorization capabilities. Version 3.1 also includes additional callbacks for plug-in developers and other enhancement software written to extend Movable Type’s functionality.

Publishing Templates Dynamically

The most ambitious feature introduced with Movable Type 3.1 is the capability to designate parts of your weblog to publish dynamically each time they are requested.

Up to this point, all files created by the software were generated from templates statically, changing only when the files were rebuilt.

The new dynamic publishing feature, which is implemented with the PHP programming language, eliminates the need to rebuild those parts of the site in response to a template change or new data such as a weblog entry or visitor comment.

You can choose a weblog’s publishing policy, dynamic or static, on a per-template basis or for the entire site.

Six Apart calls the new feature a “best of both worlds” approach. Frequently requested pages such as a site’s index page can be generated statically, causing them to load more quickly and consume fewer resources on your Web server. Less popular pages, such as your archives, can be generated dynamically, removing the time-consuming need to rebuild dozens or even hundreds of pages.

Before you can use the feature, you must open the weblog’s main directory and create a subdirectory named templates_c that will hold template cache files. This directory should have the read, write, and delete permissions for all users (chmod 777 on a Linux system).

Next, if you are publishing your weblog with the Apache Web server, you must create a text file named .htaccess in its root directory like the one in Listing A-1.

Listing A-1: Viewing Dynamic Files with .htaccess
Start example
# Disable fancy indexes, so mtview.php gets a chance...
Options -Indexes
  <IfModule mod_rewrite.c>
  # The mod_rewrite solution is the preferred way to invoke
  # dynamic pages, because of its flexibility.
   # Add mtview.php to the list of DirectoryIndex options, listing it last,
  # so it is invoked only if the common choices aren’t present...
  <IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.htm default.htm default.html default.asp /mtview.php
  </IfModule>
   RewriteEngine on
   # don’t serve mtview.php if the request is for a real directory
  # (allows the DirectoryIndex lookup to function)
  RewriteCond %{REQUEST_FILENAME} !-d
   # don’t serve mtview.php if the request is for a real file
  # (allows the actual file to be served)
  RewriteCond %{REQUEST_FILENAME} !-f
  # anything else is handed to mtview.php for resolution
  RewriteRule ^(.*)$ /mtview.php [L,QSA]
</IfModule>
 <IfModule !mod_rewrite.c>
  # if mod_rewrite is unavailable, we forward any missing page
  # or unresolved directory index requests to mtview
  # if mtview.php can resolve the request, it returns a 200
  # result code which prevents any 4xx error code from going
  # to the server’s access logs. However, an error will be
  # reported in the error log file. If this is your only choice,
  # and you want to suppress these messages, adding a "LogLevel crit"
  # directive within your VirtualHost or root configuration for
  # Apache will turn them off.
  ErrorDocument 404 /mtview.php
  ErrorDocument 403 /mtview.php
</IfModule>
End example

Six Apart created this .htaccess file, but it is not included with the Movable Type 3.1 installation, either in the full or upgrade versions. You must create it manually. The purpose of the file is to redirect requests for the dynamic pages to a PHP script, mtview.php.

The mtview.php script generates pages dynamically as pages are requested. The script will be created when a special index template is rebuilt, the Dynamic Site Bootstrapper.

You can use a weblog’s overall template policy to declare how often, if at all, files should be created dynamically.

When you click the Templates button in the sidebar menu of the software’s browser interface, the Build Options section atop the Templates page lists the possible choices, as shown in Figure A-1.

Click To expand
Figure A-1: Choosing a template publishing policy.

Choose the Build All Templates Statically option to adopt the same functionality as prior versions of Movable Type, publishing all files only as a consequence of a rebuild.

Choose the Build Only Archive Templates Dynamically option to take advantage of the new functionality to eliminate the need for archive page rebuilds. All index templates will be published statically.

Choose the Set Each Template’s Build Options Separately option to choose dynamic or static publishing on a per-template basis.

Click the Save button to commit your choice.

If you choose the last option and set template options separately, a new checkbox appears on each template’s editing form (see Figure A-2).

Click To expand
Figure A-2: Editing a template’s publishing policy.

To publish from a template dynamically, enable the checkbox above the text Enable Dynamic Building for this Template label.

Tip

The fastest way to take advantage of this new functionality is to publish all archives dynamically and other files statically. Doing so speeds up the site rebuild process, making all features of the site more responsive.


Managing Entry Categories and Subcategories

Movable Type 3.1 also includes a new category management tool for weblog entries that supports subcategories.

This tool uses a system based on the SubCategories plug-in developed by David Raynes, incorporated into Movable Type with his assistance. You can create new subcategories under each category and even switch them from one category to another, which makes reorganizing your weblog easy if existing categories and subcategories prove inadequate.

All of this new functionality has been integrated into the Categories form (see Figure A-3), which you can view by clicking the sidebar button Categories.

Click To expand
Figure A-3: Managing weblog categories and subcategories.

On the Categories page, the subcategories are displayed below each category. To add a new subcategory, type its name in the text field below the category and click Create Subcategory.

Gotcha

How can you tell the difference between categories and subcategories? Look for the indentation to the left of subcategory names. In Figure A-3, the News category has a Political subcategory.

Use the Move button to change the category to which a subcategory belongs.


Index

Symbols

\ (backslash character), 118
/ (forward slash character), 54, 164
> (greater-than character), 10
< (less-than character), 10
# (pound sign)
Amazon content, 307
anchor tags, 133
script names, 41
uploading photos and other files, 105–106


Index_A

Team LiB

Index

A

account
TypeKey, verifying, 162
weblog configuration, setting up, 51–52
ActivePerl distribution, 23
activity log
data, retrieving with MySQL plug-ins, 289
monitoring setup, 61–62
address, e-mail
author’s, displaying, 128, 130, 272–274
Blogger, returning, 259
comments, tagging, 175, 206
phony users, 164
sharing publicly, 59
TypeKey verifying, 161–162
address, IP
banned
listing, 280
retrieving weblog data, 288
banning
comments, 169–171
pings, managing, 188–189
exporting comments, 206
mapping host names, 170
throttling repeated messages from, 62
aggregator, content
Movable Type category collecting, 193–195
other systems, 192–193
retrieving, 295
routing category to, 195–196
Allen, Jay (plug-ins creator), 213, 375
Amazon Associates, 307–308
Amazon plug-in
content, sharing, 308–311
custom searches, 311–313
described, 301, 307–308
products, presenting by number, 313–316
wish and other product lists, sharing, 316–319
Amazon Standard Item Number (ASIN), 313–314
Analog Web server analysis program, 62
anchor tags, 133
animation, GIF, 97
Apache Web server
CGIWrap, 30
Movable Type scripts, placing, 38
API (application programming interface)
Blogger calling methods
author’s account information, retrieving (blogger.getUserInfo), 259
deleting entry (blogger.deletePost), 257
described, 4, 255–256
entry, storable or publishable (blogger.newPost), 256
list of weblogs, retrieving (blogger.getUsersBlogs), 258
one or more recent entries, retrieving (blogger.getRecentPosts), 257–258
replacing existing entry (blogger.editPost), 257
weblog entries, exporting, 17, 240–241
Google search engine, 226–229
Metaweblog calling methods
described, 260–261
new entry (metaweblog.newPost), 261
recent entries, retrieving (metaweblog.getRecentPosts), 262–263
replacing entry (metaweblog.editPost), 262
retrieving entry (metaweblog.getPost), 262
uploading files to Web server (metaweblog.newMediaObject), 263
Movable Type calling methods
assigned categories, retrieving (mt.getPostCategories), 265
categories, setting or removing all (mt.setPostCategories), 265–266
defined categories, retrieving (mt.getCategoryList), 264–265
filters, supported (mt.supportedTextFilters), 267
methods, supported (mt.supportedMethods), 267
rebuilding files (mt.publishPost), 264
titles, retrieving entry (mt.getRecentPostTitles), 266–267
trackback pings, retrieving (mt.getTrackbackPings), 266
XML-RPC libraries, 255
appkey, Blogger
acquiring, 259
described, 256
application programming interface. See API
applications
acquiring Movable Type, 4–5
connecting Movable Type to other, 17–18
weblog configuration, licensing, 55–56
archive
deleted entries, 87–88
file templates, 148–150
Google, slowing down, 229
index template, 108
linking
tags identifying, 156
with template tags, 275
“on this day” feature, 270–272
organizing weblog, 88–89
pages
creating automatically, 137–138
creating with template, 146–148
linking with template tags, 132–133, 275
template tags, 138–139
trackback functionality, 186
URL, 53
ASIN (Amazon Standard Item Number), 313–314
assigned categories, retrieving (mt.getPostCategories), 265
Atom newsfeed syndication files
API, editing weblog with, 352–354
authentication tokens, seeking, 52
author, specific (person construct), 344
categories, limiting to, 89
content constructs, 340–342
creating, 338–339
date constructs, 342–343
globally unique identifiers, defining (id element), 347–348
index, 324
link constructs, 343–344
link tags identifying, 156
Perl module, installing, 27
publishing, 350–352
resources, linking together, 348–349
support for, 12, 18
writing, 345–349
XML data, 339–340
attributes
category, grouping (glue attribute), 137
JavaScript text-encoding, 117–118
language, 121
tag
author, 112
category, 125
global, 114–116
Google, 227–228
MTRandomLine, 305
Perl plug-ins handling, 360–362
trackback pings, 278
template entry, 125–128
audience, writing for, 15–16
author
Atom element, 340, 346
Blogger account information, retrieving (blogger.getUserInfo), 259
comment tag, 174, 206
crediting imported entries, 244
displaying entry by, 128
exporting, 204
filtering entries by, 86–87
importing from other weblogs, 234, 235
permissions, retrieving with MySQL plug-ins, 290
plug-ins, managing, 272–274
programming plug-ins with, 382–383
retrieving with MySQL plug-ins, 280–281
tag attributes, 112, 125, 130
weblog, adding other, 59–61
autodiscovery feature, trackback, 190–192
automating
archive page creation, 137–138
file rebuilding, 145
weblog backup, 207–210


Index_B

Team LiB

Index

B

backslash character (\), 118
backups
automating, 207–210
comments and trackback pings, 206–207
described, 200–203
multi-line entry fields, 205–206
single-line entry fields, 203–205
banned IP address
comments, viewing, 280
retrieving with MySQL plug-ins, 288
viewing attempts to use, 169
banning IP address
from comments feature, 169–171
pings, 188–189
TypeKey user, 171–172
Barger, Jorn (Internet writer), 337
Berkeley DB
access, setting up, 39
Movable Type, installing, 43, 45
setup, 23, 24
support for, 3
Blogger API (Application Programming Interface)
application key, acquiring, 259
author’s account information, retrieving (blogger.getUserInfo), 259
deleting entry (blogger.deletePost), 257
described, 4, 255–256
entry, storable or publishable (blogger.newPost), 256
list of weblogs, retrieving (blogger.getUsersBlogs), 258
one or more recent entries, retrieving (blogger.getRecentPosts), 257–258
replacing existing entry (blogger.editPost), 257
weblog entries, exporting, 17, 240–241
BlogRoots Web site, 193
BloGTK client, 254
body tags, 112
books, product number for, 313
browser
exported data, formatting, 201
file location, keeping in template, 123–124
JavaScript capability, needed, 3
Movable Type, controlling, 6
plug-ins, managing with, 376–377
PNG format, 99
QuickPost link, creating, 79–80
settings, checking, 6–7
sites listed, 4


Index_C

Team LiB

Index

C

Cabral, Marcelo L. L. (w.bloggar creator), 253
caching Perl code, 297
calendar
links, 151–154
“on this day” feature, 270–272
callbacks, object, 70
cascading style sheet (CSS)
index template, 108
Web server, checking, 42
category
content aggregator, converting to, 194–195
creating new, 90–92
described, 8, 9, 89–90
editing, 93–94
enhancing with plug-ins, 274–276
filtering entries by, 86–87
grouping (glue attribute), 137
importing
from old weblogs, 90–92
from other weblogs, 234–235
retrieving
with Movable Type API (mt.getCategoryList), 264–265
with MySQL plug-ins, 284–285
sorting, 127
routing to content aggregator, 195–196
tag attributes, 125
template tags, 136–137
10 most recent weblog entries, 137
cell phones, moblogging and
described, 95
preparing files, 14
Central Perl Archive Network. See CPAN
CGI (Common Gateway Interface) scripts
enabling, 18
path, 38
plug-in, 378–380
relative and full URLs, 124
CGIWrap, 29–32
change, importance of, 1
checkboxes, search form, 219
Choate, Brad (plug-ins author), 270
classes, programming plug-ins with
authors, 382–383
described, 380–382
entries, manipulating, 384–385
objects, 383–384
client software, connecting to Movable Type, 253–254
client/server application, Movable Type as, 3
Coates, Tom (trackback, comment on), 180
collaborating, 7–8
command-line environment, operating system, 22
comments
abuses of, 159, 371
from banned addresses, viewing, 280
banning
IP address, 169–171
TypeKey user, 171–172
benefits of using, 15
enabling, 75
exporting
allowing, 204
performing, 206–207
HTML code, 124
importing
from old weblogs, 17
from other weblogs, 234
managing and filtering, 168–169
policy, setting, 165–167, 172–173
rebuilds, 84
receiving with TypeKey feature
account, verifying, 162
deciding whether to use, 164
described, 160
signing in, 160–163
token, acquiring, 163–164
rejected, logging, 62
retrieving with MySQL plug-ins, 285–286
template
filtering tags, 116
presenting, 175–177
tags, 173–175
weblog entries, importing, 236–240
Common Gateway Interface. See CGI scripts
compression, graphics, 98
computer system requirements, 3–4
conditional tag, Perl plug-in, 372–373
configuration file, editing
CGIWrap, 30–31
Creative Commons license, 56–59
Movable Type
database access, 39–40
described, 37–38
directories, choosing, 38–39
e-mail servers, 40–41
script names, changing, 41
weblog
account, setting up, 51–52
activity logs, monitoring, 61–62
authors, adding other, 59–61
creative commons license, adopting, 56–59
first, creating, 52–54
Movable Type, first run of, 49–51
path directories, 54
software, licensing, 55–56
connecting. See links
container tag
authors, filtered by permissions, 274
comments, managing, 173–175
conditional output, 113, 154–155
Creative Commons license, 124, 334
described, 112
extended entry, 132
Perl plug-ins, creating, 362–367
pings, determining, 196–197
searches, 219
weblogs, all on server, 125
content
advantages of using Movable Type, 2–4
Amazon, sharing, 308–311
Atom element, 340
content aggregator, trackback links
Movable Type category collecting, 193–195
other systems, 192–193
retrieving, 295
routing category to, 195–196
content-management systems, 2–4
context, 367
“continue reading” entries, creating, 72–74
contributor
Atom element, 340, 346
Blogger account information, retrieving (blogger.getUserInfo), 259
comment tag, 174, 206
crediting imported entries, 244
displaying entry by, 128
exporting, 204
filtering entries by, 86–87
importing from other weblogs, 234, 235
permissions, retrieving with MySQL plug-ins, 290
plug-ins, managing, 272–274
programming plug-ins with, 382–383
retrieving with MySQL plug-ins, 280–281
tag attributes, 112, 125, 130
weblog, adding other, 59–61
Coordinated Universal Time (UTC), 342
copyright law, 58, 346
CPAN (Central Perl Archive Network), 302
crackers, 29
Creative Commons license
RSS 1.0 template, 333–334
template tags, 124
weblog configuration, 56–59
CSS (cascading style sheet)
index template, 108
Web server, checking, 42


Index_D

Team LiB

Index

D

data
exporting
comments and trackback pings, 206–207
described, 200–203
multi-line entry fields, 205–206
single-line entry fields, 203–205
importing
with MySQL plug-ins, 281–284
from old weblogs, 18
weblog entries, 231–236, 244–246
index templates, 209–210
uploading files, 104–105
XML-RPC support, 248–249
database
access, 39–40
author permissions, 290
comments, displaying, 299
compatible, 3, 21
Movable Type, preparing, 36
programs, sites listed, 4
Radio UserLand entries, importing, 241
templates and linked template files, 293–295
trackback pings, 292–293
Web server, setting up, 23–25
date
authored, enabling, 71–72
entries ordered by, 133–136
months, specifying for calendar, 153
date and time
Atom element, 340, 346
entry, stamping, 129, 132
exporting entry fields, 203–205, 206
importing single-line entry fields, 233–234
RSS 1.0, 333
template, formatting, 119–121
debugger, XML-RPC, 252
deleting
all entry categories (mt.setPostCategories), 265–266
entries, 87–88
entry (blogger.deletePost), 257
entry form items, 77–78
files from import directory, 246
uploaded files, 14, 106
digital photos
GIF format limitations, 97
JPEG format, 98
directories
include files, specifying, 155
Movable Type, choosing, 38–39
name, transmitting HTML tag into, 117
path, setting up, 54
settings, 53
displaying
database comments, 299
e-mail address, author’s, 272–274
HTML formatting, permissible, 117
images in pop-up window
calendars, 151–154
containers, 154–157
described, 150
100 most recent posts, 133–134
pings, 197
template entry tags, 128–132
text, 113–119
trackback pings, 277
dividing weblog entry form into two fields, 72–74
domain-name system, 170
downloading
Movable Type, 33–34
MySQL, 24
Dublin Core 1.1 Internet resource information, 345
Dumpleton Software XML-RPC debugger, 252
dynamic IP addresses, 170


Index_E

Team LiB

Index

E

Ecto client, 254
editing
authors, granting permissions to other, 60–61
configuration file, 37
entry form
default values, 75–78
items excluded from additional, 77–78
trackback links, 182–183
uploading photos and other files, 103–104
writing entry, 70–72
images, 102
template, 143–146
text form, 76–77
word processing tool, 253–254
e-mail
notification data, retrieving, 289–290
pings, notifying by, 188
servers, configuring, 40–41
Web hosting service provider, suggested, 18
e-mail address
author’s, displaying, 128, 130, 272–274
Blogger, returning, 259
comments, tagging, 175, 206
phony users, 164
sharing publicly, 59
TypeKey verifying, 161–162
entry
categories
assigned, retrieving (mt.getPostCategories), 265
filing in, 9
setting or removing all (mt.setPostCategories), 265–266
container template tags, 133–136
data, retrieving with MySQL plug-ins, 286–287
deleting (blogger.deletePost), 257
described, 8
editing, 86–88
excerpt, 9, 71
exporting multi-line fields, 205–206
extended, 9
importing
from Blogger, 240–241
comments and trackback pings, 236–240
data, moving, 231–236
data to Movable Type, 244–246
described, 231
from Radio UserLand, 241–243
manipulating, 384–385
new, logging, 62
one or more recent, retrieving (blogger.getRecentPosts), 257–258
pings, displaying all, 197
QuickPost window, 78–80
replacing (blogger.editPost), 257
sending pings for each, 190–192
storable or publishable (blogger.newPost), 256
summary, 71
template tags, 125–136
entry form
described, 66–70
dividing into two fields, 72–74
editing
setting default values, 75–78
trackback links, 182–183
uploading photos and other files, 103–104
writing entry, 70–72
graphic, adding, 103
Eriksson, Richard (MovableBLOG writer), 180–181
errors
logging, 62
reporting, 368–369
escaped text, syndication formats’ use of, 342
Estey, Gavin (Weather Underground plug-in author), 302
excerpt, 9, 71
existing entry, replacing (blogger.editPost), 257
exporting
Blogger entries, 17, 240–241
Radio UserLand entries, 241–243
weblog data to text file, 200–207
extended entry
container tag, 132, 155
described, 9
extensible markup language. See XML
external Web content plug-ins
Amazon
content, sharing, 308–311
custom searches, 311–313
described, 307–308
products, presenting by number, 313–316
wish and other product lists, sharing, 316–319
described, 301–302
random quotes and other text, 303–306
weather, local, 302–303


Index_F

Team LiB

Index

F

feedback. See comments; trackback links; trackback pings
fields, dividing weblog entry form in half, 72–74
file
archive templates, 148–150
deleting
from import directory, 246
uploaded, 14, 106
include, specifying, 155
moblog, preparing, 14
name, transmitting HTML tag into, 117
path to, 305
rebuilding
all index templates or entire weblog, 143–144
automatic, turning off, 145
change prompting, 84–85
entry, all associated with (mt.publishPost), 264
error halting, 368–369
exporting all entries, 210
Google slowing down, 229
limiting to index files, 85–86
with Weather Underground plug-in, 303
uploading, 104–105
filters
comments, 168–170
entries matching author, category, or publication status, 86–87
entry text, identifying, 205
line breaks, importing from other weblogs, 235
output text, processing, 118
supported, listing (mt.supportedTextFilters), 267
finding. See searches
Footbridge client, 254
form
entry
described, 66–70
dividing into two fields, 72–74
editing, setting default values, 75–78
graphic, adding, 103
writing, 70–72
QuickPost, 78–80, 79
search
basic, 215–217
enhanced, 217–220
format
template, 10
text for, setting editing form, 76–77
Web graphics, selecting, 99
forward slash character (/), 54, 164
FTP permissions, 43


Index_G

Team LiB

Index

G

Gainsbourg, Serge (French singer), 50
games, 104–105
GIF format
best use of, 99
preparing for Web, 97–98
global attributes, 114–116
global filter Perl plug-in
described, 357
scripts, enhancing, 369–371
global template tags, 122–125
Google
licensing, 226
tags, 227–229
trackback content, 192–193
graphics manipulation tool, 28
graphics, pop-up window
calendars, 151–154
containers, 154–157
described, 150
greater-than character (>), 10
Greymatter weblog program, 17


Index_H

Team LiB

Index

H

Haughey, Matt (MetaFilter weblog publisher), 95
home page
author’s, 128, 130, 175
index template, 108, 143
host, finding
Movable Type, 18
publishing, 18
host names, 170
hosting service, 18
HTML (HyperText Markup Language)
comments, 167
entries, composing, 67–68
Google search results, publishing, 228–229
permissible, listing in template, 116–117
search, converting to, 216
titles, extracting, 245
HTTP (HyperText Transfer Protocol). See also XML-RPC protocol
Atom server, 354
plug-ins, handling, 360
hyperlinks. See links
HyperText Markup Language. See HTML


Index_I

Team LiB

Index

I

ID number, entry
Blogger entry, returning, 256, 261
linking to archive pages, 132–133
padding, 131
image manipulation tool, 28
ImageMagik software, 102
images, pop-up window
calendars, 151–154
containers, 154–157
described, 150
incentive, Amazon sales, 307
include files, specifying, 155
index
archived pages, master, 138
files, limiting rebuild to, 85–86
100 most recent posts, displaying, 133–134
search form, attaching, 215
templates
described, 108–110
exporting, 209–210
newsfeeds, 324
rebuilding, 143–144
stock quote, 366
initializing Movable Type software, 46–47
input element, form, 216
installation, verifying
Perl 5, 22–23
Web server, 31
installing Movable Type
database, preparing, 36
Perl 5 components, 35
security and connection issues, 18
software, downloading, 33–34
on Web server, 5–6
instructions, search, 222
interface. See also API (application programming interface); CGI (Common Gateway Interface) scripts
browser, 123–124
graphics file, 42
links, 377–380
International Standard Book Number (ISBN), 313–314
Internet Explorer (Microsoft)
exported data, formatting, 201
scripting settings, 6
Internet Topic Exchange Web site, 192
IP address
banned
listing, 280
retrieving weblog data, 288
banning
comments, 169–171
pings, managing, 188–189
exporting comments, 206
mapping host names, 170
throttling repeated messages from, 62
ISBN (International Standard Book Number), 313–314


Index_J

Team LiB

Index

J

J2ME (Java 2 Millennium Edition), 254
Java, XML-RPC, 255
JavaScript
described, 3
interface functions, uploading, 42
QuickPost window, opening, 79
text-encoding attributes, 117–118
JPEG format
best use of, 99
preparing for Web, 98


Index_K

Team LiB

Index

K

Kablog, 254
keyword
container tags, 155
multi-line fields, exporting, 205
summary entry, 71


Index_L

Team LiB

Index

L

label element, form, 216
language attribute, 121
less-than character (<), 10
licensing
creative commons, adopting, 56–59
Google, 226
Movable Type, choosing, 34
“on this day” feature, 272
RSS 1.0, 333–334
template tags, 124
weblog software, 55–56
line breaks
filter converting, 131
importing from other weblogs, 235
random quotes, pulling, 306
links
archive pages, 132–133, 275
authors, 128
calendar, 151–154
comment tag, 174, 177
extended and summary entries, 72–74
plug-ins
adding to interface, 377–380
to previous years, 270–272
QuickPost form, 79
unwanted, 15
weblogs, 180–181
links sidebar. See category
links, trackback
content aggregator, contributing to
category, collecting in, 193–195
described, 192–193
routing category to, 195–196
described, 16, 179
enabling, 75
exporting, 207
list, requesting, 250–252
receiving from other weblogs
described, 182–186
import fields, 238–240
Metaweblog API (metaweblog.newPost), 261
template tags, 196–197
weblogs, connecting, 180–181
Linux
CGIWrap, 30
e-mail program, 40
Movable Type weblog, storing, 44
MySQL database and, 25, 36
Perl 5, checking for, 22
Perl modules, installing, 28
XML-RPC client, 254
list
Amazon wish and other product, 316–319
HTML permissions, 116–117
trackback links, 250–252
of weblogs, retrieving (blogger.getUsersBlogs), 258
local archive path, 53
local site path, 53
local weather, 301, 302–303
log
data, retrieving with MySQL plug-ins, 289
monitoring setup, 61–62
longer entry
container tag, 132, 155
described, 9
Lundh, Fredrik (Python library creator), 255


Index_M

Team LiB

Index

M

MacOS, XML-RPC clients, 254
Mancuso, Bull (private investigator), 50
Manila weblog program, 17
message, trackback
data, exporting, 206–207
described, 16, 180, 187
e-mail notification, 188
errors, 62
importing from other weblogs, 234, 238–240
IP addresses, banning from specific, 188–189
managing
described, 187
e-mail notification, 188
enabling, 75
IP addresses, banning from specific, 188–189
MySQL plug-ins
displaying by weblog name, 277
retrieving weblog data with, 292–293
rebuilds, 84
receiving from other weblogs, 182–186
retrieving (mt.getTrackbackPings), 266
weblog entries, importing, 236–240
Metaweblog API calling methods
described, 260–261
new entry (metaweblog.newPost), 261
recent entries, retrieving (metaweblog.getRecentPosts), 262–263
replacing entry (metaweblog.editPost), 262
retrieving entry (metaweblog.getPost), 262
uploading files to Web server (metaweblog.newMediaObject), 263
Microsoft Internet Explorer
exported data, formatting, 201
scripting settings, 6
Microsoft Windows
database access, setting up, 39
Perl 5, checking for, 22, 23
Perl modules, installing, 28
text editor, editing configuration file, 37
XML-RPC clients, 254
Mikulich, Dawn (Chicago Uncommon weblog publisher), 96
mobile devices, moblogging and
described, 95
preparing, 14
moblog
described, 95
preparing graphics for Web
format, selecting right, 99
GIF format, 97–98
JPEG format, 98
PNG format, 99
uploading photos and other files
described, 99–102
graphics, 102–104
maximum size, changing, 105–106
non-graphic files, 104–105
modules, Perl
checking availability, 44–46
Movable Type, downloading, 33–34
Web server, setting up, 26–29
months, specifying for calendar, 153
Movable Type
acquiring software, 4–5
API calling methods
assigned categories, retrieving (mt.getPostCategories), 265
categories, setting or removing all (mt.setPostCategories), 265–266
defined categories, retrieving (mt.getCategoryList), 264–265
filters, supported (mt.supportedTextFilters), 267
methods, supported (mt.supportedMethods), 267
rebuilding files (mt.publishPost), 264
titles, retrieving entry (mt.getRecentPostTitles), 266–267
trackback pings, retrieving (mt.getTrackbackPings), 266
browser settings, checking, 6–7
classes, programming plug-ins with
authors, 382–383
described, 380–382
entries, manipulating, 384–385
objects, 383–384
as client/server application, 3
collaborating, 7–8
configuration file, editing
database access, 39–40
described, 37–38
directories, choosing, 38–39
e-mail servers, 40–41
script names, changing, 41
connecting to other software, 17–18
development of, 2–3
host, finding, 18
initializing software, 46–47
installing
database, 36
Perl 5 components, 35
security and connection issues, 18
software, downloading, 33–34
Perl modules, checking availability, 44–46
publishing, 9–16
security permissions, setting up, 42–44
system requirements, 3–4
uploading to Web server, 5–6, 41–42
weblog public programs versus, 3
writing weblog, 8–9
Mozilla scripting, 6
MT-QOTD plug-in, 301
multi-line fields
exporting data, 205–206
importing from other weblogs, 232–233, 235–236
music
Amazon products, presenting, 313
files, uploading, 104–105
MySQL
database access, setting up, 40
downloading, 24
Movable Type, installing, 45
plug-ins, retrieving weblog data with
activity log data, 289
author data, 280–281
author permissions, 290
banned IP address data, 288
category data, 284–285
comment data, 285–286
described, 276–278
e-mail notification data, 289–290
entry data, 286–287
existing tags, working with, 278–279
other Movable Type data, 279–280
plug-in data, 291
session data, 291–292
template data, 293–295
trackback aggregator data, 295
trackback ping data, 292–293
weblog data, 281–284
preparing, 36
security, 25
use of, 3, 23
user and database, creating, 25


Index_N

Team LiB

Index

N

names
archive pages, custom, 148–150
author, displaying, 272–274
file or directory, transforming text into, 117
script, changing, 41
template, specifying, 155
namespaces, 332
Nelson, Melody (initial setup account), 50–52
Neoteny (Movable Type investor), 5
Netscape Navigator scripting, 6
Neulinger, Nathan (CGIWrap program author), 29
new category, 90–92
new entry
logging, 62
Metaweblog API (metaweblog.newPost), 261
newsfeeds
Atom syndication files
API, editing weblog with, 352–354
authentication tokens, seeking, 52
author, specific (person construct), 344
authoring, 345–349
categories, limiting to, 89
content constructs, 340–342
creating, 338–339
date constructs, 342–343
globally unique identifiers, defining (id element), 347–348
index, 324
link constructs, 343–344
link tags identifying, 156
Perl module, installing, 27
publishing, 350–352
resources, linking together, 348–349
support for, 12, 18
XML data, 339–340
described, 56–57
index template, 324
RSS 1.0
categories, limiting to, 89
identifying link tags, 156
indexing link tags, 324
license information, 59
support for, 12
XML syndication files, 330–334
RSS 2.0
identifying link tags, 156
indexing link tags, 324
sample weblog entry, 68
support for, 260
template, 13–14
XML syndication files, 325–330
Newspro weblog program, 17
newsreader, 12, 57, 145
Noonan, Peggy (writer), 65
Notepad, 37
number, retrieving specified entries, 125


Index_O

Team LiB

Index

O

objects
callback, 70
plug-ins, programming, 383–384
older files, storing
deleted entries, 87–88
file templates, 148–150
Google, slowing down, 229
index template, 108
linking
tags identifying, 156
with template tags, 275
“on this day” feature, 270–272
organizing weblog, 88–89
pages
creating automatically, 137–138
creating with template, 146–148
linking with template tags, 132–133, 275
template tags, 138–139
trackback functionality, 186
URL, 53
“on this day” feature, 270–272
one or more recent entries, retrieving (blogger.getRecentPosts), 257–258
online journal, frequently updated. See weblog
opacity, 99
Opera Web browser
exported data, formatting, 201
scripting settings, 6
operating systems, compatible, 21–22
order of search results, 220
organization
archiving entries, 88–89
categorizing
described, 89–90
new, 90–92
Power Edit mode, 93–94
described, 83
editing entries, 86–88
publishing, 83–86
Orlando Vacationer sample weblog
archive, 88, 148
graphics files, 101
RDF ping data, 184–185
searching, 214
syndication file, 322–323
text ads, displaying, 155
URL and directory settings, 53


Index_P

Team LiB

Index

P

pages
archive
automatic creation, 137–138
linking with template tags, 132–133, 275
template, 146–148
home
author’s, 128, 130, 175
index template, 108, 143
template, generating from, 141–143
PalmOS XML-RPC client, 254
password
changing, 51–52
content aggregators, 195
path
CGI, 38
directories, 54
to file, 305
PDAs (personal digital assistants), moblogging and
described, 95
preparing, 14
performers, finding Amazon product by, 312–313
Perl
object callbacks, 70
site listed, 4
Perl 5
installing components, 35
Web server installation, verifying, 22–23
Perl modules
checking availability, 44–46
Movable Type, downloading, 33–34
Web server, setting up, 26–29
Perl plug-ins
authors, managing, 272–274
browser, managing with, 376–377
category tags, enhancing, 274–276
container tag, creating, 362–367
described, 269–270
designing first, 358–360
linking to previous years, 270–272
links, adding to interface, 377–380
MySQL, retrieving weblog data with
activity log data, 289
author data, 280–281
author permissions, 290
banned IP address data, 288
category data, 284–285
comment data, 285–286
described, 276–278
e-mail notification data, 289–290
entry data, 286–287
existing tags, working with, 278–279
other Movable Type data, 279–280
ping data, 292–293
plug-in data, 291
session data, 291–292
template data, 293–295
trackback aggregator data, 295
weblog data, 281–284
programming with Movable Type classes
authors, 382–383
described, 380–382
entries, manipulating, 384–385
objects, 383–384
scripts, enhancing
conditional tag, creating, 372–373
errors, reporting, 368–369
global filter plug-in, 369–371
tag attributes, handling, 360–362
template tags, working with other, 367–368
templates, programming with scripting tags, 295–300
permalinks, 133
permissions
author
database, 290
editing, 60–61
filtering, 274
retrieving, 290
setting, 7–8, 59–60
security, 42–44
personal digital assistants (PDAs), moblogging and
described, 95
preparing, 14
photoblog
described, 95
preparing graphics for Web
format, selecting right, 99
GIF format, 97–98
JPEG format, 98
PNG format, 99
uploading photos and other files
described, 99–102
graphics, 102–104
maximum size, changing, 105–106
non-graphic files, 104–105
photos
file format, choosing, 99
preparing for Web, 98
publishing, 14
PHP text, encoding, 117, 118–119
pings
data, exporting, 206–207
described, 16, 180, 187
e-mail notification, 188
errors, 62
importing from other weblogs, 234, 238–240
IP addresses, banning from specific, 188–189
managing
described, 187
e-mail notification, 188
enabling, 75
IP addresses, banning from specific, 188–189
MySQL plug-ins
displaying by weblog name, 277
retrieving weblog data with, 292–293
rebuilds, 84
receiving from other weblogs, 182–186
retrieving (mt.getTrackbackPings), 266
weblog entries, importing, 236–240
plug-ins
authors, managing, 272–274
browser, managing with, 376–377
category tags, enhancing, 274–276
container tag, creating, 362–367
described, 269–270
designing first, 358–360
linking to previous years, 270–272
links, adding to interface, 377–380
MySQL, retrieving weblog data with
activity log data, 289
author data, 280–281
author permissions, 290
banned IP address data, 288
category data, 284–285
comment data, 285–286
described, 276–278
e-mail notification data, 289–290
entry data, 286–287
existing tags, working with, 278–279
other Movable Type data, 279–280
ping data, 292–293
plug-in data, 291
session data, 291–292
template data, 293–295
trackback aggregator data, 295
weblog data, 281–284
programming with Movable Type classes
authors, 382–383
described, 380–382
entries, manipulating, 384–385
objects, 383–384
scripts, enhancing
conditional tag, creating, 372–373
errors, reporting, 368–369
global filter plug-in, 369–371
tag attributes, handling, 360–362
template tags, working with other, 367–368
templates, programming with scripting tags, 295–300
PNG format, 99
policy
comments, 165–167, 172–173
trackbacks, 182–183
pop-up window
adding entries, 78–80
calendars, 151–154
containers, 154–157
described, 150
trackbacks, 183–184
port 17, 303
Post role, 60
PostgreSQL
compatibility with, 3
database access, setting up, 23, 24, 40, 45
preparing, 36
security, 25
pound sign (#)
Amazon content, 307
anchor tags, 133
script names, 41
uploading photos and other files, 105–106
Power Edit mode, 93–94
preparing graphics for Web
format, selecting right, 99
GIF format, 97–98
JPEG format, 98
PNG format, 99
processing, speeding, 297
products, Amazon
lists, linking, 316–319
number, presenting by, 313–316
programming
plug-ins with Movable Type classes
described, 380–382
entries, manipulating, 384–385
objects, 383–384
weblog authors, 382–383
templates, with scripting tags, 295–300
programs
acquiring Movable Type, 4–5
connecting Movable Type to other, 17–18
weblog configuration, licensing, 55–56
publishing
audience, writing for, 15–16
described, 9–10
formatting text for, setting editing form, 76–77
host, finding, 18
Movable Type, 9–16
photos, graphics, and other files, 14
status, filtering entries by, 86–87
templates for, 10–14
weblog organization, 83–86
Python library, 255


Index_Q

Team LiB

Index

Q

QuickPost form window, 78–80
quote of the day server, 301
quote, stock market data, 298, 362–365


Index_R

Team LiB

Index

R

radio buttons, search form, 219
Radio UserLand
described, 17
exporting weblog entries, 241–243
random quotes, 301, 303–306
RandomLine plug-in, 304–306
RDF (Resource Description Framework), 184–185
read timeout error, 62
reading lists, creating separate. See category
Rebuild Files role, 60
rebuilding files
all index templates or entire weblog, 143–144
automatic, turning off, 145
change prompting, 84–85
entry, all associated with (mt.publishPost), 264
error halting, 368–369
exporting all entries, 210
full site, 69–70
Google slowing down, 229
limiting to index files, 85–86
with Weather Underground plug-in, 303
recent entries, retrieving
Blogger (blogger.getRecentPosts), 257–258
Metaweblog (metaweblog.getRecentPosts), 262–263
Red Hat Linux, 25, 36
Red Hat Network, 248
referrer tracking, Web server, 16
Remote Authentication, 52
remote commenting, 181
removing
all entry categories (mt.setPostCategories), 265–266
entries, 87–88
entry (blogger.deletePost), 257
entry form items, 77–78
files from import directory, 246
uploaded files, 14, 106
replacing
accidental overwriting, 146, 241
Blogger entry (blogger.editPost), 257
Metaweblog entry (metaweblog.editPost), 262
request, XML-RPC protocol, 249–251
Resource Description Framework (RDF), 184–185
response, XML-RPC protocol, 251–253
retrieving
author’s account information (blogger.getUserInfo), 259
entry (metaweblog.getPost), 262
list of weblogs (blogger.getUsersBlogs), 258
one or more recent entries (blogger.getRecentPosts), 257–258
reusable design
archive pages, creating, 146–148
Blogger entries, replacing with, 240–241
data, retrieving with MySQL plug-ins, 293–295
described, 10, 107–111
editing, 143–146
export format, 208–210
images, displaying in pop-up window
calendars, 151–154
containers, 154–157
described, 150
lines, pulling, 305–306
names, customized for archive pages, 148–150
pages, generating from, 141–143
presenting comments, 175–177
programming with scripting tags, 295–300
publishing, 10–14
searches, enabling
described, 220
script, setting up, 222–226
tags, 221–222
tags
archive, 138–139
archive pages, linking, 132–133
attributes, entry tag, 125–128
category, 136–137
comments, 173–175
date and time, formatting, 119–121
described, 10–12, 111–113
entry container, 133–136
entry, displaying, 128–132
global, 122–125
Perl plug-ins, 367–368
text, displaying, 113–119
trackback links, 196–197
trackbacks, 183–184
routing category to content aggregator, 195–196
RSD file, 109
RSS 1.0 newsfeed
categories, limiting to, 89
index, 324
license information, 59
link tags identifying, 156
support for, 12
XML syndication files, 330–334
RSS 2.0 newsfeed
identifying link tags, 156
indexing link tags, 324
sample weblog entry, 68
support for, 260
template, 13–14
XML syndication files, 325–330


Index_S

Team LiB

Index

S

script
CGI
enabling, 18
path, 38
plug-in, 378–380
relative and full URLs, 124
names, changing, 41
Perl plug-ins
conditional tag, creating, 372–373
errors, reporting, 368–369
global filter plug-in, 369–371
searches, setting up, 222–226
tags, programming templates with, 295–300
URL, relative and full, 124
UserTalk, importing from Radio UserLand weblogs, 241–243
Web browser settings, checking, 6
search engines, 88. See also Google
searches
Amazon custom, 311–313
described, 213–215
entries by author, category, or publication status, 86–87
form, adding to Web page
basic, 215–217
enhanced, 217–220
Google
licensing, 226
tags, 227–229
template
described, 220
script, setting up, 222–226
tags, 221–222
security
CGI scripting and Web hosts, 18
external template files, 146
Perl plug-in problems, 295, 299
permissions, setting up, 42–44
Web server with CGIWrap, 29–32
Sedley, Neil (MT-QOTD provider), 304
Sendmail program, 40
server
conditions, meeting, 21–22
database, setting up, 23–25
files, deleting uploaded, 14
graphics file, uploading, 100–102
Movable Type
ability to run on, 3
installing, 5–6
XML-RPC protocol, 254–255
Perl 5 installation, verifying, 22–23
Perl modules, setting up, 26–29
qotd, 303–306
read timeout error, 62
referrer tracking, 16
securing with CGIWrap, 29–32
TypePad hosting service, 21–22
verifying installation, 31
session data, retrieving, 291–292
setting all entry categories (mt.setPostCategories), 265–266
showing
database comments, 299
e-mail address, author’s, 272–274
HTML formatting, permissible, 117
images in pop-up window
calendars, 151–154
containers, 154–157
described, 150
100 most recent posts, 133–134
pings, 197
template entry tags, 128–132
text, 113–119
trackback pings, 277
sidebars, creating. See category
signing in, TypeKey feature, 160–163
similar products, finding on Amazon, 316
Simple Mail Transport Protocol (SMTP) server, 40–41
Simple Object Access Protocol (SOAP), 249
simple tags, 112
single-line entry fields
exporting, 203–205
importing from other weblogs, 232–233, 234
site syndication, 57
site URL, 53
Six Apart Ltd. (Movable Type developer)
history of software, 2, 4, 17
Web site, downloading software from, 33–34
size, maximum for uploading files, 105–106
slash characters. See backslash character; forward slash character
Slug client, 254
SMTP (Simple Mail Transport Protocol) server, 40–41
SOAP (Simple Object Access Protocol), 249
software
acquiring Movable Type, 4–5
connecting Movable Type to other, 17–18
weblog configuration, licensing, 55–56
sorting entries, 127–128
spam
author’s e-mail address, disguising, 130
described, 15
excessive links, filtering, 370–371
trackback pings, 187–189
SQL (Structured Query Language)
access, setting up, 39
Berkley DB and, 23
use of, 3
SQLite
compatibility, 3
database access, setting up, 23, 24, 40
Movable Type, installing, 43, 45
stash, 365–368
stock quote data, 298, 362–365
storage files
deleted entries, 87–88
file templates, 148–150
Google, slowing down, 229
index template, 108
linking
tags identifying, 156
with template tags, 275
“on this day” feature, 270–272
organizing weblog, 88–89
pages
creating automatically, 137–138
creating with template, 146–148
linking with template tags, 132–133, 275
template tags, 138–139
trackback functionality, 186
URL, 53
strftime code, 234
Structured Query Language (SQL)
access, setting up, 39
Berkley DB and, 23
use of, 3
stylesheet, index template, 108
summary entry, 71
Sutherland, Andrew (KoalaRainbow plug-in creator), 375
Sutherland, Martin (RandomLine plug-in provider), 304–306
Symbian XML-RPC client, 254
syndication files
Atom newsfeed
API, editing weblog with, 352–354
author, specific (person construct), 344
authoring, 345–349
content constructs, 340–342
creating, 338–339
date constructs, 342–343
globally unique identifiers, defining (id element), 347–348
link constructs, 343–344
publishing, 350–352
resources, linking together, 348–349
XML data, 339–340
need for, 321–322
XML
described, 322–325
RSS 1.0 newsfeed, 330–334
RSS 2.0 newsfeed, 325–330
system requirements, 3–4


Index_T

Team LiB

Index

T

tables, Movable Type in MySQL, 24–25
tag
attributes, Perl handling, 360–362
described, 10
Google, 227–229
Perl container, 362–367
template
archive, 138–139
attributes, entry tag, 125–128
category, 136–137
container, 133–136
date and time, formatting, 119–121
described, 10, 111–113
displaying entry, 128–132
entry, 125–136
global, 122–125
linking archive pages, 132–133
searches, enabling, 221–222
text, displaying, 113–119
Tag URI scheme, Atom feed, 347–348
telnet, qotd connection, 304
template
archive pages, creating, 146–148
Blogger entries, replacing with, 240–241
data, retrieving with MySQL plug-ins, 293–295
described, 10, 107–111
editing, 143–146
export format, 208–210
images, displaying in pop-up window
calendars, 151–154
containers, 154–157
described, 150
lines, pulling, 305–306
names, customized for archive pages, 148–150
pages, generating from, 141–143
presenting comments, 175–177
programming with scripting tags, 295–300
publishing, 10–14
searches, enabling
described, 220
script, setting up, 222–226
tags, 221–222
tags
archive, 138–139
archive pages, linking, 132–133
attributes, entry tag, 125–128
category, 136–137
comments, 173–175
date and time, formatting, 119–121
described, 10–12, 111–113
entry container, 133–136
entry, displaying, 128–132
global, 122–125
Perl plug-ins, 367–368
text, displaying, 113–119
trackback links, 196–197
trackbacks, 183–184
text
formatting for publishing, 76–77
template, displaying, 113–119
text editor, 37
text file
exporting data from weblog to, 200–207
uploading, 104–105
text formatter, 76–77
thumbnails, 103
timeout error, 62
timestamp
Atom element, 340, 346
entry, stamping, 129, 132
exporting entry fields, 203–205, 206
importing single-line entry fields, 233–234
RSS 1.0, 333
template, formatting, 119–121
title
archive pages, linking, 138–139
described, 8
extracting from imported weblog entries, 245
retrieving entry
Movable Type API (mt.getRecentPostTitles), 266–267
posted during specified period, 126
tags, 112–113, 129
10 most recent weblog entries, 137
token, TypeKey, 163–164
trackback aggregator data, 295
trackback links
content aggregator, contributing to
category, collecting in, 193–195
described, 192–193
routing category to, 195–196
described, 16, 179
enabling, 75
exporting, 207
list, requesting, 250–252
receiving from other weblogs
described, 182–186
import fields, 238–240
Metaweblog API (metaweblog.newPost), 261
template tags, 196–197
weblogs, connecting, 180–181
trackback pings
data, exporting, 206–207
described, 187
e-mail notification, 188
entry, sending for each
described, 190–191
manual, setting up, 191–192
IP addresses, banning from specific, 188–189
MySQL plug-ins
displaying by weblog name, 277
retrieving weblog data with, 292–293
rebuilds, 84
retrieving (mt.getTrackbackPings), 266
weblog entries, importing, 236–240
transparency, GIF, 97–98
Trott, Ben and Mena (Movable Type developers)
Atom feed sample, 344
calendar sample, 50, 154
history of software, 2–3, 4
musical taste, 50
on trackback, 181, 192
TypeKey
account, verifying, 162
authentication tokens, seeking, 52
deciding whether to use, 164
described, 160
signing in, 160–163
token, acquiring, 163–164
unwanted links, avoiding, 15–16
user, banning, 171–172
TypePad
described, 5
files, deleting uploaded, 14


Index_U

Team LiB

Index

U

Uniform Product Code (UPC), 313, 315
uniform resource locator. See URL
UNIX
CGIWrap, 30
e-mail program, 40
Movable Type and, 21, 22
server analysis program, 62
session data, retrieving, 292
unwanted e-mail
author’s e-mail address, disguising, 130
described, 15
excessive links, filtering, 370–371
trackback pings, 187–189
UPC (Uniform Product Code), 313, 315
Update Key, 56
uploading
Movable Type software to Web server, 41–42
photos and other files
described, 99–102
graphics, 102–104
maximum size, changing, 105–106
metaweblog.newMediaObject, 263
non-graphic files, 104–105
Urchin Web server analysis program, 62
URL (uniform resource locator)
Amazon wish lists, 317
archives, 88, 150
Atom element, 340, 343
comment tag, 174
connecting weblogs, 180–181
content aggregator, contributing to
category, collecting in, 193–195
described, 192–193
routing category to, 195–196
described, 16, 179
enabling, 75
entries, tagging, 129
exporting, 207
file location, browser interface, 123–124
Google searches, 226
graphics, displaying in pop-up window, 150
list, requesting, 250–252
pinging, 75–76
receiving from other weblogs
described, 182–186
import fields, 238–240
Metaweblog API (metaweblog.newPost), 261
template tags, 196–197
text, formatting as, 117
weblog, configuring, 53
user
activity log, 62
database, specifying, 40
menu after logging in, 51
misuse of TypeKey, 164
search instructions, providing, 222
TypeKey, signing in, 160–163
with web authoring privileges, 382–383
user interface. See also API (application programming interface); CGI (Common Gateway Interface) scripts
browser, 123–124
graphics file, 42
links, 377–380
user manual, 42
username
Blogger, returning, 259
changing, 51–52
UserTalk script, 241–243
UTC (Coordinated Universal Time), 342


Index_V

Team LiB

Index

V

verifying installation
Perl 5, 22–23
Web server, 31


Index_W

Team LiB

Index

W

w.bloggar client, 253–254
weather, local, 301, 302–303
Web browser
exported data, formatting, 201
file location, keeping in template, 123–124
JavaScript capability, needed, 3
Movable Type, controlling, 6
plug-ins, managing with, 376–377
PNG format, 99
QuickPost link, creating, 79–80
settings, checking, 6–7
sites listed, 4
Web content
advantages of using Movable Type, 2–4
Amazon, sharing, 308–311
Atom element, 340
Web content aggregator, trackback links
Movable Type category collecting, 193–195
other systems, 192–193
retrieving, 295
routing category to, 195–196
Web hosting service, 18
Web server
conditions, meeting, 21–22
database, setting up, 23–25
files, deleting uploaded, 14
graphics file, uploading, 100–102
Movable Type
ability to run on, 3
installing, 5–6
XML-RPC protocol, 254–255
Perl 5 installation, verifying, 22–23
Perl modules, setting up, 26–29
qotd, 303–306
read timeout error, 62
referrer tracking, 16
securing with CGIWrap, 29–32
TypePad hosting service, 21–22
verifying installation, 31
Webalizer Web server analysis program, 62
weblog
configuration
account, setting up, 51–52
activity logs, monitoring, 61–62
authors, adding other, 59–61
creative commons license, adopting, 56–59
first, creating, 52–54
Movable Type, first run of, 49–51
path directories, 54
software, licensing, 55–56
described, 2, 65
entries, filing in categories, 9
public programs, Movable Type versus, 3
publishing software, 4–5
trackback links, receiving from other, 182–186
writing, 8–9
weblog entry
categories
assigned, retrieving (mt.getPostCategories), 265
filing in, 9
setting or removing all (mt.setPostCategories), 265–266
container template tags, 133–136
data, retrieving with MySQL plug-ins, 286–287
deleting (blogger.deletePost), 257
described, 8
editing, 86–88
excerpt, 9, 71
exporting multi-line fields, 205–206
extended, 9
importing
from Blogger, 240–241
comments and trackback pings, 236–240
data, moving, 231–236
data to Movable Type, 244–246
described, 231
from Radio UserLand, 241–243
manipulating, 384–385
new, logging, 62
one or more recent, retrieving (blogger.getRecentPosts), 257–258
pings, displaying all, 197
QuickPost window, 78–80
replacing (blogger.editPost), 257
sending pings for each, 190–192
storable or publishable (blogger.newPost), 256
summary, 71
template tags, 125–136
weblog organization
archiving entries, 88–89
categorizing
described, 89–90
new, 90–92
Power Edit mode, 93–94
described, 83
editing entries, 86–88
publishing, 83–86
WebTrends Web server analysis program, 62
window, pop-up
adding entries, 78–80
calendars, 151–154
containers, 154–157
described, 150
trackbacks, 183–184
Windows (Microsoft)
database access, setting up, 39
Perl 5, checking for, 22, 23
Perl modules, installing, 28
text editor, editing configuration file, 37
XML-RPC clients, 254
Winer, Dave (XML-RPC creator), 248
wish lists, Amazon, 316–319
word processing tool, 253–254
Wordpad, 37
writing
Atom newsfeed syndication files, 345–349
for audience, 15–16
entry form, 70–72
plug-ins with Movable Type classes
described, 380–382
entries, manipulating, 384–385
objects, 383–384
weblog authors, 382–383
templates, with scripting tags, 295–300
weblog, 8–9, 70–72


Index_X

Team LiB

Index

X

XHTML (XML-based HTML markup language)
comments, 167
index templates incorporating, 109
search form, attaching, 215
text, formatting, 76–77, 103
XML (extensible markup language). See also newsfeeds
RDF, 184–185
RSD file, 109
syndication files
described, 322–325
HTML formatting, displaying permissible, 117
index template, 108
RSS 1.0 newsfeed, 330–334
RSS 2.0 newsfeed, 325–330
XML-RPC protocol
Blogger API calling methods
application key, acquiring, 259
author’s account information, retrieving (blogger.getUserInfo), 259
deleting entry (blogger.deletePost), 257
described, 255–256
entry, storable or publishable (blogger.newPost), 256
list of weblogs, retrieving (blogger.getUsersBlogs), 258
replacing existing entry (blogger.editPost), 257
retrieving one or more recent entries (blogger.getRecentPosts), 257–258
client software, connecting to Movable Type, 253–254
data, importing from other weblogs, 18
described, 247–249
Metaweblog API calling methods
described, 260–261
new entry (metaweblog.newPost), 261
recent entries, retrieving (metaweblog.getRecentPosts), 262–263
replacing entry (metaweblog.editPost), 262
retrieving entry (metaweblog.getPost), 262
uploading files to Web server (metaweblog.newMediaObject), 263
Movable Type API calling methods
defined categories, retrieving (mt.getCategoryList), 264–265
entry categories, setting or removing all (mt.setPostCategories), 265–266
entry’s assigned categories, retrieving (mt.getPostCategories), 265
filters, supported (mt.supportedTextFilters), 267
methods, supported (mt.supportedMethods), 267
rebuilding files (mt.publishPost), 264
titles, retrieving entry (mt.getRecentPostTitles), 266–267
trackback pings, retrieving (mt.getTrackbackPings), 266
request, sending, 249–251
response, receiving, 251–253
server, Movable Type’s, 254–255


Index_Y

Team LiB

Index

Y

Yahoo! stock quote data, 298


Index_Z

Team LiB

Index

Z

Zempt client, 254


List of Figures

Chapter 1: Publishing with Movable Type

Figure 1-1: Editing a weblog with Movable Type.
Figure 1-2: Defining what a user is permitted to do in Movable Type.
Figure 1-3: Composing a new entry in a weblog.
Figure 1-4: Generating a Web page from a template.
Figure 1-5: Deciding whether to allow comments for a weblog entry.
Figure 1-6: Working on multiple weblog entries in power-editing mode.

Chapter 2: Preparing a Web Server for Movable Type

Figure 2-1: Determining which Perl modules are present on a server.

Chapter 3: Installing Movable Type

Figure 3-1: Setting file permissions with an FTP client.
Figure 3-2: Looking for Perl modules used by Movable Type.
Figure 3-3: Setting up database records for a new Movable Type installation.

Chapter 4: Configuring a Weblog

Figure 4-1: Logging in to Movable Type.
Figure 4-2: Browsing the software’s Main Menu.
Figure 4-3: Configuring a weblog.
Figure 4-4: Setting an author’s permissions.
Figure 4-5: Monitoring Movable Type usage.

Chapter 5: Writing a Weblog Entry

Figure 5-1: Using a simplified entry-editing form.
Figure 5-2: Presenting a weblog entry on a Web page.
Figure 5-3: Publishing a site by rebuilding files from templates.
Figure 5-4: Using the full entry-editing form.
Figure 5-5: Reading a divided weblog entry.
Figure 5-6: Publishing articles and other longer text.
Figure 5-7: Creating a new weblog entry.
Figure 5-8: Writing an entry with QuickPost.
Figure 5-9: Creating a QuickPost link in a Web browser.

Chapter 6: Organizing a Weblog

Figure 6-1: Observing Movable Type as it rebuilds pages.
Figure 6-2: Noting the need for a site rebuild.
Figure 6-3: Rebuilding a weblog.
Figure 6-4: Using the entry filter.
Figure 6-5: Creating new entry categories.
Figure 6-6: Assigning the primary category to an entry.
Figure 6-7: Assigning additional entry categories.
Figure 6-8: Working on a weblog in power edit mode.

Chapter 7: Publishing Photographs and Other Files

Figure 7-1: Using Movable Type to publish a photoblog.
Figure 7-2: Displaying transparent (left) and nontransparent (right) graphics.
Figure 7-3: Choosing a file to upload.
Figure 7-4: Uploading a file to a specified subdirectory.
Figure 7-5: Publishing photos and other graphics.
Figure 7-6: Editing an entry containing a graphic.
Figure 7-7: Publishing nongraphical files.

Chapter 8: Producing Web Pages with Template Tags

Figure 8-1: Editing templates in Movable Type.
Figure 8-2: Creating a new index template.
Figure 8-3: Viewing a template-created Web page.
Figure 8-4: Linking to adjacent weblog entries on a page.

Chapter 9: Designing a Weblog with Templates

Figure 9-1: Viewing and editing a weblog’s templates.
Figure 9-2: Rebuilding weblog files from their templates.
Figure 9-3: Tracking the progress of a site rebuild.
Figure 9-4: Editing a template.
Figure 9-5: Creating archive pages from an archive template.
Figure 9-6: Generating archive pages from selected archive templates.
Figure 9-7: Displaying archive links as a monthly calendar.
Figure 9-8: Presenting full-page calendars.

Chapter 10: Offering Comments

Figure 10-1: Encouraging users to log in to TypeKey.
Figure 10-2: Signing in to TypeKey.
Figure 10-3: Making a comment after signing in to TypeKey.
Figure 10-4: Choosing a weblog’s comments settings.
Figure 10-5: Refining the settings for a weblog’s comments.
Figure 10-6: Customizing how comments are presented.
Figure 10-7: The page for managing visitor comments.
Figure 10-8: Viewing and editing visitor comments.
Figure 10-9: Tracking the use of IP addresses by comment authors.
Figure 10-10: Banning a TypeKey registered user from making comments.
Figure 10-11: Displaying comments on an entry page.

Chapter 11: Sharing Trackback Links

Figure 11-1: Presenting trackback links on a weblog.
Figure 11-2: Setting a weblog entry’s trackback policy.
Figure 11-3: Choosing a default trackback policy for new entries.
Figure 11-4: Deleting a trackback ping.
Figure 11-5: Managing a weblog’s banned IP list.
Figure 11-6: Watching as trackback pings are sent.
Figure 11-7: Displaying an entry’s trackback URL.
Figure 11-8: Specifying trackback URLs with an entry.
Figure 11-9: Collecting weblog content from multiple sites by means of trackback.
Figure 11-10: Setting up a category as a content aggregator.
Figure 11-11: Sending a category to a content aggregator.

Chapter 12: Backing Up a Weblog

Figure 12-1: Exporting data from a Movable Type weblog.
Figure 12-2: Spotting incorrectly exported data in a Web browser.
Figure 12-3: Creating a weblog export template.

Chapter 13: Adding Search Capabilities to a Weblog

Figure 13-1: Viewing results from a weblog search.
Figure 13-2: Offering search capabilities on a weblog.
Figure 13-3: Conducting an extended search.
Figure 13-4: Presenting search results.

Chapter 14: Importing Entries from Another Weblog

Figure 14-1: Creating a workspace for an export script.
Figure 14-2: Writing a new script.
Figure 14-3: Importing weblog data using Movable Type’s browser interface.

Chapter 15: Connecting to Movable Type with XML-RPC

Figure 15-1: Editing a Movable Type weblog entry with desktop software.

Chapter 16: Enhancing Movable Type with Plug-Ins

Figure 16-1: Viewing content produced with the MTOnThisDay plug-in.
Figure 16-2: Pulling trackback pings directly from a MySQL database.

Chapter 17: Presenting External Web Content with Plug-Ins

Figure 17-1: Displaying weather data on a page.
Figure 17-2: Creating a template module for use by MTRandomLine.
Figure 17-3: Presenting Amazon products on a weblog.
Figure 17-4: Presenting an actor’s credits.
Figure 17-5: Displaying a list of products.
Figure 17-6: Using product information throughout a Web page.
Figure 17-7: Displaying three lists in a table.

Chapter 18: Publishing RSS Syndication Files

Figure 18-1: Reading a syndicated XML newsfeed in a newsreader.

Chapter 20: Developing New Plug-Ins with Perl

Figure 20-1: Presenting stock quotes with plug-in tags.
Figure 20-2: Stopping a template rebuild with an error.

Chapter 21: Hooking into Movable Type with Plug-Ins

Figure 21-1: Managing plug-ins with a Web browser.
Figure 21-2: Calling scripts from an editing page in the browser.
Figure 21-3: Reading Movable Type’s Perl class documentation.

Appendix: Using Movable Type 3.1

Figure A-1: Choosing a template publishing policy.
Figure A-2: Editing a template’s publishing policy.
Figure A-3: Managing weblog categories and subcategories.


List of Tables

Chapter 1: Publishing with Movable Type

Table 1-1: Most Widely Used Standalone Weblog Tools†

Chapter 2: Preparing a Web Server for Movable Type

Table 2-1: Movable Type’s Database Tables in MySQL
Table 2-2: Perl Modules Required by Movable Type

Chapter 4: Configuring a Weblog

Table 4-1: Movable Type Licensing Options

Chapter 8: Producing Web Pages with Template Tags

Table 8-1: Global Tag Attributes
Table 8-2: Date Format Attribute Strftime Codes
Table 8-3: Date Language Attribute Values
Table 8-4: Global Template Tags
Table 8-5: MTEntries Tag Attributes
Table 8-6: MTEntries Element Tags
Table 8-7: Weblog Category Tags
Table 8-8: Weblog Archive Tags

Chapter 9: Designing a Weblog with Templates

Table 9-1: Calendar Tags

Chapter 10: Offering Comments

Table 10-1: Weblog Comment Tags

Chapter 11: Sharing Trackback Links

Table 11-1: Weblog Trackback Tags

Chapter 12: Backing Up a Weblog

Table 12-1: Single-Line Export Fields
Table 12-2: Multi-Line Import Fields
Table 12-3: Comment Export Fields
Table 12-4: Trackback Export Fields

Chapter 13: Adding Search Capabilities to a Weblog

Table 13-1: Search Script Configuration Settings
Table 13-2: MTGoogleSearch Tag Attributes
Table 13-3: MTGoogleSearchResult Property Attribute Values

Chapter 14: Importing Entries from Another Weblog

Table 14-1: Single-Line Import Fields
Table 14-2: Multi-Line Import Fields
Table 14-3: Comment Import Fields
Table 14-4: Trackback Import Fields

Chapter 15: Connecting to Movable Type with XML-RPC

Table 15-1: Movable Type XML-RPC Clients

Chapter 16: Enhancing Movable Type with Plug-Ins

Table 16-1: MTAuthors Plug-in Tags
Table 16-2: MTAuthors Plug-in Tags
Table 16-3: mt_author Database Fields
Table 16-4: mt_blog Database Fields
Table 16-5: mt_category Database Fields
Table 16-6: mt_placement Database Fields
Table 16-7: mt_comment Database Fields
Table 16-8: mt_entry Database Fields
Table 16-9: mt_ipbanlist Database Fields
Table 16-10: mt_log Database Fields
Table 16-11: mt_notification Database Fields
Table 16-12: mt_permission Database Fields
Table 16-13: mt_plugin Database Fields
Table 16-14: mt_session Database Fields
Table 16-15: mt_tbping Database Fields
Table 16-16: mt_trackback Database Fields
Table 16-17: mt_template Database Fields
Table 16-18: mt_templatemap Database Fields

Chapter 17: Presenting External Web Content with Plug-Ins

Table 17-1: MTRandomLine Tag Attributes
Table 17-2: MTAmazon Tag Attributes

Chapter 18: Publishing RSS Syndication Files

Table 18-1: RFC 822 Time Zone Codes

Chapter 19: Supporting the Atom Syndication Format and API

Table 19-1: Atom Feed Elements
Table 19-2: Atom Link Relationships
Table 19-3: Atom Entry Elements
Table 19-4: Atom API Rules

Chapter 20: Developing New Plug-Ins with Perl

Table 20-1: Useful Stash Objects and Values

Chapter 21: Hooking into Movable Type with Plug-Ins

Table 21-1: Fields of the MT::Author Class
Table 21-2: Fields of the MT::Blog Class
Table 21-3: Fields of the MT::Entry Class


List of Listings

Chapter 1: Publishing with Movable Type

Listing 1-1: A Web Page Template
Listing 1-2: A Web Page Produced from a Template
Listing 1-3: An RSS 2.0 Template

Chapter 5: Writing a Weblog Entry

Listing 5-1: A Weblog Entry in RSS 2.0
Listing 5-2: Formatted Entry Text

Chapter 8: Producing Web Pages with Template Tags

Listing 8-1: A Simple Index Template

Chapter 9: Designing a Weblog with Templates

Listing 9-1: Displaying an Image Pop-Up Window
Listing 9-2: Presenting Calendar Links

Chapter 10: Offering Comments

Listing 10-1: Displaying an Entry’s Comments
Listing 10-2: Reviewing Recent Comments

Chapter 11: Sharing Trackback Links

Listing 11-1: Trackback Pop-Up Window Script
Listing 11-2: A Trackback Entry’s RDF Data
Listing 11-3: Linking to an Entry’s Trackbacks
Listing 11-4: Displaying an Entry’s Trackback Pings

Chapter 12: Backing Up a Weblog

Listing 12-1: Movable Type Export File
Listing 12-2: A Weblog Export Template

Chapter 13: Adding Search Capabilities to a Weblog

Listing 13-1: A Simple Search Form in XHTML
Listing 13-2: The Same Search Form in HTML
Listing 13-3: A Full Search Form
Listing 13-4: Formatted Search Results
Listing 13-5: Publishing Google Search Results

Chapter 14: Importing Entries from Another Weblog

Listing 14-1: A Weblog Import File
Listing 14-2: Weblog Entry with Comments
Listing 14-3: Comments for an Existing Weblog Entry
Listing 14-4: Creating Import Data in Blogger
Listing 14-5: Creating Import Data in Radio UserLand

Chapter 15: Connecting to Movable Type with XML-RPC

Listing 15-1: An XML-RPC Request
Listing 15-2: An XML-RPC Response

Chapter 16: Enhancing Movable Type with Plug-Ins

Listing 16-1: Adding On This Day Archive Links to a Page
Listing 16-2: Retrieving Entries from the Database
Listing 16-3: Viewing Comments from Banned IP Addresses
Listing 16-4: Displaying a Yahoo! Stock Quote
Listing 16-5: Displaying Database Entries

Chapter 17: Presenting External Web Content with Plug-Ins

Listing 17-1: Displaying Book Data on a Web Page
Listing 17-2: An Actor’s Credit Page
Listing 17-3: A Product Information Page
Listing 17-4: A Product Picture Page
Listing 17-5: Displaying Product Lists

Chapter 18: Publishing RSS Syndication Files

Listing 18-1: Syndicated Weblog Entries in RSS 2.0
Listing 18-2: RSS 2.0 Index Template (index.xml)
Listing 18-3: RSS 1.0 Index Template (index.rdf)

Chapter 19: Supporting the Atom Syndication Format and API

Listing 19-1: A Sample Atom Index Template (atom.xml)
Listing 19-2: A Content Construct

Chapter 20: Developing New Plug-Ins with Perl

Listing 20-1: Linking to a Random Web Page
Listing 20-2: Displaying Stock Quotes from Yahoo!
Listing 20-3: Displaying Customized Stock Quotes
Listing 20-4: A Stock Quote Web Page Template
Listing 20-5: Filtering Excessive Links
Listing 20-6: Displaying Output on Business Days

Chapter 21: Hooking into Movable Type with Plug-Ins

Listing 21-1: Adding a Plug-In Action
Listing 21-2: Redirecting Visitors to Another URL

Appendix: Using Movable Type 3.1

Listing A-1: Viewing Dynamic Files with .htaccess


List of Sidebars

Chapter 1: Publishing with Movable Type

Finding a Host That’s Your Type

Chapter 2: Preparing a Web Server for Movable Type

Double-Checking the Installation

Chapter 4: Configuring a Weblog

Who Is Melody Nelson?
Setting Up Path Directories

Chapter 10: Offering Comments

Verifying a TypeKey Account

Team LiB
Previous Section