[ Index ]

MailPress 544

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

title

Body

[close]

/mp-content/add-ons/ -> MailPress_Headers_specific.php (source)

   1  <?php
   2  if (class_exists('MailPress') && !class_exists('MailPress_Headers_specific'))
   3  {
   4  /*
   5  Plugin Name: MailPress_Headers_specific
   6  Plugin URI: http://blog.mailpress.org/tutorials/add-ons/headers_specific/
   7  Description: Mails : Adding specific headers in mail (sample)
   8  Version: 5.4.4
   9  */
  10  
  11  class MailPress_Headers_specific
  12  {
  13  	function __construct()
  14      {
  15  // prepare mail
  16          add_filter('MailPress_swift_message_headers',      array(__CLASS__, 'swift_message_headers'), 8, 2);
  17      }
  18  
  19  // prepare mail
  20  	public static function swift_message_headers($message, $row)
  21      {
  22          if ($row->template == 'new_subscriber') return $message;
  23  
  24          $url = apply_filters('MailPress_header_url', '{{unsubscribe}}', $row);
  25          if ('{{unsubscribe}}' == $url) $url = MP_User::get_unsubscribe_url( '{{_confkey}}' );
  26  
  27          if (isset($row->mp_user_id))
  28          {
  29              $confkey = MP_User::get_key_by_email(MP_User::get_email($row->mp_user_id));
  30              $url = str_replace('{{_confkey}}', $confkey, $url);
  31          }
  32  
  33          $headers = array(
  34                      array(    'type' => Swift_Mime_Header::TYPE_TEXT , 
  35                              'name' => 'List-Unsubscribe', 
  36                              'value' => "<$url>"
  37                      ),
  38                      array(    'type' => Swift_Mime_Header::TYPE_TEXT , 
  39                              'name' => 'List-ID', 
  40                              'value' => get_option( 'blogname' )
  41                      )
  42                  );
  43  
  44  
  45          $_headers = $message->getHeaders();
  46          foreach ($headers as $header)
  47          {
  48              switch ($header['type'])
  49              {
  50                  case Swift_Mime_Header::TYPE_TEXT :
  51                      $_headers->addTextHeader($header['name'], $header['value']);
  52                    break;
  53                  case Swift_Mime_Header::TYPE_PARAMETERIZED :
  54                      $_headers->addParameterizedHeader($header['name'], $header['value'], $header['parms']);
  55                    break;
  56                  case Swift_Mime_Header::TYPE_MAILBOX :
  57                      $_headers->addMailboxHeader($header['name'], $header['value']);
  58                    break;
  59                  case Swift_Mime_Header::TYPE_DATE :
  60                      $_headers->addDateHeader($header['name'], $header['value']);
  61                    break;
  62                  case Swift_Mime_Header::TYPE_ID :
  63                      $_headers->addIdHeader($header['name'], $header['value']);
  64                    break;
  65                  case Swift_Mime_Header::TYPE_PATH :
  66                      $_headers->addPathHeader($header['name'], $header['value']);
  67                    break;
  68              }
  69          }
  70  
  71          return $message;
  72      }
  73  }
  74  new MailPress_Headers_specific();
  75  }


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