############################################################################### # Favor.pl # ############################################################################### # YaBB: Yet another Bulletin Board # # Open-Source Community Software for Webmasters # # Version: YaBB 1 Gold - SP 1.2 # # Released: December 2001; Updated January 27, 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 # ############################################################################### $favorplver = "1 Gold - SP 1.2"; sub Favor { if( $currentboard eq '' ) { &fatal_error($txt{'1'}); } if($username eq "Guest") { &fatal_error("$txt{'138'}"); } # Check, if User already has this as a Favorite fopen(FILE, "$datadir/$INFO{'thread'}.fav"); @names = ; fclose(FILE); $isonlist = 0; foreach $curname (@names) { $curname =~ s/[\n\r]//g; if($username eq "$curname") { $isonlist = 1; } } if ($isonlist){ $yymain .= qq~
$fav{'9'}
$fav{'2'}
$txt{'163'} - $txt{'164'}
~; } else { $yymain .= qq~
$fav{'9'}
$fav{'3'}
$txt{'163'} - $txt{'164'}
~; } $yytitle = "$fav{'1'}"; &template; exit; } sub Favor2 { if( $currentboard eq '' ) { &fatal_error($txt{'1'}); } if($username eq 'Guest') { &fatal_error($txt{'138'}); } $board = $INFO{'board'}; $thread = $INFO{'thread'}; $start = $INFO{'start'} ne '' ? $INFO{'start'} : 9999999; fopen(FILE, "$datadir/$thread.fav"); @names = ; fclose(FILE); # if there is only one entry and this is the address which is to remove, remove the file at all fopen(FILE, ">$datadir/$thread.fav", 1) || &fatal_error("$txt{'23'} $thread.fav"); print FILE "$board\n"; print FILE "$username\n"; foreach $curname (@names) { $curname =~ s/[\n\r]//g; if(($username ne "$curname") && ($board ne "$curname")) { print FILE "$curname\n"; } } fclose(FILE); $yySetLocation = qq~$cgi;action=display;num=$thread;start=$start~; &redirectexit; } sub Favor3 { if( $currentboard eq '' ) { &fatal_error($txt{'1'}); } if($username eq "Guest") { &fatal_error("$txt{'138'}"); } $thread = $INFO{'thread'}; $start = $INFO{'start'} ne '' ? $INFO{'start'} : 9999999; fopen(FILE, "$datadir/$thread.fav"); @names = ; fclose(FILE); # if there is only one entry and this is the address which is to remove, remove the file at all # if( $#names eq 0) { if( @names == 2) { unlink("$datadir/$thread.fav"); } else # make no change with the file { fopen(FILE, ">$datadir/$thread.fav", 1) || &fatal_error("$txt{'23'} $thread.fav"); foreach $curname (@names) { $curname =~ s/[\n\r]//g; if($username ne $curname) { print FILE "$curname\n"; } } fclose(FILE); } $yySetLocation = qq~$cgi;action=display;num=$thread;start=$start~; &redirectexit; } sub Favor4 { if($username eq "Guest") { &fatal_error("$txt{'138'}"); } my( $variable, $dummy, $dummy2, $threadno, @names, $curname ); foreach $variable (keys %FORM) { $dummy = $FORM{$variable}; ($dummy2,$threadno) = split(/-/,$variable); if ($dummy2 eq "thread") { fopen(FILE, "$datadir/$threadno.fav"); @names = ; $boardname = $names[0]; chomp $boardname; fclose(FILE); # if there is only one entry and this is the address which is to remove, remove the file at all # if( $#names eq 0) { if( @names <= 2) { unlink("$datadir/$threadno.fav"); } else # make no change with the file { fopen(FILE, ">$datadir/$threadno.fav") || &fatal_error("$txt{'23'} $threadno.fav"); print FILE "$boardname\n"; foreach $curname (@names) { $curname =~ s/[\n\r]//g; if(($username ne $curname) && ($boardname ne $curname)) { print FILE "$curname\n"; } } fclose(FILE); } } } &ShowFavors; } sub ShowFavors { if($username eq "Guest") { &fatal_error("$txt{'138'}"); } my(@dirdata,@datdata,@threadlist,$filename,$entry,@entries,$boardname,$mnum2,$mnum,$dummy,$msub,$mname,$memail,$mdate,$musername,$micon,$mattach,$mip,$mmessage,@messages,@found_number,@found_subject,@found_date,@found_mreplies,@found_views,@found_new,@found_micon,@found_lpost,@found_board,@found_name); # Read all .fav-Files and search for username opendir (DIRECTORY,"$datadir"); @dirdata = readdir(DIRECTORY); closedir (DIRECTORY); @datdata = grep(/fav/,@dirdata); # Load Censor List &LoadCensorList; foreach $filename (@datdata) { fopen(FILE, "$datadir/$filename"); @entries = ; fclose(FILE); $boardname = $entries[0]; chomp $boardname; foreach $entry (@entries) { $entry =~ s/[\n\r]//g; if ($entry eq $username) { ($mnum, $dummy) = split(/\./,$filename); fopen(FILE, "$boardsdir/$boardname.txt") || &fatal_error("300 $txt{'106'}: $txt{'23'} $currentboard.txt"); @threadlist = ; # $threadcount = $#threadlist; fclose(FILE); foreach( @threadlist ) { my ($threaddate,$dlp,$new); ($mnum2, $msub, $mname, $memail, $mdate, $mreplies, $musername, $micon, $mstate) = split( /\|/, $_ ); if($mnum2 == $mnum) { # Set thread class depending on locked status and number of replies. # $threadclass = 'thread'; # if( $mstate == 1 ) { $threadclass = 'locked'; } # elsif( $mreplies > 24 ) { $threadclass = 'veryhotthread'; } # elsif( $mreplies > 14 ) { $threadclass = 'hotthread'; } # elsif( $mstate == 0 ) { $threadclass = 'thread'; } # Decide if thread should have the "NEW" indicator next to it. # Do this by reading the user's log for last read time on thread, # and compare to the last post time on the thread. $dlp = &getlog($mnum2); $threaddate = stringtotime($mdate); if( $max_log_days_old && $dlp < $threaddate && $username ne 'Guest' && &getlog("$boardname--mark") < $threaddate ) { $new = qq~$txt{'302'}~; } else { $new = ''; } # Load the current nickname of the account name of the thread starter. if( $musername ne 'Guest' && -e "$memberdir/$musername.dat" ) { &LoadUser($musername); $mname = $userprofile{$musername}->[1] || $mname || $txt{'470'}; $mname = qq~$mname~; } else { $mname ||= $txt{'470'}; } #italicize the subject if notification is on for this user if(-e "$datadir/$mnum2.mail") { fopen(FILE, "$datadir/$mnum2.mail"); @starter = ; fclose(FILE); foreach $alx (@starter) { $alx =~ s/[\n\r]//g; if($settings[2] eq "$alx") {$msub = qq~$msub~;} } } # Censor the subject of the thread. foreach (@censored) { ($tmpa,$tmpb) = @{$_}; $msub =~ s~\Q$tmpa\E~$tmpb~gi; } # Decide how many pages the thread should have. $threadlength = $mreplies + 1; $pages = ''; if( $threadlength > $maxmessagedisplay ) { $tmpa = 1; for( $tmpb = 0; $tmpb < $threadlength; $tmpb += $maxmessagedisplay ) { $pages .= qq~$tmpa\n~; ++$tmpa; } $pages =~ s/\n\Z//; $pages = qq~
« $txt{'139'} $pages »~; } if( fopen(FILE, "$datadir/$mnum2.data") ) { $tmpa = ; fclose(FILE); } elsif( -e "$datadir/$mnum2.data" ) { &fatal_error("301 $txt{'106'}: $txt{'23'} $mnum2.data"); } else { $tmpa = '0'; } ($views, $lastposter) = split(/\|/, $tmpa); if( $lastposter =~ m~\AGuest-(.*)~ ) { $lastposter = $1; } else { unless( $lastposter eq $txt{'470'} ) { $lastposterid = $lastposter; &LoadUser($lastposterid); if($userprofile{$lastposter}->[1]) { $lastposter = qq~$userprofile{$lastposter}->[1]~; } } &LoadUser($lastposter); } $lastpostername = $lastposter || $txt{'470'}; $views = $views ? $views - 1 : 0; $mydate = &timeformat($mdate); push(@found_lpost,$lastpostername); push(@found_board,$boardname); push(@found_number,$mnum2); push(@found_subject,$msub); push(@found_date,$mydate); push(@found_pages,$pages); push(@found_name,$mname); push(@found_mreplies,$mreplies); push(@found_views,$views); push(@found_new,$new); push(@found_micon,$micon); } } } } } # Display all Entries $yymain .= qq~
 $fav{'1'}

