[ Index ]

MailPress 7.1

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

title

Body

[close]

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

   1  <?php
   2  if ( class_exists( 'MailPress_mailinglist' ) )
   3  {
   4  
   5  class MP_export_mailinglist extends MP_import_importer_
   6  {
   7      var $id = 'csv_export_mailing_list';
   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                      $export = $this->export();
  22                  $this->end_trace( true );
  23                  if ( $export )
  24                  {
  25                      $file = $this->url;
  26                      $this->success( '<p>' . sprintf( __( "<b>File exported</b> : <i>%s</i>", 'MailPress' ), '<a href="' . $file . '">' . $file . '</a>' ) . '</p><p><strong>' . sprintf( __( "<b>Number of records</b> : <i>%s</i>", 'MailPress' ), $export ) . '</strong></p>' );
  27                  }
  28                  else 
  29                      $this->error( '<p><strong>' . $this->file . '</strong></p>' );
  30              break;
  31          }
  32          $this->footer();
  33      }
  34  
  35  // step 0
  36  
  37  	function greet() 
  38      {
  39          $args = array( 'mp_import' => $this->id, 'step' => 1 );
  40  ?>
  41  <div>
  42      <p>
  43  <?php        _e( 'Howdy! Choose your mailing list and we&#8217;ll export the emails ... into a file.', 'MailPress' ); ?>
  44          <br />
  45      </p>
  46      <form id="export-mailing-list" method="post" action="<?php echo esc_url( add_query_arg( $args, MailPress_import ) ); ?>">
  47          <p>
  48              <label for="download"><?php _e( 'Choose a mailing list :', 'MailPress' ); ?></label>
  49  <?php
  50              $dropdown_options = array( 'hierarchical' => true, 'show_count' => 0, 'orderby' => 'name', 'htmlid' => 'export_mailinglist', 'htmlname' => 'export_mailinglist', 'selected' => get_option( MailPress_mailinglist::option_name_default ) );
  51              MP_Mailinglist::dropdown( $dropdown_options );
  52  ?>
  53          </p>
  54          <p class="submit">
  55              <input type="submit" class="button" value="<?php echo esc_attr( __( 'Export', 'MailPress' ) ); ?>" />
  56          </p>
  57      </form>
  58  </div>
  59  <?php
  60      }
  61  
  62  // step 1
  63  
  64  	function export() 
  65      {
  66          $this->message_report( " EXPORTING  !" );
  67  
  68          $id = MP_AdminPage::$pst_['export_mailinglist'];
  69  
  70          $x = $id;
  71          $y = MP_Mailinglist::get_children( $x, ', ', '' );
  72          $x = ( '' == $y ) ? ' = ' . $x : ' IN ( ' . $x . $y . ' ) ';
  73  
  74  
  75          global $wpdb;
  76  
  77          $fields = array( 'c.id', 'c.email', 'c.name', 'c.status', 'c.created', 'c.created_IP', 'c.created_agent', 'c.created_user_id', 'c.created_country', 'c.created_US_state', 'c.laststatus', 'c.laststatus_IP', 'c.laststatus_agent', 'c.laststatus_user_id' );
  78          $users = $wpdb->get_results( "SELECT DISTINCT " . join( ', ', $fields ) . " 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 $x AND c.id = b.object_id AND c.status = 'active'; ", ARRAY_A );
  79  
  80          if ( empty( $users ) )
  81          {
  82              $this->message_report( ' **WARNING* ! Mailing list is empty !' );
  83              return false;
  84          }
  85  
  86          $export_path     = 'import/' . get_current_blog_id() . '/';
  87          if ( !is_dir( MP_UPL_ABSPATH . $export_path ) ) mkdir( MP_UPL_ABSPATH . $export_path, 0777, true );
  88  
  89          $this->file = 'csv_export_mailing_list_' . $id . '_' . date( 'Ymd_Hi' ) . '.csv';
  90  
  91          require_once  'parsecsv/parsecsv.lib.php';
  92          $csv = new parseCSV();
  93          $r = file_put_contents( MP_UPL_ABSPATH . $export_path . $this->file, $csv->unparse( $users, $fields ) );
  94  
  95          if ( !$r )
  96          {
  97              $this->message_report( ' ***ERROR** ! Unable to write file' );
  98              return false;
  99          }
 100  
 101          $file['name'] = $this->file;
 102          $file['tmp_name'] = MP_UPL_ABSPATH . $export_path . $this->file;
 103          $file['type'] = 'csv';
 104  
 105          $this->url = $this->insert_attachment( $file );
 106  
 107          if ( !$this->url ) $this->url =  MP_UPL_URL . $export_path . $this->file;
 108  
 109          $this->message_report( '   SUCCESS  ! file available at ' . $this->url );
 110          return count( $users );
 111      }
 112  }
 113  new MP_export_mailinglist( __( 'Export your mailing list in a <strong>csv</strong> file.', 'MailPress' ), __( 'Export mailing list', 'MailPress' ) );
 114  }


Generated: Mon Mar 11 18:33:33 2019 Cross-referenced by PHPXref 0.7.1