#!/usr/bin/perl use strict; use lib '/path/to/forum/admin'; use GT::CGI; use GT::SQL; use GForum::Template; use GT::Date qw/:all/; # path to GForum admin (no trailing slash) my $path = '/path/to/forum/admin'; # template set to be used my $templateset = 'default'; # set your favourite date format date_set_format("%d% %mmm% %yyyy%"); # number of recent links to display # this is used in case no other value n is passed by "recent.cgi?number=n" my $num = 5; ######################################################################## # No modifications below this line (unless you know what you are doing)! ######################################################################## # see how many recents posts have to be displayed my $in = new GT::CGI; if ($in->param('number') != 0) {$num = $in->param('number');} # get the details of the recents posts from the database my $db = new GT::SQL $path . '/defs'; my $post_db = $db->table ('Post'); $post_db->select_options('ORDER BY post_time DESC', "LIMIT $num"); my $sth = $post_db->select; my @output; my $date = date_get(); while (my $post = $sth->fetchrow_hashref) { $$post{'time_ago'} = time_ago($$post{'post_time'}); $$post{'post_time'} = date_get($$post{'post_time'}); push @output, $post; } # parse the temmplate and print it my $tpl = new GT::Template; print "Content-type: text/html\n\n"; $tpl->parse_print($path . '/templates/' . $templateset . '/external_display_recent_posts.html', {post_loop => \@output, number => $num, localtime=> $date}); # this subroutine return the time difference in a human readable form sub time_ago { my $post_time = shift; my $current_time = time(); my $time_diff = $current_time - $post_time; my $time_text = ''; if ($time_diff < 60) { if ($time_diff == 1) {$time_text = "One second";} else {$time_text = "$time_diff seconds";} } elsif ($time_diff < (60 * 60)) { my $minutes = int $time_diff/60; if ($minutes == 1) {$time_text = "One minute";} else {$time_text = "$minutes minutes";} } elsif ($time_diff < (60 * 60 * 48)) { my $hours = int $time_diff/(60*60); if ($hours == 1) {$time_text = "One hour";} else {$time_text = "$hours hours";} } elsif ($time_diff < (60 * 60 * 24 * 7)) { my $days = int $time_diff/(60*60*24); if ($days == 1) {$time_text = "$days day";} else {$time_text = "$days days";} } else {$time_text = "A while"} return "$time_text ago"; } 1;