[ Index ]

MailPress 7.1

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


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