[ Index ]

MailPress 7.1

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

title

Body

[close]

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

   1  <?php
   2  class MP_export extends MP_import_importer_
   3  {
   4      var $id = 'csv_export';
   5  
   6  	function dispatch() 
   7      {
   8          $step = $this->get_step();
   9  
  10          $this->header();
  11          switch ( $step ) 
  12          {
  13              case 0 :
  14                  $this->greet();
  15              break;
  16              case 1:
  17                  $this->start_trace( $step );
  18                      $export = $this->export();
  19                  $this->end_trace( true );
  20                  if ( $export )
  21                  {
  22                      $file = $this->url;
  23                      $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>' );
  24                  }
  25                  else 
  26                      $this->error( '<p><strong>' . $this->file . '</strong></p>' );
  27              break;
  28          }
  29          $this->footer();
  30      }
  31  
  32  // step 0
  33  
  34  	function greet() 
  35      {
  36          $args = array( 'mp_import' => $this->id, 'step' => 1 );
  37  ?>
  38  <div>
  39      <p>
  40  <?php        _e( 'Howdy! Ready to export the emails ... into a file.', 'MailPress' ); ?>
  41          <br />
  42      </p>
  43      <form id="export" method="post" action="<?php echo esc_url( add_query_arg( $args, MailPress_import ) ); ?>">
  44          <p>
  45              <br /><br /><br />
  46          </p>
  47          <p class="submit">
  48              <input type="submit" class="button" value="<?php echo esc_attr( __( 'Export', 'MailPress' ) ); ?>" />
  49          </p>
  50      </form>
  51  </div>
  52  <?php
  53      }
  54  
  55  // step 1
  56  
  57  	function export() 
  58      {
  59          $this->message_report( " EXPORTING  !" );
  60  
  61          global $wpdb;
  62  
  63          $fields = array( 'id', 'email', 'name', 'status', 'created', 'created_IP', 'created_agent', 'created_user_id', 'created_country', 'created_US_state', 'laststatus', 'laststatus_IP', 'laststatus_agent', 'laststatus_user_id' );
  64          $users = $wpdb->get_results( "SELECT DISTINCT " . join( ', ', $fields ) . " FROM $wpdb->mp_users ; ", ARRAY_A );
  65  
  66          if ( empty( $users ) )
  67          {
  68              $this->message_report( ' **WARNING* ! list is empty !' );
  69              return false;
  70          }
  71   
  72          $export_path     = 'import/' . get_current_blog_id() . '/';
  73          if ( !is_dir( MP_UPL_ABSPATH . $export_path ) ) mkdir( MP_UPL_ABSPATH . $export_path, 0777, true );
  74  
  75          $this->file = 'csv_export_' . date( 'Ymd_Hi' ) . '.csv';
  76  
  77          require_once  'parsecsv/parsecsv.lib.php';
  78          $csv = new parseCSV();
  79          $r = file_put_contents( MP_UPL_ABSPATH . $export_path . $this->file, $csv->unparse( $users, $fields ) );
  80  
  81          if ( !$r )
  82          {
  83              $this->message_report( ' ***ERROR** ! Unable to write file' );
  84              return false;
  85          }
  86  
  87          $file['name'] = $this->file;
  88          $file['tmp_name'] = MP_UPL_ABSPATH . $export_path . $this->file;
  89          $file['type'] = 'csv';
  90  
  91          $this->url = $this->insert_attachment( $file );
  92  
  93          if ( !$this->url ) $this->url = MP_UPL_URL . $export_path . $this->file;
  94  
  95          $this->message_report( '   SUCCESS  ! file available at ' . $this->url );
  96          return count( $users );
  97      }
  98  }
  99  new MP_export( __( 'Export your MP users in a <strong>csv</strong> file.', 'MailPress' ), __( 'Export', 'MailPress' ) );


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