[ Index ]

MailPress 544

[ 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          $this->lower_bound = max($this->old_lower_bound, $this->lower_bound);
  34  
  35          MP_Newsletter_processors::message_report($this->newsletter, "old : {$this->lower_bound}, lower : {$this->lower_bound}, upper = {$this->upper_bound}", $this->trace, true);
  36  
  37          if ( $this->lower_bound >=  $this->upper_bound)
  38          {
  39              MP_Newsletter_processors::message_report(false, "newsletter already processed : ({$this->lower_bound} >= {$this->upper_bound}) ", $this->trace, true);
  40              return true;
  41          }
  42  
  43          $this->options = array('end' => $this->upper_bound);
  44  
  45          if (!update_option($this->newsletter[$this->args]['threshold'], $this->options))
  46                add_option($this->newsletter[$this->args]['threshold'], $this->options);
  47  
  48          $query_posts = (isset($this->newsletter[$this->args]['query_posts'])) ? $this->newsletter[$this->args]['query_posts'] : array();
  49          $this->newsletter['query_posts'] = $this->query_posts($query_posts);
  50  
  51          if (isset($this->lower_bound)) $this->newsletter['bounds']['lower'] = $this->lower_bound ;
  52          if (isset($this->upper_bound)) $this->newsletter['bounds']['upper'] = $this->upper_bound ;
  53  
  54          return false;
  55      }
  56  
  57  	function get_old_lower_bound()
  58      {
  59          $this->old_lower_bound = (isset($this->options['end'])) ? $this->options['end'] : $this->lower_bound;
  60      }
  61  
  62  	function add_filter()
  63      {
  64          global $wpdb;
  65          MP_Newsletter_processors::message_report(false, "filter(posts_where) : \" AND $wpdb->posts.post_date >= '{$this->lower_bound}'\"", $this->trace);
  66          MP_Newsletter_processors::message_report(false, "filter(posts_where) : \" AND $wpdb->posts.post_date <  '{$this->upper_bound}'\"", $this->trace);
  67  
  68          add_filter('posts_where', array($this, 'posts_where'), 8, 1);
  69      }
  70  
  71  	function posts_where($where)
  72      {
  73          global $wpdb;
  74  
  75          if (isset($this->lower_bound)) $where .= " AND $wpdb->posts.post_date >= '{$this->lower_bound}' ";
  76          if (isset($this->upper_bound)) $where .= " AND $wpdb->posts.post_date <  '{$this->upper_bound}' ";
  77  
  78          return $where;
  79      }
  80  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1