F:\WEBSITES\testbed\zipped\yabb_svn_new\branches\2.5.2\cgi-bin\yabb2\Sources\HelpCentre.pl F:\WEBSITES\testbed\zipped\yabb_svn_new\trunk\cgi-bin\yabb2\Sources\HelpCentre.pm
############################################################################### ###############################################################################
# HelpCentre.pl                                                               # # HelpCentre.pm                                                               #
  # $Date: 01.05.16 $                                                           #
############################################################################### ###############################################################################
# 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.6.12                                                 #
# Packaged:       October 21, 2012                                            # # Packaged:       January 5, 2016                                             #
# 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-2016 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.                      #
############################################################################### ###############################################################################
  use CGI::Carp qw(fatalsToBrowser);
  our $VERSION = '2.6.12';
   
$helpcentreplver = 'YaBB 2.5.2 $Revision: 1.0 $'; $helpcentrepmver = 'YaBB 2.6.12 $Revision: 1713 $';
if ($action eq 'detailedversion') { return 1; } if ( $action eq 'detailedversion' ) { return 1; }
   
&LoadLanguage('HelpCentre');  LoadLanguage('HelpCentre'); 
   
  require Sources::Menu;
$yytitle = $helptxt{'1'}; $yytitle = $helptxt{'1'};
undef $guest_media_disallowed; undef $guest_media_disallowed;
   
  @my_modimglist =
   qw( admin_rem admin_move_split_splice admin_lock hide admin_sticky admin_del );
  $my_moding = q{};
  foreach (@my_modimglist) {
     $modimg = SetImage( $_, $UseMenuType );
     $mymoding .= qq~$menusep$modimg~;
  }
  $mymoding =~ s/\Q$menusep//ism;
   
sub SectionDecide { sub SectionDecide {
   # This bit decides what section we are in and sets the background accordingly  
   # Also sets the variables are used to open up the correct Help Directory  
   $moderator_class  = "catbg";  
   $admin_class      = "catbg";  
   $global_mod_class = "catbg";  
   $UserClass        = "catbg";  
   
   if ($UseHelp_Perms) {  
       $ismod = 0;  
       unless (exists $memberinfo{$username}) { &LoadUser($username); }  
       foreach $catid (@categoryorder) {  
           if ($ismod) { last; }  
           $boardlist = $cat{$catid};  
           (@bdlist) = split(/\,/, $boardlist);  
           foreach $curboard (@bdlist) {  
               if ($ismod) { last; }  
               foreach $curuser (split(/, ?/, ${$uid.$curboard}{'mods'})) {  
                   if ($curuser eq $username) { $ismod = 1; last; }  
               }  
               foreach (split(/, /, ${$uid.$curboard}{'modgroups'})) {  
                   if ($_ eq ${$uid.$username}{'position'}) { $ismod = 1; last; }  
               }  
           }  
       }  
   }  
   
   if ($INFO{'section'} eq "admin") {  
       if ($UseHelp_Perms && !$iamadmin) { &fatal_error("no_access","HelpCentre->SectionDecide"); }  
       ${ $INFO{'section'} . _class } = "titlebg";  
       $help_area = "Admin";  
   } elsif ($INFO{'section'} eq "moderator") {  
       if ($UseHelp_Perms && !$ismod && !$iamgmod && !$iamadmin) { &fatal_error("no_access","HelpCentre->SectionDecide"); }  
       ${ $INFO{'section'} . _class } = "titlebg";  
       $help_area = "Moderator";  
   } elsif ($INFO{'section'} eq "global_mod") {  
       if ($UseHelp_Perms && !$iamgmod && !$iamadmin) { &fatal_error("no_access","HelpCentre->SectionDecide"); }  
       ${ $INFO{'section'} . _class } = "titlebg";  
       $help_area = "Gmod";  
   } else {  
       $UserClass = "titlebg";  
       $help_area = "User";  
   }  
   
    # This bit decides what section we are in and sets the background accordingly
    # Also sets the variables are used to open up the correct Help Directory
   
     if ($UseHelp_Perms) {
         $ismod = 0;
         if ( !exists $memberinfo{$username} ) { LoadUser($username); }
         foreach my $catid (@categoryorder) {
             if ($ismod) { last; }
             $boardlist = $cat{$catid};
             (@bdlist) = split /\,/xsm, $boardlist;
             foreach my $curboard (@bdlist) {
                 if ($ismod) { last; }
                 foreach
                   my $curuser ( split /, ?/sm, ${ $uid . $curboard }{'mods'} )
                 {
                     if ( $curuser eq $username ) { $ismod = 1; last; }
                 }
                 foreach ( split /, /sm, ${ $uid . $curboard }{'modgroups'} ) {
                     if ( $_ eq ${ $uid . $username }{'position'} ) {
                         $ismod = 1;
                         last;
                     }
                 }
             }
         }
     }
   
     if ( $INFO{'section'} eq 'admin' ) {
         if ( $UseHelp_Perms && !$iamadmin ) {
             fatal_error( 'no_access', 'HelpCentre->SectionDecide' );
         }
         ${ $INFO{'section'} . _class } = 'selected-bg';
         $help_area = 'Admin';
     }
     elsif ( $INFO{'section'} eq 'global_mod' ) {
         if ( $UseHelp_Perms && !$iamgmod && !$iamadmin ) {
             fatal_error( 'no_access', 'HelpCentre->SectionDecide' );
         }
         ${ $INFO{'section'} . _class } = 'selected-bg';
         $help_area = 'Gmod';
     }
     elsif ( $INFO{'section'} eq 'moderator' ) {
         if ( $UseHelp_Perms && !$ismod && !$iamgmod && !$iamadmin && !$iamfmod ) {
             fatal_error( 'no_access', 'HelpCentre->SectionDecide' );
         }
         ${ $INFO{'section'} . _class } = 'selected-bg';
         $help_area = 'Moderator';
     }
   
     else {
         $UserClass = 'selected-bg';
         $help_area = 'User';
     }
     return;
} }
   
