<<

NAME

MT::WeblogPublisher - Express weblog templates and content into a specific URL structure

SYNOPSIS

    use MT::WeblogPublisher;
    my $pub = MT::WeblogPublisher->new;
    $pub->rebuild(Blog => $blog, ArchiveType => "Individual");

METHODS

MT::WeblogPublisher->new()

Return a new MT::WeblogPublisher. Additionally, call "instance" in MT::ConfigMgr and set the NoTempFiles and PublishCommenterIcon attributes, if not already set.

$mt->rebuild( %args )

Rebuilds your entire blog, indexes and archives; or some subset of your blog, as specified in the arguments.

%args can contain:

  • Blog

    An MT::Blog object corresponding to the blog that you would like to rebuild.

    Either this or BlogID is required.

  • BlogID

    The ID of the blog that you would like to rebuild.

    Either this or Blog is required.

  • ArchiveType

    The archive type that you would like to rebuild. This should be one of the following string values: Individual, Daily, Weekly, Monthly, or Category.

    This argument is optional; if not provided, all archive types will be rebuilt.

  • EntryCallback

    A callback that will be called for each entry that is rebuilt. If provided, the value should be a subroutine reference; the subroutine will be handed the MT::Entry object for the entry that is about to be rebuilt. You could use this to keep a running log of which entry is being rebuilt, for example:

        $mt->rebuild(
                  BlogID => $blog_id,
                  EntryCallback => sub { print $_[0]->title, "\n" },
              );

    Or to provide a status indicator:

        use MT::Entry;
        my $total = MT::Entry->count({ blog_id => $blog_id });
        my $i = 0;
        local $| = 1;
        $mt->rebuild(
                  BlogID => $blog_id,
                  EntryCallback => sub { printf "%d/%d\r", ++$i, $total },
              );
        print "\n";

    This argument is optional; by default no callbacks are executed.

  • NoIndexes

    By default rebuild will rebuild the index templates after rebuilding all of the entries; if you do not want to rebuild the index templates, set the value for this argument to a true value.

    This argument is optional.

  • Limit

    Limit the number of entries to be rebuilt to the last N entries in the blog. For example, if you set this to 20 and do not provide an offset (see Offset, below), the 20 most recent entries in the blog will be rebuilt.

    This is only useful if you are rebuilding Individual archives.

    This argument is optional; by default all entries will be rebuilt.

  • Offset

    When used with Limit, specifies the entry at which to start rebuilding your individual entry archives. For example, if you set this to 10, and set a Limit of 5 (see Limit, above), entries 10-14 (inclusive) will be rebuilt. The offset starts at 0, and the ordering is reverse chronological.

    This is only useful if you are rebuilding Individual archives, and if you are using Limit.

    This argument is optional; by default all entries will be rebuilt, starting at the first entry.

$mt->rebuild_entry( %args )

Rebuilds a particular entry in your blog (and its dependencies, if specified).

%args can contain:

  • Entry

    An MT::Entry object corresponding to the object you would like to rebuild.

    This argument is required.

  • Blog

    An MT::Blog object corresponding to the blog to which the Entry belongs.

    This argument is optional; if not provided, the MT::Blog object will be loaded in rebuild_entry from the $entry->blog_id column of the MT::Entry object passed in. If you already have the MT::Blog object loaded, however, it makes sense to pass it in yourself, as it will skip one small step in rebuild_entry (loading the object).

  • BuildDependencies

    Saving an entry can have effects on other entries; so after saving, it is often necessary to rebuild other entries, to reflect the changes onto all of the affected archive pages, indexes, etc.

    If you supply this parameter with a true value, rebuild_indexes will rebuild: the archives for the next and previous entries, chronologically; all of the index templates; the archives for the next and previous daily, weekly, and monthly archives.

  • Previous, Next, OldPrevious, OldNext

    These values identify entries which may need to be updated now that "this" entry has changed. When the authored_on field of an entry is changed, its new neighbors (Previous and Next) need to be rebuilt as well as its former neighbors (OldPrevious and OldNext).

  • NoStatic

    When this value is true, it acts as a hint to the rebuilding routine that static output files need not be rebuilt; the "rebuild" operation is just to update the bookkeeping that supports dynamic rebuilds.

$mt->rebuild_file($blog, $archive_root, $map, $archive_type, $ctx, \%cond, $build_static, %specifier)

Method responsible for building a single archive page from a template and writing it to the file management layer.

$blog refers to the target weblog. $archive_root is the target archive path to publish the file. $map is a MT::TemplateMap object that relates to publishing the file. $archive_type is one of "Daily", "Weekly", "Monthly", "Category" or "Individual". $ctx is a handle to the MT::Template::Context object to use to build the file. \%cond is a hashref to conditional arguments used to drive the build process. $build_static is a boolean flag that controls whether static files are created (otherwise, the records necessary for serving dynamic pages are created and that is all).

