D:\WEBSITES\testbed\cgi-bin\yabb252\Sources\Subs.pl D:\WEBSITES\testbed\252_zip\sources\Subs_08_30\Subs.pl
############################################################################### ###############################################################################
# Subs.pl                                                                     # # Subs.pl                                                                     #
############################################################################### ###############################################################################
# YaBB: Yet another Bulletin Board                                            # # YaBB: Yet another Bulletin Board                                            #
# Open-Source Community Software for Webmasters                               # # Open-Source Community Software for Webmasters                               #
# Version:        YaBB 2.5.2                                                  # # Version:        YaBB 2.5.2                                                  #
# Packaged:       September 30, 2012                                          # # Packaged:       September 30, 2012                                          #
# Distributed by: http://www.yabbforum.com                                    # # Distributed by: http://www.yabbforum.com                                    #
# =========================================================================== # # =========================================================================== #
# Copyright (c) 2000-2012 YaBB (www.yabbforum.com) - All Rights Reserved.     # # Copyright (c) 2000-2012 YaBB (www.yabbforum.com) - All Rights Reserved.     #
# Software by:  The YaBB Development Team                                     # # Software by:  The YaBB Development Team                                     #
#               with assistance from the YaBB community.                      # #               with assistance from the YaBB community.                      #
############################################################################### ###############################################################################
   
$subsplver = 'YaBB 2.5.2 $Revision: 1.2 $'; $subsplver = 'YaBB 2.5.2 $Revision: 1.1 $';
if ($debug) { &LoadLanguage('Debug'); } if ($debug) { &LoadLanguage('Debug'); }
   
use subs 'exit'; use subs 'exit';
   
$yymain = ''; $yymain = '';
$yyjavascript = ''; $yyjavascript = '';
$langopt = ''; $langopt = '';
   
# set line wrap limit in Display. # set line wrap limit in Display.
$linewrap = 80; $linewrap = 80;
$newswrap = 0; $newswrap = 0;
   
# get the current date/time # get the current date/time
$date = int(time() + $timecorrection); $date = int(time() + $timecorrection);
   
# check if browser accepts encoded output # check if browser accepts encoded output
$gzaccept = $ENV{'HTTP_ACCEPT_ENCODING'} =~ /\bgzip\b/ || $gzforce; $gzaccept = $ENV{'HTTP_ACCEPT_ENCODING'} =~ /\bgzip\b/ || $gzforce;
   
# parse the query string # parse the query string
&readform; &readform;
   
$uid = substr($date, length($date) - 3, 3); $uid = substr($date, length($date) - 3, 3);
$session_id = $cookiesession_name; $session_id = $cookiesession_name;
   
$randaction = substr($date,0,length($date)-2); $randaction = substr($date,0,length($date)-2);
   
$user_ip = $ENV{'REMOTE_ADDR'}; $user_ip = $ENV{'REMOTE_ADDR'};
if ($user_ip eq "127.0.0.1") { if ($user_ip eq "127.0.0.1") {
   if    ($ENV{'HTTP_CLIENT_IP'}       && $ENV{'HTTP_CLIENT_IP'}       ne "127.0.0.1") { $user_ip = $ENV{'HTTP_CLIENT_IP'}; }    if    ($ENV{'HTTP_CLIENT_IP'}       && $ENV{'HTTP_CLIENT_IP'}       ne "127.0.0.1") { $user_ip = $ENV{'HTTP_CLIENT_IP'}; }
   elsif ($ENV{'X_CLIENT_IP'}          && $ENV{'X_CLIENT_IP'}          ne "127.0.0.1") { $user_ip = $ENV{'X_CLIENT_IP'}; }    elsif ($ENV{'X_CLIENT_IP'}          && $ENV{'X_CLIENT_IP'}          ne "127.0.0.1") { $user_ip = $ENV{'X_CLIENT_IP'}; }
   elsif ($ENV{'HTTP_X_FORWARDED_FOR'} && $ENV{'HTTP_X_FORWARDED_FOR'} ne "127.0.0.1") { $user_ip = $ENV{'HTTP_X_FORWARDED_FOR'}; }    elsif ($ENV{'HTTP_X_FORWARDED_FOR'} && $ENV{'HTTP_X_FORWARDED_FOR'} ne "127.0.0.1") { $user_ip = $ENV{'HTTP_X_FORWARDED_FOR'}; }
} }
   
if (-e "$yyexec.cgi") { $yyext = "cgi"; } if (-e "$yyexec.cgi") { $yyext = "cgi"; }
else { $yyext = "pl"; } else { $yyext = "pl"; }
if (-e "AdminIndex.cgi") { $yyaext = "cgi"; } if (-e "AdminIndex.cgi") { $yyaext = "cgi"; }
else { $yyaext = "pl"; } else { $yyaext = "pl"; }
   
sub automaintenance { sub automaintenance {
   my $maction = $_[0];    my $maction = $_[0];
   my $mreason = $_[1];    my $mreason = $_[1];
   if (lc($maction) eq "on") {    if (lc($maction) eq "on") {
       fopen (MAINT, ">$vardir/maintenance.lock");        fopen (MAINT, ">$vardir/maintenance.lock");
       print MAINT qq~Remove this file if your board is in maintenance for no reason\n~;        print MAINT qq~Remove this file if your board is in maintenance for no reason\n~;
       fclose (MAINT);        fclose (MAINT);
       if ($mreason eq "low_disk"){        if ($mreason eq "low_disk"){
           &LoadLanguage('Error');            &LoadLanguage('Error');
           &alertbox($error_txt{'low_diskspace'});            &alertbox($error_txt{'low_diskspace'});
       }        }
       $maintenance = 2 if !$maintenance;        $maintenance = 2 if !$maintenance;
   } elsif (lc($maction) eq "off") {    } elsif (lc($maction) eq "off") {
       unlink "$vardir/maintenance.lock" || &admin_fatal_error("cannot_open_dir","$vardir/maintenance.lock");        unlink "$vardir/maintenance.lock" || &admin_fatal_error("cannot_open_dir","$vardir/maintenance.lock");
       $maintenance = 0 if $maintenance == 2;        $maintenance = 0 if $maintenance == 2;
   }    }
} }
   
sub getnewid { sub getnewid {
   my $newid = $date;    my $newid = $date;
   while (-e "$datadir/$newid.txt") { ++$newid; }    while (-e "$datadir/$newid.txt") { ++$newid; }
   return $newid;    return $newid;
} }
   
sub undupe { sub undupe {
   my (@out,$duped,$check);    my (@out,$duped,$check);
   foreach $check (@_) {    foreach $check (@_) {
       $duped = 0;        $duped = 0;
       foreach (@out) { if ($_ eq $check) { $duped = 1; last; } }        foreach (@out) { if ($_ eq $check) { $duped = 1; last; } }
       if (!$duped) { push(@out, $check); }        if (!$duped) { push(@out, $check); }
   }    }
   return @out;    return @out;
} }
   
sub exit { sub exit {
   local $| = 1;    local $| = 1;
   local $\ = '';    local $\ = '';
   print '';    print '';
   wait if $child_pid;    wait if $child_pid;
   CORE::exit($_[0] || 0);    CORE::exit($_[0] || 0);
} }
   
sub print_output_header { sub print_output_header {
   $headerstatus ||= '200 OK';    $headerstatus ||= '200 OK';
   $contenttype  ||= 'text/html';    $contenttype  ||= 'text/html';
   
   my $ret = $yyIIS ? "HTTP/1.0 $headerstatus\n" : "Status: $headerstatus\n";    my $ret = $yyIIS ? "HTTP/1.0 $headerstatus\n" : "Status: $headerstatus\n";
   
   foreach ($yySetCookies1,$yySetCookies2,$yySetCookies3) { $ret .= "Set-Cookie: $_\n" if $_; }    foreach ($yySetCookies1,$yySetCookies2,$yySetCookies3) { $ret .= "Set-Cookie: $_\n" if $_; }
   
   if ($yySetLocation) {    if ($yySetLocation) {
       $ret .= "Location: $yySetLocation";        $ret .= "Location: $yySetLocation";
   } else {    } else {
       $ret .= "Cache-Control: no-cache, must-revalidate\nPragma: no-cache\n" if !$cachebehaviour;        $ret .= "Cache-Control: no-cache, must-revalidate\nPragma: no-cache\n" if !$cachebehaviour;
       $ret .= "ETag: \"$ETag\"\n" if $ETag;        $ret .= "ETag: \"$ETag\"\n" if $ETag;
       $ret .= "Last-Modified: $LastModified\n" if $LastModified;        $ret .= "Last-Modified: $LastModified\n" if $LastModified;
       $ret .= "Content-Encoding: gzip\n" if $gzcomp && $gzaccept;        $ret .= "Content-Encoding: gzip\n" if $gzcomp && $gzaccept;
       $ret .= "Content-Type: $contenttype";        $ret .= "Content-Type: $contenttype";
       $ret .= "; charset=$yycharset" if $yycharset;        $ret .= "; charset=$yycharset" if $yycharset;
   }    }
   print $ret . "\r\n\r\n";    print $ret . "\r\n\r\n";
} }
   
sub print_HTML_output_and_finish { sub print_HTML_output_and_finish {
   if ($gzcomp && $gzaccept) {    if ($gzcomp && $gzaccept) {
       my $filehandle_exists = fileno GZIP;        my $filehandle_exists = fileno GZIP;
       if ($gzcomp == 1 || $filehandle_exists) {        if ($gzcomp == 1 || $filehandle_exists) {
           $| = 1;            $| = 1;
           open(GZIP, "| gzip -f") unless $filehandle_exists;            open(GZIP, "| gzip -f") unless $filehandle_exists;
           print GZIP $output;            print GZIP $output;
           close(GZIP);            close(GZIP);
       } else {        } else {
           require Compress::Zlib;            require Compress::Zlib;
           binmode STDOUT;            binmode STDOUT;
           print Compress::Zlib::memGzip($output);            print Compress::Zlib::memGzip($output);
       }        }
   } else {    } else {
       print $output;        print $output;
   }    }
   exit;    exit;
} }
   
sub write_cookie { sub write_cookie {
   my %params = @_;    my %params = @_;
   
   if ($params{'-expires'} =~ /\+(\d+)m/) {    if ($params{'-expires'} =~ /\+(\d+)m/) {
       my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime($date + $1 * 60);        my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime($date + $1 * 60);
   
       $year += 1900;        $year += 1900;
       my @mos = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");        my @mos = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
       my @dys = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");        my @dys = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
       $mon  = $mos[$mon];        $mon  = $mos[$mon];
       $wday = $dys[$wday];        $wday = $dys[$wday];
   
       $params{'-expires'} = sprintf("%s, %02i-%s-%04i %02i:%02i:%02i GMT", $wday, $mday, $mon, $year, $hour, $min, $sec);        $params{'-expires'} = sprintf("%s, %02i-%s-%04i %02i:%02i:%02i GMT", $wday, $mday, $mon, $year, $hour, $min, $sec);
   }    }
   
   $params{'-path'}    = " path=$params{'-path'};"       if $params{'-path'};    $params{'-path'}    = " path=$params{'-path'};"       if $params{'-path'};
   $params{'-expires'} = " expires=$params{'-expires'};" if $params{'-expires'};    $params{'-expires'} = " expires=$params{'-expires'};" if $params{'-expires'};
   
   "$params{'-name'}=$params{'-value'};$params{'-path'}$params{'-expires'}";    "$params{'-name'}=$params{'-value'};$params{'-path'}$params{'-expires'}";
} }
   
sub redirectexit { sub redirectexit {
   $headerstatus = '302 Moved Temporarily';    $headerstatus = '302 Moved Temporarily';
   &print_output_header;    &print_output_header;
   exit;    exit;
} }
   
