[ Index ]

MailPress 7.2

[ 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.2
   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_settings_tab',                array( __CLASS__, 'settings_tab' ), 20, 1 );
  45          // for settings batches
  46              add_filter( 'MailPress_settings_batches_help',        array( __CLASS__, 'settings_batches_help' ), 20, 1 );
  47              add_action( 'MailPress_settings_batches_update',    array( __CLASS__, 'settings_batches_update' ), 20 );
  48              add_action( 'MailPress_settings_batches_form',        array( __CLASS__, 'settings_batches_form'), 20 );
  49          // for settings logs
  50              add_action( 'MailPress_settings_logs_form',                array( __CLASS__, 'settings_logs_form' ), 20, 1 );
  51  
  52              if ( isset( $config['batch_mode'] ) && ( 'wpcron' == $config['batch_mode'] ) )
  53              {    
  54              // for autorefresh
  55                  add_filter( 'MailPress_autorefresh_every',        array( __CLASS__, 'autorefresh_every' ), 8, 1 );
  56                  add_filter( 'MailPress_autorefresh_js',        array( __CLASS__, 'autorefresh_js' ), 8, 1 );
  57              }
  58  
  59          // for meta box in tracking page
  60              add_action( 'MailPress_tracking_add_meta_box',        array( __CLASS__, 'tracking_add_meta_box' ), 8, 1 );
  61          }
  62  
  63          // for to mails column
  64          add_filter( 'MailPress_to_mails_column',                array( __CLASS__, 'to_mails_column' ), 8, 2 );
  65      }
  66  
  67  // prepare mail
  68  	public static function status_mail()
  69      {
  70          return 'unsent';
  71      }
  72  
  73  // process
  74  	public static function process()
  75      {
  76          MP_::no_abort_limit();
  77  
  78          new MP_Batch();
  79      }
  80  
  81  // schedule
  82  	public static function schedule()
  83      {
  84          $config = get_option( self::option_name );
  85          $now4cron = current_time( 'timestamp', 'gmt' );
  86  
  87          if ( !wp_next_scheduled( self::process_name ) ) 
  88              wp_schedule_single_event( $now4cron + $config['every'], self::process_name );
  89      }
  90  
  91  ////  ADMIN  ////
  92  ////  ADMIN  ////
  93  ////  ADMIN  ////
  94  ////  ADMIN  ////
  95  
  96  // for install
  97  	public static function install() 
  98      {
  99          self::uninstall();
 100  
 101          global $wpdb;
 102          $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->mp_mailmeta SET meta_key = %s WHERE meta_key = %s;", self::meta_key, 'batch_send' ) );
 103  
 104          MP_Log::set_option( self::log_name );
 105  
 106          do_action( 'MailPress_schedule_batch_send' );
 107      }
 108  
 109  	public static function uninstall() 
 110      {
 111          wp_clear_scheduled_hook( self::process_name );
 112      }
 113  
 114  // for link on plugin page
 115  	public static function plugin_action_links( $links, $file )
 116      {
 117          return MailPress::plugin_links( $links, $file, plugin_basename( __FILE__ ), 'batches' );
 118      }
 119  
 120  // for settings
 121  	public static function settings_tab( $tabs )
 122      {
 123          $tabs['batches'] = __( 'Batches', 'MailPress' );
 124          return $tabs;
 125      }
 126  
 127  // for settings batches
 128  	public static function settings_batches_help( $content )
 129      {
 130          include  ( MP_ABSPATH . 'mp-admin/includes/settings/batches/batch_send/help.php' );
 131          return $content;
 132      }
 133  
 134  	public static function settings_batches_update()
 135      {
 136          include  ( MP_ABSPATH . 'mp-admin/includes/settings/batches/batch_send/update.php' );
 137      }
 138  
 139  	public static function settings_batches_form()
 140      {
 141          include  ( MP_ABSPATH . 'mp-admin/includes/settings/batches/batch_send/form.php' );
 142      }
 143  
 144  // for settings logs
 145  	public static function settings_logs_form( $logs )
 146      {
 147          MP_AdminPage::log_form( self::log_name, $logs, __( 'Batch', 'MailPress' ) );
 148      }
 149  
 150  	public static function autorefresh_every( $every = 30 )
 151      {
 152          $config = get_option( self::option_name );
 153          if ( !$config ) return $every;
 154          if ( $every < $config['every'] ) return $every;
 155          return $config['every'];
 156      }
 157  
 158  	public static function autorefresh_js( $scripts )
 159      {
 160          return MP_WP_AutoRefresh_js::getInstance( $scripts );
 161      }
 162  
 163  // for meta box in tracking page
 164  	public static function tracking_add_meta_box( $screen )
 165      {
 166          if ( 'mailpress_tracking_m' != $screen ) return;
 167          if ( !isset( MP_AdminPage::$get_['id'] ) ) return;
 168  
 169          if ( !MP_Mail_meta::get( MP_AdminPage::$get_['id'], self::meta_key ) ) return;
 170  
 171          add_meta_box( 'batchsenddiv', __( 'Batch current status', 'MailPress' ), array( __CLASS__, 'meta_box_status' ), $screen, 'normal', 'core' );
 172      }
 173  
 174  	public static function meta_box_status( $mail )
 175      { 
 176          $mailmeta = MP_Mail_meta::get( $mail->id , self::meta_key );
 177  
 178          include  ( MP_ABSPATH . 'mp-includes/meta_boxes/mail/batch_status.php' );
 179      }
 180  
 181  // for mails list
 182  	public static function to_mails_column( $to, $mail )
 183      {
 184          $mailmeta = MP_Mail_meta::get( $mail->id , self::meta_key );
 185  
 186          if ( $mailmeta )
 187          {
 188              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'] );
 189          }
 190          else
 191          {
 192              if ( self::status_mail() == $mail->status ) return __( 'Pending...', 'MailPress' );
 193              else
 194              {
 195                  if ( 'paused' == $mail->status ) return __( 'Paused...', 'MailPress' );
 196              }
 197          }
 198  
 199          return $to;
 200      }
 201  }
 202  new MailPress_batch_send();
 203  }


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