%specifier is a hash that uniquely identifies the specific instance of the given archive type. That is, for a category archive page it identifies the category; for a date-based archive page it identifies which time period is covered by the page; for an individual archive it identifies the entry. %specifier should contain just one of these keys:

  • Category

    A category ID or MT::Category instance of the category archive page to be built.

  • Entry

    An entry ID or MT::Entry instance of the entry archive page to be built.

  • StartDate

    The starting timestamp of the date-based archive to be built.

$mt->rebuild_indexes( %args )

Rebuilds all of the index templates in your blog, or just one, if you use the Template argument (below). Only rebuilds templates that are set to be rebuilt automatically, unless you use the Force (below).

%args can contain:

  • Blog

    An MT::Blog object corresponding to the blog whose indexes you would like to rebuild.

    Either this or BlogID is required.

  • BlogID

    The ID of the blog whose indexes you would like to rebuild.

    Either this or Blog is required.

  • Template

    An MT::Template object specifying the index template to rebuild; if you use this argument, only this index template will be rebuilt.

    Note that if the template that you specify here is set to not rebuild automatically, you must specify the Force argument in order to force it to be rebuilt.

  • Force

    A boolean flag specifying whether or not to rebuild index templates who have been marked not to be rebuilt automatically.

    The default is 0 (do not rebuild such templates).

$mt->trans_error

Call "translate" in MT.

$mt->make_commenter_icon

Make sure there is a nav-commenters.gif file under the blog site_path.

$mt->remove_entry_archive_file(%param)

Delete the archive files for an entry based on the following parameters. One of a Blog, Entry or Category are required.

  • Blog =item * Entry =item * Category =item * ArchiveType (Default 'Individual') =item * TemplateID

$mt->rebuild_categories(%param)

Rebuild category archives based on the following parameters:

  • Blog =item * BlogID =item * Limit =item * Offset =item * Limit =item * NoStatic

$mt->publish_future_posts

Build and publish all scheduled entries with a authored_on timestamp that is less than the current time.

CALLBACKS

BuildFileFilter

This filter is called when Movable Type wants to rebuild a file, but before doing so. This gives plugins the chance to determine whether a file should actually be rebuild in particular situations.

A BuildFileFilter callback routine is called as follows:

    sub build_file_filter($eh, %args)
    {
        ...
        return $boolean;
    }

As with other callback funcions, the first parameter is an MT::ErrorHandler object. This can be used by the callback to propagate an error message to the surrounding context.

The %args parameters identify the page to be built. See MT::FileInfo for more information on how a page is determined by these parameters. Elements in %args are as follows:

Context

Holds the template context that has been constructed for building (see MT::Template::Context).

ArchiveType

The archive type of the file, usually one of 'Index', 'Individual', 'Category', 'Daily', 'Monthly', or 'Weekly'.

Templatemap

An MT::TemplateMap object; this singles out which template is being built, and the filesystem path of the file to be written.

Blog

The MT::Blog object representing the blog whose pages are being rebuilt.

Entry

In the case of an individual archive page, this points to the MT::Entry object whose page is being rebuilt. In the case of an archive page other than an individual page, this parameter is not necessarily undefined. It is best to rely on the $at parameter to determine whether a single entry is on deck to be built.

PeriodStart

In the case of a date-based archive page, this is a timestamp at the beginning of the period from which entries will be included on this page, in Movable Type's standard 14-digit "timestamp" format. For example, if the page is a Daily archive for April 17, 1796, this value would be 17960417000000. If the page were a Monthly archive for March, 2003, $start would be 20030301000000. Again, this parameter may be defined even when the page on deck is not a date-based archive page.

Category

In the case of a Category archive, this parameter identifies the category which will be built on the page.

FileInfo

If defined, an MT::FileInfo object which contains information about the file. See MT::FileInfo for more information about what a MT::FileInfo contains. Chief amongst all the members of MT::FileInfo, for these purposes, will be the virtual member. This is a boolean value which will be false if a page was actually created on disk for this "page," and false if no page was created (because the corresponding template is set to be built dynamically).

It is possible for the FileInfo parameter to be undefined, namely if the blog has not been configured to publish anything dynamically, or if the installation is using a data driver that does not support dynamic publishing.

BuildPage

BuildPage callbacks are invoked just after a page has been built, but before the content has been written to the file system.

    sub build_page($eh, %args)
    {
    }

The parameters given are include those sent to the BuildFileFilter callback. In addition, the following parameters are also given:

Content

This is a scalar reference to the content that will eventually be published.

BuildResult / (or RawContent, deprecated)

This is a scalar reference to the content originally produced by building the page. This value is provided mainly for reference; modifications to it will be ignored.

BuildFile

BuildFile callbacks are invoked just after a file has been built.

    sub build_file($eh, %args)
    {
    }

Parameters in %args are as with BuildPage.

AUTHOR & COPYRIGHT

Please see "AUTHOR & COPYRIGHT" in MT.

<<