sub redirectinternal { sub redirectinternal {
   if ($currentboard) {    if ($currentboard) {
       if ($INFO{'num'}) { require "$sourcedir/Display.pl"; &Display; }        if ($INFO{'num'}) { require "$sourcedir/Display.pl"; &Display; }
       else { require "$sourcedir/MessageIndex.pl"; &MessageIndex; }        else { require "$sourcedir/MessageIndex.pl"; &MessageIndex; }
   } else {    } else {
       require "$sourcedir/BoardIndex.pl";        require "$sourcedir/BoardIndex.pl";
       &BoardIndex;        &BoardIndex;
   }    }
} }
   
sub ImgLoc { sub ImgLoc {
   return (!-e "$forumstylesdir/$useimages/$_[0]" ? qq~$forumstylesurl/default/$_[0]~ : qq~$imagesdir/$_[0]~);    return (!-e "$forumstylesdir/$useimages/$_[0]" ? qq~$forumstylesurl/default/$_[0]~ : qq~$imagesdir/$_[0]~);
} }
   
sub template { sub template {
   &print_output_header;    &print_output_header;
   
   if ($yytitle ne $maintxt{'error_description'}) {    if ($yytitle ne $maintxt{'error_description'}) {
       if ((!$iamguest || ($iamguest && $guestaccess == 1)) && !$maintenance ) { $yyforumjump = &jumpto; }        if (!$iamguest || ($iamguest && $guestaccess == 1)) { $yyforumjump = &jumpto; }
   }    }
   $yyposition      = $yytitle;    $yyposition      = $yytitle;
   $yytitle         = "$mbname - $yytitle";    $yytitle         = "$mbname - $yytitle";
   $yyimages        = $imagesdir;    $yyimages        = $imagesdir;
   $yydefaultimages = $defaultimagesdir;    $yydefaultimages = $defaultimagesdir;
   
   $yystyle  = qq~<link rel="stylesheet" href="$forumstylesurl/$usestyle.css" type="text/css" />\n~;    $yystyle  = qq~<link rel="stylesheet" href="$forumstylesurl/$usestyle.css" type="text/css" />\n~;
   $yystyle  =~ s~$usestyle\/~~g;    $yystyle  =~ s~$usestyle\/~~g;
   $yystyle  .= qq~<link rel="stylesheet" href="$yyhtml_root/shjs/styles/sh_style.css" type="text/css" />\n~;    $yystyle  .= qq~<link rel="stylesheet" href="$yyhtml_root/shjs/styles/sh_style.css" type="text/css" />\n~;
   $yystyle .= $yyinlinestyle; # This is for the Help Center and anywhere else that wants to add inline CSS.    $yystyle .= $yyinlinestyle; # This is for the Help Center and anywhere else that wants to add inline CSS.
$yysyntax_js = qq~ $yysyntax_js = qq~
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_main.js"></script> <script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_main.js"></script>
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_cpp.js"></script> <script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_cpp.js"></script>
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_css.js"></script> <script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_css.js"></script>
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_html.js"></script> <script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_html.js"></script>
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_java.js"></script> <script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_java.js"></script>
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_javascript.js"></script> <script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_javascript.js"></script>
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_pascal.js"></script> <script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_pascal.js"></script>
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_perl.js"></script> <script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_perl.js"></script>
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_php.js"></script> <script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_php.js"></script>
<script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_sql.js"></script> <script language="JavaScript1.2" type="text/javascript" src="$yyhtml_root/shjs/sh_sql.js"></script>
~; ~;
   
   # add 'back to top' Button on the end of each page    # add 'back to top' Button on the end of each page
   $yynavback .= qq~<img src="$imagesdir/tabsep211.png" border="0" alt="" style="vertical-align: middle;" />~ if !$yynavback;    $yynavback .= qq~<img src="$imagesdir/tabsep211.png" border="0" alt="" style="vertical-align: middle;" />~ if !$yynavback;
   $yynavback .= qq~ <a href="#pagetop" class="nav">$img_txt{'102'}</a> <img src="$imagesdir/tabsep211.png" border="0" alt="" style="vertical-align: middle;" />~;    $yynavback .= qq~ <a href="#pagetop" class="nav">$img_txt{'102'}</a> <img src="$imagesdir/tabsep211.png" border="0" alt="" style="vertical-align: middle;" />~;
   
   if (!$usehead) { $usehead = qq~default~; }    if (!$usehead) { $usehead = qq~default~; }
   $yytemplate = "$templatesdir/$usehead/$usehead.html";    $yytemplate = "$templatesdir/$usehead/$usehead.html";
   fopen(TEMPLATE, $yytemplate) || die("$maintxt{'23'}: $yytemplate");    fopen(TEMPLATE, $yytemplate) || die("$maintxt{'23'}: $yytemplate");
   $output = join('', <TEMPLATE>);    $output = join('', <TEMPLATE>);
   fclose(TEMPLATE);    fclose(TEMPLATE);
   
   if ($iamadmin || $iamgmod) {    if ($iamadmin || $iamgmod) {
       if ($maintenance) { $yyadmin_alert .= qq~<br /><span class="highlight"><b>$load_txt{'616'}</b></span>~; }        if ($maintenance) { $yyadmin_alert .= qq~<br /><span class="highlight"><b>$load_txt{'616'}</b></span>~; }
       if ($iamadmin && $rememberbackup) {        if ($iamadmin && $rememberbackup) {
           if ($lastbackup && $date > $rememberbackup + $lastbackup) {            if ($lastbackup && $date > $rememberbackup + $lastbackup) {
               $yyadmin_alert .= qq~<br /><span class="highlight"><b>$load_txt{'617'} ~ . &timeformat($lastbackup) . qq~</b></span>~;                $yyadmin_alert .= qq~<br /><span class="highlight"><b>$load_txt{'617'} ~ . &timeformat($lastbackup) . qq~</b></span>~;
           }            }
       }        }
   }    }
   
   $yyboardname = "$mbname";    $yyboardname = "$mbname";
   $yyboardlink = qq~<a href="$scripturl">$mbname</a>~;    $yyboardlink = qq~<a href="$scripturl">$mbname</a>~;
   
   # static/dynamic clock    # static/dynamic clock
   $yytime = &timeformat($date, 1);    $yytime = &timeformat($date, 1);
   if ($mytimeselected != 7 && (($iamguest && $dynamic_clock) || ${$uid.$username}{'dynamic_clock'})) {    if ($mytimeselected != 7 && (($iamguest && $dynamic_clock) || ${$uid.$username}{'dynamic_clock'})) {
       $yytime =~ /(.*?)\d+:\d+((\w+)|:\d+)?/;        $yytime =~ /(.*?)\d+:\d+((\w+)|:\d+)?/;
       my ($a,$b) = ($1,$3);        my ($a,$b) = ($1,$3);
       $a =~ s/<.+?>//g;        $a =~ s/<.+?>//g;
       $b = ' ' if $mytimeselected == 6;        $b = ' ' if $mytimeselected == 6;
       $yytime = qq~&nbsp;<script language="javascript" type="text/javascript">\n<!--\nWriteClock('yabbclock','$a','$b');\n//-->\n</script>~;        $yytime = qq~&nbsp;<script language="javascript" type="text/javascript">\n<!--\nWriteClock('yabbclock','$a','$b');\n//-->\n</script>~;
       $yyjavascript .= qq~\n\nvar OurTime = ~ . ($date + (3600 * $toffs)) . qq~000;\nvar YaBBTime = new Date();\nvar TimeDif = YaBBTime.getTime() - (YaBBTime.getTimezoneOffset() * 60000) - OurTime - 1000; // - 1000 compromise to transmission time~;        $yyjavascript .= qq~\n\nvar OurTime = ~ . ($date + (3600 * $toffs)) . qq~000;\nvar YaBBTime = new Date();\nvar TimeDif = YaBBTime.getTime() - (YaBBTime.getTimezoneOffset() * 60000) - OurTime - 1000; // - 1000 compromise to transmission time~;
   }    }
   
   $yyjavascript .= qq~    $yyjavascript .= qq~
   
   function txtInFields(thefield, defaulttxt) {    function txtInFields(thefield, defaulttxt) {
       if (thefield.value == defaulttxt) thefield.value = "";        if (thefield.value == defaulttxt) thefield.value = "";
       else { if (thefield.value == "") thefield.value = defaulttxt; }        else { if (thefield.value == "") thefield.value = defaulttxt; }
   }    }
   ~;    ~;
   if ($output =~ /\{yabb tabmenu\}/) {    if ($output =~ /\{yabb tabmenu\}/) {
       require "$sourcedir/TabMenu.pl";        require "$sourcedir/TabMenu.pl";
       &mainMenu;        &mainMenu;
   
   } else {    } else {
       $yymenu = qq~<a href="$scripturl">$img{'home'}</a>$menusep<a href="$scripturl?action=help" style="cursor:help;">$img{'help'}</a>~;        $yymenu = qq~<a href="$scripturl">$img{'home'}</a>$menusep<a href="$scripturl?action=help" style="cursor:help;">$img{'help'}</a>~;
       # remove search from menu if disabled by the admin        # remove search from menu if disabled by the admin
       if ($maxsearchdisplay > -1) {        if ($maxsearchdisplay > -1) {
           $yymenu .= qq~$menusep<a href="$scripturl?action=search">$img{'search'}</a>~;            $yymenu .= qq~$menusep<a href="$scripturl?action=search">$img{'search'}</a>~;
       }        }
       if (!$ML_Allowed || ($ML_Allowed == 1 && !$iamguest) || ($ML_Allowed == 2 && $staff) || ($ML_Allowed == 3 && ($iamadmin || $iamgmod))) {        if (!$ML_Allowed || ($ML_Allowed == 1 && !$iamguest) || ($ML_Allowed == 2 && $staff) || ($ML_Allowed == 3 && ($iamadmin || $iamgmod))) {
           $yymenu .= qq~$menusep<a href="$scripturl?action=ml">$img{'memberlist'}</a>~;            $yymenu .= qq~$menusep<a href="$scripturl?action=ml">$img{'memberlist'}</a>~;
       }        }
   
       if ($iamadmin) { $yymenu .= qq~$menusep<a href="$boardurl/AdminIndex.$yyaext">$img{'admin'}</a>~; }        if ($iamadmin) { $yymenu .= qq~$menusep<a href="$boardurl/AdminIndex.$yyaext">$img{'admin'}</a>~; }
       if ($iamgmod) {        if ($iamgmod) {
           if (-e ("$vardir/gmodsettings.txt")) {            if (-e ("$vardir/gmodsettings.txt")) {
               require "$vardir/gmodsettings.txt";                require "$vardir/gmodsettings.txt";
           }            }
           if ($allow_gmod_admin) { $yymenu .= qq~$menusep<a href="$boardurl/AdminIndex.$yyaext">$img{'admin'}</a>~; }            if ($allow_gmod_admin) { $yymenu .= qq~$menusep<a href="$boardurl/AdminIndex.$yyaext">$img{'admin'}</a>~; }
       }        }
       if ($sessionvalid == 0 && !$iamguest) {        if ($sessionvalid == 0 && !$iamguest) {
           my $sesredir;            my $sesredir;
           unless (!$testenv || $action eq "revalidatesession" || $action eq "revalidatesession2") {            unless (!$testenv || $action eq "revalidatesession" || $action eq "revalidatesession2") {
               $sesredir = $testenv;                $sesredir = $testenv;
               $sesredir =~ s/\=/\~/g;                $sesredir =~ s/\=/\~/g;
               $sesredir =~ s/;/x3B/g;                $sesredir =~ s/;/x3B/g;
               $sesredir = qq~;sesredir=$sesredir~;                $sesredir = qq~;sesredir=$sesredir~;
           }            }
           $yymenu .= qq~$menusep<a href="$scripturl?action=revalidatesession$sesredir">$img{'sessreval'}</a>~;            $yymenu .= qq~$menusep<a href="$scripturl?action=revalidatesession$sesredir">$img{'sessreval'}</a>~;
       }        }
       if ($iamguest) {        if ($iamguest) {
           my $sesredir;            my $sesredir;
           if ($testenv) {            if ($testenv) {
               $sesredir = $testenv;                $sesredir = $testenv;
               $sesredir =~ s/\=/\~/g;                $sesredir =~ s/\=/\~/g;
               $sesredir =~ s/;/x3B/g;                $sesredir =~ s/;/x3B/g;
               $sesredir = qq~;sesredir=$sesredir~;                $sesredir = qq~;sesredir=$sesredir~;
           }            }
           $yymenu .= qq~$menusep<a href="~ . ($loginform ? "javascript:if(jumptologin>1)alert('$maintxt{'35'}');jumptologin++;window.scrollTo(0,10000);document.loginform.username.focus();" : "$scripturl?action=login$sesredir") . qq~">$img{'login'}</a>~;            $yymenu .= qq~$menusep<a href="~ . ($loginform ? "javascript:if(jumptologin>1)alert('$maintxt{'35'}');jumptologin++;window.scrollTo(0,10000);document.loginform.username.focus();" : "$scripturl?action=login$sesredir") . qq~">$img{'login'}</a>~;
           if ($regtype != 0) { $yymenu .= qq~$menusep<a href="$scripturl?action=register">$img{'register'}</a>~; }            if ($regtype != 0) { $yymenu .= qq~$menusep<a href="$scripturl?action=register">$img{'register'}</a>~; }
           if ($PMenableGuestButton && $PM_level > 0 && $PMenableBm_level > 0) {            if ($PMenableGuestButton && $PM_level > 0 && $PMenableBm_level > 0) {
               $yymenu .= qq~$menusep<a href="$scripturl?action=guestpm">$img{'pmadmin'}</a>~; }                $yymenu .= qq~$menusep<a href="$scripturl?action=guestpm">$img{'pmadmin'}</a>~; }
   
       } else {        } else {
           ## pointing towards pm now            ## pointing towards pm now
           $yymenu .= qq~$menusep<a href="$scripturl?action=mycenter">$img{'mycenter'}</a>~;            $yymenu .= qq~$menusep<a href="$scripturl?action=mycenter">$img{'mycenter'}</a>~;
           $yymenu .= qq~$menusep<a href="$scripturl?action=logout">$img{'logout'}</a>~;            $yymenu .= qq~$menusep<a href="$scripturl?action=logout">$img{'logout'}</a>~;
       }        }
   }    }
   
   $yylangChooser = "";    $yylangChooser = "";
   if (($iamguest && !$guestLang) && $enable_guestlanguage && $guestaccess) {    if (($iamguest && !$guestLang) && $enable_guestlanguage && $guestaccess) {
       if (!$langopt) {&guestLangSel;}        if (!$langopt) {&guestLangSel;}
       if ($morelang > 1) {        if ($morelang > 1) {
           $yylangChooser = qq~$guest_txt{'sellanguage'}: <form action="$scripturl?action=guestlang" method="post" name="sellanguage">            $yylangChooser = qq~$guest_txt{'sellanguage'}: <form action="$scripturl?action=guestlang" method="post" name="sellanguage">
           <select name="guestlang" onchange="submit();">            <select name="guestlang" onchange="submit();">
           $langopt            $langopt
           </select>            </select>
           <noscript><input type="submit" value="$maintxt{'32'}" class="button" /></noscript>            <noscript><input type="submit" value="$maintxt{'32'}" class="button" /></noscript>
           </form>~;            </form>~;
       }        }
   
   } elsif (($iamguest && $guestLang) && $enable_guestlanguage && $guestaccess) {    } elsif (($iamguest && $guestLang) && $enable_guestlanguage && $guestaccess) {
       if (!$langopt) {&guestLangSel;}        if (!$langopt) {&guestLangSel;}
       if ($morelang > 1) {        if ($morelang > 1) {
           $yylangChooser = qq~$guest_txt{'changelanguage'}: <form action="$scripturl?action=guestlang" method="post" name="changelanguage">            $yylangChooser = qq~$guest_txt{'changelanguage'}: <form action="$scripturl?action=guestlang" method="post" name="changelanguage">
           <select name="guestlang" onchange="submit();">            <select name="guestlang" onchange="submit();">
           $langopt            $langopt
           </select>            </select>
           <noscript><input type="submit" value="$maintxt{'32'}" class="button" /></noscript>            <noscript><input type="submit" value="$maintxt{'32'}" class="button" /></noscript>
           </form>~;            </form>~;
       }        }
   }    }
   
   my $wmessage;    my $wmessage;
   if    ($hour >= 12 && $hour < 18) { $wmessage = $maintxt{'247a'}; } # Afternoon    if    ($hour >= 12 && $hour < 18) { $wmessage = $maintxt{'247a'}; } # Afternoon
   elsif ($hour <  12 && $hour >= 0) { $wmessage = $maintxt{'247m'}; } # Morning    elsif ($hour <  12 && $hour >= 0) { $wmessage = $maintxt{'247m'}; } # Morning
   else                              { $wmessage = $maintxt{'247e'}; } # Evening    else                              { $wmessage = $maintxt{'247e'}; } # Evening
   if ($iamguest) {    if ($iamguest) {
       $yyuname = qq~$maintxt{'248'} $maintxt{'28'}. $maintxt{'249'} <a href="~ . ($loginform ? "javascript:if(jumptologin>1)alert('$maintxt{'35'}');jumptologin++;window.scrollTo(0,10000);document.loginform.username.focus();" : "$scripturl?action=login") . qq~">$maintxt{'34'}</a>~;        $yyuname = qq~$maintxt{'248'} $maintxt{'28'}. $maintxt{'249'} <a href="~ . ($loginform ? "javascript:if(jumptologin>1)alert('$maintxt{'35'}');jumptologin++;window.scrollTo(0,10000);document.loginform.username.focus();" : "$scripturl?action=login") . qq~">$maintxt{'34'}</a>~;
       $yyuname .= qq~ $maintxt{'377'} <a href="$scripturl?action=register">$maintxt{'97'}</a>~ if $regtype;        $yyuname .= qq~ $maintxt{'377'} <a href="$scripturl?action=register">$maintxt{'97'}</a>~ if $regtype;
       $yyjavascript .= "\njumptologin = 1;";        $yyjavascript .= "\njumptologin = 1;";
   } else {    } else {
       if (${$uid.$username}{'bday'} ne '') {        if (${$uid.$username}{'bday'} ne '') {
           my ($usermonth, $userday, $useryear) = split(/\//, ${$uid.$username}{'bday'});            my ($usermonth, $userday, $useryear) = split(/\//, ${$uid.$username}{'bday'});
           if ($usermonth == $mon_num && $userday == $mday) { $wmessage = $maintxt{'247bday'}; }            if ($usermonth == $mon_num && $userday == $mday) { $wmessage = $maintxt{'247bday'}; }
       }        }
       $yyuname = ($PM_level == 0 || ($PM_level == 2 && !$iamadmin && !$iamgmod && !$iammod) || ($PM_level == 3 && !$iamadmin && !$iamgmod)) ? "$wmessage ${$uid.$username}{'realname'}" : "$wmessage ${$uid.$username}{'realname'}, ";        $yyuname = ($PM_level == 0 || ($PM_level == 2 && !$iamadmin && !$iamgmod && !$iammod) || ($PM_level == 3 && !$iamadmin && !$iamgmod)) ? "$wmessage ${$uid.$username}{'realname'}" : "$wmessage ${$uid.$username}{'realname'}, ";
   }    }
   
   # Add new notifications if allowed    # Add new notifications if allowed
   if (!$iamguest && $NewNotificationAlert) {    if (!$iamguest && $NewNotificationAlert) {
       unless ($board_notify || $thread_notify) {        unless ($board_notify || $thread_notify) {
           require "$sourcedir/Notify.pl";            require "$sourcedir/Notify.pl";
           ($board_notify,$thread_notify) = &NotificationAlert;            ($board_notify,$thread_notify) = &NotificationAlert;
       }        }
       my ($bo_num,$th_num);        my ($bo_num,$th_num);
       foreach (keys %$board_notify) { # boardname, boardnotifytype , new        foreach (keys %$board_notify) { # boardname, boardnotifytype , new
           $bo_num++ if ${$$board_notify{$_}}[2];            $bo_num++ if ${$$board_notify{$_}}[2];
       }        }
       foreach (keys %$thread_notify) { # mythread, msub, new, username_link, catname_link, boardname_link, lastpostdate        foreach (keys %$thread_notify) { # mythread, msub, new, username_link, catname_link, boardname_link, lastpostdate
           $th_num++ if ${$$thread_notify{$_}}[2];            $th_num++ if ${$$thread_notify{$_}}[2];
       }        }
       if ($bo_num || $th_num) {        if ($bo_num || $th_num) {
           my $noti_text = ($bo_num ? "$notify_txt{'201'} $notify_txt{'205'} ($bo_num)" : "") . ($th_num ? ($bo_num ? " $notify_txt{'202'} " : "") . "$notify_txt{'201'}  $notify_txt{'206'} ($th_num)" : "");            my $noti_text = ($bo_num ? "$notify_txt{'201'} $notify_txt{'205'} ($bo_num)" : "") . ($th_num ? ($bo_num ? " $notify_txt{'202'} " : "") . "$notify_txt{'201'}  $notify_txt{'206'} ($th_num)" : "");
           $yyadmin_alert = qq~<br />$notify_txt{'200'} <a href="$scripturl?action=shownotify">$noti_text</a>.$yyadmin_alert~;            $yyadmin_alert = qq~<br />$notify_txt{'200'} <a href="$scripturl?action=shownotify">$noti_text</a>.$yyadmin_alert~;
           $yymain .= qq~<script language="javascript" type="text/javascript">            $yymain .= qq~<script language="javascript" type="text/javascript">
           <!--            <!--
           window.setTimeout("Noti_Popup();", 1000);            window.setTimeout("Noti_Popup();", 1000);
           function Noti_Popup() {            function Noti_Popup() {
               if (confirm('$notify_txt{'200'} $noti_text.\\n$notify_txt{'203'}'))                if (confirm('$notify_txt{'200'} $noti_text.\\n$notify_txt{'203'}'))
                   window.location.href='$scripturl?action=shownotify';                    window.location.href='$scripturl?action=shownotify';
           }            }
           //-->            //-->
           </script>~ if ${$uid.$username}{'onlinealert'} and $boardindex_template;            </script>~ if ${$uid.$username}{'onlinealert'} and $boardindex_template;
       }        }
   }    }
   
   # This next line fixes problems created when a fatal_error is called before Security.pl is loaded    # This next line fixes problems created when a fatal_error is called before Security.pl is loaded
   # We don't want to require since it's an error and trying to do anything extra for an error could be bad    # We don't want to require since it's an error and trying to do anything extra for an error could be bad
   if ($output =~ m~<yabb copyright>~ || $output =~ m~{yabb copyright}~) { $yycopyin = 1; } ## new template style in also    if ($output =~ m~<yabb copyright>~ || $output =~ m~{yabb copyright}~) { $yycopyin = 1; } ## new template style in also
   $yysearchbox = '';    $yysearchbox = '';
   unless ($iamguest && $guestaccess == 0) {    unless ($iamguest && $guestaccess == 0) {
       if ($maxsearchdisplay > -1) {        if ($maxsearchdisplay > -1) {
           $yysearchbox = qq~            $yysearchbox = qq~
       <script language="JavaScript1.2" src="$yyhtml_root/ubbc.js" type="text/javascript"></script>        <script language="JavaScript1.2" src="$yyhtml_root/ubbc.js" type="text/javascript"></script>
       <form action="$scripturl?action=search2" method="post">        <form action="$scripturl?action=search2" method="post">
       <input type="hidden" name="searchtype" value="allwords" />        <input type="hidden" name="searchtype" value="allwords" />
       <input type="hidden" name="userkind" value="any" />        <input type="hidden" name="userkind" value="any" />
       <input type="hidden" name="subfield" value="on" />        <input type="hidden" name="subfield" value="on" />
       <input type="hidden" name="msgfield" value="on" />        <input type="hidden" name="msgfield" value="on" />
       <input type="hidden" name="age" value="31" />        <input type="hidden" name="age" value="31" />
       <input type="hidden" name="numberreturned" value="$maxsearchdisplay" />        <input type="hidden" name="numberreturned" value="$maxsearchdisplay" />
       <input type="hidden" name="oneperthread" value="1" />        <input type="hidden" name="oneperthread" value="1" />
       <input type="hidden" name="searchboards" value="!all" />        <input type="hidden" name="searchboards" value="!all" />
       <input type="text" name="search" size="16" id="search1" value="$img_txt{'182'}" style="font-size: 11px;" onfocus="txtInFields(this, '$img_txt{'182'}');" onblur="txtInFields(this, '$img_txt{'182'}')" />        <input type="text" name="search" size="16" id="search1" value="$img_txt{'182'}" style="font-size: 11px;" onfocus="txtInFields(this, '$img_txt{'182'}');" onblur="txtInFields(this, '$img_txt{'182'}')" />
       <input type="image" src="$imagesdir/search.gif" style="border: 0; background-color: transparent; margin-right: 5px; vertical-align: middle;" />        <input type="image" src="$imagesdir/search.gif" style="border: 0; background-color: transparent; margin-right: 5px; vertical-align: middle;" />
       </form>        </form>
       ~;        ~;
       }        }
   }    }
   if ($enable_news && -s "$vardir/news.txt" > 5) {    if ($enable_news && -s "$vardir/news.txt" > 5) {
       fopen(NEWS, "$vardir/news.txt");        fopen(NEWS, "$vardir/news.txt");
       my @newsmessages = <NEWS>;        my @newsmessages = <NEWS>;
       fclose(NEWS);        fclose(NEWS);
       chomp(@newsmessages);        chomp(@newsmessages);
       my $startnews = int(rand(@newsmessages));        my $startnews = int(rand(@newsmessages));
       my $newstitle = qq~<b>$maintxt{'102'}:</b>~;        my $newstitle = qq~<b>$maintxt{'102'}:</b>~;
       $newstitle =~ s/'/\\'/g;        $newstitle =~ s/'/\\'/g;
       $guest_media_disallowed = 0;        $guest_media_disallowed = 0;
       $newswrap = 40;        $newswrap = 40;
       if ($shownewsfader) {        if ($shownewsfader) {
           $fadedelay = $maxsteps * $stepdelay;            $fadedelay = $maxsteps * $stepdelay;
           $yynews .= qq~            $yynews .= qq~
           <script language="JavaScript1.2" type="text/javascript">            <script language="JavaScript1.2" type="text/javascript">
               <!--                <!--
                   var index = $startnews;                    var index = $startnews;
                   var maxsteps = "$maxsteps";                    var maxsteps = "$maxsteps";
                   var stepdelay = "$stepdelay";                    var stepdelay = "$stepdelay";
                   var fadelinks = $fadelinks;                    var fadelinks = $fadelinks;
                   var delay = "$fadedelay";                    var delay = "$fadedelay";
                   function convProp(thecolor) {                    function convProp(thecolor) {
                       if(thecolor.charAt(0) == "#") {                        if(thecolor.charAt(0) == "#") {
                           if(thecolor.length == 4) thecolor=thecolor.replace(/(\\#)([a-f A-F 0-10]{1,1})([a-f A-F 0-10]{1,1})([a-f A-F 0-10]{1,1})\/i, "\$1\$2\$2\$3\$3\$4\$4");                            if(thecolor.length == 4) thecolor=thecolor.replace(/(\\#)([a-f A-F 0-10]{1,1})([a-f A-F 0-10]{1,1})([a-f A-F 0-10]{1,1})\/i, "\$1\$2\$2\$3\$3\$4\$4");
                           var thiscolor = new Array(HexToR(thecolor), HexToG(thecolor), HexToB(thecolor));                            var thiscolor = new Array(HexToR(thecolor), HexToG(thecolor), HexToB(thecolor));
                           return thiscolor;                            return thiscolor;
                       }                        }
                       else if(thecolor.charAt(3) == "(") {                        else if(thecolor.charAt(3) == "(") {
                           thecolor=thecolor.replace(/rgb\\((\\d+?\\%*?)\\,(\\s*?)(\\d+?\\%*?)\\,(\\s*?)(\\d+?\\%*?)\\)/i, "\$1|\$3|\$5");                            thecolor=thecolor.replace(/rgb\\((\\d+?\\%*?)\\,(\\s*?)(\\d+?\\%*?)\\,(\\s*?)(\\d+?\\%*?)\\)/i, "\$1|\$3|\$5");
                           var thiscolor = thecolor.split("|");                            var thiscolor = thecolor.split("|");
                           return thiscolor;                            return thiscolor;
                       }                        }
                       else {                        else {
                           thecolor=thecolor.replace(/\\"/g, "");                            thecolor=thecolor.replace(/\\"/g, "");
                           thecolor=thecolor.replace(/maroon/ig, "128|0|0");                            thecolor=thecolor.replace(/maroon/ig, "128|0|0");
                           thecolor=thecolor.replace(/red/i, "255|0|0");                            thecolor=thecolor.replace(/red/i, "255|0|0");
                           thecolor=thecolor.replace(/orange/i, "255|165|0");                            thecolor=thecolor.replace(/orange/i, "255|165|0");
                           thecolor=thecolor.replace(/olive/i, "128|128|0");                            thecolor=thecolor.replace(/olive/i, "128|128|0");
                           thecolor=thecolor.replace(/yellow/i, "255|255|0");                            thecolor=thecolor.replace(/yellow/i, "255|255|0");
                           thecolor=thecolor.replace(/purple/i, "128|0|128");                            thecolor=thecolor.replace(/purple/i, "128|0|128");
                           thecolor=thecolor.replace(/fuchsia/i, "255|0|255");                            thecolor=thecolor.replace(/fuchsia/i, "255|0|255");
                           thecolor=thecolor.replace(/white/i, "255|255|255");                            thecolor=thecolor.replace(/white/i, "255|255|255");
                           thecolor=thecolor.replace(/lime/i, "00|255|00");                            thecolor=thecolor.replace(/lime/i, "00|255|00");
                           thecolor=thecolor.replace(/green/i, "0|128|0");                            thecolor=thecolor.replace(/green/i, "0|128|0");
                           thecolor=thecolor.replace(/navy/i, "0|0|128");                            thecolor=thecolor.replace(/navy/i, "0|0|128");
                           thecolor=thecolor.replace(/blue/i, "0|0|255");                            thecolor=thecolor.replace(/blue/i, "0|0|255");
                           thecolor=thecolor.replace(/aqua/i, "0|255|255");                            thecolor=thecolor.replace(/aqua/i, "0|255|255");
                           thecolor=thecolor.replace(/teal/i, "0|128|128");                            thecolor=thecolor.replace(/teal/i, "0|128|128");
                           thecolor=thecolor.replace(/black/i, "0|0|0");                            thecolor=thecolor.replace(/black/i, "0|0|0");
                           thecolor=thecolor.replace(/silver/i, "192|192|192");                            thecolor=thecolor.replace(/silver/i, "192|192|192");
                           thecolor=thecolor.replace(/gray/i, "128|128|128");                            thecolor=thecolor.replace(/gray/i, "128|128|128");
                           var thiscolor = thecolor.split("|");                            var thiscolor = thecolor.split("|");
                           return thiscolor;                            return thiscolor;
                       }                        }
                   } #" make my syntax checker happy;                    } #" make my syntax checker happy;
   
                   if (ie4 || DOM2) document.write('$newstitle<div class="windowbg2" id="fadestylebak" style="display: none;"><div class="newsfader" id="fadestyle" style="display: none;"> </div></div>');                    if (ie4 || DOM2) document.write('$newstitle<div class="windowbg2" id="fadestylebak" style="display: none;"><div class="newsfader" id="fadestyle" style="display: none;"> </div></div>');
   
                   if (document.getElementById('fadestyle').currentStyle) {                    if (document.getElementById('fadestyle').currentStyle) {
                       tcolor = document.getElementById('fadestyle').currentStyle['color'];                        tcolor = document.getElementById('fadestyle').currentStyle['color'];
                       bcolor = document.getElementById('fadestyle').currentStyle['backgroundColor'];                        bcolor = document.getElementById('fadestyle').currentStyle['backgroundColor'];
                       fntsize = document.getElementById('fadestyle').currentStyle['fontSize'];                        fntsize = document.getElementById('fadestyle').currentStyle['fontSize'];
                       fntstyle = document.getElementById('fadestyle').currentStyle['fontStyle'];                        fntstyle = document.getElementById('fadestyle').currentStyle['fontStyle'];
                       fntweight = document.getElementById('fadestyle').currentStyle['fontWeight'];                        fntweight = document.getElementById('fadestyle').currentStyle['fontWeight'];
                       fntfamily = document.getElementById('fadestyle').currentStyle['fontFamily'];                        fntfamily = document.getElementById('fadestyle').currentStyle['fontFamily'];
                       txtdecoration = document.getElementById('fadestyle').currentStyle['textDecoration'];                        txtdecoration = document.getElementById('fadestyle').currentStyle['textDecoration'];
                   }                    }
                   else if (window.getComputedStyle) {                    else if (window.getComputedStyle) {
                       tcolor = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('color');                        tcolor = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('color');
                       bcolor = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('background-color');                        bcolor = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('background-color');
                       fntsize = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('font-size');                        fntsize = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('font-size');
                       fntstyle = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('font-style');                        fntstyle = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('font-style');
                       fntweight = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('font-weight');                        fntweight = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('font-weight');
                       fntfamily = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('font-family');                        fntfamily = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('font-family');
                       txtdecoration = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('text-decoration');                        txtdecoration = window.getComputedStyle(document.getElementById('fadestyle'), null).getPropertyValue('text-decoration');
                   }                    }
                   if (bcolor == "transparent" || bcolor == "rgba\\(0\\, 0\\, 0\\, 0\\)") {                    if (bcolor == "transparent" || bcolor == "rgba\\(0\\, 0\\, 0\\, 0\\)") {
                       if (document.getElementById('fadestylebak').currentStyle) {                        if (document.getElementById('fadestylebak').currentStyle) {
                           tcolor = document.getElementById('fadestylebak').currentStyle['color'];                            tcolor = document.getElementById('fadestylebak').currentStyle['color'];
                           bcolor = document.getElementById('fadestylebak').currentStyle['backgroundColor'];                            bcolor = document.getElementById('fadestylebak').currentStyle['backgroundColor'];
                       }                        }
                       else if (window.getComputedStyle) {                        else if (window.getComputedStyle) {
                           tcolor = window.getComputedStyle(document.getElementById('fadestylebak'), null).getPropertyValue('color');                            tcolor = window.getComputedStyle(document.getElementById('fadestylebak'), null).getPropertyValue('color');
                           bcolor = window.getComputedStyle(document.getElementById('fadestylebak'), null).getPropertyValue('background-color');                            bcolor = window.getComputedStyle(document.getElementById('fadestylebak'), null).getPropertyValue('background-color');
                       }                        }
                   }                    }
                   txtdecoration = txtdecoration.replace(/\'/g, "");                    txtdecoration = txtdecoration.replace(/\'/g, "");
                   var endcolor = convProp(tcolor);                    var endcolor = convProp(tcolor);
                   var startcolor = convProp(bcolor);~;                    var startcolor = convProp(bcolor);~;
           my $greybox = $img_greybox;            my $greybox = $img_greybox;
           $img_greybox = 0;            $img_greybox = 0;
           for (my $j = 0; $j < @newsmessages; $j++) {            for (my $j = 0; $j < @newsmessages; $j++) {
               $message = $newsmessages[$j];                $message = $newsmessages[$j];
               &wrap;                &wrap;
               if ($enable_ubbc) {                if ($enable_ubbc) {
                   if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; }                    if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; }
                   $ns = "";                    $ns = "";
                   &DoUBBC;                    &DoUBBC;
                   $message =~ s/ style="display:none"/ style="display:block"/g;                    $message =~ s/ style="display:none"/ style="display:block"/g;
               }                }
               &wrap2;                &wrap2;
               $message =~ s/"/\\"/g;                $message =~ s/"/\\"/g;
               &ToChars($message);                &ToChars($message);
               $yynews .= qq~                    fcontent[$j] = "$message";\n~;                $yynews .= qq~                    fcontent[$j] = "$message";\n~;
           }            }
           $img_greybox = $greybox;            $img_greybox = $greybox;
           $yynews .= qq~            $yynews .= qq~
                   if (ie4 || DOM2) document.write('<div style="font-size: ' + fntsize + '\\; font-weight: ' + fntweight + '\\; font-style: ' + fntstyle + '\\; font-family: ' + fntfamily + '\\; text-decoration: ' + txtdecoration + '\\;" id="fscroller"></div>');                    if (ie4 || DOM2) document.write('<div style="font-size: ' + fntsize + '\\; font-weight: ' + fntweight + '\\; font-style: ' + fntstyle + '\\; font-family: ' + fntfamily + '\\; text-decoration: ' + txtdecoration + '\\;" id="fscroller"></div>');
   
                   if (window.addEventListener)                    if (window.addEventListener)
                       window.addEventListener("load", changecontent, false);                        window.addEventListener("load", changecontent, false);
                   else if (window.attachEvent)                    else if (window.attachEvent)
                       window.attachEvent("onload", changecontent);                        window.attachEvent("onload", changecontent);
                   else if (document.getElementById)                    else if (document.getElementById)
                       window.onload = changecontent;                        window.onload = changecontent;
               // -->                // -->
           </script>            </script>
       ~;        ~;
       } else {        } else {
           $message = $newsmessages[$startnews];            $message = $newsmessages[$startnews];
           &wrap;            &wrap;
           if ($enable_ubbc) {            if ($enable_ubbc) {
               if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; }                if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; }
               &DoUBBC;                &DoUBBC;
               $message =~ s/ style="display:none"/ style="display:block"/g;                $message =~ s/ style="display:none"/ style="display:block"/g;
           }            }
           &wrap2;            &wrap2;
           &ToChars($message);            &ToChars($message);
           $yynews = $message;            $yynews = $message;
       }        }
       $newswrap = 0;        $newswrap = 0;
   } else {    } else {
       $yynews = '&nbsp;';        $yynews = '&nbsp;';
   }    }
   # Moved this down here so it shows more    # Moved this down here so it shows more
   ##  pushed to own file for flexibility    ##  pushed to own file for flexibility
   if ($debug == 1 or ($debug == 2 && $iamadmin)) { require "$sourcedir/Debug.pl"; &Debug; }    if ($debug == 1 or ($debug == 2 && $iamadmin)) { require "$sourcedir/Debug.pl"; &Debug; }
   $yyurl      = $scripturl;    $yyurl      = $scripturl;
   ## new and old tag template style decoding ##    ## new and old tag template style decoding ##
   while ($output =~ s~(<|{)yabb\s+(\w+)(}|>)~${"yy$2"}~g) {}    while ($output =~ s~(<|{)yabb\s+(\w+)(}|>)~${"yy$2"}~g) {}
   $output =~ s~(a href=\S+?action=viewprofile;username=.+?)>~$1 rel="nofollow">~isg;    $output =~ s~(a href=\S+?action=viewprofile;username=.+?)>~$1 rel="nofollow">~isg;
   if ($imagesdir ne $defaultimagesdir) {    if ($imagesdir ne $defaultimagesdir) {
       $output =~ s~img src=(\\*"|')$imagesdir/(.+?)(\1)~ "img src=$1" . &ImgLoc($2) . $3 ~eisg;        $output =~ s~img src=(\\*"|')$imagesdir/(.+?)(\1)~ "img src=$1" . &ImgLoc($2) . $3 ~eisg;
       $output =~ s~\.src='$imagesdir/(.+?)'~ ".src='" . &ImgLoc($1) . "'" ~eisg; # For Javascript generated images        $output =~ s~\.src='$imagesdir/(.+?)'~ ".src='" . &ImgLoc($1) . "'" ~eisg; # For Javascript generated images
       $output =~ s~input type="image" src="$imagesdir/(.+?)"~ 'input type="image" src="' . &ImgLoc($1) . '"' ~eisg; # For input images        $output =~ s~input type="image" src="$imagesdir/(.+?)"~ 'input type="image" src="' . &ImgLoc($1) . '"' ~eisg; # For input images
       $output =~ s~option value="$imagesdir/(.+?)"~ 'option value="' . &ImgLoc($1) . '"' ~eisg; # For the post page        $output =~ s~option value="$imagesdir/(.+?)"~ 'option value="' . &ImgLoc($1) . '"' ~eisg; # For the post page
   }    }
   $output =~ s~</form>~<input type="hidden" name="formsession" value="$formsession" /></form>~g;    $output =~ s~</form>~<input type="hidden" name="formsession" value="$formsession" /></form>~g;
   
   &image_resize;    &image_resize;
   
   # Start workaround to substitute all ';' by '&' in all URLs    # Start workaround to substitute all ';' by '&' in all URLs
   # This workaround solves problems with servers that use mod_security    # This workaround solves problems with servers that use mod_security
   # in a very strict way. (error 406)    # in a very strict way. (error 406)
   # Take the comments out of the following two lines if you had this problem.    # Take the comments out of the following two lines if you had this problem.
   # $output =~ s/($scripturl\?)([^'"]+)/ $1 . &URL_modify($2) /eg;    # $output =~ s/($scripturl\?)([^'"]+)/ $1 . &URL_modify($2) /eg;
   # sub URL_modify { my $x = shift; $x =~ s/;/&/g; $x; }    # sub URL_modify { my $x = shift; $x =~ s/;/&/g; $x; }
   # End of workaround    # End of workaround
   
   if ($yycopyin == 0) {    if ($yycopyin == 0) {
       $output = q~<center><h1><b>Sorry, the copyright tag <yabb copyright> must be in the template.<br />Please notify this forum's administrator that this site is using an ILLEGAL copy of YaBB!</b></h1></center>~;        $output = q~<center><h1><b>Sorry, the copyright tag <yabb copyright> must be in the template.<br />Please notify this forum's administrator that this site is using an ILLEGAL copy of YaBB!</b></h1></center>~;
   }    }
   
   &print_HTML_output_and_finish;    &print_HTML_output_and_finish;
} }
   
