[ Index ]

MailPress 7.2

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

title

Body

[close]

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

   1  <?php
   2  abstract class MP_newsletter_
   3  {
   4  	function __construct( $desc )
   5      {
   6          $this->desc = $desc;
   7  
   8          $this->time = time();
   9  
  10          $this->date   = wp_date( 'Y-m-d H:i:s', $this->time );
  11          $this->year   = (int) substr( $this->date, 0, 4 );
  12          $this->month  = (int) substr( $this->date, 5, 2 );
  13          $this->day    = (int) substr( $this->date, 8, 2 );
  14          $this->hour   = (int) substr( $this->date, 11, 2 );
  15          $this->minute = (int) substr( $this->date, 14, 2 );
  16          $this->second = (int) substr( $this->date, 17, 2 );
  17  
  18          $this->wday  = ( int ) wp_date( 'w', $this->time );
  19  
  20          add_filter( "MailPress_newsletter_{$this->args}s_register",    array( $this, 'register' ), 8, 1 );
  21      }
  22  
  23  	function register( $x ) { $x[$this->id] = $this->desc; return $x; }
  24  
  25  	function get_day( $y, $m ) 
  26      {
  27          $d = ( int ) $this->newsletter[$this->args]['args']['day'] ?? 1;
  28  
  29          $max_day = $this->get_last_day( $y, $m );
  30  
  31          return ( !is_numeric( $d ) ) ? 1 : ( ( $d <= 0 || $d > $max_day ) ? $max_day : $d );
  32      }
  33  
  34  	function get_last_day( $y, $m ) 
  35      {
  36          $maxd = array( 31,( !( $y%4 )&&( $y%100||!( $y%400 ) ) )?29:28,31,30,31,30,31,31,30,31,30,31 ); 
  37          return $maxd[$m - 1];
  38      }
  39  
  40  	function get_wday() 
  41      {
  42          $w = ( isset( $this->newsletter[$this->args]['args']['wday'] ) && is_numeric( $this->newsletter[$this->args]['args']['wday'] ) ) ? $this->newsletter[$this->args]['args']['wday'] : get_option( 'start_of_week' );
  43          if ( $w === false )     $w = 1;
  44          if ( $w == 7 )         $w = 0;
  45          return ( !is_numeric( $w ) || $w < 0 || $w > 6 ) ? 1 : $w;
  46      }
  47  
  48  	function get_hour() 
  49      {
  50          $h = ( int ) $this->newsletter[$this->args]['args']['hour'] ?? 0;
  51          return ( !is_numeric( $h ) || $h < 0 || $h > 23 ) ? 0 : $h;
  52      }
  53  
  54  	function get_minute() 
  55      {
  56          $i = ( int ) $this->newsletter[$this->args]['args']['minute'] ?? 0;
  57          return ( !is_numeric( $i ) || $i < 0 || $i > 59 ) ? 0 : $i;
  58      }
  59  
  60  	function mktime( $h, $i, $s, $m, $d, $y )
  61      {
  62          return gmmktime( $h, $i, $s, $m, $d, $y ) - get_option( 'gmt_offset' ) * 3600;
  63      }
  64  
  65  
  66  	function format_timestamp( $y, $m, $d, $h, $i, $s = false ) 
  67      {
  68          if ( !$s ) $s = 0;
  69          return $this->format_date( $y, $m, $d ) . ' ' . $this->format_hour( $h, $i, $s );
  70      }
  71  
  72  	function format_date( $y, $m, $d ) 
  73      {
  74          return zeroise( $y, 4 ) . '-' . zeroise( $m, 2 ) . '-' . zeroise( $d, 2 );
  75      }
  76  
  77  	function format_hour( $h, $i, $s = false ) 
  78      {
  79          $hh = zeroise( $h, 2 ) . ':' . zeroise( $i, 2 );
  80          if ( $s !== false ) $hh .= ':' . zeroise( $s, 2 );
  81          return $hh;
  82      }
  83  
  84  	function get_slots( $s = NULL ) 
  85      {
  86          $s = $s ?? $this->newsletter['slots'] ?? 1;
  87          return (int) ( !( 24%$s ) ) ? $s : 1;
  88      }
  89  
  90  	function get_slot_context( $s = NULL )
  91      {
  92          $h = $this->get_hour();
  93          $i = $this->get_minute();
  94  
  95          $s = $this->get_slots( $s );
  96  
  97          /* "map" the slots */
  98  
  99          $this->slot_in_hour = 24 / $s;
 100          $this->slot_in_sec  = DAY_IN_SECONDS / $s;
 101  
 102          $this->slots = array();
 103          for( $z = 0; $z <= $s; $z++ )
 104          {
 105              $x = $h + ( $z * $this->slot_in_hour );
 106              if ( $x >= 24 ) $x -= 24;
 107              $this->slots[$z] = $this->slots[$z - $s] = $this->format_hour( $x, $i, 0 );
 108          }
 109          ksort( $this->slots );
 110  
 111          /* in which slot are we ? */
 112  
 113          $diff = ( ( $this->hour - $h ) * HOUR_IN_SECONDS ) + ( ( $this->minute - $i ) * MINUTE_IN_SECONDS ) + $this->second;
 114  
 115          $this->slot_overnight = ( $diff < 0 );
 116  
 117          if ( $this->slot_overnight ) $diff += DAY_IN_SECONDS;
 118  
 119          $this->slot = 0;
 120          while ( $diff >= $this->slot_in_sec )
 121          {
 122              $this->slot++;
 123              $diff -= $this->slot_in_sec;
 124          }
 125  
 126          $this->slot_overnight = ( $this->slot_overnight && ( $this->slots[$this->slot] != '00:00:00' ) );
 127      }
 128  }


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