WYSIJA_help_email

The MailPoet Newsletters WYSIJA help email class.

Defined (1)

The class is defined in the following location(s).

/helpers/email.php  
  1. class WYSIJA_help_email extends WYSIJA_object{ 
  2.  
  3. function __construct() { 
  4. parent::__construct(); 
  5.  
  6. /** 
  7. * used to strip the unsubscribe links and the view in browser links from an email html 
  8. * @param type $content 
  9. * @return type 
  10. */ 
  11. function stripPersonalLinks($content) { 
  12.  
  13. //delete the view in browser span 
  14. $content = preg_replace('#<td id="wysija_viewbrowser_content"[^>]*>(.*)</td>#Uis', '', $content); 
  15. $content = preg_replace('#<p *class="wysija_viewbrowser_container"[^>]*>(.*)</p>#Uis', '', $content); 
  16.  
  17. //delete the unsubscribe td 
  18. $content = preg_replace('#<td id="wysija_unsubscribe_content"[^>]*>(.*)</td>#Uis', '', $content); 
  19. $content = preg_replace('#<p *class="wysija_unsubscribe_container"[^>]*>(.*)</p>#Uis', '', $content); 
  20.  
  21. return $content; 
  22.  
  23.  
  24. /** 
  25. * @param array $values configuration form's current values 
  26. * @param boolean $testMultisite test the multisite configuration 
  27. * @return boolean 
  28. */ 
  29. function send_test_mail($values, $testMultisite=false) { 
  30. $content_email=__('Yup, it works. You can start blasting away emails to the moon.', WYSIJA); 
  31.  
  32. $options=array( 
  33. 'sending_method'=>'sending_method',  
  34. 'sending_emails_site_method'=>'sending_emails_site_method',  
  35. 'sendmail_path'=>'sendmail_path',  
  36. 'smtp_rest'=>'smtp_rest',  
  37. 'smtp_host'=>'smtp_host',  
  38. 'smtp_port'=>'smtp_port',  
  39. 'smtp_secure'=>'smtp_secure',  
  40. 'smtp_auth'=>'smtp_auth',  
  41. ); 
  42.  
  43. if($testMultisite) { 
  44. $is_multisite=is_multisite(); 
  45.  
  46. //$is_multisite=true;//PROD comment that line 
  47. if(!$is_multisite) return false; 
  48.  
  49. switch($values[$options['sending_method']]) { 
  50. case 'network': 
  51. case 'site': 
  52. if($values[$options['sending_emails_site_method']]=='phpmail') { 
  53. $send_method='PHP Mail'; 
  54. }else{ 
  55. $send_method='Sendmail'; 
  56. $sendmail_path=$_POST['data']['wysija[config]['.$options['sendmail_path'].']']; 
  57. break; 
  58. case 'smtp': 
  59. $smtp=array(); 
  60. $send_method='SMTP'; 
  61. $config=WYSIJA::get('config', 'model'); 
  62. if(!isset($values[$options['smtp_rest']])) unset($config->values[$options['smtp_rest']]); 
  63. break; 
  64. case 'gmail': 
  65. $send_method='Gmail'; 
  66.  
  67. $values[$options['smtp_host']]='smtp.gmail.com'; 
  68. $values[$options['smtp_port']]='465'; 
  69. $values[$options['smtp_secure']]='ssl'; 
  70. $values[$options['smtp_auth']]=true; 
  71.  
  72. $content_email=__('You\'re all setup! You\'ve successfully sent with Gmail.', WYSIJA).'<br/><br/>'; 
  73. $content_email.=str_replace( 
  74. array('[link]', '[/link]'),  
  75. array('<a href="http://support.mailpoet.com/knowledgebase/send-with-smtp-when-using-a-professional-sending-provider/?utm_source=wpadmin&utm_campaign=test_email_result" target="_blank" title="SendGrid partnership">', '</a>'),  
  76. __('Looking for a faster method to send? [link]Read more[/link] on sending with a professional SMTP.', WYSIJA)); 
  77. break; 
  78.  
  79. $mailer=WYSIJA::get('mailer', 'helper'); 
  80. $mailer->__construct('', $values, $testMultisite); 
  81.  
  82. $current_user=WYSIJA::wp_get_userdata(); 
  83. $mailer->testemail=true; 
  84. $mailer->wp_user=&$current_user->data; 
  85. // If users enter a custom email, let's send to that address 
  86. if (isset($values['test_mails']) && trim($values['test_mails']) != '') { 
  87. $current_user->data->user_email = $values['test_mails']; 
  88.  
  89. $res=$mailer->sendSimple($current_user->data->user_email, str_replace('[send_method]', $send_method, __('[send_method] works with MailPoet', WYSIJA)), $content_email); 
  90.  
  91. if($res) { 
  92. $this->notice(sprintf(__('Test email successfully sent to %s', WYSIJA), '<b><i>'.$current_user->data->user_email.'</i></b>')); 
  93. return true; 
  94. }else{ 
  95. $config=WYSIJA::get('config', 'model'); 
  96. $bounce = $config->getValue('bounce_email'); 
  97. if(in_array($config->getValue('sending_method'), array('smtp', 'gmail')) && $config->getValue('smtp_secure')=='ssl' && !function_exists('openssl_sign')) { 
  98. $this->error(__('The PHP Extension openssl is not enabled on your server. Ask your host to enable it if you want to use an SSL connection.', WYSIJA)); 
  99. }elseif(!empty($bounce) AND !in_array($config->getValue('sending_method'), array('smtp_com', 'elasticemail'))) { 
  100. $this->error(sprintf(__('The bounce email address "%1$s" might actually cause the problem. Leave the field empty and try again.', WYSIJA), $bounce)); 
  101. //Case 2 : you are using SMTP but you didn't add an authentication 
  102. }elseif(in_array($config->getValue('sending_method'), array('smtp', 'gmail')) AND !$config->getValue('smtp_auth') AND strlen($config->getValue('smtp_password')) > 1) { 
  103. $this->error(__('You specified an SMTP password but you don\'t require an authentication, you might want to turn the SMTP authentication ON.', WYSIJA)); 
  104. //Case 3 : you are on localhost! 
  105. }elseif((strpos(WYSIJA_URL, 'localhost') || strpos(WYSIJA_URL, '127.0.0.1')) && in_array($config->getValue('sending_method'), array('sendmail', 'qmail', 'mail'))) { 
  106. $this->error(__('Your localhost may not have a mail server. To verify, please log out and click on the "Lost your password?" link on the login page. Do you receive the reset password email from your WordPress?', WYSIJA)); 
  107.  
  108. $this->error($mailer->reportMessage); 
  109. return false; 
  110.  
  111. /** 
  112. * get view in browser link 
  113. * @param array/stdClass $data_email 
  114. * @return string url 
  115. */ 
  116. function getVIB($data_email) { 
  117. if (!is_array($data_email) && is_object($data_email)) 
  118. $data_email = (array) $data_email; 
  119. if(false && isset($data_email['params']['vib_id'])) return WYSIJA::get_permalink($data_email['params']['vib_id'], false); 
  120. else{ 
  121. $paramsurl=array( 
  122. 'wysija-page'=>1,  
  123. 'controller'=>'email',  
  124. 'action'=>'view',  
  125. 'email_id'=>$data_email['email_id'] 
  126. ); 
  127.  
  128. $modelConf=WYSIJA::get('config', 'model'); 
  129. return WYSIJA::get_permalink($modelConf->getValue('confirm_email_link'), $paramsurl); 
  130.  
  131. /** 
  132. * return an array of active follow_ups 
  133. * @param type $data 
  134. * @param boolean $delay calculate delay and add it to the result 
  135. */ 
  136. function get_active_follow_ups($data=array('subject', 'params'), $delay=false) { 
  137. if($delay) $model_queue=WYSIJA::get('queue', 'model'); 
  138.  
  139. $model_email=WYSIJA::get('email', 'model'); 
  140. $model_email->setConditions(array('type'=>2, 'status'=>99)); 
  141. $automatic_emails=$model_email->getRows($data); 
  142.  
  143. $follow_ups_per_list=array(); 
  144. foreach($automatic_emails as &$auto_email) { 
  145. $model_email->getParams($auto_email); 
  146. if($delay) $auto_email['delay']=$model_queue->calculate_delay($auto_email['params']['autonl']); 
  147. if(isset($auto_email['params']['autonl']['event']) && $auto_email['params']['autonl']['event']=='subs-2-nl') { 
  148. if(!isset($follow_ups_per_list[$auto_email['params']['autonl']['subscribetolist']])) $follow_ups_per_list[$auto_email['params']['autonl']['subscribetolist']]=array(); 
  149. $follow_ups_per_list[$auto_email['params']['autonl']['subscribetolist']][]=$auto_email; 
  150.  
  151. return $follow_ups_per_list; 
  152.