[ Index ]

MailPress 7.2

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/class/ -> MP_newsletter_processor_.class.php (source)

   1  <?php
   2  abstract class MP_newsletter_processor_ extends MP_newsletter_
   3  {
   4      public $args = 'processor';
   5  
   6  	function __construct( $description )
   7      {
   8          parent::__construct( $description );
   9  
  10          add_action( "MailPress_newsletter_processor_{$this->id}_process", array( $this, 'process' ), 8, 2 );
  11      }
  12  
  13  	function process( $newsletter, $trace )
  14      {
  15          global $wpdb;
  16  
  17          $this->newsletter = $newsletter;
  18          $this->trace     = $trace;
  19  
  20          if ( $this->already_processed() ) return false;
  21  
  22          MP_Newsletter_processors::send( $this->newsletter, $this->trace, false );
  23  
  24          remove_filter( 'posts_where', array( $this, 'posts_where' ) );
  25      }
  26  
  27  	function already_processed()
  28      {
  29          $this->options = get_option( $this->newsletter[$this->args]['threshold'] );
  30  
  31          $this->get_bounds();
  32  
  33          MP_Newsletter_processors::message_report( $this->newsletter, "old : {$this->old_lower_bound}, lower : {$this->lower_bound}, upper : {$this->upper_bound}", $this->trace, true );
  34  
  35          if ( max( $this->old_lower_bound, $this->lower_bound ) >=  $this->upper_bound )
  36          {
  37              MP_Newsletter_processors::message_report( false, "newsletter already processed : ( " . max( $this->old_lower_bound, $this->lower_bound ) . " >= {$this->upper_bound} ) ", $this->trace, true );
  38              return true;
  39          }
  40  
  41          $this->options = array( 'end' => $this->upper_bound );
  42  
  43          if ( !update_option( $this->newsletter[$this->args]['threshold'], $this->options ) )
  44                add_option( $this->newsletter[$this->args]['threshold'], $this->options );
  45  
  46          $query_posts = $this->newsletter[$this->args]['query_posts'] ?? array();
  47          $this->newsletter['query_posts'] = $this->query_posts( $query_posts );
  48  
  49          if ( isset( $this->lower_bound ) ) $this->newsletter['bounds']['lower'] = $this->lower_bound ;
  50          if ( isset( $this->upper_bound ) ) $this->newsletter['bounds']['upper'] = $this->upper_bound ;
  51  
  52          return false;
  53      }
  54  
  55  	function get_old_lower_bound()
  56      {
  57          $this->old_lower_bound = $this->options['end'] ?? $this->lower_bound;
  58      }
  59  
  60  	function query_posts( $query_posts = array() ) 
  61      { 
  62          $this->add_filter();
  63          return $query_posts;
  64      }
  65  
  66  	function add_filter()
  67      {
  68          global $wpdb;
  69          MP_Newsletter_processors::message_report( false, "filter( posts_where ) : \" AND $wpdb->posts.post_date >= '{$this->lower_bound}'\"", $this->trace );
  70          MP_Newsletter_processors::message_report( false, "filter( posts_where ) : \" AND $wpdb->posts.post_date <  '{$this->upper_bound}'\"", $this->trace );
  71  
  72          add_filter( 'posts_where', array( $this, 'posts_where' ), 8, 1 );
  73      }
  74  
  75  	function posts_where( $where )
  76      {
  77          global $wpdb;
  78  
  79          if ( isset( $this->lower_bound ) ) $where .= " AND $wpdb->posts.post_date >= '{$this->lower_bound}' ";
  80          if ( isset( $this->upper_bound ) ) $where .= " AND $wpdb->posts.post_date <  '{$this->upper_bound}' ";
  81  
  82          return $where;
  83      }
  84  }


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1