Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: T_2_3_0_136
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 163 lines (131 sloc) 4.159 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
#!/usr/bin/perl -w
# This code is a part of Slash, and is released under the GPL.
# Copyright 1997-2003 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
###############################################################################

exit(1); # this is no longer in use, see themes/slashcode/tasks/daily.pl

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 my $uid (keys %$users) {
my $user = $users->{$uid};

my $key = $user->{sectioncollapse};
for (@{$user}{qw(exaid extid exsect)}) {
$key .= '|' . join(',', sort m/'(.+?)'/g);
}
# allow us to make certain emails sent individually,
# by including a unique value in users_param for
# this key -- pudge
$user->{daily_mail_special} ||= '';
$key .= '|' . $user->{daily_mail_special};

if (exists $mkeys->{$key}) {
push @{$mkeys->{$key}{mails}}, $user->{realemail};
} else {
$mkeys->{$key}{mails} = [$user->{realemail}];
$mkeys->{$key}{user} = {
uid => $uid,
map { ($_ => $user->{$_}) }
qw(sectioncollapse exaid extid exsect daily_mail_special)
};
}
}
}

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});

$story{introtext} = parseSlashizedLinks($story{introtext});
$story{bodytext} = parseSlashizedLinks($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, $user->{uid}
);
}
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;

__END__
Something went wrong with that request. Please try again.