############################################################################### # Favorites.pl # ############################################################################### # YaBB: Yet another Bulletin Board # # Open-Source Community Software for Webmasters # # Version: YaBB 3.0 Beta # # Packaged: October 05, 2010 # # Distributed by: http://www.yabbforum.com # # =========================================================================== # # Copyright (c) 2000-2010 YaBB (www.yabbforum.com) - All Rights Reserved. # # Software by: The YaBB Development Team # # with assistance from the YaBB community. # ############################################################################### $favoritesplver = 'YaBB 3.0 Beta $Revision: 328 $'; if ($action eq 'detailedversion') { return 1; } sub Favorites { &LoadLanguage('MessageIndex'); require "$templatesdir/$usemessage/MessageIndex.template"; my $start = int($INFO{'start'}) || 0; my (@threads, $counter, $pages, $mnum, $msub, $mname, $memail, $mdate, $mreplies, $musername, $micon, $mstate, $dlp); my $treplies = 0; # grab all relevant info on the favorite thread for this user and check access to them if (!$maxfavs) { $maxfavs = 10; } my @favboards; eval { require "$datadir/movedthreads.cgi" }; foreach my $myfav (split(/,/, ${$uid.$username}{'favorites'})) { # see if thread exists and search for it if moved if (exists $moved_file{$myfav}) { my @moved = ($myfav); while (exists $moved_file{$myfav}) { $myfav = $moved_file{$myfav}; unshift(@moved, $myfav); } foreach (@moved) { $myfav = $_; if ($myfav ne $moved[$#moved]) { if (&checkfor_DBorFILE("$datadir/$myfav.ctb")) { &RemFav($moved[$#moved], "nonexist"); &AddFav($myfav,0,1); last; } } elsif (!&checkfor_DBorFILE("$datadir/$myfav.ctb")) { &RemFav($myfav, "nonexist"); $myfav = 0; } } next if !$myfav; } elsif (!&checkfor_DBorFILE("$datadir/$myfav.ctb")) { &RemFav($myfav, "nonexist"); next; } &MessageTotals("load", $myfav); $favoboard = ${$myfav}{'board'}; push(@favboards, "$favoboard|$myfav"); } foreach (sort(@favboards)) { ($loadboard, $loadfav) = split(/\|/, $_); &BoardTotals("load", $loadboard) if !${$uid.$loadboard}{'board'}; next if !$iamadmin && &AccessCheck($loadboard, '', (split(/\|/, $board{$loadboard}))[1]) ne "granted"; next if !$iamadmin && !&CatAccess((split(/\|/, $catinfo{"${$uid.$loadboard}{'cat'}"}))[1]); foreach (&read_DBorFILE(0,'',$boardsdir,$loadboard,'txt')) { if ((split(/\|/, $_, 2))[0] eq $loadfav) { push(@threads, $_); } } } my $curfav = &NumberFormat(scalar @threads); &LoadCensorList; my %attachments; if (-s "$vardir/attachments.txt" > 5) { foreach (&read_DBorFILE(0,'',$vardir,'attachments','txt')) { $attachments{(split(/\|/, $_, 2))[0]}++; } } # Print the header and board info. my $colspan = 7; # Begin printing the message index for current board. $counter = $start; &getlog; my $dmax = $date - ($max_log_days_old * 86400); foreach (@threads) { ($mnum, $msub, $mname, $memail, $mdate, $mreplies, $musername, $micon, $mstate) = split(/\|/, $_); # Set thread class depending on locked status and number of replies. if ($mnum == '') { next; } #if ($mstate =~ /h/i && !$staff) { next; } &MessageTotals('load', $mnum); $permlinkboard = ${$mnum}{'board'} eq $annboard ? $annboard : $currentboard; my $permdate = &permtimer($_); my $message_permalink = qq~$messageindex_txt{'10'}~; $threadclass = 'thread'; if ($mstate =~ /h/i) { $threadclass = 'hide'; } elsif ($mstate =~ /l/i) { $threadclass = 'locked'; } elsif ($mreplies >= $VeryHotTopic) { $threadclass = 'veryhotthread'; } elsif ($mreplies >= $HotTopic) { $threadclass = 'hotthread'; } elsif ($mstate == '') { $threadclass = 'thread'; } if ($threadclass eq 'hide' && $mstate =~ /s/i && $mstate !~ /l/i) { $threadclass = 'hidesticky'; } elsif ($threadclass eq 'hide' && $mstate =~ /l/i && $mstate !~ /s/i) { $threadclass = 'hidelock'; } elsif ($threadclass eq 'hide' && $mstate =~ /s/i && $mstate =~ /l/i) { $threadclass = 'hidestickylock'; } elsif ($threadclass eq 'locked' && $mstate =~ /s/i && $mstate !~ /h/i) { $threadclass = 'stickylock'; } elsif ($mstate =~ /s/i && $mstate !~ /h/i) { $threadclass = 'sticky'; } elsif (${$mnum}{'board'} eq $annboard && $mstate !~ /h/i) { $threadclass = $threadclass eq 'locked' ? 'announcementlock' : 'announcement'; } my $movedFlag; (undef, $movedFlag) = &Split_Splice_Move($msub,$mnum); if (!$iamguest && $max_log_days_old) { # 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 = int($yyuserlog{$mnum}) > int($yyuserlog{"$currentboard--mark"}) ? int($yyuserlog{$mnum}) : int($yyuserlog{"$currentboard--mark"}); if ($yyuserlog{"$mnum--unread"} || (!$dlp && $mdate > $dmax) || ($dlp > $dmax && $dlp < $mdate)) { if (${$mnum}{'board'} eq $annboard) { $new = qq~$messageindex_txt{'302'}~; } else { $new = qq~$messageindex_txt{'302'}~; } } else { $new = ''; } } $new = '' if $movedFlag; $micon = qq~~; $mpoll = ""; if (&checkfor_DBorFILE("$datadir/$mnum.poll")) { $mpoll = qq~$messageindex_txt{'15'}: ~; my @poll = &read_DBorFILE(0,'',$datadir,$mnum,'poll'); my ($poll_question, $poll_locked, $poll_uname, $poll_name, $poll_email, $poll_date, $guest_vote, $hide_results, $multi_vote, $poll_mod, $poll_modname, $poll_comment, $vote_limit, $pie_radius, $pie_legends, $poll_end) = split(/\|/, $poll[0]); chomp $poll_end; if ($poll_end && !$poll_locked && $poll_end < $date) { $poll_locked = 1; $poll_end = ''; $poll[0] = "$poll_question|$poll_locked|$poll_uname|$poll_name|$poll_email|$poll_date|$guest_vote|$hide_results|$multi_vote|$poll_mod|$poll_modname|$poll_comment|$vote_limit|$pie_radius|$pie_legends|$poll_end\n"; &write_DBorFILE(1,'',$datadir,$mnum,'poll',@poll); } $micon = qq~$img{'pollicon'}~; if ($poll_locked) { $micon = $img{'polliconclosed'}; } elsif ($max_log_days_old && $mdate > $dmax) { if ($dlp < $createpoll_date) { $micon = qq~$img{'polliconnew'}~; } else { my $polled = &read_DBorFILE(0,'',$datadir,$mnum,'polled'); if ($dlp < (split(/\|/, $polled))[3]) { $micon = qq~$img{'polliconnew'}~; } } } } # Load the current nickname of the account name of the thread starter. if ($musername ne 'Guest') { &LoadUser($musername); if (${$uid.$musername}{'realname'}) { $mname = qq~$ {$uid.$musername}{'realname'}~; } else { $mname .= qq~ ($messageindex_txt{'470a'})~; } } ($msub, undef) = &Split_Splice_Move($msub,0); # Censor the subject of the thread. $msub = &Censor($msub); &ToChars($msub); # Build the page links list. $pages = ''; $pagesall; if ($showpageall) { $pagesall = qq~$pidtxt{'01'}~; } if (int(($mreplies + 1) / $maxmessagedisplay) > 6) { $pages = qq~ 1~; $pages .= qq~ 2~; $endpage = int($mreplies / $maxmessagedisplay) + 1; $i = ($endpage - 1) * $maxmessagedisplay; $j = $i - $maxmessagedisplay; $k = $endpage - 1; $tmpa = $endpage - 2; $tmpb = $j - $maxmessagedisplay; $pages .= qq~ ...~; $pages .= qq~ $tmpa~; $pages .= qq~ $k~; $pages .= qq~ $endpage~; $pages = qq~
« $messageindex_txt{'139'} $pages $pagesall »~; } elsif ($mreplies + 1 > $maxmessagedisplay) { $tmpa = 1; for ($tmpb = 0; $tmpb < $mreplies + 1; $tmpb += $maxmessagedisplay) { $pages .= qq~$tmpa\n~; ++$tmpa; } $pages =~ s/\n\Z//; $pages = qq~
« $messageindex_txt{'139'} $pages »~; } $views = ${$mnum}{'views'}; $lastposter = ${$mnum}{'lastposter'}; if ($lastposter =~ m~\AGuest-(.*)~) { $lastposter = $1; } elsif ($lastposter !~ m~Guest~ && !&checkfor_DBorFILE("$memberdir/$lastposter.vars")) { $lastposter = $messageindex_txt{'470a'}; } else { unless (($lastposter eq $messageindex_txt{'470'} || $lastposter eq $messageindex_txt{'470a'}) && &checkfor_DBorFILE("$memberdir/$lastposter.vars")) { &LoadUser($lastposter); if (${$uid.$lastposter}{'realname'}) { $lastposter = qq~${$uid.$lastposter}{'realname'}~; } } } $lastpostername = $lastposter || $messageindex_txt{'470'}; $views = $views ? $views - 1 : 0; # Check if the thread contains attachments and create a paper-clip icon if it does $temp_attachment = $attachments{$mnum} ? qq~$messageindex_txt{'3'} $attachments{$mnum} ~ . ($attachments{$mnum} == 1 ? $messageindex_txt{'5'} : $messageindex_txt{'4'}) . qq~~ : ""; $mydate = &timeformat($mdate); my $threadpic = qq~~; my $msublink = qq~$msub~; if (!$movedFlag && ${$mnum}{'board'} eq $annboard) { $msublink = qq~$msub~; } my $lastpostlink = qq~$img{'lastpost'}$mydate~; my $fmreplies = &NumberFormat($mreplies); $views = &NumberFormat($views); my $tempbar = $threadbar; if ($movedFlag) { $tempbar = $threadbarMoved; } $adminbar = qq~~; $admincol = $admincolumn; $admincol =~ s/({|<)yabb admin(}|>)/$adminbar/g; $tempbar =~ s/({|<)yabb admin column(}|>)/$admincol/g; $tempbar =~ s/({|<)yabb threadpic(}|>)/$threadpic/g; $tempbar =~ s/({|<)yabb icon(}|>)/$micon/g; $tempbar =~ s/({|<)yabb new(}|>)/$new/g; $tempbar =~ s/({|<)yabb poll(}|>)/$mpoll/g; $tempbar =~ s/({|<)yabb favorite(}|>)/$favicon{$mnum}/g; $tempbar =~ s/({|<)yabb subjectlink(}|>)/$msublink/g; $tempbar =~ s/({|<)yabb attachmenticon(}|>)/$temp_attachment/g; $tempbar =~ s/({|<)yabb pages(}|>)/$pages/g; $tempbar =~ s/({|<)yabb starter(}|>)/$mname/g; $tempbar =~ s/({|<)yabb replies(}|>)/$fmreplies/g; $tempbar =~ s/({|<)yabb views(}|>)/$views/g; $tempbar =~ s/({|<)yabb lastpostlink(}|>)/$lastpostlink/g; $tempbar =~ s/({|<)yabb lastposter(}|>)/$lastpostername/g; if ($accept_permalink == 1) { $tempbar =~ s/({|<)yabb permalink(}|>)/$message_permalink/g; } else { $tempbar =~ s/({|<)yabb permalink(}|>)//g; } $tmptempbar .= $tempbar; $counter++; $mcount++; $treplies += $mreplies + 1; } # Put a "no messages" message if no threads exisit: if (!$tmptempbar) { $tmptempbar = qq~
$messageindex_txt{'840'}