sub image_resize { sub image_resize {
   my ($resize_js,$resize_num);    my ($resize_js,$resize_num);
   my $perl_do_it = 0; # Hardcoded! Set to 1 for Perl to do the fix...size work here. Set to 0 for the javascript within the browser do this work.    my $perl_do_it = 0; # Hardcoded! Set to 1 for Perl to do the fix...size work here. Set to 0 for the javascript within the browser do this work.
   $output =~ s/"((avatar|post|attach|signat)_img_resize)"([^>]*>)/ &check_image_resize($1,$2,$3) /ge;    $output =~ s/"((avatar|post|attach|signat)_img_resize)"([^>]*>)/ &check_image_resize($1,$2,$3) /ge;
   
   sub check_image_resize {    sub check_image_resize {
       my @x = @_;        my @x = @_;
       if ($fix_avatar_img_size && $perl_do_it == 1 && $x[1] eq 'avatar') {        if ($fix_avatar_img_size && $perl_do_it == 1 && $x[1] eq 'avatar') {
           if ($max_avatar_width  && $x[2] !~ / width=./)  { $x[2] =~ s/( style=.)/$1width:$max_avatar_width\px;/; }            if ($max_avatar_width  && $x[2] !~ / width=./)  { $x[2] =~ s/( style=.)/$1width:$max_avatar_width\px;/; }
           if ($max_avatar_height && $x[2] !~ / height=./) { $x[2] =~ s/( style=.)/$1height:$max_avatar_height\px;/; }            if ($max_avatar_height && $x[2] !~ / height=./) { $x[2] =~ s/( style=.)/$1height:$max_avatar_height\px;/; }
           $x[2] =~ s/display:none/display:inline/;            $x[2] =~ s/display:none/display:inline/;
       } elsif ($fix_post_img_size && $perl_do_it == 1 && $x[1] eq 'post') {        } elsif ($fix_post_img_size && $perl_do_it == 1 && $x[1] eq 'post') {
           if ($max_post_width  && $x[2] !~ / width=./)  { $x[2] =~ s/( style=.)/$1width:$max_post_width\px;/; }            if ($max_post_width  && $x[2] !~ / width=./)  { $x[2] =~ s/( style=.)/$1width:$max_post_width\px;/; }
           if ($max_post_height && $x[2] !~ / height=./) { $x[2] =~ s/( style=.)/$1height:$max_post_height\px;/; }            if ($max_post_height && $x[2] !~ / height=./) { $x[2] =~ s/( style=.)/$1height:$max_post_height\px;/; }
           $x[2] =~ s/display:none/display:inline/;            $x[2] =~ s/display:none/display:inline/;
       } elsif ($fix_attach_img_size && $perl_do_it == 1 && $x[1] eq 'attach') {        } elsif ($fix_attach_img_size && $perl_do_it == 1 && $x[1] eq 'attach') {
           if ($max_attach_width  && $x[2] !~ / width=./)  { $x[2] =~ s/( style=.)/$1width:$max_attach_width\px;/; }            if ($max_attach_width  && $x[2] !~ / width=./)  { $x[2] =~ s/( style=.)/$1width:$max_attach_width\px;/; }
           if ($max_attach_height && $x[2] !~ / height=./) { $x[2] =~ s/( style=.)/$1height:$max_attach_height\px;/; }            if ($max_attach_height && $x[2] !~ / height=./) { $x[2] =~ s/( style=.)/$1height:$max_attach_height\px;/; }
           $x[2] =~ s/display:none/display:inline/;            $x[2] =~ s/display:none/display:inline/;
       } elsif ($fix_signat_img_size && $perl_do_it == 1 && $x[1] eq 'signat') {        } elsif ($fix_signat_img_size && $perl_do_it == 1 && $x[1] eq 'signat') {
           if ($max_signat_width  && $x[2] !~ / width=./)  { $x[2] =~ s/( style=.)/$1width:$max_signat_width\px;/; }            if ($max_signat_width  && $x[2] !~ / width=./)  { $x[2] =~ s/( style=.)/$1width:$max_signat_width\px;/; }
           if ($max_signat_height && $x[2] !~ / height=./) { $x[2] =~ s/( style=.)/$1height:$max_signat_height\px;/; }            if ($max_signat_height && $x[2] !~ / height=./) { $x[2] =~ s/( style=.)/$1height:$max_signat_height\px;/; }
           $x[2] =~ s/display:none/display:inline/;            $x[2] =~ s/display:none/display:inline/;
       } else {        } else {
           $resize_num++;            $resize_num++;
           $x[0] .= "_$resize_num";            $x[0] .= "_$resize_num";
           $resize_js .= "'$x[0]',";            $resize_js .= "'$x[0]',";
       }        }
       qq~"$x[0]"$x[2]~;        qq~"$x[0]"$x[2]~;
   }    }
   
   if ($resize_num) {    if ($resize_num) {
       $resize_js =~ s/,$//;        $resize_js =~ s/,$//;
       $resize_js = qq~<script language="JavaScript1.2" type="text/javascript">        $resize_js = qq~<script language="JavaScript1.2" type="text/javascript">
<!-- <!--
   // resize image start    // resize image start
   var resize_time = 2;    var resize_time = 2;
   var img_resize_names = new Array ($resize_js);    var img_resize_names = new Array ($resize_js);
   
   var avatar_img_w    = $max_avatar_width;    var avatar_img_w    = $max_avatar_width;
   var avatar_img_h    = $max_avatar_height;    var avatar_img_h    = $max_avatar_height;
   var fix_avatar_size = $fix_avatar_img_size;    var fix_avatar_size = $fix_avatar_img_size;
   var post_img_w      = $max_post_img_width;    var post_img_w      = $max_post_img_width;
   var post_img_h      = $max_post_img_height;    var post_img_h      = $max_post_img_height;
   var fix_post_size   = $fix_post_img_size;    var fix_post_size   = $fix_post_img_size;
   var attach_img_w    = $max_attach_img_width;    var attach_img_w    = $max_attach_img_width;
   var attach_img_h    = $max_attach_img_height;    var attach_img_h    = $max_attach_img_height;
   var fix_attach_size = $fix_attach_img_size;    var fix_attach_size = $fix_attach_img_size;
   var signat_img_w    = $max_signat_img_width;    var signat_img_w    = $max_signat_img_width;
   var signat_img_h    = $max_signat_img_height;    var signat_img_h    = $max_signat_img_height;
   var fix_signat_size = $fix_signat_img_size;    var fix_signat_size = $fix_signat_img_size;
   
   noimgdir   = '$imagesdir';    noimgdir   = '$imagesdir';
   noimgtitle = '$maintxt{'171'}';    noimgtitle = '$maintxt{'171'}';
   
   resize_images();    resize_images();
   // resize image end    // resize image end
// --> // -->
</script>~; </script>~;
   
       $output =~ s|(</body>)|$resize_js\n$1|;        $output =~ s|(</body>)|$resize_js\n$1|;
   }    }
} }
   
