static function send_mail()
 {
     global $wpdb;
     $attempted_count = SendPress_Option::get('autocron-per-call', 25);
     if (SendPress_Manager::limit_reached($attempted_count)) {
         return;
     }
     $count = SendPress_Data::emails_in_queue();
     $email_count = 0;
     $attempts = 0;
     SendPress_Email_Cache::build_cache();
     if ($count > 0) {
         for ($i = 0; $i < $attempted_count; $i++) {
             $email = SendPress_Data::get_single_email_from_queue();
             SendPress_Queue::send_the_queue($email);
         }
     }
 }
예제 #2
0
 function auto_cron()
 {
     // make sure we're in wp-cron.php
     if (false !== strpos($_SERVER['REQUEST_URI'], '/wp-cron.php')) {
         // make sure a secret string is provided in the ur
         if (isset($_GET['action']) && $_GET['action'] == 'sendpress') {
             $time_start = microtime(true);
             $count = SendPress_Data::emails_in_queue();
             $bg = 0;
             if ($count > 0) {
                 SendPress_Queue::send_mail();
                 $count = SendPress_Data::emails_in_queue();
             } else {
                 SPNL()->log->prune_logs();
                 SendPress_Data::clean_queue_table();
                 //SendPress_Logging::prune_logs();
                 $bg = 1;
             }
             $attempted_count = SendPress_Option::get('autocron-per-call', 25);
             $pro = 0;
             if (defined('SENDPRESS_PRO_VERSION')) {
                 $pro = SENDPRESS_PRO_VERSION;
             }
             $stuck = SendPress_Data::emails_stuck_in_queue();
             $limit = SendPress_Manager::limit_reached();
             $emails_per_day = SendPress_Option::get('emails-per-day');
             $emails_per_hour = SendPress_Option::get('emails-per-hour');
             $hourly_emails = SendPress_Data::emails_sent_in_queue("hour");
             $emails_so_far = SendPress_Data::emails_sent_in_queue("day");
             $limits = array('autocron' => $attempted_count, 'dl' => $emails_per_day, 'hl' => $emails_per_hour, 'ds' => $emails_so_far, 'hs' => $hourly_emails);
             $time_end = microtime(true);
             $time = $time_end - $time_start;
             echo json_encode(array("background" => $bg, "queue" => $count, "stuck" => $stuck, "version" => SENDPRESS_VERSION, "pro" => $pro, "limit" => $limit, 'info' => $limits, 'time' => number_format($time, 3)));
             die;
         }
     }
 }
 static function send_optin($subscriberID, $listids, $lists)
 {
     //SendPress_Error::log('send optin');
     $subscriber = SendPress_Data::get_subscriber($subscriberID);
     $l = '';
     $optin_id = 0;
     foreach ($lists as $list) {
         if (in_array($list->ID, $listids)) {
             $l .= $list->post_title . " <br>";
             if ($optin_id === 0) {
                 $o = get_post_meta($list->ID, 'opt-in-id', true);
                 if ($o === "") {
                     $o = 0;
                 }
                 if ($o > 0) {
                     $optin_id = $o;
                 }
             }
         }
     }
     //	add_filter( 'the_content', array( $this, 'the_content') );
     $optin = $optin_id > 0 ? $optin_id : SendPress_Data::get_template_id_by_slug('double-optin');
     $user = SendPress_Data::get_template_id_by_slug('user-style');
     SendPress_Posts::copy_meta_info($optin, $user);
     SendPress_Email_Cache::build_cache_for_system_email($optin);
     $go = array('from_name' => 'queue', 'from_email' => 'queue', 'to_email' => $subscriber->email, 'emailID' => intval($optin), 'subscriberID' => intval($subscriberID), 'subject' => '', 'listID' => 0);
     $id = SendPress_Data::add_email_to_queue($go);
     SPNL()->load("Subscribers_Tracker")->add(array('subscriber_id' => intval($subscriberID), 'email_id' => intval($optin), 'tracker_type' => SendPress_Enum_Tracker_Type::Confirm));
     $confirm_email = SendPress_Data::get_single_email_from_queue_by_id($id);
     SendPress_Email_Cache::build_cache_for_system_email($confirm_email->id);
     $confirm_email->is_confirm = true;
     SendPress_Queue::send_the_queue($confirm_email);
     /*
     $message = new SendPress_Email();
     $message->id($optin);
     $message->subscriber_id($subscriberID);
     $message->remove_links(true);
     $message->purge(true);
     $html = $message->html();
     $message->purge(false);
     $text = $message->text();
     
     $code = array(
     		"id"=>$subscriberID,
     		"listids"=> implode(',',$listids),
     		"view"=>"confirm"
     	);
     $code = SendPress_Data::encrypt( $code );
     
     if( SendPress_Option::get('old_permalink') || !get_option('permalink_structure') ){
     	$link = home_url() ."?sendpress=".$code;
     } else {
     	$link = home_url() ."/sendpress/".$code;
     }
     
     $href = $link;
     $html_href = "<a href='". $link  ."'>". $link  ."</a>";
     
     
     $html = str_replace("*|SP:CONFIRMLINK|*", $html_href , $html );
     $text = str_replace("*|SP:CONFIRMLINK|*", $href , $text );
     $text = nl2br($text);
     $sub =  $message->subject();
     SPNL()->load("Subscribers_Tracker")->add( array('subscriber_id' => intval( $subscriberID ), 'email_id' => intval( $optin), 'tracker_type' => SendPress_Enum_Tracker_Type::Confirm ) );
     //SendPress_Data::register_event( 'confirm_sent', $subscriberID );			
     SendPress_Manager::send( $subscriber->email, $sub , $html, $text, false );
     */
 }
 static function auto_cron()
 {
     // make sure we're in wp-cron.php
     if (false !== strpos($_SERVER['REQUEST_URI'], '/wp-cron.php')) {
         // make sure a secret string is provided in the ur
         if (isset($_GET['action']) && $_GET['action'] == 'sendpress') {
             //* Use cache
             static $cron_bg_run = null;
             static $cron_bg_run_weekly = null;
             $time_start = microtime(true);
             $count = SendPress_Data::emails_in_queue();
             $bg = 0;
             $bg_weekly = 0;
             $error = '';
             try {
                 if ($count > 0) {
                     SendPress_Queue::send_mail();
                     $count = SendPress_Data::emails_in_queue();
                 } else {
                     //* If cache is empty, pull transient
                     if (!$cron_bg_run) {
                         $cron_bg_run = get_transient('spnl-background-daily');
                     }
                     //* If transient has expired, do a fresh update check
                     if (!$cron_bg_run) {
                         //* If cache is empty, pull transient
                         if (!$cron_bg_run_weekly) {
                             $cron_bg_run_weekly = get_transient('spnl-background-weekly');
                         }
                         //* If transient has expired, do a fresh update check
                         if (!$cron_bg_run_weekly) {
                             SPNL()->log->prune_logs();
                             SendPress_Data::clean_queue_table();
                             SendPress_DB_Tables::repair_tables();
                             $cron_bg_run_weekly = array('runtime' => date("F j, Y, g:i a"));
                             set_transient('spnl-background-weekly', $cron_bg_run_weekly, 60 * 60 * 24 * 7);
                             $bg_weekly = 1;
                         }
                         //SendPress_Logging::prune_logs();
                         $bg = 1;
                         $cron_bg_run = array('runtime' => date("F j, Y, g:i a"));
                         set_transient('spnl-background-daily', $cron_bg_run, 60 * 60 * 24);
                     }
                 }
             } catch (Exception $e) {
                 $error = $e->getMessage();
                 SPNL()->log->add('Autocron', $error, 0, 'error');
             }
             $attempted_count = SendPress_Option::get('autocron-per-call', 25);
             $pro = 0;
             if (defined('SENDPRESS_PRO_VERSION')) {
                 $pro = SENDPRESS_PRO_VERSION;
             }
             $stuck = SendPress_Data::emails_stuck_in_queue();
             $limit = SendPress_Manager::limit_reached();
             $emails_per_day = SendPress_Option::get('emails-per-day');
             $emails_per_hour = SendPress_Option::get('emails-per-hour');
             $hourly_emails = SendPress_Data::emails_sent_in_queue("hour");
             $emails_so_far = SendPress_Data::emails_sent_in_queue("day");
             $limits = array('autocron' => $attempted_count, 'dl' => $emails_per_day, 'hl' => $emails_per_hour, 'ds' => $emails_so_far, 'hs' => $hourly_emails);
             $time_end = microtime(true);
             $time = $time_end - $time_start;
             echo json_encode(array("error" => $error, "background" => $bg, "weekly" => $bg_weekly, "queue" => $count, "stuck" => $stuck, "version" => SENDPRESS_VERSION, "pro" => $pro, "limit" => $limit, 'info' => $limits, 'time' => number_format($time, 3)));
             die;
         }
     }
 }
 function html()
 {
     SendPress_Queue::send_mail();
     $count = SendPress_Data::emails_in_queue();
     echo json_encode(array("queue" => $count));
 }