sub SectionPrint { sub SectionPrint {
   # Prints the navigation bar for the help section  
   $userhlp = qq~<a href="$scripturl?action=help">$helptxt{'3'}</a>~;     # Prints the navigation bar for the help section 
   if ($UseHelp_Perms) {     $userhlp = qq~<a href="$scripturl?action=help">$helptxt{'3'}</a>~; 
       if (!$ismod && !$iamgmod && !$iamadmin) { return }     if ($UseHelp_Perms) { 
       if ($ismod || $iamgmod || $iamadmin) {         if ( !$ismod && !$iamgmod && !$iamadmin && !$iamfmod ) { return } 
           $modhlp = qq~<a href="$scripturl?action=help;section=moderator">$helptxt{'4'}</a>~;         if ( $ismod || $iamgmod || $iamadmin || $iamfmod ) { 
       } else {             $modhlp = 
           $modhlp = "&nbsp;";  qq~<a href="$scripturl?action=help;section=moderator">$helptxt{'4'}</a>~; 
       }        }
       if ($iamgmod || $iamadmin) {        else {
           $gmodhlp = qq~<a href="$scripturl?action=help;section=global_mod">$helptxt{'5'}</a>~;             $modhlp = '&nbsp;'; 
       } else {         } 
           $gmodhlp = "&nbsp;";         if ( $iamgmod || $iamadmin ) { 
       }             $gmodhlp = 
       if ($iamadmin) {  qq~<a href="$scripturl?action=help;section=global_mod">$helptxt{'5'}</a>~; 
           $adminhlp = qq~<a href="$scripturl?action=help;section=admin">$helptxt{'6'}</a>~;         } 
       } else {        else {
           $adminhlp = "&nbsp;";             $gmodhlp = '&nbsp;'; 
       }        }
   } else {        if ($iamadmin) {
       $modhlp   = qq~<a href="$scripturl?action=help;section=moderator">$helptxt{'4'}</a>~;             $adminhlp = 
       $gmodhlp  = qq~<a href="$scripturl?action=help;section=global_mod">$helptxt{'5'}</a>~;  qq~<a href="$scripturl?action=help;section=admin">$helptxt{'6'}</a>~; 
       $adminhlp = qq~<a href="$scripturl?action=help;section=admin">$helptxt{'6'}</a>~;         } 
   }         else { 
             $adminhlp = '&nbsp;';
   $HelpNavBar =~ s/<user menu>/$userhlp/g;         } 
   $HelpNavBar =~ s/<moderator menu>/$modhlp/g;     } 
   $HelpNavBar =~ s/<global mod menu>/$gmodhlp/g;     else { 
   $HelpNavBar =~ s/<admin menu>/$adminhlp/g;         $modhlp = 
   $HelpNavBar =~ s/<user class>/$UserClass/g;  qq~<a href="$scripturl?action=help;section=moderator">$helptxt{'4'}</a>~; 
   $HelpNavBar =~ s/<moderator class>/$moderator_class/g;         $gmodhlp = 
   $HelpNavBar =~ s/<global mod class>/$global_mod_class/g;  qq~<a href="$scripturl?action=help;section=global_mod">$helptxt{'5'}</a>~; 
   $HelpNavBar =~ s/<admin class>/$admin_class/g;         $adminhlp = 
   $yymain .= $HelpNavBar;  qq~<a href="$scripturl?action=help;section=admin">$helptxt{'6'}</a>~; 
     }
   
     $HelpNavBar =~ s/{user menu}/$userhlp/gsm;
     $HelpNavBar =~ s/{moderator menu}/$modhlp/gsm;
     $HelpNavBar =~ s/{global mod menu}/$gmodhlp/gsm;
     $HelpNavBar =~ s/{admin menu}/$adminhlp/gsm;
     $HelpNavBar =~ s/{user class}/$UserClass/gsm;
     $HelpNavBar =~ s/{moderator class}/$moderator_class/gsm;
     $HelpNavBar =~ s/{global mod class}/$global_mod_class/gsm;
     $HelpNavBar =~ s/{admin class}/$admin_class/gsm;
     $yymain .= $HelpNavBar;
     return $yymain;
   
} }
   
