Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Display most recent post to a YaBB forum

by newrisedesigns (Curate)
on Jan 26, 2003 at 21:20 UTC ( #230048=sourcecode: print w/ replies, xml ) Need Help??

Category: Web Stuff
Author/Contact Info John J Reiser http://www.newrisedesigns.com
Description: This code (used in conjunction with Apache SSI) will display a link within a page to the most recently updated topic in your YaBB forum. See http://www.yabbforum.com for information and source to the YaBB message board.
#!/usr/bin/perl -w

use strict;
use HTTP::Date;

print "Content-type: text/html\n\n";

my %ref;

my $boarddir = './yabb/Boards';
my $boardurl = '/cgi-bin/yabb/YaBB.pl';

opendir(my $dir, $boarddir) or die("Cannot open Boards directory $!");
my @files = grep(/\.txt\Z/, readdir($dir));
closedir($dir);

my @months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );

my $file;
my $time;
foreach $file (@files){
    open(my $fh, "$boarddir/$file") or die("Cannot open File $!");
    flock($fh, 4);
    
    while(<$fh>){
        my ($id, $name, $user, $email, $datetime) = split(/\|/, $_);
        if($datetime =~ m#(\d+)/(\d+)/(\d+) at (\d\d:\d\d:\d\d)#){
            my $num = $1;
            $num--;
            my $month = $months[$num];
            $time = "$2 $month $3 $4 GMT";
            $datetime = str2time($time);
            my $board;
            if($file =~ /(\w+)\./){
                $board = $1;
            }
            $ref{$datetime} = ({
                'time' => $time,
                'num' => $id,
                'board' => $board,
                'description' => $name,
                });
        }
    }
    close($fh);
}

foreach(sort {$b <=> $a} keys %ref){
    my %link = %{ $ref{$_} };

    print qq[<div id="lastmbpost"><a href="$boardurl?board=$link{board
+};action=display;num=$link{num};start=1">$link{description}</a><br />
+was updated on $link{time}</div>];

    last;
}

Comment on Display most recent post to a YaBB forum
Download Code
Re: Display most recent post to a YaBB forum
by Aristotle (Chancellor) on Jan 26, 2003 at 23:10 UTC
    #!/usr/bin/perl -w use strict; use Fcntl qw(:flock); use constant MONTHS => qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); use constant DATE_RX => qr#(\d+)/(\d+)/(\d+) at (\d\d:\d\d:\d\d)#; print "Content-type: text/html\n\n"; my $boarddir = './yabb/Boards'; my $boardurl = '/cgi-bin/yabb/YaBB.pl'; chdir $boarddir or die "Cannot chdir to $boarddir: $!"; my @files = do { opendir my $dir, "." or die ("Cannot open Boards directory $!"); grep /\.txt\z/, readdir $dir; }; sub parse_time { require HTTP::Date; return unless @_ == 4; my $time = "$_[1] ".(MONTHS)[$_[0]-1]." $_[2] $_[3] GMT"; return ($time, HTTP::Date::str2time($time)); } my @data; for my $file (@files) { open my $fh, "<", $file or die "Cannot open file $file: $!"; flock $fh, LOCK_SH; my ($board) = $file =~ /(\w+)\./; while (<$fh>) { my ($id, $name, $user, $email, $datetime) = split /\|/; my ($time, $utime) = parse_date($datetime =~ DATE_RX); push @data, [ $utime, $board, $id, $name, $time ] if defined $utime; } } my @link = @{ sort { $a->[0] <=> $b->[0] } @data)[0] || [] }; printf qq{<div id="lastmbpost"><a href="%s?board=%d;action=display;num=%d +;start=1">%s</a><br />was updated on %s</div>}, $boardurl, @link[1..4];
    Untested.

    Makeshifts last the longest.

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://230048]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-09-02 23:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (34 votes), past polls