Wow, you’re still helping at one in the morning? Now that’s dedication! I appreciate your help.
I think I’ve come up with a solution outside of MODx, but it could probably be ported into the system by someone with a better understanding of the events sytem (even with your explanation, I’m not sure I understand which event I could tie to that would fire before the parser). Basically, I just wrote a script that gets the current time, created a second variable that adds one week to the current time(time + 604,800 seconds), then queries the DB and gathers up and emails documents with unpub_dates that are greater than the current time but less than the one-week-out time. Also, I only wanted docs that were assigned a certain template, which is where the ($template == 4) line comes in, but you could remove this if you didn’t need it. Then, I set up a cron job to run once a week on this script. So far, it’s working great!
It looks like this, with the confidential info removed and all editable values in uppercase (please excuse my rookie php; I’m open to suggestions if anyone would like to critique it):
<?php
$today = time();
$today_formatted = date( 'l, F j, Y', $today ).' at '.date('g:s a', $today);
$oneweek = ($today + 604800);
include "/PATH/TO/MYSQLCONNECTION.PHP";
mysql_connect($SERVER, $USERNAME, $PASSWORD) or die(mysql_error()) ;
mysql_select_db("DATABASENAME") or die(mysql_error()) ;
$results = mysql_query("SELECT * FROM DATABASE_TABLENAME") or die(mysql_error());
while($data = mysql_fetch_array($results)) {
$pagetitle = $data['pagetitle'];
$template = $data['template'];
$unpub_date = $data['unpub_date'];
$unpub_date_formatted = date( 'l, F j', $unpub_date );
if(($unpub_date > $today) && ($template==4) && ($unpub_date < $oneweek)){
$message_content .= ($pagetitle.' ('.$unpub_date_formatted.')'.'<br />');
}
}
if (!empty($message_content)) {
$to = '[email protected]';
$subject = 'SUBJECT';
$message = '
<html>
<head>
<title>SUBJECT</title>
</head>
<body>
<p>Message sent on ';
$message .= $today_formatted;
$message .= '</p>
<p><strong>BELOW IS THE CONTENT THAT IS SCHEDULED TO UNPUBLISH IN THE NEXT WEEK</strong></p><br />
';
$message .= $message_content;
$message .= '
</body>
</html>
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: RECIPIENT <[email protected]>' . "\r\n";
$headers .= 'From: SENDER <[email protected]>' . "\r\n";
$headers .= 'Reply-To: SENDER <[email protected]>' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
?>