I have been starting to learn how the Movable Type APIs work as I learn Perl. One of the extensions that I want to write for Movable Type requires you to get some of the configuration data for the database and embed it into the PHP code of each page generated by Movable Type, so this is how you would get it. Nothing too big and fancy, and partially stolen from the documentation on the MT:ConfigMgr, but it's a practical example of how to get the configuration data.
#!C:\development\xampp\perl\bin\perl.exe -w
use strict;
my ($MT_DIR);
BEGIN {
if ($0 =~ m!(.*[/\\])!) {
$MT_DIR = $1;
}
else {
$MT_DIR = './';
}
unshift @INC, $MT_DIR . 'lib';
unshift @INC, $MT_DIR . 'extlib';
}
use MT;
print "Content-Type: text/html\n\n";
my $mt = MT->new(Config => $ENV{MT_HOME} . 'mt-config.cgi', Director => $ENV{MT_HOME});
my $cfg = MT::ConfigMgr->instance();
print "Host: " . $cfg->DBHost() . "<br/>";
print "Database: " . $cfg->Database() . "<br/>";
print "User: " . $cfg->DBUser() . "<br/>";
print "Password: " . $cfg->DBPassword() . "<br/>";


Leave a comment