[ Index ]

MailPress 7.1

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

title

Body

[close]

/mp-content/add-ons/ -> MailPress_batch_send.php (source)

   1  <?php
   2  if ( class_exists( 'MailPress' ) && !class_exists( 'MailPress_batch_send' ) )
   3  {
   4  /*
   5  Plugin Name: MailPress_batch_send 
   6  Plugin URI: http://blog.mailpress.org/tutorials/add-ons/batch_send/
   7  Description: Mails : Send them in batch mode  ( <span style="color:red;">not compatible with Batch_spool_send</span> add-on )
   8  Version: 7.1
   9  */
  10  
  11  class MailPress_batch_send
  12  {
  13      const meta_key = '_MailPress_batch_send';
  14      const option_name = 'MailPress_batch_send';
  15      const log_name = 'batch_send';
  16  
  17      const process_name = 'mp_process_batch_send';
  18  
  19      const bt = 132;
  20  
  21  	function __construct()
  22      {
  23  // prepare mail
  24          add_filter( 'MailPress_status_mail',                    array( __CLASS__, 'status_mail' ) );
  25  
  26  // for batch mode
  27          add_action( self::process_name,                    array( __CLASS__, 'process' ) );
  28  
  29          $config = get_option( self::option_name );
  30          if ( !empty( $config['batch_mode'] ) && 'wpcron' == $config['batch_mode'] )
  31          {    
  32              add_action( 'MailPress_schedule_batch_send',        array( __CLASS__, 'schedule' ) );
  33          }
  34  
  35          if ( is_admin() )
  36          {
  37          // for install
  38              register_activation_hook( plugin_basename( __FILE__ ),    array( __CLASS__, 'install' ) );
  39              register_deactivation_hook( plugin_basename( __FILE__ ),array( __CLASS__, 'uninstall' ) );
  40          // for link on plugin page
  41              add_filter( 'plugin_action_links',                array( __CLASS__, 'plugin_action_links' ), 10, 2 );
  42  
  43          // for settings
  44              add_filter( 'MailPress_scripts',                array( __CLASS__, 'scripts' ), 8, 2 );
  45              add_filter( 'MailPress_settings_tab',                array( __CLASS__, 'settings_tab' ), 20, 1 );
  46          // for settings batches
  47              add_filter( 'MailPress_settings_batches_help',        array( __CLASS__, 'settings_batches_help' ), 20, 1 );
  48              add_action( 'MailPress_settings_batches_update',    array( __CLASS__, 'settings_batches_update' ), 20 );
  49              add_action( 'MailPress_settings_batches_form',        array( __CLASS__, 'settings_batches_form'), 20 );
  50          // for settings logs
  51              add_action( 'MailPress_settings_logs_form',                array( __CLASS__, 'settings_logs_form' ), 20, 1 );
  52  
  53              if ( isset( $config['batch_mode'] ) && ( 'wpcron' == $config['batch_mode'] ) )
  54              {    
  55              // for autorefresh
  56                  add_filter( 'MailPress_autorefresh_every',        array( __CLASS__, 'autorefresh_every' ), 8, 1 );
  57                  add_filter( 'MailPress_autorefresh_js',        array( __CLASS__, 'autorefresh_js' ), 8, 1 );
  58              }
  59  
  60          // for meta box in tracking page
  61              add_action( 'MailPress_tracking_add_meta_box',        array( __CLASS__, 'tracking_add_meta_box' ), 8, 1 );
  62          }
  63  
  64          // for to mails column
  65          add_filter( 'MailPress_to_mails_column',                array( __CLASS__, 'to_mails_column' ), 8, 2 );
  66      }
  67  
  68  // prepare mail
  69  	public static function status_mail()
  70      {
  71          return 'unsent';
  72      }
  73  
  74  // process
  75  	public static function process()
  76      {
  77          MP_::no_abort_limit();
  78  
  79          new MP_Batch();
  80      }
  81  
  82  // schedule
  83  	public static function schedule()
  84      {
  85          $config = get_option( self::option_name );
  86          $now4cron = current_time( 'timestamp', 'gmt' );
  87  
  88          if ( !wp_next_scheduled( self::process_name ) ) 
  89              wp_schedule_single_event( $now4cron + $config['every'], self::process_name );
  90      }
  91  
  92  ////  ADMIN  ////
  93  ////  ADMIN  ////
  94  ////  ADMIN  ////
  95  ////  ADMIN  ////
  96  
  97  // for install
  98  	public static function install() 
  99      {
 100          self::uninstall();
 101  
 102          global $wpdb;
 103          $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->mp_mailmeta SET meta_key = %s WHERE meta_key = %s;", self::meta_key, 'batch_send' ) );
 104  
 105          MP_Log::set_option( self::log_name );
 106  
 107          do_action( 'MailPress_schedule_batch_send' );
 108      }
 109  
 110  	public static function uninstall() 
 111      {
 112          wp_clear_scheduled_hook( self::process_name );
 113      }
 114  
 115  // for link on plugin page
 116  	public static function plugin_action_links( $links, $file )
 117      {
 118          return MailPress::plugin_links( $links, $file, plugin_basename( __FILE__ ), 'batches' );
 119      }
 120  
 121  // for settings
 122  	public static function scripts( $scripts, $screen ) 
 123      {
 124          if ( $screen != MailPress_page_settings ) return $scripts;
 125  
 126          wp_register_script( 'mp-batchsend',     '/' . MP_PATH . 'mp-admin/js/settings_batch_send.js', array(), false, 1 );
 127          $scripts[] = 'mp-batchsend';
 128          return $scripts;
 129      }
 130  
 131  	public static function settings_tab( $tabs )
 132      {
 133          $tabs['batches'] = __( 'Batches', 'MailPress' );
 134          return $tabs;
 135      }
 136  
 137  // for settings batches
 138  	public static function settings_batches_help( $content )
 139      {
 140          include  ( MP_ABSPATH . 'mp-admin/includes/settings/batches/batch_send/help.php' );
 141          return $content;
 142      }
 143  
 144  	public static function settings_batches_update()
 145      {
 146          include  ( MP_ABSPATH . 'mp-admin/includes/settings/batches/batch_send/update.php' );
 147      }
 148  
 149  	public static function settings_batches_form()
 150      {
 151          include  ( MP_ABSPATH . 'mp-admin/includes/settings/batches/batch_send/form.php' );
 152      }
 153  
 154  // for settings logs
 155  	public static function settings_logs_form( $logs )
 156      {
 157          MP_AdminPage::logs_sub_form( self::log_name, $logs, __( 'Batch', 'MailPress' ) );
 158      }
 159  
 160  	public static function autorefresh_every( $every = 30 )
 161      {
 162          $config = get_option( self::option_name );
 163          if ( !$config ) return $every;
 164          if ( $every < $config['every'] ) return $every;
 165          return $config['every'];
 166      }
 167  
 168  	public static function autorefresh_js( $scripts )
 169      {
 170          return MP_WP_AutoRefresh_js::getInstance( $scripts );
 171      }
 172  
 173  // for meta box in tracking page
 174  	public static function tracking_add_meta_box( $screen )
 175      {
 176          if ( 'mailpress_tracking_m' != $screen ) return;
 177          if ( !isset( MP_AdminPage::$get_['id'] ) ) return;
 178  
 179          if ( !MP_Mail_meta::get( MP_AdminPage::$get_['id'], self::meta_key ) ) return;
 180  
 181          add_meta_box( 'batchsenddiv', __( 'Batch current status', 'MailPress' ), array( __CLASS__, 'meta_box_status' ), $screen, 'normal', 'core' );
 182      }
 183  
 184  	public static function meta_box_status( $mail )
 185      { 
 186          $mailmeta = MP_Mail_meta::get( $mail->id , self::meta_key );
 187  
 188          include  ( MP_ABSPATH . 'mp-includes/meta_boxes/mail/batch_status.php' );
 189      }
 190  
 191  // for mails list
 192  	public static function to_mails_column( $to, $mail )
 193      {
 194          $mailmeta = MP_Mail_meta::get( $mail->id , self::meta_key );
 195  
 196          if ( $mailmeta )
 197          {
 198              if ( $mailmeta['sent'] != $mailmeta['count'] ) return sprintf( _n( _x( '%1$s of %2$s sent', 'Singular', 'MailPress' ), _x( '%1$s of %2$s sent', 'Plural', 'MailPress' ), $mailmeta['sent'] ), $mailmeta['sent'], $mailmeta['count'] );
 199          }
 200          else
 201          {
 202              if ( self::status_mail() == $mail->status ) return __( 'Pending...', 'MailPress' );
 203              else
 204              {
 205                  if ( 'paused' == $mail->status ) return __( 'Paused...', 'MailPress' );
 206              }
 207          }
 208  
 209          return $to;
 210      }
 211  }
 212  new MailPress_batch_send();
 213  }


Generated: Mon Mar 11 18:33:33 2019 Cross-referenced by PHPXref 0.7.1