« August 2007 | Main | October 2007 »

September 17, 2007

Dynamic publishing in MovableType at NearlyFreeSpeech.NET

My web host, NearlyFreeSpeech.NET, has a rather unusual setup. The web root as seen by a Perl CGI script is very different from that seen by PHP. This leads to a problem in a MovableType-powered blog, which has its administrative web site written in Perl, and its customer-facing site written in PHP (when published dynamically - as a static site it's all HTML). However, it's nothing that a few edits to the source won't fix.

Note that in the code excerpts below I've included the preceding lines to indicate where the code should be placed, in case the line numbers are out. Also, the alterations are based on MovableType v4.01, but other releases of MT4 should be very similar.

  1. File cgi/lib/MT/App/CMS.pm. Here we alter the folder names written into mtview.php, the main dynamic viewing page -

    Line 16687:
    $cgi_path =~ s!/*$!!;
    #Fix Perl -> PHP folder
    $cgi_path =~ s|/home/|/nfsn/content/mySite/|;


    Line 16690:
    my $config = MT->instance->{cfg_file};
    #Fix Perl -> PHP folder
    $config =~ s|/home/|/nfsn/content/mySite/|;


    Note that if you edit these folder names directly in blog/mtview.php then your changes will be overwritten when your site is republished or if you change your publishing settings.

  2. File cgi/php/mt.php. Now another easy part. In here we just need to insert a line in a couple of places to change the folder retrieved from the config file from Perl to PHP form.

    Line 215: (This change might only be needed for SQLite databases) $cfg['dbdriver'] = strtolower($driver);

    //Fix Perl -> PHP folder for database
    $cfg['database'] = str_replace("/home/","/nfsn/content/mySite/",$cfg['database']);

    Line 338:
    function configure_paths($blog_site_path) {
    //Fix Perl -> PHP folder for templating
    $blog_site_path = str_replace("/home/","/nfsn/content/mySite/",$blog_site_path);


You might noticed a pattern from my last few blog entries. If you put them together you might get the impression that I've been trying to run a dynamically-published MovableType blog in SQLite3 at NearlyFreeSpeech.NET. Whilst this is true, I found that the end result was unbearably slow, so I've had to remain in the statically-published world.

Update 19 Sep 2007: I have found that enabling the dynamic publishing option Enable Conditional Retrieval speeds up the page display tremendously. The only documentation I've seen on that feature is too sparse for me to understand what it does or why it works so well. In contrast, Enable Dynamic Cache is self-explanatory, but I don't see why it makes no improvement to my site's speed at all. Still, this is good news, and makes dynamic publishing a viable option for me.

September 16, 2007

Dynamic publishing with SQLite 3 in MovableType

MovableType 4 has just been released, but it still hasn't been updated to let you publish dynamically with an SQLite 3 database (SQLite 2 is supported). This is an interesting omission, because dynamic publishing is the best option for low-volume sites, and SQLite 3 is an excellent choice for low volume sites.

PHP 5.1 with SQLite 3 support has been out since 2005, so the developer community, including me, has had plenty of time to get used to the change. Which brings me to the solution.

  1. Reactivate the administration option to publish dynamically

    In file /lib/MT/App/CMS.pm, comment out lines 13277-13280, like so (a '#' at the start of the line tells Perl to ignore the rest of that line):
    #if ( $app->config->ObjectDriver =~ qr/(db[id]::)?sqlite/i ) {
    # $param{hide_build_option} = 1
    # unless $app->config->UseSQLite2;
    #}

  2. Change the PHP calls from the old SQLite functions to the new PHP Data Objects (PDO) functions

    • File /php/lib/mtdb_sqlite.php

      Line 158:
      //$this->result = @sqlite_query($query,$this->dbh);
      $this->result = @$this->dbh->query($query);

      Line 188:
      //if ( $row = sqlite_fetch_array($this->result, SQLITE_ASSOC) )

      if ($row = $this->result->fetch(PDO::FETCH_ASSOC) )

    • File /php/extlib/ezsql/ezsql_sqlite.php

      Line 50:
      //$this->dbh = @sqlite_open($dbpath.$dbname);
      //if ( ! $this->dbh )
      //{
      // $this->print_error("Error","<ol><b>Error establishing a database!</b><li>Are you sure you have the correct path?<li>Are you sure that you have typed the correct database instance name?<li>Are you sure that the database is installed?</ol>");
      //}

      try {
      $this->dbh = new PDO("sqlite:$dbpath$dbname");
      } catch (PDOException $e) {
      $this->print_error($e->getMessage());
      }

      Line 168:

      //$handle = @sqlite_query($query,$this->dbh);
      $handle = $this->dbh->query($query);


      Line 239:

      //while ($row = sqlite_fetch_array($handle, SQLITE_ASSOC)) {
      while ($row = $handle->fetch(PDO::FETCH_ASSOC) ) {


Although there are many further SQLite 2 specific lines of code in MovableType, the above changes were all that were required to get my dynamic blog to work with my SQLite 3 database.

September 15, 2007

Rights of Indigenous Peoples

On Thursday the UN adopted the Declaration on Rights of Indigenous Peoples, which outlines their rights and outlaws discrimination against them. Although the declaration was overwhelmingly supported, it was opposed by some notable countries, namely Australia, Canada, New Zealand and the United States.

There's a good summary of the declaration, and the reasons that various countries voted against it, in the Wikipedia. The Australian position should be rectified soon, as the opposition have vowed to ratify it if they win government, which pollsters believe will happen this year. Canada's position has also been criticised by their opposition.

September 4, 2007

Child Lifers

I just watched an interesting Frontline documentary called When Kids Get Life (viewable online), about children who are treated as adults after they commit a crime, and are sentenced to life in prison without chance of parole. It's also discussed in The American Prospect. Below is the headline statistic:

September 2, 2007

SBS Funding from Ads

If you've been annoyed by the recent introduction of advertisements which break into SBS programming, then you might be further annoyed by how little money SBS earns from them:

The eminently non-annoying advertising between programs (which provides a handy buffer ensuring that the start of programs is not easily missed) brings in an additional $29 million.

The current government has been notoriously stingy in their arts funding. If they increased their funding of SBS in line with inflation then in-program advertising could be removed, and viewers would universally rejoice.