[ Index ]

MailPress 7.2

[ 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: 7.2
  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', 'MailPress' ), 
  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          $out  = '<!-- MailPress_bulk_import -->' . "\r\n";
  45          $out .= '<form id="bulk-add" method="post" style="z-index:2000">' . "\r\n";
  46          $out .= '    <input type="text"   name="emails" id="emails" onclick="document.getElementById( \'bulk-add\' ).style.width=\'90%\';document.getElementById( \'emails\' ).style.width=\'70%\';document.getElementById( \'radios\' ).style.display=\'block\';" value="" />' . "\r\n";
  47          $out .= '    <input type="submit" name="bulk_add" class="button" value="' . esc_attr( __( 'Bulk Add', 'MailPress' ) ) . '" />' . "\r\n";
  48          $out .= '    <div id="radios" class="hidden">' . "\r\n";
  49          if ( current_user_can( 'MailPress_manage_mailinglists' ) ) $out .= MP_Mailinglist::dropdown( array( 'echo' => false, 'htmlname' => 'bulk_import_mailinglist', 'htmlid' => 'bulk_import_mailinglist', 'hierarchical' => true, 'orderby' => 'name', 'hide_empty' => '0', 'show_option_none' => __( 'Choose mailinglist', 'MailPress' ) ) ) . "\r\n";
  50          $out .= '        <label for="bulki-activate"><input type="radio" name="activate" id="bulki-activate" value="activate" />' . __( 'Activate', 'MailPress' ) . '</label>' . "\r\n";
  51          $out .= '        <label for="bulki-waiting"><input  type="radio" name="activate" id="bulki-waiting"  value="waiting" checked="checked" /> ' . __( 'Require Authorization', 'MailPress' ) . '</label>' . "\r\n";
  52          $out .= '        <span style="color:#f00;padding-left:50px;">' . "\r\n";
  53          $out .= __( 'email,name;email,name;...', 'MailPress' ) . "\r\n";
  54          $out .= '        </span>' . "\r\n";
  55          $out .= '    </div>' . "\r\n";
  56          $out .= MP_AdminPage::post_url_parms( $url_parms, array( 'mode', 'status', 'paged', 'author', 'mailinglist', 'newsletter' ), false ) . "\r\n";
  57          $out .= '</form>' . "\r\n";
  58          $out .= '<br />' . "\r\n";
  59          $out .= '<!-- MailPress_bulk_import -->' . "\r\n";
  60  
  61          echo $out;
  62      }
  63  
  64  	public static function process_form()
  65      {
  66          if ( !( isset( MP_AdminPage::$pst_['bulk_add'] ) ) ) return;
  67          if ( ( empty( MP_AdminPage::$pst_['emails'] ) ) ) return;
  68  
  69          global $wpdb;
  70  
  71          $count_emails    = self::bulk_users( MP_AdminPage::$pst_['emails'], MP_AdminPage::$pst_['activate'] );
  72  
  73          MP_AdminPage::message( sprintf( _n( __( '%s subscriber added', 'MailPress' ), __( '%s subscribers added', 'MailPress' ), $count_emails ), $count_emails ) );
  74      }
  75  
  76  	public static function bulk_users( $mails, $type )
  77      {
  78          $count = 0;
  79          $email_array     = explode( ';', $mails );
  80  
  81          foreach ( $email_array as $email_name ) 
  82          {
  83              $x = explode( ',', $email_name );
  84  
  85              $email = trim( $x[0] );
  86              $name = ( isset( $x[1] ) ) ? trim( $x[1] ) : '';
  87  
  88              if ( MailPress::is_email( $email ) && ( 'deleted' == MP_User::get_status_by_email( $email ) ) )
  89              {
  90                  if ( 'activate' == $type ) 
  91                  {
  92                      MP_User::insert( $email, $name, array( 'status' => 'active' ) );
  93                      $count++;
  94                  }
  95                  else
  96                  {
  97                      $return = MP_User::add( $email, $name );
  98                      if ( $return['result'] ) $count++;
  99                  }
 100  
 101                  if ( current_user_can( 'MailPress_manage_mailinglists' ) )
 102                  {
 103                      $mp_user_id  = MP_User::get_id_by_email( $email );
 104                      MP_Mailinglist::set_object_terms( MP_User::get_id_by_email( $email ), ( is_array( MP_AdminPage::$pst_['bulk_import_mailinglist'] ) ) ? MP_AdminPage::$pst_['bulk_import_mailinglist'] : array( MP_AdminPage::$pst_['bulk_import_mailinglist'] ) );
 105                  }
 106              }
 107              else
 108              {
 109                  if ( current_user_can( 'MailPress_manage_mailinglists' ) )
 110                  {
 111                      $mp_user_id  = MP_User::get_id_by_email( $email );
 112  
 113                      $mls = array();
 114                      $mls = MP_Mailinglist::get_object_terms( $mp_user_id );
 115                      $mls[] = MP_AdminPage::$pst_['bulk_import_mailinglist'];
 116                      $mls = MP_Mailinglist::set_object_terms( $mp_user_id, $mls );
 117                  }
 118              }
 119          }
 120          return $count;
 121      }
 122  }
 123  new MailPress_bulk_import();
 124  }


Generated: Fri Mar 20 15:22:40 2020 Cross-referenced by PHPXref 0.7.1