[ Index ]

MailPress 544

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

title

Body

[close]

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

   1  <?php
   2  class MP_import_subscribe_to_comments extends MP_import_importer_
   3  {
   4      var $id = 'subscribe_to_comments';
   5  
   6  	function dispatch($step = 0) 
   7      {
   8          global $wpdb;
   9          $this->column_name = 'comment_subscribe';
  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                  $validate_data = $this->validate_data();
  22                  if ( $validate_data )
  23                  {
  24                      $sniff = $this->sniff();
  25                      $this->end_trace($sniff);
  26                      if ($sniff)
  27                          echo $this->step1;
  28                      else
  29                          $this->error($this->step1);
  30                  }
  31                  else
  32                  {
  33                      $this->end_trace($validate_data);
  34                      $this->error($this->step1);
  35                  }
  36              break;
  37              case 2:
  38                  $this->start_trace($step);
  39                  $import = $this->import();
  40                  $this->end_trace($import);
  41                  if ($import)
  42                      $this->success('<p>' . __("<b>Data imported</b>", MP_TXTDOM) . '</p>');
  43                  else 
  44                      $this->error();
  45              break;
  46          }
  47          $this->footer();
  48      }
  49  
  50  // step 0
  51  
  52  	function greet() {
  53          $x = "<div style='text-align:center;'>\n";
  54          $x .= "<br />\n";
  55          $x .= __('First Things First', MP_TXTDOM);
  56          $x .= "<br />\n";        $x .= "<br />\n";
  57          $x .= __("Before importing your 'Subscribe to comments' datas : ", MP_TXTDOM);
  58          $x .= "<br />\n";        $x .= "<br />\n";
  59          $x .= "<span style='color:red;font-weight:bold;'>";
  60          $x .= __('SAVE YOUR DATABASE', MP_TXTDOM);
  61          $x .= "</span>\n";
  62          $x .= "<br />\n";        $x .= "<br />\n";
  63          $x .= __('and make sure you can restore it !', MP_TXTDOM);
  64          $x .= "<br />\n";        $x .= "<br />\n";
  65          $x .= "</div>\n";
  66  ?>
  67  <?php MP_AdminPage::message($x, false); ?>
  68  <br />
  69  <div>
  70      <?php _e('Howdy! Ready to import your <b>Subscribe to comments</b> data into <b>MailPress</b> ...', MP_TXTDOM); ?>
  71  
  72      <p><?php _e('<b>Subscribe to comments</b> data are stored into the following table :', MP_TXTDOM); ?></p>
  73      <ol>
  74          <li>comments
  75              <p>
  76                  <?php _e('In this table, subscribers can subscribe to posts comments.', MP_TXTDOM); ?>
  77                  <br />
  78                  <?php _e('You will be able to convert these subscriptions to MailPress.', MP_TXTDOM); ?>
  79              </p>
  80          </li>
  81      </ol>
  82      <br />
  83      <p><?php _e('Note : If a subscriber already exists in MailPress, only the subscriptions to comments are added.', MP_TXTDOM); ?></p>
  84  
  85      <form method='post' action='<?php echo MailPress_import; ?>&amp;mp_import=subscribe_to_comments&amp;step=1'>
  86          <p class='submit'>
  87              <input class='button-primary' type='submit' name='Submit' value='<?php  _e('Continue', MP_TXTDOM); ?>' />
  88          </p>
  89      </form>
  90  </div>
  91  <?php
  92      }
  93  
  94  // step 1
  95  
  96  	function validate_data()
  97      {
  98          $this->message_report(" ANALYSIS   !");
  99  
 100          global $wpdb;
 101          foreach ( (array) $wpdb->get_col("DESC $wpdb->comments", 0) as $column )
 102          {
 103              if ($column == $this->column_name)
 104              {
 105                  $this->message_report('            ! Subscribe to comments column >>> ' . $this->column_name . ' detected in >>> ' . $wpdb->comments);
 106                  return true;
 107              }
 108          }
 109          $this->message_report('** ERROR ** ! Subscribe to comments column NOT in ' . $wpdb->comments);
 110  
 111           $this->step1  = "<style type='text/css'> .general th {font-weight:bold;width:auto;} .general td, .general th {border:solid 1px #555;margin:0;padding:5px;vertical-align:top;} </style>";
 112           $this->step1 .= "<div>\n";
 113           $this->step1 .= "<h3>" . __('Data Analysis', MP_TXTDOM) . "</h3>\n";
 114           $this->step1 .= "<table class='form-table'>\n";
 115           $this->step1 .= "<tr>\n";
 116           $this->step1 .= "<th>" . $this->column_name . "</th>\n";
 117           $this->step1 .= "<td>\n";
 118           $this->step1 .= "<p>" . sprintf(__('*** ERROR *** Column not detected in %1$s', MP_TXTDOM), $wpdb->comments) . "</p>\n";
 119           $this->step1 .= "</td>\n";
 120           $this->step1 .= "</tr>\n";
 121           $this->step1 .= "</table>\n";
 122           $this->step1 .= '</div>';
 123  
 124          return false;
 125      }
 126  
 127  	function sniff() 
 128      {
 129          global $wpdb;
 130          $import = false;
 131  
 132          $this->step1  = '';
 133  
 134          $subs = $wpdb->get_results( "SELECT distinct LCASE(comment_author_email) as email FROM $wpdb->comments WHERE comment_subscribe='Y' AND comment_approved = '1' " );
 135  
 136          if ( $subs )
 137          {
 138               $head1  = "<style type='text/css'> .general th {font-weight:bold;width:auto;} .general td, .general th {border:solid 1px #555;margin:0;padding:5px;vertical-align:top;} </style>";
 139               $head1 .= "<h3>" . __('Data Analysis', MP_TXTDOM) . "</h3>\n";
 140               $head1 .= "<form action='" . MailPress_import . "&amp;mp_import=subscribe_to_comments&amp;step=2' method='post'><table class='form-table'>\n";
 141  
 142               $foot1 = "</table>\n";
 143              $foot1 .= "<p class='submit'>\n";
 144              $foot1 .= "<input type='submit' value='" . esc_attr( __('Submit')) . "' />\n";
 145              $foot1 .= "</p>\n";
 146              $foot1 .= "</form>\n";
 147  
 148              $import = true; 
 149          }
 150          else
 151          {     
 152               $head1  = "<style type='text/css'> .general th {font-weight:bold;width:auto;} .general td, .general th {border:solid 1px #555;margin:0;padding:5px;vertical-align:top;} </style>";
 153               $head1 .= "<h3>" . __('Data Analysis', MP_TXTDOM) . "</h3>\n";
 154              $head1 = "<table class='form-table'>\n";
 155  
 156               $foot1 = "</table>\n";
 157          }
 158  
 159          if ($subs)
 160          {
 161              $this->message_report('             ! ' . sprintf('%1$s subscriber(s) found', count($subs) ));
 162  
 163              $this->step1 .= "<tr>\n";
 164              $this->step1 .= "<th>" . $wpdb->comments . "</th>\n";
 165              $this->step1 .= "<td>\n";
 166              $this->step1 .= "<p>" .  sprintf(__('%1$s subscriber(s) found', MP_TXTDOM), count($subs) ) . "</p>\n";
 167              $this->step1 .= "</td>\n";
 168              $this->step1 .= "</tr>\n";
 169          }
 170          else
 171          {
 172              $this->message_report('             ! Comments table: no data');
 173  
 174              $this->step1 .= "<tr>\n";
 175              $this->step1 .= "<th>" . $wpdb->comments . "</th>\n";
 176              $this->step1 .= "<td>\n";
 177              $this->step1 .= "<p>" .  __('no data', MP_TXTDOM) . "</p>\n";
 178              $this->step1 .= "</td>\n";
 179              $this->step1 .= "</tr>\n";
 180          }
 181          $this->step1 = $head1 . $this->step1 . $foot1;
 182          return $import;
 183      }
 184  
 185  // step 2
 186  
 187  	function import() 
 188      {
 189          global $wpdb;
 190          $this->import_subscribe_to_comments();
 191          return true;
 192      }
 193  
 194  	function import_subscribe_to_comments() 
 195      {
 196          global $wpdb;
 197  
 198          $subs = $wpdb->get_results( "SELECT comment_author_email as email, comment_post_ID as post_ID FROM $wpdb->comments WHERE comment_subscribe='Y' AND comment_approved = '1' order by email " );
 199  
 200          if ($subs) 
 201          {
 202              $this->message_report(" IMPORTING  !");
 203  
 204              $email = '';
 205              foreach ($subs as $sub)
 206              {
 207                  if ($email != $sub->email)
 208                  {
 209                      $email = $sub->email;
 210                      $mp_user_id = $this->sync_mp_user($email, 'waiting');
 211                  }
 212  
 213                  if ($mp_user_id)
 214                  {
 215                      $postid = $sub->post_ID; 
 216                      update_post_meta($postid, '_MailPress_subscribe_to_comments_', $mp_user_id);
 217                      new MP_Stat('c', $postid, 1);
 218                      $this->message_report(" meta       ! user [18]=>  subscribed to post #" . $postid);
 219                  }
 220              }
 221          }
 222          elseif($wpdb->last_error)
 223              $this->message_report("** ERROR ** ! " . sprintf('Database error : %1$s', $wpdb->last_error));
 224          else
 225              $this->message_report("** ERROR ** ! no data");
 226          return true;
 227      }
 228  }
 229  new MP_import_subscribe_to_comments(__('Import data from <strong>subscribe to comments</strong> plugin.', MP_TXTDOM), __('Import from Subscribe to comments', MP_TXTDOM));


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