Пример #1
0
function mailmanager_check_series_queue()
{
    $mm_action = $_GET['mm_action'];
    if ($mm_action) {
        echo __('The MM Check Series Queue is being manually run', 'ym_mailmanager') . '<br />';
    }
    global $wpdb;
    // contains a element with target email_id
    $emails_to_send = array();
    //get series
    $sql = 'SELECT id, recipient_list FROM ' . $wpdb->prefix . 'mm_series WHERE enabled = 1';
    foreach ($wpdb->get_results($sql) as $row) {
        //get target users
        if ($sql = mailmanager_get_sql($row->recipient_list)) {
            if ($users = $wpdb->get_results($sql)) {
                foreach ($users as $i => $user) {
                    if ($mm_action) {
                        echo '<br />' . __('Found', 'ym_mailmanager') . ' ' . $user->email;
                    }
                    //add users not in table
                    $user_id = mailmanager_get_user_id($user->email);
                    // when did user join series
                    $user_join = mailmanager_get_user_in_series($user_id, $row->id, $row->recipient_list);
                    if ($user_join) {
                        if ($mm_action) {
                            echo ' ' . __('user is subscribed', 'ym_mailmanager');
                        }
                        // get what has been sent to this users
                        $sql = 'SELECT email_id FROM ' . $wpdb->prefix . 'mm_email_sent WHERE user_id = ' . $user_id;
                        $ignore = array();
                        foreach ($wpdb->get_results($sql) as $sent) {
                            $ignore[] = $sent->email_id;
                        }
                        // series emails
                        $sql = 'SELECT email_id, delay_days FROM ' . $wpdb->prefix . 'mm_email_in_series WHERE series_id = ' . $row->id;
                        $emails = array();
                        $one_day = 86400;
                        foreach ($wpdb->get_results($sql) as $email) {
                            $offset = $email->delay_days * $one_day;
                            $send_email = $user_join + $offset;
                            // already sent this email id?
                            if (!in_array($email->email_id, $ignore)) {
                                // check if need senting
                                if ($send_email <= time()) {
                                    $emails[] = $email->email_id;
                                }
                            }
                        }
                        // emails now contains the emails in this series that are due to be sent
                        // in theory this should only be a array of size 1
                        // depends how many emails of day delay 0 there are
                        foreach ($emails as $email_id) {
                            if ($mm_action) {
                                echo ' ' . __('sending EID:', 'ym_mailmanager') . $email_id;
                            }
                            list($subject, $body) = mailmanager_process_hooks($email_id, $row->id, $user_id);
                            mailmanager_send_email($user->email, $subject, $body);
                            mailmanager_log_email_send($user_id, $email_id);
                        }
                    }
                }
            }
        }
    }
}
Пример #2
0
<?php

$passed_id = isset($passed_id) ? $passed_id : 0;
$email_id = ym_get('mm_eid');
$iframe_id = ym_get('iframe_preview');
global $mm, $wpdb;
if ($email_id || $passed_id) {
    ym_box_top(__('Message Preview', 'ym_mailmanager'));
    echo '<div style="width: 900px;"><iframe src="' . $mm->page_root . '&mm_action=preview&iframe_preview=' . ($passed_id ? $passed_id : $email_id) . '" style="width: 100%; height: 400px;" /></div>';
    ym_box_bottom();
} else {
    if ($iframe_id) {
        do_action('mailmanager_email_preview', $iframe_id);
        if (defined('STOP_PREVIEW')) {
            return;
        }
        $sql = 'SELECT * FROM ' . $wpdb->prefix . 'mm_email WHERE id = ' . $iframe_id;
        $r = $wpdb->get_row($sql);
        get_currentuserinfo();
        global $current_user;
        list($subject, $body) = mailmanager_process_hooks($iframe_id, false, $current_user->ID);
        echo '<pre>' . $body . '</pre>';
        exit;
    }
}