#!/usr/bin/perl -w
# Copyright 2006 Byrne Reese.
use CGI qw(:standard);
use LWP::Simple;
use strict;
sub BEGIN {
my $dir;
require File::Spec;
if (!($dir = $ENV{MT_HOME})) {
if ($0 =~ m!(.*[/\\])!) {
$dir = $1;
} else {
$dir = './';
}
$ENV{MT_HOME} = $dir;
}
unshift @INC, File::Spec->catdir($dir, 'lib');
unshift @INC, File::Spec->catdir($dir, 'extlib');
}
local $| = 1;
my $mt;
eval {
require MT;
$mt = MT->new();
};
my $app = MT->instance;
use MT::L10N;
my $LH = $mt ? $mt->language_handle : MT::L10N->get_handle('en_US');
sub trans_templ {
my($text) = @_;
return $mt->translate_templatized($text) if $mt;
$text =~ s!(]+?>|[^\3]+?)+?\3))+?\s*/?>)!
my($msg, %args) = ($1);
#print $msg;
while ($msg =~ /\b(\w+)\s*=\s*(["'])((?:<[^>]+?>|[^\2])*?)\2/g) { #"
$args{$1} = $3;
}
$args{params} = '' unless defined $args{params};
my @p = map MT::Util::decode_html($_),
split /\s*%%\s*/, $args{params};
@p = ('') unless @p;
my $translation = translate($args{phrase}, @p);
$translation =~ s/([\\'])/\\$1/sg if $args{escape};
$translation;
!ge;
$text;
}
sub translate {
return $mt->translate(@_) if $mt;
$LH->maketext(@_);
}
my $charset = $LH->encoding;
print "Content-Type: text/html; charset=$charset\n\n";
print trans_templ(<
HTML
if (param('check')) {
my $plugin_dir = File::Spec->catfile($mt->mt_dir,'plugins');
my $static = param('static_path');
my $static_dir = File::Spec->catfile($static,'plugins');
my $tmpl_dir = File::Spec->catfile($mt->{cfg}->TemplatePath);
my $lib_dir = File::Spec->catfile($mt->mt_dir,'lib');
my $alt_dir = File::Spec->catfile($mt->mt_dir,'alt-tmpl','cms');
# print "Plugins directory: " . $plugin_dir . "
";
# print "Static directory: " . $static_dir . "
";
# print "Template directory: " . $tmpl_dir . "
";
# print "Lib directory: " . $lib_dir . "
";
my $success = '✔';
my $fail = '✘';
my @prereqs;
push @prereqs, { label => 'Movable Type 3.3 or greater (you have '.$mt->version_number().')',
test => $mt->version_number() >= 3.3 };
push @prereqs, { label => 'Archive::Extract',
test => eval { require Archive::Extract; } };
push @prereqs, { label => 'File::Copy',
test => eval { require File::Copy; } };
push @prereqs, { label => 'File::Temp',
test => eval { require File::Temp; } };
push @prereqs, { label => 'File::Copy::Recursive',
test => eval { require File::Copy::Recursive; } };
push @prereqs, { label => 'File::Basename installed',
test => eval { require File::Basename; } };
push @prereqs, { label => 'File::Spec',
test => eval { require File::Spec; } };
push @prereqs, { label => 'File::Find',
test => eval { require File::Find; } };
push @prereqs, { label => 'File::Path',
test => eval { require File::Path; } };
push @prereqs, { label => 'LWP::Simple',
test => eval { require LWP::Simple; } };
push @prereqs, { label => 'XML::Simple',
test => eval { require XML::Simple; } };
my @perms;
push @perms, { label => "Template directory ($tmpl_dir)",
test => (-w $tmpl_dir) };
push @perms, { label => "Alt-Template directory ($alt_dir)",
test => (-w $alt_dir) };
push @perms, { label => "Plugin directory ($plugin_dir)",
test => (-w $plugin_dir) };
push @perms, { label => "Static files directory ($static_dir)",
test => (-w $static_dir) };
print trans_templ(<
INFO
my $proceed = 1;
foreach (@prereqs) {
if ($_->{test}) {
print "- $success " . $_->{label} ." is installed.
\n";
} else {
print "- $fail " . $_->{label} ." is not installed.
\n";
}
$proceed = $_->{test} if $proceed;
}
print trans_templ(<
INFO
foreach (@perms) {
if ($_->{test}) {
print "- $success " . $_->{label} ." is writable.
\n";
} else {
print "- $fail " . $_->{label} ." is not writable.
\n";
}
$proceed = $_->{test} if $proceed;
}
print trans_templ(<
INFO
if ($proceed) {
print trans_templ(<
INFO
} else {
print trans_templ(< .
INFO
}
} elsif (param('install')) {
my @files;
push @files, { file => 'app.css',
static => 1,
dest => File::Spec->catfile('plugins','PluginManager','styles') };
push @files, { file => 'app.js',
static => 1,
dest => File::Spec->catfile('plugins','PluginManager','js') };
push @files, { file => 'icon-uninstall.png',
static => 1,
dest => File::Spec->catfile('plugins','PluginManager','images') };
push @files, { file => 'indicator.gif',
static => 1,
dest => File::Spec->catfile('plugins','PluginManager','images') };
push @files, { file => 'icon-updates.png',
static => 1,
dest => File::Spec->catfile('plugins','PluginManager','images') };
push @files, { file => 'pm-icon32.gif',
static => 1,
dest => File::Spec->catfile('plugins','PluginManager','images') };
push @files, { file => 'header.tmpl',
dest => File::Spec->catfile('plugins','PluginManager','tmpl') };
push @files, { file => 'install.tmpl',
dest => File::Spec->catfile('plugins','PluginManager','tmpl') };
push @files, { file => 'preview.tmpl',
dest => File::Spec->catfile('plugins','PluginManager','tmpl') };
push @files, { file => 'list.tmpl',
dest => File::Spec->catfile('plugins','PluginManager','tmpl') };
push @files, { file => 'sanity.tmpl',
dest => File::Spec->catfile('plugins','PluginManager','tmpl') };
push @files, { file => 'check_ajax.tmpl',
dest => File::Spec->catfile('plugins','PluginManager','tmpl') };
push @files, { file => 'plugins.txt',
dest => File::Spec->catfile('plugins','PluginManager'),
dest_file => 'plugins.cgi',
perm => '0755' };
push @files, { file => 'PluginManager.txt',
dest_file => 'PluginManager.pl',
dest => File::Spec->catfile('plugins','PluginManager') };
push @files, { file => 'Util.pm',
dest => File::Spec->catfile('plugins','PluginManager','lib','PluginManager') };
push @files, { file => 'Plugin.pm',
dest => File::Spec->catfile('plugins','PluginManager','lib','PluginManager') };
push @files, { file => 'CMS.pm',
dest => File::Spec->catfile('plugins','PluginManager','lib','PluginManager') };
push @files, { file => 'mtplugin.pkg',
dest => File::Spec->catfile('plugins','PluginManager') };
my $failed;
foreach my $file (@files) {
print "Installing $file->{file}... ";
my $destdir;
if ($file->{static}) {
$destdir = File::Spec->catfile(param('static_path'),$file->{dest});
} else {
$destdir = File::Spec->catfile($mt->mt_dir,$file->{dest});
}
my $dest = File::Spec->catfile($destdir,
($file->{dest_file} ? $file->{dest_file} : $file->{file}));
if (-e $dest && !(-w $dest)) {
print "failed. The file being installed ($dest) already exists and is not writable.
";
$failed = 1;
print "Installation aborted.
";
last;
}
my $src = 'http://www.majordojo.com/projects/pluginmanager/downloads/files/' .
$file->{file};
require File::Copy::Recursive;
File::Copy::Recursive::pathmk($destdir);
getstore($src,$dest) or die "Failed to get $src: ".$!;
chmod(oct($file->{perm}),$dest) if ($file->{perm});
if (-e $dest) {
print "ok.";
} else {
print "failed. The file being installed ($dest) could not be written to disk for some reason.";
$failed = 1;
print "Installation aborted.
";
last;
}
}
if (!$failed) {
my $path = $mt->{cfg}->CGIPath . "plugins/PluginManager/plugins.cgi";
my $static = param('static_path');
print trans_templ(<Success. You have installed Plugin Manager.
INFO
}
} else {
my $guess = File::Spec->catfile($mt->mt_dir,'mt-static');
print trans_templ(<Welcome to the Plugin Manager Installation Wizard
Plugin Manager automates the process of installing and upgrading
Movable Type plugins. To this end, Plugin Manager requires special
write access to a number of directories. One of those directories
is the location where static files are stored.
Below is the best guess at where this directory is located. If this
is not correct, click the "Change" link below and enter in the
correct path.
Select Your Static Web Path
INFO
}
print "\n\n\n";