# FILE: fcn-info.pl
# DESCRIPTION: Board Information
#-------------------------------------------------------------------------------
# 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);

###
### board_info_substitutions
###
### Enhances page substitutions with data from various board information
### files, as required by selected options
###

sub board_info_substitutions {
	my ($subst) = @_;
	if ($GLOBAL_OPTIONS->{skinvar_board} == 1) {
		if (defined $PARAMS->{cache}->{boardinfo}) {
			$subst->{boardinfo} = $PARAMS->{cache}->{boardinfo};
		} else {
			my $d = readfile("$DCONF->{admin_dir}/data/boardinf.txt", "board_info_substitutions", { no_lock => 1, no_unlock => 1, zero_ok => 1, create => 1 });	
			my $h = {};
			foreach my $x (@{ $d }) {
				if ($x =~ m|^(\w+)=(.*)|) {
					$h->{$1} = unescape($2);
				}
			}
			$PARAMS->{cache}->{boardinfo} = $h;
			$subst->{boardinfo} = $h;			
		}		
	}
	return $subst;
}

###
### board_info_topicinfo_save
###
### Information on topics storage in a file
###

sub board_info_topicinfo_save {
	my ($topicdata, $X_in) = @_;
	dreq("topic-pg");
	my $X = defined $X_in ? $X_in : topic_page_board_info({}, $topicdata);
	my @d = ();
	foreach my $k (keys %{ $X->{topicinfo} }) {
		push @d, join("", $k, "=", escape($X->{topicinfo}->{$k}), "\n");
	}
	writefile("$DCONF->{admin_dir}/data/boardinf.txt", \@d, "board_info_topicinfo_save", { no_lock => 1, no_unlock => 1, zero_ok => 1, create => 1 });
	return $X->{topicinfo};
}

1;
