#!/usr/bin/perl
# Create HTML file with links to WordPress Blog titles and
# directory with text files for Blosxom blog
# Copyright 2009 - A. Zamora - All rights reserved
# URL for WordPress Blog
$blogurl = "http://example.com/blog";
# Directory for local storage of Blosxom text files (must end in slash)
$dir = 'C:/blosxom-txt/';
print <<"===END1";
Index to WordPress Blog Entries
Index to WordPress Blog Entries
===END1
@titles = ();
$recct = 0;
$postct = 0;
LINE:
while($line = <>) { # Read from SYSIN
if (length($line) < 50) {next LINE;}
chomp $line; # remove \n
$recct++;
if (index($line, 'INSERT INTO') > -1) {
$i = index($line,'wp_posts');
if (($i > 0) && ($i <16) ) { # wp_posts
($head, $tail) = split (/VALUES \(/, $line, 2);
($t1,$t2,$t3,$t4, $tail1) = split(', ',$tail, 5);
$linkd = $blogurl.'?p='.$t1;
$date1 = $t3;
$date1 =~ s/^'//; # remove leading apostrophe
$date1 =~ s/'$//; # remove trailing apostrophe
($dated, $time) = split(/ /, $date1, 2);
# tail1 has start of post
$tail2 = "x";
($post, $tail2) = split(/', /, $tail1, 2); # tail2 has beginning of title and link
# print $tail2,"\n";
if (length($post) < 50) {next LINE;}
($title, $tail3) = split(/', /, $tail2, 2);
# clean up title
$title =~ s/^'//; # remove leading apostrophe
$title =~ s/'$//; # remove trailing apostrophe
$title =~ s/\\'/'/; # unscape apostrophes in title
#print $tail3,"\n";
($t1,$t2,$t3,$t4,$t5,$t6,$blogentry,$t8,$t9,$date2,$tail4) = split(/, /, $tail3, 11);
$date2 =~ s/^'//; # remove leading apostrophe
$date2 =~ s/'$//; # remove trailing apostrophe
($date, $time2) = split(/ /, $date2, 2);
#print $tail4,"
\n";
($t1,$t2,$t3, $link, $t4,$revpost,$tail5) = split(/, /,$tail4,7);
$typ = "";
if (index($revpost,"revision") > -1) {$typ = "rev"}
if ( (length($link) > 10) && ($typ ne "rev") ) {
$link =~ s/^'//; # remove leading apostrophe
$link =~ s/'$//; # remove trailing apostrophe
# $titles[$postct] = ''.$title.' '.$date.'
'."\n";
$titles[$postct] = ''.$title.' '.$dated.'
'."\n";
#print '', $title, ' ', $date, '
', "\n";
#print $title, ", ", $date, ", ", $link, "\n";
$postct++;
# Generate text file in Blosxom folder with txt files
$blogentry =~ s/^'//; # remove leading apostrophe
$blogentry =~ s/'$//; # remove trailing apostrophe
if (length($blogentry) < 5) {print "NULL title for: $line",'
',"\n";}
if (length($date1) < 2) {print "NULL date: $date1",'
',"\n";}
if ($date1 eq 0) {print "Zero date: $date1",'
',"\n";}
open OUT1, ">",$dir.$blogentry.'.txt' or die "Cannot create file for: $title";
print OUT1 '',$title,'
',"\n";
print OUT1 'meta-creation_date: ',$date1,"\n";
$post =~ s/^'//; # remove leading apostrophe
$post =~ s/'$//; # remove trailing apostrophe
$post =~ s/\\'/'/g; # unscape apostrophes
$post =~ s/<\/p>\\r\\n/<\/p>\n/g;
$post =~ s/\\r\\n/
/g;
$post =~ s/\\r\\n
/\n
/g;
$post =~ s/\\r\\n<\/tr>/\n<\/tr>/g;
$post =~ s/\\r\\n| /\n | /g;
$post =~ s/\\r\\n<\/th>/\n<\/th>/g;
$post =~ s/\\r\\n | /\n | /g;
$post =~ s/\\r\\n<\/td>/\n<\/td>/g;
$post =~ s/\\r\\n/ \n/g;
print OUT1 $post,"\n";
close OUT1
}
} # wp_posts
}
} # end while($line = <>)
print "Number of records=$recct",' ',"\n";
print "Number of posts=$postct",' ',"\n";
for ($i=0; $i<$postct; $i++) {
print $titles[$postct-1-$i];
}
print <<"===END2";
===END2
1;
|