[ Index ]

MailPress 544

[ 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($step = 0) 
  10      {
  11          if (isset($_GET['step']) && !empty($_GET['step'])) $step = (int) $_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>", MP_TXTDOM), "<a href='$file'>$file</a>") . '</p><p><strong>' . sprintf(__("<b>Number of records</b> : <i>%s</i>", MP_TXTDOM), $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  ?>
  40  <div>
  41      <p>
  42  <?php        _e('Howdy! Choose your mailing list and we&#8217;ll export the emails ... into a file.', MP_TXTDOM); ?>
  43          <br />
  44      </p>
  45      <form id='export-mailing-list' method='post' action='<?php echo MailPress_import . '&amp;mp_import=' . $this->id . '&amp;step=1'; ?>'>
  46          <p>
  47              <label for='download'><?php _e( 'Choose a mailing list :', MP_TXTDOM ); ?></label>
  48  <?php
  49              $dropdown_options = array('hierarchical' => true, 'show_count' => 0, 'orderby' => 'name', 'htmlid' => 'export_mailinglist', 'htmlname' => 'export_mailinglist', 'selected' => get_option(MailPress_mailinglist::option_name_default));
  50              MP_Mailinglist::dropdown($dropdown_options);
  51  ?>
  52          </p>
  53          <p class='submit'>
  54              <input type='submit' class='button' value='<?php esc_attr_e( 'Export', MP_TXTDOM ); ?>' />
  55          </p>
  56      </form>
  57  </div>
  58  <?php
  59      }
  60  
  61  // step 1
  62  
  63  	function export() 
  64      {
  65          $this->message_report(" EXPORTING  !");
  66  
  67          $id = $_POST['export_mailinglist'];
  68  
  69          $x = $id;
  70          $y = MP_Mailinglist::get_children($x, ', ', '');
  71          $x = ('' == $y) ? ' = ' . $x : ' IN (' . $x . $y . ') ';
  72  
  73  
  74          global $wpdb;
  75  
  76          $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');
  77          $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);
  78  
  79          if (empty($users))
  80          {
  81              $this->message_report(' **WARNING* ! Mailing list is empty !');
  82              return false;
  83          }
  84  
  85          $this->file = 'csv_export_mailing_list_' . $id . '_' . date('Ymd_Hi') . '.csv';
  86  
  87          require_once  'parsecsv/parsecsv.lib.php';
  88          $csv = new parseCSV();
  89          $r = file_put_contents(MP_ABSPATH . 'tmp/' . $this->file, $csv->unparse($users, $fields));
  90  
  91          if (!$r)
  92          {
  93              $this->message_report(' ***ERROR** ! Unable to write file');
  94              return false;
  95          }
  96  
  97          $file['name'] = $this->file;
  98          $file['tmp_name'] = MP_ABSPATH . 'tmp/' . $this->file;
  99          $file['type'] = 'csv';
 100  
 101          $this->url = $this->insert_attachment($file);
 102  
 103          if (!$this->url) $this->url = site_url() . '/' . MP_PATH . 'tmp/' . $this->file;
 104  
 105          $this->message_report('   SUCCESS  ! file available at ' . $this->url);
 106          return count($users);
 107      }
 108  }
 109  new MP_export_mailinglist(__('Export your mailing list in a <strong>csv</strong> file.', MP_TXTDOM), __('Export mailing list', MP_TXTDOM));
 110  }


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