[ Index ]

MailPress 544

[ 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: 5.4.4
   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 bt = 132;
  18  
  19  	function __construct()
  20      {
  21  // prepare mail
  22          add_filter('MailPress_status_mail',         array(__CLASS__, 'status_mail'));
  23  
  24  // for batch mode
  25          add_action('mp_process_batch_send',         array(__CLASS__, 'process'));
  26  
  27          $config = get_option(self::option_name);
  28          if (!empty($config['batch_mode']) && 'wpcron' == $config['batch_mode'])
  29          {    
  30              add_action('MailPress_schedule_batch_send',     array(__CLASS__, 'schedule'));
  31          }
  32  
  33          if (is_admin())
  34          {
  35          // for install
  36              register_activation_hook(plugin_basename(__FILE__),     array(__CLASS__, 'install'));
  37              register_deactivation_hook(plugin_basename(__FILE__), array(__CLASS__, 'uninstall'));
  38          // for link on plugin page
  39              add_filter('plugin_action_links',         array(__CLASS__, 'plugin_action_links'), 10, 2 );
  40  
  41          // for settings
  42              add_filter('MailPress_scripts',         array(__CLASS__, 'scripts'), 8, 2);
  43              add_filter('MailPress_settings_tab',     array(__CLASS__, 'settings_tab'), 20, 1);
  44          // for settings batches
  45              add_action('MailPress_settings_batches',     array(__CLASS__, 'settings_batches'), 10);
  46          // for settings logs
  47              add_action('MailPress_settings_logs',     array(__CLASS__, 'settings_logs'), 20, 1);
  48  
  49              if (isset($config['batch_mode']) && ('wpcron' == $config['batch_mode']))
  50              {    
  51              // for autorefresh
  52                  add_filter('MailPress_autorefresh_every', array(__CLASS__, 'autorefresh_every'), 8, 1);
  53                  add_filter('MailPress_autorefresh_js',    array(__CLASS__, 'autorefresh_js'), 8, 1);
  54              }
  55  
  56          // for meta box in tracking page
  57              add_action('MailPress_tracking_add_meta_box',  array(__CLASS__, 'tracking_add_meta_box'), 8, 1);
  58          }
  59  
  60  // for to mails column
  61          add_filter('MailPress_to_mails_column',         array(__CLASS__, 'to_mails_column'), 8, 2);
  62      }
  63  
  64  // prepare mail
  65  	public static function status_mail()
  66      {
  67          return 'unsent';
  68      }
  69  
  70  // process
  71  	public static function process()
  72      {
  73          MP_::no_abort_limit();
  74  
  75          new MP_Batch();
  76      }
  77  
  78  // schedule
  79  	public static function schedule()
  80      {
  81          $config = get_option(self::option_name);
  82          $now4cron = current_time('timestamp', 'gmt');
  83  
  84          if (!wp_next_scheduled( 'mp_process_batch_send' )) 
  85              wp_schedule_single_event($now4cron + $config['every'], 'mp_process_batch_send');
  86      }
  87  
  88  ////  ADMIN  ////
  89  ////  ADMIN  ////
  90  ////  ADMIN  ////
  91  ////  ADMIN  ////
  92  
  93  // for install
  94  	public static function install() 
  95      {
  96          self::uninstall();
  97  
  98          global $wpdb;
  99          $wpdb->query( $wpdb->prepare("UPDATE $wpdb->mp_mailmeta SET meta_key = %s WHERE meta_key = %s;", self::meta_key, 'batch_send') );
 100  
 101          $logs = get_option(MailPress::option_name_logs);
 102          if (!isset($logs[self::log_name]))
 103          {
 104              $logs[self::log_name] = MailPress::$default_option_logs;
 105              update_option(MailPress::option_name_logs, $logs );
 106          }
 107  
 108          do_action('MailPress_schedule_batch_send');
 109      }
 110  
 111  	public static function uninstall() 
 112      {
 113          wp_clear_scheduled_hook('mp_process_batch_send');
 114      }
 115  
 116  // for link on plugin page
 117  	public static function plugin_action_links($links, $file)
 118      {
 119          return MailPress::plugin_links($links, $file, plugin_basename(__FILE__), 'batches');
 120      }
 121  
 122  // for settings
 123  	public static function scripts($scripts, $screen) 
 124      {
 125          if ($screen != MailPress_page_settings) return $scripts;
 126  
 127          wp_register_script( 'mp-batchsend',     '/' . MP_PATH . 'mp-admin/js/settings_batch_send.js', array(), false, 1);
 128          $scripts[] = 'mp-batchsend';
 129          return $scripts;
 130      }
 131  
 132  	public static function settings_tab($tabs)
 133      {
 134          $tabs['batches'] = __('Batches', MP_TXTDOM);
 135          return $tabs;
 136      }
 137  
 138  	public static function settings_batches()
 139      {
 140          include  (MP_ABSPATH . 'mp-admin/includes/settings/batches_batch_send.form.php');
 141      }
 142  
 143  	public static function settings_logs($logs)
 144      {
 145          MP_AdminPage::logs_sub_form(self::log_name, $logs, __('Batch', MP_TXTDOM));
 146      }
 147  
 148  	public static function autorefresh_every($every = 30)
 149      {
 150          $config = get_option(self::option_name);
 151          if (!$config) return $every;
 152          if ($every < $config['every']) return $every;
 153          return $config['every'];
 154      }
 155  
 156  	public static function autorefresh_js($scripts)
 157      {
 158          return MP_AutoRefresh_js::register_scripts($scripts);
 159      }
 160  
 161  // for meta box in tracking page
 162  	public static function tracking_add_meta_box($screen)
 163      {
 164          if ('mailpress_tracking_m' != $screen) return;
 165          if (!isset($_GET['id'])) return;
 166  
 167          if (!MP_Mail_meta::get( $_GET['id'], self::meta_key)) return;
 168  
 169          add_meta_box('batchsenddiv', __('Batch current status', MP_TXTDOM), array(__CLASS__, 'meta_box_status'), $screen, 'normal', 'core');
 170      }
 171  
 172  	public static function meta_box_status($mail)
 173      { 
 174          $mailmeta = MP_Mail_meta::get( $mail->id , self::meta_key);
 175  ?>
 176          <table style='width:100%;'>
 177              <tr>
 178                  <td><?php _e('Batch status', MP_TXTDOM); ?></td>
 179                  <td colspan='3'><?php echo $mail->status; ?></td>
 180              </tr>
 181  <?php     if (is_array($mailmeta)) : ?>
 182              <tr><td colspan='4'>&#160;</td></tr>
 183              <tr>
 184                  <td style='width:25%;text-align:center;'><?php _e('Total recipients', MP_TXTDOM); ?></td>
 185                  <td style='width:25%;text-align:center;'><?php _e('Sent', MP_TXTDOM); ?></td>
 186                  <td style='width:25%;text-align:center;'><?php _e('Try/Pass', MP_TXTDOM); ?></td>
 187                  <td style='width:25%;text-align:center;'><?php _e('Processed', MP_TXTDOM); ?></td>
 188              </tr>
 189              <tr>
 190                     <td style='width:25%;text-align:center;'><?php echo $mailmeta['count']; ?></td>
 191                  <td style='width:25%;text-align:center;'><?php echo $mailmeta['sent']; ?></td>
 192                  <td style='width:25%;text-align:center;'><?php echo $mailmeta['try']; ?>/<?php echo $mailmeta['pass']; ?></td>
 193                  <td style='width:25%;text-align:center;'><?php echo $mailmeta['processed']; ?></td>
 194              </tr>
 195  <?php         if (!empty($mailmeta['failed'])) : ?>
 196              <tr><td colspan='4'>&#160;</td></tr>
 197              <tr>
 198                  <td><?php printf(__('Failed (%1$s)', MP_TXTDOM), count($mailmeta['failed'])); ?></td>
 199                  <td colspan='3'><select><?php MP_AdminPage::select_option(array_keys($mailmeta['failed']),''); ?></select></td>
 200              </tr>
 201  <?php         endif; ?>
 202  
 203  <?php     endif; ?>
 204          </table>
 205  <?php
 206      }
 207  
 208  // for mails list
 209  	public static function to_mails_column($to, $mail)
 210      {
 211          $mailmeta = MP_Mail_meta::get( $mail->id , self::meta_key);
 212  
 213          if ($mailmeta)
 214          {
 215              if ($mailmeta['sent'] != $mailmeta['count']) return sprintf( _n( _x('%1$s of %2$s sent', 'Singular', MP_TXTDOM), _x('%1$s of %2$s sent', 'Plural', MP_TXTDOM), $mailmeta['sent'] ), $mailmeta['sent'], $mailmeta['count'] );
 216          }
 217          else
 218          {
 219              if (self::status_mail() == $mail->status) return __('Pending...', MP_TXTDOM);
 220              else
 221              {
 222                  if ('paused' == $mail->status) return __('Paused...', MP_TXTDOM);
 223              }
 224          }
 225  
 226          return $to;
 227      }
 228  }
 229  new MailPress_batch_send();
 230  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1