sub GetHelpFiles { sub GetHelpFiles {
   unless ($HelpTemplateLoaded) {    if ( !$HelpTemplateLoaded ) {
       if (-e ("$templatesdir/$usestyle/HelpCentre.template")) {         get_template('HelpCentre'); 
           require "$templatesdir/$usestyle/HelpCentre.template";     } 
       } else {  
           require "$templatesdir/default/HelpCentre.template";     SectionDecide(); 
       }  
   }     # This determines if the order file is present and if it isn't 
     # It creates a new one, in default alphabetical order
   &SectionDecide;     if ( !-e "$vardir/$help_area.helporder" ) { CreateOrderFile(); } 
   
   # This determines if the order file is present and if it isn't     fopen( HELPORDER, "$vardir/$help_area.helporder" ); 
   # It creates a new one, in default alphabetical order     my @helporderlist = <HELPORDER>; 
   &CreateOrderFile if !-e "$vardir/$help_area.helporder";     fclose(HELPORDER); 
     chomp @helporderlist;
   fopen(HELPORDER, "$vardir/$help_area.helporder");  
   my @helporderlist = <HELPORDER>;     foreach (@helporderlist) { 
   fclose(HELPORDER);         if ( -e "$helpfile/$language/$help_area/$_.help" ) { 
   chomp(@helporderlist);             require "$helpfile/$language/$help_area/$_.help"; 
         }
   foreach (@helporderlist) {        elsif ( -e "$helpfile/English/$help_area/$_.help" ) {
       if (-e "$helpfile/$language/$help_area/$_.help") {             require "$helpfile/English/$help_area/$_.help"; 
           require "$helpfile/$language/$help_area/$_.help";         } 
       } elsif (-e "$helpfile/English/$help_area/$_.help") {        else {
           require "$helpfile/English/$help_area/$_.help";             next; 
       } else {         } 
           next;  
       }         MainHelp(); 
         DoContents();
       &MainHelp;     } 
       &DoContents;  
   }     SectionPrint(); 
     ContentContainer();
   &SectionPrint;  
   &ContentContainer;     $yynavigation = qq~&rsaquo; $yytitle~; 
     template();
   $yynavigation = qq~&rsaquo; $yytitle~;     return; 
   &template;  
} }
   
