mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-19 16:11:21 +02:00
added email queue + small changes (do not hit me for the mysql_basic change :D)
git-svn-id: file:///svn/phpbb/trunk@4067 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
@@ -24,11 +24,18 @@ class emailer
|
||||
var $msg, $subject, $extra_headers;
|
||||
var $to_addres, $cc_address, $bcc_address;
|
||||
var $reply_to, $from;
|
||||
var $use_queue, $queue;
|
||||
|
||||
var $tpl_msg = array();
|
||||
|
||||
function emailer()
|
||||
function emailer($use_queue = false)
|
||||
{
|
||||
$this->use_queue = $use_queue;
|
||||
if ($use_queue)
|
||||
{
|
||||
$this->queue = new Queue();
|
||||
$this->queue->init('emailer', 100);
|
||||
}
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
@@ -202,7 +209,22 @@ class emailer
|
||||
$this->extra_headers = (($this->replyto !='') ? "Reply-to: <$this->replyto>\r\n" : '') . (($this->from != '') ? "From: <$this->from>\r\n" : "From: <" . $config['board_email'] . ">\r\n") . "Return-Path: <" . $config['board_email'] . ">\r\nMessage-ID: <" . md5(uniqid(time())) . "@" . $config['server_name'] . ">\r\nMIME-Version: 1.0\r\nContent-type: text/plain; charset=" . $this->encoding . "\r\nContent-transfer-encoding: 8bit\r\nDate: " . gmdate('D, d M Y H:i:s Z', time()) . "\r\nX-Priority: 3\r\nX-MSMail-Priority: Normal\r\nX-Mailer: PHP\r\n" . (($cc != '') ? "Cc:$cc\r\n" : '') . (($bcc != '') ? "Bcc:$bcc\r\n" : '') . trim($this->extra_headers);
|
||||
|
||||
// Send message ... removed $this->encode() from subject for time being
|
||||
if (!$this->use_queue)
|
||||
{
|
||||
$result = ($config['smtp_delivery']) ? smtpmail($to, $this->subject, $this->msg, $this->extra_headers) : mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\r\n", $this->msg), $this->extra_headers);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->queue->put('emailer', array(
|
||||
'smtp_delivery' => $config['smtp_delivery'],
|
||||
'to' => $to,
|
||||
'subject' => $this->subject,
|
||||
'msg' => $this->msg,
|
||||
'extra_headers' => $this->extra_headers)
|
||||
);
|
||||
|
||||
$result = true;
|
||||
}
|
||||
|
||||
// Did it work?
|
||||
if (!$result)
|
||||
@@ -432,4 +454,170 @@ function smtpmail($mail_to, $subject, $message, $headers = '')
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// This class is for handling queues - to be placed into another file ?
|
||||
// At the moment it is only handling the email queue
|
||||
class Queue
|
||||
{
|
||||
var $data = array();
|
||||
var $queue_data = array();
|
||||
var $package_size = 0;
|
||||
var $cache_file = '';
|
||||
|
||||
function Queue()
|
||||
{
|
||||
global $phpEx, $phpbb_root_path;
|
||||
|
||||
$this->data = array();
|
||||
$this->cache_file = $phpbb_root_path . 'cache/queue.' . $phpEx;
|
||||
}
|
||||
|
||||
//--TEMP
|
||||
function queue_filled()
|
||||
{
|
||||
if (file_exists($this->cache_file))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function init($object, $package_size)
|
||||
{
|
||||
$this->data[$object] = array();
|
||||
$this->data[$object]['package_size'] = $package_size;
|
||||
$this->data[$object]['data'] = array();
|
||||
}
|
||||
|
||||
function put($object, $scope)
|
||||
{
|
||||
$this->data[$object]['data'][] = $scope;
|
||||
}
|
||||
|
||||
//--TEMP
|
||||
function show()
|
||||
{
|
||||
echo ";<pre>";
|
||||
print_r($this->data);
|
||||
echo "</pre>;";
|
||||
}
|
||||
|
||||
function process()
|
||||
{
|
||||
global $_SERVER, $_ENV;
|
||||
|
||||
if (file_exists($this->cache_file))
|
||||
{
|
||||
include($this->cache_file);
|
||||
}
|
||||
|
||||
foreach ($this->queue_data as $object => $data_array)
|
||||
{
|
||||
$package_size = $data_array['package_size'];
|
||||
|
||||
$num_items = (count($data_array['data']) < $package_size) ? count($data_array['data']) : $package_size;
|
||||
|
||||
if ($object == 'emailer')
|
||||
{
|
||||
@set_time_limit(60);
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $num_items; $i++)
|
||||
{
|
||||
foreach ($data_array['data'][0] as $var => $value)
|
||||
{
|
||||
$$var = $value;
|
||||
}
|
||||
|
||||
if ($object == 'emailer')
|
||||
{
|
||||
$result = ($smtp_delivery) ? smtpmail($to, $subject, $msg, $extra_headers) : mail($to, $subject, preg_replace("#(?<!\r)\n#s", "\r\n", $msg), $extra_headers);
|
||||
|
||||
if (!$result)
|
||||
{
|
||||
$message = '<u>EMAIL ERROR</u> [ ' . (($smtp_delivery) ? 'SMTP' : 'PHP') . ' ]<br /><br />' . $result . '<br /><br /><u>CALLING PAGE</u><br /><br />' . ((!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : $_ENV['PHP_SELF']) . '<br />';
|
||||
trigger_error($message, E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
array_shift($this->queue_data[$object]['data']);
|
||||
}
|
||||
|
||||
if (count($this->queue_data[$object]['data']) == 0)
|
||||
{
|
||||
unset($this->queue_data[$object]);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($this->queue_data) == 0)
|
||||
{
|
||||
unlink($this->cache_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
$file = '<?php $this->queue_data=' . $this->format_array($this->queue_data) . '; ?>';
|
||||
|
||||
if ($fp = @fopen($this->cache_file, 'wb'))
|
||||
{
|
||||
@flock($fp, LOCK_EX);
|
||||
fwrite($fp, $file);
|
||||
@flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function save()
|
||||
{
|
||||
if (file_exists($this->cache_file))
|
||||
{
|
||||
include($this->cache_file);
|
||||
|
||||
foreach ($this->queue_data as $object => $data_array)
|
||||
{
|
||||
if (count($this->data[$object]))
|
||||
{
|
||||
$this->data[$object]['data'] = array_merge($data_array['data'], $this->data[$object]['data']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$file = '<?php $this->queue_data=' . $this->format_array($this->data) . '; ?>';
|
||||
|
||||
if ($fp = @fopen($this->cache_file, 'wb'))
|
||||
{
|
||||
@flock($fp, LOCK_EX);
|
||||
fwrite($fp, $file);
|
||||
@flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
|
||||
// From acm_file.php
|
||||
function format_array($array)
|
||||
{
|
||||
$lines = array();
|
||||
foreach ($array as $k => $v)
|
||||
{
|
||||
if (is_array($v))
|
||||
{
|
||||
$lines[] = "'$k'=>" . $this->format_array($v);
|
||||
}
|
||||
elseif (is_int($v))
|
||||
{
|
||||
$lines[] = "'$k'=>$v";
|
||||
}
|
||||
elseif (is_bool($v))
|
||||
{
|
||||
$lines[] = "'$k'=>" . (($v) ? 'TRUE' : 'FALSE');
|
||||
}
|
||||
else
|
||||
{
|
||||
$lines[] = "'$k'=>'" . str_replace("'", "\'", str_replace('\\', '\\\\', $v)) . "'";
|
||||
}
|
||||
}
|
||||
return 'array(' . implode(',', $lines) . ')';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@@ -1239,6 +1239,7 @@ function user_notification($mode, $subject, $forum_id, $topic_id, $post_id)
|
||||
|
||||
if ($ids != '')
|
||||
{
|
||||
// TODO: Paul - correct call to check f_read for specific users ?
|
||||
$sql = "SELECT a.user_id
|
||||
FROM " . ACL_OPTIONS_TABLE . " ao, " . ACL_USERS_TABLE . " a
|
||||
WHERE a.user_id IN (" . $ids . ")
|
||||
@@ -1288,24 +1289,24 @@ function user_notification($mode, $subject, $forum_id, $topic_id, $post_id)
|
||||
//
|
||||
if ($topic_notification)
|
||||
{
|
||||
$sql = "SELECT u.user_id, u.username, u.user_email, u.user_lang, t.topic_title, f.forum_name
|
||||
FROM " . TOPICS_WATCH_TABLE . " tw, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . FORUMS_TABLE . " f
|
||||
WHERE tw.topic_id = $topic_id
|
||||
AND tw.user_id NOT IN ($sql_ignore_users)
|
||||
$sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, t.topic_title, f.forum_name
|
||||
FROM ' . TOPICS_WATCH_TABLE . ' tw, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . FORUMS_TABLE . ' f
|
||||
WHERE tw.topic_id = ' . $topic_id . '
|
||||
AND tw.user_id NOT IN (' . $sql_ignore_users . ')
|
||||
AND tw.notify_status = 0
|
||||
AND f.forum_id = $forum_id
|
||||
AND f.forum_id = ' . $forum_id . '
|
||||
AND t.topic_id = tw.topic_id
|
||||
AND u.user_id = tw.user_id";
|
||||
AND u.user_id = tw.user_id';
|
||||
}
|
||||
else if ($newtopic_notification)
|
||||
{
|
||||
$sql = "SELECT u.user_id, u.username, u.user_email, u.user_lang, f.forum_name
|
||||
FROM " . USERS_TABLE . " u, " . FORUMS_WATCH_TABLE . " fw, " . FORUMS_TABLE . " f
|
||||
WHERE fw.forum_id = $forum_id
|
||||
AND fw.user_id NOT IN ($sql_ignore_users)
|
||||
$sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, f.forum_name
|
||||
FROM ' . USERS_TABLE . ' u, ' . FORUMS_WATCH_TABLE . ' fw, ' . FORUMS_TABLE . ' f
|
||||
WHERE fw.forum_id = ' . $forum_id . '
|
||||
AND fw.user_id NOT IN (' . $sql_ignore_users . ')
|
||||
AND fw.notify_status = 0
|
||||
AND f.forum_id = fw.forum_id
|
||||
AND u.user_id = fw.user_id";
|
||||
AND u.user_id = fw.user_id';
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1354,14 +1355,14 @@ function user_notification($mode, $subject, $forum_id, $topic_id, $post_id)
|
||||
$already_notified = ($update_watched_sql_topic == '') ? '' : $update_watched_sql_topic . ', ';
|
||||
$already_notified .= ($update_watched_sql_forum == '') ? '' : $update_watched_sql_forum . ', ';
|
||||
|
||||
$sql = "SELECT u.user_id, u.username, u.user_email, u.user_lang, t.topic_title, f.forum_name
|
||||
FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . FORUMS_WATCH_TABLE . " fw, " . FORUMS_TABLE . " f
|
||||
WHERE fw.forum_id = $forum_id
|
||||
AND fw.user_id NOT IN ($already_notified $sql_ignore_users)
|
||||
$sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, t.topic_title, f.forum_name
|
||||
FROM ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . FORUMS_WATCH_TABLE . ' fw, ' . FORUMS_TABLE . ' f
|
||||
WHERE fw.forum_id = ' . $forum_id . '
|
||||
AND fw.user_id NOT IN (' . $already_notified . ' ' . $sql_ignore_users . ')
|
||||
AND fw.notify_status = 0
|
||||
AND t.topic_id = $topic_id
|
||||
AND t.topic_id = ' . $topic_id . '
|
||||
AND f.forum_id = fw.forum_id
|
||||
AND u.user_id = fw.user_id";
|
||||
AND u.user_id = fw.user_id';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
if ($row = $db->sql_fetchrow($result))
|
||||
@@ -1382,9 +1383,8 @@ function user_notification($mode, $subject, $forum_id, $topic_id, $post_id)
|
||||
}
|
||||
}
|
||||
|
||||
// We're going to try and minimise the number of emails we send by using bcc.
|
||||
// The complication here is that different templates and/or localisations may
|
||||
// be required so we need to account for these.
|
||||
// We are using an email queue here, no emails are sent now, only queued.
|
||||
// Returned to use the TO-Header, default package size is 100 (should be admin-definable) !?
|
||||
if (sizeof($email_users) && $config['email_enable'])
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
@@ -1392,28 +1392,26 @@ function user_notification($mode, $subject, $forum_id, $topic_id, $post_id)
|
||||
@set_time_limit(60);
|
||||
|
||||
include($phpbb_root_path . 'includes/emailer.'.$phpEx);
|
||||
$emailer = new emailer();
|
||||
$emailer = new emailer(true); // use queue
|
||||
|
||||
$bcc_list_ary = array();
|
||||
$email_list_ary = array();
|
||||
foreach ($email_users as $row)
|
||||
{
|
||||
$pos = sizeof($bcc_list_ary[$row['email_template']][$row['user_lang']]);
|
||||
$bcc_list_ary[$row['email_template']][$row['user_lang']][$pos]['email'] = $row['user_email'];
|
||||
$bcc_list_ary[$row['email_template']][$row['user_lang']][$pos]['name'] = $row['username'];
|
||||
$pos = sizeof($email_list_ary[$row['email_template']]);
|
||||
$email_list_ary[$row['email_template']][$pos]['email'] = $row['user_email'];
|
||||
$email_list_ary[$row['email_template']][$pos]['name'] = $row['username'];
|
||||
$email_list_ary[$row['email_template']][$pos]['lang'] = $row['user_lang'];
|
||||
}
|
||||
unset($email_users);
|
||||
|
||||
foreach ($bcc_list_ary as $email_template => $bcc_list)
|
||||
foreach ($email_list_ary as $email_template => $email_list)
|
||||
{
|
||||
foreach ($bcc_list as $lang => $bcc)
|
||||
foreach ($email_list as $addr)
|
||||
{
|
||||
$emailer->template($email_template, $lang);
|
||||
$emailer->template($email_template, $addr['lang']);
|
||||
|
||||
$emailer->replyto($config['board_email']);
|
||||
foreach ($bcc as $addr)
|
||||
{
|
||||
$emailer->bcc($addr['email'], $addr['name']);
|
||||
}
|
||||
$emailer->to($addr['email'], $addr['name']);
|
||||
|
||||
$emailer->assign_vars(array(
|
||||
'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']),
|
||||
@@ -1431,8 +1429,10 @@ function user_notification($mode, $subject, $forum_id, $topic_id, $post_id)
|
||||
$emailer->reset();
|
||||
}
|
||||
}
|
||||
|
||||
$emailer->queue->save();
|
||||
}
|
||||
unset($bcc_list_ary);
|
||||
unset($email_list_ary);
|
||||
|
||||
if ($delete_users_topic != '')
|
||||
{
|
||||
|
@@ -33,7 +33,6 @@ $user->start();
|
||||
$user->setup();
|
||||
$auth->acl($user->data);
|
||||
|
||||
|
||||
// Handle marking posts
|
||||
if ($mark_read == 'forums')
|
||||
{
|
||||
@@ -48,6 +47,15 @@ if ($mark_read == 'forums')
|
||||
trigger_error($message);
|
||||
}
|
||||
|
||||
// Handle queue - to be placed into common.php ? I think to only check and process at the index is enough. ;)
|
||||
// Do not initiate the object, we do not need to do this...
|
||||
if (file_exists($phpbb_root_path . 'cache/queue.' . $phpEx))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/emailer.'.$phpEx);
|
||||
$queue = new Queue();
|
||||
$queue->process();
|
||||
}
|
||||
|
||||
// Set some stats, get posts count from forums data if we... hum... retrieve all forums data
|
||||
$total_posts = $config['num_posts'];
|
||||
$total_topics = $config['num_topics'];
|
||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user