17 require_once dirname(__FILE__).
'/../../core/include/init.inc';
18 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
19 require_once
'Mail/Queue.php';
35 var $error_log_file_name =
'bulkmail_errors';
63 pcntl_signal(SIGTERM, Array(&$this,
'_sigHandler'));
64 pcntl_signal(SIGHUP, Array(&$this,
'_sigHandler'));
66 $am = $GLOBALS[
'SQ_SYSTEM']->am;
67 $bm = $am->getSystemAsset(
'bulkmail_manager');
70 $old_log_errors = ini_set(
'log_errors',
'1');
71 $old_error_log = ini_set(
'error_log', SQ_LOG_PATH.
'/'.$this->error_log_file_name.SQ_CONF_LOG_EXTENSION);
72 set_error_handler(Array(&$this,
'_errorHandler'));
75 $root_user = $am->getSystemAsset(
'root_user');
76 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
77 trigger_localised_error(
'BML0003', E_USER_WARNING, $root_user->name, $root_user->id);
82 $GLOBALS[
'min_mpm_threshold'] = 1;
83 $GLOBALS[
'max_mpm_threshold'] = 600;
86 $GLOBALS[
'sleep_threshold'] = 1800;
89 $GLOBALS[
'timeout_threshold'] = 3600;
92 $results = $bm->getQueuedJobs();
95 foreach ($results as $job_id => $info) {
96 if ($info[
'status'] == BML_JOB_STATE_RUNNING) {
97 $progress_info = $bm->getJobProgress($job_id);
100 if ($this->
checkThreshold(
'excluded_time', $info[
'details'][
'threshold'])) {
109 foreach ($results as $job_id => $info) {
110 if ($info[
'status'] == BML_JOB_STATE_NOT_RUNNING) {
112 if ($this->
checkThreshold(
'excluded_time', $info[
'details'][
'threshold'])) {
113 $bm->updateJob($job_id, BML_JOB_STATE_RUNNING);
133 $child_pid = pcntl_fork();
134 switch ($child_pid) {
136 trigger_localised_error(
'BML0004', E_USER_WARNING);
144 pcntl_waitpid(-1, $status);
162 $pid = $this->
fork();
166 $bm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'bulkmail_manager');
167 $info = $bm->getQueuedJobs($job_id);
168 $job_path = $bm->getJobDataPath($job_id);
170 $recipient_path = $job_path.
'/cache/recipient';
171 $progress_path = $job_path.
'/progress_info';
172 $recip_per_chunk = $this->
calculateChunkSize($info[$job_id][
'details'][
'threshold'], $progress_path);
173 $progress_info = Array();
174 if (file_exists($progress_path)) {
175 include $progress_path;
177 trigger_localised_error(
'BML0009', E_USER_WARNING, $progress_path);
181 if (!is_dir($recipient_path)) {
182 $result = $this->
getAllRecipients($info[$job_id][
'details'][
'content_id'], $info[$job_id][
'details'][
'recipients']);
184 $progress_info[
'total_count'] = count($result[
'recipient']);
185 $progress_info[
'problematic'] = $result[
'problematic'];
186 if (!array_to_file($progress_info,
'progress_info', $progress_path)) {
187 trigger_localised_error(
'BML0008', E_USER_WARNING, $progress_path);
191 create_directory($recipient_path);
192 $chunks = array_chunk($result[
'recipient'], $recip_per_chunk, TRUE);
193 foreach ($chunks as $index => $chunk) {
194 if (!array_to_file($chunk,
'recipient_chunk', $recipient_path.
'/recipient_'.$index)) {
195 trigger_localised_error(
'BML0008', E_USER_WARNING, $recipient_path.
'/recipient_'.$index);
215 $am = $GLOBALS[
'SQ_SYSTEM']->am;
216 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
218 $bm = $am->getSystemAsset(
'bulkmail_manager');
219 $info = $bm->getQueuedJobs($job_id);
220 $job_path = $bm->getJobDataPath($job_id);
221 $progress_path = $job_path.
'/progress_info';
222 $recipient_path = $job_path.
'/cache/recipient';
225 $progress_info = $info[$job_id][
'progress'];
226 $details = $info[$job_id][
'details'];
227 $header_details = $details[
'header_details'];
228 $header_details[
'from'] = $details[
'from'];
230 require_once SQ_FUDGE_PATH.
'/general/text.inc';
231 $keywords = retrieve_keywords_replacements($details[
'subject']);
232 $replacements = Array();
233 $content_asset = $am->getAsset($details[
'content_id']);
235 $details[
'search_page'] = NULL;
236 $details[
'user_subscriptions'] = NULL;
238 if ((get_class($content_asset) ==
'Search_Page') && !$details[
'user_subscriptions_status']) {
239 trigger_localised_error(
'BML0020', E_USER_WARNING);
241 }
else if ((get_class($content_asset) !=
'Search_Page') && $details[
'user_subscriptions_status']) {
242 trigger_localised_error(
'BML0021', E_USER_WARNING);
244 }
else if ((get_class($content_asset) ==
'Search_Page') && $details[
'user_subscriptions_status'] && empty($details[
'subscriptions'])) {
245 trigger_localised_error(
'BML0023', E_USER_WARNING);
247 }
else if ((get_class($content_asset) ==
'Search_Page') && $details[
'user_subscriptions_status']) {
249 $details[
'search_page'] = $content_asset;
250 $details[
'user_subscriptions'] = $details[
'subscriptions'];
255 if (!empty($content_asset->charset)) {
256 $content_charset = $content_asset->charset;
258 $content_charset = SQ_CONF_DEFAULT_CHARACTER_SET;
262 'head_charset' => $content_charset,
263 'text_charset' => $content_charset,
264 'html_charset' => $content_charset,
267 foreach ($keywords as $word) {
268 if (0 === strpos($word,
'recipient_')) {
270 $replacements[$word] =
"%$word%";
272 $replacements[$word] = $content_asset->getKeywordReplacement($word);
275 $am->forgetAsset($content_asset);
277 replace_keywords($details[
'subject'], $replacements);
278 $header_details[
'subject'] = $details[
'subject'];
281 $queue_path = $details[
'queue_details'][
'dir'];
282 $sent_path = $queue_path.
'/sent';
283 if (!is_dir($sent_path)) create_directory($sent_path);
285 $GLOBALS[
'chunk_start'] = get_microtime();
288 while (file_exists($recipient_path.
'/recipient_'.$progress_info[
'current_chunk'])) {
291 if (!isset($info[$job_id])) {
295 $state = $info[$job_id][
'status'];
296 if ($state == BML_JOB_STATE_PAUSED) {
299 }
else if ($state == BML_JOB_STATE_NOT_RUNNING) {
306 if (!$this->
checkThreshold(
'excluded_time', $details[
'threshold'])) {
308 $bm->updateJob($job_id, BML_JOB_STATE_NOT_RUNNING);
313 include($recipient_path.
'/recipient_'.$progress_info[
'current_chunk']);
315 $pid = $this->
fork();
318 $mime =
new Mail_mime(
"\n");
319 $mail_queue =
new Mail_Queue($details[
'queue_details'], $details[
'server_details']);
321 if (strpos($job_id,
':') === FALSE) {
322 $job = $am->getAsset($job_id);
323 $current_post_office = $job->getPostOffice();
325 $job = $current_post_office = NULL;
328 if ($details[
'content_text_only']) {
329 unset($details[
'content_design']);
330 unset($details[
'content_layout']);
333 foreach ($recipient_chunk as $r_info) {
335 $user_id = $r_info[
'assetid'];
336 $email = $r_info[
'custom_val'];
337 $user = $am->getAsset($user_id,
'', TRUE);
346 if ((is_string($email) && (trim($email) ==
'')) || ($email != trim($email) || !valid_email($email))
347 || (is_array($email) && (trim($email[
'email']) ==
'')) || (array_get_index($email,
'email', FALSE) && ($email[
'email'] != trim($email[
'email']) || !valid_email($email[
'email'])))) {
355 if (!file_exists($queue_path.
'/'.$id) && !file_exists($sent_path.
'/'.$id)) {
357 $pid = $this->
fork();
362 if (!is_null($details[
'search_page']) && !is_null($details[
'user_subscriptions'])) {
363 $search_asset_list = Array();
364 $user_metadata = NULL;
366 if (!is_null($user)) {
367 foreach ($details[
'user_subscriptions'] as $sub_name => $sub_info) {
368 $matches[$sub_name] = Array();
369 foreach ($sub_info as $index => $info) {
371 $category_type = array_keys($info);
372 $user_metadata = $mm->getMetadataValueByAssetid($user->id, $info[$category_type[0]][
'assetid']);
373 $metadata_field= $GLOBALS[
'SQ_SYSTEM']->am->getAsset($info[$category_type[0]][
'assetid']);
374 $rule_text = $info[$category_type[0]][
'rule_text'];
375 $old_frontend_asset = $GLOBALS[
'SQ_SYSTEM']->frontend_asset;
377 $GLOBALS[
'SQ_SYSTEM']->frontend_asset = $job;
378 $GLOBALS[
'SQ_SYSTEM']->replaceKeyword($rule_text);
379 $GLOBALS[
'SQ_SYSTEM']->frontend_asset = $old_frontend_asset;
381 if ($info[$category_type[0]][
'rule_cond'] ==
'contains') {
383 $rule_text_array = explode(
';', $rule_text);
385 foreach ($rule_text_array as $individial_text) {
386 $match = (stripos($user_metadata, trim($individial_text)) !== FALSE);
390 $match = (stripos($user_metadata, $rule_text) !== FALSE);
394 $match = (strtolower($user_metadata) == strtolower($rule_text));
397 if ($match && !in_array($user_metadata, $matches[$sub_name])) {
399 $matches[$sub_name] = explode(
'\;', $user_metadata);
401 $matches[$sub_name][] = $user_metadata;
412 $user = $am->getAsset($details[
'content_gen_as']);
415 $GLOBALS[
'SQ_SYSTEM']->setCurrentUser($user);
416 $old_get_vars = $_GET;
418 $_GET = $good_query = Array();
419 foreach ($matches as $get_var => $strings_to_srch) {
420 foreach ($strings_to_srch as $srch_string) {
421 $_REQUEST[
'mode'] =
'results';
422 $_GET[$get_var] = $srch_string;
423 $search_vars = $content_asset->processSearchVars();
427 $search_res = $content_asset->processSearch($search_vars);
429 unset($_GET[$get_var]);
430 if (!empty($search_res)) {
431 $good_query[$get_var][] = $srch_string;
440 if (!empty($_GET)) $search_result .= $this->
generateContent($details, $job_path, $user_id, $email);
444 $_GET = $old_get_vars;
445 $GLOBALS[
'SQ_SYSTEM']->restoreCurrentUser();
447 $details[
'content_id'] = NULL;
448 $details[
'search_content'] = $search_result;
452 if (empty($details)) $this->
updateProgress($progress_path, $user_id, $problematic, $filtered);
454 if (!isset($details[
'search_content'])) {
455 $content = $this->
generateContent($details, $job_path, $user_id, $email);
457 $content = $details[
'search_content'];
459 $text_only_content = html_entity_decode(strip_tags($content));
464 if (array_get_index($details,
'content_body_filter')) {
465 $match = array_get_index($details,
'content_body_filter_match', TRUE);
466 $filter_text = array_get_index($details,
'content_body_filter_text',
'');
468 if (!empty($filter_text)) {
469 $target_content = ($details[
'content_text_only'] ? $text_only_content : $content);
470 $ok = (strpos($target_content, $filter_text) !== FALSE);
471 if ($ok != $match) $filtered = TRUE;
475 if (is_array($email)) {
478 $user = $am->getAsset($user_id);
483 $search_content_empty = FALSE;
484 if (empty($content) && isset($details[
'search_content'])) {
485 $search_content_empty = TRUE;
486 }
else if (empty($content)) {
490 if (!$problematic && !$filtered && !$search_content_empty) {
492 if (is_array($email)) $email = $email[
'email'];
496 $mime->setTxtBody($text_only_content);
497 if (!$details[
'content_text_only']) {
498 $mime->setHTMLBody($content);
501 $body = @$mime->get($mime_param);
503 $header_details[
'custom_id'] = $user_id;
504 $header_details[
'To'] = $email;
506 if (!is_null($current_post_office) && $current_post_office->attr(
'bulkmail_mode') ==
'test') {
508 $message_type =
'bulkmail.job.testmode';
510 'from' => $header_details[
'from'],
511 'to' => $header_details[
'To'],
512 'subject' => $header_details[
'subject'],
514 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
515 $message = $ms->newMessage(Array(), $message_type, $msg_reps);
516 $message->parameters[
'assetid'] = $job_id;
519 $am->forgetAsset($message);
520 $am->forgetAsset($ms);
522 $headers = @$mime->headers($header_details);
523 $mail_id = $mail_queue->put(
'', $email, $headers, $body);
526 $this->
updateProgress($progress_path, $user_id, $problematic, $filtered);
535 if (!is_null($job)) $am->forgetAsset($job);
536 if (!is_null($current_post_office)) $am->forgetAsset($current_post_office);
538 $status = $mail_queue->sendMailsInQueue();
539 }
catch (Exception $e) {
540 trigger_localised_error(
'BML0001', E_USER_WARNING, $e->getMessage());
545 if ($status instanceof PEAR_Error) {
546 trigger_localised_error(
'BML0001', E_USER_WARNING, $status->getMessage());
557 $progress_info = $bm->getJobProgress($job_id);
558 $info = $bm->getQueuedJobs($job_id);
565 $progress_info = $bm->getJobProgress($job_id);
566 if ($progress_info[
'current_count'] >= $progress_info[
'total_count']) {
567 if (strpos($job_id,
':') === FALSE) {
568 $job = $am->getAsset($job_id);
569 $current_post_office = $job->getPostOffice();
571 $job = $current_post_office = NULL;
575 $bm->deleteJob($job_id);
578 $job_id_parts = explode(
':', $job_id);
579 if (!isset($job_id_parts[1])) {
581 if (!is_null($current_post_office) && $current_post_office->attr(
'bulkmail_mode') ==
'test') {
582 $message_type =
'bulkmail.job.testmode.completed';
584 'num_recip' => number_format($progress_info[
'total_count']),
585 'num_problem' => number_format(count($progress_info[
'problematic'])),
586 'num_filtered' => isset($progress_info[
'filtered']) ? number_format(count($progress_info[
'filtered'])) : 0,
590 if (count($progress_info[
'problematic']) > 0) {
591 trigger_localised_error(
'BML0010', E_USER_WARNING, implode(
',', $progress_info[
'problematic']));
595 if (isset($progress_info[
'filtered']) && (count($progress_info[
'filtered']) > 0)) {
596 trigger_localised_error(
'BML0019', E_USER_WARNING, implode(
',', $progress_info[
'filtered']));
597 if (empty($subtype)) {
598 $subtype =
'.filtered';
600 $subtype =
'+filtered';
604 $message_type =
'bulkmail.job.completed'.$subtype;
608 'num_recip' => number_format($progress_info[
'total_count']),
609 'num_problem' => number_format(count($progress_info[
'problematic'])),
610 'num_filtered' => isset($progress_info[
'filtered']) ? number_format(count($progress_info[
'filtered'])) : 0,
615 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
616 $message = $ms->newMessage(Array(), $message_type, $msg_reps);
617 $message->parameters[
'assetid'] = $job_id;
619 $am->forgetAsset($message);
620 $am->forgetAsset($ms);
622 if (!is_null($job)) $am->forgetAsset($job);
623 if (!is_null($current_post_office)) $am->forgetAsset($current_post_office);
643 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection(TRUE);
645 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2', TRUE);
647 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection(TRUE);
649 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'dbsearch', TRUE);
671 $progress_info = Array();
672 if (file_exists($progress_path)) {
673 include $progress_path;
675 trigger_localised_error(
'BML0009', E_USER_WARNING, $progress_path);
680 $progress_info[
'total_count']--;
681 $progress_info[
'problematic'][] = $user_id;
682 }
else if ($filtered) {
683 $progress_info[
'total_count']--;
684 $progress_info[
'filtered'][] = $user_id;
686 $progress_info[
'current_count']++;
688 $progress_info[
'current_recip_id'] = $user_id;
689 $progress_info[
'last_updated'] = time();
691 if (!array_to_file($progress_info,
'progress_info', $progress_path)) {
692 trigger_localised_error(
'BML0008', E_USER_WARNING, $progress_path);
711 $progress_info = Array();
712 if (file_exists($progress_path)) {
713 include $progress_path;
715 trigger_localised_error(
'BML0009', E_USER_WARNING, $progress_path);
719 $progress_info[
'current_chunk']++;
721 if (!$progress_info[
'time_per_chunk']) {
722 $progress_info[
'time_per_chunk'] = get_microtime() - $GLOBALS[
'chunk_start'];
725 if (!array_to_file($progress_info,
'progress_info', $progress_path)) {
726 trigger_localised_error(
'BML0008', E_USER_WARNING, $progress_path);
753 $am = $GLOBALS[
'SQ_SYSTEM']->am;
755 if (!is_array($recipients)) {
756 $recipients = Array($recipients);
759 $asset_to_send = $am->getAsset($asset_to_send_id);
760 $recipients_expanded = Array();
761 $problematic_list = Array();
763 foreach ($recipients as $recipient_key => $recipient_id) {
765 if (isset($recipient_id[
'email']) && preg_match(
'/(.*)\@(.*)/is', $recipient_id[
'email'])) {
766 $recipients_expanded[$recipient_key] = $recipients[$recipient_key];
769 $recipient = $am->getAsset($recipient_id);
775 if ($recipient->type() ==
'search_folder') {
776 $map_links = $recipient->getAssetMapLinks();
777 foreach ($map_links as $map_link) {
779 $all_user_types = Array();
780 $user_types = $am->getTypeDescendants(
'user', TRUE);
781 $bulkmail_user_types = $am->getTypeDescendants(
'bulkmail_user', TRUE);
782 $all_user_types = array_merge($user_types, $bulkmail_user_types);
783 if (in_array($map_link[
'type_code'], $all_user_types)) {
784 $id_parts = explode(
':', $map_link[
'assetid']);
786 if (isset($id_parts[1])) {
787 $link_assetid = $id_parts[1];
788 $recipients_expanded[$link_assetid] = $map_link[
'type_code'];
793 $recipients_expanded += $am->getChildren($recipient->id,
'user', FALSE, FALSE);
794 $recipients_expanded += $am->getChildren($recipient->id,
'bulkmail_user', FALSE, FALSE);
798 $recipients_expanded[$recipient->id] = $recipient->type();
801 $am->forgetAsset($recipient);
806 $recipients = Array();
807 $recipients_query = Array();
808 $permission_denied = $am->getPermission($asset_to_send_id, SQ_PERMISSION_READ, FALSE, FALSE);
809 $public_user = $am->getSystemAsset(
'public_user');
810 $public_user_id = $public_user->id;
811 for ($recipients_expanded; NULL != ($recipient_id = key($recipients_expanded)); next($recipients_expanded)) {
813 if (!in_array($recipient_id, $permission_denied) && (!is_array($recipients_expanded[$recipient_id]) || !array_key_exists(
'email',$recipients_expanded[$recipient_id]))) {
815 $recipient_id_parts = explode(
':', $recipient_id);
816 if (isset($recipient_id_parts[1])) {
817 $recipient = $am->getAsset($recipient_id);
819 if ($recipient instanceof
User) {
820 $recipients[] = Array(
821 'assetid' => $recipient->id,
822 'custom_val' => $recipient->attr(
'email'),
825 $am->forgetAsset($recipient);
828 $recipients_query[] = $recipient_id;
830 }
else if (!in_array($public_user_id, $permission_denied)) {
832 if (isset($recipients_expanded[$recipient_id][
'email']) && preg_match(
'/(.*)\@(.*)/is', $recipients_expanded[$recipient_id][
'email'])) {
834 $recipients[] = Array(
835 'assetid' => $recipient_id,
836 'custom_val' => Array(
837 'first_name' => $recipients_expanded[$recipient_id][
'first_name'],
838 'last_name' => $recipients_expanded[$recipient_id][
'last_name'],
839 'email' => $recipients_expanded[$recipient_id][
'email'],
845 $problematic_list[] = $recipient_id;
849 $query_results = Array();
850 if (!empty($recipients_query)) {
852 $recipients_query = array_unique($recipients_query);
857 $recipient_chunks = array_chunk($recipients_query, $chunk_size, TRUE);
859 foreach ($recipient_chunks as $recipient_chunk) {
861 $bind_vars[
'recipient_list'] = $recipient_chunk;
862 $bind_vars[
'contextid'] = $GLOBALS[
'SQ_SYSTEM']->getContextId();
864 $query_results = array_merge($query_results, $query_result);
865 }
catch (Exception $e) {
866 throw new Exception(
'Unable to get recipient list due to database error: '.$e->getMessage());
871 $recipients = array_merge($recipients, $query_results);
872 $result[
'recipient'] = $recipients;
873 $result[
'problematic'] = $problematic_list;
897 public function generateContent($job_details, $job_path, $recipient_id=NULL, $email=NULL)
900 $am = $GLOBALS[
'SQ_SYSTEM']->am;
901 if (isset($job_details[
'content_id']) && $job_details[
'content_id']) {
902 $content_asset = $am->getAsset($job_details[
'content_id']);
903 $GLOBALS[
'SQ_SYSTEM']->frontend_asset = &$content_asset;
905 $am->forgetAsset($content_asset);
908 if (!empty($recipient_id)) {
909 if (!is_null($email) && is_array($email)) {
910 $recipient = Array($recipient_id => $email);
912 $recipient = $am->getAsset($recipient_id);
915 $recipient = $GLOBALS[
'SQ_SYSTEM']->user;
919 if (isset($job_details[
'job_id']) && !empty($job_details[
'job_id'])) {
920 $job = $am->getAsset($job_details[
'job_id']);
925 if (($job_details[
'content_gen'] ==
'one_user') || ($recipient instanceof
Bulkmail_User)) {
929 if ((file_exists($job_path.
'/cache/content_file_'.$job_details[
'content_id'].
'.html')) && !empty($recipient_id)) {
931 $content = file_to_string($job_path.
'/cache/content_file_'.$job_details[
'content_id'].
'.html');
936 $generator_user = $am->getAsset($job_details[
'content_gen_as']);
937 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($generator_user)) {
938 trigger_localised_error(
'BML0017', E_USER_WARNING);
946 $content = $job->generateRawContent($job_details, $recipient);
950 $GLOBALS[
'SQ_SYSTEM']->restoreCurrentUser();
953 if (!empty($recipient_id) || !($recipient instanceof Bulkmail_User)) {
954 string_to_file($content, $job_path.
'/cache/content_file_'.$job_details[
'content_id'].
'.html');
964 if (is_array($recipient)) {
969 $content = $job->generateRawContent($job_details, $recipient);
977 if (!empty($recipient_id)) {
978 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($recipient)) {
979 trigger_localised_error(
'BML0017', E_USER_WARNING);
988 $content = $job->generateRawContent($job_details, $recipient);
992 if (!empty($recipient_id)) {
993 $GLOBALS[
'SQ_SYSTEM']->restoreCurrentUser();
1015 return $GLOBALS[
'SQ_SYSTEM']->am->generateRawContent($details);
1033 require_once SQ_FUDGE_PATH.
'/general/text.inc';
1035 $keywords = retrieve_keywords_replacements($content);
1036 $keyword_replacements = Array();
1037 foreach ($keywords as $word) {
1038 if (0 === strpos($word,
'recipient_')) {
1039 $user_keyword = substr($word, 10);
1040 if (is_array($user)) {
1042 foreach ($user as $user_login => $user_details) {
1043 if ($user_keyword ==
'login') {
1044 $keyword_replacements[$word] = $user_login;
1045 }
else if (isset($user_details[$user_keyword])) {
1046 $keyword_replacements[$word] = $user_details[$user_keyword];
1048 $keyword_replacements[$word] =
"%$word%";
1052 $user_replacement = $user->getKeywordReplacement($user_keyword);
1053 if ($user_replacement ==
"%$user_keyword%") {
1055 $keyword_replacements[$word] =
"%$word%";
1057 $keyword_replacements[$word] = $user_replacement;
1061 $keyword_replacements[$word] =
'';
1064 require_once SQ_INCLUDE_PATH.
'/general.inc';
1065 replace_global_keywords($content);
1066 replace_keywords($content, $keyword_replacements);
1087 foreach ($thresholds as $threshold) {
1088 if ($threshold[
'type'] == translate(
'bulkmail_threshold_rule_send_rate')) {
1089 $value = $threshold[
'params'][
'value'];
1090 $unit = $threshold[
'params'][
'unit'];
1091 $mpm = ceil(($value/$unit) * 60);
1093 if ($mpm < $GLOBALS[
'min_mpm_threshold'] || $mpm > $GLOBALS[
'max_mpm_threshold']) {
1100 $bm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'bulkmail_manager');
1101 $mpm = $bm->attr(
'chunk_size');
1105 $progress_info = Array();
1106 if (file_exists($progress_path)) {
1107 include $progress_path;
1109 trigger_localised_error(
'BML0009', E_USER_WARNING, $progress_path);
1111 $progress_info[
'mpm'] = $mpm;
1112 if (!array_to_file($progress_info,
'progress_info', $progress_path)) {
1113 trigger_localised_error(
'BML0008', E_USER_WARNING, $progress_path);
1132 $progress_info = Array();
1133 if (file_exists($progress_path)) {
1134 include $progress_path;
1136 trigger_localised_error(
'BML0009', E_USER_WARNING, $progress_path);
1139 if (!isset($progress_info[
'mpm'])) {
1145 if (($progress_info[
'time_per_chunk'] != 0) && (!isset($progress_info[
'sleep_time']))) {
1146 $time_diff = 60 - $progress_info[
'time_per_chunk'];
1147 $progress_info[
'sleep_time'] = -1;
1148 if ($time_diff > 0) {
1151 $progress_info[
'sleep_time'] = ($time_diff/$chunk_size) * 1000000;
1153 usleep($progress_info[
'sleep_time'] * $chunk_size);
1157 if (!array_to_file($progress_info,
'progress_info', $progress_path)) {
1158 trigger_localised_error(
'BML0008', E_USER_WARNING, $progress_path);
1163 if (isset($progress_info[
'sleep_time']) && ($progress_info[
'sleep_time'] != -1)) {
1164 usleep($progress_info[
'sleep_time']);
1185 case 'excluded_time' :
1188 case 'wakeup_time' :
1189 return $this->checkWakeUpTime($thresholds, $extra);
1213 $days_array = Array(
1223 foreach ($thresholds as $threshold) {
1224 if ($threshold[
'type'] == translate(
'bulkmail_threshold_rule_excluded_time')) {
1225 $excluded_days = Array();
1226 foreach ($threshold[
'params'][
'days'] as $excluded_day) {
1227 $excluded_days[] = $days_array[$excluded_day];
1229 $now_day = date(
'D', time());
1230 $now_time = date(
'G', time());
1231 if (in_array($now_day, $excluded_days)) {
1233 if ($now_time >= $threshold[
'params'][
'from'] && (($threshold[
'params'][
'to'] < $threshold[
'params'][
'from']) || ($now_time < $threshold[
'params'][
'to']))) {
1236 }
else if ($threshold[
'params'][
'from'] > $threshold[
'params'][
'to']) {
1238 $yesterday_day = date(
'D', time()-86400);
1239 if (in_array($yesterday_day, $excluded_days)) {
1240 if ($now_time < $threshold[
'params'][
'to']) {
1263 if (isset($progress_info[
'last_updated']) && ($progress_info[
'last_updated'] != 0)) {
1264 $time_diff = time() - $progress_info[
'last_updated'];
1266 if ($time_diff > $GLOBALS[
'timeout_threshold']) {
1314 $terminate = ((E_USER_ERROR | E_ERROR) & $err_no);
1318 if ((error_reporting() & $err_no) || $terminate) {
1320 $bt = debug_backtrace();
1321 if (count($bt) > 1) {
1324 while (($real_bt_index < count($bt)-1) && ((FALSE !== strpos(array_get_index($bt[$real_bt_index],
'class'),
'locale_manager')) || (FALSE !== strpos(array_get_index($bt[$real_bt_index],
'file'),
'locale_manager')) || ($bt[$real_bt_index][
'function'] ==
'_errorhandler'))) {
1327 if (isset($bt[$real_bt_index][
'file'])) {
1328 $err_file = hide_system_root($bt[$real_bt_index][
'file']);
1330 if (isset($bt[$real_bt_index][
'line'])) {
1331 $err_line = $bt[$real_bt_index][
'line'];
1333 $err_msg = hide_system_root($err_msg);
1336 $text_msg = strip_tags(preg_replace(Array(
'/<br\\/?>/i',
'/<p[^>]*>/i'), Array(
"\n",
"\n\n"), $err_msg));
1339 if (ini_get(
'log_errors')) {
1340 log_error($text_msg, $err_no, $err_file, $err_line, $this->error_log_file_name);
1345 if ($terminate) exit(1);