sub fatal_error_logging { sub fatal_error_logging {
   my $tmperror = $_[0];    my $tmperror = $_[0];
   
   # This flaw was brought to our attention by S M <savy91@msn.com> Italy    # This flaw was brought to our attention by S M <savy91@msn.com> Italy
   # Thanks! We couldn't make YaBB successful without the help from the bug testers.    # Thanks! We couldn't make YaBB successful without the help from the bug testers.
   &ToHTML($action);    &ToHTML($action);
   &ToHTML($INFO{'num'});    &ToHTML($INFO{'num'});
   &ToHTML($currentboard);    &ToHTML($currentboard);
   
   $tmperror =~ s/\n//ig;    $tmperror =~ s/\n//ig;
   fopen(ERRORLOG, "+<$vardir/errorlog.txt");    fopen(ERRORLOG, "+<$vardir/errorlog.txt");
   seek ERRORLOG, 0, 0;    seek ERRORLOG, 0, 0;
   my @errorlog = <ERRORLOG>;    my @errorlog = <ERRORLOG>;
   truncate ERRORLOG, 0;    truncate ERRORLOG, 0;
   seek ERRORLOG, 0, 0;    seek ERRORLOG, 0, 0;
   chomp @errorlog;    chomp @errorlog;
   $errorcount = @errorlog;    $errorcount = @errorlog;
   
   if ($elrotate) {    if ($elrotate) {
       while ($errorcount >= $elmax) {        while ($errorcount >= $elmax) {
           shift @errorlog;            shift @errorlog;
           $errorcount = @errorlog;            $errorcount = @errorlog;
       }        }
   }    }
   
   foreach my $formdata (keys %FORM) {    foreach my $formdata (keys %FORM) {
       chomp $FORM{$formdata};        chomp $FORM{$formdata};
       $FORM{$formdata} =~ s/\n//ig;        $FORM{$formdata} =~ s/\n//ig;
   }    }
   
   if ($iamguest) {    if ($iamguest) {
       push @errorlog, int(time()) . "|$date|$user_ip|$tmperror|$action|$INFO{'num'}|$currentboard|$FORM{'username'}|$FORM{'passwrd'}";        push @errorlog, int(time()) . "|$date|$user_ip|$tmperror|$action|$INFO{'num'}|$currentboard|$FORM{'username'}|$FORM{'passwrd'}";
   } else {    } else {
       push @errorlog, int(time()) . "|$date|$user_ip|$tmperror|$action|$INFO{'num'}|$currentboard|$username|$FORM{'passwrd'}";        push @errorlog, int(time()) . "|$date|$user_ip|$tmperror|$action|$INFO{'num'}|$currentboard|$username|$FORM{'passwrd'}";
   }    }
   foreach (@errorlog) {    foreach (@errorlog) {
       chomp;        chomp;
       if ($_ ne "") {        if ($_ ne "") {
           print ERRORLOG $_ . "\n";            print ERRORLOG $_ . "\n";
       }        }
   }    }
   fclose(ERRORLOG);    fclose(ERRORLOG);
} }
   
