#!/perl/bin/perl.exe # John Breslin, 20000124 # For converting messages from wwwb to ubb print "Content-type: text/html\n\n"; # just in case someone runs it via cgi-bin $message_path = "e:/wwwboard/messages"; # where your wwwb files are kept $out_path = "e:/boards/Forum1"; # where your output ubb forum is $out_count = 1; # start off our 00000x.cgi file naming for the ubb forum opendir (MESSDIR, "$message_path"); @all_files = readdir(MESSDIR); closedir (MESSDIR); @message_files = grep(/\.html/, @all_files); if ($message_files[0] ne "") { foreach $message_file(@message_files) { # open all the message files my @message_data = &open_file("$message_path/$message_file"); ($message_number, $junk) = split(/\./, $message_file); @replies_text = @blank; # don't want any left over replies $reply_files = ""; # or file names $reply_count = 0; # set the number of replies to zero $reply_message = 0; # this is used to tell whether a message is a reply or not $name_found = 0; # this flag is used to tell us that the message poster has been identified foreach $message_line(@message_data) { # for each line in the message file $message_line =~ s/\|/|/sg; if ($name_found == 1) { if ($message_line =~ /In Reply to: /) { $reply_message = 1; # don't write a file for replies, just thread starters $name_found = 1; } else { $text = $message_line; # get the message content chop($text); $name_found = 0; } } if ($message_line =~ / (.*)<\/title>/) { $subject = "$1"; } if ($message_line =~ /Posted by <a href="mailto:(.*)">(.*)<\/a> on (.*) at (.*):<p>/) { $email = $1; $name = $2; $etad = $3; # convert the message from April 2, 2000 to 04-02-00 ($month_and_day, $year) = split(/, /, $etad); ($month_name, $day) = split(/ /, $month_and_day); $month_number = &monthnum($month_name); $month_number = sprintf("%2d", $month_number); $month_number =~tr/ /0/; $day = sprintf("%2d", $day); $day =~tr/ /0/; # convert the time from 15:55:00 to 3:55 PM $emit = $4; ($hour, $min, $sec) = split(/:/, $emit); &NormalTime; $name_found = 1; } if (($message_line =~ /Posted by (.*) on (.*) at (.*):<p>/) && ($name_found != 1)) { $email = ""; # no email address in this format $name = $1; $etad = $2; ($month_and_day, $year) = split(/, /, $etad); ($month_name, $day) = split(/ /, $month_and_day); $month_number = &monthnum($month_name); $month_number = sprintf("%2d", $month_number); $month_number =~tr/ /0/; $day = sprintf("%2d", $day); $day =~tr/ /0/; $emit = $3; ($hour, $min, $sec) = split(/:/, $emit); &NormalTime; $name_found = 1; } if ($message_line =~ /<!--responses: (.*)-->/) { $reply_files = $reply_files . " - $1.html"; $reply_text = &ReplyFile($1); # get a reply line for each matching response in original file push (@replies_text, $reply_text); # we need to open replies and add them to our existing data } } # end of cycling through lines in message file if ($reply_message == 0) { # if it is not a reply to a previous message, we write a file $out_counter = sprintf("%6d", $out_count); # add trailing zeroes to ubb message number $out_counter =~tr/ /0/; print "[UBB $out_counter.cgi] WWWB $message_file$reply_files\n\n"; $number_of_replies = 0; foreach $thisone(@replies_text) { $number_of_replies++; # we need the number of replies for the first line in the ubb message file } open (OUTFILE, ">$out_path/$out_counter.cgi") or die("Unable to open file"); print OUTFILE "A||||$number_of_replies||$name||$subject||||\n"; print OUTFILE "Z||000000||$name||$month_number-$day-$year||$hour:$min $AMPM||$email||$text||||reg||\n"; @replies_text = sort(@replies_text); for $reply_text(@replies_text) { $reply_count++; $reply_counter = sprintf("%6d", $reply_count); $reply_counter =~tr/ /0/; $reply_text =~ s/(.+?)\|\|Z\|\|REPLY_COUNTER/Z\|\|REPLY_COUNTER/isg; $reply_text =~ s/REPLY_COUNTER/$reply_counter/isg; print OUTFILE "$reply_text"; } $out_count++; } } } # end of iterating through message files sub open_file { my $file_path = shift; my @file_data = ""; if (-e "$file_path") { open (OPENED_FILE, "$file_path") or die("Unable to open $file_path."); @file_data = <OPENED_FILE>; close (OPENED_FILE); } else { @file_data = ""; } return(@file_data); } sub NormalTime { if ($hour < 12) { $AMPM = "AM"; } if ($hour > 12) { $hour = $hour - 12; $AMPM = "PM"; } if ($hour == 12) { $AMPM = "PM"; } if ($hour == 0) { $hour = "12"; } $hour = sprintf ("%2d", $hour); $hour =~tr/ /0/; } sub rNormalTime { if ($rhour < 12) { $rAMPM = "AM"; } if ($rhour > 12) { $rhour = $rhour - 12; $rAMPM = "PM"; } if ($rhour == 12) { $rAMPM = "PM"; } if ($rhour == 0) { $rhour = "12"; } $rhour = sprintf ("%2d", $rhour); $rhour =~tr/ /0/; } sub monthnum # Usage: $month_number = &monthnum($month_name) { local($name) = @_; local(%names) = ( 'JAN',1,'FEB',2,'MAR',3,'APR',4,'MAY',5,'JUN',6,'JUL',7,'AUG',8, 'SEP',9,'OCT',10,'NOV',11,'DEC',12); $name =~ tr/a-z/A-Z/; $name = substr($name,0,3); $names{$name}; } sub ReplyFile { my $reply_file = shift; my @rmessage_data = &open_file("$message_path/$reply_file.html"); $rname_found = 0; foreach $rmessage_line(@rmessage_data) { $rmessage_line =~ s/\|/|/sg; if ($rname_found == 1) { if ($rmessage_line =~ /In Reply to: <a href="(.*).html">/) { $rname_found = 1; } else { $rtext = $rmessage_line; chop($rtext); $rname_found = 0; } } if ($rmessage_line =~ /Posted by <a href="mailto:(.*)">(.*)<\/a> on (.*) at (.*):<p>/) { $remail = $1; $rname = $2; $retad = $3; ($rmonth_and_day, $ryear) = split(/, /, $retad); ($rmonth_name, $rday) = split(/ /, $rmonth_and_day); $rmonth_number = &monthnum($rmonth_name); $rmonth_number = sprintf("%2d", $rmonth_number); $rmonth_number =~tr/ /0/; $rday = sprintf("%2d", $rday); $rday =~tr/ /0/; $remit = $4; ($rhour, $rmin, $rsec) = split(/:/, $remit); $rold_hour = $rhour; &rNormalTime; $rname_found = 1; } if (($rmessage_line =~ /Posted by (.*) on (.*) at (.*):<p>/) && ($rname_found != 1)) { $remail = ""; $rname = $1; $retad = $2; ($rmonth_and_day, $ryear) = split(/, /, $retad); ($rmonth_name, $rday) = split(/ /, $rmonth_and_day); $rmonth_number = &monthnum($rmonth_name); $rmonth_number = sprintf("%2d", $rmonth_number); $rmonth_number =~tr/ /0/; $rday = sprintf("%2d", $rday); $rday =~tr/ /0/; $remit = $3; ($rhour, $rmin, $rsec) = split(/:/, $remit); $rold_hour = $rhour; &rNormalTime; $rname_found = 1; } } # we add in the date details so that we can sort them per date as per ubb, not by reply as # wwwboard can have replies out of chronological sequence $reply_text = "$ryear-$rmonth_number-$rday-$rold_hour:$rmin:$rsec||Z||REPLY_COUNTER||$rname||$rmonth_number-$rday-$ryear||$rhour:$rmin $rAMPM||$remail||$rtext||||reg||\n"; return($reply_text); }