root/branches/release-30/lib/MT/DefaultTemplates.pm @ 1429

Revision 1429, 9.7 kB (checked in by bsmith, 21 months ago)

Atom becomes Recent Entries Feed with the departing of RSS. (Thx Atsushi for discovering the bug)

  • Property svn:keywords set to Id Revision
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::DefaultTemplates;
8
9use strict;
10
11=start
12Registry storage format for default templates:
13
14default_templates:
15    index:
16        # The identifier used here never changes for this
17        # template. It is also unique.
18        main_index:
19            filename: (optional; defaults to <identifier>.mtml)
20            label: Main Index (auto-translated)
21            outfile: (applicable for index templates only)
22            rebuild_me: (applicable for index templates only)
23
24=cut
25
26my $loaded = 0;
27my $templates;
28BEGIN {
29    $templates = {
30        'index' => {
31            'main_index' => {
32                label => 'Main Index',
33                outfile => 'index.html',
34                rebuild_me => 1,
35            },
36            'archive_index' => {
37                label => 'Archive Index',
38                outfile => 'archives.html',
39                rebuild_me => 1,
40            },
41            'styles' => {
42                label => 'Stylesheet',
43                outfile => 'styles.css',
44                rebuild_me => 1,
45            },
46            'javascript' => {
47                label => 'JavaScript',
48                outfile => 'mt.js',
49            },
50            'rsd' => {
51                label => 'RSD',
52                outfile => 'rsd.xml',
53                rebuild_me => 1,
54            },
55            'feed_recent' => {
56                label => 'Feed - Recent Entries',
57                outfile => 'atom.xml',
58                rebuild_me => 1,
59            },
60        },
61        'individual' => {
62            'entry' => {
63                label => 'Entry',
64                mappings => {
65                    entry_archive => {
66                        archive_type => 'Individual',
67                    },
68                },
69            },
70        },
71        'page' => {
72            'page' => {
73                label => 'Page',
74                mappings => {
75                    page_archive => {
76                        archive_type => 'Page',
77                    },
78                },
79            },
80        },
81        'archive' => {
82            'entry_listing' => {
83                label => 'Entry Listing',
84                mappings => {
85                    monthly => {
86                        archive_type => 'Monthly',
87                    },
88                    category_monthly => {
89                        archive_type => 'Category-Monthly',
90                    },
91                    author_monthly => {
92                        archive_type => 'Author-Monthly',
93                    },
94                    category => {
95                        archive_type => 'Category',
96                    },
97                },
98            },
99        },
100        'system' => {
101            'comment_response' => {
102                label => 'Comment Response',
103                description_label => 'Displays error, pending or confirmation message for comments.'
104            },
105            'comment_preview' => {
106                label => 'Comment Preview',
107                description_label => 'Displays preview of comment.',
108            },
109            'dynamic_error' => {
110                label => 'Dynamic Error',
111                description_label => 'Displays errors for dynamically published templates.',
112            },
113            'popup_image' => {
114                label => 'Popup Image',
115                description_label => 'Displays image when user clicks a popup-linked image.',
116            },
117            'search_results' => {
118                label => 'Search Results',
119                description_label => 'Displays results of a search.',
120            },
121        },
122        'module' => {
123            'categories' => {
124                label => 'Categories',
125            },
126            'comment_detail' => {
127                label => 'Comment Detail',
128            },
129            'comment_form' => {
130                label => 'Comment Form',
131            },
132            'comments' => {
133                label => 'Comments',
134            },
135            'entry_detail' => {
136                label => 'Entry Detail',
137            },
138            'entry_summary' => {
139                label => 'Entry Summary',
140            },
141            'entry_metadata' => {
142                label => 'Entry Metadata',
143            },
144            'tags' => {
145                label => 'Tags',
146            },
147            'footer' => {
148                label => 'Footer',
149            },
150            'header' => {
151                label => 'Header',
152            },
153            'sidebar_2col' => {
154                label => 'Sidebar - 2 Column Layout',
155            },
156            'sidebar_3col' => {
157                label => 'Sidebar - 3 Column Layout',
158            },
159            'sidebar' => {
160                label => 'Sidebar',
161            },
162            'trackbacks' => {
163                label => 'TrackBacks',
164            },
165            'page_detail' => {
166                label => 'Page Detail',
167            },
168        },
169        'global:module' => {
170            'footer-email' => {
171                label => 'Mail Footer',
172            },
173        },
174        'global:email' => {
175            'comment_throttle' => {
176                label => 'Comment throttle',
177            },
178            'commenter_confirm' => {
179                label => 'Commenter Confirm',
180            },
181            'commenter_notify' => {
182                label => 'Commenter Notify',
183            },
184            'new-comment' => {
185                label => 'New Comment',
186            },
187            'new-ping' => {
188                label => 'New Ping',
189            },
190            'notify-entry' => {
191                label => 'Entry Notify',
192            },
193            'recover-password' => {
194                label => 'Password Recovery',
195            },
196            'verify-subscribe' => {
197                label => 'Subscribe Verify',
198            },
199        },
200    };
201}
202
203sub core_default_templates {
204    return $templates;
205}
206
207sub load {
208    my $class = shift;
209    my ($terms) = @_;
210    my $tmpls = $class->templates || [];
211    if ($terms) {
212        foreach my $key (keys %$terms) {
213            @$tmpls = grep { $_->{$key} eq $terms->{$key} } @$tmpls;
214        }
215    }
216    return wantarray ? @$tmpls : (@$tmpls ? $tmpls->[0] : undef);
217}
218
219sub templates {
220    my $pkg = shift;
221    my ($set) = @_;
222    require File::Spec;
223
224    # A set of default templates as returned by MT::Component->registry
225    # yields an array of hashes.
226
227    my @tmpl_path = $set ? ("template_sets", $set) : ("default_templates");
228    my $all_tmpls = MT::Component->registry(@tmpl_path) || [];
229    my $weblog_templates_path = MT->config('WeblogTemplatesPath');
230
231    my (%tmpls, %global_tmpls);
232    foreach my $def_tmpl (@$all_tmpls) {
233        # copy structure, then run filter
234
235        my $tmpl_hash;
236        if ($def_tmpl->{templates} && ($def_tmpl->{templates} eq '*')) {
237            $tmpl_hash = MT->registry("default_templates");
238        }
239        else {
240            $tmpl_hash = $set ? $def_tmpl->{templates} : $def_tmpl;
241        }
242
243        foreach my $tmpl_set (keys %$tmpl_hash) {
244            next unless ref($tmpl_hash->{$tmpl_set}) eq 'HASH';
245            foreach my $tmpl_id (keys %{ $tmpl_hash->{$tmpl_set} }) {
246                next if $tmpl_id eq 'plugin';
247
248                my $p = $tmpl_hash->{plugin} || $tmpl_hash->{$tmpl_set}{plugin};
249                my $base_path = $def_tmpl->{base_path} || $tmpl_hash->{$tmpl_set}{base_path};
250                if ($p && $base_path) {
251                    $base_path = File::Spec->catdir($p->path, $base_path);
252                }
253                else {
254                    $base_path = $weblog_templates_path;
255                }
256
257                my $tmpl = { %{ $tmpl_hash->{$tmpl_set}{$tmpl_id} } };
258                my $type = $tmpl_set;
259                if ($tmpl_set =~ m/^global:/) {
260                    $type =~ s/^global://;
261                    $tmpl->{global} = 1;
262                }
263                $tmpl->{set} = $type; # system, index, archive, etc.
264
265                $type = 'custom' if $type eq 'module';
266                $type = $tmpl_id if $type eq 'system';
267                my $name = $tmpl->{label};
268                $name = $name->() if ref($name) eq 'CODE';
269                $tmpl->{name} = $name;
270                $tmpl->{type} = $type;
271                $tmpl->{key} = $tmpl_id;
272                $tmpl->{identifier} = $tmpl_id;
273
274                # load template if it hasn't been loaded already
275                if (!exists $tmpl->{text}) {
276                    local (*FIN, $/);
277                    my $filename = $tmpl->{filename} || ($tmpl_id . '.mtml');
278                    my $file = File::Spec->catfile($base_path, $filename);
279                    if ((-e $file) && (-r $file)) {
280                        open FIN, "<$file"; my $data = <FIN>; close FIN;
281                        $tmpl->{text} = $data;
282                    } else {
283                        $tmpl->{text} = '';
284                    }
285                }
286
287                my $local_global_tmpls = $tmpl->{global} ? \%global_tmpls : \%tmpls;
288                if (exists $local_global_tmpls->{$tmpl_id}) {
289                    # allow components/plugins to override core
290                    # templates
291                    $local_global_tmpls->{$tmpl_id} = $tmpl if $p && ($p->id ne 'core');
292                }
293                else {
294                    $local_global_tmpls->{$tmpl_id} = $tmpl;
295                }
296            }
297        }
298    }
299    my @tmpls = (values(%tmpls), values(%global_tmpls));
300    MT->run_callbacks('DefaultTemplateFilter' . ($set ? '.' . $set : ''), \@tmpls);
301    return \@tmpls;
302}
303
3041;
305__END__
306
307=head1 NAME
308
309MT::DefaultTemplates
310
311=head1 METHODS
312
313=head2 templates()
314
315Return the list of the templates in the WeblogTemplatesPath.
316
317=head1 AUTHOR & COPYRIGHT
318
319Please see L<MT/AUTHOR & COPYRIGHT>.
320
321=cut
Note: See TracBrowser for help on using the browser.