sub fatal_error { sub fatal_error {
   my $verbose = $!;    my $verbose = $!;
   
   &LoadLanguage('Error');    &LoadLanguage('Error');
   my $errormessage = "$error_txt{$_[0]} $_[1]";    my $errormessage = "$error_txt{$_[0]} $_[1]";
   
   # Gets filename and line where fatal_error was called.    # Gets filename and line where fatal_error was called.
   # Need to go further back to get correct subroutine name,    # Need to go further back to get correct subroutine name,
   # otherwise will print fatal_error as current subroutine!    # otherwise will print fatal_error as current subroutine!
   (undef, $e_filename, $e_line) = caller(0);    (undef, $e_filename, $e_line) = caller(0);
   (undef, undef, undef, $e_subroutine) = caller(1);    (undef, undef, undef, $e_subroutine) = caller(1);
   (undef, $e_subroutine) = split(/::/, $e_subroutine);    (undef, $e_subroutine) = split(/::/, $e_subroutine);
   if (($debug == 1 || ($debug == 2 && $iamadmin)) && ($e_filename || $e_line || $e_subroutine)) { $errormessage .= "<br />$maintxt{'error_location'}: $e_filename<br />$maintxt{'error_line'}: $e_line<br />$maintxt{'error_subroutine'}: $e_subroutine"; }    if (($debug == 1 || ($debug == 2 && $iamadmin)) && ($e_filename || $e_line || $e_subroutine)) { $errormessage .= "<br />$maintxt{'error_location'}: $e_filename<br />$maintxt{'error_line'}: $e_line<br />$maintxt{'error_subroutine'}: $e_subroutine"; }
   
   if ($_[2]) { $errormessage .= "<br />$maintxt{'error_verbose'}: $verbose"; }    if ($_[2]) { $errormessage .= "<br />$maintxt{'error_verbose'}: $verbose"; }
   
   if ($elenable) { &fatal_error_logging($errormessage); }    if ($elenable) { &fatal_error_logging($errormessage); }
   
   if ($_[0] =~ /no_access|members_only|no_perm/) {    if ($_[0] =~ /no_access|members_only|no_perm/) {
       $headerstatus = "403 Forbidden";        $headerstatus = "403 Forbidden";
   } elsif ($_[0] =~ /cannot_open|no.+_found/) {    } elsif ($_[0] =~ /cannot_open|no.+_found/) {
       $headerstatus = "404 Not Found";        $headerstatus = "404 Not Found";
   }    }
   
   $yymain .= qq~    $yymain .= qq~
<table border="0" width="80%" cellspacing="1" class="bordercolor" align="center" cellpadding="4"> <table border="0" width="80%" cellspacing="1" class="bordercolor" align="center" cellpadding="4">
   <tr>    <tr>
       <td class="titlebg"><span class="text1"><b>$maintxt{'error_description'}</b></span></td>        <td class="titlebg"><span class="text1"><b>$maintxt{'error_description'}</b></span></td>
   </tr><tr>    </tr><tr>
       <td class="windowbg"><br /><span class="text1">$errormessage</span><br /><br /></td>        <td class="windowbg"><br /><span class="text1">$errormessage</span><br /><br /></td>
   </tr>    </tr>
</table> </table>
<center><br /><a href="javascript:history.go(-1)">$maintxt{'193'}</a></center> <center><br /><a href="javascript:history.go(-1)">$maintxt{'193'}</a></center>
~; ~;
   
   $yytitle = "$maintxt{'error_description'}";    $yytitle = "$maintxt{'error_description'}";
   &template;    &template;
} }
   
