root/branches/release-31/lib/MT/ArchiveType/Page.pm @ 1486

Revision 1486, 2.6 kB (checked in by bchoate, 21 months ago)

Refactoring of archive type publishing code into separate modules.

Line 
1# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
2# This program is distributed under the terms of the
3# GNU General Public License, version 2.
4#
5# $Id$
6
7package MT::ArchiveType::Page;
8
9use strict;
10use base qw( MT::ArchiveType::Individual );
11
12sub name {
13    return 'Page';
14}
15
16sub archive_label {
17    return MT->translate("PAGE_ADV");
18}
19
20# archive_title proved by MT::ArchiveType::Individual
21sub dynamic_template {
22    return 'page/<$MTEntryID$>';
23}
24
25sub entry_class {
26    return 'page';
27}
28
29sub template_params {
30    return {
31        archive_class     => "page-archive",
32        page_archive      => 1,
33        main_template     => 1,
34        archive_template  => 1,
35        page_template     => 1,
36        feedback_template => 1,
37    };
38}
39
40sub archive_file {
41    my $obj = shift;
42    my ( $ctx, %param ) = @_;
43    my $timestamp = $param{Timestamp};
44    my $file_tmpl = $param{Template};
45    my $blog      = $ctx->{__stash}{blog};
46    my $page      = $ctx->{__stash}{entry};
47
48    my $file;
49    Carp::croak("archive_file_for Page archive needs a page")
50      unless $page && $page->isa('MT::Page');
51    unless ($file_tmpl) {
52        my $basename = $page->basename();
53        my $folder   = $page->folder;
54        my $folder_path;
55        if ($folder) {
56            $folder_path = $folder->publish_path || '';
57            $file =
58              $folder_path ne '' ? $folder_path . '/' . $basename : $basename;
59        }
60        else {
61            $file = $basename;
62        }
63    }
64    return $file;
65}
66
67sub archive_group_iter {
68    my $obj = shift;
69    my ( $ctx, $args ) = @_;
70
71    require MT::Page;
72    my $blog_id = $ctx->stash('blog')->id;
73    my $iter    = MT::Page->load_iter(
74        {
75            blog_id => $blog_id,
76            status  => MT::Entry::RELEASE()
77        },
78        { sort => 'title', direction => 'ascend' }
79    );
80    return sub {
81        while ( my $entry = $iter->() ) {
82            return ( 1, entries => [$entry], entry => $entry );
83        }
84        undef;
85      }
86}
87
88sub default_archive_templates {
89    return [
90        {
91            label    => MT->translate('folder-path/page-basename.html'),
92            template => '%-c/%-f',
93            default  => 1
94        },
95        {
96            label =>
97              MT->translate('folder-path/page-basename/index.html'),
98            template => '%-c/%-b/%i'
99        },
100        {
101            label    => MT->translate('folder_path/page_basename.html'),
102            template => '%c/%f'
103        },
104        {
105            label =>
106              MT->translate('folder_path/page_basename/index.html'),
107            template => '%c/%b/%i'
108        },
109    ];
110}
111
1121;
Note: See TracBrowser for help on using the browser.