Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: pudge
Fetching contributors…

Cannot retrieve contributors at this time

executable file 147 lines (112 sloc) 3.776 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 Slash;
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');
sendAdminMail();
mailingList();
# Now lets clean up the database
$slashdb->archiveComments();
$slashdb->deleteDaily();
exit;
sub sendAdminMail {
my $count = $slashdb->countDaily();
my $sdTotalHits = $slashdb->getVar('totalhits', 'value');
$sdTotalHits = $sdTotalHits + $count->{'total'};
$slashdb->setVar("totalhits", $sdTotalHits);
$slashdb->updateStamps();
my $email = <<EOT;
$constants->{sitename} Stats for yesterday
total $count->{'total'}
unique $count->{'unique'}
total hits $sdTotalHits
homepage $count->{'index'}{'index'}
indexes
EOT
for (keys %{$count->{'index'}}) {
$email .= "\t $_=$count->{'index'}{$_}\n"
}
$email .= "\n-----------------------\n";
# DOESN'T WORK
# for my $key (sort { $count->{'articles'}{$b} <=> $count->{'articles'}{$a} } keys %{$count->{'articles'}}) {
# my $value = $count->{'articles'}{$key};
#
# my $story = $slashdb->getStory($key, 'title', 'aid');
#
# $email .= "$value\t$key " . substr($story->{'title'}, 0, 30) .
# " by $story->{'author'}\n" if $value > 100;
# }
$email .= "\n-----------------------\n";
$email .= `$constants->{slashdir}/bin/tailslash -u $virtual_user -y today`;
$email .= "\n-----------------------\n";
# Send a message to the site admin.
for (@{$constants->{stats_reports}}) {
sendEmail($_, "$constants->{sitename} Stats Report", $email, 'bulk');
}
}
sub generateDailyMail {
my $data = $slashdb->getDailyMail();
return unless @$data;
my @stories;
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;
}
my $newsletter = slashDisplay("dailynews",
{ stories => \@stories, urlize => \&urlize },
{ Return => 1, Nocomm => 1, Page => 'messages', Section => 'NONE' }
);
my $headlines = slashDisplay("dailyheadlines",
{ stories => \@stories },
{ Return => 1, Nocomm => 1, Page => 'messages', Section => 'NONE' }
);
return($newsletter, $headlines);
}
sub mailingList {
return unless $messages;
my($newsletter, $headlines) = generateDailyMail();
return unless $headlines;
# need to change for specific prefs, later
my $h_users = $messages->getHeadlineUsers();
my $n_users = $messages->getNewsletterUsers();
for (@{$h_users}) {
my $head_subj = "24 Hours of $constants->{sitename} Headlines For $_->[0]";
$messages->quicksend($_->[1], $head_subj, $headlines, 1);
}
for (@{$n_users}) {
my $news_subj = "24 Hours of $constants->{sitename} Stories For $_->[0]";
$messages->quicksend($_->[1], $news_subj, $newsletter, 0);
}
}
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.