home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
FAQ
/
discus_admin_1357211388
/
source
/
topic-pg.pl
< prev
next >
Wrap
Text File
|
2009-11-06
|
6KB
|
175 lines
# FILE: topic-pg.pl
# DESCRIPTION: Generates and regenerates the board topics page
#-------------------------------------------------------------------------------
# DISCUS COPYRIGHT NOTICE
#
# Discus is copyright (c) 2002 by DiscusWare, LLC, all rights reserved.
# The use of Discus is governed by the Discus License Agreement which is
# available from the Discus WWW site at:
# http://www.discusware.com/discus/license
#
# Pursuant to the Discus License Agreement, this copyright notice may not be
# removed or altered in any way.
#-------------------------------------------------------------------------------
use strict;
use vars qw($GLOBAL_OPTIONS $DCONF $PARAMS);
###
### regenerate_topic_page
###
### Regenerate the board topics page
###
sub regenerate_topic_page {
my ($arg, $tree) = @_;
if (! $arg->{no_lock}) {
my $rv = &lock({ max => 1, no_error_message => 1 }, "$DCONF->{message_dir}/$DCONF->{board_topics_file}");
return 0 if $rv == 0;
}
$arg->{file} = read_topic_page(undef, $tree) if ! defined($arg->{file});
write_topic_page($arg->{file});
unlock("regenerate_topic_page", "$DCONF->{message_dir}/$DCONF->{board_topics_file}") if ! $arg->{no_unlock};
}
###
### read_topic_page
###
### Gets all kinds of information about the topics on the board
###
sub read_topic_page {
my ($args, $tree, $file_input) = @_;
undef my $pass;
$pass->{no_lock} = 1 if !$args->{lock};
$pass->{no_unlock} = 1 if !$args->{unlock};
if (defined $file_input) {
my @fi = ref $file_input eq 'ARRAY' ? @{$file_input} : ($file_input);
$file_input = \@fi;
}
my $file = defined $file_input ? $file_input : undef;
if (! defined($file)) {
if (! $DCONF->{pro} || (! $GLOBAL_OPTIONS->{secure_topics_file} && ! $GLOBAL_OPTIONS->{topics_to_show})) {
$file = readfile("$DCONF->{message_dir}/$DCONF->{board_topics_file}", "read_topic_page", $pass);
} else {
dreq("authwrap-PRO");
$file = wrapped_topics_file($pass);
}
}
undef my $result;
my $flag = 0;
$result->{'topics'} = board_topics(undef, $file, $tree);
foreach my $line (@{$file}) {
if ($line =~ m|^<!--Title Message-->|) {
$flag = 1;
} elsif ($line =~ m|^<!--/Title Message-->|) {
$flag = 0;
} elsif ($line =~ m|^<!--Message-->|) {
$flag = 2;
} elsif ($line =~ m|^<!--/Message-->|) {
$flag = 0;
} elsif ($flag == 1 || $flag == 2) {
next if ($line =~ m|^<!-Skip-!>| || $line =~ m|^<!--Skip-->|);
next if $line !~ m|\S|;
if ($line =~ m|^<hr>|i) {
$result->{'titlemsg'}->{'hr'} = 1 if $flag == 1;
$result->{'mainmsg'}->{'hr'} = 1 if $flag == 2;
next;
} elsif ($line =~ m|^<!--Source:|) {
next;
} elsif ($line !~ m|\S|) {
next;
} else {
chomp $line;
$result->{'titlemsg'}->{text} = $line if $flag == 1;
$result->{'mainmsg'}->{text} = $line if $flag == 2;
}
}
}
return $result;
}
###
### write_topic_page
###
### Writes the topic page
###
sub write_topic_page {
my ($arg, $zarg, $in_message_dir) = @_;
dreq("template");
hash_merge($arg, $zarg, 1);
my $subst = $arg;
bless $subst;
# $subst->{'color'}->{'bgcolor'} = $GLOBAL_OPTIONS->{'COLOR_bgcolor'};
# $subst->{'color'}->{'text'} = $GLOBAL_OPTIONS->{'COLOR_text'};
# $subst->{'color'}->{'link'} = $GLOBAL_OPTIONS->{'COLOR_link'};
# $subst->{'color'}->{'vlink'} = $GLOBAL_OPTIONS->{'COLOR_vlink'};
# $subst->{'color'}->{'alink'} = $GLOBAL_OPTIONS->{'COLOR_alink'};
# $subst->{'color'}->{'image'} = $GLOBAL_OPTIONS->{'COLOR_image'};
# $subst->{'color'}->{'face'} = $GLOBAL_OPTIONS->{'COLOR_face'};
# $subst->{'color'}->{'size'} = $GLOBAL_OPTIONS->{'COLOR_size'};
$subst->topic_page_board_info($arg->{topics});
$subst->{DYNAMIC}->{'server_time'} = time if $arg->{return_val};
my $text = templ_int("*topics", $subst);
return $text if $arg->{return_val};
my @text = ($text);
my $pass = {};
$pass->{no_lock} = 1 if !$arg->{lock};
$pass->{no_unlock} = 1 if !$arg->{unlock};
if ($in_message_dir || ! $DCONF->{pro} || (! $GLOBAL_OPTIONS->{secure_topics_file} && ! $GLOBAL_OPTIONS->{topics_to_show})) {
writefile("$DCONF->{message_dir}/$DCONF->{board_topics_file}", \@text, "write_topic_page", $pass);
} else {
dreq("authwrap-PRO");
wrapped_topics_file_write(\@text, $pass);
}
}
###
### topic_page_board_info
###
### For the Discus version, total messages, total messages displayed, registered users...
###
sub topic_page_board_info {
my $self = shift;
my $topics = shift;
undef my $i;
foreach my $l (@{ $topics }) {
$i->{topic_items_total} += 1;
if ($l->{type} == 1) {
$i->{topics_total} += 1;
if ($l->{lastmod} > $i->{last_post}) {
$i->{last_post} = $l->{lastmod};
$i->{last_poster} = $l->{last_poster};
}
$i->{messages_total} += $l->{posts};
$i->{pages_total} += $l->{subs};
if ($l->{hidden}) {
$i->{topics_hidden} += 1 if $l->{hidden};
} else {
$i->{topics_displayed} += 1;
$i->{messages_displayed} += $l->{posts};
$i->{pages_displayed} += $l->{subs};
if ($l->{lastmod} > $i->{last_post_visible}) {
$i->{last_post_visible} = $l->{lastmod};
$i->{last_poster_visible} = $l->{last_poster};
}
}
} else {
$i->{categories} + 1;
}
}
$i->{discus_version} = join(" ", "Discus", join(".", $PARAMS->{release}, $PARAMS->{revision}), ( $DCONF->{pro} == 1 ? "Pro" : "" ));
my $o = readfile("$DCONF->{admin_dir}/data/regusers.txt", "topic_page_board_info", { no_lock => 1, no_unlock => 1, create => 1 });
$i->{registered_users} = 0 + $o->[0]; chomp $i->{registered_users};
$self->{topicinfo} = hash_merge($self->{topicinfo}, $i, 1);
if ($GLOBAL_OPTIONS->{skinvar_board}) {
dreq("fcn-info");
board_info_topicinfo_save($topics, $self);
}
return $self;
}
1;