Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 150 lines (122 sloc) 3.805 kb
#!/usr/bin/perl -w
# This code is a part of Slash, and is released under the GPL.
# Copyright 1997-2001 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 generateDailyMail {
my($n_users, $h_users) = @_;
my(%storydata);
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};
my @ex = @{$user}{qw(exaid extid exsect)};
for (@ex) {
$key .= '|' . join(',', sort m/'(.+?)'/g);
}
# if this mailing created, just add a user to it
if (exists $mkeys->{$key}) {
push @{$mkeys->{$key}{mails}}, $user->{realemail};
# else, we gotta create the mailing
} else {
my $stories;
# get data if not gotten yet
if (exists $storydata{$key}) {
$stories = $storydata{$key};
} else {
my $data = $slashdb->getDailyMail($user);
next 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;
}
$storydata{$key} = $stories;
}
$mkeys->{$key}{mails} = [$user->{realemail}];
$mkeys->{$key}{text} = slashDisplay($mailing,
{ stories => $stories, urlize => \&urlize },
{ Return => 1, Nocomm => 1, Page => 'messages', Section => 'NONE' }
);
}
}
}
return \%mailings;
}
sub mailingList {
return unless $messages;
my $n_users = $messages->getNewsletterUsers();
my $h_users = $messages->getHeadlineUsers();
my $mailings = generateDailyMail($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) {
dailyStuffLog("Daily Mail ($mailing) begin: $key");
$messages->bulksend(
$mkeys->{$key}{mails}, $subj,
$mkeys->{$key}{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.