コード例 #1
0
ファイル: sola-newsletters.php プロジェクト: jekv/devia
function sola_nl_action_callback()
{
    global $wpdb;
    global $sola_nl_camp_tbl;
    global $sola_nl_camp_subs_tbl;
    $check = check_ajax_referer('sola_nl', 'security');
    if ($check == 1) {
        if ($_POST['action'] == "get_perc") {
            if (isset($_POST['camp_id'])) {
                $camp_id = $_POST['camp_id'];
            } else {
                return false;
            }
            $sql = "SELECT COUNT(`id`) as `total` FROM `{$sola_nl_camp_subs_tbl}` WHERE `camp_id` = '{$camp_id}'";
            $sdf = $wpdb->get_row($sql);
            $total_subscribers = $sdf->total;
            $sql = "SELECT COUNT(`id`) as `total` FROM `{$sola_nl_camp_subs_tbl}` WHERE `camp_id` = '{$camp_id}' AND `status` >= 1";
            $sdf = $wpdb->get_row($sql);
            $total_sent = $sdf->total;
            $sent_perc = round($total_sent / $total_subscribers * 100, 0);
            $temp_array[] = $sent_perc;
            $sql = "SELECT `last_sent` FROM `{$sola_nl_camp_tbl}` WHERE `camp_id` = '{$camp_id}' LIMIT 1";
            $sdf = $wpdb->get_row($sql);
            if ($sdf->last_sent == "0000-00-00 00:00:00") {
                $time_next = __("Pending first batch", "sola");
            } else {
                $last_sent = strtotime($sdf->last_sent);
                $time_interval = get_option("sola_nl_send_limit_time");
                $time_next = $last_sent + $time_interval - time();
                $orig_time_next = $time_next;
                if ($time_next <= 0) {
                    $time_next = __("Sending again in about ", "sola") . '0' . __(" minute(s)", "sola");
                } else {
                    $time_next = __("Sending again in about ", "sola") . ceil($time_next / 60) . __(" minute(s)", "sola");
                }
            }
            $temp_array[] = $time_next;
            if ($sent_perc == 100) {
                $next_camp_id = sola_check_send_mail_time(3);
                if (!$next_camp_id) {
                    $temp_array[] = "0";
                } else {
                    $temp_array[] = $next_camp_id;
                }
            } else {
                $camp_id = sola_check_send_mail_time(3);
                /* must we send a batch now, is it time? */
                if ($camp_id) {
                    sola_cron_send($camp_id);
                }
                $temp_array[] = "0";
            }
            $temp_array[] = $total_sent . " " . __("of", "sola") . " " . $total_subscribers . " " . __("sent", "sola");
            echo json_encode($temp_array);
        }
        if ($_POST['action'] == "force_send") {
            if (isset($_POST['camp_id'])) {
                $camp_id = $_POST['camp_id'];
            } else {
                return false;
            }
            sola_cron_send($_POST['camp_id']);
        }
        if ($_POST['action'] == "save_template") {
            //var_dump($_POST);
            $sola_html = $_POST['sola_html'];
            $camp_id = $_POST['camp_id'];
            $auto_options_array = $_POST['auto_options'];
            $auto_option = $auto_options_array;
            //var_dump($auto_option);
            $auto_options_data = array();
            foreach ($auto_options_array as $auto_option) {
                foreach ($auto_option as $key => $val) {
                    $auto_options_data[$key] = $val;
                    echo $key . " " . $val . "\n";
                }
            }
            $sql = "SELECT * FROM `{$sola_nl_camp_tbl}` WHERE `camp_id` = '{$camp_id}'";
            $current_auto_options = $wpdb->get_row($sql);
            $raw_auto_data = $current_auto_options->automatic_data;
            $raw_auto_data_unserialized = maybe_unserialize($raw_auto_data);
            if (!is_array($raw_auto_data_unserialized)) {
                $raw_auto_data_unserialized = array();
            }
            $raw_auto_data_unserialized["automatic_layout"] = $auto_options_data["automatic_layout"];
            $raw_auto_data_unserialized["automatic_options_posts"] = $auto_options_data["automatic_options_posts"];
            $raw_auto_data_unserialized["automatic_options_columns"] = $auto_options_data["automatic_options_columns"];
            $raw_auto_data_unserialized["automatic_image"] = $auto_options_data["automatic_image"];
            $raw_auto_data_unserialized["automatic_author"] = $auto_options_data["automatic_author"];
            $raw_auto_data_unserialized["automatic_title"] = $auto_options_data["automatic_title"];
            $raw_auto_data_unserialized["automatic_content"] = $auto_options_data["automatic_content"];
            $raw_auto_data_unserialized["automatic_readmore"] = $auto_options_data["automatic_readmore"];
            $raw_auto_data_unserialized["automatic_post_date"] = $auto_options_data["automatic_post_date"];
            $raw_auto_data_unserialized["automatic_post_length"] = $auto_options_data["automatic_post_length"];
            $auto_data = maybe_serialize($raw_auto_data_unserialized);
            if (isset($_POST['auto_options'])) {
                $auto_options = $_POST['auto_options'];
            } else {
                $auto_options = "";
            }
            //            $doc = new DOMDocument();
            //            $doc->loadHTML($sola_html);
            //            $xpath = new DOMXPath($doc);
            //            $nodeList = $xpath->query('//a/@href');
            //            for ($i = 0; $i < $nodeList->length; $i++) {
            //                # Xpath query for attributes gives a NodeList containing DOMAttr objects.
            //                # http://php.net/manual/en/class.domattr.php
            //                echo $nodeList->item($i)->value . "<br/>\n";
            //            }
            //            $regex = '/<a\s+(?:[^"'>]+|"[^"]*"|'[^']*')*href=("[^"]+"|'[^']+'|[^<>\s]+)/i';
            //            preg_match_all('/<a\s+(?:[^"\'>]+|"[^"]*"|\'[^\']*\')*href=("[^"]+"|\'[^\']+\'|[^<>\s]+)/i', $sola_html, $matches);
            //            var_dump($matches);
            $style_array = serialize(sola_nl_save_style($_POST["styles"], $camp_id));
            $wpdb->update($sola_nl_camp_tbl, array('email' => $sola_html, 'last_save' => date("Y-m-d H:i:s"), 'styles' => $style_array, 'automatic_data' => $auto_data), array('camp_id' => $camp_id), array('%s', '%s', '%s', '%s'), array('%d'));
        }
        if ($_POST['action'] == "preview_mail") {
            sola_nl_preview_mail();
        }
        if ($_POST['action'] == "sola_nl_sign_up_add_sub") {
            global $wpdb;
            global $sola_nl_subs_tbl;
            global $sola_nl_subs_list_tbl;
            extract($_POST);
            if (sola_nl_add_single_subscriber(2)) {
                /* albert */
                $sub_email = $_POST["sub_email"];
                $sql = "SELECT * FROM `{$sola_nl_subs_tbl}` WHERE `sub_email` = '{$sub_email}'";
                $result = $wpdb->get_row($sql);
                $sub_key = $result->sub_key;
                $sub_id = $result->sub_id;
                if (isset($_REQUEST['sola_list_ids_signup_widget'])) {
                    $selected_lists = $_REQUEST['sola_list_ids_signup_widget'];
                    if (is_array($selected_lists)) {
                        foreach ($selected_lists as $list_id) {
                            $result = $wpdb->get_results('SELECT count(*) as count FROM ' . $sola_nl_subs_list_tbl . '  WHERE sub_id="' . $sub_id . '" AND list_id="' . $list_id . '" ; ');
                            $count = (int) $result[0]->count;
                            if ($count === 0) {
                                $query = 'INSERT INTO ' . $sola_nl_subs_list_tbl . ' (sub_id,list_id) VALUES (' . $sub_id . ',' . $list_id . ')';
                                $result = $wpdb->query($query);
                            }
                        }
                    }
                } else {
                    $default_lists_set = unserialize(get_option('sola_nl_sign_up_lists'));
                    if (is_array($default_lists_set)) {
                        foreach ($default_lists_set as $list_id) {
                            $result = $wpdb->get_results('SELECT count(*) as count FROM ' . $sola_nl_subs_list_tbl . '  WHERE sub_id="' . $sub_id . '" AND list_id="' . $list_id . '" ; ');
                            $count = (int) $result[0]->count;
                            if ($count === 0) {
                                $query = 'INSERT INTO ' . $sola_nl_subs_list_tbl . ' (sub_id,list_id) VALUES (' . $sub_id . ',' . $list_id . ')';
                                $result = $wpdb->query($query);
                            }
                        }
                    }
                }
                $page_url = get_permalink(get_option("sola_nl_confirm_page"));
                $body = do_shortcode(nl2br(get_option("sola_nl_confirm_mail")));
                $subject = get_option('sola_nl_confirm_subject');
                sola_mail("", $_POST['sub_email'], $subject, $body);
                echo get_option("sola_nl_confirm_thank_you");
            }
        }
        if ($_POST['action'] == "test_mail_2") {
            sola_nl_test_mail_2();
        }
        if ($_POST['action'] == "send_mail") {
            sola_nl_ajax_send($_POST['subscribers'], $_POST['camp_id']);
            //sola_nl_send_mail();
        }
        if ($_POST['action'] == "done_sending") {
            sola_nl_done_sending_camp($_POST['camp_id']);
        }
        if ($_POST['action'] == "sola_get_next_subs") {
            extract($_POST);
            $limit = sola_get_camp_limit($camp_id);
            if ($limit) {
                $subscribers = sola_nl_camp_subs($camp_id, $limit);
                echo json_encode($subscribers);
            } else {
                echo false;
            }
        }
    }
    die;
    // this is required to return a proper result
}
コード例 #2
0
ファイル: module_sending.php プロジェクト: jekv/devia
function sola_cron_send_original()
{
    $debug_start = (double) array_sum(explode(' ', microtime()));
    $camp_id = sola_check_send_mail_time(3);
    if ($camp_id) {
        $limit = sola_get_camp_limit($camp_id);
        if ($limit) {
            $subscribers = sola_nl_camp_subs($camp_id, $limit);
            if ($subscribers) {
                foreach ($subscribers as $subscriber) {
                    set_time_limit(600);
                    $sub_id = $subscriber->sub_id;
                    $sub_email = $subscriber->sub_email;
                    echo $sub_email;
                    $check = sola_nl_send_mail_via_cron_original($camp_id, $sub_id, $sub_email);
                    $end = (double) array_sum(explode(' ', microtime()));
                    echo "<br />processing time: " . sprintf("%.4f", $end - $debug_start) . " seconds<br />";
                    if (is_wp_error($check)) {
                        sola_return_error($check);
                    }
                }
            }
        } else {
            /* do nothing, reached limit */
        }
        $end = (double) array_sum(explode(' ', microtime()));
        echo "<br />processing time: " . sprintf("%.4f", $end - $debug_start) . " seconds<br />";
        sola_nl_done_sending_camp($camp_id);
    } else {
        echo "<br />nothing to send at this time<br />";
    }
}