function sendSchedule($d, $showHTML, $receivers, $list, &$message, &$max, $tags = null) { static $countEmails = 0; $mailing = $d['mailing']; $h = ''; $xf = new xonfig(); if (empty($mailing)) { $message = _ACA_NO_MAILING_ENTERED; return false; } elseif (empty($receivers)) { $message = _ACA_NO_ADDRESS_ENTERED; return false; } elseif (empty($list)) { $message = _ACA_NO_LIST_ENTERED; return false; } else { $message = ''; } $mailingId = $mailing->id; $issue_nb = $mailing->issue_nb; $subject = $mailing->subject; $content = $mailing->htmlcontent; $textonly = $mailing->textonly; $fromname = $mailing->fromname; $fromemail = $mailing->fromemail; $images = $mailing->images; $listId = $list->id; $html = $list->html; $layout = $list->layout; $totalsofar = number_format(0, 4, ',', ''); $nbPause = 0; $tags['issuenb'] = $issue_nb; if (ini_get('safe_mode')) { } else { @set_time_limit(60 * $GLOBALS[ACA . 'script_timeout']); } ignore_user_abort(true); ### create the mail $mail = acajoom_mail::getMailer($mailing); ### create content acajoom_mail::getContent($images, $layout, $content, $textonly); $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; $html_sent = 0; $text_sent = 0; $size = sizeof($receivers); $log_detailed = "\r\n" . "\r\n" . '*** ' . strftime(_DATE_FORMAT_LC) . ' ***' . "\r\n"; foreach ($receivers as $receiver) { $tags['user_id'] = $receiver->user_id; if ($html && intval($receiver->receive_html) == 1) { $mail->IsHTML(true); $ashtml = 1; $Altbody = acajoom_mail::replaceTags($textonly, $receiver, $list, $mailingId, 0, $tags); $mail->AltBody = acajoom_mail::safe_utf8_encode($Altbody, $mail->CharSet); $html_sent++; $mail->Body = acajoom_mail::replaceTags($content, $receiver, $list, $mailingId, $ashtml, $tags); } else { $mail->IsHTML(false); $mail->AltBody = ''; $ashtml = 0; $text_sent++; $mail->Body = acajoom_mail::replaceTags($textonly, $receiver, $list, $mailingId, $ashtml, $tags); // if we are in TEXT Mode, Why do we add embedded images??? if (!empty($images)) { foreach ($images as $image) { $img = explode('|', $image); $attrib = explode("/", $img[0]); $path = $GLOBALS['mosConfig_absolute_path'] . '/images/stories/'; if (count($img) == 1) { $imageName = $img[0]; } else { $imageName = $attrib[count($attrib) - 1]; for ($index = 0; $index < sizeof($attrib) - 1; $index++) { $path .= $attrib[$index] . '/'; } } $mail->AddAttachment($path . $imageName); } } } $tname = explode(" ", $receiver->name); $firstname = $tname[0]; $mail->AddAddress($receiver->email, $receiver->name); $sujetReplaced = str_replace('[NAME]', $receiver->name, $subject); $sujetReplaced = str_replace('[FIRSTNAME]', $firstname, $sujetReplaced); if (class_exists('auto')) { auto::tags($sujetReplaced, $tags); } $mail->Subject = $sujetReplaced; $mailssend = $mail->Send(); $countEmails++; if ($countEmails >= $GLOBALS[ACA . 'cron_max_emails']) { $max = true; } if ($mail->error_count > 0) { static $info = false; if (!$info and acajoom::checkPermissions('admin')) { echo '<br/>Mailer Error : ' . $mail->ErrorInfo; $info = true; } $log_detailed .= '[' . $mailingId . '] ' . $subject . ' : ' . $receiver->email . ' -> ' . _ACA_MESSAGE_NOT . "\r\n" . _ACA_MAILER_ERROR . ': ' . $mail->ErrorInfo . "\r\n"; if ($html && intval($receiver->receive_html) == 1) { $html_sent--; } else { $text_sent--; } } else { $log_detailed .= '[' . $mailingId . '] ' . $subject . ' : ' . $receiver->email . ' -> ' . _ACA_MESSAGE_SENT_SUCCESSFULLY . "\r\n"; if ($GLOBALS[ACA . 'enable_statistics'] == 1 and $GLOBALS[ACA . 'statistics_per_subscriber'] == 1) { xmailing::insertStats($mailingId, $receiver->id, $ashtml); } $d['qids'] = array(); $erro = new xerr(__FILE__, __FUNCTION__, __CLASS__); if ($d['listype'] == '2') { $d['qids'][0] = queue::whatQID($mailingId, $receiver->id, $d['listype']); $erro->ck = auto::updateAutoresponderSent($d); $erro->Eck(__LINE__, '8137', $d); } elseif ($d['listype'] == '1' || $d['listype'] == '7') { $d['qids'][0] = queue::whatQID($mailingId, $receiver->id, $d['listype']); $erro->ck = queue::deleteQueues($d['qids']); $erro->Eck(__LINE__, '8127', $d); } } $mail->ClearAddresses(); } if ($GLOBALS[ACA . 'enable_statistics'] == 1) { xmailing::updateStatsGlobal($mailingId, $html_sent, $text_sent, false); } $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; if ($totalsofar > 0) { $totaltime = $totalsofar; $totalstr = strval($totaltime); } else { $totaltime = number_format($endtime - $starttime - $nbPause * $GLOBALS[ACA . 'pause_time'], 4, ',', ''); $totalstr = strval($totaltime); } if ($GLOBALS[ACA . 'send_data'] == 1) { acajoom_mail::sendReport($fromemail, $totalstr, $html_sent, $text_sent); } $xf->plus('totalmailingsent' . $list->list_type, $html_sent + $text_sent); $xf->plus('totalmailingsent0', $html_sent + $text_sent); $log_simple = 'Time to send: ' . $totalstr . ' ' . _ACA_SECONDS . "\r\n" . 'Number of subscribers: ' . ($text_sent + $html_sent) . "\r\n" . 'HTML format: ' . $html_sent . "\r\n" . 'Text format: ' . $text_sent . "\r\n"; $log_detailed = $log_simple . 'Details: ' . "\r\n" . $log_detailed . "\r\n"; if (class_exists('lisType')) { acajoom_mail::writeLogs($list, $log_simple, $log_detailed); } if ($d['listype'] == '2') { echo '<br/>' . _ACA_QUEUE_AUTO_PROCESSED; } elseif ($d['listype'] == '1') { echo '<br/>' . _ACA_QUEUE_NEWS_PROCESSED; } if ($html_sent + $text_sent > 0) { return true; } else { $message = xmailing::M('no', _ACA_NO_MAILING_SENT); return false; } }
function updateQueueData($qid, $subsId, $type, $listId, $mailingId, $issue, $date, $delay, $accLevel, $published) { if (ACA_CMSTYPE) { $database =& JFactory::getDBO(); } else { global $database; } //endif $erro = new xerr(__FILE__, __FUNCTION__, __CLASS__); if (!empty($qid) or !empty($subsId)) { $query = 'UPDATE `#__acajoom_queue` SET '; $query .= ' `type` = ' . $type . ','; $query .= ' `list_id` = ' . $listId . ','; if (!empty($mailingId)) { $query .= ' `mailing_id` = ' . $mailingId . ','; } if (!empty($date)) { $query .= ' `send_date` = \'' . $date . '\', '; } if (!empty($delay)) { $query .= ' `delay` = ' . $delay . ' ,'; } if (!empty($issue)) { $query .= ' `issue_nb` = ' . $issue . ' , '; } if ($accLevel != 0) { $query .= ' `acc_level` = ' . $accLevel . ' ,'; } $query .= ' `published` = ' . $published; if (!empty($qid)) { $qids = implode(',', $qid); $query .= ' WHERE `qid` IN ( ' . $qids . ' ) '; } else { $subsIds = implode(',', $subsId); if ($mailingId > 0) { $query .= ' WHERE `subscriber_id` IN ( ' . $subsIds . ' ) AND `mailing_id` =' . $mailingId; } else { $query .= ' WHERE `subscriber_id` IN ( ' . $subsIds . ' ) AND `list_id` =' . $listId; } } $database->setQuery($query); if (!$database->query() and !empty($qid)) { queue::deleteQueues($qid); } $erro->err = $database->getErrorMsg(); $erro->E(__LINE__, '8532', $database); } return $erro->R(); }
function sendSchedule($d, $showHTML, $receivers, $list, &$message, &$max, $tags = null) { static $countEmails = 0; $mailing = $d['mailing']; $h = ''; $xf = new xonfig(); if (empty($mailing)) { $message = _ACA_NO_MAILING_ENTERED; return false; } elseif (empty($receivers)) { $message = _ACA_NO_ADDRESS_ENTERED; return false; } elseif (empty($list)) { $message = _ACA_NO_LIST_ENTERED; return false; } else { $message = ''; } $mailingId = $mailing->id; $issue_nb = $mailing->issue_nb; $subject = $mailing->subject; $content = $mailing->htmlcontent; $textonly = $mailing->textonly; $fromname = $mailing->fromname; $fromemail = $mailing->fromemail; $images = $mailing->images; $listId = $list->id; $html = $list->html; $layout = $list->layout; $totalsofar = number_format(0, 4, ',', ''); $nbPause = 0; $tags['issuenb'] = $issue_nb; //Just in case of... @ini_set('max_execution_time', 0); @ini_set('memory_limit', '128M'); ignore_user_abort(true); ### create the mail $mail = acajoom_mail::getMailer($mailing); ### create content acajoom_mail::getContent($images, $layout, $content, $textonly, true); $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; $html_sent = 0; $text_sent = 0; $size = sizeof($receivers); $format = defined('_DATE_FORMAT_LC') ? _DATE_FORMAT_LC : JText::_('DATE_FORMAT_LC'); $log_detailed = "\r\n" . "\r\n" . '*** ' . strftime($format) . ' ***' . "\r\n"; //variables used in integration of jLinks $mailCatID = null; $convertedLinks = null; foreach ($receivers as $receiver) { $tags['user_id'] = $receiver->user_id; if ($html && intval($receiver->receive_html) == 1) { $mail->IsHTML(true); $ashtml = 1; $Altbody = acajoom_mail::replaceTags($textonly, $receiver, $list, $mailingId, 0, $tags); $mail->AltBody = acajoom_mail::safe_utf8_encode($Altbody, $mail->CharSet); $html_sent++; $mail->Body = acajoom_mail::replaceTags($content, $receiver, $list, $mailingId, $ashtml, $tags); acajoom_mail::replaceClass($mail->Body, $mail->AltBody, $receiver); } else { $mail->IsHTML(false); $mail->AltBody = ''; $ashtml = 0; $text_sent++; $mail->Body = acajoom_mail::replaceTags($textonly, $receiver, $list, $mailingId, $ashtml, $tags); $simpleText = ''; acajoom_mail::replaceClass($mail->Body, $simpleText, $receiver); } $tname = explode(" ", $receiver->name); $firstname = $tname[0]; $toUser = $GLOBALS[ACA . 'minisendmail'] ? '' : $receiver->name; $mail->AddAddress($receiver->email, $toUser); if (!empty($receiver->id)) { $mail->addCustomHeader("X-SubscriberID: {$receiver->id}"); } $username = empty($receiver->username) ? $firstname : $receiver->username; $date = ACA_CMSTYPE ? JHTML::_('date', acajoom::getNow(), JText::_('DATE_FORMAT_LC1'), 0) : mosFormatDate(acajoom::getNow(), '', 0); $replaceWhat = array('[NAME]', '[FIRSTNAME]', '[USERNAME]', '[DATE]'); $replaceBy = array($receiver->name, $firstname, $username, $date); $sujetReplaced = str_replace($replaceWhat, $replaceBy, $subject); if (class_exists('auto')) { auto::tags($sujetReplaced, $tags); } $mail->Subject = $sujetReplaced; if ($GLOBALS[ACA . 'embed_images']) { acajoom_mail::embedImages($mail); } $mailssend = $mail->Send(); $countEmails++; if ($countEmails >= $GLOBALS[ACA . 'cron_max_emails']) { $max = true; } if (!$mailssend || $mail->error_count > 0) { static $info = false; if (!$info and acajoom::checkPermissions('admin')) { echo '<br/>Mailer Error : ' . $mail->ErrorInfo; echo " : Newsletter '{$sujetReplaced}' to {$receiver->email}"; $info = true; } $log_detailed .= '[' . $mailingId . '] ' . $subject . ' : ' . $receiver->email . ' -> ' . _ACA_MESSAGE_NOT . "\r\n" . _ACA_MAILER_ERROR . ': ' . $mail->ErrorInfo . "\r\n"; if ($html && intval($receiver->receive_html) == 1) { $html_sent--; } else { $text_sent--; } if (!subscribers::validEmail($receiver->email, true)) { $deleteQueue = array(); $deleteQueue[0] = queue::whatQID($mailingId, $receiver->id, $d['listype']); queue::deleteQueues($deleteQueue); } } else { $log_detailed .= '[' . $mailingId . '] ' . $subject . ' : ' . $receiver->email . ' -> ' . _ACA_MESSAGE_SENT_SUCCESSFULLY . "\r\n"; if ($GLOBALS[ACA . 'enable_statistics'] == 1 and $GLOBALS[ACA . 'statistics_per_subscriber'] == 1) { xmailing::insertStats($mailingId, $receiver->id, $ashtml); } $d['qids'] = array(); $erro = new xerr(__FILE__, __FUNCTION__, __CLASS__); if ($d['listype'] == '2') { $d['qids'][0] = queue::whatQID($mailingId, $receiver->id, $d['listype']); $erro->ck = auto::updateAutoresponderSent($d); $erro->Eck(__LINE__, '8137', $d); } elseif ($d['listype'] == '1' || $d['listype'] == '7') { $d['qids'][0] = queue::whatQID($mailingId, $receiver->id, $d['listype']); $erro->ck = queue::deleteQueues($d['qids']); $erro->Eck(__LINE__, '8127', $d); } } $mail->ClearAddresses(); } if ($GLOBALS[ACA . 'enable_statistics'] == 1) { xmailing::updateStatsGlobal($mailingId, $html_sent, $text_sent, false); } $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; if ($totalsofar > 0) { $totaltime = $totalsofar; $totalstr = strval($totaltime); } else { $totaltime = number_format($endtime - $starttime - $nbPause * $GLOBALS[ACA . 'pause_time'], 4, ',', ''); $totalstr = strval($totaltime); } $xf->plus('totalmailingsent' . $list->list_type, $html_sent + $text_sent); $xf->plus('totalmailingsent0', $html_sent + $text_sent); $log_simple = 'Time to send: ' . $totalstr . ' ' . _ACA_SECONDS . "\r\n" . 'Number of subscribers: ' . ($text_sent + $html_sent) . "\r\n" . 'HTML format: ' . $html_sent . "\r\n" . 'Text format: ' . $text_sent . "\r\n"; $log_detailed = $log_simple . 'Details: ' . "\r\n" . $log_detailed . "\r\n"; if (class_exists('lisType')) { acajoom_mail::writeLogs($list, $log_simple, $log_detailed); } if ($d['listype'] == '2') { echo '<br/>' . _ACA_QUEUE_AUTO_PROCESSED; } elseif ($d['listype'] == '1') { echo '<br/>' . _ACA_QUEUE_NEWS_PROCESSED; } if ($html_sent + $text_sent > 0) { return true; } else { $message = xmailing::M('no', _ACA_NO_MAILING_SENT); return false; } }
function updateQueues($subId, $qids, $listId, $acc_level, $new) { global $database; $erro = new xerr(__FILE__, __FUNCTION__, __CLASS__); $list = lists::getOneList($listId); if ($list->list_type == 1) { if ($new) { if (!empty($subId)) { $erro->ck = queue::insertQueuesForNews($subId, $listId, $acc_level); $erro->Eck(__LINE__, '8504'); } else { if (!empty($qids)) { $qid = implode(',', $qids); $query = 'SELECT `subscriber_id` FROM `#__acajoom_queue` WHERE `qid` IN ( ' . $qid . ' ) '; $database->setQuery($query); $subIds = $database->loadObjectList(); $erro->err = $database->getErrorMsg(); } foreach ($subIds as $v) { $subId[] = $v->subscriber_id; } $erro->ck = queue::insertQueuesForNews($subId, $listId, $acc_level); $erro->E(__LINE__, '8505'); } } else { if (!empty($subId)) { $erro->ck = queue::updateQueueData('', $subId, 0, $listId, 0, 0, 0, 0, $acc_level, 0); $erro->Eck(__LINE__, '8506'); } elseif (!empty($qids)) { $erro->ck = queue::updateQueueData($qids, '', 0, $listId, 0, 0, 0, 0, $acc_level, 0); $erro->Eck(__LINE__, '8507'); } } } elseif ($list->list_type == 7) { $newQueue->list_id = $list->id; $newQueue->mailing_id = 0; $newQueue->issue_nb = 0; $newQueue->send_date = 0; $newQueue->delay = 0; $newQueue->acc_level = $acc_level; $newQueue->published = $list->published; $erro->ck = autonews::insertQueuesForAutoNews($subId, $newQueue); $erro->Eck(__LINE__, '8508'); } else { if ($new) { if (!empty($subId)) { $mailingId = 0; $mailing = queue::getValidMailing($list, $mailingId); if (!empty($mailing)) { if (class_exists('auto')) { if ($mailing->list_type == 2) { $newQueue->list_id = $mailing->list_id; $newQueue->mailing_id = $mailing->id; $newQueue->issue_nb = $mailing->issue_nb; $newQueue->send_date = acajoom::getNow(); $newQueue->delay = $mailing->delay; $newQueue->acc_level = $acc_level; $newQueue->published = $list->published; $erro->ck = auto::insertQueuesForAuto($subId, $newQueue); $erro->Eck(__LINE__, '8508'); } else { $erro->ck = queue::insertQueuesForNews($subId, $mailing->list_id, $acc_level); $erro->Eck(__LINE__, '8509'); } } } else { if (class_exists('auto')) { $newQueue->list_id = $list->id; $newQueue->mailing_id = 0; $newQueue->issue_nb = 0; $newQueue->send_date = 0; $newQueue->delay = 0; $newQueue->acc_level = $acc_level; $newQueue->published = $list->published; $erro->ck = auto::insertQueuesForAuto($subId, $newQueue); $erro->Eck(__LINE__, '8510'); } } } elseif (!empty($qids)) { $mailingId = xmailing::getFirstMailingId($listId); if (!empty($mailingId)) { $mailing = queue::getValidMailing($list, $mailingId); if (!empty($mailing)) { if ($mailing->list_type == 2) { $subscribers = subscribers::getSubscribers(-1, -1, '', $total, $listId, '', 1, 1, ''); $subId = acajoom::convertObjectToIdList($subscribers, 'id'); if (!empty($subId)) { $erro->ck = queue::updateQueueData('', $subId, 1, $listId, $mailing->id, $mailing->issue_nb, 0, $mailing->delay, 0, 1); $erro->Eck(__LINE__, '8511'); } } else { $subscribers = subscribers::getSubscribers(-1, -1, '', $total, $listId, '', 1, 1, ''); $subId = acajoom::convertObjectToIdList($subscribers, 'id'); $erro->ck = queue::insertQueuesForNews($subId, $mailing->list_id, $acc_level); $erro->Eck(__LINE__, '8512'); } } } } } else { if (!empty($subId)) { $mailing = queue::getValidMailing($list, 0); if (!empty($mailing)) { $erro->ck = queue::updateQueueData('', $subId, $list->list_type, $listId, '', '', 0, '', 0, $list->published); } else { $erro->ck = queue::updateQueueData('', $subId, $mailing->list_type, $mailing->list_id, $mailing->id, $mailing->issue_nb, acajoom::getNow(), $mailing->delay, $acc_level, $mailing->published); } $erro->E(__LINE__, '8513'); } elseif (!empty($qids)) { $mailing = queue::getValidMailing($list, 0); if (!empty($mailing)) { if ($mailing->list_type == 2) { $erro->ck = queue::updateQueueData($qids, '', $list->list_type, $listId, $mailing->id, $mailing->issue_nb, acajoom::getNow(), $mailing->delay, 0, 1); $erro->E(__LINE__, '8514'); } else { $subId = acajoom::convertObjectToIdList($qids, 'subscriber_id'); $erro->ck = queue::deleteQueues($qids); $erro->Eck(__LINE__, '8515'); $erro->ck = queue::insertQueuesForNews($subId, $mailing->list_id, $acc_level); $erro->Eck(__LINE__, '8516'); } } } } } return $erro->R(); }