sub admin_fatal_error { sub admin_fatal_error {
   my $verbose = $!;    my $verbose = $!;
   
   &LoadLanguage('Error');    &LoadLanguage('Error');
   my $errormessage = "$error_txt{$_[0]} $_[1]";    my $errormessage = "$error_txt{$_[0]} $_[1]";
   
   # Gets filename and line where fatal_error was called.    # Gets filename and line where fatal_error was called.
   # Need to go further back to get correct subroutine name,    # Need to go further back to get correct subroutine name,
   # otherwise will print fatal_error as current subroutine!    # otherwise will print fatal_error as current subroutine!
   (undef, $e_filename, $e_line) = caller(0);    (undef, $e_filename, $e_line) = caller(0);
   (undef, undef, undef, $e_subroutine) = caller(1);    (undef, undef, undef, $e_subroutine) = caller(1);
   (undef, $e_subroutine) = split(/::/, $e_subroutine);    (undef, $e_subroutine) = split(/::/, $e_subroutine);
   if (($debug == 1 || ($debug == 2 && $iamadmin)) && ($e_filename || $e_line || $e_subroutine)) { $errormessage .= "<br />$maintxt{'error_location'}: $e_filename<br />$maintxt{'error_line'}: $e_line<br />$maintxt{'error_subroutine'}: $e_subroutine"; }    if (($debug == 1 || ($debug == 2 && $iamadmin)) && ($e_filename || $e_line || $e_subroutine)) { $errormessage .= "<br />$maintxt{'error_location'}: $e_filename<br />$maintxt{'error_line'}: $e_line<br />$maintxt{'error_subroutine'}: $e_subroutine"; }
   
   if ($_[2]) { $errormessage .= "<br />$maintxt{'error_verbose'}: $verbose"; }    if ($_[2]) { $errormessage .= "<br />$maintxt{'error_verbose'}: $verbose"; }
   
   if ($elenable) { &fatal_error_logging($errormessage); }    if ($elenable) { &fatal_error_logging($errormessage); }
   
   $yymain .= qq~    $yymain .= qq~
<table border="0" width="80%" cellspacing="1" class="bordercolor" align="center" cellpadding="4"> <table border="0" width="80%" cellspacing="1" class="bordercolor" align="center" cellpadding="4">
   <tr>    <tr>
       <td class="titlebg"><span class="text1"><b>$maintxt{'error_description'}</b></span></td>        <td class="titlebg"><span class="text1"><b>$maintxt{'error_description'}</b></span></td>
   </tr><tr>    </tr><tr>
       <td class="windowbg"><br /><span class="text1">$errormessage</span><br /><br /></td>        <td class="windowbg"><br /><span class="text1">$errormessage</span><br /><br /></td>
   </tr>    </tr>
</table> </table>
<center><br /><a href="javascript:history.go(-1)">$admin_txt{'193'}</a></center> <center><br /><a href="javascript:history.go(-1)">$admin_txt{'193'}</a></center>
~; ~;
   
   $yytitle = "$maintxt{'error_description'}";    $yytitle = "$maintxt{'error_description'}";
   &AdminTemplate;    &AdminTemplate;
} }
   
