Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: T_2_3_0_11
Fetching contributors…

Cannot retrieve contributors at this time

executable file 149 lines (120 sloc) 3.67 kb
#!/usr/bin/perl -w
# This code is a part of Slash, and is released under the GPL.
# Copyright 1997-2002 by Open Source Development Network. See README
# and COPYING for more information, or see http://slashcode.com/.
# $Id$
###############################################################################
# dailyStuff - this program runs various housekeeping tasks, sends out the
# the mailing list, and compiles site statistics report and sends the report
# to the site admin
###############################################################################
use strict;
use File::Basename;
use File::Path;
use File::Spec::Functions;
use Slash;
use Slash::Constants qw(:messages);
use Slash::Display;
use Slash::Utility;
my $virtual_user = $ARGV[0];
createEnvironment($ARGV[0]);
my $constants = getCurrentStatic();
my $slashdb = getCurrentDB();
my $messages = getObject('Slash::Messages');
doLogInit('dailyStuff');
# On a site with a lot of users, this may take hours.
dailyStuffLog('MailingList Begin');
mailingList();
dailyStuffLog('MailingList End');
doLogExit('dailyStuff');
sub generateDailyMailees {
my($n_users, $h_users) = @_;
my %mailings = (
dailynews => {
users => $n_users,
code => MSG_CODE_NEWSLETTER,
subj => getData('newsletter subject', {}, 'messages'),
},
dailyheadlines => {
users => $h_users,
code => MSG_CODE_HEADLINES,
subj => getData('headlines subject', {}, 'messages'),
},
);
for my $mailing (keys %mailings) {
my $users = $mailings{$mailing}{users};
my $mkeys = $mailings{$mailing}{mkeys} ||= {};
for (keys %$users) {
my $user = $users->{$_};
my $key = $user->{sectioncollapse};
for (@{$user}{qw(exaid extid exsect)}) {
$key .= '|' . join(',', sort m/'(.+?)'/g);
}
if (exists $mkeys->{$key}) {
push @{$mkeys->{$key}{mails}}, $user->{realemail};
} else {
$mkeys->{$key}{mails} = [$user->{realemail}];
$mkeys->{$key}{user} = {
map { ($_ => $user->{$_}) }
qw(sectioncollapse exaid extid exsect)
};
}
}
}
return \%mailings;
}
sub generateDailyMail {
my($mailing, $user) = @_;
my $stories;
# get data if not gotten yet
my $data = $slashdb->getDailyMail($user) or return;
return unless @$data; # no mail, no mas!
for (@$data) {
my(%story, @ref);
@story{qw(sid title section author tid time dept
introtext bodytext)} = @$_;
1 while chomp($story{introtext});
1 while chomp($story{bodytext});
my $asciitext = $story{introtext};
$asciitext .= "\n\n" . $story{bodytext}
if $constants->{newsletter_body};
($story{asciitext}, @ref) = html2text($asciitext, 74);
$story{refs} = \@ref;
push @$stories, \%story;
}
return slashDisplay($mailing,
{ stories => $stories, urlize => \&urlize },
{ Return => 1, Nocomm => 1, Page => 'messages', Section => 'NONE' }
);
}
sub mailingList {
return unless $messages;
my $n_users = $messages->getNewsletterUsers();
my $h_users = $messages->getHeadlineUsers();
my $mailings = generateDailyMailees($n_users, $h_users) or return;
for my $mailing (keys %$mailings) {
my $subj = $mailings->{$mailing}{subj};
my $code = $mailings->{$mailing}{code};
my $mkeys = $mailings->{$mailing}{mkeys};
dailyStuffLog("Daily Mail ($mailing) begin");
for my $key (keys %$mkeys) {
my $user = $mkeys->{$key}{user};
my $text = generateDailyMail($mailing, $user) or next;
$messages->bulksend(
$mkeys->{$key}{mails}, $subj, $text, $code
);
}
dailyStuffLog("Daily Mail ($mailing) end");
}
}
sub dailyStuffLog {
doLog('dailyStuff', \@_);
}
sub urlize {
local($_) = @_;
s/^(.{62})/$1\n/g;
s/(\S{74})/$1\n/g;
$_ = "<URL:" . $_ . ">";
return $_;
}
1;
Jump to Line
Something went wrong with that request. Please try again.