Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cron_hook() {
- global $wpdb, $Db, $Email, $History, $Subscriber, $SubscribersList, $Queue;
- $emailssent = 0;
- //update scheduling
- $this -> scheduling();
- $this -> autoresponders_hook();
- //ensure that scheduling has been turned on
- if ($this -> get_option('scheduling') == "Y") {
- $emailsperinterval = $this -> get_option('emailsperinterval');
- $emailsquery = "SELECT * FROM " . $wpdb -> prefix . $Queue -> table . " WHERE `senddate` < '" . date("Y-m-d H:i:s", time()) . "' LIMIT " . $emailsperinterval . "";
- //retrieve all the queue emails for this execution
- if ($emails = $wpdb -> get_results($emailsquery)) {
- //if ($emails = $Queue -> find_all(false, false, false, $emailsperinterval)) {
- //send an email notification to the administrator if specified
- if ($this -> get_option('schedulenotify') == "Y" && $this -> get_option('scheduling') == "Y") {
- $subscriber_id = $Subscriber -> admin_subscriber_id($_POST['mailinglists']);
- $subscriber = $Subscriber -> get($subscriber_id, false);
- $subject = $this -> et_subject('schedule', $subscriber);
- $fullbody = $this -> et_message('schedule', $subscriber);
- $message = $this -> render_email(false, array('subscriber' => $subscriber, 'mailinglist' => $mailinglist), false, $this -> htmltf($subscriber -> format), true, $this -> default_theme_id(), false, $fullbody);
- $this -> execute_mail($subscriber, $subject, $message, false, false, false, false);
- }
- $subscriber = false;
- $subscriberids = array();
- $subscriberemails = array();
- $emailssent = 0;
- foreach ($emails as $email) {
- $this -> remove_server_limits();
- $historyquery = "SELECT `post_id` FROM `" . $wpdb -> prefix . $History -> table . "` WHERE `id` = '" . $email -> history_id . "'";
- if ($history_post_id = $wpdb -> get_var($historyquery)) {
- if ($getpost = get_post($history_post_id)) {
- global $post;
- $post = $getpost;
- }
- }
- if ($subscriber = $Subscriber -> get($email -> subscriber_id, false)) {
- $subscriber -> mailinglist_id = $email -> mailinglist_id;
- $subscriber -> mailinglists = $email -> mailinglists;
- $eunique = md5($subscriber -> id . $subscriber -> mailinglist_id . $email -> history_id . date("YmdH", time()));
- $checkemailquery = "SELECT `id` FROM `" . $wpdb -> prefix . $Email -> table . "` WHERE `eunique` = '" . $eunique . "' AND `history_id` = '" . $email -> history_id . "'";
- if (!$wpdb -> get_var($checkemailquery)) {
- if (empty($subscriberids) || (!empty($subscriberids) && !in_array($subscriber -> id, $subscriberids))) {
- $subscriberids[] = $subscriber -> id;
- if ((empty($subscriberemails[$email -> history_id])) || (!empty($subscriberemails[$email -> history_id]) && !in_array($subscriber -> email, $subscriberemails[$email -> history_id]))) {
- $subscriberemails[$email -> history_id][] = $subscriber -> email;
- $Db -> model = $Email -> model;
- $message = $this -> render_email('send', array('message' => $email -> message, 'subject' => $email -> subject, 'subscriber' => $subscriber, 'history_id' => $email -> history_id, 'post_id' => $email -> post_id, 'eunique' => $eunique), false, $this -> htmltf($subscriber -> format), true, $email -> theme_id);
- if ($this -> execute_mail($subscriber, $email -> subject, $message, $email -> attachments, $email -> history_id, $eunique)) {
- $Queue -> delete($email -> id);
- $emailssent++;
- }
- }
- }
- }
- } else {
- $Queue -> delete($email -> id);
- }
- $subscriber = array();
- }
- }
- }
- //update the "lastcron" setting
- $this -> update_option('lastcron', time());
- echo $emailssent . " " . __('emails have been sent out', $this -> plugin_name);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement