[ Index ]

MailPress 7.1

[ 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.1
   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_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  // spool
  69  	public static function is_path( $p )
  70      {
  71          if ( is_writable( $p ) ) return $p;
  72  
  73          if ( !is_dir( $p ) ) if ( mkdir( $p, 0777, true ) ) return $p;
  74  
  75          return false;
  76      }
  77  
  78  // prepare mail
  79  	public static function status_mail()
  80      {
  81          return 'unsent';
  82      }
  83  
  84  // process
  85  	public static function process()
  86      {
  87          MP_::no_abort_limit();
  88  
  89          new MP_Batch_spool();
  90      }
  91  
  92  // schedule
  93  	public static function schedule()
  94      {
  95          $config = get_option( self::option_name );
  96          $now4cron = current_time( 'timestamp', 'gmt' );
  97  
  98          if ( !wp_next_scheduled( self::process_name ) ) 
  99              wp_schedule_single_event( $now4cron + $config['every'], self::process_name );
 100      }
 101  
 102  ////  ADMIN  ////
 103  ////  ADMIN  ////
 104  ////  ADMIN  ////
 105  ////  ADMIN  ////
 106  
 107  // for install
 108  	public static function install() 
 109      {
 110          self::uninstall();
 111  
 112          global $wpdb;
 113          $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->mp_mailmeta SET meta_key = %s WHERE meta_key = %s;", self::meta_key, 'batch_spool_send' ) );
 114  
 115          MP_Log::set_option( self::log_name );
 116  
 117          do_action( 'MailPress_schedule_batch_spool_send' );
 118      }
 119  
 120  	public static function uninstall() 
 121      {
 122          wp_clear_scheduled_hook( self::process_name );
 123      }
 124  
 125  // for link on plugin page
 126  	public static function plugin_action_links( $links, $file )
 127      {
 128          return MailPress::plugin_links( $links, $file, plugin_basename( __FILE__ ), 'batches' );
 129      }
 130  
 131  // for settings
 132  	public static function scripts( $scripts, $screen ) 
 133      {
 134          if ( $screen != MailPress_page_settings ) return $scripts;
 135  
 136          wp_register_script( 'mp-batchspoolsend',     '/' . MP_PATH . 'mp-admin/js/settings_batch_spool_send.js', array(), false, 1 );
 137          $scripts[] = 'mp-batchspoolsend';
 138          return $scripts;
 139      }
 140  
 141  	public static function settings_tab( $tabs )
 142      {
 143          $tabs['batches'] = __( 'Batches', 'MailPress' );
 144          return $tabs;
 145      }
 146  
 147  // for settings batches
 148  	public static function settings_batches_help( $content )
 149      {
 150          include  ( MP_ABSPATH . 'mp-admin/includes/settings/batches/batch_spool_send/help.php' );
 151          return $content;
 152      }
 153  
 154  	public static function settings_batches_update()
 155      {
 156          include  ( MP_ABSPATH . 'mp-admin/includes/settings/batches/batch_spool_send/update.php' );
 157      }
 158  
 159  	public static function settings_batches_form()
 160      {
 161          include  ( MP_ABSPATH . 'mp-admin/includes/settings/batches/batch_spool_send/form.php' );
 162      }
 163  
 164  // for settings logs
 165  	public static function settings_logs_form( $logs )
 166      {
 167          MP_AdminPage::logs_sub_form( self::log_name, $logs, __( 'Spool', 'MailPress' ) );
 168      }
 169  
 170  	public static function autorefresh_every( $every = 30 )
 171      {
 172          $config = get_option( self::option_name );
 173          if ( !$config ) return $every;
 174          if ( $every < $config['every'] ) return $every;
 175          return $config['every'];
 176      }
 177  
 178  	public static function autorefresh_js( $scripts )
 179      {
 180          return MP_WP_AutoRefresh_js::getInstance( $scripts );
 181      }
 182  
 183  // for meta box in tracking page
 184  	public static function tracking_add_meta_box( $screen )
 185      {
 186          if ( 'mailpress_tracking_m' != $screen ) return;
 187          if ( !isset( MP_AdminPage::$get_['id'] ) ) return;
 188  
 189          if ( !MP_Mail_meta::get( MP_AdminPage::$get_['id'], self::meta_key ) ) return;
 190  
 191          add_meta_box( 'batchspoolsenddiv', __( 'Batch Spool current status', 'MailPress' ), array( __CLASS__, 'meta_box_status' ), $screen, 'normal', 'core' );
 192      }
 193  
 194  	public static function meta_box_status( $mail )
 195      { 
 196          $mailmeta = MP_Mail_meta::get( $mail->id , self::meta_key );
 197  
 198          include  ( MP_ABSPATH . 'mp-includes/meta_boxes/mail/batch_status.php' );
 199      }
 200  
 201  // for mails list
 202  	public static function to_mails_column( $to, $mail )
 203      {
 204          $mailmeta = MP_Mail_meta::get( $mail->id , self::meta_key );
 205  
 206          if ( $mailmeta )
 207          {
 208              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'] );
 209          }
 210          else
 211          {
 212              if ( self::status_mail() == $mail->status ) return __( 'Pending...', 'MailPress' );
 213              else
 214              {
 215                  if ( 'paused' == $mail->status ) return __( 'Paused...', 'MailPress' );
 216              }
 217          }
 218  
 219          return $to;
 220      }
 221  }
 222  new MailPress_batch_spool_send();
 223  }


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