} header("location:admin.php?page=sola-nl-menu"); } else { if ($_POST['sola_nl_save_automatic']) { $time = date("Y-m-d H:i:s", current_time('timestamp')); $sola_nl_check = sola_nl_finish_camp(3, $time); if (is_wp_error($sola_nl_check)) { sola_return_error($sola_nl_check); } else { echo "<div id=\"message\" class=\"updated\"><p>" . __("Automatic campaign saved", "sola") . "</p></div>"; } header("location:admin.php?page=sola-nl-menu"); } else { if ($_POST['schedule_send']) { if ($_POST['schedule_date'] == '') { $the_date = date("Y-m-d H:i:s", current_time('timestamp')); } else { $the_date = $_POST['schedule_date']; } $schedule_format = $the_date . " " . $_POST['schedule_hour'] . ":" . $_POST['schedule_minutes'] . ":00"; $sola_nl_check = sola_nl_finish_camp(3, $schedule_format); if (is_wp_error($sola_nl_check)) { sola_return_error($sola_nl_check); } else { echo "<div id=\"message\" class=\"updated\"><p>" . __("Campaign Ready to Send", "sola") . "</p></div>"; } sola_nl_add_subs_to_camp($_GET['camp_id']); header("location:admin.php?page=sola-nl-menu"); } } }
function sola_nl_ajax_send($subscribers, $camp_id) { $debug_start = (double) array_sum(explode(' ', microtime())); global $wpdb; global $sola_nl_camp_tbl; global $sola_nl_camp_subs_tbl; global $sola_nl_subs_tbl; global $sola_global_subid; global $sola_global_campid; if ($camp_id) { echo get_option("sola_currently_sending"); if (!get_option("sola_currently_sending")) { if (get_option("sola_currently_sending") == "yes") { return "We are currently sending. Dont do anything"; } else { update_option("sola_currently_sending", "yes"); } } else { add_option("sola_currently_sending", "yes"); } update_option("sola_currently_sending", "yes"); $camp = sola_nl_get_camp_details($camp_id); if (isset($camp->reply_to)) { $reply = $camp->reply_to; } if (isset($camp->reply_to_name)) { $reply_name = stripslashes($camp->reply_to_name); } if (isset($camp->sent_from)) { $sent_from = $camp->sent_from; } if (isset($camp->sent_from_name)) { $sent_from_name = stripslashes($camp->sent_from_name); } if (empty($reply)) { $reply = get_option("sola_nl_reply_to"); } if (empty($reply_name)) { $reply_name = get_option("sola_nl_reply_to_name"); } if (empty($sent_from)) { $sent_from = get_option("sola_nl_sent_from"); } if (empty($sent_from_name)) { $sent_from_name = get_option("sola_nl_sent_from_name"); } // get option for either SMTP or normal WP MAil // split below based on above $saved_send_method = get_option("sola_nl_send_method"); if ($saved_send_method == "1") { $headers[] = 'From: ' . $sent_from_name . '<' . $sent_from . '>'; $headers[] = 'Content-type: text/html'; $headers[] = 'Reply-To: ' . $reply_name . '<' . $reply . '>'; } else { if ($saved_send_method >= "2") { $file = PLUGIN_URL . '/includes/phpmailer/PHPMailerAutoload.php'; require_once $file; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->SMTPKeepAlive = true; $port = get_option("sola_nl_port"); $encryption = get_option("sola_nl_encryption"); if ($encryption) { $mail->SMTPSecure = $encryption; } $host = get_option("sola_nl_host"); $mail->Host = $host; $mail->Username = get_option("sola_nl_username"); $mail->Password = get_option("sola_nl_password"); $mail->Port = $port; $mail->AddReplyTo($reply, $reply_name); $mail->SetFrom($sent_from, $sent_from_name); $mail->Subject = $camp->subject; $mail->SMTPDebug = 0; } } if ($subscribers) { foreach ($subscribers as $subscriber) { set_time_limit(600); $sub_id = $subscriber['sub_id']; $sub_email = $subscriber['sub_email']; echo $sub_email; $body = sola_nl_mail_body($camp->email, $sub_id, $camp->camp_id); $sola_global_subid = $sub_id; $sola_global_campid = $camp->camp_id; $body = do_shortcode($body); $body = sola_nl_replace_links($body, $sub_id, $camp->camp_id); /* ------ */ //$check = sola_mail($camp_id ,$sub_email, $camp->subject, $body); if ($saved_send_method == "1") { if (wp_mail($sub_email, $camp->subject, $body, $headers)) { $check = true; } else { if (!$debug) { $check = array('error' => 'Error sending mail to' . $sub_email); } else { $check = array('error' => "Failed to send email to {$sub_email}... " . $GLOBALS['phpmailer']->ErrorInfo); } } } else { if ($saved_send_method >= "2") { if (is_array($sub_email)) { foreach ($sub_email as $address) { $mail->AddAddress($address); } } else { $mail->AddAddress($sub_email); } $mail->Body = $body; $mail->IsHTML(true); //echo "sending to $sub_email<br />"; if (!$mail->Send()) { $check = array('error' => 'Error sending mail to ' . $sub_email); } else { $check = true; } } } if ($check === true) { sola_update_camp_limit($camp_id); $wpdb->update($sola_nl_camp_subs_tbl, array('status' => 1), array('camp_id' => $camp_id, 'sub_id' => $sub_id), array('%d'), array('%d', '%d')); //echo "Email sent to $sub_email successfully <br />"; } else { sola_return_error(new WP_Error('sola_error', __('Failed to send email to subscriber'), 'Could not send email to ' . $sub_email)); //echo "<p>Failed to send to ".$sub_email."</p>"; } $mail->clearAddresses(); $mail->clearAttachments(); $end = (double) array_sum(explode(' ', microtime())); echo "<br />processing time: " . sprintf("%.4f", $end - $debug_start) . " seconds<br />"; //$check = sola_nl_send_mail_via_cron($camp_id,$sub_id,$sub_email); //if ( is_wp_error($check)) sola_return_error($check); } } else { /* do nothing, reached limit */ } if ($saved_send_method >= "2") { $mail->smtpClose(); } $end = (double) array_sum(explode(' ', microtime())); echo "<br />processing time: " . sprintf("%.4f", $end - $debug_start) . " seconds<br />"; update_option("sola_currently_sending", "no"); sola_nl_done_sending_camp($camp_id); } else { echo "<br />nothing to send at this time<br />"; } }
function custom_auto_mail_send() { global $wpdb; global $sola_nl_camp_tbl; global $sola_nl_subs_tbl; global $sola_global_campid; global $sola_global_subid; // echo 'Running'; /* * Check to see if there are any auto posts available */ $sql = "SELECT * FROM {$sola_nl_camp_tbl} WHERE `type` = 2 AND `action` = 3"; $results = $wpdb->get_results($sql); if ($results) { foreach ($results as $result) { $auto_camp_id = $result->camp_id; // echo "<h1>$auto_camp_id</h1>"; $auto_data = $result->automatic_data; $raw_auto_data = maybe_unserialize($auto_data); // if not immediate but automatic post, create new campaign if ($raw_auto_data['type'] != 5 && $raw_auto_data['action'] == 3) { // var_dump("type != 5 action = 3"); $current_time = date('Y-m-d H:i:s', current_time('timestamp')); $scheduled_time = $raw_auto_data['automatic_scheduled_date']; if ($current_time >= $scheduled_time && $scheduled_time != '0000-00-00 00:00:00') { echo 'Running Because Time Is Less Than Current'; $are_there_new_posts_to_email = sola_nl_check_if_new_posts_exist($auto_camp_id, $raw_auto_data['automatic_options_posts'], $raw_auto_data['automatic_scheduled_date']); if ($are_there_new_posts_to_email != null) { $auto_camp_id = $result->camp_id; $auto_data = $result->automatic_data; $raw_auto_data = maybe_unserialize($auto_data); // var_dump($raw_auto_data); $camp = sola_nl_get_camp_details($auto_camp_id); $lists = sola_nl_get_camp_lists($auto_camp_id); // var_dump($lists); foreach ($lists as $list) { $list_id = $list->list_id; $new_lists[] = $list_id; // var_dump($new_lists); } $type = 1; /* insert it as a normal campaign */ $letter = sola_nl_get_letter($auto_camp_id); // echo $letter; // exit(); $inserted_data = sola_nl_build_automatic_content($auto_camp_id, true); // echo $inserted_data; // $sola_global_campid = $auto_camp_id; // var_dump("CAMP ID ". $auto_camp_id); // exit(); $table = preg_replace('/<table id="sola_nl_automatic_container"(.*?)<\\/table>/is', $inserted_data, $letter); // $table = do_shortcode($table); echo $table; $subject = do_shortcode($camp->subject); $wpdb->insert($sola_nl_camp_tbl, array('camp_id' => '', 'subject' => $subject, 'theme_id' => $camp->theme_id, 'email' => $table, 'styles' => $camp->styles, 'type' => $type)); $camp_id = $wpdb->insert_id; // var_dump("NEW CAMP ID = ".$camp_id); global $sola_global_campid; $sola_global_campid = $camp_id; //$working_table = do_shortcode($table); //echo $working_table; // echo 'Doing Update Below This'; //$wpdb->update($sola_nl_camp_tbl, array('email' => $working_table), array('camp_id' => $camp_id)); $checker = sola_nl_finish_camp(3, $current_time, $camp->sent_from, $camp->sent_from_name, $camp->reply_to, $camp->reply_to_name, $camp_id, $new_lists, $auto = true); // print_r($new_lists); var_dump('This will be the new campaign id ' . $camp_id); // exit(); if (is_wp_error($checker)) { sola_return_error($checker); } /* we need to have a check here to see if this works or not */ if (function_exists('sola_nl_add_subs_to_camp_pro')) { sola_nl_add_subs_to_camp_pro($camp_id); } else { sola_nl_add_subs_to_camp($camp_id); } } else { /* there are no new posts during this scheduled run */ var_dump("there are no new posts to send in this scheduled run"); } } /* set the next scheduled run */ $the_current_time = current_time('timestamp'); var_dump("current time: " . date("Y-m-d H:i:s", $the_current_time)); $type = $raw_auto_data['type']; $day = $raw_auto_data['data']['day']; var_dump($day); $custom_time = $raw_auto_data['data']['time']; var_dump($custom_time); // echo 'The time here'; // $the_current_time = strtotime('2014-10-08 08:30:00'); if ($type == 1) { //Daily if (strtotime(date("Y-m-d", $the_current_time) . " " . $custom_time . ":00") > $the_current_time) { var_dump("current time less than time. set it for today"); $time = date('Y-m-d H:i:s', strtotime(date("Y-m-d", $the_current_time) . " " . $custom_time . ":00")); } else { var_dump("current time greater than time, set it for next time"); $time = date('Y-m-d H:i:s', strtotime('+1 day ' . $custom_time . ':00', $the_current_time)); } } else { if ($type == 2) { //Weekly if ($day == 1) { $chosen_day = 'Monday'; } else { if ($day == 2) { $chosen_day = 'Tuesday'; } else { if ($day == 3) { $chosen_day = 'Wednesday'; } else { if ($day == 4) { $chosen_day = 'Thursday'; } else { if ($day == 5) { $chosen_day = 'Friday'; } else { if ($day == 6) { $chosen_day = 'Saturday'; } else { if ($day == 7) { $chosen_day = 'Sunday'; } } } } } } } $time = date('Y-m-d H:i:s', strtotime("+1 Week " . $chosen_day . ' ' . $custom_time . ':00', $the_current_time)); } else { $time = date('Y-m-d H:i:s', current_time('timestamp')); } } // echo $time; $new_automatic_data = array('type' => $raw_auto_data['type'], 'action' => $raw_auto_data['action'], 'data' => array('day' => $raw_auto_data['data']['day'], 'time' => $raw_auto_data['data']['time'], 'daynum' => $raw_auto_data['data']['daynum'], 'timeafter' => $raw_auto_data['data']['timeafter'], 'timeqty' => $raw_auto_data['data']['timeqty'], 'role' => $raw_auto_data['data']['role']), 'automatic_layout' => $raw_auto_data['automatic_layout'], 'automatic_options_posts' => $raw_auto_data['automatic_options_posts'], 'automatic_options_columns' => $raw_auto_data['automatic_options_columns'], 'automatic_image' => $raw_auto_data['automatic_image'], 'automatic_author' => $raw_auto_data['automatic_author'], 'automatic_title' => $raw_auto_data['automatic_title'], 'automatic_content' => $raw_auto_data['automatic_content'], 'automatic_readmore' => $raw_auto_data['automatic_readmore'], 'automatic_scheduled_date' => $time, 'automatic_post_date' => $raw_auto_data['automatic_post_date'], 'automatic_post_length' => $raw_auto_data['automatic_post_length']); $serialized_auto_data = maybe_serialize($new_automatic_data); $wpdb->update($sola_nl_camp_tbl, array('automatic_data' => $serialized_auto_data), array('camp_id' => $auto_camp_id)); var_dump("Next scheduled date set to " . $time); } } } /* * Check to see if there are any subscribers that need to be emailed. */ $sql = "SELECT * FROM {$sola_nl_subs_tbl} WHERE `status` = 1 AND `sola_nl_mail_sent` = 0"; $sub_results = $wpdb->get_results($sql); // var_dump($sub_results); if ($sub_results) { foreach ($sub_results as $sub) { $sub_id = $sub->sub_id; $user_email = $sub->sub_email; if ($sub->sub_name == '') { $user_name = $sub->sub_email; } else { $user_name = $sub->sub_name; } $user_mail_sent = $sub->sola_nl_mail_sent; $user_mail_send_time = $sub->sola_nl_mail_sending_time; if ($user_mail_sent != '' && $user_mail_send_time != '' && $user_mail_send_time != '0000-00-00 00:00:00') { $current_time = date('Y-m-d H:i:s', current_time('timestamp')); $sql = "SELECT * FROM {$sola_nl_camp_tbl} WHERE `type` = 2 AND `action` = 4"; $results = $wpdb->get_results($sql); // var_dump($results); if ($results) { foreach ($results as $result) { if (isset($result->camp_id)) { $camp_id = $result->camp_id; } else { $camp_id = ''; } $sola_global_campid = $camp_id; $sql = "SELECT * FROM {$sola_nl_subs_tbl} WHERE `sub_email` = '{$user_email}'"; $subscriber_details = $wpdb->get_row($sql); $sub_id = $subscriber_details->sub_id; $sola_global_subid = $sub_id; if (isset($user_email)) { $to = $user_email; } else { $to = ''; } if (isset($result->subject)) { $subject = stripslashes(do_shortcode($result->subject)); } else { $subject = ''; } if (isset($result->email)) { $body_contents = stripslashes(do_shortcode(trim($result->email))); } else { $body_contents = ''; } // var_dump($result->email); // echo SITE_URL; // echo $body_contents; // exit(); $body = sola_nl_mail_body($body_contents, $camp_id, $camp_id); if (isset($result->styles)) { $styles = $result->styles; } else { $styles = ''; } } if ($current_time >= $user_mail_send_time && $user_mail_sent == 0) { $mail_sent = sola_mail($camp_id, $to, $subject, $body); if ($mail_sent) { $wpdb->update($sola_nl_subs_tbl, array('sola_nl_mail_sent' => 1), array('sub_id' => $sub_id)); } } } } } } /* * Check to see if there are any users that need to be emailed. */ $args = array('meta_key' => '_sola_nl_mail_sent', 'meta_value' => '0'); $users = get_users($args); foreach ($users as $user) { $user_id = $user->ID; $user_email = $user->data->user_email; $user_name = $user->data->display_name; $user_role = $user->roles[0]; $sql = "SELECT * FROM {$sola_nl_camp_tbl} WHERE `type` = 2 AND `action` = 5"; $results = $wpdb->get_results($sql); // var_dump("USERS"); // var_dump($results); foreach ($results as $result) { $auto_camp_id = $result->camp_id; $auto_data = $result->automatic_data; $raw_auto_data = maybe_unserialize($auto_data); $role = intval($raw_auto_data['data']['role']); if ($role == 1 || $role == 2 && $user_role == 'administrator' || $role == 3 && $user_role == 'editor' || $role == 4 && $user_role == 'author' || $role == 5 && $user_role == 'contributor' || $role == 6 && $user_role == 'subscriber') { $user_mail_sent = get_user_meta($user_id, '_sola_nl_mail_sent', true); $user_mail_send_time = get_user_meta($user_id, '_sola_nl_mail_sending_time', true); if ($user_mail_sent != '' && $user_mail_send_time != '') { $current_time = date('Y-m-d H:i:s', current_time('timestamp')); $user_meta = get_user_meta($user_id); $user_data = get_userdata($user_id); $user_role = $user_data->roles[0]; $sql = "SELECT * FROM {$sola_nl_camp_tbl} WHERE `type` = 2 AND `action` = 5"; $results = $wpdb->get_results($sql); if ($results) { foreach ($results as $result) { $camp_id = $result->camp_id; // echo $camp_id; // global $sola_global_campid; $sola_global_campid = $camp_id; $to = $user_email; $subject = do_shortcode($result->subject); $body_contents = stripslashes(do_shortcode(trim($result->email))); // echo $body_contents; $body = sola_nl_mail_body($body_contents, $user_id, $camp_id); $styles = $result->styles; } if ($current_time >= $user_mail_send_time && $user_mail_sent == 0) { $mail_sent = sola_mail($camp_id, $to, $subject, $body); if ($mail_sent) { update_user_meta($user_id, '_sola_nl_mail_sent', 1); } } } } } } } }
function sola_nl_widget_add_sub() { extract($_POST); $check = sola_nl_add_single_subscriber(); if ($check == true) { $body = "<p>Hi There</p>\n <p>Thank you for signing up. Please click on the following link to activate your subscription.</p>\n <a href=''>Click Here</a>"; $subject = get_option('sola_nl_confirm_subject'); $body = get_option('sola_nl_confirm_mail'); sola_mail(0, $sub_email, $subject, $body); ?> <div> <?php echo get_option("sola_nl_confirm_thank_you"); ?> </div> <?php } else { if (is_wp_error($check)) { sola_return_error($check); } } }