Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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
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 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/';

opendir(my $dir, $boarddir) or die("Cannot open Boards directory $!");
my @files = grep(/\.txt\Z/, readdir($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);
        my ($id, $name, $user, $email, $datetime) = split(/\|/, $_);
        if($datetime =~ m#(\d+)/(\d+)/(\d+) at (\d\d:\d\d:\d\d)#){
            my $num = $1;
            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,

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>];


Comment on Display most recent post to a YaBB forum
Download Code
Replies are listed 'Best First'.
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/'; 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];

    Makeshifts last the longest.

Back to Code Catacombs

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2015-11-28 01:05 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (736 votes), past polls