sub MainHelp { sub MainHelp {
   
   $TempParse = $BodyHeader;    $TempParse = $BodyHeader;
   $TempParse =~ s/<yabb section_anchor>/$SectionName/g;     $BrdID = $mbname; 
   $SectionNam = $SectionName;     $BrdID =~ s/ /_/gsm; 
   $SectionNam =~ s/_/ /g;     $SectionName =~ s/{yabb myboardname}/$BrdID/gsm; 
   $TempParse  =~ s/<yabb section_name>/$SectionNam/g;     $SectionName =~ s/ /_/gsm; 
   $Body .= qq~$TempParse~;     $TempParse =~ s/{yabb section_anchor}/$SectionName/gsm; 
     $SectionNam = $SectionName;
   $i = 1;     $SectionNam =~ s/_/ /gsm; 
   while (${ SectionSub . $i }) {     $TempParse  =~ s/{yabb section_name}/$SectionNam/gsm; 
     $Body .= qq~$TempParse~;
       if (${ SectionExcl . $i } eq "yabbc" && (!$enable_ubbc || !$showyabbcbutt)) { $i++; next; }  
     $i = 1;
       $TempParse     = $BodySubHeader;     while ( ${ SectionSub . $i } ) { 
       $SectionAnchor = ${ SectionSub . $i };  
       $SectionSub    = ${ SectionSub . $i };         if ( ${ SectionExcl . $i } eq 'yabbc' 
       $SectionSub =~ s/_/ /g;             && ( !$enable_ubbc || !$showyabbcbutt ) ) 
       $TempParse  =~ s/<yabb section_anchor>/$SectionAnchor/g;         { 
       $TempParse  =~ s/<yabb section_sub>/$SectionSub/g;             $i++; 
       $Body .= qq~$TempParse~;             next; 
         }
       $message = ${ SectionBody . $i };  
       $displayname = ${$uid.$username}{'realname'};         $TempParse     = $BodySubHeader; 
       if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; }         $BrdID = $mbname; 
       $message =~ s~\[yabbc\](.*?)\[/yabbc\]~my($text) = $1; &ToHTML($text); &DoUBBCTo($text);~sge;         $BrdID =~ s/ /_/gsm; 
       &wrap2;         $SectionAnchor = ${ SectionSub . $i }; 
         $SectionSub    = ${ SectionSub . $i };
         $SectionSub =~ s/_/ /gsm;
         $SectionAnchor =~ s/{yabb myboardname}/$BrdID/gsm;
         $SectionAnchor =~ s/ /_/gsm;
         $TempParse  =~ s/{yabb section_anchor}/$SectionAnchor/gsm;
         $TempParse  =~ s/{yabb section_sub}/$SectionSub/gsm;
         $TempParse  =~ s/{yabb myboardname}/$mbname/gsm;
         $Body .= qq~$TempParse~;
   
         $message     = ${ SectionBody . $i };
         $displayname = ${ $uid . $username }{'realname'};
         enable_yabbc();
         $message =~
  s/\[yabbc\](.*?)\[\/yabbc\]/my($text) = $1; ToHTML($text); DoUBBCTo($text);/sgem;
         wrap2();
   
       if($SectionAnchor eq 'YaBBC_Reference') {        if ( $SectionAnchor eq 'YaBBC_Reference' ) {
           $yyinlinestyle .= qq~<style type="text/css">            $yyinlinestyle .= qq~<style type="text/css">
.yabbc td {width: 75%; text-align: left;} .yabbc td {width: 75%; text-align: left;}
.yabbc td:first-child {width: 25%; vertical-align: top;} .yabbc td:first-child {width: 25%; vertical-align: top;}
.yabbc th {width: 100%;} .yabbc th {width: 100%;}
.yabbc th img {float: left;} .yabbc th img {float: left;}
  .ubbcbutton {float: left;}
.yabbc table {width: 75%;} .yabbc table {width: 75%;}
</style>\n~; </style>\n~;
       }        }
   
       $TempParse = $BodyItem;        $TempParse = $BodyItem;
       $TempParse =~ s/<yabb item>/$message/g;         $TempParse =~ s/{yabb item}/$message/gsm; 
       $Body .= qq~$TempParse~;         $TempParse =~ s/{yabb mymoding}/$mymoding/sm; 
       $i++;         $TempParse  =~ s/{top_img}/$top_img/gsm; 
   }         $Body .= qq~$TempParse~; 
   $Body .= qq~$BodyFooter~;         $i++; 
     }
     $Body .= qq~$BodyFooter~;
     return $Body;
} }
   