~; } $yabbicons = qq~ $messageindex_txt{'457'} $messageindex_txt{'457'}
$messageindex_txt{'779'} $messageindex_txt{'779'}
$messageindex_txt{'456'} $messageindex_txt{'456'}
$messageindex_txt{'780'} $messageindex_txt{'780'}
~; if ($staff) { $yabbadminicons = qq~$messageindex_txt{'458'} $messageindex_txt{'458'}
~; $yabbadminicons .= qq~$messageindex_txt{'459'} $messageindex_txt{'459'}
~; $yabbadminicons .= qq~$messageindex_txt{'460'} $messageindex_txt{'460'}
~; $yabbadminicons .= qq~$messageindex_txt{'461'} $messageindex_txt{'461'}
~; } $yabbadminicons .= qq~ $messageindex_txt{'779a'} $messageindex_txt{'779a'}
$messageindex_txt{'779b'} $messageindex_txt{'779b'}
$messageindex_txt{'454'} $HotTopic $messageindex_txt{'454a'} $messageindex_txt{'454'} $HotTopic $messageindex_txt{'454a'}
$messageindex_txt{'455'} $VeryHotTopic $messageindex_txt{'454a'} $messageindex_txt{'455'} $VeryHotTopic $messageindex_txt{'454a'}
~; $formstart = qq~
~; $formend = qq~
~; &LoadAccess; $adminselector = qq~ ~; $admincheckboxes = qq~ ~; $subfooterbar =~ s/({|<)yabb admin selector(}|>)/$adminselector/g; $subfooterbar =~ s/({|<)yabb admin checkboxes(}|>)/$admincheckboxes/g; # Template it $adminheader =~ s/({|<)yabb admin(}|>)/$messageindex_txt{'2'}/g; $messageindex_template =~ s/({|<)yabb home(}|>)//g; $messageindex_template =~ s/({|<)yabb category(}|>)//g; $yynavigation = qq~› $img_txt{'mycenter'} › $img_txt{'70'}~; $favboard = qq~$img_txt{'70'}~; $messageindex_template =~ s/({|<)yabb board(}|>)/$favboard/g; $messageindex_template =~ s/({|<)yabb moderators(}|>)//g; $bdescrip = qq~$messageindex_txt{'75'}
$messageindex_txt{'76'} $curfav $messageindex_txt{'77'} $maxfavs $messageindex_txt{'78'}~; $treplies = &NumberFormat($treplies); &ToChars($bdescrip); $boarddescription =~ s/({|<)yabb boarddescription(}|>)/$bdescrip/g; $messageindex_template =~ s/({|<)yabb description(}|>)/$boarddescription/g; $bdpic = qq~ $img_txt{'70'} ~; $messageindex_template =~ s/({|<)yabb bdpicture(}|>)/$bdpic/g; $messageindex_template =~ s/({|<)yabb threadcount(}|>)/$curfav/g; $messageindex_template =~ s/({|<)yabb messagecount(}|>)/$treplies/g; $messageindex_template =~ s/({|<)yabb colspan(}|>)/$colspan/g; $messageindex_template =~ s/({|<)yabb notify button(}|>)//g; $messageindex_template =~ s/({|<)yabb markall button(}|>)//g; $messageindex_template =~ s/({|<)yabb new post button(}|>)//g; $messageindex_template =~ s/({|<)yabb new poll button(}|>)//g; $messageindex_template =~ s/({|<)yabb pageindex top(}|>)//g; $messageindex_template =~ s/({|<)yabb pageindex bottom(}|>)//g; $messageindex_template =~ s/({|<)yabb topichandellist(}|>)//g; $messageindex_template =~ s/({|<)yabb pageindex toggle(}|>)//g; $messageindex_template =~ s/({|<)yabb admin column(}|>)/$adminheader/g; $messageindex_template =~ s/({|<)yabb modupdate(}|>)/$formstart/g; $messageindex_template =~ s/({|<)yabb modupdateend(}|>)/$formend/g; $messageindex_template =~ s/({|<)yabb stickyblock(}|>)//g; $messageindex_template =~ s/({|<)yabb threadblock(}|>)/$tmptempbar/g; $messageindex_template =~ s/({|<)yabb adminfooter(}|>)/$subfooterbar/g; $messageindex_template =~ s/({|<)yabb icons(}|>)/$yabbicons/g; $messageindex_template =~ s/({|<)yabb admin icons(}|>)/$yabbadminicons/g; $messageindex_template =~ s/({|<)yabb rss(}|>)//g; $messageindex_template =~ s/({|<)yabb rssfeed(}|>)//g; $showFavorites .= qq~$messageindex_template~; $showFavorites .= qq~ ~; $yytitle = $img_txt{'70'}; } sub AddFav { my $favo = $INFO{'fav'} || $_[0]; my $goto = $INFO{'start'} || $_[1] || 0; my $return = $_[2]; &fatal_error("error_occurred",'',1) if $favo =~ /\D/; my @oldfav = split(/,/, ${$uid.$username}{'favorites'}); if (@oldfav < ($maxfavs || 10)) { push(@oldfav, $favo); ${$uid.$username}{'favorites'} = join(",", &undupe(@oldfav)); &UserAccount($username, "update"); } if (!$return) { if ($INFO{'oldaddfav'}) { $yySetLocation = qq~$scripturl?num=$favo/$goto~; &redirectexit; } $elenable = 0; die ""; # This is here only to avoid server error log entries! } } sub MultiRemFav { while ($maxfavs >= $count) { &RemFav($FORM{"admin$count"}); $count++; } $yySetLocation = qq~$scripturl?action=favorites~; &redirectexit; } sub RemFav { my $favo = $INFO{'fav'} || $_[0]; my $goto = $INFO{'start'} || $_[1]; if (!$goto) { $goto = 0; } my @newfav; foreach (split(/,/, ${$uid.$username}{'favorites'})) { push(@newfav, $_) if $favo ne $_; } ${$uid.$username}{'favorites'} = join(",", &undupe(@newfav)); &UserAccount($username, "update"); return if $_[1] eq "nonexist"; if ($INFO{'ref'} ne "delete" && $action ne "multiremfav" && $INFO{'oldaddfav'}) { $yySetLocation = qq~$scripturl?num=$favo/$goto~; &redirectexit; } if ($action eq 'remfav') { $elenable = 0; die ""; # This is here only to avoid server error log entries! } } sub IsFav { my $favo = $_[0]; my $goto = $_[1] || 0; my $postcheck = $_[2]; my $addfav = $img{'addfav'}; my $remfav = $img{'remfav'}; if($threadtools) { $addfav =~ s~\[tool=(.+?)\](.+?)\[/tool\]~$2~g; $remfav =~ s~\[tool=(.+?)\](.+?)\[/tool\]~$2~g; } $yyjavascript .= qq~\n var addlink = '$addfav'; var remlink = '$remfav';\n~ if !$postcheck; my @oldfav = split(/,/, ${$uid.$username}{'favorites'}); my ($button,$nofav); if (@oldfav < ($maxfavs || 10)) { $button = qq~$menusep$img{'addfav'}~; $nofav = 1; } else { $nofav = 2; } foreach (@oldfav) { if ($favo eq $_) { $button = qq~$menusep$img{'remfav'}~; $nofav = 0; } } (!$postcheck ? $button : $nofav); } 1;