[ Index ]

MailPress 7.2

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

title

Body

[close]

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

   1  <?php
   2  class MP_Newsletter_schedulers extends MP_options_
   3  {
   4      const bt = 150;
   5  
   6      var $path    = 'newsletter/schedulers';
   7  
   8  	public static function get_all()
   9      {
  10          return apply_filters( 'MailPress_newsletter_schedulers_register', array() );
  11      }
  12  
  13  	public static function schedule( $event )
  14      {
  15          MP_::no_abort_limit();
  16          $results = array();
  17          $error = false;
  18  
  19          $schedulers = self::get_all();
  20  
  21          global $mp_registered_newsletters;
  22          $nls = MP_Newsletter::get_active();
  23  
  24          $trace = self::header_report( $event );
  25  
  26          foreach ( $nls as $k => $v )
  27          {
  28              $newsletter = $mp_registered_newsletters[$k];
  29              if ( isset( $newsletter['scheduler']['id'] ) && isset( $schedulers[$newsletter['scheduler']['id']] ) )
  30              {
  31                  if ( !$results[] = apply_filters( "MailPress_newsletter_scheduler_{$newsletter['scheduler']['id']}_schedule", $newsletter ) ) array_pop( $results );
  32              }
  33              else
  34              {
  35                  if ( !isset( $newsletter['scheduler']['id'] ) )
  36                  {
  37                      if ( !$error ) self::sep_report( $trace );
  38                      self::message_report( $newsletter, 'no scheduler in newsletter ( see xml file ) ', $trace, true );
  39                      $error = true;
  40                  }
  41                  if ( !isset( $schedulers[$newsletter['scheduler']['id']] ) )
  42                  {
  43                      if ( !$error ) self::sep_report( $trace );
  44                      self::message_report( $newsletter, 'scheduler unknown ', $trace, true );
  45                      $error = true;
  46                  }
  47              }
  48          }
  49  
  50          if ( !empty( $results ) )
  51          {
  52              self::sep_report( $trace );
  53              $results = array_reverse( $results );
  54              uasort( $results, array( 'self', 'sort_newsletter_schedulers' ) );
  55              foreach( $results as $result ) $trace->log( $result['log'] );
  56          }
  57          self::footer_report( $trace );
  58      }
  59  
  60  	public static function sort_newsletter_schedulers( $a, $b ) 
  61      {
  62          return strcmp( $a['timestamp'], $b['timestamp'] );
  63      }
  64  
  65  	public static function header_report( $event )
  66      {
  67          $trace = new MP_Log( 'mp_sched_proc_newsletter', array( 'option_name' => 'newsletter' ) );
  68  
  69          self::sep_report( $trace );
  70          $bm = "Scheduling Newsletters    event : $event ";
  71          $trace->log( '!' . self::item_report( str_repeat( ' ', 5 ) . $bm, self::bt, '!' ) );
  72          self::sep_report( $trace );
  73          $bm = ' ';
  74          $bm .= self::item_report( 'Newsletter id', 30 );
  75          $bm .= self::item_report( 'scheduler',     20 );
  76          $bm .= self::item_report( 'processor',     20 );
  77          $bm .= self::item_report( 'timestamp',     10 );
  78          $bm .= self::item_report( 'time' );
  79          $trace->log( '!' . self::item_report( $bm, self::bt, '!' ) );
  80  
  81          return $trace;
  82      }
  83  
  84  	public static function schedule_report( $newsletter, $timestamp, $id )
  85      {
  86          $bm = ' ';
  87          $bm .= self::item_report( $newsletter['id'],            30 );
  88          $bm .= self::item_report( $id,                    20 );
  89          $bm .= self::item_report( $newsletter['processor']['id'],    20 );
  90          $bm .= self::item_report( $timestamp,                10 );
  91          $bm .= self::item_report( wp_date( 'l jS \of F Y H:i', $timestamp ) );
  92          return array( 'timestamp' => $timestamp, 'log' => '!' . self::item_report( $bm, self::bt, '!' ) );
  93      }
  94  
  95  	public static function message_report( $newsletter, $text, $trace, $error = false )
  96      {
  97          $bm = ' ';
  98          if ( $error )
  99              $bm .= ( $newsletter ) ? self::item_report( $newsletter['id'], 30 ) : '';
 100          else
 101              $bm .= ( $newsletter ) ? self::item_report( $newsletter['id'], 30 ) : self::item_report( ' ', 30 );
 102  
 103          $bm .= $text;
 104          $trace->log( '!' . self::item_report( $bm, self::bt, '!' ) );
 105      }
 106  
 107  	public static function item_report( $item, $max = false, $trailer = ' ! ' )
 108      {
 109          if ( false === $max ) return $item;
 110  
 111          $l = $max - strlen( $item );
 112  
 113          if ( $l < 0 ) return $item . $trailer;
 114          return $item . str_repeat( ' ', $l ) . $trailer;
 115      }
 116  
 117  	public static function sep_report( $trace )
 118      {
 119          $trace->log( '!' . str_repeat( '-', self::bt ) . '!' );
 120      }
 121  
 122  	public static function footer_report( $trace )
 123      {
 124          self::sep_report( $trace );
 125          $trace->end( true );
 126      }
 127  }


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