File: DefaultTemplates.pm

package info (click to toggle)
movabletype-opensource 4.2.3-1%2Blenny3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 21,268 kB
  • ctags: 15,862
  • sloc: perl: 178,892; php: 26,178; sh: 161; makefile: 82
file content (424 lines) | stat: -rw-r--r-- 13,721 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
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id: DefaultTemplates.pm 3130 2008-10-24 00:53:02Z bchoate $

package MT::DefaultTemplates;

use strict;

=start
Registry storage format for default templates:

default_templates:
    index:
        # The identifier used here never changes for this
        # template. It is also unique.
        main_index:
            filename: (optional; defaults to <identifier>.mtml)
            label: Main Index (auto-translated)
            outfile: (applicable for index templates only)
            rebuild_me: (applicable for index templates only)

=cut

my $loaded = 0;
my $templates;
BEGIN {
    $templates = {
        'index' => {
            'main_index' => {
                label => 'Main Index',
                outfile => 'index.html',
                rebuild_me => 1,
            },
            'archive_index' => {
                label => 'Archive Index',
                outfile => 'archives.html',
                rebuild_me => 1,
            },
            'styles' => {
                label => 'Stylesheet',
                outfile => 'styles.css',
                rebuild_me => 1,
            },
            'javascript' => {
                label => 'JavaScript',
                outfile => 'mt.js',
                rebuild_me => 1,
            },
            'feed_recent' => {
                label => 'Feed - Recent Entries',
                outfile => 'atom.xml',
                rebuild_me => 1,
            },
            'rsd' => {
                label => 'RSD',
                outfile => 'rsd.xml',
                rebuild_me => 1,
            },
        },
        'individual' => {
            'entry' => {
                label => 'Entry',
                mappings => {
                    entry_archive => {
                        archive_type => 'Individual',
                    },
                },
            },
        },
        'page' => {
            'page' => {
                label => 'Page',
                mappings => {
                    page_archive => {
                        archive_type => 'Page',
                    },
                },
            },
        },
        'archive' => {
            'monthly_entry_listing' => {
                label => 'Monthly Entry Listing',
                mappings => {
                    monthly => {
                        archive_type => 'Monthly',
                    },
                },
            },
            'category_entry_listing' => {
                label => 'Category Entry Listing',
                mappings => {
                    category => {
                        archive_type => 'Category',
                    },
                },
            },
        },
        'system' => {
            'comment_response' => {
                label => 'Comment Response',
                description_label => 'Displays error, pending or confirmation message for comments.'
            },
            'comment_preview' => {
                label => 'Comment Preview',
                description_label => 'Displays preview of comment.',
            },
            'dynamic_error' => {
                label => 'Dynamic Error',
                description_label => 'Displays errors for dynamically published templates.',
            },
            'popup_image' => {
                label => 'Popup Image',
                description_label => 'Displays image when user clicks a popup-linked image.',
            },
            'search_results' => {
                label => 'Search Results',
                description_label => 'Displays results of a search.',
            },
        },
        'module' => {
            'banner_header' => {
                label => 'Banner Header',
            },
            'banner_footer' => {
                label => 'Banner Footer',
            },
            'entry_summary' => {
                label => 'Entry Summary',
            },
            'html_head' => {
                label => 'HTML Head',
            },
            'sidebar' => {
                label => 'Sidebar',
            },
            'comments' => {
                label => 'Comments',
            },
            'trackbacks' => {
                label => 'Trackbacks',
            },
        },
        'widget' => {
            'about_this_page' => {
                label => 'About This Page',
            },
            'archive_widgets_group' => {
                label => 'Archive Widgets Group',
            },
            'author_archive_list' => {
                label => 'Author Archives',
            },
            'current_author_monthly_archive_list' => {
                label => 'Current Author Monthly Archives',
            },
            'calendar' => {
                label => 'Calendar',
            },
            'category_archive_list' => {
                label => 'Category Archives',
            },
            'current_category_monthly_archive_list' => {
                label => 'Current Category Monthly Archives',
            },
            'creative_commons' => {
                label => 'Creative Commons',
            },
            'main_index_widgets_group' => {
                label => 'Home Page Widgets Group',
            },
            'monthly_archive_dropdown' => {
                label => 'Monthly Archives Dropdown',
            },
            'monthly_archive_list' => {
                label => 'Monthly Archives',
            },
            'pages_list' => {
                label => 'Page Listing',
            },
            'recent_assets' => {
                label => 'Recent Assets',
            },
            'powered_by' => {
                label => 'Powered By',
            },
            'recent_comments' => {
                label => 'Recent Comments',
            },
            'recent_entries' => {
                label => 'Recent Entries',
            },
            'search' => {
                label => 'Search',
            },
            'signin' => {
                label => 'Sign In',
            },
            'syndication' => {
                label => 'Syndication',
            },
            'tag_cloud' => {
                label => 'Tag Cloud',
            },
            'technorati_search' => {
                label => 'Technorati Search',
            },
            'date_based_author_archives' => {
                label => 'Date-Based Author Archives',
            },
            'date_based_category_archives' => {
                label => 'Date-Based Category Archives',
            },
            'openid' => {
                label => 'OpenID Accepted',
            },
        },
        'widgetset' => {
            '2column_layout_sidebar' => {
                order => 1000,
                label   => '2-column layout - Sidebar',
                widgets => [
                    'Search',
                    'About This Page',
                    'Home Page Widgets Group',
                    'Archive Widgets Group',
                    'Page Listing',
                    'Syndication',
                    'OpenID Accepted',
                    'Powered By',
                ],
            },
            '3column_layout_primary_sidebar' => {
                order => 1000,
                label   => '3-column layout - Primary Sidebar',
                widgets => [
                    'Archive Widgets Group',
                    'Page Listing',
                    'Syndication',
                    'OpenID Accepted',
                    'Powered By',
                ],
            },
            '3column_layout_secondary_sidebar' => {
                order => 1000,
                label   => '3-column layout - Secondary Sidebar',
                widgets => [
                    'Search',
                    'Home Page Widgets Group',
                    'About This Page',
                ],
            },
        },
        'global:module' => {
            'footer-email' => {
                label => 'Mail Footer',
            },
        },
        'global:email' => {
            'comment_throttle' => {
                label => 'Comment throttle',
            },
            'commenter_confirm' => {
                label => 'Commenter Confirm',
            },
            'commenter_notify' => {
                label => 'Commenter Notify',
            },
            'new-comment' => {
                label => 'New Comment',
            },
            'new-ping' => {
                label => 'New Ping',
            },
            'notify-entry' => {
                label => 'Entry Notify',
            },
            'recover-password' => {
                label => 'Password Recovery',
            },
            'verify-subscribe' => {
                label => 'Subscribe Verify',
            },
        },
    };
}

