Description:
This provides the functionality of the story digests but only for stories in the edit and voting queues.
It requires a user pref named queue_digest which is a checkbox, and should use the Site Control 'enable_story_digests' and the perm 'moderate' for both view and edit (especially if your site restricts voting in the queue to a subset of registered users).
It requires the following blocks: queue_digest_subject, queue_digest_header, queue_digest_footer. You can optionally use queue_digest_headerfooter instead of the previous two if you want the header and footer to be identical. I suggest modelling the blocks after the digest_* blocks, as that's what I copied when creating this box.
Box Code:
my @date = localtime();
# get user list
my $where = "userprefs.prefname = 'queue_digest' AND userprefs.uid = users.uid AND userprefs.prefvalue = 'yes'";
my ($rv, $sth) = $S->db_select({
WHAT => "userprefs.uid, userprefs.prefvalue, users.realemail, users.nickname",
FROM => "userprefs, users",
WHERE => $where
});
my @users;
while (my($uid, $prefvalue, $email, $nick) = $sth->fetchrow()) {
push(@users, {uid => $uid, nick => $nick, email => $email});
}
$sth->finish();
# Get digest contents
my $rollback = 60 * 24;
# one day; no weekly option for the queue
my $data = "";
my $excl_sql = $S->excluded_from_all_stories();
my ($rv, $sth) = $S->db_select({
FROM => 'stories LEFT JOIN users ON stories.aid = users.uid',
WHAT => 'sid, tid, aid, users.nickname AS nick, time, title, dept, introtext, section',
WHERE => "displaystatus = '-2' $excl_sql AND time >= DATE_SUB(NOW(), INTERVAL $rollback minute)",
ORDER_BY => 'time desc'
});
while (my $storydata = $sth->fetchrow_hashref()) {
$storydata->{nick} = $S->var('anon_user_nick') if $storydata->{aid} == -1;
$data .= $S->_cron_digest_format_stories($storydata);
}
$sth->finish();
return 1 unless $data;
# no emails sent if no stories return
my $header = $S->{UI}->{BLOCKS}->{queue_digest_header} \|\| $S->{UI}->{BLOCKS}->{queue_digest_headerfooter};
my $footer = $S->{UI}->{BLOCKS}->{queue_digest_footer} \|\| $S->{UI}->{BLOCKS}->{queue_digest_headerfooter};
my $mail = join("\n\n",$header,$data,$footer);
my $errors;
foreach my $user (@users) {
# send each user the email
my $usermail = $S->interpolate($mail,$user);
my $ret = $S->mail($user->{email}, $S->{UI}->{BLOCKS}->{queue_digest_subject}, $usermail);
$errors .= $ret if ( $ret != 1 );
}
return $errors if $errors;
return 1;
|