$fav{'5'}
~; if (@found_number==0) { $yymain .= "$fav{'4'}

 "; } else { foreach (@censored) { ($tmpa,$tmpb) = @{$_}; $found_subject[$counter] =~ s~\Q$tmpa\E~$tmpb~gi; } $yymain .= qq~
~; $counter=0; foreach $entry (@found_number) { $yymain .= qq~ ~; $counter++; } $yymain .= qq~
  $txt{'70'} $txt{'109'} $txt{'110'} $txt{'301'} $txt{'111'}
$found_new[$counter]$found_subject[$counter] $found_pages[$counter] $found_name[$counter] $found_mreplies[$counter]  $found_views[$counter]  $found_date[$counter]
$txt{'525'} $found_lpost[$counter]
~; $yymain .= qq~~; $yymain .= qq~~; $yymain .= qq~

$fav{'6'}
 
~; $yymain .= qq~   
~; } $yymain .= qq~
~; $yytitle = "$fav{'7'}"; &template; exit; } sub remove_favorites { my (@deaduser, @favdir, $filename, $content, $content_old) = (@_); opendir (DIRECTORY,"$datadir"); @favdir = grep {/\.fav$/} readdir(DIRECTORY); closedir (DIRECTORY); foreach $filename (@favdir) { $content = ''; fopen(MYFILE, "+<$datadir/$filename") || &fatal_error("$txt{'23'} $filename"); while () { $content .= $_; } $content_old = $content; foreach (@deaduser) { $content =~ s/$_(?:\r\n|\r|\n)//ig; } if (length($content) > 1) { if ($content ne $content_old) { truncate(MYFILE,0); seek(MYFILE,0,0); print MYFILE $content; fclose(MYFILE); $done .= "$filename\n"; } else { fclose(MYFILE); } } else { fclose(MYFILE); unlink("$datadir/$filename"); } } } 1;