[ Index ]

MailPress 7.2

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

title

Body

[close]

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

   1  <?php
   2  class MP_Newsletter_processors extends MP_options_
   3  {
   4      const bt = 150;
   5  
   6      var $path       = 'newsletter/processors';
   7  
   8  	public static function get_all()
   9      {
  10          return apply_filters( 'MailPress_newsletter_processors_register', array() );
  11      }
  12  
  13  	public static function process( $newsletter )
  14      {
  15          MP_::no_abort_limit();
  16  
  17          $processors = self::get_all();
  18  
  19          $nls = MP_Newsletter::get_active();
  20  
  21          $trace = self::header_report( $newsletter );
  22          self::sep_report( $trace );
  23  
  24          if ( isset( $newsletter['processor']['id'] ) && isset( $processors[$newsletter['processor']['id']] ) && isset( $nls[$newsletter['id']] ) )
  25          {
  26              do_action( "MailPress_newsletter_processor_{$newsletter['processor']['id']}_process", $newsletter, $trace );
  27          }
  28          else
  29          {
  30              $bm = ' ' . self::item_report( $newsletter['id'], 30 );
  31              if ( !isset( $newsletter['processor']['id'] ) )
  32                  self::message_report( $newsletter, 'no processor in newsletter ( see xml file ) ', $trace, true );
  33              elseif ( !isset( $processors[$newsletter['processor']['id']] ) )
  34                  self::message_report( $newsletter, 'unknown processor : ' . $newsletter['processor']['id'], $trace, true );
  35              elseif ( !isset( $nls[$newsletter['id']] ) )
  36                  self::message_report( $newsletter, 'newsletter not active : ' . $newsletter['id'], $trace, true );
  37          }
  38          self::footer_report( $trace );
  39          unset( $trace, $newsletter );
  40      }
  41  
  42  	public static function send( $newsletter, $trace = false, $report = true )
  43      {
  44          if ( !isset( $newsletter['query_posts'] ) )
  45          {
  46              if ( $trace ) self::message_report( false, '>> empty query_posts : end of process <<', $trace );
  47              return;
  48          }
  49  
  50          self::message_report( ( $report ) ? $newsletter : false, 'query_posts : ' . json_encode( $newsletter['query_posts'] ), $trace );
  51  
  52          $rc = MP_Newsletter::send( $newsletter, true, false, $trace );
  53  
  54          if ( $trace )
  55          {
  56              $bm = "( $rc ) ";
  57              switch ( true )
  58              {
  59                  case ( 0 === $rc ) :
  60                      $bm .= 'no recipients';
  61                  break;
  62                  case ( !$rc ) :
  63                      $bm .= 'a problem occured ( further details in appropriate Mail log )';
  64                  break;
  65                  case ( 'npst' == $rc ) :
  66                      $post_type = ( isset( $newsletter['params']['post_type'] ) ) ? strtolower( $newsletter['params']['post_type'] ) : 'post';
  67                      $bm .= sprintf( 'no %s for this newsletter', $post_type );
  68                  break;
  69                  case ( 'noqp' == $rc ) :
  70                      $bm .= 'newsletter[\'query_posts\'] not set ( error in code ? )';
  71                  break;
  72                  default :
  73                      $bm = "** Process successful ** ( recipients : $rc )";
  74                  break;
  75              }
  76              self::message_report( false, $bm, $trace );
  77          }
  78      }
  79  
  80  	public static function header_report( $newsletter )
  81      {
  82          $trace = new MP_Log( 'mp_sched_proc_newsletter', array( 'option_name' => 'newsletter' ) );
  83  
  84          self::sep_report( $trace );
  85          $bm = 'Processing Newsletter    ' . '  processor : ' . $newsletter['processor']['id'] . ' ' ;
  86          $trace->log( '!' . self::item_report( str_repeat( ' ', 5 ) . $bm, self::bt, '!' ) );
  87          self::sep_report( $trace );
  88          $bm = ' ';
  89          $bm .= self::item_report( 'Newsletter id', 30 );
  90          $trace->log( '!' . self::item_report( $bm, self::bt, '!' ) );
  91  
  92          return $trace;
  93      }
  94  
  95  	public static function message_report( $newsletter, $text, $trace, $error = false ) { MP_Newsletter_schedulers::message_report( $newsletter, $text, $trace, $error ); }
  96  	public static function item_report( $item, $max = false, $trailer = ' ! ' ) { return MP_Newsletter_schedulers::item_report( $item, $max, $trailer );  }
  97  	public static function sep_report( $trace ) { MP_Newsletter_schedulers::sep_report( $trace ); }
  98  	public static function footer_report( $trace ) { MP_Newsletter_schedulers::footer_report( $trace ); }
  99  }


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