Skip to content

Commit

Permalink
Added [noarchive] tagblock and lists date/time plan was written.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed May 4, 2002
1 parent 32f88a7 commit c8defca
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 16 deletions.
24 changes: 18 additions & 6 deletions IcculusFinger_archiveplans.pl
Expand Up @@ -85,6 +85,7 @@ sub run_external_updater {
1 while ($t =~ s/\[defaultsection=".*?"\](\n|\r\n|\b)//is);
1 while ($t =~ s/\[section=".*?"\](\n|\r\n|\b)(.*?)[\/section](\n|\r\n|\b)/$2/is);
1 while ($t =~ s/\[font(.*?)\](.*?)\[\/font\]/<font $1>$2<\/font>/is);
1 while ($t =~ s/\[noarchive\](.*?)\[\/noarchive\]/$1/is);

print(" parsed markup tags...\n") if $debug;
my $newssubj = "Notable .plan update from $u";
Expand Down Expand Up @@ -164,13 +165,14 @@ sub update_planfile {
my $modtime = (stat($filename))[9];
my $fdate = get_sqldate($modtime);
my $sql = '';
my $plantext = undef;

print(" * Examining $user\'s .planfile (modtime $fdate)...\n") if $debug;

$user = $link->quote($user);

# ... get date of the latest archived .plan ...
$sql = "select postdate from $dbtable_archive where username=$user" .
$sql = "select postdate, text from $dbtable_archive where username=$user" .
" order by postdate desc limit 1";
my $sth = $link->prepare($sql);
$sth->execute() or die "can't execute the query: $sth->errstr";
Expand Down Expand Up @@ -202,20 +204,30 @@ sub update_planfile {
print(" Matches archive timestamp. Skipping.\n") if $debug;
return;
} else {
print(" Newer revision needs archiving.\n") if $debug;
}
$plantext = read_plantext($link, $filename);
my $plancpy = $plantext;
# Ditch [noarchive][/noarchive] tag blocks and strcmp rest.
1 while ($row[1] =~ s/\[noarchive].*?\[\/noarchive\]//is);
1 while ($plancpy =~ s/\[noarchive].*?\[\/noarchive\]//is);
if ($row[1] ne $plancpy) {
print(" Newer revision needs archiving.\n") if $debug;
} else {
print(" Newer revision only changed [noarchive] section(s). Skipping.\n") if ($debug);
return;
}
}
}
$sth->finish();

my $t = read_plantext($link, $filename);
my $ftext = $link->quote($t);
$plantext = read_plantext($link, $filename) if (not defined $plantext);
my $ftext = $link->quote($plantext);
$sql = "insert into $dbtable_archive (username, postdate, text)" .
" values ($user, '$fdate', $ftext)";

$link->do($sql) or die "can't execute the query: $link->errstr";
print(" Revision added to archives.\n") if $debug;

run_external_updater(basename($filename), $fdate, $t);
run_external_updater(basename($filename), $fdate, $plantext);
}


Expand Down
56 changes: 46 additions & 10 deletions IcculusFinger_daemon.pl
Expand Up @@ -31,18 +31,20 @@
# Added "root" as a fakeuser.
# 2.0.2 : Added "time" and "ipaddr" fakeusers.
# 2.0.3 : Added "linkdigest" arg, and made it the default for text output.
# 2.0.4 : Added "noarchive" tagblocks and optional "plan written on"
# date/time output.
#-----------------------------------------------------------------------------

# TODO: Let [img] tags nest inside [link] tags.
# TODO: Make [center] tags attempt to format plain text.
# !!! TODO: Let [img] tags nest inside [link] tags.
# !!! TODO: Make [center] tags attempt to format plain text.


use strict; # don't touch this line, nootch.
use warnings; # don't touch this line, either.
use DBI; # or this. I guess. Maybe.

# Version of IcculusFinger. Change this if you are forking the code.
my $version = "v2.0.3";
my $version = "v2.0.4";


#-----------------------------------------------------------------------------#
Expand Down Expand Up @@ -108,6 +110,10 @@
# leave this blank or undef it, since that's confusing for everyone.
my $no_report_string = "[center][i]Nothing to report.[/i][/center]";

# List at the bottom of the finger output (above wittyremark) when the .plan
# was last updated?
my $show_revision_date = 1;

# This is the default title for the webpage. The user can override it with
# the [title] tag in their .plan file. Do not use HTML. You can specify an
# empty string (""), but not undef; however, you should REALLY have a
Expand Down Expand Up @@ -246,6 +252,7 @@
my $embed = 0;
my $do_link_digest = undef;


my $did_output_start = 0;
sub output_start {
my ($user, $host) = @_;
Expand Down Expand Up @@ -279,12 +286,20 @@ sub output_ending {

return if $embed;

my $revision = undef;
if (($show_revision_date) and (defined $archive_date)) {
$revision = "When this .plan was written: $archive_date";
}

if ($do_html_formatting) {
$revision = ((defined $revision) ? "$revision<br>\n" : '');

print <<__EOF__;
<hr>
<center>
<font size="-3">
$revision
$html_credits<br>
<i>$wittyremark</i>
</font>
Expand All @@ -294,6 +309,7 @@ sub output_ending {
} else {
# !!! FIXME : Make that ------ line fit the length of the strings.
print "-------------------------------------------------------------------------\n";
print "$revision\n" if (defined $revision);
print "$text_credits\n";
print "$wittyremark\n\n";
}
Expand Down Expand Up @@ -364,6 +380,27 @@ sub parse_args {
}


sub get_sqldate {
my $mtime = shift;
my @t = localtime($mtime);
$t[5] = "0000" . ($t[5] + 1900);
$t[5] =~ s/.*?(\d\d\d\d)\Z/$1/;
$t[4] = "00" . ($t[4] + 1);
$t[4] =~ s/.*?(\d\d)\Z/$1/;
$t[3] = "00" . $t[3];
$t[3] =~ s/.*?(\d\d)\Z/$1/;
$t[2] = "00" . $t[2];
$t[2] =~ s/.*?(\d\d)\Z/$1/;
$t[1] = "00" . $t[1];
$t[1] =~ s/.*?(\d\d)\Z/$1/;
$t[0] = "00" . $t[0];
$t[0] =~ s/.*?(\d\d)\Z/$1/;

return('' . ($t[5]) . '-' . ($t[4]) . '-' . ($t[3]) . ' ' .
($t[2]) . ':' . ($t[1]) . ':' . ($t[0]));
}


sub get_database_link {
if (not defined $dbpass) {
if (defined $dbpassfile) {
Expand Down Expand Up @@ -493,6 +530,7 @@ sub load_file {
if (not -f "$fname") { # this is NOT an error.
$output_text = "";
} else {
my $modtime = (stat($fname))[9];
if (not open(FINGER, '<', "$fname")) {
$errormsg = "Couldn't open planfile: $!";
} else {
Expand All @@ -501,6 +539,8 @@ sub load_file {
}
close(FINGER);
}

$archive_date = get_sqldate($modtime);
}

return($errormsg);
Expand Down Expand Up @@ -619,13 +659,6 @@ sub do_fingering {
1 while ($output_text =~ s/\[section=\".*?\"\](.*?)\[\/section\](\r\n|\n|\b)/$1/is);
}

if (defined $archive_date) {
$output_text = "[center][font size=\"-1\"][b][u]" .
"(Archived plan from $archive_date follows...)" .
"[/u][/b][/font][/center]\n\n\n" . $output_text;
}


if (($do_html_formatting) or ($is_web_interface)) {
# HTMLify some characters...
1 while ($output_text =~ s/</&lt;/s);
Expand Down Expand Up @@ -695,6 +728,9 @@ sub do_fingering {
1 while ($output_text =~ s/\[img=\"(.*?)\"\](.*?)\[\/img\]/$2/is);
}

# Ditch [noarchive][/noarchive] tags ... those are metadata.
1 while ($output_text =~ s/\[noarchive](.*?)\[\/noarchive\]/$1/is);

if ($do_html_formatting) {
# try to make URLs into hyperlinks in the HTML output.
1 while ($output_text =~ s/(?<!href=")(?<!src=")(?<!">)\b([a-zA-Z]+?:\/\/[-~=\w&\.\/?]+)/<a href="$1">$1<\/a>/);
Expand Down

0 comments on commit c8defca

Please sign in to comment.