{ {
   my %hpkillhash = (    my %hpkillhash = (
       ';'  => '&#059;',        q{;}  => '&#059;',
       '!'  => '&#33;',        q{!}  => '&#33;',
       '('  => '&#40;',        q{(}  => '&#40;',
       ')'  => '&#41;',        q{)}  => '&#41;',
       '-'  => '&#45;',        q{-}  => '&#45;',
       '.'  => '&#46;',        q{.}  => '&#46;',
       '/'  => '&#47;',        q{/}  => '&#47;',
       ':'  => '&#58;',        q{:}  => '&#58;',
       '?'  => '&#63;',        q{?}  => '&#63;',
       '['  => '&#91;',        q{[}  => '&#91;',
       '\\' => '&#92;',        q{\\} => '&#92;',
       ']'  => '&#93;',        q{]}  => '&#93;',
       '^'  => '&#94;');         q{^}  => '&#94;', 
     );
   sub codehlp {  
       my $hcode = $_[0];     sub codehlp { 
       if ($hcode !~ /&\S*;/) { $hcode =~ s/;/&#059;/g; }         my ($hcode) = @_; 
       $hcode =~ s~([\(\)\-\:\\\/\?\!\]\[\.\^])~$hpkillhash{$1}~g;         if ( $hcode !~ /&\S*;/xsm ) { $hcode =~ s/;/&\x23059;/gxsm; } 
       $hcode =~ s~(&#91\;.+?&#93\;)~<span style="color: #ff0000;">$1</span>~isg;         $hcode =~ s/([\(\)\-\:\\\/\?\!\]\[\.\^])/$hpkillhash{$1}/gxsm; 
       $hcode =~ s~(&#91\;&#47\;.+?&#93\;)~<span style="color: #ff0000;">$1</span>~isg;         $hcode =~ 
       return $hcode;  s/(&\x2391\;.+?&\x2393\;)/<span class="important">$1<\/span>/isgm; 
   }         $hcode =~ 
  s/(&\x2391\;&\x2347\;.+?&\x2393\;)/<span class="important">$1<\/span>/isgm;
         return $hcode;
     }
} }
   
sub ContentContainer { sub ContentContainer {
   $MainLayout =~ s/<yabb contents>/$Contents/g;     $MainLayout =~ s/{yabb contents}/$Contents/gsm; 
   $MainLayout =~ s/<yabb body>/$Body/g;     $MainLayout =~ s/{yabb body}/$Body/gsm; 
   
   $yymain .= qq~$MainLayout~;    $yymain .= qq~$MainLayout~;
     return $yymain;
} }
   
sub DoContents { sub DoContents {
   $TempParse = $ContentHeader;    $TempParse = $ContentHeader;
   
   $TempParse =~ s/<yabb section_anchor>/$SectionName/g;     $BrdID = $mbname; 
   $SectionNam = $SectionName;     $BrdID =~ s/ /_/gsm; 
   $SectionNam =~ s/_/ /g;     $SectionName =~ s/{yabb myboardname}/$BrdID/gsm; 
   $TempParse  =~ s/<yabb section_name>/$SectionNam/g;     $TempParse =~ s/{yabb section_anchor}/$SectionName/gsm; 
   $Contents .= qq~$TempParse~;     $SectionNam = $SectionName; 
     $SectionNam =~ s/_/ /gsm;
   $Contents .= qq~<ul style="list-style: none; margin: 0; padding: 2px; border: none;">~;     $TempParse  =~ s/{yabb section_name}/$SectionNam/gsm; 
   $i = 1;     $TempParse  =~ s/{top_img}/$top_img/gsm; 
   while (${ SectionSub . $i }) {     $Contents .= qq~$TempParse~; 
   
       if (${ SectionExcl . $i } eq "yabbc" && (!$enable_ubbc || !$showyabbcbutt)) { $i++; next; }     $Contents .= q~<ul class="help_ul">~; 
     $i = 1;
       $SectionAnchor = ${ SectionSub . $i };     while ( ${ SectionSub . $i } ) { 
       ${ SectionSub . $i } =~ s/_/ /g;  
         if ( ${ SectionExcl . $i } eq 'yabbc' 
       $TempParse = $ContentItem;             && ( !$enable_ubbc || !$showyabbcbutt ) ) 
       $TempParse =~ s/<yabb anchor>/$SectionAnchor/g;         { 
       $TempParse =~ s/<yabb content>/${SectionSub.$i}/g;             $i++; 
             next;
       $Contents .= qq~$TempParse~;         } 
       ${ SectionSub . $i } = "";  
       $i++;         $SectionAnchor = ${ SectionSub . $i }; 
   }         ${ SectionSub . $i } =~ s/_/ /gxsm; 
   $Contents .= qq~</ul>~;  
         $TempParse = $ContentItem;
         $TempParse =~ s/{yabb anchor}/$SectionAnchor/gsm;
         $TempParse =~ s/{yabb myboardname}/$BrdID/gsm;
         $TempParse =~ s/{yabb content}/${SectionSub.$i}/gsm;
   
         $Contents .= qq~$TempParse~;
         ${ SectionSub . $i } = q{};
         $i++;
     }
     $Contents .= q~</ul>~;
     return $Contents;
} }
   
sub CreateOrderFile { sub CreateOrderFile {
   opendir(HELPDIR, "$helpfile/$language/$help_area");     if ( opendir HELPDIR, "$helpfile/$language/$help_area" ) { 
   @contents = readdir(HELPDIR);         @contents = readdir HELPDIR; 
   closedir(HELPDIR);         closedir HELPDIR; 
     }
   foreach (sort { uc($a) cmp uc($b) } @contents) {     elsif ( opendir HELPDIR, "$helpfile/English/$help_area" ) { 
       ($name, $extension) = split(/\./, $_);         @contents = readdir HELPDIR; 
       next if $extension !~ /help/i;         closedir HELPDIR; 
       $order_list .= "$name\n";     } 
   }  
     foreach ( sort { uc($a) cmp uc $b } @contents ) {
   fopen(HELPORDER, ">$vardir/$help_area.helporder") || die("couldn't write order file - check permissions on $vardir and $vardir/$help_area.helporder");         ( $name, $extension ) = split /\./xsm, $_; 
   print HELPORDER qq~$order_list~;         next if $extension !~ /help/ism; 
   fclose(HELPORDER);         $order_list .= "$name\n"; 
     }
   
     fopen( HELPORDER, ">$vardir/$help_area.helporder" )
       or croak(
  "couldn't write order file - check permissions on $vardir and $vardir/$help_area.helporder" 
       );
     print {HELPORDER} qq~$order_list~ or croak "$croak{'print'} HELPORDER";
     fclose(HELPORDER);
     return;
} }
   
1; 1;