" : $to_header;
fputs($socket, "To: $to_header\r\n");
// Now any custom headers....
fputs($socket, "$headers\r\n\r\n");
// Ok now we are ready for the message...
fputs($socket, "$message\r\n");
// Ok the all the ingredients are mixed in let's cook this puppy...
fputs($socket, ".\r\n");
server_parse($socket, "250");
// Now tell the server we are done and close the socket...
fputs($socket, "QUIT\r\n");
fclose($socket);
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 is_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 ";";
print_r($this->data);
echo "
;";
}
// Thinking about a lock file...
function process()
{
global $_SERVER, $_ENV, $db;
if (file_exists($this->cache_file))
{
include($this->cache_file);
$fp = @fopen($this->cache_file, 'r');
@flock($fp, LOCK_EX);
}
else
{
return;
}
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("#(?EMAIL ERROR [ ' . (($smtp_delivery) ? 'SMTP' : 'PHP') . ' ]
' . $result . '
CALLING PAGE
' . ((!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : $_ENV['PHP_SELF']) . '
';
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)
{
@flock($fp, LOCK_UN);
fclose($fp);
unlink($this->cache_file);
}
else
{
$file = 'queue_data=' . $this->format_array($this->queue_data) . '; ?>';
@flock($fp, LOCK_UN);
fclose($fp);
if ($fp = @fopen($this->cache_file, 'wb'))
{
@flock($fp, LOCK_EX);
fwrite($fp, $file);
@flock($fp, LOCK_UN);
fclose($fp);
}
}
$sql = "UPDATE " . CONFIG_TABLE . "
SET config_value = '" . time() . "'
WHERE config_name = 'last_queue_run'";
$db->sql_query($sql);
}
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 = 'queue_data = ' . $this->format_array($this->data) . '; ?>';
if ($fp = @fopen($this->cache_file, 'wt'))
{
@flock($fp, LOCK_EX);
fwrite($fp, $file);
@flock($fp, LOCK_UN);
fclose($fp);
}
}
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) . ')';
}
}
?>