[ Index ]

MailPress 7.2

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

title

Body

[close]

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

   1  <?php
   2  if ( class_exists( 'MailPress' ) && !class_exists( 'MailPress_batch_spool_send' ) )
   3  {
   4  /*
   5  Plugin Name: MailPress_batch_spool_send 
   6  Plugin URI: http://blog.mailpress.org/tutorials/add-ons/batch_spool_send/
   7  Description: Mails : Send them in batch mode via spool ( <span style="color:red;">not compatible with Batch_send</span> add-on )
   8  Version: 7.2
   9  */
  10  
  11  class MailPress_batch_spool_send
  12  {
  13      const meta_key = '_MailPress_batch_spool_send';
  14      const option_name = 'MailPress_batch_spool_send';
  15      const log_name = 'batch_spool_send';
  16  
  17      const process_name = 'mp_process_batch_spool_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_spool_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  // spool
  68  	public static function is_path( $p )
  69      {
  70          if ( is_writable( $p ) ) return $p;
  71  
  72          if ( !is_dir( $p ) ) if ( mkdir( $p, 0777, true ) ) return $p;
  73  
  74          return false;
  75      }
  76  
  77  // prepare mail
  78  	public static function status_mail()
  79      {
  80          return 'unsent';
  81      }
  82  
  83  // process
  84  	public static function process()
  85      {
  86          MP_::no_abort_limit();
  87  
  88          new MP_Batch_spool();
  89      }
  90  
  91  // schedule
  92  	public static function schedule()
  93      {
  94          $config = get_option( self::option_name );
  95          $now4cron = current_time( 'timestamp', 'gmt' );
  96  
  97          if ( !wp_next_scheduled( self::process_name ) ) 
  98              wp_schedule_single_event( $now4cron + $config['every'], self::process_name );
  99      }
 100  
 101  ////  ADMIN  ////
 102  ////  ADMIN  ////
 103  ////  ADMIN  ////
 104  ////  ADMIN  ////
 105  
 106  // for install
 107  	public static function install() 
 108      {
 109          self::uninstall();
 110  
 111          global $wpdb;
 112          $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->mp_mailmeta SET meta_key = %s WHERE meta_key = %s;", self::meta_key, 'batch_spool_send' ) );
 113  
 114          MP_Log::set_option( self::log_name );
 115  
 116          do_action( 'MailPress_schedule_batch_spool_send' );
 117      }
 118  
 119  	public static function uninstall() 
 120      {
 121          wp_clear_scheduled_hook( self::process_name );
 122      }
 123  
 124  // for link on plugin page
 125  	public static function plugin_action_links( $links, $file )
 126      {
 127          return MailPress::plugin_links( $links, $file, plugin_basename( __FILE__ ), 'batches' );
 128      }
 129  
 130  // for settings
 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_spool_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_spool_send/update.php' );
 147      }
 148  
 149  	public static function settings_batches_form()
 150      {
 151          include  ( MP_ABSPATH . 'mp-admin/includes/settings/batches/batch_spool_send/form.php' );
 152      }
 153  
 154  // for settings logs
 155  	public static function settings_logs_form( $logs )
 156      {
 157          MP_AdminPage::log_form( self::log_name, $logs, __( 'Spool', '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( 'batchspoolsenddiv', __( 'Batch Spool 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_spool_send();
 213  }


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