############################################################################### # 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~
$boardtemplates_txt{11}

~; } $yymain .= qq~
~; # Build a list of the templates into a drop-down selector $templatelist .= qq~ ~; while (($curtemplate, $value) = each(%templateset)) { $templatelist .= qq~ ~; } # Loop through each board and display the selector for($i = 0; $i < @allboards; $i++) { my($board, $mytemplatelist, $mytemplate); $board = $allboards[$i]; # Use a regex to find out what template we're using. $mytemplate = $boardtemplate{$board} || 0; $mytemplatelist = $templatelist; $mytemplatelist =~ s/\~; } $yymain .= qq~ ~; # Loop through each category and display the selector for($i = 0; $i < @categoryorder; $i++) { my($cat, $mytemplatelist, $mytemplate); $cat = $categoryorder[$i]; # Use a regex to find out what template we're using. $mytemplate = $cattemplate{$cat} || 0; $mytemplatelist = $templatelist; $mytemplatelist =~ s/\~; } @overridecheck = (); $overridecheck[$templateoverridemode] = ' selected="selected"'; $yymain .= qq~
$boardtemplates_txt{1}
$boardtemplates_txt{2}
$board
$boardtemplates_txt{4}
$cat
$boardtemplates_txt{5}
$boardtemplates_txt{6}
$boardtemplates_txt{7}
~; $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;