[ Index ]

MailPress 7.2

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

title

Body

[close]

/mp-includes/class/options/privacy/erasers/ -> mails.php (source)

   1  <?php /* erase or anonymize mails */
   2  class MP_WP_Privacy_eraser_mails extends MP_WP_privacy_eraser_
   3  {
   4      const per_page = 100;
   5  
   6      var $priority = 46;
   7  
   8  	function eraser( $email, $page = 1 )
   9      {
  10          global $wpdb;
  11  
  12          $mp_user = $this->get_user( $email );
  13  
  14          /*  */
  15  
  16          $mails = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS id, toemail FROM $wpdb->mp_mails WHERE toemail LIKE '%{$email}%' ORDER BY id ASC LIMIT 0, " . self::per_page . ";" );
  17  
  18          if ( !$mails ) return $this->erase;
  19  
  20          $total = $wpdb->get_var( "SELECT FOUND_ROWS()" );
  21  
  22          /*  */
  23  
  24          $anonymized = $deleted = $retained = array();
  25  
  26          foreach ( (array) $mails as $mail )
  27          {
  28              if ( $mail->toemail == $email )
  29                  ( $this->delete( $mail ) ) ?  $deleted[] = $mail->id : $retained[] = $mail->id;
  30              else
  31                  ( $this->anonymize( $mail, $mp_user, $email ) ) ? $anonymized[] = $mail->id : $retained[] = $mail->id;
  32          }
  33  
  34          $this->erase['items_removed'] = count( $anonymized ) + count( $deleted );
  35          $this->erase['items_retained']= count( $retained );
  36  
  37          if ( !empty( $retained )   ) $this->erase['messages'][] = sprintf( __( 'Process "%1$s" aborted for %2$s : (%3$s).', 'MailPress' ), $this->name, $email, implode( ', ', $retained ) );
  38          if ( !empty( $anonymized ) ) $this->erase['messages'][] = sprintf( __( 'Mails sent to %1$s have been successfully anonymized (%2$s).', 'MailPress' ), $email, implode( ', ', $anonymized ) );
  39          if ( !empty( $deleted )    ) $this->erase['messages'][] = sprintf( __( 'Mails sent to %1$s have been successfully deleted (%2$s).', 'MailPress' ), $email, implode( ', ', $deleted ) );
  40  
  41          if ( $retained ) return $this->erase; // abort otherwise we enter in a loop
  42   
  43          $this->erase['done'] = ( $total <= self::per_page );
  44  
  45          return $this->erase;
  46      }
  47  
  48  	function anonymize( $mail, $mp_user, $email )
  49      {
  50          global $wpdb;
  51  
  52          if ( !is_serialized( $mail->toemail ) ) return false;
  53  
  54          $toemails = unserialize( $mail->toemail );
  55  
  56          if ( !isset( $toemails[$email] ) ) return true;
  57  
  58          $a = $toemails[$email];
  59  
  60          $mp_user_id = $a['{{_user_id}}'] ?? $mp_user->id      ?? NULL;
  61          $confkey    = $a['{{_confkey}}'] ?? $mp_user->confkey ?? NULL;
  62  
  63          unset( $toemails[$email] );
  64  
  65          if ( isset( $mp_user_id ) )
  66          {
  67              $toemails[$mp_user_id]['{{_user_id}}'] = $mp_user_id;
  68              if ( isset( $confkey ) ) 
  69                  $toemails[$mp_user_id]['{{_confkey}}'] = $confkey;
  70          }
  71  
  72          $data = $format = $where = $where_format = array();
  73  
  74          $data['toemail'] = serialize( $toemails );    $format[] = '%s';
  75  
  76          $where['id']      = ( int ) $mail->id;        $where_format[] = '%d';
  77  
  78          return $wpdb->update( $wpdb->mp_mails, $data, $where, $format, $where_format );
  79      }
  80  
  81  	function delete( $mail )
  82      {
  83          return MP_Mail::delete( $mail->id );
  84      }
  85  }
  86  new MP_WP_Privacy_eraser_mails( __( 'Subscriber > Mail Anonymizer', 'MailPress' ) );


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1