sub core_default_templates {
    return $templates;
}

sub load {
    my $class = shift;
    my ($terms) = @_;
    my $tmpls = $class->templates || [];
    if ($terms) {
        foreach my $key (keys %$terms) {
            @$tmpls = grep { $_->{$key} eq $terms->{$key} } @$tmpls;
        }
    }
    return wantarray ? @$tmpls : (@$tmpls ? $tmpls->[0] : undef);
}

sub templates {
    my $pkg = shift;
    my ($set) = @_;
    require File::Spec;

    # A set of default templates as returned by MT::Component->registry
    # yields an array of hashes.

    my @tmpl_path = $set ? ("template_sets", $set) : ("default_templates");
    my $all_tmpls = MT::Component->registry(@tmpl_path) || [];
    my $weblog_templates_path = MT->config('WeblogTemplatesPath');

    my (%tmpls, %global_tmpls);
    foreach my $def_tmpl (@$all_tmpls) {
        # copy structure, then run filter

        my $tmpl_hash;
        if ($def_tmpl->{templates} && ($def_tmpl->{templates} eq '*')) {
            $tmpl_hash = MT->registry("default_templates");
        }
        else {
            $tmpl_hash = $set ? $def_tmpl->{templates} : $def_tmpl;
        }
        my $plugin = $tmpl_hash->{plugin};

        foreach my $tmpl_set (keys %$tmpl_hash) {
            next unless ref($tmpl_hash->{$tmpl_set}) eq 'HASH';
            foreach my $tmpl_id (keys %{ $tmpl_hash->{$tmpl_set} }) {
                next if $tmpl_id eq 'plugin';
                my $p = $tmpl_hash->{plugin} || $tmpl_hash->{$tmpl_set}{plugin};
                my $base_path = $def_tmpl->{base_path} || $tmpl_hash->{$tmpl_set}{base_path};
                if ($p && $base_path) {
                    $base_path = File::Spec->catdir($p->path, $base_path);
                }
                else {
                    $base_path = $weblog_templates_path;
                }

                my $tmpl = { %{ $tmpl_hash->{$tmpl_set}{$tmpl_id} } };
                my $type = $tmpl_set;
                if ($tmpl_set =~ m/^global:/) {
                    $type =~ s/^global://;
                    $tmpl->{global} = 1;
                }
                $tmpl->{set} = $type; # system, index, archive, etc.
                $tmpl->{order} = 0 unless exists $tmpl->{order};

                $type = 'custom' if $type eq 'module';
                $type = $tmpl_id if $type eq 'system';
                my $name = $tmpl->{label};
                $name = $name->() if ref($name) eq 'CODE';
                $tmpl->{name} = $name;
                $tmpl->{type} = $type;
                $tmpl->{key} = $tmpl_id;
                $tmpl->{identifier} = $tmpl_id;

                if ( exists $tmpl->{widgets} ) {
                    my $widgets = $tmpl->{widgets};
                    my @widgets;
                    foreach my $widget ( @$widgets ) {
                        if ( $plugin ) {
                            push @widgets, $plugin->translate( $widget );
                        }
                        else {
                            push @widgets, MT->translate( $widget );
                        }
                    }
                    $tmpl->{widgets} = \@widgets if @widgets;
                } else {
                    # load template if it hasn't been loaded already
                    if (!exists $tmpl->{text}) {
                        local (*FIN, $/);
                        my $filename = $tmpl->{filename} || ($tmpl_id . '.mtml');
                        my $file = File::Spec->catfile($base_path, $filename);
                        if ((-e $file) && (-r $file)) {
                            open FIN, "<$file"; my $data = <FIN>; close FIN;
                            $tmpl->{text} = $data;
                        } else {
                            $tmpl->{text} = '';
                        }
                    }
                }

                my $local_global_tmpls = $tmpl->{global} ? \%global_tmpls : \%tmpls;
                my $tmpl_key = $type . ":" . $tmpl_id;
                if (exists $local_global_tmpls->{$tmpl_key}) {
                    # allow components/plugins to override core
                    # templates
                    $local_global_tmpls->{$tmpl_key} = $tmpl if $p && ($p->id ne 'core');
                }
                else {
                    $local_global_tmpls->{$tmpl_key} = $tmpl;
                }
            }
        }
    }
    my @tmpls = (values(%tmpls), values(%global_tmpls));
    @tmpls = sort { $a->{order} <=> $b->{order} } @tmpls;
    MT->run_callbacks('DefaultTemplateFilter' . ($set ? '.' . $set : ''), \@tmpls);
    return \@tmpls;
}

1;
__END__

=head1 NAME

MT::DefaultTemplates

=head1 METHODS

=head2 templates()

Return the list of the templates in the WeblogTemplatesPath.

=head1 AUTHOR & COPYRIGHT

Please see L<MT/AUTHOR & COPYRIGHT>.

=cut