[ Index ]

MailPress 544

[ 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($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                      $this->message_report(" **  INFO * ! 'From' Mailing list is #" . $_POST['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  ?>
  43  <div>
  44      <p>
  45  <?php        _e('Howdy!', MP_TXTDOM); ?>
  46          <br />
  47      </p>
  48      <form id='export-mailing-list' method='post' action='<?php echo MailPress_import . '&amp;mp_import=' . $this->id . '&amp;step=1'; ?>'>
  49          <p>
  50              <label for='download'><?php _e( "Choose the 'From' mailing list :", MP_TXTDOM ); ?></label>
  51  <?php
  52              $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));
  53              MP_Mailinglist::dropdown($dropdown_options);
  54  ?>
  55          </p>
  56          <p class='submit'>
  57              <input type='submit' class='button' value='<?php esc_attr_e( 'Continue', MP_TXTDOM ); ?>' />
  58          </p>
  59      </form>
  60  </div>
  61  <?php
  62      }
  63  
  64  // step 1
  65  
  66  	function step1() 
  67      { 
  68  ?>
  69  <div>
  70      <p>
  71  <?php        printf(__('From mailing list is #%s', MP_TXTDOM), $_POST['export_mailinglist']); ?>
  72      </p>
  73      <form id='export-mailing-list' method='post' action='<?php echo MailPress_import . '&amp;mp_import=' . $this->id . '&amp;step=2'; ?>'>
  74          <p>
  75              <label for='download'><?php _e( "Choose the 'To' mailing list :", MP_TXTDOM ); ?></label>
  76              <input type='hidden' name='from_mailinglist' value='<?php echo $_POST['export_mailinglist']; ?>' />
  77  <?php
  78              $dropdown_options = array('hide_empty' => 0, 'hierarchical' => true, 'show_count' => 0, 'orderby' => 'name', 'htmlid' => 'to_mailinglist', 'htmlname' => 'to_mailinglist', 'exclude' => $_POST['export_mailinglist'] );
  79              MP_Mailinglist::dropdown($dropdown_options);
  80  ?>
  81          </p>
  82          <p class='submit'>
  83              <input type='submit' class='button' value='<?php esc_attr_e( 'Export', MP_TXTDOM ); ?>' />
  84          </p>
  85      </form>
  86  </div>
  87  <?php
  88      }
  89  
  90  // step 2
  91  	function export() 
  92      {
  93          $count = $exported = 0;
  94          $from = $_POST['from_mailinglist'];
  95          $to   = $_POST['to_mailinglist'];
  96  
  97          $this->message_report(" EXPORTING  ! mailing list #{$from} to mailing list #{$to}");
  98  
  99          global $wpdb;
 100  
 101          $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 ;");
 102  
 103          foreach ($users as $user)
 104          {
 105              $count++;
 106  
 107              $mp_user_mls = MP_Mailinglist::get_object_terms($user->id);
 108              if (!in_array($to, $mp_user_mls)) 
 109              {
 110                  $mp_user_mls[] = $to;
 111                  if (MP_Mailinglist::set_object_terms($user->id, $mp_user_mls)) $exported++;
 112                  continue;
 113              }
 114              $this->message_report(" **WARNING* ! mp_user #{$user->id} already in mailing list #{$to} !");
 115          }
 116  
 117          if (!$count) 
 118              $this->message_report(" **WARNING* ! 'From' Mailing list is empty !");
 119          else
 120              $this->message_report(" **EXPORTED*! read in #{$from} : ". $count .", imported in #{$to} : ". $exported );
 121  
 122          return $exported;
 123      }
 124  }
 125  new MP_export_mailinglist_mailinglist(__('Export a mailing list into another mailing list.', MP_TXTDOM), __('Export mailing list into mailing list', MP_TXTDOM));
 126  }


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