[ Index ]

MailPress 544

[ 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($step = 0) 
   7      {
   8          if (isset($_GET['step']) && !empty($_GET['step'])) $step = (int) $_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>", MP_TXTDOM), "<a href='$file'>$file</a>") . '</p><p><strong>' . sprintf(__("<b>Number of records</b> : <i>%s</i>", MP_TXTDOM), $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  ?>
  37  <div>
  38      <p>
  39  <?php        _e('Howdy! Ready to export the emails ... into a file.', MP_TXTDOM); ?>
  40          <br />
  41      </p>
  42      <form id='export' method='post' action='<?php echo MailPress_import . '&amp;mp_import=' . $this->id . '&amp;step=1'; ?>'>
  43          <p>
  44              <br /><br /><br />
  45          </p>
  46          <p class='submit'>
  47              <input type='submit' class='button' value='<?php esc_attr_e( 'Export', MP_TXTDOM ); ?>' />
  48          </p>
  49      </form>
  50  </div>
  51  <?php
  52      }
  53  
  54  // step 1
  55  
  56  	function export() 
  57      {
  58          $this->message_report(" EXPORTING  !");
  59  
  60          global $wpdb;
  61  
  62          $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');
  63          $users = $wpdb->get_results("SELECT DISTINCT " . join(', ', $fields) . " FROM $wpdb->mp_users ; ", ARRAY_A);
  64  
  65          if (empty($users))
  66          {
  67              $this->message_report(' **WARNING* ! list is empty !');
  68              return false;
  69          }
  70  
  71          $this->file = 'csv_export_' . date('Ymd_Hi') . '.csv';
  72  
  73          require_once  'parsecsv/parsecsv.lib.php';
  74          $csv = new parseCSV();
  75          $r = file_put_contents(MP_ABSPATH . 'tmp/' . $this->file, $csv->unparse($users, $fields));
  76  
  77          if (!$r)
  78          {
  79              $this->message_report(' ***ERROR** ! Unable to write file');
  80              return false;
  81          }
  82  
  83          $file['name'] = $this->file;
  84          $file['tmp_name'] = MP_ABSPATH . 'tmp/' . $this->file;
  85          $file['type'] = 'csv';
  86  
  87          $this->url = $this->insert_attachment($file);
  88  
  89          if (!$this->url) $this->url = site_url() . '/' . MP_PATH . 'tmp/' . $this->file;
  90  
  91          $this->message_report('   SUCCESS  ! file available at ' . $this->url);
  92          return count($users);
  93      }
  94  }
  95  new MP_export(__('Export your MP users in a <strong>csv</strong> file.', MP_TXTDOM), __('Export', MP_TXTDOM));


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