Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: v2_0_0_0_p2
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 133 lines (106 sloc) 3.47 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
#!/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::Utility;

my $virtual_user = $ARGV[0];
createEnvironment($ARGV[0]);
my $constants = getCurrentStatic();
my $slashdb = getCurrentDB();


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";

sub generateDailyMail {
my $email = $slashdb->getDailyMail();

my $r = "$constants->{sitename} Daily Headline Mailer\n\n";
$r .= $slashdb->getBlock("emailsponsor", 'block');
# newlines after advert
$r .= "\n\n";

return unless @$email;
for (@{$email}) {
my($sid, $title, $section, $aid, $tid, $time, $dept) = @$_;
$dept = $constants->{use_dept} ? "\n from the $dept dept." : "";
$time = timeCalc($time, '%A %B %d, @%H:%M');

$r .= <<EOT;

$title
$dept
posted by $aid on $time ($tid)
$constants->{absolutedir}/article.pl?sid=$sid
EOT
}
print "$r\n";
return $r;
}

sub mailingList {
my $p = generateDailyMail() or return;

my $users = $slashdb->getMailingList();

for (@{$users}) {
sendEmail($_->[0], "24 Hours of $constants->{sitename} Headlines For $_->[2]", <<EOT, 'bulk');
      $p
      You are getting this message because you subscribed to it.
      If you want to unsubscribe from this, go to
       $constants->{absolutedir}/users.pl
      You can login as "$_->[2]" and disable the mailing from there.
EOT
}
}

sub prog2file {
my($command, $arguments, $f) = @_;

my $d = `$command virtual_user=$virtual_user $arguments`;
my $dir = dirname($f);
mkpath($dir, 0, 0755) unless -e $dir;
if (length($d) > 0) {
local *F;
open F, ">$f" or die "Can't open $f: $!";
print F $d;
close F;
return "1";

} else {
return "0";
}
}

# Send a message to the site admin.
if ($constants->{send_mail} == 1) {
for (@{$constants->{stats_reports}}) {
sendEmail($_, "$constants->{sitename} Stats Report", $email, 'bulk');
}
mailingList();
}
# Now lets clean up the database
$slashdb->deleteDaily();
Something went wrong with that request. Please try again.