File: Page.pm

package info (click to toggle)
movabletype-opensource 5.1.4%2Bdfsg-4%2Bdeb7u3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 32,996 kB
  • sloc: perl: 197,285; php: 62,405; sh: 166; xml: 117; makefile: 83; sql: 32
file content (113 lines) | stat: -rw-r--r-- 2,789 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Movable Type (r) Open Source (C) 2001-2012 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id$

package MT::ArchiveType::Page;

use strict;
use base qw( MT::ArchiveType::Individual );

sub name {
    return 'Page';
}

sub archive_label {
    return MT->translate("PAGE_ADV");
}

# archive_title proved by MT::ArchiveType::Individual
sub dynamic_template {
    return 'page/<$MTEntryID$>';
}

sub entry_class {
    return 'page';
}

sub template_params {
    return {
        archive_class     => "page-archive",
        entry_archive     => 0,
        page_archive      => 1,
        archive_template  => 1,
        page_template     => 1,
        feedback_template => 1,
    };
}

sub archive_file {
    my $obj = shift;
    my ( $ctx, %param ) = @_;
    my $timestamp = $param{Timestamp};
    my $file_tmpl = $param{Template};
    my $blog      = $ctx->{__stash}{blog};
    my $page      = $ctx->{__stash}{entry};

    my $file;
    Carp::croak("archive_file_for Page archive needs a page")
        unless $page && $page->isa('MT::Page');
    unless ($file_tmpl) {
        my $basename = $page->basename();
        my $folder   = $page->folder;
        my $folder_path;
        if ($folder) {
            $folder_path = $folder->publish_path || '';
            $file
                = $folder_path ne ''
                ? $folder_path . '/' . $basename
                : $basename;
        }
        else {
            $file = $basename;
        }
    }
    return $file;
}

sub archive_group_iter {
    my $obj = shift;
    my ( $ctx, $args ) = @_;

    my $order
        = ( $args->{sort_order} || '' ) eq 'ascend' ? 'ascend' : 'descend';

    require MT::Page;
    my $blog_id = $ctx->stash('blog')->id;
    my $iter    = MT::Page->load_iter(
        {   blog_id => $blog_id,
            status  => MT::Entry::RELEASE()
        },
        {   'sort'    => 'authored_on',
            direction => $order,
            $args->{lastn} ? ( limit => $args->{lastn} ) : ()
        }
    );
    return sub {
        while ( my $entry = $iter->() ) {
            return ( 1, entries => [$entry], entry => $entry );
        }
        undef;
        }
}

sub default_archive_templates {
    return [
        {   label    => MT->translate('folder-path/page-basename.html'),
            template => '%-c/%-f',
            default  => 1
        },
        {   label    => MT->translate('folder-path/page-basename/index.html'),
            template => '%-c/%-b/%i'
        },
        {   label    => MT->translate('folder_path/page_basename.html'),
            template => '%c/%f'
        },
        {   label    => MT->translate('folder_path/page_basename/index.html'),
            template => '%c/%b/%i'
        },
    ];
}

1;