[ Index ]

MailPress 544

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

title

Body

[close]

/mp-includes/class/ -> MP_Pluggable.class.php (source)

   1  <?php
   2  class MP_Pluggable
   3  {
   4  	public static function wp_mail( $to, $subject, $message, $headers = '', $attachments = false ) 
   5      {
   6      // Compact the input, apply the filters, and extract them back out
   7          extract( apply_filters('wp_mail', compact( 'to', 'subject', 'message', 'headers' ) ) );
   8  
   9          if ( !is_array($attachments) )
  10              $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
  11  
  12          $mail =  new stdClass();
  13  
  14      // Attachments
  15  
  16          if (is_array($attachments))
  17          {
  18              $f = true;
  19              $attachments = @str_replace("\\", "/", $attachments);
  20  
  21              foreach ($attachments as $attachment)
  22              {
  23                  if (@is_file($attachment))
  24                  {
  25                      if ($f) $mail->id = MP_Mail::get_id('wp_mail_3.0');
  26  
  27                      $object = array(    'name'     => basename($attachment), 
  28                                  'mime_type'    => 'application/octet-stream', 
  29                                  'file'    => '', 
  30                                  'file_fullpath'    => $attachment, 
  31                                  'guid'     => ''
  32                      );
  33                      MP_Mail_meta::add( $mail->id, '_MailPress_attached_file', $object );
  34                  }
  35                  $f = false;
  36              }
  37          }
  38  
  39      // Headers
  40          if ( !empty( $headers ) && !is_array( $headers ) )
  41          {                                            // Explode the headers out, so this function can take both
  42                                                      // string headers and an array of headers.
  43              $tempheaders = (array) explode( "\n", $headers );
  44              $headers = array();
  45              if ( !empty( $tempheaders ) ) 
  46              {                                        // Iterate through the raw headers
  47                  foreach ( $tempheaders as $header ) 
  48                  {
  49                      if ( strpos($header, ':') === false ) continue;
  50                                                      // Explode them out
  51                      list( $name, $content ) = explode( ':', trim( $header ), 2 );
  52                                                      // Cleanup crew
  53                      $name = trim( $name );
  54                      $content = trim( $content );
  55                                                      // Mainly for legacy -- process a From: header if it's there
  56                      switch (true)
  57                      {
  58                          case ( 'from' == strtolower($name) ) :
  59                              if ( strpos($content, '<' ) !== false ) 
  60                              {
  61                                                      // So... making my life hard again?
  62                                  $from_name = substr( $content, 0, strpos( $content, '<' ) - 1 );
  63                                  $from_name = str_replace( '"', '', $from_name );
  64                                  $from_name = trim( $from_name );
  65      
  66                                  $from_email = substr( $content, strpos( $content, '<' ) + 1 );
  67                                  $from_email = str_replace( '>', '', $from_email );
  68                                  $from_email = trim( $from_email );
  69                              } 
  70                              else 
  71                              {
  72                                  $from_name = trim( $content );
  73                              }
  74                          break;
  75                          case ( 'content-type' == strtolower($name) ) :
  76                              if ( strpos( $content, ';' ) !== false ) 
  77                              {
  78                                  list( $type, $charset ) = explode( ';', $content );
  79                                  $content_type = trim( $type );
  80                                  $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset ) );
  81                              } 
  82                              else 
  83                              {
  84                                  $content_type = trim( $content );
  85                              }
  86                          break;
  87                          default :
  88                              $headers[trim( $name )] = trim( $content );
  89                          break;
  90                      }
  91                  }
  92              }
  93          }
  94                                                      // From email and name
  95                                                      // Set the from name and email
  96          if ( isset( $from_email ) ) 
  97          {
  98              $mail->fromemail  = apply_filters('wp_mail_from', $from_email );
  99              $mail->fromname   = apply_filters('wp_mail_from_name', $from_name );
 100          }
 101                                                      // Set destination address
 102  
 103  // Set destination addresses
 104  //        $mail->toemail = (is_array($to)) ? $to['email'] : $to;
 105  //        $mail->toname  = (is_array($to)) ? $to['name']  : '';
 106  
 107                  if (!is_array($to)) $to = explode(',', $to);
 108  //
 109          $mail->replacements = $mail->recipients = array();
 110          foreach((array) $to as $recipient){
 111              // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
 112              if(preg_match('/(.*)<(.+)>/usS', $recipient, $matches) && (count($matches) == 3))
 113                  $mail->recipients[$matches[2]] = $matches[1];
 114              else
 115                  $mail->recipients[$recipient] = '';
 116          }
 117                                                      // Set mail's subject and body
 118          $mail->subject = $subject;
 119  
 120          if (is_array($message))
 121          {
 122              if (isset($message['plaintext']))      $mail->plaintext = $message['plaintext'];
 123              if (isset($message['text/plain']))     $mail->plaintext = $message['text/plain'];
 124              if (isset($message['html']))      $mail->html = $message['html'];
 125              if (isset($message['text/html']))      $mail->html = $message['text/html'];
 126          }
 127          else
 128          {
 129              $mail->content = $message;
 130          }
 131  
 132          if (!empty( $headers )) $mail->headers = $headers;
 133  
 134          return MailPress::mail($mail);
 135      }
 136  
 137  	public static function wp_notify_postauthor($comment_id, $comment_type='') 
 138      {
 139          $comment = get_comment( $comment_id );
 140          $post    = get_post( $comment->comment_post_ID );
 141          $author  = get_userdata( $post->post_author );
 142  
 143          // The comment was left by the author
 144          if ( $comment->user_id == $post->post_author )
 145              return false;
 146  
 147          // The author moderated a comment on his own post
 148          if ( $post->post_author == get_current_user_id() )
 149              return false;
 150  
 151          // If there's no email to send the comment to
 152          if ( '' == $author->user_email )
 153              return false;
 154  
 155          $comment->author_domain = @gethostbyaddr($comment->comment_author_IP);
 156  
 157          $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
 158  
 159          $url['comments'] = get_permalink($comment->comment_post_ID) . '#comments';
 160          $url['permalink']= get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment_id;
 161          $url['trash']  = admin_url("comment.php?action=trash&c={$comment->comment_ID}");
 162          $url['delete'] = admin_url("comment.php?action=delete&c={$comment->comment_ID}");
 163          $url['spam']   = admin_url("comment.php?action=spam&c={$comment->comment_ID}");
 164  
 165          switch ($comment->comment_type)
 166          {
 167              case 'trackback' :
 168                  $notify_message  = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "<br />\r\n";
 169                  $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment->author_domain ) . "<br />\r\n";
 170                  $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "<br />\r\n";
 171                  $notify_message .= __('Excerpt: ') . "<br />\r\n" . apply_filters('comment_text', $comment->comment_content) . "<br />\r\n<br />\r\n";
 172                  $notify_message .= __('You can see all trackbacks on this post here: ') . "<br />\r\n";
 173  
 174                  $subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title );
 175              break;
 176              case 'pingback' :
 177                  $notify_message  = sprintf( __( 'New pingback on your post "%s"' ), $post->post_title ) . "<br />\r\n";
 178                  $notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment->author_domain ) . "<br />\r\n";
 179                  $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "<br />\r\n";
 180                  $notify_message .= __('Excerpt: ') . "<br />\r\n" . sprintf('[...] %s [...]', apply_filters('comment_text', $comment->comment_content) ) . "<br />\r\n<br />\r\n";
 181                  $notify_message .= __('You can see all pingbacks on this post here: ') . "<br />\r\n";
 182              
 183                  $subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title );
 184              break;
 185              default: //Comments
 186                  $notify_message  = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "<br />\r\n";
 187                  $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment->author_domain ) . "<br />\r\n";
 188                  $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "<br />\r\n";
 189                  $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "<br />\r\n";
 190                  $notify_message .= sprintf( __('Whois  : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "<br />\r\n";
 191                  $notify_message .= __('Comment: ') . "<br />\r\n" . apply_filters('comment_text', $comment->comment_content) . "<br />\r\n<br />\r\n";
 192                  $notify_message .= __('You can see all comments on this post here: ') . "<br />\r\n";
 193              
 194                  $subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title );
 195              break;
 196          }
 197          $notify_message .= $url['comments'] . "<br />\r\n<br />\r\n";
 198          $notify_message .= sprintf( __('Permalink: %s'), $url['comments']) . "<br />\r\n";
 199  
 200          if ( EMPTY_TRASH_DAYS )
 201              $notify_message .= sprintf( __('Trash it: %s'), $url['trash'] ) . "<br />\r\n";
 202          else
 203              $notify_message .= sprintf( __('Delete it: %s'), $url['delete'] ) . "<br />\r\n";
 204          $notify_message .= sprintf( __('Spam it: %s'), $url['spam'] ) . "<br />\r\n";
 205  
 206          $mail = new stdClass();
 207          $mail->Template    = 'moderate';
 208          $mail->toemail     = $author->user_email;
 209          $mail->toname     = $author->display_name;
 210          $mail->subject     = $subject;
 211          $mail->content     = $notify_message;
 212  
 213          $mail->advanced = new stdClass();
 214          $mail->advanced->comment       = $comment;
 215          $mail->advanced->user          = $author;
 216          unset ($post->post_content, $post->post_excerpt);
 217          $mail->advanced->post          = $post;
 218          $mail->advanced->url           = $url;
 219  
 220          $mail->the_title          = $post->post_title; 
 221  
 222          /* deprecated */
 223              $mail->c = new stdClass();
 224              $mail->c->id        = $comment->comment_ID;
 225              $mail->c->post_ID     = $comment->comment_post_ID;
 226              $mail->c->author        = $comment->comment_author;
 227              $mail->c->author_IP     = $comment->comment_author_IP;
 228              $mail->c->email        = $comment->comment_author_email;
 229              $mail->c->url         = $comment->comment_author_url;
 230              $mail->c->domain        = $comment->author_domain;
 231              $mail->c->content     = $comment->comment_content;
 232              $mail->c->type        = $comment->comment_type;
 233          /* deprecated */
 234  
 235          return MailPress::mail($mail);
 236      }
 237  
 238  	public static function wp_notify_moderator($comment_id) 
 239      {
 240          global $wpdb;
 241  
 242          if ( 0 == get_option( 'moderation_notify' ) )
 243              return true;
 244  
 245          $comment = get_comment($comment_id);
 246          $post = get_post($comment->comment_post_ID);
 247          $user = get_userdata( $post->post_author );
 248          // Send to the administration and to the post author if the author can modify the comment.
 249          $email_to = array( get_option('admin_email') );
 250          if ( user_can($user->ID, 'edit_comment', $comment_id) && !empty($user->user_email) && ( get_option('admin_email') != $user->user_email) )
 251              $email_to[] = $user->user_email;
 252  
 253          $comment->author_domain = @gethostbyaddr($comment->comment_author_IP);
 254          $comment->waiting       = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");
 255  
 256          $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
 257  
 258          $url['approve']= admin_url("comment.php?action=approve&c=$comment_id");
 259          $url['trash']  = admin_url("comment.php?action=trash&c=$comment_id");
 260          $url['delete'] = admin_url("comment.php?action=delete&c=$comment_id");
 261          $url['spam']   = admin_url("comment.php?action=spam&c=$comment_id");
 262          $url['moderate'] = admin_url("edit-comments.php?comment_status=moderated");
 263  
 264          switch ($comment->comment_type)
 265          {
 266              case 'trackback':
 267                  $notify_message  = sprintf( __('A new trackback on the post "%s" is waiting for your approval'), $post->post_title ) . "<br />\r\n";
 268                  $notify_message .= get_permalink($comment->comment_post_ID) . "<br />\r\n<br />\r\n";
 269                  $notify_message .= sprintf( __('Website : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment->author_domain ) . "<br />\r\n";
 270                  $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "<br />\r\n";
 271                  $notify_message .= __('Trackback excerpt: ') . "<br />\r\n" . apply_filters('comment_text', $comment->comment_content) . "<br />\r\n<br />\r\n";
 272              break;
 273              case 'pingback':
 274                  $notify_message  = sprintf( __('A new pingback on the post "%s" is waiting for your approval'), $post->post_title ) . "<br />\r\n";
 275                  $notify_message .= get_permalink($comment->comment_post_ID) . "<br />\r\n<br />\r\n";
 276                  $notify_message .= sprintf( __('Website : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment->author_domain ) . "<br />\r\n";
 277                  $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "<br />\r\n";
 278                  $notify_message .= __('Pingback excerpt: ') . "<br />\r\n" . apply_filters('comment_text', $comment->comment_content) . "<br />\r\n<br />\r\n";
 279              break;
 280              default: //Comments
 281                  $notify_message  = sprintf( __('A new comment on the post "%s" is waiting for your approval'), $post->post_title ) . "<br />\r\n";
 282                  $notify_message .= get_permalink($comment->comment_post_ID) . "<br />\r\n<br />\r\n";
 283                  $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment->author_domain ) . "<br />\r\n";    
 284                  $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "<br />\r\n";
 285                  $notify_message .= sprintf( __('URL    : %s'), $comment->comment_author_url ) . "<br />\r\n";
 286                  $notify_message .= sprintf( __('Whois  : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "<br />\r\n";
 287                  $notify_message .= __('Comment: ') . "<br />\r\n" . apply_filters('comment_text', $comment->comment_content) . "<br />\r\n<br />\r\n";
 288              break;
 289          }
 290  
 291          $notify_message .= sprintf( __('Approve it: %s'), $url['approve'] ) . "<br />\r\n";
 292          if ( EMPTY_TRASH_DAYS )
 293              $notify_message .= sprintf( __('Trash it: %s'), $url['trash'] ) . "<br />\r\n";
 294          else
 295              $notify_message .= sprintf( __('Delete it: %s'), $url['delete'] ) . "<br />\r\n";
 296          $notify_message .= sprintf( __('Spam it: %s'), $url['spam'] ) . "<br />\r\n";
 297  
 298          $notify_message .= sprintf( _n('Currently %s comment is waiting for approval. Please visit the moderation panel:',
 299               'Currently %s comments are waiting for approval. Please visit the moderation panel:', $comment->waiting), number_format_i18n($comment->waiting) ) . "<br />\r\n";
 300          $notify_message .= $url['moderate'] . "<br />\r\n";
 301      
 302          $subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), $blogname, $post->post_title );
 303  
 304          $notify_message = apply_filters('comment_moderation_text', $notify_message, $comment->comment_ID);
 305          $subject = apply_filters('comment_moderation_subject', $subject, $comment->comment_ID);
 306  
 307          $mail = new stdClass();
 308          $mail->Template    = 'moderate';
 309          $mail->toemail     = $user->user_email;
 310          $mail->toname     = $user->display_name;
 311          $mail->subject     = $subject;
 312          $mail->content     = $notify_message;
 313  
 314              $mail->advanced = new stdClass();
 315              $mail->advanced->comment = $comment;
 316              $mail->advanced->user    = $user;    
 317              unset ($post->post_content, $post->post_excerpt);
 318              $mail->advanced->post    = $post;
 319              $mail->advanced->url     = $url;
 320          
 321              $mail->the_title          = $post->post_title; 
 322      
 323              /* deprecated */
 324                  $mail->c = new stdClass();
 325                  $mail->c->id        = $comment->comment_ID;
 326                  $mail->c->post_ID     = $comment->comment_post_ID;
 327                  $mail->c->author         = $comment->comment_author;
 328                  $mail->c->author_IP     = $comment->comment_author_IP;
 329                  $mail->c->email         = $comment->comment_author_email;
 330                  $mail->c->url         = $comment->comment_author_url;
 331                  $mail->c->domain         = $comment->author_domain;
 332                  $mail->c->content     = $comment->comment_content;
 333                  $mail->c->type        = $comment->comment_type;
 334                  $mail->p = new stdClass();
 335                  $mail->p->title        = $post->post_title;
 336              /* deprecated */
 337      
 338          foreach ( $email_to as $email )
 339          {
 340              $mail->toemail = $email;
 341              MailPress::mail($mail);
 342          }
 343          return true;
 344      }
 345  
 346  	public static function wp_password_change_notification(&$user) 
 347      {
 348      // send a copy of password change notification to the admin
 349      // but check to see if it's the admin whose password we're changing, and skip this
 350          if ( $user->user_email == get_option('admin_email') ) return;
 351  
 352          $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
 353  
 354          $mail = new stdClass();
 355          $mail->Template    = 'changed_pwd';
 356          $mail->toemail     = get_option('admin_email');
 357          $mail->toname     = '';
 358          $mail->subject     = sprintf(__('[%s] Password Lost/Changed'), $blogname);
 359          $mail->content     = sprintf(__('Password Lost and Changed for user: %s'), $user->user_login) . "<br />\r\n";
 360  
 361              $mail->advanced = new stdClass();
 362              $mail->advanced->admin   = $mail->toemail;
 363              $mail->advanced->user    = $user;
 364  
 365          return MailPress::mail($mail);
 366      }
 367  
 368  	public static function wp_new_user_notification($user_id, $plaintext_pass = '') 
 369      {
 370          $user = new WP_User($user_id);
 371  
 372          $user_login = stripslashes($user->user_login);
 373          $user_email = stripslashes($user->user_email);
 374  
 375          $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
 376  
 377          $message  = sprintf(__('New user registration on your site %s:'), $blogname) . "<br />\r\n<br />\r\n";
 378          $message .= sprintf(__('Username: %s'), $user_login) . "<br />\r\n<br />\r\n";
 379          $message .= sprintf(__('E-mail: %s'), $user_email) . "<br />\r\n";
 380  
 381          $mail = new stdClass();
 382          $mail->Template    = 'new_user';
 383          $mail->toemail     = get_option('admin_email');
 384          $mail->toname     = '';
 385          $mail->subject     = sprintf(__('[%s] New User Registration'), $blogname);
 386          $mail->content     = $message;
 387  
 388              $mail->advanced = new stdClass();
 389                 $mail->advanced->admin   = $mail->toemail;
 390              $mail->advanced->user    = $user;
 391  
 392          /* deprecated */
 393              $mail->u = new stdClass();
 394              $mail->u->login    = $user_login;
 395              $mail->u->email    = $user_email;
 396          /* deprecated */
 397  
 398          MailPress::mail($mail);
 399  
 400          if ( empty($plaintext_pass) ) return;
 401  
 402          $user->plaintext_pass = $plaintext_pass;
 403  
 404          $message  = sprintf(__('Username: %s'), $user_login) . "<br />\r\n";
 405          $message .= sprintf(__('Password: %s'), $plaintext_pass) . "<br />\r\n";
 406          $message .= wp_login_url() . "<br />\r\n";
 407  
 408          $mail = new stdClass();
 409          $mail->Template    = 'new_user';
 410          $mail->toemail     = $user->user_email;
 411          $mail->toname     = $user->display_name;
 412          $mail->subject     = sprintf(__('[%s] Your username and password'), $blogname);
 413          $mail->content     = $message;
 414  
 415              $mail->advanced = new stdClass();
 416              $mail->advanced->user    = $user;
 417  
 418          /* deprecated */
 419              $mail->u = new stdClass();
 420              $mail->u->login    = $user_login;
 421              $mail->u->pwd    = $plaintext_pass;
 422          /* deprecated */
 423  
 424          MailPress::mail($mail);
 425      }
 426  
 427  	public static function retrieve_password_message($message, $key)
 428      {
 429          $user = ( strpos($_POST['user_login'], '@') ) ? get_user_by('email', trim( $_POST['user_login'])) : get_user_by('login', trim($_POST['user_login']));
 430  
 431          $user_login = $user->user_login;
 432          $user_email = $user->user_email;
 433          $url['site']   = network_site_url();
 434          $url['reset']  = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login');
 435  
 436          $_message = __('Someone requested that the password be reset for the following account:') . "<br />\r\n<br />\r\n";
 437          $_message .= $url['site'] . "<br />\r\n<br />\r\n";
 438          $_message .= sprintf(__('Username: %s'), $user_login) . "<br />\r\n<br />\r\n";
 439          $_message .= __('If this was a mistake, just ignore this email and nothing will happen.') . "<br />\r\n<br />\r\n";    
 440          $_message .= __('To reset your password, visit the following address:') . "<br />\r\n<br />\r\n";    
 441          $_message .= $url['reset'] . "<br />\r\n";
 442  
 443          $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
 444  
 445          $mail = new stdClass();
 446          $mail->Template    = 'retrieve_pwd';
 447          $mail->toemail     = $user_email;
 448          $mail->toname     = $user->display_name;
 449          $mail->subject     = sprintf( __('[%s] Password Reset'), $blogname );
 450          $mail->content     = $_message;
 451  
 452              $mail->advanced = new stdClass();
 453              $mail->advanced->user = $user;
 454              $mail->advanced->url  = $url;
 455  
 456          /* deprecated */
 457              $mail->u = new stdClass();
 458              $mail->u->login    = $user_login;
 459              $mail->u->key    = $key;
 460              $mail->u->url    = $url['reset'];
 461          /* deprecated */
 462  
 463          if (MailPress::mail($mail)) return false;
 464          return $message;
 465      }
 466  }


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