-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathPage.pm
228 lines (185 loc) · 6.83 KB
/
Page.pm
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# Movable Type (r) Open Source (C) 2001-2010 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id$
package MT::Page;
use strict;
use base qw( MT::Entry );
use MT::Util qw( archive_file_for );
__PACKAGE__->install_properties( {
class_type => 'page',
child_of => 'MT::Blog',
child_classes =>
[ 'MT::Comment', 'MT::Placement', 'MT::Trackback', 'MT::FileInfo' ],
}
);
# Callbacks: clean list of changed columns to only
# include versioned columns
MT->add_callback( 'api_pre_save.' . 'page',
1, undef, \&MT::Revisable::mt_presave_obj );
MT->add_callback( 'cms_pre_save.' . 'page',
1, undef, \&MT::Revisable::mt_presave_obj );
# Callbacks: object-level callbacks could not be
# prioritized and thus caused problems with plugins
# registering a post_save and saving
MT->add_callback( 'api_post_save.' . 'page',
9, undef, \&MT::Revisable::mt_postsave_obj );
MT->add_callback( 'cms_post_save.' . 'page',
9, undef, \&MT::Revisable::mt_postsave_obj );
__PACKAGE__->add_callback( 'post_remove', 0, MT->component('core'),
\&MT::Revisable::mt_postremove_obj );
sub list_props {
return {
id => { base => 'entry.id', order => 100, },
title => { base => 'entry.title', order => 200, },
author_name => { base => 'entry.author_name', order => 300, },
blog_name => {
base => '__common.blog_name',
display => 'default',
order => 400,
},
folder => {
base => 'entry.category',
label => 'Folder',
filter_label => 'Folder',
display => 'default',
view_filter => [ 'blog', 'website' ],
order => 500,
category_class => 'folder',
zero_state_label => '(root)',
},
folder_id => {
base => 'entry.category_id',
label => 'Folder',
filter_label => 'Folder',
display => 'default',
view_filter => [ 'blog', 'website' ],
order => 500,
category_class => 'folder',
zero_state_label => '(root)',
label_via_param => sub {
my $prop = shift;
my ($app) = @_;
my $id = $app->param('filter_val');
my $cat = MT->model('folder')->load($id);
my $label = MT->translate( 'Pages in folder: [_1]',
$cat->label . " (ID:" . $cat->id . ")", );
$prop->{filter_label} = MT::Util::encode_html($label);
$label;
},
},
created_on => { base => 'entry.created_on', order => 600, },
modified_on => {
order => 700,
base => 'entry.modified_on',
display => 'default',
},
comment_count => {
display => 'optional',
base => 'entry.comment_count',
order => 800,
},
ping_count => { base => 'entry.ping_count', order => 900, },
text => { base => 'entry.text' },
text_more => { base => 'entry.text_more' },
excerpt =>
{ base => 'entry.excerpt', display => 'none', label => 'Excerpt', },
authored_on =>
{ base => 'entry.authored_on', display => 'optional', },
status => {
base => 'entry.status',
single_select_options => [
{ label => MT->translate('Draft'), value => 1, },
{ label => MT->translate('Published'), value => 2, },
{ label => MT->translate('Scheduled'), value => 4, },
],
},
basename => { base => 'entry.basename' },
commented_on => { base => 'entry.commented_on' },
tag => { base => 'entry.tag', tag_ds => 'entry', },
current_user =>
{ base => 'entry.current_user', label => 'My Pages', },
author_status => { base => 'entry.author_status' },
current_context => { base => '__common.current_context' },
};
} ## end sub list_props
sub class_label {
return MT->translate("Page");
}
sub class_label_plural {
MT->translate("Pages");
}
sub container_label {
MT->translate("Folder");
}
sub container_type {
return "folder";
}
sub folder {
return $_[0]->category;
}
sub archive_file {
my $page = shift;
my $blog = $page->blog()
|| return $page->error(
MT->translate( "Load of blog failed: [_1]", MT::Blog->errstr ) );
return archive_file_for( $page, $blog, 'Page' );
}
sub archive_url {
my $page = shift;
my $blog = $page->blog()
|| return $page->error(
MT->translate( "Load of blog failed: [_1]", MT::Blog->errstr ) );
my $url = $blog->site_url || "";
$url .= '/' unless $url =~ m!/$!;
return $url . $page->archive_file(@_);
}
sub permalink {
my $page = shift;
return $page->archive_url(@_);
}
sub all_permalinks {
my $page = shift;
return ( $page->permalink(@_) );
}
1;
__END__
=head1 NAME
MT::Page - Movable Type page record
=head1 SYNOPSIS
use MT::Page;
my $page = MT::Page->new;
$page->blog_id($blog->id);
$page->author_id($author->id);
$page->title('Page title');
$page->text('Some text');
$page->save
or die $page->errstr;
=head1 DESCRIPTION
The C<MT::Page> class is a subclass of L<MT::Entry>. Pages are very similar
to entries, except that they are not published in a reverse-chronological
listing, typically. Pages are published into folders, represented by
L<MT::Folder> instead of categories.
=head2 MT::Page->class_label
Returns the localized descriptive name for this class.
=head2 MT::Page->class_label_plural
Returns the localized, plural descriptive name for this class.
=head2 MT::Page->container_label
Returns the localized phrase identifying the "container" type for
pages (ie: "Folder").
=head2 MT::Page->container_type
Returns the string "folder", which is the MT type identifier for
the L<MT::Folder> class.
=head2 $page->folder
Returns the L<MT::Folder> the page is assigned to.
=head2 $page->archive_file
Returns the filename for the published page.
=head2 $page->archive_url
Returns the permalink for the page, based on the site_url of the
blog, and folder assignment for the page.
=head2 $page->permalink
Returns the permalink for the page.
=head2 $page->all_permalinks
Returns the permalink for the page.
=cut