[ Index ]

MailPress 7.0.1

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

title

Body

[close]

/mp-includes/class/options/import/importers/ -> export_mailinglist2mailinglist.php (source)

   1  <?php
   2  if ( class_exists( 'MailPress_mailinglist' ) )
   3  {
   4  
   5  class MP_export_mailinglist_mailinglist extends MP_import_importer_
   6  {
   7      var $id = 'mailinglist_export_mailinglist';
   8  
   9  	function dispatch() 
  10      {
  11          $step = $this->get_step();
  12  
  13          $this->header();
  14          switch ( $step ) 
  15          {
  16              case 0 :
  17                  $this->greet();
  18              break;
  19              case 1:
  20                  $this->start_trace( $step );
  21                      $this->message_report( " **  INFO * ! 'From' Mailing list is #" . MP_AdminPage::$pst_['export_mailinglist'] );
  22                  $this->end_trace( true );
  23                  $this->step1();
  24              break;
  25              case 2:
  26                  $this->start_trace( $step );
  27                      $export = $this->export();
  28                  $this->end_trace( true );
  29                  if ( $export )
  30                      $this->success( "<p><b>Mailinglist exported</b></p>" );
  31                  else 
  32                      $this->error( "<p><b>No mp users imported in Mailinglist</b></p>" );
  33              break;
  34          }
  35          $this->footer();
  36      }
  37  
  38  // step 0
  39  
  40  	function greet() 
  41      {
  42          $args = array( 'mp_import' => $this->id, 'step' => 1 );
  43  ?>
  44  <div>
  45      <p>
  46  <?php        _e( 'Howdy!', 'MailPress' ); ?>
  47          <br />
  48      </p>
  49      <form id="export-mailing-list" method="post" action="<?php echo esc_url( add_query_arg( $args, MailPress_import ) ); ?>">
  50          <p>
  51              <label for="download"><?php _e( "Choose the 'From' mailing list :", 'MailPress' ); ?></label>
  52  <?php
  53              $dropdown_options = array( 'hide_empty' => 0, 'hierarchical' => true, 'show_count' => 0, 'orderby' => 'name', 'htmlid' => 'export_mailinglist', 'htmlname' => 'export_mailinglist', 'selected' => get_option( MailPress_mailinglist::option_name_default ) );
  54              MP_Mailinglist::dropdown( $dropdown_options );
  55  ?>
  56          </p>
  57          <p class="submit">
  58              <input type="submit" class="button" value="<?php echo esc_attr( __( 'Continue', 'MailPress' ) ); ?>" />
  59          </p>
  60      </form>
  61  </div>
  62  <?php
  63      }
  64  
  65  // step 1
  66  
  67  	function step1() 
  68      {
  69          $args = array( 'mp_import' => $this->id, 'step' => 2 );
  70  ?>
  71  <div>
  72      <p>
  73  <?php        printf( __( 'From mailing list is #%s', 'MailPress' ), MP_AdminPage::$pst_['export_mailinglist'] ); ?>
  74      </p>
  75      <form id="export-mailing-list" method="post" action="<?php echo esc_url( add_query_arg( $args, MailPress_import ) ); ?>">
  76          <p>
  77              <label for="download"><?php _e( "Choose the 'To' mailing list :", 'MailPress' ); ?></label>
  78              <input type="hidden" name="from_mailinglist" value="<?php echo esc_attr( MP_AdminPage::$pst_['export_mailinglist'] ); ?>" />
  79  <?php
  80              $dropdown_options = array( 'hide_empty' => 0, 'hierarchical' => true, 'show_count' => 0, 'orderby' => 'name', 'htmlid' => 'to_mailinglist', 'htmlname' => 'to_mailinglist', 'exclude' => MP_AdminPage::$pst_['export_mailinglist'] );
  81              MP_Mailinglist::dropdown( $dropdown_options );
  82  ?>
  83          </p>
  84          <p class="submit">
  85              <input type="submit" class="button" value="<?php echo esc_attr( __( 'Export', 'MailPress' ) ); ?>" />
  86          </p>
  87      </form>
  88  </div>
  89  <?php
  90      }
  91  
  92  // step 2
  93  	function export() 
  94      {
  95          $count = $exported = 0;
  96          $from = MP_AdminPage::$pst_['from_mailinglist'];
  97          $to   = MP_AdminPage::$pst_['to_mailinglist'];
  98  
  99          $this->message_report( " EXPORTING  ! mailing list #{$from} to mailing list #{$to}" );
 100  
 101          global $wpdb;
 102  
 103          $users = $wpdb->get_results( "SELECT DISTINCT c.id as id FROM $wpdb->term_taxonomy a, $wpdb->term_relationships b, $wpdb->mp_users c WHERE a.taxonomy = '" . MailPress_mailinglist::taxonomy . "' AND  a.term_taxonomy_id = b.term_taxonomy_id AND a.term_id = $from AND c.id = b.object_id ;" );
 104  
 105          foreach ( $users as $user )
 106          {
 107              $count++;
 108  
 109              $mp_user_mls = MP_Mailinglist::get_object_terms( $user->id );
 110              if ( !in_array( $to, $mp_user_mls ) ) 
 111              {
 112                  $mp_user_mls[] = $to;
 113                  if ( MP_Mailinglist::set_object_terms( $user->id, $mp_user_mls ) ) $exported++;
 114                  continue;
 115              }
 116              $this->message_report( " **WARNING* ! mp_user #{$user->id} already in mailing list #{$to} !" );
 117          }
 118  
 119          if ( !$count ) 
 120              $this->message_report( " **WARNING* ! 'From' Mailing list is empty !" );
 121          else
 122              $this->message_report( " **EXPORTED*! read in #{$from} : ". $count .", imported in #{$to} : ". $exported );
 123  
 124          return $exported;
 125      }
 126  }
 127  new MP_export_mailinglist_mailinglist( __( 'Export a mailing list into another mailing list.', 'MailPress' ), __( 'Export mailing list into mailing list', 'MailPress' ) );
 128  }


Generated: Mon Jan 28 00:07:10 2019 Cross-referenced by PHPXref 0.7.1