############################################################################### # Search.pl # ############################################################################### # YaBB: Yet another Bulletin Board # # Open-Source Community Software for Webmasters # # Version: YaBB 1 Gold - SP 1.3 # # Released: December 2001; Updated April 6, 2003 # # Distributed by: http://www.yabbforum.com # # =========================================================================== # # Copyright (c) 2000-2003 YaBB (www.yabbforum.com) - All Rights Reserved. # # Software by: The YaBB Development Team # # with assistance from the YaBB community. # # Sponsored by: Xnull Internet Media, Inc. - http://www.ximinc.com # ############################################################################### $searchplver = "1 Gold - SP 1.3"; sub plushSearch1 { if ($maxsearchdisplay < 0){ &fatal_error($floodtxt{'8'}); } my( @categories, %cat, $curcat, %catname, %cataccess, %catboards, $openmemgr, @membergroups, $tmpa, %openmemgr, $curboard, @threads, @boardinfo, $counter ); @categories = (); fopen(FILE, "$vardir/cat.txt"); @categories = ; fclose(FILE); &LoadCensorList; # Load Censor List $searchpageurl = $curposlinks ? qq~$txt{'182'}~ : $txt{'182'}; $yymain .= qq~
  $mbname
  $searchpageurl
$txt{'183'}
$txt{'582'}:  
$txt{'583'}:  
$txt{'189'}: ~; $counter = 1; foreach $curcat (@categories) { chomp $curcat; fopen(FILE, "$boardsdir/$curcat.cat"); $catname{$curcat} = ; chomp $catname{$curcat}; $cataccess{$curcat} = ; chomp $cataccess{$curcat}; @{$catboards{$curcat}} = ; fclose(FILE); $openmemgr{$curcat} = 0; @membergroups = split( /,/, $cataccess{$curcat} ); foreach $tmpa (@membergroups) { if( $tmpa eq $settings[7]) { $openmemgr{$curcat} = 1; last; } } if( ! $cataccess{$curcat} || $settings[7] eq 'Administrator' ) { $openmemgr{$curcat} = 1; } unless( $openmemgr{$curcat} ) { next; } boardcheck: foreach $curboard (@{$catboards{$curcat}}) { chomp $curboard; #### unless ($settings[7] eq "Administrator") { my $cookiename = "$cookiepassword$curboard"; my $crypass = crypt($boardpw{$curboard},$pwseed); my $access = &AccessCheck($curboard, ''); if (($boardpw{$curboard} && $yyCookies{$cookiename} ne $crypass) || ($access ne "granted")) { next; } } #### fopen(FILE, "$boardsdir/$curboard.dat"); @boardinfo = ; fclose(FILE); chomp @boardinfo; @{$boardinfo{$curboard}} = @boardinfo; $cat{$curboard} = $curcat; $yymain .= qq~~; unless( $counter % 2 ) { $yymain .= qq~~; } ++$counter; } } $yymain .= qq~
$boardinfo[0]

$txt{'737'}
$txt{'573'}:
$txt{'70'} $txt{'72'} ~; if($settings[7] eq 'Administrator'){ $yymain .= qq~$IPsrch{'1'}~; } $yymain .= qq~
$txt{'575'} $txt{'574'}: $txt{'578'} + $txt{'579'}
$txt{'576'} $txt{'574'}: $txt{'578'} + $txt{'579'}
$txt{'191'}
$txt{'191a'}


~; # if ($settings[7] ne "Administrator") { $search_log_display = 0; } if ($search_log_display) { fopen(FILE, "$vardir/search_log.txt"); @searches = ; fclose(FILE); @last_searches = @searches; @top_searches = sort {$b <=> $a} @searches; for( $i = 0; $i < @searches; $i++ ) { chomp $searches[$i]; ($dummy, $last_searches[$i]) = split(/\|/, $last_searches[$i]); ($tmp_number, $top_searches[$i]) = split(/\|/, $top_searches[$i]); foreach (@censored) { ($tmpa,$tmpb) = @{$_}; $last_searches[$i] =~ s~\Q$tmpa\E~$tmpb~gi; $top_searches[$i] =~ s~\Q$tmpa\E~$tmpb~gi; } $top_searches[$i] = qq~$top_searches[$i] ($tmp_number)~; } if ($search_log_display == 2 || $search_log_display == 3) { $yymain .= qq~
$txt{'1872'}
~; for( $i = 1; $i <= 5; $i++ ) { $j = $i + 5; $yymain .= qq~ ~; } $yymain .= qq~
$i. $top_searches[$i-1] $j. $top_searches[$j-1]
~;} if ($search_log_display == 1 || $search_log_display == 3) { $yymain .= qq~
$txt{'1871'}
~; for( $i = 1; $i <= 5; $i++ ) { $j = $i + 5; $yymain .= qq~ ~; } $yymain .= qq~
$i. $last_searches[$i-1] $j. $last_searches[$j-1]
~;} if ($settings[7] eq "Administrator") { $yymain .= qq~
$txt{'137'} - $txt{'1874'}
~; } } $yytitle = $txt{'183'}; &template; exit; } sub plushSearch2 { if ($maxsearchdisplay < 0){ &fatal_error($floodtxt{'8'}); } my $minripe = $FORM{'minripe'} || 0; my $minage = $FORM{'minage'} || 0; my $maxripe = $FORM{'maxripe'} || 0; my $maxage = $FORM{'maxage'} || 7; my $display = $FORM{'numberreturned'} || 25; if( $minripe =~ /\D/ ) { &fatal_error($txt{'337'}); } if( $minage =~ /\D/ ) { &fatal_error($txt{'337'}); } if( $maxripe =~ /\D/ ) { &fatal_error($txt{'337'}); } if( $maxage =~ /\D/ ) { &fatal_error($txt{'337'}); } if( $display =~ /\D/ ) { &fatal_error($txt{'337'}); } if( $display > $maxsearchdisplay) { &fatal_error($floodtxt{'7'}); } my $userkind = $FORM{'userkind'}; my $userspec = $FORM{'userspec'}; if( $userkind eq 'starter' ) { $userkind = 1; } elsif( $userkind eq 'poster' ) { $userkind = 2; } elsif( $userkind eq 'noguests' ) { $userkind = 3; } elsif( $userkind eq 'onlyguests' ) { $userkind = 4; } else { $userkind = 0; $userspec = ''; } if ($userspec =~ m~/~){ &fatal_error($txt{'224'}); } if ($userspec =~ m~\\~){ &fatal_error($txt{'225'}); } $userspec =~ s/\A\s+//; $userspec =~ s/\s+\Z//; $userspec =~ s/[^0-9A-Za-z#%+,-\.@^_]//g; my $searchtype = $FORM{'searchtype'}; my $search = $FORM{'search'}; my $one_per_thread = $FORM{'oneperthread'} || 0; #Search IP # my $search_ip = $FORM{'search'}; #Search IP # if( $searchtype eq 'anywords' ) { $searchtype = 2; } elsif( $searchtype eq 'asphrase' ) { $searchtype = 3; } elsif( $searchtype eq 'aspartial' ) { $searchtype = 4; } else { $searchtype = 1; } if ($search eq "" || $search eq " "){ &fatal_error($txt{'754'}); } if ($search =~ m~/~){ &fatal_error($txt{'397'}); } if ($search =~ m~\\~){ &fatal_error($txt{'397'}); } if ($search =~ /\AIs UBB Good\?\Z/i) { &fatal_error("Many llamas have pondered this question for ages. They each came up with logical answers to this question, each being quite different. The consensus of their answers: UBB is a decent piece of software made by a large company. They, however, lack a strong supporting community, charge a lot for their software and the employees are very biased towards their own products. And so, once again, let it be written into the books that
\"\"
YaBB is the greatest community software there ever was!
"); } my $searchsubject = $FORM{'subfield'} eq 'on'; my $searchmessage = $FORM{'msgfield'} eq 'on'; #search IP# my $searchIP = $FORM{'IPfield'} eq 'on'; #search IP# $search =~ s/\A\s+//; $search =~ s/\s+\Z//; &ToHTML($search); $search =~ s/\t/ \  \  \ /g; $search =~ s/\cM//g; $search =~ s/\n/
/g; if( $searchtype != 3 ) { @search = split( /\s+/, lc $search ); } else { @search = ( lc $search ); } my( $curboard, @threads, $curthread, $tnum, $tsub, $tname, $temail, $tdate, $treplies, $tusername, $ticon, $tstate, $ttime, @messages, $curpost, $mtime, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $mns, $subfound, $msgfound, $numfound, %data, $i, $board, $curcat, @categories, %catname, %cataccess, %openmemgr, @membergroups, %cats, @boardinfo, %boardinfo, @boards, $counter, $msgnum ); my $ipfound; my $tmp_mip; my $curtime = time + (3600*$settings[17]); my $mintime = $curtime - (($minage*86400)+($minripe*3600) - 1); my $maxtime = $curtime - (($maxage*86400)+($maxripe*3600) + 1); my $oldestfound = stringtotime("01/10/37 $txt{'107'} 00:00:00"); if ($search_log_display) { fopen(FILE, "$vardir/search_log.txt"); @searches = ; fclose(FILE); foreach $cursearch (@searches){ chomp $cursearch; ($tmp_number, $tmp_search) = split(/\|/, $cursearch); if (lc $tmp_search eq lc $search) {$number = $tmp_number;} } $number++; fopen(FILE, ">$vardir/search_log.txt"); print FILE "$number|$search\n"; foreach $cursearch (@searches){ chomp $cursearch; ($tmp_number, $tmp_search) = split(/\|/, $cursearch); if (lc $tmp_search ne lc $search) {print FILE "$tmp_number|$tmp_search\n";} } fclose(FILE); } fopen(FILE, "$vardir/cat.txt"); @categories = ; fclose(FILE); foreach $curcat (@categories) { chomp $curcat; fopen(FILE, "$boardsdir/$curcat.cat"); $catname{$curcat} = ; chomp $catname{$curcat}; $cataccess{$curcat} = ; chomp $cataccess{$curcat}; @{$catboards{$curcat}} = ; fclose(FILE); $openmemgr{$curcat} = 0; @membergroups = split( /,/, $cataccess{$curcat} ); foreach $tmpa (@membergroups) { if( $tmpa eq $settings[7]) { $openmemgr{$curcat} = 1; last; } } if( ! $cataccess{$curcat} || $settings[7] eq 'Administrator' ) { $openmemgr{$curcat} = 1; } unless( $openmemgr{$curcat} ) { next; } foreach $curboard (@{$catboards{$curcat}}) { chomp $curboard; fopen(FILE, "$boardsdir/$curboard.dat"); @boardinfo = ; fclose(FILE); chomp @boardinfo; @{$boardinfo{$curboard}} = @boardinfo; $cat{$curboard} = $curcat; } } $counter = 1; while( $_ = each(%FORM) ) { unless( $_ =~ m~\Abrd(\d+)\Z~ ) { next; } $_ = $FORM{$_}; if ($_ =~ m~/~){ &fatal_error($txt{'397'}); } if ($_ =~ m~\\~){ &fatal_error($txt{'397'}); } if( $cat{$_} ) { push( @boards, $_ ); } ++$counter; } boardcheck: foreach $curboard (@boards) { fopen(FILE, "$boardsdir/$curboard.txt") || next; @threads = ; fclose(FILE); #### unless ($settings[7] eq "Administrator") { my $cookiename = "$cookiepassword$curboard"; my $crypass = crypt($boardpw{$curboard},$pwseed); my $access = &AccessCheck($curboard, ''); if (($boardpw{$curboard} && $yyCookies{$cookiename} ne $crypass) || ($access ne "granted")) { next; } } #### #$yymain .= qq~
    Beginning search in board $curboard
      ~; threadcheck: foreach $curthread (@threads) { chomp $curthread; #$yymain .= qq~
    Beginning search in topic $curthread.
      ~; ($tnum, $tsub, $tname, $temail, $tdate, $treplies, $tusername, $ticon, $tstate) = split( /\|/, $curthread ); if( $userkind == 1 ) { if( $tusername eq 'Guest' ) { if( $tname !~ m~\A\Q$userspec\E\Z~i ) { next threadcheck; } } else { if( $tusername !~ m~\A\Q$userspec\E\Z~i ) { next threadcheck; } } } $ttime = stringtotime($tdate); unless( $ttime < $mintime ) { next threadcheck; } unless( $ttime > $maxtime ) { next threadcheck; } fopen(FILE, "$datadir/$tnum.txt") || next; @messages = ; fclose(FILE); postcheck: for( $msgnum = @messages; $msgnum >= 0; $msgnum-- ) { $curpost = $messages[$msgnum]; chomp $curpost; #$yymain .= qq~Beginning search in post $curpost.
      ~; ($msub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $message, $mns) = split(/\|/,$curpost); $mtime = stringtotime($mdate); unless( $mtime < $mintime ) { next postcheck; } if( $numfound >= $display && $mtime <= $oldestfound ) { next postcheck; } if( $musername eq 'Guest' ) { if( $userkind == 3 || ( $userkind == 2 && $mname !~ m~\A\Q$userspec\E\Z~i ) ) { next postcheck; } } else { if( $userkind == 4 || ( $userkind == 2 && $musername !~ m~\A\Q$userspec\E\Z~i ) ) { next postcheck; } } #$yymain .= qq~
        Performing search in post $curpost.
      ~; if( $searchsubject ) { if( $searchtype == 2 || $searchtype == 4 ) { $subfound = 0; foreach( @search ) { if( $searchtype == 4 && $msub =~ m~\Q$_\E~i ) { $subfound = 1; last; } elsif( $msub =~ m~(^|\W|_)\Q$_\E(?=$|\W|_)~i ) { $subfound = 1; last; } } } else { $subfound = 1; foreach( @search ) { if( $msub !~ m~(^|\W|_)\Q$_\E(?=$|\W|_)~i ) { $subfound = 0; last; } } } } if( $searchmessage && ! $subfound ) { if( $searchtype == 2 || $searchtype == 4 ) { $msgfound = 0; foreach( @search ) { if( $searchtype == 4 && $message =~ m~\Q$_\E~i ) { $msgfound = 1; last; } elsif( $message =~ m~(^|\W|_)\Q$_\E(?=$|\W|_)~i ) { $msgfound = 1; last; } } } else { $msgfound = 1; foreach( @search ) { if( $message !~ m~(^|\W|_)\Q$_\E(?=$|\W|_)~i ) { $msgfound = 0; last; } } } } unless( $msgfound || $subfound ) { next postcheck; } $data{$mtime} = [$curboard, $tnum, $msgnum, $tusername, $tname, $msub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $message, $mns, $tstate]; if( $mtime < $oldestfound ) { $oldestfound = $mtime; } ++$numfound; if( $one_per_thread ) { last postcheck; } } } } @messages = sort {$b <=> $a } keys %data; if( @messages ) { if( @messages > $display ) { $#messages = $display - 1; } $counter = 1; &LoadCensorList; # Load Censor List } else { $yymain .= qq~
      $txt{'170'}
      ~; } foreach (@censored) { ($tmpa,$tmpb) = @{$_}; $search =~ s~\Q$tmpa\E~$tmpb~gi; } # Search for censored or uncencored search string and remove duplicate words my @tmpsearch; if( $searchtype == 3 ) {@tmpsearch = ( lc $search );} else {@tmpsearch = split( /\s+/, lc $search );} push @tmpsearch, @search; undef %found; @search = grep(!$found{$_}++, @tmpsearch); # $searchstring = join('", "', @search); # $yymain .= qq~Search for: "$searchstring"

      ~; for( $i = 0; $i < @messages; $i++ ) { ($board, $tnum, $msgnum, $tusername, $tname, $msub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $message, $mns, $tstate) = @{ $data{$messages[$i]} }; $mdate = &timeformat($mdate); $displayname = $mname; if( $tusername ne 'Guest' ) { if( &LoadUser($tusername) ) { $tname = "$userprofile{$tusername}->[1]"; } } if( $musername ne 'Guest' ) { if( &LoadUser($musername) ) { $mname = "$userprofile{$musername}->[1]"; } } foreach (@censored) { ($tmpa,$tmpb) = @{$_}; $message =~ s~\Q$tmpa\E~$tmpb~gi; $msub =~ s~\Q$tmpa\E~$tmpb~gi; } # Highlight search strings in Subject heading foreach $tmp ( @search ) { if( $searchtype == 4 ) {$msub =~ s~(\Q$tmp\E)~$1~ig;} else {$msub =~ s~(^|\W|_)(\Q$tmp\E)(?=$|\W|_)~$1$2$3~ig;} } #### Remove excessive line returns mod while ($message =~ m~
      [(/ /;)\s]*
      [(/ /;)\s]*
      ~i) { $message =~ s~
      [(/ /;)\s]*
      [(/ /;)\s]*
      ~

      ~ig; } #### &wrap; # Highlight search strings in Message if( $autolinkurls ) { $message =~ s~([^\w\"\=\[\]]|[\n\b]|\A)\\*(\w+://[\w\~\.\;\:\,\$\-\+\!\*\?/\=\&\@\#\%]+\.[\w\~\;\:\$\-\+\!\*\?/\=\&\@\#\%]+[\w\~\;\:\$\-\+\!\*\?/\=\&\@\#\%])~$1\[url=$2\]$2\[\/url\]~isg; $message =~ s~([^\"\=\[\]/\:\.(\://\w+)]|[\n\b]|\A)\\*(www\.[^\.][\w\~\.\;\:\,\$\-\+\!\*\?/\=\&\@\#\%]+\.[\w\~\;\:\$\-\+\!\*\?/\=\&\@\#\%]+[\w\~\;\:\$\-\+\!\*\?/\=\&\@\#\%])~$1\[url=$2\]$2\[\/url\]~isg; } $message =~ s~\[(url|link|email)\](.*?)\[/\1\]~\[$1=$2\]$2\[/$1\]~ig; $message =~ s~\[(news|gopher|ftp|flash|img)(.*?)\](.*?)\[/\1\]~\[$1$2 tmp=$3\](.*?)\[/$1\]~ig; foreach $tmp ( @search ) { if($searchtype == 4) { $message =~ s~(\Q$tmp\E)~\[highlight\]$1\[/highlight\]~ig; } else { $message =~ s~(^|\W|_)(\Q$tmp\E)(?=$|\W|_)~$1\[highlight\]$2\[/highlight\]$3~ig; } } $tmp=1; while($tmp) { $message =~ s~\[([^\]]*?)\[/?highlight(.*?)\]~\[$1~ig; if ($message !~ m~\[([^\]]*?)\[/?highlight(.*?)\]~i) { $tmp=0; } } $message =~ s~\[(news|gopher|ftp|flash|img)(.*?) tmp=(.*?)\](.*?)\[/\1\]~\[$1$2\]$3\[/$1\]~ig; if($enable_ubbc) { $ns = $mns; if(!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; } &DoUBBC; } &wrap2; #Search IP # $mip = $settings[7] eq 'Administrator' ? $mip : "$txt{'511'}"; #Search IP # if($enable_notification) { $notify = qq~$menusep$img{'notify'}~; } $yymain .= qq~
       $counter   $catname{$cat{$board}} / $boardinfo{$board}->[0] / $msub  $mdate 
      $txt{'109'} $tname | $txt{'105'} $txt{'525'} $mname
      $message
      $mip
        ~; if ($tstate != 1) { $yymain .= qq~$img{'reply'}$menusep$img{'replyquote'}$notify~; } $yymain .= qq~

      ~; ++$counter; } $yymain .= qq~ $txt{'167'}
      $txt{'236'} $txt{'237'}
      ~; $yytitle = $txt{'166'}; &template; exit; } sub clean_search_log { &is_admin; unlink("$vardir/search_log.txt"); &plushSearch1; } 1;