2d09d13e959429c4415e64cac44fa2ed63b8094f
[catagits/Catalyst-Controller-MovableType.git] / lib / Catalyst / Controller / MovableType.pm
1 package Catalyst::Controller::MovableType;
2 use Moose;
3 BEGIN { extends 'Catalyst::Controller::WrapCGI'; }
4 use utf8;
5 use namespace::autoclean;
6
7 has 'perl' => (is => 'rw', default => 'perl');
8
9 has 'mt_home' => (is => 'rw'); # /my/app/root/mt/
10
11 sub run_mt_script :Path {
12     my ($self, $c, $cgi_script) = @_;
13
14     my %mt_scripts
15         = map +($_ => 1),
16         qw( mt-add-notify.cgi
17             mt-atom.cgi
18             mt.cgi
19             mt-comments.cgi
20             mt-feed.cgi
21             mt-ftsearch.cgi
22             mt-search.cgi
23             mt-tb.cgi
24             mt-testbg.cgi
25             mt-upgrade.cgi
26             mt-wizard.cgi
27             mt-xmlrpc.cgi
28         ) # mt-config.cgi intentionally left out
29     ;
30
31     # http://www.movabletype.org/documentation/installation/install-movable-type.html#start-blogging states:
32     # Warning: because the mt-check.cgi script displays server details which could be useful to a hacker, it
33     # is recommended that this script be removed or renamed.
34     #
35     # Allow it only in debug mode.
36     $mt_scripts{'mt_check.cgi'} = 1 if ($c->debug());
37
38     $self->not_found() unless ($mt_scripts{$cgi_script});
39
40     $ENV{MT_HOME} = $self->mt_home;
41
42     $self->cgi_to_response($c, sub { 
43         system($self->perl, $self->mt_home.$cgi_script);
44     });
45 }
46
47 sub not_found :Private {
48     my ($self, $c) = @_;
49     $c->response->status(404);
50     $c->response->body('Not found!');
51     $c->detach();
52 }
53  
54 1;
55
56 __END__
57
58 =head1 NAME
59
60 Catalyst::Controller::MovableType - Run Movable Type through Catalyst
61
62 =head1 SYNOPSIS
63
64 package MyApp::Controller::Mt;
65
66 use Moose;
67 BEGIN {extends 'Catalyst::Controller::MT'; }
68 use utf8;
69
70 1;
71
72 =head1 INSTALLATION
73
74 Install Movable Type by extracting the zip into your template root directory.
75 Move mt-static to root/static/mt, and configure Movable Type accordingly.
76
77 =head1 DESCRIPTION
78
79 Runs Movable Type 5 through Catalyst.
80 Download Movable Type 5 from http://www.movabletype.org/
81
82 =head1 METHODS
83
84 =head2 run_mt_script
85
86 Runs the requested Movable Type .cgi script transparently with cgi_to_response.
87
88 =head2 not_found
89
90 Sets the response to a simple 404 Not found page. You can override this method
91 with your own.
92
93 =head1 BUGS
94
95 None known.
96
97 =head1 SEE ALSO
98
99 L<Catalyst::Controller::WrapCGI>
100
101 =head1 AUTHOR
102
103 Oskari 'Okko' Ojala <perl@okko.net>
104
105 =head1 CONTRIBUTORS
106
107 Matt S. Trout <mst@shadowcatsystems.co.uk>
108
109 =head1 COPYRIGHT & LICENSE
110
111 Copyright 2010 the above author(s).
112
113 This sofware is free software, and is licensed under the same terms as Perl itself.
114
115 =cut
116