# Blosxom Plugin: mtexport # Author(s): James Vasile (james@brutalhugs.com) # Version: 0.1 # See the perldoc info at the bottom for more details package mtexport; # --- Configurable variables ----- # Author - replace Brutal Hugger with the author name used by your new blog system $author = "Brutal Hugger"; #The %categories hash is used to translate your blosxom directories into Movable Type categories. my %categories = ( "/category/subcategory" => "exact mt category name", "/category/second_subcategory" => "exact mt category name", "/category/subcategory/subcategory" => "different mt category name", #the below are some of the categories I used, and I include them as examples #"/math_and_science" => "Math and Science", #"/polis/terrorism" => "Polis" ); # writeback_dir is the directory your writebacks live in. Check your writebacks plugin and set # this to the same as that one. The default might be fine. If you don't have writebacks, set this to "" my $writeback_dir = "$blosxom::plugin_state_dir/writeback"; # What file extension should I use for writebacks? Check your writebacks plugin and set this to the same as there. # The defualt might be fine. my $file_extension = "wb"; # Disable trackback_counts_display - trackback_counts_display is incompatible with the export on # some (maybe all) systems, so we disable it when running mtexport. Set to 0 if you want to # enable tracback_counts_display (although when running mtexport, it has no effect, so I can't # see why you would want to do that). my $disable_trackback_counts_display = 1; #---------------EVERYTHING BELOW THIS LINE IS OF NO CONCERN TO THE AVERAGE USER---------------------- # --- Public Variables ---------------------------- $category; #this gets set to the category for each post and is used in the builtin template. You can ignore it. $comments; #this string gets all the writebacks formatted for export. You can ignore it. #---------------------------------------------------- use CGI qw/:standard/; use File::stat; my $cgi = new CGI; ########################################################### sub start { #return unless $cgi->param('mtexport') eq 'export'; return unless $blosxom::flavour eq 'mtexport'; $blosxom::num_entries=1000; return 1; } sub head { # Here's where we detect and disable the trackback_counts_display plugin. Hideously ugly! Look away! foreach my $plugin (@blosxom::plugins) { $blosxom::plugins{$plugin} = -1 if $plugin eq 'trackback_counts_display'; } } sub story { my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref, $ne) = @_; #match up the category with the path of the post foreach my $path_key (keys %categories) { $category = $categories{$path_key} if $path eq $path_key; } # More category sorting... left here as an example #$category = "Polis" if $path =~ /polis/; #$category = "Fun, Personal, Life" if $path =~ /life/; #$category = "Projects" if $path =~ /flavours/; #$category = "Projects" if $path =~ /trackback/; #$category = "Arts and Culture" if $path =~ /arts/; #if no match, just put the path in there so the user can see it (or should we default to no category?) $category = $path if $category eq ''; #handle writebacks - this is no fun, and I think there might be a better way to do it w/ flavours, but I have a headache and I'm stupid right now. my $fh = new FileHandle; $comments=''; if ( $fh->open("$writeback_dir$path/$filename.$file_extension") ) { my ($seconds, $minutes, $hours, $dom, $mon, $yr, $wday, $yday, $isdst) = localtime(stat("$writeback_dir$path/$filename.$file_extension")->mtime); $mon+=1; $yr+=1900; $seconds=0; foreach my $line (<$fh>) { $line =~ /^(.+?):(.*)$/ and $param{$1} = $2; if ( $line =~ /^-----$/ ) { $param{'comment'} =~ s/

/\n/; $param{'comment'} =~ s/^ //; $param{'excerpt'} =~ s/^ //; if ($param{'comment'} ne '') { # it's a ping my $url = $param{'url'} if $param{'url'} =~ /^http:\/\//; my $email = $param{'url'} if $url eq ''; $comments .= <