Пример #1
0
 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();
             if ($email != null) {
                 $attempts++;
                 SendPress_Data::queue_email_process($email->id);
                 $result = SendPress_Manager::send_email_from_queue($email);
                 $email_count++;
                 if ($result) {
                     if ($result === true) {
                         $wpdb->update(SendPress_Data::queue_table(), array('success' => 1, 'inprocess' => 3), array('id' => $email->id));
                         SPNL()->db->subscribers_tracker->add(array('subscriber_id' => intval($email->subscriberID), 'email_id' => intval($email->emailID)));
                     } else {
                         $wpdb->update(SendPress_Data::queue_table(), array('success' => 2, 'inprocess' => 3), array('id' => $email->id));
                         SendPress_Data::bounce_subscriber_by_id($email->subscriberID);
                     }
                 } else {
                     $wpdb->update(SendPress_Data::queue_table(), array('attempts' => $email->attempts + 1, 'inprocess' => 0, 'last_attempt' => date('Y-m-d H:i:s')), array('id' => $email->id));
                 }
             }
         }
     }
 }
 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);
         }
     }
 }
Пример #3
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 emails_allowed_to_send()
 {
     $emails_per_day = SendPress_Option::get('emails-per-day');
     $emails_per_hour = SendPress_Option::get('emails-per-hour');
     $count = SendPress_Data::emails_in_queue();
     $emails_this_hour = SendPress_Data::emails_sent_in_queue("hour");
     $emails_today = SendPress_Data::emails_sent_in_queue("day");
     $hour = $emails_per_hour - $emails_this_hour;
     $day = $emails_per_day - $emails_today;
     if ($count <= $hour && $count <= $day) {
         return $count;
     }
     if ($hour <= $day) {
         return $hour;
     }
     return $day;
 }
 /** ************************************************************************
  * Recommended. This method is called when the parent class can't find a method
  * specifically build for a given column. Generally, it's recommended to include
  * one method for each column you want to render, keeping your package class
  * neat and organized. For example, if the class needs to process a column
  * named 'title', it would first see if a method named $this->column_title() 
  * exists - if it does, that method will be used. If it doesn't, this one will
  * be used. Generally, you should try to use custom column methods as much as 
  * possible. 
  * 
  * Since we have defined a column_title() method later on, this method doesn't
  * need to concern itself with any column with a name of 'title'. Instead, it
  * needs to handle everything else.
  * 
  * For more detailed insight into how columns are handled, take a look at 
  * WP_List_Table::single_row_columns()
  * 
  * @param array $item A singular item (one full row's worth of data)
  * @param array $column_name The name/slug of the column to be processed
  * @return string Text or HTML to be placed inside the column <td>
  **************************************************************************/
 function column_default($item, $column_name)
 {
     $stat_type = get_post_meta($item->ID, '_stat_type', true);
     switch ($column_name) {
         /* case 'firstname':
             case 'lastname':
                 return $item->$column_name;
             case 'status':
                return $item->$column_name;
            
            */
         case 'bounces':
             return '<span class="label">Coming Soon</span>';
             break;
         case 'count':
             $rec = get_post_meta($item->ID, '_send_count', true) + get_post_meta($item->ID, '_send_last_count', true) . '';
             $sentold = get_post_meta($item->ID, '_sent_total', true);
             $queue = 0;
             $sent = get_post_meta($item->ID, '_send_total', true);
             $inqueue = get_post_meta($item->ID, '_in_queue', true);
             if ($inqueue !== 'none') {
                 $queue = SendPress_Data::emails_in_queue($item->ID);
                 $sentindb = SendPress_Data::emails_sent_in_queue_for_report($item->ID);
                 if ($sentindb > $sent) {
                     update_post_meta($item->ID, '_send_total', $sentindb);
                     $sent = $sentindb;
                 }
                 if ($queue == 0) {
                     update_post_meta($item->ID, '_in_queue', 'none');
                 }
             }
             $string = "Recipients: " . $rec . "<br>";
             $string .= "Sent: " . $sent . "<br>";
             $string .= "In Queue: " . $queue . "<br>";
             return $string;
             break;
         case 'sentto':
             $display = '';
             $info = get_post_meta($item->ID, '_send_data', true);
             if (!empty($info['listIDS'])) {
                 foreach ($info['listIDS'] as $list_id) {
                     $list = get_post($list_id);
                     if ($list && $list->post_type == 'sendpress_list') {
                         $display .= $list->post_title . '<br>';
                     }
                 }
             } else {
                 $lists = get_post_meta($item->ID, '_send_lists', true);
                 $list = explode(",", $lists);
                 foreach ($list as $list_id) {
                     $list = get_post($list_id);
                     if ($list && $list->post_type == 'sendpress_list') {
                         $display .= $list->post_title . '<br>';
                     }
                 }
             }
             return $display;
             break;
         case 'opens':
             //if( $stat_type == 'new'){
             $opens = SPNL()->load("Subscribers_Tracker")->get_opens($item->ID);
             $opens_total = SPNL()->load("Subscribers_Tracker")->get_opens_total($item->ID);
             $opens = $opens == 0 ? '-' : $opens;
             $opens_total = $opens_total == 0 ? '-' : $opens_total;
             return '<span class="label label-success">' . $opens . '</span> <span class="label label-info">' . $opens_total . '</span>';
             /*
             } else {
                 $ou = $this->_sendpress->get_opens_unique_count($item->ID);
                 $ou = $ou ? $ou : '-';
             
                
                 $ot = $this->_sendpress->get_opens_count($item->ID);
                 $ot = $ot ? $ot : '-';
             
                 return '<span class="label label-success">'. $ou .'</span> <span class="label label-info">'. $ot .'</span>';
             } 
             */
             break;
         case 'clicks':
             //if( $stat_type == 'new'){
             $clicks = SPNL()->load("Subscribers_Url")->clicks_email_id($item->ID);
             $clicks_total = SPNL()->load("Subscribers_Url")->clicks_total_email_id($item->ID);
             $clicks = $clicks == 0 ? '-' : $clicks;
             $clicks_total = $clicks_total == 0 ? '-' : $clicks_total;
             return '<span class="label label-success">' . $clicks . '</span> <span class="label label-info">' . $clicks_total . '</span>';
             /*
             } else {
             
                 $ou = $this->_sendpress->get_clicks_unique_count($item->ID);
                 $ou = $ou ? $ou : '-';
             
                 $ot = $this->_sendpress->get_clicks_count($item->ID);
                 $ot = $ot ? $ot : '-';
             
                 return '<span class="label label-success">'. $ou .'</span> <span class="label label-info">'. $ot .'</span>';
             }
             */
             break;
         case 'unsubscribe':
             //if( $stat_type == 'new'){
             $clicks = SPNL()->load("Subscribers_Tracker")->get_unsubs($item->ID);
             $clicks = $clicks == 0 ? '-' : $clicks;
             return '<span class="label label-danger">' . $clicks . '</span>';
             /*
                                 } else {
                $clicks = get_post_meta($item->ID, '_unsubscribe_count', true);
                if($clicks) { 
                    return '<span class="label label-danger">'. $clicks .'</span>';
                 }
             }
             */
             // return '<span class="label label-danger">0</span>';
             break;
         case 'subject':
             $sub = get_post_meta($item->ID, "_sendpress_subject", true);
             return $sub;
             break;
         case 'lastsend':
             $date = get_post_meta($item->ID, "send_date", true);
             if (!empty($date)) {
                 return date_i18n(get_option('date_format'), strtotime($date));
             }
             return '';
             break;
         case 'created':
             $canceled = get_post_meta($item->ID, '_canceled', true);
             if ($canceled == true) {
                 return "CANCELED";
             }
             $info = get_post_meta($item->ID, '_send_time', true);
             if ($info == false || $info == '0000-00-00 00:00:00' || date_i18n('Y-m-d H:i:s', strtotime($info)) < date_i18n('Y-m-d H:i:s')) {
                 return date_i18n(get_option('date_format'), strtotime($item->post_date));
             }
             return "Scheduled for " . date_i18n('Y/m/d @ h:i A', strtotime($info)) . "<br><a href='" . SendPress_Admin::link('Emails_Send_Cancel', array('emailID' => $item->ID)) . "'>Cancel Send</a>";
             break;
         case 'actions':
             return '<div class="inline-buttons"><a class="spbutton left" href="' . get_permalink($item->ID) . '">View</a><a class="spbutton right" href="?page=' . SPNL()->validate->page($_REQUEST['page']) . '&view=edit-email&emailID=' . $item->ID . '">Edit</a><a class="spbutton bluebtn" href="?page=' . SPNL()->validate->page($_REQUEST['page']) . '&view=send-email&emailID=' . $item->ID . '">Send</a></div>';
             break;
         default:
             return apply_filters('sendpress_reports_column_' . $column_name, $item);
             //Show the whole array for troubleshooting purposes
     }
 }
 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));
 }
 /** ************************************************************************
  * REQUIRED! This is where you prepare your data for display. This method will
  * usually be used to query the database, sort and filter the data, and generally
  * get it ready to be displayed. At a minimum, we should set $this->items and
  * $this->set_pagination_args(), although the following properties and methods
  * are frequently interacted with here...
  * 
  * @uses $this->_column_headers
  * @uses $this->items
  * @uses $this->get_columns()
  * @uses $this->get_sortable_columns()
  * @uses $this->get_pagenum()
  * @uses $this->set_pagination_args()
  **************************************************************************/
 function prepare_items()
 {
     global $wpdb, $_wp_column_headers;
     $screen = get_current_screen();
     /*      
             select t1.* from `sp_sendpress_list_subscribers` as t1 , `sp_sendpress_subscribers` as t2
             where t1.subscriberID = t2.subscriberID and t1.listID = 2*/
     $query = "SELECT * FROM " . SendPress_Data::queue_table();
     /* -- Pagination parameters -- */
     //Number of elements in your table?
     $totalitems = SendPress_Data::emails_in_queue();
     //$wpdb->query($query); //return the total number of affected rows
     //How many to display per page?
     // get the current user ID
     $user = get_current_user_id();
     // get the current admin screen
     $screen = get_current_screen();
     // retrieve the "per_page" option
     $per_page = 10;
     $screen_option = $screen->get_option('per_page', 'option');
     if (!empty($screen_option)) {
         // retrieve the value of the option stored for the current user
         $per_page = get_user_meta($user, $screen_option, true);
         if (empty($per_page) || $per_page < 1) {
             // get the default value if none is set
             $per_page = $screen->get_option('per_page', 'default');
         }
     }
     //Which page is this?
     $paged = !empty($_GET["paged"]) ? esc_sql($_GET["paged"]) : '';
     //Page Number
     if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
         $paged = 1;
     }
     //How many pages do we have in total?
     $totalpages = ceil($totalitems / $per_page);
     $query .= ' WHERE success = 0 AND max_attempts > attempts ';
     $query .= "AND ( date_sent = '0000-00-00 00:00:00' or date_sent < '" . date_i18n('Y-m-d H:i:s') . "') ";
     if (isset($_GET["listid"]) && $_GET["listid"] > 0) {
         $query .= ' AND listID = ' . $_GET["listid"];
     }
     if (isset($_GET["qs"])) {
         $query .= ' AND to_email LIKE "%' . $_GET["qs"] . '%"';
     }
     /* -- Ordering parameters -- */
     //Parameters that are going to be used to order the result
     $orderby = !empty($_GET["orderby"]) ? esc_sql($_GET["orderby"]) : '';
     $order = !empty($_GET["order"]) ? esc_sql($_GET["order"]) : 'ASC';
     if (!empty($orderby) & !empty($order)) {
         $query .= ' ORDER BY ' . $orderby . ' ' . $order;
     }
     if (empty($orderby)) {
         $query .= ' ORDER BY  attempts ASC, id ASC ';
     }
     //adjust the query to take pagination into account
     if (!empty($paged) && !empty($per_page)) {
         $offset = ($paged - 1) * $per_page;
         $query .= ' LIMIT ' . (int) $offset . ',' . (int) $per_page;
     }
     /* -- Register the pagination -- */
     $this->set_pagination_args(array("total_items" => $totalitems, "total_pages" => $totalpages, "per_page" => $per_page));
     //The pagination links are automatically built according to those parameters
     /* -- Register the Columns -- */
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     /* -- Fetch the items -- */
     $this->items = $wpdb->get_results($query);
 }
 function queue_count()
 {
     $this->verify_ajax_call();
     // Create the response array
     //
     $count = SendPress_Data::emails_in_queue();
     //$sp = new SendPress;
     $response = array('total' => $count);
     echo json_encode($response);
     exit;
 }