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