21-7 アプリケーションの実装
451ページ
http://user-domain/mt/plugins/Test/test.cgi?__mode=main&_type=entry&blog_id=[ブログID]
test.cgi
#!/usr/bin/perl
use strict;
use warnings;
use lib '../../lib';
use lib '../../extlib';
use MT::Bootstrap App => 'Test::App';
App.pm
package Test::App;
use strict;
use base qw( MT::App );
sub init_request {
my $app = shift;
$app->SUPER::init_request(@_);
$app->add_methods( main => \&view );
$app->{ default_mode } = 'main';
$app->{ requires_login } = 0;
}
sub view {
my $app = shift;
my $q = $app->param;
my $id = $q->param('blog_id') || 2;
my $blog = MT::Blog->load($id);
my $type = $q->param('_type') || 'entry';
my $class = $app->model($type);
my ( $terms, $args );
$terms->{ blog_id } = $id;
$terms->{ status } = MT::Entry::RELEASE();
$args->{ sort } = 'created_on';
$args->{ limit } = 10;
$args->{ direction } = 'descend';
my @entries = $class->load ( $terms, $args );
my $param;
$param->{ page_title } = 'Test';
$param->{ blog_name } = $blog->name;
$param->{ object_type } = 'entry';
$param->{ entries } = \@entries;
$app->{ plugin_template_path } = 'tmpl';
$app->build_page( 'list_entry.tmpl', $param );
}
1;
454ページ
list_entry.tmpl
<html>
<head>
<title><mt:GetVar name="page_title" /></title>
<style type="text/css">
body { margin: 15px; font-size: 80%; font-family: Verdana, Arial, sans-serif; }
h1 { font-weight: normal; }
ul { font-size: 75%; }
</style>
</head>
<body>
<h1><mt:var name="blog_name" /><h1>
<mt:loop name="entries">
<mt:if name="__first__">
<ul>
</mt:if>
<li><a href="<mt:GetVar name="mt_url" />?__mode=edit&_type=<mt:GetVar name="object_type" />&id=<mt:GetVar name="id" />&blog_id=<mt:GetVar name="blog_id" />">
<mt:GetVar name="title" /></a></li>
<mt:if name="__last__">
</ul>
</mt:if>
</mt:loop>
</body>
</html>