How to grab configuration data programmatically in Movable Type

| 0 Comments

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

March 2010

Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Recent Entries

A window into the totalitarian mind of the left on freedom of religion
From Digg: Me: I'm not going to hold my breath waiting for the same liberal democrats who shriek about the…
Google's lossy compiler
Google's closure compiler service gets a little too frisky under ADVANCED_OPTIMIZATIONS. Original code: With advanced optimizations enabled, it was able…
The three purposes of the federal income tax law
Businesses will spend about 3.4 billion man-hours and individuals about 1.7 billion hours figuring out their taxes this year.…

Subscribe

Advertisements

OpenID accepted here Learn more about OpenID