[ Index ]

MailPress 544

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

title

Body

[close]

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

   1  <?php
   2  if (class_exists('MailPress') && !class_exists('MailPress_bulk_import') && (is_admin()) )
   3  {
   4  /*
   5  Plugin Name: MailPress_bulk_import
   6  Plugin URI: http://blog.mailpress.org/tutorials/add-ons/bulk_import/
   7  Description: Users : import from mp users list
   8  Author: Daniel Caleb &amp; Andre Renaut
   9  Version: 5.4.4
  10  Author URI: http://galerie-eigenheim.de
  11  */
  12  
  13  class MailPress_bulk_import
  14  {
  15  	function __construct()
  16      {
  17          add_action('MailPress_users_addon',         array(__CLASS__, 'form'));
  18          add_action('MailPress_users_addon_update',    array(__CLASS__, 'process_form'));
  19  
  20  // for wp admin
  21          if (is_admin() && current_user_can('MailPress_manage_mailinglists'))     add_filter('MailPress_scripts', array(__CLASS__, 'scripts'), 8, 2);
  22      }
  23  
  24  	public static function scripts($scripts, $screen) 
  25      {
  26          if ( MailPress_page_users != MailPress::get_admin_page() ) return $scripts;
  27  
  28          wp_register_script( 'mp-import', '/' . MP_PATH . 'mp-includes/js/mp_mailinglist_dropdown.js', array('jquery'), false, 1);
  29          wp_localize_script( 'mp-import',     'mp_ml_select_L10n', array(
  30              'error' => __('Please, choose a mailinglist', MP_TXTDOM), 
  31              'select' => 'bulk_import_mailinglist', 
  32              'form'   => 'bulk-add',
  33              'l10n_print_after' => 'try{convertEntities(mp_ml_select_L10n);}catch(e){};' 
  34          ));
  35  
  36          $scripts[] = 'mp-import';
  37  
  38          return $scripts;
  39      }
  40  
  41  	public static function form($url_parms)
  42      {
  43  ?>
  44  <!-- MailPress_bulk_import -->
  45  <form id='bulk-add' action='' method='post' style="z-index:2000">
  46      <input type='text'   name='emails'   value='' id='emails' onclick="document.getElementById('bulk-add').style.width='90%';document.getElementById('emails').style.width='70%';document.getElementById('radios').style.display='block';" />
  47      <input type='submit' name='bulk_add' value='<?php _e('Bulk Add', MP_TXTDOM ); ?>' class='button' />
  48      <div id="radios" style="display:none">
  49  
  50  <?php if (current_user_can('MailPress_manage_mailinglists')) MP_Mailinglist::dropdown(array('htmlname' => 'bulk_import_mailinglist', 'htmlid' => 'bulk_import_mailinglist', 'hierarchical' => true, 'orderby' => 'name', 'hide_empty' => '0', 'show_option_none' => __('Choose mailinglist', MP_TXTDOM))); ?>
  51  
  52          <label for='bulki-activate'><input type='radio' id='bulki-activate' name='activate' value='activate' /><?php _e('Activate', MP_TXTDOM); ?></label>
  53          <label for='bulki-waiting'><input type='radio'  id='bulki-waiting'  name='activate' value='waiting' checked='checked' /> <?php _e('Require Authorization', MP_TXTDOM); ?></label>
  54          <span style="color:#f00;padding-left:50px;">
  55              <?php _e('email,name;email,name;...', MP_TXTDOM); ?>
  56          </span>
  57      </div>
  58  <?php MP_AdminPage::post_url_parms($url_parms, array('mode', 'status', 'paged', 'author', 'mailinglist', 'newsletter')); ?>
  59  </form>
  60  <br />
  61  <!-- MailPress_bulk_import -->
  62  <?php
  63      }
  64  
  65  	public static function process_form()
  66      {
  67          if (!(isset($_POST['bulk_add']))) return;
  68          if ((empty($_POST['emails']))) return;
  69  
  70          global $wpdb;
  71  
  72          $count_emails    = self::bulk_users($_POST['emails'], $_POST['activate']);
  73  
  74          MP_AdminPage::message( sprintf( _n( __('%s subscriber added', MP_TXTDOM), __('%s subscribers added', MP_TXTDOM), $count_emails ), $count_emails ) );
  75      }
  76  
  77  	public static function bulk_users($mails, $type)
  78      {
  79          $count = 0;
  80          $email_array     = explode(';', $mails);
  81  
  82          foreach ($email_array as $email_name) 
  83          {
  84              $x = explode(',', $email_name);
  85  
  86              $email = trim($x[0]);
  87              $name = (isset($x[1])) ? trim($x[1]) : '';
  88  
  89              if (is_email($email) && ('deleted' == MP_User::get_status_by_email($email)))
  90              {
  91                  if ('activate' == $type) 
  92                  {
  93                      MP_User::insert($email, $name, array('status' => 'active'));
  94                      $count++;
  95                  }
  96                  else
  97                  {
  98                      $return = MP_User::add($email, $name);
  99                      if ($return['result']) $count++;
 100                  }
 101  
 102                  if (current_user_can('MailPress_manage_mailinglists'))
 103                  {
 104                      $mp_user_id  = MP_User::get_id_by_email($email);
 105                      MP_Mailinglist::set_object_terms(MP_User::get_id_by_email($email), (is_array($_POST['bulk_import_mailinglist'])) ? $_POST['bulk_import_mailinglist'] : array($_POST['bulk_import_mailinglist']) );
 106                  }
 107              }
 108              else
 109              {
 110                  if (current_user_can('MailPress_manage_mailinglists'))
 111                  {
 112                      $mp_user_id  = MP_User::get_id_by_email($email);
 113  
 114                      $mls = array();
 115                      $mls = MP_Mailinglist::get_object_terms($mp_user_id);
 116                      $mls[] = $_POST['bulk_import_mailinglist'];
 117                      $mls = MP_Mailinglist::set_object_terms($mp_user_id, $mls);
 118                  }
 119              }
 120          }
 121          return $count;
 122      }
 123  }
 124  new MailPress_bulk_import();
 125  }


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