File: dailyStuff

package info (click to toggle)
slash 2.2.6-8etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 3,672 kB
  • ctags: 1,915
  • sloc: perl: 23,113; sql: 1,878; sh: 433; makefile: 233
file content (109 lines) | stat: -rwxr-xr-x 2,919 bytes parent folder | download | duplicates (3)
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
#!/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,v 1.2.2.21 2001/10/25 17:34:43 pudge Exp $

###############################################################################
# dailyStuff - this program runs various housekeeping tasks, sends out 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::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 $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 $n_users = $messages->getNewsletterUsers();
	my $h_users = $messages->getHeadlineUsers();

	# get addresses from users
	my @n_email = map { $_->[2] } @$n_users;
	my @h_email = map { $_->[2] } @$h_users;

	my $n_subj = getData('newsletter subject', {}, 'messages');
	my $h_subj = getData('headlines subject',  {}, 'messages');

	dailyStuffLog("Daily Newsletter begin");
	$messages->bulksend(\@n_email, $n_subj, $newsletter, 0);
	dailyStuffLog("Daily Newsletter end");
	dailyStuffLog("Daily Headlines begin");
	$messages->bulksend(\@h_email, $h_subj, $headlines,  1);
	dailyStuffLog("Daily Headlines end");
}

sub dailyStuffLog {
	doLog('dailyStuff', \@_);
}

sub urlize {
	local($_) = @_;
	s/^(.{62})/$1\n/g;
	s/(\S{74})/$1\n/g;
	$_ = "<URL:" . $_ . ">";
	return $_;
}

1;