###############################################################################
# BoardTemplates.pl #
###############################################################################
# Board Templates #
# Allows the admin to select templates for each board/category. #
# Version: 1.0 (YaBB 2.0/2.1) #
# Released: November 11th, 2005 #
# =========================================================================== #
# Written by AK108 for the YaBB community #
###############################################################################
# BoardTemplates Admin area, changes settings #
###############################################################################
if($action eq 'detailedversion') { return 1; }
LoadLanguage('BoardTemplates');
if(-e "$vardir/boardtemplatelist.txt") {require "$vardir/boardtemplatelist.txt";}
### Oddly, this isn't loaded. But I like the category order array, so I'm going to load it now.
require "$boardsdir/forum.master";
sub boardtemplates {
my($templatelist);
if($INFO{'updated'} == 1) {
$yymain .= qq~
~;
}
$yymain .= qq~
~;
$yytitle = 'Board Template Settings';
$action_area = 'boardtemplates';
&AdminTemplate;
exit;
}
sub boardtemplates2 {
my($settings);
# Write out the settings
# IMPORTANT TO ANYONE TRYING TO UNDERSTAND THIS SECTION!
# I change between qq~~; and q~~; so sometimes variables are interpeted and sometimes not.
# Pay close attention. It's confusing, but efficient.
# Board-level templates
$settings = q~%boardtemplate = (
~;
for($i = 0; $FORM{"boardname$i"}; $i++) {
if($FORM{"boardtemplate$i"}) {
$settings .= qq~'$FORM{"boardname$i"}', '$FORM{"boardtemplate$i"}',\n~;
}
}
$settings =~ s~,\n\Z~~s; # Clean out final comma -- I like my generated code clean
$settings .= q~
);
%cattemplate = (
~;
# Category loop
for($i = 0; $FORM{"catname$i"}; $i++) {
if($FORM{"cattemplate$i"}) {
$settings .= qq~'$FORM{"catname$i"}', '$FORM{"cattemplate$i"}',\n~;
}
}
$settings =~ s~,\n\Z~~s;
$settings .= q~
);~;
# Override setting
if($FORM{'overridemode'} !~ /\A(1|2)\Z/) {$FORM{'overridemode'} = 0;}
$settings .= qq~
\$templateoverridemode = \'$FORM{'overridemode'}\';
~;
# Logic to make it work
### First, we check if we're allowed to override.
### Then we change the user's template value, saving the original. We call WhatTemplate and then return the original value.
$settings .= q~
if($templateoverridemode == 0 || ($templateoverridemode == 1 && ${$uid.$username}{'template'} eq 'Forum default')) {
my($oldtemp) = ${$uid.$username}{'template'};
if($boardtemplate{$currentboard}) {${$uid.$username}{'template'} = $boardtemplate{$currentboard}; &WhatTemplate();}
elsif($cattemplate{$INFO{'catselect'}} || ${$uid.$currentboard}{'cat'}) {
${$uid.$username}{'template'} = $cattemplate{$INFO{'catselect'}} || $cattemplate{${$uid.$currentboard}{'cat'}};
&WhatTemplate();
}
${$uid.$username}{'template'} = $oldtemp;
}
1;~;
fopen(BOARDTEMPLATEUPDATE, ">$vardir/boardtemplatelist.txt") || &admin_fatal_error("$load_txt{23} $vardir/boardtemplatelist.txt: $!");
print BOARDTEMPLATEUPDATE $settings;
fclose(BOARDTEMPLATEUPDATE);
$yySetLocation = qq~$adminurl?action=boardtemplates;updated=1~;
&redirectexit;
}
1;