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 157 lines (126 sloc) 4.621 kb
#!/usr/bin/perl -w
# This code is a part of Slash, which is Copyright 1997-2001 OSDN, and
# released under the GPL. See README and COPYING for more information.
# $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'}es{'index'}
indexes
EOT
for (keys %{$count->{'index'}}) {
$email .= "\t $_=$count->{'index'}es{$_}\n"
}
$email .= "\n-----------------------\n";
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 $virtual_user today`;
$email .= "\n-----------------------\n";
#if($constants->{archive_delay}) {
# my $anonymous_coward_uid = getCurrentStatic('anonymous_coward_uid');
# my $comlim = $slashdb->getUser($anonymous_coward_uid, 'commentlimit');
# $slashdb->setUser($anonymous_coward_uid, { commentlimit => 50000 });
# $email .= "Archiving Comments...\n";
#
# # Find all stories over $constants->{archive_delay} days where writestatus != 5
# my $columns = "sid,time,section,title";
# my $tables = "stories";
# my $where = "writestatus<5 AND writestatus >= 0 AND to_days(now()) - to_days(time) > $constants->{archive_delay}";
#
# my $E = $slashdb->getOldStories($constants->{archive_delay});
#
# for (@{$E}) {
# my($sid, $date, $section, $title) = ($_->[0], $_->[1], $_->[2], $_->[3]);
# $email.= "archiving: $sid $title \n";
# prog2file("$constants->{basedir}/article.pl", "sid=$sid ssi=yes mode=archive",
# "$constants->{basedir}/$section/$sid"."_F.shtml");
#
# unlink("$constants->{basedir}/$section/$sid.shtml")
# or warn "Can't unlink $constants->{basedir}/$section/$sid.shtml: $!";
# symlink("$constants->{basedir}/$section/${sid}_F.shtml", "$constants->{basedir}/$section/$sid.shtml")
# or die "Can't symlink $constants->{basedir}/$section/${sid}_F.shtml -> $sid.shtml";
# $slashdb->deleteComment($sid);
# }
# $slashdb->setUser($anonymous_coward_uid, { commentlimit=>$comlim });
#}
sub generateDailyMail {
my $email = $slashdb->getDailyEmail();
my $r = "$constants->{sitename} Daily Headline Mailer\n\n";
$r .= $slashdb->getBlock("emailsponsor");
# 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." : "";
$r .= <<EOT;
$title$dept
posted by $aid on $time ($tid)
$constants->{rootdir}/article.pl?sid=$sid
EOT
}
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);
$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);
}
mailingList();
}
# Now lets clean up the database
$slashdb->deleteDaily();
Jump to Line
Something went wrong with that request. Please try again.