sub FindPermalink { sub FindPermalink {
   $old_env = $_[0];    $old_env = $_[0];
   $old_env = substr($old_env,1, length($old_env));    $old_env = substr($old_env,1, length($old_env));
   $permtopicfound = 0;    $permtopicfound = 0;
   $permboardfound = 0;    $permboardfound = 0;
   $is_perm = 1;    $is_perm = 1;
   ## strip off symlink for redirectlike e.g. /articles/ ##    ## strip off symlink for redirectlike e.g. /articles/ ##
   $old_env =~ s~$symlink~~g;    $old_env =~ s~$symlink~~g;
   ## get date/time/board/topic from permalink    ## get date/time/board/topic from permalink
   
   ($permyear, $permmonth, $permday, $permboard, $permnum) = split (/\//, $old_env);    ($permyear, $permmonth, $permday, $permboard, $permnum) = split (/\//, $old_env);
   if(-e "$boardsdir/$permboard.txt") {    if(-e "$boardsdir/$permboard.txt") {
       $permboardfound = 1;        $permboardfound = 1;
       if($permnum ne "" && -e "$datadir/$permnum.txt") {        if($permnum ne "" && -e "$datadir/$permnum.txt") {
           $new_env = qq~num=$permnum~;            $new_env = qq~num=$permnum~;
           $permtopicfound = 1;            $permtopicfound = 1;
       } else { $new_env = qq~board=$permboard~; }        } else { $new_env = qq~board=$permboard~; }
   }    }
   return $new_env;    return $new_env;
} }
   
sub permtimer { sub permtimer {
   my $thetime = $_[0];    my $thetime = $_[0];
   my (undef, $pmin, $phour, $pmday, $pmon, $pyear, undef, undef, undef) = gmtime($thetime + (3600 * $timeoffset));    my (undef, $pmin, $phour, $pmday, $pmon, $pyear, undef, undef, undef) = gmtime($thetime + (3600 * $timeoffset));
   my $pmon_num = $pmon + 1;    my $pmon_num = $pmon + 1;
   $phour = sprintf("%02d", $phour);    $phour = sprintf("%02d", $phour);
   $pmin = sprintf("%02d", $pmin);    $pmin = sprintf("%02d", $pmin);
   $pyear = 1900 + $pyear;    $pyear = 1900 + $pyear;
   $pmon_num = sprintf("%02d", $pmon_num);    $pmon_num = sprintf("%02d", $pmon_num);
   $pmday = sprintf("%02d", $pmday);    $pmday = sprintf("%02d", $pmday);
   $pyear = sprintf("%04d", $pyear);    $pyear = sprintf("%04d", $pyear);
   return "$pyear/$pmon_num/$pmday";    return "$pyear/$pmon_num/$pmday";
} }
   
sub readform { sub readform {
   my (@pairs, $pair, $name, $value);    my (@pairs, $pair, $name, $value);
   if (substr($ENV{QUERY_STRING},0,1) eq "/" && $accept_permalink) { $ENV{QUERY_STRING} = &FindPermalink($ENV{QUERY_STRING}); }    if (substr($ENV{QUERY_STRING},0,1) eq "/" && $accept_permalink) { $ENV{QUERY_STRING} = &FindPermalink($ENV{QUERY_STRING}); }
   if ($ENV{QUERY_STRING} =~ m/action\=dereferer/) {    if ($ENV{QUERY_STRING} =~ m/action\=dereferer/) {
       $INFO{'action'} = "dereferer";        $INFO{'action'} = "dereferer";
       $urlstart = index($ENV{QUERY_STRING}, "url=");        $urlstart = index($ENV{QUERY_STRING}, "url=");
       $INFO{'url'} = substr($ENV{QUERY_STRING}, $urlstart + 4, length($ENV{QUERY_STRING}) - $urlstart + 3);        $INFO{'url'} = substr($ENV{QUERY_STRING}, $urlstart + 4, length($ENV{QUERY_STRING}) - $urlstart + 3);
       $INFO{'url'} =~ s/\;anch\=/#/g;        $INFO{'url'} =~ s/\;anch\=/#/g;
       $testenv = "";        $testenv = "";
   } else {    } else {
       $testenv = $ENV{QUERY_STRING};        $testenv = $ENV{QUERY_STRING};
       $testenv =~ s/\&/\;/g;        $testenv =~ s/\&/\;/g;
       if ($testenv && $debug) { $getpairs = qq~<br /><u>$debug_txt{'getpairs'}:</u><br />~; }        if ($testenv && $debug) { $getpairs = qq~<br /><u>$debug_txt{'getpairs'}:</u><br />~; }
   }    }
   # URL encoding for web.de http://www.blooberry.com/indexdot/html/topics/urlencoding.htm    # URL encoding for web.de http://www.blooberry.com/indexdot/html/topics/urlencoding.htm
   $testenv =~ s/\%3B/;/ig; # search must be case insensitiv for some servers!    $testenv =~ s/\%3B/;/ig; # search must be case insensitiv for some servers!
   $testenv =~ s/\%26/&/g;    $testenv =~ s/\%26/&/g;
   
   &split_string(\$testenv, \%INFO, 1);    &split_string(\$testenv, \%INFO, 1);
   if ($ENV{'SERVER_SOFTWARE'} =~ /IIS/) {    if ($ENV{'SERVER_SOFTWARE'} =~ /IIS/) {
       ($dummy,$IISver) = split( '\/', $ENV{'SERVER_SOFTWARE'});        ($dummy,$IISver) = split( '\/', $ENV{'SERVER_SOFTWARE'});
       ($IISver,$IISverM) = split( '.',$IISver);        ($IISver,$IISverM) = split( '.',$IISver);
       if (int($IISver) < 6 && int($IISverM) < 1) { eval 'use CGI qw(:standard)'; }        if (int($IISver) < 6 && int($IISverM) < 1) { eval 'use CGI qw(:standard)'; }
   }    }
   if ($ENV{REQUEST_METHOD} eq 'POST') {    if ($ENV{REQUEST_METHOD} eq 'POST') {
       if ($debug) { $getpairs .= qq~<br /><u>$debug_txt{'postpairs'}:</u><br />~; }        if ($debug) { $getpairs .= qq~<br /><u>$debug_txt{'postpairs'}:</u><br />~; }
       if ($ENV{CONTENT_TYPE} =~ /multipart\/form-data/) {        if ($ENV{CONTENT_TYPE} =~ /multipart\/form-data/) {
           require CGI;            require CGI;
           # A possible attack is for the remote user to force CGI.pm to accept            # A possible attack is for the remote user to force CGI.pm to accept
           # a huge file upload. CGI.pm will accept the upload and store it in            # a huge file upload. CGI.pm will accept the upload and store it in
           # a temporary directory even if your script doesn't expect to receive            # a temporary directory even if your script doesn't expect to receive
           # an uploaded file. CGI.pm will delete the file automatically when it            # an uploaded file. CGI.pm will delete the file automatically when it
           # terminates, but in the meantime the remote user may have filled up            # terminates, but in the meantime the remote user may have filled up
           # the server's disk space, causing problems for other programs.            # the server's disk space, causing problems for other programs.
           # The best way to avoid denial of service attacks is to limit the            # The best way to avoid denial of service attacks is to limit the
           # amount of memory, CPU time and disk space that CGI scripts can use.            # amount of memory, CPU time and disk space that CGI scripts can use.
           # If $CGI::POST_MAX is set to a non-negative integer, this variable            # If $CGI::POST_MAX is set to a non-negative integer, this variable
           # puts a ceiling on the size of POSTings, in bytes. If CGI.pm detects            # puts a ceiling on the size of POSTings, in bytes. If CGI.pm detects
           # a POST that is greater than the ceiling, it will immediately exit            # a POST that is greater than the ceiling, it will immediately exit
           # with an error message like this:            # with an error message like this:
           # "413 Request entity too large"            # "413 Request entity too large"
           # This value will affect both ordinary POSTs and multipart POSTs,            # This value will affect both ordinary POSTs and multipart POSTs,
           # meaning that it limits the maximum size of file uploads as well.            # meaning that it limits the maximum size of file uploads as well.
           if ($allowattach && $ENV{'QUERY_STRING'} =~ /action=(post|modify)2\b/) {            if ($allowattach && $ENV{'QUERY_STRING'} =~ /action=(post|modify)2\b/) {
               $CGI::POST_MAX = int(1024 * $limit * $allowattach);                $CGI::POST_MAX = int(1024 * $limit * $allowattach);
               $CGI::POST_MAX += 1000000 if $CGI::POST_MAX; # *                $CGI::POST_MAX += 1000000 if $CGI::POST_MAX; # *
           } elsif ($upload_useravatar && $ENV{'QUERY_STRING'} =~ /action=profileOptions2\b/) {            } elsif ($upload_useravatar && $ENV{'QUERY_STRING'} =~ /action=profileOptions2\b/) {
               $CGI::POST_MAX = int(1024 * $avatar_limit);                $CGI::POST_MAX = int(1024 * $avatar_limit);
               $CGI::POST_MAX += 1000000 if $CGI::POST_MAX; # *                $CGI::POST_MAX += 1000000 if $CGI::POST_MAX; # *
           } else {            } else {
               # If NO uploads are allowed YaBB sets this default limit                # If NO uploads are allowed YaBB sets this default limit
               # to 1 MB. Change this values if you get error messages.                # to 1 MB. Change this values if you get error messages.
               $CGI::POST_MAX = 1000000;                $CGI::POST_MAX = 1000000;
           }            }
           # * adds volume, if a upload limit is set, to not get error if the other            # * adds volume, if a upload limit is set, to not get error if the other
           # uploaded data is larger. Change this values if you get error messages.            # uploaded data is larger. Change this values if you get error messages.
           $CGI_query = new CGI; # $CGI_query must be a global variable            $CGI_query = new CGI; # $CGI_query must be a global variable
           my ($name, @value);            my ($name, @value);
           foreach $name ($CGI_query->param()) {            foreach $name ($CGI_query->param()) {
               next if $name =~ /^file(\d+|_avatar)$/; # files are directly called in Profile.pl, Post.pl and ModifyMessages.pl                next if $name =~ /^file(\d+|_avatar)$/; # files are directly called in Profile.pl, Post.pl and ModifyMessages.pl
               @value = $CGI_query->param($name);                @value = $CGI_query->param($name);
               if ($debug) { $getpairs .= qq~[$debug_txt{'name'}-&gt;]$name=@value\[&lt;-$debug_txt{'value'}]<br />~; }                if ($debug) { $getpairs .= qq~[$debug_txt{'name'}-&gt;]$name=@value\[&lt;-$debug_txt{'value'}]<br />~; }
               $FORM{$name} = join(', ', @value); # multiple values are joined                $FORM{$name} = join(', ', @value); # multiple values are joined
           }            }
       } else {        } else {
           read(STDIN, my $input, $ENV{CONTENT_LENGTH});            read(STDIN, my $input, $ENV{CONTENT_LENGTH});
           &split_string(\$input, \%FORM);            &split_string(\$input, \%FORM);
       }        }
   }    }
   $action = $INFO{'action'} || $FORM{'action'};    $action = $INFO{'action'} || $FORM{'action'};
   # Formsession checking moved to YaBB.pl to fix a bug.    # Formsession checking moved to YaBB.pl to fix a bug.
   if ($INFO{'username'} && $do_scramble_id) { $INFO{'username'} = &decloak($INFO{'username'}); }    if ($INFO{'username'} && $do_scramble_id) { $INFO{'username'} = &decloak($INFO{'username'}); }
   if ($FORM{'username'} && $do_scramble_id && $action ne "login2" && $action ne "reminder2" && $action ne "register2" && $action ne "profile2") { $FORM{'username'} = &decloak($FORM{'username'}); }    if ($FORM{'username'} && $do_scramble_id && $action ne "login2" && $action ne "reminder2" && $action ne "register2" && $action ne "profile2") { $FORM{'username'} = &decloak($FORM{'username'}); }
   if ($INFO{'to'} && $do_scramble_id) { $INFO{'to'} = &decloak($INFO{'to'}); }    if ($INFO{'to'} && $do_scramble_id) { $INFO{'to'} = &decloak($INFO{'to'}); }
   if ($FORM{'to'} && $do_scramble_id) { $FORM{'to'} = &decloak($FORM{'to'}); }    if ($FORM{'to'} && $do_scramble_id) { $FORM{'to'} = &decloak($FORM{'to'}); }
   
   # Dont do this here or you get problems with foreign characters!!!!    # Dont do this here or you get problems with foreign characters!!!!
   #if ($action eq 'search2') { &FromHTML($FORM{'search'}); }    #if ($action eq 'search2') { &FromHTML($FORM{'search'}); }
   #&ToHTML($INFO{'title'});    #&ToHTML($INFO{'title'});
   #&ToHTML($FORM{'title'});    #&ToHTML($FORM{'title'});
   #&ToHTML($INFO{'subject'});    #&ToHTML($INFO{'subject'});
   #&ToHTML($FORM{'subject'});    #&ToHTML($FORM{'subject'});
   
   sub split_string {    sub split_string {
       my ($string, $hash, $altdelim) = @_;        my ($string, $hash, $altdelim) = @_;
   
       if ($altdelim && $$string =~ m~;~) { @pairs = split(/;/, $$string); }        if ($altdelim && $$string =~ m~;~) { @pairs = split(/;/, $$string); }
       else { @pairs = split(/&/, $$string); }        else { @pairs = split(/&/, $$string); }
       foreach $pair (@pairs) {        foreach $pair (@pairs) {
           my ($name, $value) = split(/=/, $pair);            my ($name, $value) = split(/=/, $pair);
           $name  =~ tr/+/ /;            $name  =~ tr/+/ /;
           $name  =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;            $name  =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
           $value =~ tr/+/ /;            $value =~ tr/+/ /;
           $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;            $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
           if ($debug) { $getpairs .= qq~[$debug_txt{'name'}-&gt;]$name=$value\[&lt;-$debug_txt{'value'}]<br />~; }            if ($debug) { $getpairs .= qq~[$debug_txt{'name'}-&gt;]$name=$value\[&lt;-$debug_txt{'value'}]<br />~; }
           if (exists($hash->{$name})) {            if (exists($hash->{$name})) {
               $hash->{$name} .= ", $value";                $hash->{$name} .= ", $value";
           } else {            } else {
               $hash->{$name} = $value;                $hash->{$name} = $value;
           }            }
       }        }
   }    }
} }
   
sub getlog { sub getlog {
   return if %yyuserlog || $iamguest || !$max_log_days_old || !-e "$memberdir/$username.log";    return if %yyuserlog || $iamguest || !$max_log_days_old || !-e "$memberdir/$username.log";
   
   %yyuserlog = ();    %yyuserlog = ();
   fopen(GETLOG, "$memberdir/$username.log");    fopen(GETLOG, "$memberdir/$username.log");
   my @logentries = <GETLOG>;    my @logentries = <GETLOG>;
   fclose(GETLOG);    fclose(GETLOG);
   chomp(@logentries);    chomp(@logentries);
   
   my ($name,$thistime);    my ($name,$thistime);
   foreach (@logentries) {    foreach (@logentries) {
       ($name,$thistime) = split(/\|/, $_);        ($name,$thistime) = split(/\|/, $_);
       if ($name && $thistime) { $yyuserlog{$name} = $thistime; }        if ($name && $thistime) { $yyuserlog{$name} = $thistime; }
   }    }
} }
   
sub dumplog { sub dumplog {
   return if $iamguest || !$max_log_days_old;    return if $iamguest || !$max_log_days_old;
   
   if ($_[0]) {    if ($_[0]) {
       &getlog;        &getlog;
       $yyuserlog{$_[0]} = $_[1] || $date;        $yyuserlog{$_[0]} = $_[1] || $date;
   }    }
   if (%yyuserlog) {    if (%yyuserlog) {
       my $name;        my $name;
       $date2 = $date;        $date2 = $date;
       fopen(DUMPLOG, ">$memberdir/$username.log");        fopen(DUMPLOG, ">$memberdir/$username.log");
       while (($name,$date1) = each(%yyuserlog)) {        while (($name,$date1) = each(%yyuserlog)) {
           &calcdifference; # output => $result            &calcdifference; # output => $result
           if ($result <= $max_log_days_old) {            if ($result <= $max_log_days_old) {
               print DUMPLOG qq~$name|$date1\n~;                print DUMPLOG qq~$name|$date1\n~;
           }            }
       }        }
       fclose(DUMPLOG);        fclose(DUMPLOG);
   }    }
} }
   
## standard jump to menu ## standard jump to menu
sub jumpto { sub jumpto {
   my (@masterdata, $category, @data, $found, $tmp, @memgroups, @newcatdata, $boardname);    my (@masterdata, $category, @data, $found, $tmp, @memgroups, @newcatdata, $boardname);
   ## jump links to messages/favourites/notifications.    ## jump links to messages/favourites/notifications.
   my $action = 'action=jump';    my $action = 'action=jump';
   my $onchange = qq~ onchange="if(this.options[this.selectedIndex].value) window.location.href='$scripturl?' + this.options[this.selectedIndex].value;"~;    my $onchange = qq~ onchange="if(this.options[this.selectedIndex].value) window.location.href='$scripturl?' + this.options[this.selectedIndex].value;"~;
   if ($templatejump == 1) {    if ($templatejump == 1) {
       $action = 'action=';        $action = 'action=';
       $onchange = '';        $onchange = '';
   }    }
   $selecthtml = qq~    $selecthtml = qq~
<form method="post" action="$scripturl?$action" name="jump" style="display: inline;"> <form method="post" action="$scripturl?$action" name="jump" style="display: inline;">
<select name="values"$onchange> <select name="values"$onchange>
   <option value="" class="forumjump">$jumpto_txt{'to'}</option>\n    <option value="" class="forumjump">$jumpto_txt{'to'}</option>\n
   <option value="gohome">$img_txt{'103'}</option>\n~;    <option value="gohome">$img_txt{'103'}</option>\n~;
   
   ## as guests don't have these, why show them?    ## as guests don't have these, why show them?
   if (!$iamguest) {    if (!$iamguest) {
       $selecthtml .= qq~        $selecthtml .= qq~
   <option value="action=im" class="forumjumpcatm">$jumpto_txt{'mess'}</option>~ if $PM_level == 1 || ($PM_level == 2 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && ($iamadmin || $iamgmod));    <option value="action=im" class="forumjumpcatm">$jumpto_txt{'mess'}</option>~ if $PM_level == 1 || ($PM_level == 2 && ($iamadmin || $iamgmod || $iammod)) || ($PM_level == 3 && ($iamadmin || $iamgmod));
       $selecthtml .= qq~        $selecthtml .= qq~
   <option value="action=shownotify" class="forumjumpcatmf">$jumpto_txt{'note'}</option>    <option value="action=shownotify" class="forumjumpcatmf">$jumpto_txt{'note'}</option>
   <option value="action=favorites" class="forumjumpcatm">$jumpto_txt{'fav'}</option>~;    <option value="action=favorites" class="forumjumpcatm">$jumpto_txt{'fav'}</option>~;
   }    }
   
   # drop in recent topics/posts lists. guests can see if browsing permitted    # drop in recent topics/posts lists. guests can see if browsing permitted
   $selecthtml .= qq~    $selecthtml .= qq~
   <option value="action=recent;display=10">$recent_txt{'recentposts'}</option>    <option value="action=recent;display=10">$recent_txt{'recentposts'}</option>
   <option value="action=recenttopics;display=10">$recent_txt{'recenttopic'}</option>\n~;    <option value="action=recenttopics;display=10">$recent_txt{'recenttopic'}</option>\n~;
   
   unless ($mloaded == 1) { require "$boardsdir/forum.master"; }    unless ($mloaded == 1) { require "$boardsdir/forum.master"; }
   foreach $catid (@categoryorder) {    foreach $catid (@categoryorder) {
       @bdlist = split(/,/, $cat{$catid});        @bdlist = split(/,/, $cat{$catid});
       ($catname, $catperms) = split(/\|/, $catinfo{"$catid"});        ($catname, $catperms) = split(/\|/, $catinfo{"$catid"});
   
       $cataccess = &CatAccess($catperms);        $cataccess = &CatAccess($catperms);
       if (!$cataccess) { next; }        if (!$cataccess) { next; }
       &ToChars($catname);        &ToChars($catname);
       ## I've removed the dashed bands and css handles the cat highlighting.        ## I've removed the dashed bands and css handles the cat highlighting.
       $selecthtml .= $INFO{'catselect'} eq $catid ? qq~    <option selected=\"selected\" value="catselect=$catid" class="forumjumpcat">&raquo;&raquo; $catname</option>\n~ : qq~ <option value="catselect=$catid" class="forumjumpcat">$catname</option>\n~;        $selecthtml .= $INFO{'catselect'} eq $catid ? qq~    <option selected=\"selected\" value="catselect=$catid" class="forumjumpcat">&raquo;&raquo; $catname</option>\n~ : qq~ <option value="catselect=$catid" class="forumjumpcat">$catname</option>\n~;
       foreach $board (@bdlist) {        foreach $board (@bdlist) {
           ($boardname, $boardperms, $boardview) = split(/\|/, $board{"$board"});            ($boardname, $boardperms, $boardview) = split(/\|/, $board{"$board"});
           &ToChars($boardname);            &ToChars($boardname);
           my $access = &AccessCheck($board, '', $boardperms);            my $access = &AccessCheck($board, '', $boardperms);
           if (!$iamadmin && $access ne "granted" && $boardview != 1) { next; }            if (!$iamadmin && $access ne "granted" && $boardview != 1) { next; }
           if ($board eq $annboard && !$iamadmin && !$iamgmod) { next; }            if ($board eq $annboard && !$iamadmin && !$iamgmod) { next; }
   
           if ($board eq $currentboard) { $selecthtml .= $INFO{'num'} ? "   <option value=\"board=$board\" class=\"forumcurrentboard\">&nbsp; - $boardname &#171;&#171;</option>\n" : "   <option selected=\"selected\" value=\"board=$board\" class=\"forumcurrentboard\">&raquo;&raquo; $boardname</option>\n"; }            if ($board eq $currentboard) { $selecthtml .= $INFO{'num'} ? "   <option value=\"board=$board\" class=\"forumcurrentboard\">&nbsp; - $boardname &#171;&#171;</option>\n" : "   <option selected=\"selected\" value=\"board=$board\" class=\"forumcurrentboard\">&raquo;&raquo; $boardname</option>\n"; }
           else { $selecthtml .= "   <option value=\"board=$board\">&nbsp; - $boardname</option>\n"; }            else { $selecthtml .= "   <option value=\"board=$board\">&nbsp; - $boardname</option>\n"; }
       }        }
   }    }
   $selecthtml .= qq~</select>    $selecthtml .= qq~</select>
<noscript><input type="submit" value="$maintxt{'32'}" class="button" /></noscript> <noscript><input type="submit" value="$maintxt{'32'}" class="button" /></noscript>
</form>~; </form>~;
} }
   
sub dojump { sub dojump {
   $yySetLocation = $scripturl . $FORM{'values'};    $yySetLocation = $scripturl . $FORM{'values'};
   &redirectexit;    &redirectexit;
} }
   
sub spam_protection { sub spam_protection {
   unless ($timeout) { return; }    unless ($timeout) { return; }
   my ($time, $flood_ip, $flood_time, $flood, @floodcontrol);    my ($time, $flood_ip, $flood_time, $flood, @floodcontrol);
   
   if (-e "$vardir/flood.txt") {    if (-e "$vardir/flood.txt") {
       fopen(FLOOD, "$vardir/flood.txt");        fopen(FLOOD, "$vardir/flood.txt");
       push(@floodcontrol, "$user_ip|$date\n");        push(@floodcontrol, "$user_ip|$date\n");
       while (<FLOOD>) {        while (<FLOOD>) {
           chomp($_);            chomp($_);
           ($flood_ip, $flood_time) = split(/\|/, $_);            ($flood_ip, $flood_time) = split(/\|/, $_);
           if ($user_ip eq $flood_ip && $date - $flood_time <= $timeout) { $flood = 1; }            if ($user_ip eq $flood_ip && $date - $flood_time <= $timeout) { $flood = 1; }
           elsif ($date - $flood_time < $timeout) { push(@floodcontrol, "$_\n"); }            elsif ($date - $flood_time < $timeout) { push(@floodcontrol, "$_\n"); }
       }        }
       fclose(FLOOD);        fclose(FLOOD);
   }    }
   if ($flood && !$iamadmin && $action eq 'post2') { &Preview("$maintxt{'409'} $timeout $maintxt{'410'}"); }    if ($flood && !$iamadmin && $action eq 'post2') { &Preview("$maintxt{'409'} $timeout $maintxt{'410'}"