[ Index ]

MailPress 544

[ 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: 5.4.4
   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 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_spool_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_spool_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  // spool
  65  	public static function is_path($p)
  66      {
  67          if (is_writable($p)) return $p;
  68  
  69          if (!is_dir($p)) if (mkdir($p)) return $p;
  70  
  71          return false;
  72      }
  73  
  74  // prepare mail
  75  	public static function status_mail()
  76      {
  77          return 'unsent';
  78      }
  79  
  80  // process
  81  	public static function process()
  82      {
  83          MP_::no_abort_limit();
  84  
  85          new MP_Batch_spool();
  86      }
  87  
  88  // schedule
  89  	public static function schedule()
  90      {
  91          $config = get_option(self::option_name);
  92          $now4cron = current_time('timestamp', 'gmt');
  93  
  94          if (!wp_next_scheduled( 'mp_process_batch_spool_send' )) 
  95              wp_schedule_single_event($now4cron + $config['every'], 'mp_process_batch_spool_send');
  96      }
  97  
  98  ////  ADMIN  ////
  99  ////  ADMIN  ////
 100  ////  ADMIN  ////
 101  ////  ADMIN  ////
 102  
 103  // for install
 104  	public static function install() 
 105      {
 106          self::uninstall();
 107  
 108          global $wpdb;
 109          $wpdb->query( $wpdb->prepare("UPDATE $wpdb->mp_mailmeta SET meta_key = %s WHERE meta_key = %s;", self::meta_key, 'batch_spool_send') );
 110  
 111          $logs = get_option(MailPress::option_name_logs);
 112          if (!isset($logs[self::log_name]))
 113          {
 114              $logs[self::log_name] = MailPress::$default_option_logs;
 115              update_option(MailPress::option_name_logs, $logs );
 116          }
 117  
 118          do_action('MailPress_schedule_batch_spool_send');
 119      }
 120  
 121  	public static function uninstall() 
 122      {
 123          wp_clear_scheduled_hook('mp_process_batch_spool_send');
 124      }
 125  
 126  // for link on plugin page
 127  	public static function plugin_action_links($links, $file)
 128      {
 129          return MailPress::plugin_links($links, $file, plugin_basename(__FILE__), 'batches');
 130      }
 131  
 132  // for settings
 133  	public static function scripts($scripts, $screen) 
 134      {
 135          if ($screen != MailPress_page_settings) return $scripts;
 136  
 137          wp_register_script( 'mp-batchspoolsend',     '/' . MP_PATH . 'mp-admin/js/settings_batch_spool_send.js', array(), false, 1);
 138          $scripts[] = 'mp-batchspoolsend';
 139          return $scripts;
 140      }
 141  
 142  	public static function settings_tab($tabs)
 143      {
 144          $tabs['batches'] = __('Batches', MP_TXTDOM);
 145          return $tabs;
 146      }
 147  
 148  	public static function settings_batches()
 149      {
 150          include  (MP_ABSPATH . 'mp-admin/includes/settings/batches_batch_spool_send.form.php');
 151      }
 152  
 153  	public static function settings_logs($logs)
 154      {
 155          MP_AdminPage::logs_sub_form(self::log_name, $logs, __('Spool', MP_TXTDOM));
 156      }
 157  
 158  	public static function autorefresh_every($every = 30)
 159      {
 160          $config = get_option(self::option_name);
 161          if (!$config) return $every;
 162          if ($every < $config['every']) return $every;
 163          return $config['every'];
 164      }
 165  
 166  	public static function autorefresh_js($scripts)
 167      {
 168          return MP_AutoRefresh_js::register_scripts($scripts);
 169      }
 170  
 171  // for meta box in tracking page
 172  	public static function tracking_add_meta_box($screen)
 173      {
 174          if ('mailpress_tracking_m' != $screen) return;
 175          if (!isset($_GET['id'])) return;
 176  
 177          if (!MP_Mail_meta::get( $_GET['id'], self::meta_key)) return;
 178  
 179          add_meta_box('batchspoolsenddiv', __('Batch Spool current status', MP_TXTDOM), array(__CLASS__, 'meta_box_status'), $screen, 'normal', 'core');
 180      }
 181  
 182  	public static function meta_box_status($mail)
 183      { 
 184          $mailmeta = MP_Mail_meta::get( $mail->id , self::meta_key);
 185  ?>
 186          <table style='width:100%;'>
 187              <tr>
 188                  <td><?php _e('Batch Spool status', MP_TXTDOM); ?></td>
 189                  <td colspan='3'><?php echo $mail->status; ?></td>
 190              </tr>
 191  <?php     if (is_array($mailmeta)) : ?>
 192              <tr><td colspan='4'>&#160;</td></tr>
 193              <tr>
 194                  <td style='width:25%;text-align:center;'><?php _e('Total recipients', MP_TXTDOM); ?></td>
 195                  <td style='width:25%;text-align:center;'><?php _e('Sent', MP_TXTDOM); ?></td>
 196                  <td style='width:25%;text-align:center;'><?php _e('Try/Pass', MP_TXTDOM); ?></td>
 197                  <td style='width:25%;text-align:center;'><?php _e('Processed', MP_TXTDOM); ?></td>
 198              </tr>
 199              <tr>
 200                     <td style='width:25%;text-align:center;'><?php echo $mailmeta['count']; ?></td>
 201                  <td style='width:25%;text-align:center;'><?php echo $mailmeta['sent']; ?></td>
 202                  <td style='width:25%;text-align:center;'><?php echo $mailmeta['try']; ?>/<?php echo $mailmeta['pass']; ?></td>
 203                  <td style='width:25%;text-align:center;'><?php echo $mailmeta['processed']; ?></td>
 204              </tr>
 205  <?php         if (!empty($mailmeta['failed'])) : ?>
 206              <tr><td colspan='4'>&#160;</td></tr>
 207              <tr>
 208                  <td><?php printf(__('Failed (%1$s)', MP_TXTDOM), count($mailmeta['failed'])); ?></td>
 209                  <td colspan='3'><select><?php MP_AdminPage::select_option(array_keys($mailmeta['failed']),''); ?></select></td>
 210              </tr>
 211  <?php         endif; ?>
 212  
 213  <?php     endif; ?>
 214          </table>
 215  <?php
 216      }
 217  
 218  // for mails list
 219  	public static function to_mails_column($to, $mail)
 220      {
 221          $mailmeta = MP_Mail_meta::get( $mail->id , self::meta_key);
 222  
 223          if ($mailmeta)
 224          {
 225              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'] );
 226          }
 227          else
 228          {
 229              if (self::status_mail() == $mail->status) return __('Pending...', MP_TXTDOM);
 230              else
 231              {
 232                  if ('paused' == $mail->status) return __('Paused...', MP_TXTDOM);
 233              }
 234          }
 235  
 236          return $to;
 237      }
 238  }
 239  new MailPress_batch_spool_send();
 240  }


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